test(app): sheet list spec binds its SQL values, pins UTC, checks Escape
- the three fixture statements pass every value through literal(); the
sheet, draft and actor ids are refused unless they have the uuid shape
- test.use({ timezoneId: 'UTC' }): a row still in Paris time proves the
page sets the zone itself, whatever the host's
- the home ordering loop first asserts one <time> per item
- ratifiedDate escapes the dictionary text (escaped, now exported by
support/admin.ts)
- the long-search check types the text again and presses Escape: field
empty and focused, count back (Chromium's native type=search included)
R-24: no assertion removed or rewritten. Added: 'one date per home item'
(toHaveLength) before the unchanged ordering loop; the Escape block after
the unchanged button block. ratifiedDate builds the same pattern for the
current dictionaries (no RegExp character in them).
Run: admin-sheets-list 4 passed (fr, en x desktop, 375).
This commit is contained in:
1 parent
8bb2486a34
commit
ea5512af02
2 files changed
+36
-7
No files matched your search
@@ -4,7 +4,7 @@ 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 { allSheetsLink, escaped, stepUpAdmin } from '../support/admin'
|
||||
import {
|
||||
expect,
|
||||
expectAccessible,
|
||||
@@ -13,6 +13,7 @@ import {
|
||||
} from '../support/browser'
|
||||
import { seedOfficialSheet, type SheetNames } from '../support/catalogue'
|
||||
import { editorActor, serverDocument, type Actor } from '../support/editor'
|
||||
import { literal } from '../support/records'
|
||||
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
|
||||
import { signIn } from '../support/shell'
|
||||
|
||||
@@ -49,6 +50,14 @@ interface Fixtures {
|
||||
sheets: { id: string; names: SheetNames }[]
|
||||
}
|
||||
|
||||
const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/
|
||||
|
||||
/** An id as an SQL literal, refused unless it has the uuid shape. */
|
||||
function uuidLiteral(id: string): string {
|
||||
if (!UUID.test(id)) throw new Error('fixture: an id without the uuid shape')
|
||||
return literal(id)
|
||||
}
|
||||
|
||||
const main = (page: Page) => page.getByRole('main')
|
||||
const heading = (page: Page, name: string) =>
|
||||
main(page).getByRole('heading', { level: 1, name })
|
||||
@@ -66,7 +75,7 @@ const sheetsCard = (page: Page) =>
|
||||
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}$`)
|
||||
return new RegExp(`^${escaped(before!)}${date}${escaped(after!)}$`)
|
||||
}
|
||||
|
||||
/** The hour and minute of `iso` on a Paris clock, as the row must show them. */
|
||||
@@ -100,11 +109,12 @@ async function seedSheets(token: string, created: string[]) {
|
||||
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'`,
|
||||
where sheet_id = ${uuidLiteral(sheetId)} and status = 'draft'`,
|
||||
)
|
||||
const revision = Number(
|
||||
await sql(
|
||||
`select revision from public.anatomical_sheet_versions where id = '${draftId}'`,
|
||||
`select revision from public.anatomical_sheet_versions
|
||||
where id = ${uuidLiteral(draftId)}`,
|
||||
),
|
||||
)
|
||||
const document = await serverDocument(draftId)
|
||||
@@ -137,7 +147,8 @@ async function deleteCreated(actor: Actor, created: string[]) {
|
||||
/** 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}'`,
|
||||
`update public.profiles set locale = ${literal(locale)}
|
||||
where id = ${uuidLiteral(actor.account.id)}`,
|
||||
)
|
||||
await signIn(page, actor.account, dict)
|
||||
await page.goto('/app/admin')
|
||||
@@ -164,6 +175,7 @@ async function checkHome(page: Page, dict: Dict) {
|
||||
nodes.map((node) => node.getAttribute('datetime') ?? ''),
|
||||
)
|
||||
).map((iso) => Date.parse(iso))
|
||||
expect(times, 'one date per home item').toHaveLength(await items.count())
|
||||
for (let i = 1; i < times.length; i += 1)
|
||||
expect(
|
||||
times[i],
|
||||
@@ -223,7 +235,10 @@ function countText(
|
||||
.replace('{total}', String(total))
|
||||
}
|
||||
|
||||
/** Check 3: a search longer than the field, cut at 100; the no-result sentence, then cleared. */
|
||||
/**
|
||||
* Check 3: a search longer than the field, cut at 100; the no-result sentence, then
|
||||
* cleared by its button; typed again, then cleared by Escape.
|
||||
*/
|
||||
async function checkLongSearch(
|
||||
page: Page,
|
||||
dict: Dict,
|
||||
@@ -255,11 +270,24 @@ async function checkLongSearch(
|
||||
await expect(countLine(page)).toHaveText(
|
||||
countText(dict, locale, 'count', total, total),
|
||||
)
|
||||
// Escape in a field that holds text clears it, keeps the focus, brings the count back.
|
||||
await field.fill(typed)
|
||||
await expect(countLine(page)).toHaveText(
|
||||
countText(dict, locale, 'count_of', 0, total),
|
||||
)
|
||||
await field.press('Escape')
|
||||
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)', () => {
|
||||
// A browser clock in UTC: a row still in Paris time proves the zone is the page's own.
|
||||
test.use({ timezoneId: 'UTC' })
|
||||
const created: string[] = []
|
||||
let editor: Actor | null = null
|
||||
let fixtures: Fixtures | null = null
|
||||
|
||||
@@ -174,7 +174,8 @@ export async function stepUpAdmin(page: Page, dict: Dict, secret: string) {
|
||||
await expect(stepUpHeading(page, dict)).toBeHidden()
|
||||
}
|
||||
|
||||
const escaped = (text: string) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
||||
/** A text matched literally inside a RegExp. */
|
||||
export const escaped = (text: string) => text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')
|
||||
|
||||
/**
|
||||
* The link of the sheets card to the full list: « Toutes les fiches officielles »
|
||||
|
||||
Reference in new issue
Block a user