Files
faunosteo/apps/app/e2e/lan/trial-lan.spec.ts
T
bchanot 99b669bf8f feat(editor): header history, save line and Abandonner les modifications
Header Annuler/Retablir on every tab (aria-disabled, commit on pointerdown,
refused blur commit skips the undo). Save line: unsaved count selector
(savedDistance), saveLineState forms, server save time via readSaveTime
(lastSave in the store, never the browser clock). Discard relabelled and
names the stored copy. Tool column pair removed, glyphs in EditorGlyph.

Rewritten or removed assertions (R-24):
- editor-route.test: Revision 3 / unsaved text / Annuler les modifications
  -> save-line testid, Abandonner label, copy sentence in the dialog
- editor-route-conflict, editor-route-recovery: Revision n and copy_cap/
  copy_quota text queries -> save-line testid
- editor-no-loss: discard button label
- editor-annotations-tab: tool column undo/redo test -> no pair left
  (behaviour moved to editor-history-buttons.test)
- e2e journey/annotations/recovery/structures/support saveDraft/lan:
  undo/redo and revision/unsaved text -> historyButton, saveLine helpers;
  structures toHaveCount(0) on old text -> exact Revision n line
- editor-shell clickability: header Annuler/Retablir added
2026-11-08 17:55:49 +01:00

162 lines
5.9 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'
// 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')
async function revisionShown(page: Page): Promise<number> {
const text = (await saveLine(page).textContent()) ?? ''
return Number(
/révision (\d+)|Révision (\d+)/.exec(text)?.slice(1).find(Boolean),
)
}
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 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()
const before = await revisionShown(page)
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([])
})