diff --git a/e2e/tests/my-resources.spec.js b/e2e/tests/my-resources.spec.js index b2cf06c1..dedfea06 100644 --- a/e2e/tests/my-resources.spec.js +++ b/e2e/tests/my-resources.spec.js @@ -211,8 +211,12 @@ test.describe('My Resources', () => { const done = Object.assign({}, running, { status: 'done', resource_id: 9, result: { resource: { id: 9, title: 'Croup in children (new)' }, grounding: { used: true, count: 7 }, searches: [], imageJobs: [], imageFailures: [] } }); - await stub(page, { - jobs: n => [n === 0 ? running : done], + // Running until Generate is pressed, done after it. The page polls the job + // list as soon as it opens, so a job that lands on a poll *count* would + // have landed before the click and there would be no transition to + // announce — which is the behaviour under test, not a detail of the stub. + const sent = await stub(page, { + jobs: () => (sent.length ? [done] : [running]), library: n => n === 0 ? LIBRARY : { success: true, resources: LIBRARY.resources.concat([ { id: 9, title: 'Croup in children (new)', kind: 'presentation', topic: 'croup', grounded_count: 7, created_at: new Date().toISOString() }]) }, @@ -232,7 +236,8 @@ test.describe('My Resources', () => { const running = { id: 9, topic: 'croup', kind: 'presentation', status: 'running', created_at: new Date().toISOString() }; const failed = Object.assign({}, running, { status: 'failed', error: 'The model returned nothing. Try again.' }); - await stub(page, { jobs: n => [n === 0 ? running : failed] }); + // As above: running until the click, so the failure is a transition. + const sent = await stub(page, { jobs: () => (sent.length ? [failed] : [running]) }); await openTab(page); await page.fill('#mr-topic', 'croup'); await page.click('#btn-mr-generate'); @@ -389,7 +394,9 @@ test.describe('My Resources', () => { { tool: 'pubmed_search', query: 'croup', count: 6, reason: null }, { tool: 'web_search', query: 'croup', count: 0, reason: 'no results' }, ], imageJobs: [], imageFailures: [] } }); - await stub(page, { jobs: n => [n === 0 ? running : done] }); + // Running until the click, done after it — searching happens server-side, + // inside the job, so what was searched for arrives with the landing. + const sent = await stub(page, { jobs: () => (sent.length ? [done] : [running]) }); await openTab(page); await page.fill('#mr-topic', 'croup'); await page.click('#btn-mr-generate');