|
| 1 | +/** |
| 2 | + * E2E Test: Plan-first appraisals (#791) |
| 3 | + * |
| 4 | + * A reviewer's ad hoc checklist plans the cell, so the other reviewer's own |
| 5 | + * checklist appears on their To-Do tab without creating anything. Swapping a |
| 6 | + * slot holder who has work in progress asks whether to hand it over; the new |
| 7 | + * reviewer then continues from the same answers and the old one has nothing |
| 8 | + * left to do. |
| 9 | + * |
| 10 | + * Prerequisites: |
| 11 | + * pnpm --filter web dev (localhost:3010, DEV_MODE=true) |
| 12 | + */ |
| 13 | + |
| 14 | +import { test, expect } from './test'; |
| 15 | +import { |
| 16 | + addProjectMember, |
| 17 | + cleanupByEmail, |
| 18 | + cleanupScenario, |
| 19 | + seedDualReviewerScenario, |
| 20 | + switchUser, |
| 21 | + testApi, |
| 22 | + uniquePrefix, |
| 23 | + type DualReviewerScenario, |
| 24 | + type SeededUser, |
| 25 | + type SessionCookie, |
| 26 | +} from './helpers'; |
| 27 | +import { setupProjectWithStudy, waitForSynced } from './shared-steps'; |
| 28 | + |
| 29 | +let scenario: DualReviewerScenario; |
| 30 | +let carol: SeededUser; |
| 31 | +let cookiesC: SessionCookie[]; |
| 32 | + |
| 33 | +/** A third org member; the seed route ignores conflicts, so the org row is reused. */ |
| 34 | +async function seedThirdReviewer(orgId: string) { |
| 35 | + const prefix = uniquePrefix('e2e'); |
| 36 | + const id = `${prefix}-user-c`; |
| 37 | + const email = `carol-${prefix}@test.corates.org`; |
| 38 | + const seedRes = await testApi('/api/test/seed', { |
| 39 | + method: 'POST', |
| 40 | + headers: { 'Content-Type': 'application/json' }, |
| 41 | + body: JSON.stringify({ |
| 42 | + users: [{ id, name: 'Carol Reviewer', email, givenName: 'Carol', familyName: 'Reviewer' }], |
| 43 | + org: { id: orgId, name: 'E2E Test Org' }, |
| 44 | + orgMembers: [{ userId: id, role: 'member' }], |
| 45 | + }), |
| 46 | + }); |
| 47 | + if (!seedRes.ok) throw new Error(`Seed failed: ${seedRes.status} ${await seedRes.text()}`); |
| 48 | + const sessionRes = await testApi('/api/test/session', { |
| 49 | + method: 'POST', |
| 50 | + headers: { 'Content-Type': 'application/json' }, |
| 51 | + body: JSON.stringify({ userId: id }), |
| 52 | + }); |
| 53 | + if (!sessionRes.ok) throw new Error(`Session failed: ${sessionRes.status}`); |
| 54 | + const { cookies } = (await sessionRes.json()) as { cookies: SessionCookie[] }; |
| 55 | + return { user: { id, name: 'Carol Reviewer', email }, cookies }; |
| 56 | +} |
| 57 | + |
| 58 | +test.beforeAll(async () => { |
| 59 | + scenario = await seedDualReviewerScenario(); |
| 60 | + const third = await seedThirdReviewer(scenario.orgId); |
| 61 | + carol = third.user; |
| 62 | + cookiesC = third.cookies; |
| 63 | +}); |
| 64 | + |
| 65 | +test.afterAll(async () => { |
| 66 | + if (carol) await cleanupByEmail(carol.email); |
| 67 | + if (scenario) await cleanupScenario(scenario); |
| 68 | +}); |
| 69 | + |
| 70 | +test('A planned cell reaches every reviewer, and a swap hands work over', async ({ |
| 71 | + context, |
| 72 | + page, |
| 73 | +}) => { |
| 74 | + const projectId = await setupProjectWithStudy(context, page, scenario, 'Plan First E2E'); |
| 75 | + await addProjectMember(scenario.orgId, projectId, carol.id, scenario.cookiesA); |
| 76 | + |
| 77 | + // ================================================================ |
| 78 | + // Alice adds an AMSTAR2 checklist from To-Do: this plans the cell |
| 79 | + // ================================================================ |
| 80 | + await page.getByRole('tab', { name: /To-Do/i }).click(); |
| 81 | + await expect(page.getByRole('button', { name: /Select Checklist/i })).toBeVisible({ |
| 82 | + timeout: 10_000, |
| 83 | + }); |
| 84 | + await page.getByRole('button', { name: /Select Checklist/i }).click(); |
| 85 | + await page.getByRole('button', { name: /Add Checklist/i }).click(); |
| 86 | + await expect(page.getByRole('button', { name: 'Open', exact: true })).toBeVisible({ |
| 87 | + timeout: 10_000, |
| 88 | + }); |
| 89 | + await waitForSynced(page); |
| 90 | + |
| 91 | + // ================================================================ |
| 92 | + // Bob's To-Do already holds his copy; he starts answering |
| 93 | + // ================================================================ |
| 94 | + await switchUser(context, scenario.cookiesB); |
| 95 | + await page.goto(`/projects/${projectId}`); |
| 96 | + await page.getByRole('tab', { name: /To-Do/i }).click(); |
| 97 | + await expect(page.getByRole('button', { name: 'Open', exact: true })).toBeVisible({ |
| 98 | + timeout: 15_000, |
| 99 | + }); |
| 100 | + await expect(page.getByRole('button', { name: /Select Checklist/i })).toHaveCount(0); |
| 101 | + |
| 102 | + await page.getByRole('button', { name: 'Open', exact: true }).click(); |
| 103 | + await expect(page).toHaveURL(/\/checklists\//, { timeout: 10_000 }); |
| 104 | + const firstYes = page.getByRole('radio', { name: 'Yes' }).first(); |
| 105 | + await expect(firstYes).toBeVisible({ timeout: 10_000 }); |
| 106 | + await firstYes.click(); |
| 107 | + await expect(firstYes).toBeChecked({ timeout: 5_000 }); |
| 108 | + await waitForSynced(page); |
| 109 | + |
| 110 | + // ================================================================ |
| 111 | + // Alice replaces Bob with Carol; the sheet asks about Bob's work |
| 112 | + // ================================================================ |
| 113 | + await switchUser(context, scenario.cookiesA); |
| 114 | + await page.goto(`/projects/${projectId}`); |
| 115 | + await page.getByRole('tab', { name: /All Studies/i }).click(); |
| 116 | + await expect(page.getByTestId('study-card').first()).toBeVisible({ timeout: 15_000 }); |
| 117 | + await page.getByTestId('study-card').first().getByTestId('study-card-menu').click(); |
| 118 | + await page.getByRole('menuitem', { name: /Assign Reviewers/i }).click(); |
| 119 | + |
| 120 | + const sheet = page.getByTestId('assign-reviewers-sheet'); |
| 121 | + await expect(sheet).toBeVisible({ timeout: 5_000 }); |
| 122 | + await sheet.getByTestId('reviewer-picker-2').click(); |
| 123 | + await expect(page.getByRole('option', { name: /Carol/i })).toBeVisible({ timeout: 15_000 }); |
| 124 | + await page.getByRole('option', { name: /Carol/i }).click(); |
| 125 | + await expect(page.getByRole('listbox')).toBeHidden({ timeout: 5_000 }); |
| 126 | + await sheet.getByRole('button', { name: 'Save reviewers' }).click(); |
| 127 | + |
| 128 | + const prompt = page.getByTestId('in-progress-prompt'); |
| 129 | + await expect(prompt).toBeVisible({ timeout: 5_000 }); |
| 130 | + await prompt.getByRole('button', { name: 'Hand over' }).click(); |
| 131 | + await expect(sheet).toBeHidden({ timeout: 10_000 }); |
| 132 | + await waitForSynced(page); |
| 133 | + |
| 134 | + // ================================================================ |
| 135 | + // Carol continues from Bob's answers; Bob has nothing left to do |
| 136 | + // ================================================================ |
| 137 | + await switchUser(context, cookiesC); |
| 138 | + await page.goto(`/projects/${projectId}`); |
| 139 | + await page.getByRole('tab', { name: /To-Do/i }).click(); |
| 140 | + await expect(page.getByRole('button', { name: 'Open', exact: true })).toBeVisible({ |
| 141 | + timeout: 15_000, |
| 142 | + }); |
| 143 | + await page.getByRole('button', { name: 'Open', exact: true }).click(); |
| 144 | + await expect(page).toHaveURL(/\/checklists\//, { timeout: 10_000 }); |
| 145 | + await expect(page.getByRole('radio', { name: 'Yes' }).first()).toBeChecked({ timeout: 10_000 }); |
| 146 | + |
| 147 | + await switchUser(context, scenario.cookiesB); |
| 148 | + await page.goto(`/projects/${projectId}`); |
| 149 | + await page.getByRole('tab', { name: /To-Do/i }).click(); |
| 150 | + await expect(page.getByRole('tab', { name: /To-Do/i })).toBeVisible({ timeout: 15_000 }); |
| 151 | + await expect(page.getByRole('button', { name: 'Open', exact: true })).toHaveCount(0); |
| 152 | +}); |
0 commit comments