test(app): shell proof of the sheet list search, sort and dates
admin-sheets-list.spec.ts (sandbox, fr and en, desktop and 375 px): three
draft sheets of this run, the oldest saved last; search, count line against
the list answer of the same load, order by last modification then by name,
the Paris date format, a search cut at 100 characters and its clearing, axe
and no sideways scroll on the searched list, the empty state and
/app/admin; the home's latest changes. Teardown soft-deletes only the ids
this run created (D7).
allSheetsLink (e2e/support/admin.ts): the sheets card link named
admin.home.all_sheets or admin.home.see_all with any number.
R-24, locators rewritten (assertions unchanged):
- admin.spec.ts A1: areaCard(...).getByRole('link', { name:
dict['admin.home.all_sheets'] }) -> allSheetsLink(areaCard(...), dict)
- admin.spec.ts access per right: sheets.getByRole('link', { name:
dict['admin.home.all_sheets'] }) -> allSheetsLink(sheets, dict)
- editor-journey.spec.ts createSheetFromAdmin: section locator
.getByRole('link', { name: dict['admin.home.all_sheets'] }) ->
allSheetsLink(section locator, dict)
This commit is contained in:
1 parent
2326e1cb15
commit
b4a5254068
4 files changed
+353
-11
No files matched your search
@@ -0,0 +1,328 @@
|
||||
import { randomUUID } from 'node:crypto'
|
||||
import { en } from '@/i18n/en'
|
||||
import { fr } from '@/i18n/fr'
|
||||
import type { Dict } from '@/i18n/types'
|
||||
import type { Page, Response } from '@playwright/test'
|
||||
import { rpc, sql } from '../../../../packages/supabase/tests/sandbox/stack'
|
||||
import { allSheetsLink, stepUpAdmin } from '../support/admin'
|
||||
import {
|
||||
expect,
|
||||
expectAccessible,
|
||||
expectNoHorizontalOverflow,
|
||||
test,
|
||||
} from '../support/browser'
|
||||
import { seedOfficialSheet, type SheetNames } from '../support/catalogue'
|
||||
import { editorActor, serverDocument, type Actor } from '../support/editor'
|
||||
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
|
||||
import { signIn } from '../support/shell'
|
||||
|
||||
// V1-2.6 R3 on the isolated stack: the official sheet list searched by name,
|
||||
// sorted by last modification or name, counted, dated in Paris time, and the
|
||||
// Administration home's five latest sheets. Three draft sheets of this run, the
|
||||
// oldest saved last: only the true last modification (M9) puts it first. FR and
|
||||
// EN, desktop and 375 px; one editor per project. Never opens /app/admin/access
|
||||
// (BLK-015). D7: the teardown soft-deletes the ids this run created, one by one.
|
||||
|
||||
const LANGUAGES = [
|
||||
['fr', fr],
|
||||
['en', en],
|
||||
] as const
|
||||
|
||||
type Locale = (typeof LANGUAGES)[number][0]
|
||||
|
||||
/** The three sheets' names, seeded in this order (fr and en sort alike). */
|
||||
const WORDS = [
|
||||
{ fr: 'Alpha', en: 'Alpha' },
|
||||
{ fr: 'Émeu', en: 'Emu' },
|
||||
{ fr: 'Zèbre', en: 'Zebra' },
|
||||
] as const
|
||||
|
||||
const SHORT_MONTHS: Record<Locale, string> = {
|
||||
fr: 'janv\\.|févr\\.|mars|avr\\.|mai|juin|juil\\.|août|sept\\.|oct\\.|nov\\.|déc\\.',
|
||||
en: 'Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sept?|Oct|Nov|Dec',
|
||||
}
|
||||
|
||||
interface Fixtures {
|
||||
actor: Actor
|
||||
token: string
|
||||
/** Alpha, Émeu, Zèbre: ids and names, in seeding order. */
|
||||
sheets: { id: string; names: SheetNames }[]
|
||||
}
|
||||
|
||||
const main = (page: Page) => page.getByRole('main')
|
||||
const heading = (page: Page, name: string) =>
|
||||
main(page).getByRole('heading', { level: 1, name })
|
||||
const searchField = (page: Page, dict: Dict) =>
|
||||
page.getByRole('searchbox', { name: dict['admin.sheets.search'] })
|
||||
const countLine = (page: Page) => main(page).locator('p[aria-live="polite"]')
|
||||
const rows = (page: Page, dict: Dict) =>
|
||||
page
|
||||
.getByRole('list', { name: dict['admin.sheets.results_label'] })
|
||||
.getByRole('listitem')
|
||||
const sheetsCard = (page: Page) =>
|
||||
page.locator('section[aria-labelledby="admin-sheets-title"]')
|
||||
|
||||
/** « Modifiée le 9 nov. 2026, 12:06 » / « Modified on 9 Nov 2026, 12:06 » (A8). */
|
||||
function ratifiedDate(dict: Dict, locale: Locale): RegExp {
|
||||
const date = `\\d{1,2} (${SHORT_MONTHS[locale]}) \\d{4}, \\d{2}:\\d{2}`
|
||||
const [before, after] = dict['admin.sheets.modified'].split('{date}')
|
||||
return new RegExp(`^${before}${date}${after}$`)
|
||||
}
|
||||
|
||||
/** The hour and minute of `iso` on a Paris clock, as the row must show them. */
|
||||
const parisClock = (iso: string) =>
|
||||
new Intl.DateTimeFormat('en-GB', {
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
hourCycle: 'h23',
|
||||
timeZone: 'Europe/Paris',
|
||||
}).format(new Date(iso))
|
||||
|
||||
/** The admin list answer of the next load of the page. */
|
||||
const listAnswer = (page: Page): Promise<Response> =>
|
||||
page.waitForResponse((response) =>
|
||||
response.url().includes('/rest/v1/rpc/list_official_sheets_admin'),
|
||||
)
|
||||
|
||||
/** Seeds the three sheets, each id kept for the teardown as soon as it exists. */
|
||||
async function seedSheets(token: string, created: string[]) {
|
||||
const sheets: Fixtures['sheets'] = []
|
||||
for (const word of WORDS) {
|
||||
const names = { fr: `R3 ${token} ${word.fr}`, en: `R3 ${token} ${word.en}` }
|
||||
const sheet = await seedOfficialSheet(names, 'draft')
|
||||
created.push(sheet.id)
|
||||
sheets.push(sheet)
|
||||
}
|
||||
return sheets
|
||||
}
|
||||
|
||||
/** One more save of Alpha's draft by the editor: its versions move, its sheet row does not. */
|
||||
async function saveAlpha(actor: Actor, sheetId: string, token: string) {
|
||||
const draftId = await sql(
|
||||
`select id from public.anatomical_sheet_versions
|
||||
where sheet_id = '${sheetId}' and status = 'draft'`,
|
||||
)
|
||||
const revision = Number(
|
||||
await sql(
|
||||
`select revision from public.anatomical_sheet_versions where id = '${draftId}'`,
|
||||
),
|
||||
)
|
||||
const document = await serverDocument(draftId)
|
||||
document.description = { fr: `R3 ${token}`, en: `R3 ${token}` }
|
||||
const args = { version_id: draftId, expected_revision: revision, document }
|
||||
const saved = await rpc('save_sheet_draft', args, actor.aal2)
|
||||
if (saved.status !== 200)
|
||||
throw new Error(`fixture save: HTTP ${saved.status}`)
|
||||
}
|
||||
|
||||
/** D7: soft-deletes each id of this run on its own; every failure is reported at the end. */
|
||||
async function deleteCreated(actor: Actor, created: string[]) {
|
||||
const failures: string[] = []
|
||||
for (const id of created) {
|
||||
try {
|
||||
const answer = await rpc(
|
||||
'delete_anatomical_sheet',
|
||||
{ sheet_id: id },
|
||||
actor.aal2,
|
||||
)
|
||||
if (answer.status !== 200 || JSON.parse(answer.text) !== id)
|
||||
failures.push(`${id}: HTTP ${answer.status}`)
|
||||
} catch (error) {
|
||||
failures.push(`${id}: ${String(error)}`)
|
||||
}
|
||||
}
|
||||
expect(failures, 'sheets of this run soft-deleted').toEqual([])
|
||||
}
|
||||
|
||||
/** The editor, its profile in `locale` (its own preference, set earlier), at aal2 on /app/admin. */
|
||||
async function openAdmin(page: Page, dict: Dict, locale: Locale, actor: Actor) {
|
||||
await sql(
|
||||
`update public.profiles set locale = '${locale}' where id = '${actor.account.id}'`,
|
||||
)
|
||||
await signIn(page, actor.account, dict)
|
||||
await page.goto('/app/admin')
|
||||
await stepUpAdmin(page, dict, actor.secret)
|
||||
await expect(heading(page, dict['shell.nav.admin'])).toBeVisible()
|
||||
}
|
||||
|
||||
/**
|
||||
* Check 5: the latest changes, newest first, at most five; the footer link opens
|
||||
* the list. Resolves with the list's server answer of that load.
|
||||
*/
|
||||
async function checkHome(page: Page, dict: Dict) {
|
||||
const card = sheetsCard(page)
|
||||
await expect(
|
||||
card.getByRole('heading', { name: dict['admin.home.latest'] }),
|
||||
).toBeVisible()
|
||||
const items = card.getByRole('list').getByRole('listitem')
|
||||
await expect(items.first()).toBeVisible()
|
||||
expect(await items.count()).toBeLessThanOrEqual(5)
|
||||
const times = (
|
||||
await card
|
||||
.locator('time')
|
||||
.evaluateAll((nodes) =>
|
||||
nodes.map((node) => node.getAttribute('datetime') ?? ''),
|
||||
)
|
||||
).map((iso) => Date.parse(iso))
|
||||
for (let i = 1; i < times.length; i += 1)
|
||||
expect(
|
||||
times[i],
|
||||
`home item ${i} not newer than the one above`,
|
||||
).toBeLessThanOrEqual(times[i - 1]!)
|
||||
await expectAccessible(page, 'the Administration home')
|
||||
await expectNoHorizontalOverflow(page, 'the Administration home')
|
||||
const link = allSheetsLink(card, dict)
|
||||
await expect(link).toHaveText(/\d/)
|
||||
const answer = listAnswer(page)
|
||||
await link.click()
|
||||
await expect(heading(page, dict['admin.sheets.title'])).toBeVisible()
|
||||
return (await (await answer).json()) as {
|
||||
sheet_id: string
|
||||
last_modified_at: string
|
||||
}[]
|
||||
}
|
||||
|
||||
/** The rows, in order, are these sheets: link, name, and the server's date shown in Paris time. */
|
||||
async function expectRows(
|
||||
page: Page,
|
||||
dict: Dict,
|
||||
locale: Locale,
|
||||
expected: { id: string; name: string; modified: string }[],
|
||||
) {
|
||||
const list = rows(page, dict)
|
||||
await expect(list).toHaveCount(expected.length)
|
||||
for (const [i, sheet] of expected.entries()) {
|
||||
const row = list.nth(i)
|
||||
await expect(row.getByRole('link')).toHaveAttribute(
|
||||
'href',
|
||||
`/app/admin/sheets/${sheet.id}`,
|
||||
)
|
||||
await expect(row).toContainText(sheet.name)
|
||||
const time = row.locator('time')
|
||||
await expect(time).toHaveText(ratifiedDate(dict, locale))
|
||||
await expect(time).toContainText(parisClock(sheet.modified))
|
||||
await expect(time).toHaveAttribute(
|
||||
'datetime',
|
||||
new Date(sheet.modified).toISOString(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** The count line's sentence, in the plural form `locale` gives `shown` (fr: 0 is singular). */
|
||||
function countText(
|
||||
dict: Dict,
|
||||
locale: Locale,
|
||||
key: 'count' | 'count_of',
|
||||
shown: number,
|
||||
total: number,
|
||||
): string {
|
||||
const form =
|
||||
new Intl.PluralRules(locale).select(shown) === 'one' ? 'one' : 'other'
|
||||
return dict[`admin.sheets.${key}_${form}`]
|
||||
.replace('{count}', String(shown))
|
||||
.replace('{total}', String(total))
|
||||
}
|
||||
|
||||
/** Check 3: a search longer than the field, cut at 100; the no-result sentence, then cleared. */
|
||||
async function checkLongSearch(
|
||||
page: Page,
|
||||
dict: Dict,
|
||||
locale: Locale,
|
||||
token: string,
|
||||
total: number,
|
||||
) {
|
||||
const field = searchField(page, dict)
|
||||
const typed = `${token}${'x'.repeat(100)}`.slice(0, 100)
|
||||
await field.fill(`${token}${'x'.repeat(100)}`)
|
||||
await expect(field).toHaveValue(typed)
|
||||
await expect(
|
||||
main(page).getByText(dict['admin.sheets.no_result'].replace('{q}', typed), {
|
||||
exact: true,
|
||||
}),
|
||||
).toBeVisible()
|
||||
await expect(countLine(page)).toHaveText(
|
||||
countText(dict, locale, 'count_of', 0, total),
|
||||
)
|
||||
await expectNoHorizontalOverflow(page, 'the empty search')
|
||||
await expectAccessible(page, 'the empty search')
|
||||
const clear = dict['admin.sheets.clear_search']
|
||||
await main(page)
|
||||
.getByRole('button', { name: clear, exact: true })
|
||||
.filter({ hasText: clear })
|
||||
.click()
|
||||
await expect(field).toHaveValue('')
|
||||
await expect(field).toBeFocused()
|
||||
await expect(countLine(page)).toHaveText(
|
||||
countText(dict, locale, 'count', total, total),
|
||||
)
|
||||
}
|
||||
|
||||
test.describe.configure({ mode: 'serial' })
|
||||
|
||||
test.describe('official sheet list: search, sort and dates (R3)', () => {
|
||||
const created: string[] = []
|
||||
let editor: Actor | null = null
|
||||
let fixtures: Fixtures | null = null
|
||||
|
||||
test.beforeAll(async () => {
|
||||
test.setTimeout(120_000)
|
||||
editor = await editorActor('fr')
|
||||
const actor = editor
|
||||
const token = randomUUID().slice(0, 8)
|
||||
const sheets = await seedSheets(token, created)
|
||||
await saveAlpha(actor, sheets[0]!.id, token)
|
||||
fixtures = { actor, token, sheets }
|
||||
})
|
||||
|
||||
test.afterAll(async () => {
|
||||
if (editor) await deleteCreated(editor, created)
|
||||
})
|
||||
|
||||
for (const [locale, dict] of LANGUAGES) {
|
||||
test.describe(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('the home lists the latest changes; the list searches, sorts, counts and dates', async ({
|
||||
page,
|
||||
requests,
|
||||
}) => {
|
||||
test.setTimeout(240_000)
|
||||
const { actor, token, sheets } = fixtures!
|
||||
const { email, password, displayName } = actor.account
|
||||
requests.forbid(email, password, displayName, token)
|
||||
await openAdmin(page, dict, locale, actor)
|
||||
const answer = await checkHome(page, dict)
|
||||
const total = answer.length
|
||||
const modified = (id: string) =>
|
||||
answer.find((sheet) => sheet.sheet_id === id)?.last_modified_at ?? ''
|
||||
const shown = (index: number) => ({
|
||||
id: sheets[index]!.id,
|
||||
name: sheets[index]!.names[locale],
|
||||
modified: modified(sheets[index]!.id),
|
||||
})
|
||||
|
||||
// 1. The token finds the three sheets, newest modification first: Alpha, Zèbre, Émeu.
|
||||
await searchField(page, dict).fill(token)
|
||||
await expect(countLine(page)).toHaveText(
|
||||
countText(dict, locale, 'count_of', 3, total),
|
||||
)
|
||||
await expectRows(page, dict, locale, [shown(0), shown(2), shown(1)])
|
||||
await expectAccessible(page, 'the searched list')
|
||||
await expectNoHorizontalOverflow(page, 'the searched list')
|
||||
|
||||
// 2. « Nom »: Alpha, Émeu, Zèbre.
|
||||
await page.getByLabel(dict['admin.sheets.sort_by']).selectOption('name')
|
||||
await expectRows(page, dict, locale, [shown(0), shown(1), shown(2)])
|
||||
|
||||
// 3. A search past the field's limit, its sentence, then « Effacer la recherche ».
|
||||
await checkLongSearch(page, dict, locale, token, total)
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
test,
|
||||
} from '../support/browser'
|
||||
import {
|
||||
allSheetsLink,
|
||||
assignRole,
|
||||
enrolVerifiedFactor,
|
||||
enterCode,
|
||||
@@ -457,9 +458,7 @@ for (const [locale, dict] of LANGUAGES) {
|
||||
requests.forbid(account.email, account.password, account.displayName)
|
||||
await openAdmin(page, dict, info, account, secret)
|
||||
|
||||
await areaCard(page, 'admin-sheets-title')
|
||||
.getByRole('link', { name: dict['admin.home.all_sheets'] })
|
||||
.click()
|
||||
await allSheetsLink(areaCard(page, 'admin-sheets-title'), dict).click()
|
||||
await expect(heading(page, dict['admin.sheets.title'])).toBeVisible()
|
||||
await main(page)
|
||||
.getByRole('link', { name: dict['admin.sheets.new'] })
|
||||
@@ -668,9 +667,7 @@ for (const [locale, dict] of LANGUAGES) {
|
||||
page.getByRole('button', { name: dict['admin.working_copy.create'] }),
|
||||
).toHaveCount(0)
|
||||
await expect(areaCard(page, 'admin-access-title')).toHaveCount(0)
|
||||
await sheets
|
||||
.getByRole('link', { name: dict['admin.home.all_sheets'] })
|
||||
.click()
|
||||
await allSheetsLink(sheets, dict).click()
|
||||
await expect(heading(page, dict['admin.sheets.title'])).toBeVisible()
|
||||
await expect(
|
||||
page.getByRole('link', { name: dict['admin.sheets.new'] }),
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { fr } from '@/i18n/fr'
|
||||
import type { Locator, Page, TestInfo } from '@playwright/test'
|
||||
import { sql } from '../../../../packages/supabase/tests/sandbox/stack'
|
||||
import { stepUpAdmin } from '../support/admin'
|
||||
import { allSheetsLink, stepUpAdmin } from '../support/admin'
|
||||
import { expect, expectAccessible, test } from '../support/browser'
|
||||
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
|
||||
import {
|
||||
@@ -56,10 +56,10 @@ const clickButton = (page: Page, name: string) =>
|
||||
page.getByRole('button', { name, exact: true }).click()
|
||||
|
||||
async function createSheetFromAdmin(page: Page, tag: string): Promise<string> {
|
||||
await page
|
||||
.locator('section[aria-labelledby="admin-sheets-title"]')
|
||||
.getByRole('link', { name: dict['admin.home.all_sheets'] })
|
||||
.click()
|
||||
await allSheetsLink(
|
||||
page.locator('section[aria-labelledby="admin-sheets-title"]'),
|
||||
dict,
|
||||
).click()
|
||||
await main(page).getByRole('link', { name: dict['admin.sheets.new'] }).click()
|
||||
// The list page has a species filter with the same label: wait for the form's heading.
|
||||
await expect(
|
||||
|
||||
@@ -173,3 +173,20 @@ export async function stepUpAdmin(page: Page, dict: Dict, secret: string) {
|
||||
}
|
||||
await expect(stepUpHeading(page, dict)).toBeHidden()
|
||||
}
|
||||
|
||||
const escaped = (text: string) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
||||
|
||||
/**
|
||||
* The link of the sheets card to the full list: « Toutes les fiches officielles »
|
||||
* for zero or one sheet, « Voir les {count} fiches » from two (R3, D6), any number.
|
||||
*/
|
||||
export function allSheetsLink(scope: Page | Locator, dict: Dict): Locator {
|
||||
const seeAll = escaped(dict['admin.home.see_all']).replace(
|
||||
'\\{count\\}',
|
||||
'\\d+',
|
||||
)
|
||||
const name = new RegExp(
|
||||
`^(${escaped(dict['admin.home.all_sheets'])}|${seeAll})$`,
|
||||
)
|
||||
return scope.getByRole('link', { name })
|
||||
}
|
||||
Reference in new issue
Block a user