import { fr } from '@/i18n/fr' import type { Page, TestInfo } from '@playwright/test' import { expect, expectAccessible, expectNoHorizontalOverflow, test, } from '../support/browser' import { stepUpAdmin } from '../support/admin' import { dropLateReplays, routeToSandbox } from '../support/sandbox' import { SECTIONS, TABS, closeReferences, draftPath, draftTitle, editorActor, makeActor, openEditor, openReferences, openSection, pointOf, seedDraft, selectTab, shapeWith, showDrawing, type Actor, } from '../support/editor' import { signIn } from '../support/shell' // V1-2.6 access, narrow screens and axe (contract C26, C31; plan « Modes, permissions, // layout »): a reviewer-only account and an editor without the admin role read the draft // without editing it, an account without a capability is refused, the editor is read-only // at 320, 375, 768 and 800 px and edits at 1 024 px, with no sideways scroll, and axe finds no // serious violation on any tab, edit or read-only. const dict = fr const isPhone = (info: TestInfo) => info.project.name === 'chromium-375' const seedShape = shapeWith( pointOf('p1', 'main', { cx: 500, cy: 400, r: 40 }, 'Point un'), ) async function openAs(page: Page, actor: Actor, sheetId: string) { await signIn(page, actor.account, dict) await page.goto('/app/admin') await stepUpAdmin(page, dict, actor.secret) await page.goto(draftPath(sheetId)) } async function expectReadOnly(page: Page) { await expect( page.getByRole('heading', { level: 1, name: draftTitle(dict) }), ).toBeVisible() await expect( page.getByText(dict['editor.draft.read_only'], { exact: true }), ).toBeVisible() await expect( page.getByRole('button', { name: dict['common.save'], exact: true }), ).toHaveCount(0) await selectTab(page, dict, 'annotations') await expect( page.getByRole('toolbar', { name: dict['editor.annotations.tools'] }), ).toHaveCount(0) await expect(page.getByRole('textbox')).toHaveCount(0) } test.describe('editor access, narrow screens and axe', () => { test.use({ locale: 'fr-FR', actionTimeout: 15_000 }) test.beforeEach(async ({ context }, info) => { test.skip(isPhone(info), 'the widths are set by the tests themselves') // floor-guard: allow C16 editing needs >= 1024 px; phone read-only covered in editor-access await routeToSandbox(context) }) test.afterEach(async ({ context }) => { await dropLateReplays(context) }) test('a reviewer-only account reads the draft, read-only', async ({ page, requests, }) => { const [editor, reviewer] = [ await editorActor('fr'), await makeActor('fr', null, ['sheet_reviewer']), ] requests.forbid(reviewer.account.email, reviewer.account.password) const seed = await seedDraft(editor, { shape: seedShape }) await openAs(page, reviewer, seed.sheetId) await expectReadOnly(page) await expect( page.getByText(dict['editor.draft.mode.rights'], { exact: false }), ).toBeVisible() }) // The server answers « not found » to staff without the admin or owner role, so the // page shows the not-found screen, not a read-only draft (the brief expected the latter). const REFUSED = [ ['an editor grant without the admin role', null, ['sheet_editor']], ['an admin without any capability', 'admin', []], ] as const for (const [label, role, grants] of REFUSED) { test(`${label} gets the not-found screen, no editor`, async ({ page, requests, }) => { const [editor, other] = [ await editorActor('fr'), await makeActor('fr', role, [...grants]), ] requests.forbid(other.account.email, other.account.password) const seed = await seedDraft(editor, { shape: seedShape }) await openAs(page, other, seed.sheetId) await expect( page.getByRole('heading', { name: dict['admin.overview.not_found_title'], }), ).toBeVisible() await expect(page.getByRole('tablist')).toHaveCount(0) await expect( page.getByRole('button', { name: dict['common.save'], exact: true }), ).toHaveCount(0) }) } for (const width of [320, 375, 768, 800]) { test(`read-only at ${width} px, no horizontal scroll`, async ({ page, requests, }) => { const actor = await editorActor('fr') requests.forbid(actor.account.email, actor.account.password) const seed = await seedDraft(actor, { shape: seedShape }) await signIn(page, actor.account, dict) await page.goto('/app/admin') await stepUpAdmin(page, dict, actor.secret) await page.setViewportSize({ width, height: 800 }) await page.goto(draftPath(seed.sheetId)) await expect( page.getByRole('heading', { level: 1, name: draftTitle(dict) }), ).toBeVisible() await expect( page.getByText(dict['editor.draft.mode.narrow'], { exact: false }), ).toBeVisible() await expect( page.getByRole('button', { name: dict['common.save'], exact: true }), ).toHaveCount(0) await expectNoHorizontalOverflow(page, `the draft at ${width} px`) await expectAccessible(page, `the draft at ${width} px`) await openReferences(page, dict) await expectNoHorizontalOverflow(page, `the panel at ${width} px`) await expectAccessible(page, `the references panel at ${width} px`) }) } test('edit at 1 024 px, no horizontal scroll, axe on every tab', async ({ page, requests, }) => { test.setTimeout(120_000) const actor = await editorActor('fr') requests.forbid(actor.account.email, actor.account.password) const seed = await seedDraft(actor, { shape: seedShape }) await page.setViewportSize({ width: 1024, height: 800 }) await openEditor(page, dict, actor, seed.sheetId) await expect( page.getByRole('button', { name: dict['common.save'], exact: true }), ).toBeVisible() for (const tab of TABS) { await selectTab(page, dict, tab) await page.waitForLoadState('networkidle') if (tab === 'annotations') await expect( page.getByRole('button', { name: dict['editor.annotations.add.point'], }), ).toBeEnabled() await expectNoHorizontalOverflow(page, `the ${tab} tab at 1 024 px`) await expectAccessible(page, `the ${tab} tab (edit)`) } for (const section of SECTIONS) { await openSection(page, dict, section) await page.waitForLoadState('networkidle') await expectNoHorizontalOverflow( page, `the ${section} section at 1 024 px`, ) await expectAccessible(page, `the ${section} section (edit)`) } await showDrawing(page, dict) await openReferences(page, dict) await expectNoHorizontalOverflow(page, 'the references panel at 1 024 px') await expectAccessible(page, 'the references panel (edit)') await closeReferences(page, dict) }) test('axe on every tab of a read-only draft', async ({ page, requests }) => { test.setTimeout(120_000) const [editor, reviewer] = [ await editorActor('fr'), await makeActor('fr', null, ['sheet_reviewer']), ] requests.forbid(reviewer.account.email, reviewer.account.password) const seed = await seedDraft(editor, { shape: seedShape }) await openAs(page, reviewer, seed.sheetId) await expect( page.getByRole('heading', { level: 1, name: draftTitle(dict) }), ).toBeVisible() for (const tab of TABS) { await selectTab(page, dict, tab) await page.waitForLoadState('networkidle') await expectAccessible(page, `the ${tab} tab (read-only)`) } for (const section of SECTIONS) { await openSection(page, dict, section) await expectAccessible(page, `the ${section} section (read-only)`) } await showDrawing(page, dict) await openReferences(page, dict) await expectAccessible(page, 'the references panel (read-only)') }) })