Important 1: a touch press fires pointer leave between up and click; only a mouse leave (or a pointer cancel) forgets the refused field, so Annuler no longer undoes an unrelated change. Important 2: the LAN spec reads the revision before the attach, through shownRevision, which throws instead of NaN (spec stays not run). Minor 1: refocusIfHidden refocuses a still shown element the commit blurred (references search on a 1 024 px crossing). Minor 2: discardChanges keeps lastSave (reload path still drops it). Minor 3: the overview filter term lives in UiState / the read-only twin, not the card. Minor 4: categories section drops its inner h3 and the unused editor.general.categories keys. AC8: badge test. Assertions rewritten or added (R-24): - editor-tabs-general « Général no longer holds the categories editor »: queryByText of the deleted heading (now vacuous) -> queryByLabelText of the category name fields. - editor-focus-request « Annotations: selects the annotation »: findAllByText /anno-b|Sélection/ -> the properties panel holds Centre x = 20 (anno-b) and owns the focused heading. - editor-shell-layout panel walk: added after.at(-1) === 'side'. - editor-recovery title « Annuler les modifications » -> « Abandonner ». - new: touch/cancel/mouse press, references search crossing, discard keeps lastSave, filter kept, one categories heading, badge 1/2/0, shownRevision.
162 lines
6.0 KiB
TypeScript
162 lines
6.0 KiB
TypeScript
import { readFileSync } from 'node:fs'
|
|
import { fr } from '@/i18n/fr'
|
|
import type { Page } from '@playwright/test'
|
|
import { totpCode } from '../../../../packages/supabase/tests/sandbox/totp'
|
|
import { expect, test } from '../support/browser'
|
|
import { shownRevision } from '../support/saveLineText'
|
|
|
|
// Owner trial through its LAN origin (C47): sign-in, TOTP enrolment and challenge, the
|
|
// catalogue, a non-equine sheet, an SVG import, save and reload. The request guard of
|
|
// support/browser.ts fails on any request outside the origin; the listener below also
|
|
// names 127.0.0.1 and localhost. TRIAL_EMAIL and TRIAL_PW_FILE (first line, mode 600).
|
|
|
|
const dict = fr
|
|
const email = process.env.TRIAL_EMAIL ?? ''
|
|
const password =
|
|
(process.env.TRIAL_PW_FILE ?? '')
|
|
? readFileSync(process.env.TRIAL_PW_FILE ?? '', 'utf8').split('\n')[0]
|
|
: ''
|
|
|
|
const SVG =
|
|
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 300">' +
|
|
'<style>.a{fill:#c96}</style>' +
|
|
'<rect class="a" x="20" y="20" width="360" height="260"/></svg>'
|
|
|
|
const saveLine = (page: Page) => page.getByTestId('save-line')
|
|
|
|
// Read while the line says « Révision n »: a pending change shows no revision.
|
|
async function revisionShown(page: Page): Promise<number> {
|
|
return shownRevision((await saveLine(page).textContent()) ?? '')
|
|
}
|
|
|
|
async function nextCode(secret: string): Promise<string> {
|
|
const left = 30_000 - (Date.now() % 30_000)
|
|
if (left < 3000) await new Promise((r) => setTimeout(r, left + 200))
|
|
return totpCode(secret)
|
|
}
|
|
|
|
async function signIn(page: Page) {
|
|
await page.goto('/login')
|
|
await page.getByLabel(dict['auth.email']).fill(email)
|
|
await page.getByLabel(dict['auth.password'], { exact: true }).fill(password)
|
|
await page.getByRole('button', { name: dict['auth.login.submit'] }).click()
|
|
await expect(page).toHaveURL(/\/app\/?$/)
|
|
}
|
|
|
|
async function enrol(page: Page): Promise<string> {
|
|
await page.goto('/app/account')
|
|
await page.getByRole('button', { name: dict['mfa.enrol.start'] }).click()
|
|
await page.getByLabel(dict['mfa.enrol.name']).fill('Essai LAN')
|
|
await page.getByRole('button', { name: dict['mfa.enrol.continue'] }).click()
|
|
const key = page.getByText(/^[A-Z2-7]{16,}$/)
|
|
await expect(key).toBeVisible()
|
|
const secret = ((await key.textContent()) ?? '').trim()
|
|
await page.getByLabel(dict['mfa.code.label']).fill(await nextCode(secret))
|
|
await page.getByRole('button', { name: dict['mfa.code.verify'] }).click()
|
|
await expect(page.getByText(dict['mfa.enrol.done'])).toBeVisible()
|
|
return secret
|
|
}
|
|
|
|
async function challenge(page: Page, secret: string) {
|
|
await page.goto('/app/admin')
|
|
const field = page.getByRole('main').getByLabel(dict['mfa.code.label'])
|
|
await expect(field).toBeVisible()
|
|
await page.waitForLoadState('networkidle')
|
|
await field.fill(await nextCode(secret))
|
|
await page
|
|
.getByRole('main')
|
|
.getByRole('button', { name: dict['mfa.code.verify'] })
|
|
.click()
|
|
await expect(field).toBeHidden()
|
|
}
|
|
|
|
async function createNonEquineSheet(page: Page, tag: string) {
|
|
await page.goto('/app/admin/sheets')
|
|
await expect(
|
|
page.getByRole('heading', { name: dict['admin.sheets.title'] }),
|
|
).toBeVisible()
|
|
await page.getByRole('link', { name: dict['admin.sheets.new'] }).click()
|
|
const species = page.getByLabel(dict['admin.sheet_form.species'], {
|
|
exact: true,
|
|
})
|
|
const nonEquine = species.locator(
|
|
'option:not([value=""]):not([value="equine"])',
|
|
)
|
|
await expect(nonEquine.first()).toBeAttached()
|
|
await page.waitForLoadState('networkidle')
|
|
const chosen = (await nonEquine.first().getAttribute('value')) ?? ''
|
|
await species.selectOption(chosen)
|
|
await expect(species).toHaveValue(chosen)
|
|
await page
|
|
.getByLabel(dict['admin.sheet_form.name_fr'])
|
|
.fill(`Fiche LAN ${tag}`)
|
|
await page
|
|
.getByLabel(dict['admin.sheet_form.name_en'])
|
|
.fill(`LAN sheet ${tag}`)
|
|
await page
|
|
.getByRole('button', { name: dict['admin.sheet_form.submit'] })
|
|
.click()
|
|
await expect(page).toHaveURL(/\/app\/admin\/sheets\/[0-9a-f-]{36}\/draft$/)
|
|
}
|
|
|
|
/** The views section: the Annotations tab, then the overview entry (U1 moved the views). */
|
|
async function openViews(page: Page) {
|
|
await page
|
|
.getByRole('tab', { name: dict['editor.tab.annotations'], exact: true })
|
|
.click()
|
|
await page.locator('[data-section-entry="views"]').click()
|
|
}
|
|
|
|
test('trial through the LAN origin: MFA, new sheet, SVG import, save, reload', async ({
|
|
page,
|
|
}) => {
|
|
test.skip(!email || !password, 'TRIAL_EMAIL and TRIAL_PW_FILE are required') // floor-guard: allow C47 run by hand on a live trial
|
|
test.setTimeout(120_000)
|
|
const local: string[] = []
|
|
page.on('request', (request) => {
|
|
if (/\/\/(127\.0\.0\.1|localhost)/.test(request.url()))
|
|
local.push(request.url())
|
|
})
|
|
const tag = Date.now().toString(36)
|
|
await signIn(page)
|
|
const secret = await enrol(page)
|
|
// Enrolment leaves an aal2 session: a new sign-in brings the real challenge.
|
|
await page
|
|
.getByRole('button', { name: dict['shell.sign_out'] })
|
|
.first()
|
|
.click()
|
|
await expect(page).not.toHaveURL(/\/app/)
|
|
await signIn(page)
|
|
await challenge(page, secret)
|
|
await createNonEquineSheet(page, tag)
|
|
await openViews(page)
|
|
await expect(saveLine(page)).toHaveText(/^Révision \d+$/)
|
|
const before = await revisionShown(page)
|
|
await page
|
|
.locator('[data-testid$="-file"]')
|
|
.first()
|
|
.setInputFiles({
|
|
name: 'lan.svg',
|
|
mimeType: 'image/svg+xml',
|
|
buffer: Buffer.from(SVG),
|
|
})
|
|
const dialog = page.getByRole('dialog', {
|
|
name: dict['editor.cleaning.title'],
|
|
})
|
|
await expect(dialog).toBeVisible()
|
|
await dialog
|
|
.getByRole('button', { name: dict['editor.cleaning.confirm'] })
|
|
.click()
|
|
await expect(page.getByText(dict['editor.upload.done'])).toBeVisible()
|
|
await page.getByRole('button', { name: dict['common.save'] }).click()
|
|
await expect(saveLine(page)).toHaveText(
|
|
new RegExp(`^Enregistré( à \\d\\d:\\d\\d)? · révision ${before + 1}$`),
|
|
)
|
|
await page.reload()
|
|
await openViews(page)
|
|
await expect(
|
|
page.getByRole('tabpanel').getByText(dict['editor.views.drawing.ok']),
|
|
).toBeVisible()
|
|
expect(local, 'requests to 127.0.0.1 or localhost').toEqual([])
|
|
})
|