Files
faunosteo/apps/app/e2e/shell/catalogue.spec.ts
T
bchanot 4111efa1d1 fix(app): unreadable permissions show a retry, never the form (V1-2.5 L1)
Owner checkpoint 2026-11-02: creation page checks loading, server refusal, failed read, then the editor rule; Administration home shows the same notice. reloadAccess re-reads roles and grants without wiping held state; refreshAccount (no caller) removed. Zone panel live region always mounted. Unit and e2e for reviewer-only and editor.
2026-11-02 21:21:59 +01:00

337 lines
13 KiB
TypeScript

import { randomUUID } from 'node:crypto'
import { en } from '@/i18n/en'
import { fr } from '@/i18n/fr'
import type { Dict } from '@/i18n/types'
import type { Page, TestInfo } from '@playwright/test'
import {
expect,
expectAccessible,
expectNoHorizontalOverflow,
test,
} from '../support/browser'
import { seedGrant } from '../support/admin'
import { seedOfficialSheet, type FixtureSheet } from '../support/catalogue'
import {
createAccount,
dropLateReplays,
routeToSandbox,
} from '../support/sandbox'
import { signIn } from '../support/shell'
// V1-2.5 P1 on the isolated stack (contract §11.2, §16.6 Acceptance): the
// catalogue of official sheets read by a catalogue reader, with sheets
// published, archived and left in draft through SQL fixtures (prior owner
// actions); the refusal of an account without access, the same for an
// existing and an unknown sheet. FR and EN, desktop and 320 to 430 px, axe on
// every state, the whole drawing in the box at opening.
const LANGUAGES = [
['fr', fr],
['en', en],
] as const
const PHONE_WIDTHS = [320, 375, 430]
const isPhone = (info: TestInfo) => info.project.name === 'chromium-375'
const tagOf = () => randomUUID().slice(0, 8)
const heading = (page: Page, name: string) =>
page.getByRole('main').getByRole('heading', { level: 1, name })
/** Follows an entry of the shell's navigation: the sidebar, or the drawer on a phone. */
async function navigate(page: Page, dict: Dict, info: TestInfo, key: string) {
if (isPhone(info)) {
await page.getByRole('button', { name: dict['shell.open_menu'] }).click()
await page
.getByRole('dialog', { name: dict['shell.nav_label'] })
.getByRole('navigation')
.getByRole('link', { name: dict[key] })
.click()
// The drawer's modal keeps the page inert until its exit animation ends:
// typed text would be lost (a fill on the search box went nowhere).
await expect(
page.getByRole('dialog', { name: dict['shell.nav_label'] }),
).toHaveCount(0)
} else {
await page
.getByRole('navigation', { name: dict['shell.nav_label'] })
.getByRole('link', { name: dict[key] })
.click()
}
}
const cards = (page: Page, dict: Dict) =>
page
.getByRole('list', { name: dict['catalogue.results'] })
.getByRole('listitem')
/** Sheet names of a test: unique, so the shared catalogue never mixes runs. */
const namesOf = (tag: string, what: string) => ({
fr: `Cheval ${what} ${tag}`,
en: `Horse ${what} ${tag}`,
})
/** The whole composed drawing sits inside the canvas box (no part cut at opening). */
async function expectWholeDrawing(page: Page, state: string) {
const canvas = page.getByTestId('catalogue-canvas')
const svg = page
.getByTestId('catalogue-canvas-drawing')
.locator('svg')
.first()
await expect(svg).toBeVisible()
const [box, drawing] = [await canvas.boundingBox(), await svg.boundingBox()]
expect(box && drawing, `boxes on ${state}`).toBeTruthy()
const inside =
drawing!.x >= box!.x - 1 &&
drawing!.y >= box!.y - 1 &&
drawing!.x + drawing!.width <= box!.x + box!.width + 1 &&
drawing!.y + drawing!.height <= box!.y + box!.height + 1
expect(
inside,
`drawing ${JSON.stringify(drawing)} inside ${JSON.stringify(box)} on ${state}`,
).toBe(true)
expect(drawing!.width, `drawing width on ${state}`).toBeGreaterThan(
box!.width * 0.5,
)
}
async function searchCatalogue(page: Page, dict: Dict, term: string) {
await page
.getByRole('searchbox', { name: dict['catalogue.search'] })
.fill(term)
}
/** Opens a sheet page and waits for its drawing. */
async function openSheet(page: Page, path: string, name: string) {
await page.goto(path)
await expect(heading(page, name)).toBeVisible()
await expect(
page.getByTestId('catalogue-canvas-drawing').locator('svg').first(),
).toBeVisible()
}
for (const [locale, dict] of LANGUAGES) {
test.describe(`catalogue (${locale})`, () => {
test.use({ locale: locale === 'fr' ? 'fr-FR' : 'en-GB' })
test.beforeEach(async ({ context }) => {
await routeToSandbox(context)
})
test.afterEach(async ({ context }) => {
await dropLateReplays(context)
})
test('P1: a reader searches, opens a sheet, picks a zone, reads a retired version; drafts and archives stay out', async ({
page,
requests,
}, info) => {
test.setTimeout(240_000)
const tag = tagOf()
const listed = await seedOfficialSheet(namesOf(tag, 'publié'), 'listed')
const archived = await seedOfficialSheet(
namesOf(tag, 'archivé'),
'archived',
)
const draft = await seedOfficialSheet(namesOf(tag, 'brouillon'), 'draft')
const name = (sheet: FixtureSheet) => sheet.names[locale]
const reader = await createAccount(locale, false)
await seedGrant(reader, 'catalog_reader')
requests.forbid(reader.email, reader.password, reader.displayName, tag)
await signIn(page, reader, dict)
// The entry follows the reader's own grant; no administration entry.
await expect(
page.getByRole('link', { name: dict['shell.nav.admin'] }),
).toHaveCount(0)
await navigate(page, dict, info, 'shell.nav.anatomy')
await expect(page).toHaveURL(/\/app\/anatomy$/)
await expect(heading(page, dict['shell.nav.anatomy'])).toBeVisible()
await expect(cards(page, dict).first()).toBeVisible()
// Search by name: the published sheet only; the draft and the archived one are never listed.
await searchCatalogue(page, dict, tag)
await expect(cards(page, dict)).toHaveCount(1)
await expect(
cards(page, dict).getByRole('heading', { level: 2 }),
).toHaveText(name(listed))
await searchCatalogue(page, dict, name(draft))
await expect(page.getByText(dict['catalogue.no_results'])).toBeVisible()
await searchCatalogue(page, dict, name(archived))
await expect(page.getByText(dict['catalogue.no_results'])).toBeVisible()
await searchCatalogue(page, dict, tag)
const widths = isPhone(info) ? PHONE_WIDTHS : [page.viewportSize()!.width]
for (const width of widths) {
await page.setViewportSize({ width, height: isPhone(info) ? 667 : 800 })
await expectAccessible(page, `the catalogue list at ${width} px`)
await expectNoHorizontalOverflow(
page,
`the catalogue list at ${width} px`,
)
}
await cards(page, dict)
.getByRole('link', {
name: dict['catalogue.view_sheet'].replace('{name}', name(listed)),
})
.click()
await expect(page).toHaveURL(new RegExp(`/app/anatomy/${listed.id}$`))
await expect(heading(page, name(listed))).toBeVisible()
// The current version is v2, published; no admin link for a reader.
await expect(
page.getByText(dict['catalogue.versions.earlier_one']),
).toBeVisible()
await expect(
page.getByText(dict['catalogue.status.deprecated']),
).toHaveCount(0)
await expect(
page.getByRole('link', { name: dict['catalogue.open_admin'] }),
).toHaveCount(0)
for (const width of widths) {
await page.setViewportSize({ width, height: isPhone(info) ? 667 : 800 })
// Opening at this width: the framing is measured on a fresh page.
await openSheet(page, `/app/anatomy/${listed.id}`, name(listed))
await expectWholeDrawing(page, `the sheet page at ${width} px`)
await expectAccessible(page, `the sheet page at ${width} px`)
await expectNoHorizontalOverflow(page, `the sheet page at ${width} px`)
}
// Narrow screens (viewport set here, whatever the project): the zone
// panel keeps its live region from the first render, and the references
// card never covers the drawing.
const original = page.viewportSize()!
for (const width of [320, 375]) {
await page.setViewportSize({ width, height: 667 })
await openSheet(page, `/app/anatomy/${listed.id}`, name(listed))
const panel = page.locator('[aria-live="polite"]', {
has: page.locator('#catalogue-zone-title'),
})
await expect(panel, `live region before a pick at ${width} px`).toHaveCount(1)
const chooser = page.getByRole('combobox', {
name: dict['catalogue.zone.choose'],
})
const first = await chooser.locator('option').nth(1).getAttribute('value')
await chooser.selectOption(first!)
const zoneName = (await chooser.locator('option:checked').textContent()) ?? ''
await expect(panel, `live region after a pick at ${width} px`).toContainText(zoneName)
const drawingBox = await page
.getByTestId('catalogue-canvas-drawing')
.locator('svg')
.first()
.boundingBox()
const referencesBox = await page
.getByRole('heading', { level: 2, name: dict['catalogue.references.title'] })
.locator('xpath=ancestor::section[1]')
.boundingBox()
expect(
referencesBox!.y,
`references below the drawing at ${width} px`,
).toBeGreaterThanOrEqual(drawingBox!.y + drawingBox!.height - 1)
}
await page.setViewportSize(original)
// A zone picked on the drawing, then one from the list: its panel shows.
const zone = page.getByRole('combobox', {
name: dict['catalogue.zone.choose'],
})
// A real click where the marker is painted (several nodes carry the id; the top one takes it).
const point = page
.getByTestId('catalogue-canvas-drawing')
.locator(
'circle[data-anno-id="hind-fetlock"][pointer-events="visiblePainted"]',
)
.first()
await point.evaluate((el) => el.scrollIntoView({ block: 'center' }))
const marker = (await point.boundingBox())!
await page.mouse.click(
marker.x + marker.width / 2,
marker.y + marker.height / 2,
)
await expect(zone).toHaveValue('hind-fetlock')
const picked = (await zone.locator('option:checked').textContent()) ?? ''
await expect(
page.getByRole('heading', {
level: 2,
name: dict['catalogue.zone.title'].replace('{name}', picked),
}),
).toBeVisible()
const other = await zone.locator('option').nth(2).getAttribute('value')
await zone.selectOption(other!)
const otherName =
(await zone.locator('option:checked').textContent()) ?? ''
await expect(
page.getByRole('heading', {
level: 2,
name: dict['catalogue.zone.title'].replace('{name}', otherName),
}),
).toBeVisible()
await expectAccessible(page, 'the sheet page with a zone shown')
// The earlier version, retired, opens from the version line with its mark.
await page
.getByRole('button', { name: dict['catalogue.versions.earlier_one'] })
.click()
await page
.getByRole('list', { name: dict['catalogue.versions.title'] })
.getByRole('link', {
name: new RegExp(
`^${dict['catalogue.version'].replace('{number}', '1')}\\b`,
),
})
.click()
await expect(page).toHaveURL(
new RegExp(`/app/anatomy/${listed.id}/versions/1$`),
)
await expect(heading(page, name(listed))).toBeVisible()
await expect(
page
.getByRole('main')
.locator('header')
.getByText(dict['catalogue.status.deprecated'], { exact: true }),
).toBeVisible()
await expectAccessible(page, 'a retired version')
// The archived sheet opens by its address; the draft-only sheet is refused like any other.
await openSheet(page, `/app/anatomy/${archived.id}`, name(archived))
await page.goto(`/app/anatomy/${draft.id}`)
await expect(heading(page, dict['access_denied.title'])).toBeVisible()
})
test('P1: without catalogue access, no entry and the same refusal for an existing and an unknown sheet', async ({
page,
requests,
}) => {
const tag = tagOf()
const listed = await seedOfficialSheet(namesOf(tag, 'refusé'), 'listed')
const account = await createAccount(locale, false)
requests.forbid(account.email, account.password, account.displayName, tag)
await signIn(page, account, dict)
await expect(
page.getByRole('link', { name: dict['shell.nav.anatomy'] }),
).toHaveCount(0)
await expect(
page.getByRole('link', { name: dict['shell.nav.admin'] }),
).toHaveCount(0)
const pages: string[] = []
for (const path of [
'/app/anatomy',
`/app/anatomy/${listed.id}`,
`/app/anatomy/${randomUUID()}`,
]) {
await page.goto(path)
await expect(heading(page, dict['access_denied.title'])).toBeVisible()
await expect(page.getByText(name(listed))).toHaveCount(0)
pages.push(await page.getByRole('main').innerText())
}
// Nothing tells an existing sheet from an unknown one.
expect(pages[2]).toBe(pages[1])
await expectAccessible(page, 'access denied')
await expectNoHorizontalOverflow(page, 'access denied')
function name(sheet: FixtureSheet) {
return sheet.names[locale]
}
})
})
}