Files
faunosteo/apps/app/e2e/shell/editor-access.spec.ts
T
bchanot bc2dba7c14 feat(editor): four tabs, Annotations sections, references from the header
U1 Lot B1. Four tabs (Général, Annotations, Constats, Vérification); views,
categories and regions become full-width Annotations sections opened from the
overview panel; references move to a header-toggled panel (minimal, Lot D
completes it); « Aller à » goes through EditorTarget and the navigation hook.
EditorWorkspace owns the navigation; DraftHeader split in HeaderActions and
SaveLine; EditorTabs split in TabList and MoreTabs.

R-24, assertions removed or rewritten (file: old -> new):
unit
- editor-route.test: seven tab names -> four; « Plus » at 800 px with
  Références clicked -> no « Plus »; below 640 px five others -> Général,
  Constats, and Constats opens the findings tab; + references panel cases
- editor-route-recovery.test: tab Références + editor-tab-references label ->
  header button + editor-references-panel labelled by its heading
- editor-mode.test: small tier `more` of five -> [general, findings]
- editor-focus-request.test: {key,serial} -> {target,serial}; ReferencesTab and
  VertebraeTab -> ReferencesPanel and RegionsSection; issueTarget tab/key ->
  target place/section/key (vertebrae tab -> annotations/regions); consumed
  context (serial) -> (serial, outcome); annotation case adds heading focus
- editor-verification.test: onGoTo('annotations', key) -> navigate(targetOfKey
  (key), opener); props onSelectTab/onGoTo -> navigate
- editor-annotations-tab.test: props onSelectTab -> navigate + section props;
  no_category text « (onglet Général) » -> « (Annotations, section
  Catégories) »
- editor-tabs-general.test: categories cases render GeneralTab ->
  CategoriesSection(doc); + Général holds no categories editor
- editor-tabs-lists.test: tab imports -> panel and section; read-only
  references « no button » -> only « Fermer les références »
- editor-tabs-views, editor-drawing-upload, editor-repair.test: ViewsTab ->
  ViewsSection import, assertions kept; editor-findings.test: navigate prop
e2e
- support/editor selectTab: exact name -> pattern (error badge in the name);
  + place, openSection, showDrawing, backToDrawing, openReferences, TABS
- support/warm-up: seven tabs -> four + sections + references panel
- editor-access: seven-tab axe loops -> four tabs + three sections + panel
  (edit and read-only); narrow widths add panel overflow and axe
- editor-drawings: tab Vues -> openSection views; tab Annotations ->
  showDrawing
- editor-structures: tab Général (categories) -> openSection categories, axe
  label « general tab » -> « categories section »; tab Références ->
  openReferences/closeReferences; tab Vertèbres -> openSection regions; tab
  Annotations -> showDrawing
- editor-geometry: three tab Vues -> openSection views
- editor-equine: tab Général (categories add) -> openSection categories; five
  tabs loop -> two tabs + sections + panel; tab Annotations -> showDrawing
- editor-journey: tab Vues, tab Général (category), tab Annotations ->
  openSection views/categories, showDrawing; frozen axe scrolls to the header
- lan/trial-lan (not run): tab Vues -> Annotations tab + views entry

Verified: typecheck, lint, vitest 107 files / 1125 tests, whole shell suite on
the sandbox 151 passed, 49 skipped, 0 failed.
2026-11-06 20:25:35 +01:00

223 lines
7.8 KiB
TypeScript

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)')
})
})