test(editor): lot K review fixes, filled-document save proof

This commit is contained in:
bchanot committed 2026-11-04 15:52:15 +01:00
1 parent bb99edd2dd
commit 4cc27a8231
10 files changed
+132 -32

No files matched your search

@@ -79,9 +79,7 @@ test.describe('editor annotations (A3)', () => {
page,
requests,
}) => {
const { actor, seed } = await openAnnotations(page).then((opened) => {
return opened
})
const { actor, seed } = await openAnnotations(page)
requests.forbid(actor.account.email, actor.account.password)
// A point: the tool, a click in the drawing, the fields the core requires.
@@ -269,7 +267,7 @@ test.describe('editor annotations (A3)', () => {
page,
requests,
}) => {
const { actor, seed } = await openAnnotations(page)
const { actor } = await openAnnotations(page)
requests.forbid(actor.account.email, actor.account.password)
await tool(page, 'point').click()
await clickDrawing(page, 500, 400)
@@ -297,6 +295,5 @@ test.describe('editor annotations (A3)', () => {
).toBeVisible()
await selectTab(page, dict, 'verification')
await expectAccessible(page, 'the verification tab after a deletion')
expect(seed.draftId).toBeTruthy()
})
})
+2 -2
View File
@@ -166,9 +166,9 @@ test.describe('editor drawings (A2)', () => {
.getByRole('group', { name: dict['editor.annotations.views'] })
.getByRole('button', { name: 'Détail A' })
.click()
// The view shows the crop of the parent drawing, not the whole drawing.
await expect(
page.getByTestId('annotation-canvas-drawing').locator('svg').first(),
).toBeVisible()
await expect(page.getByTestId('annotation-overlay')).toBeAttached()
).toHaveAttribute('viewBox', '100 100 300 240')
})
})
+5 -4
View File
@@ -1,7 +1,7 @@
import { readFile } from 'node:fs/promises'
import { join } from 'node:path'
import { fr } from '@/i18n/fr'
import type { Locator, Page, TestInfo } from '@playwright/test'
import type { Locator, Page } from '@playwright/test'
import {
rpc,
sql,
@@ -34,7 +34,6 @@ const REPO = join(__dirname, '../../../..')
const BUDGET_MS = 500
const SAMPLES = 15
const isPhone = (info: TestInfo) => info.project.name === 'chromium-375'
interface Sample {
handler: number
@@ -211,6 +210,9 @@ test.describe.configure({ mode: 'serial' })
test.describe('equine working copy and commit latency', () => {
test.use({ locale: 'fr-FR', actionTimeout: 30_000 })
// Skipped as a whole on the phone project: beforeAll and afterAll toggle the copies'
// status and must run in one worker only.
test.skip(({ isMobile }) => isMobile, 'editing needs 1 024 px')
let actor: Actor
let setAside: string[] = []
let copyId = ''
@@ -237,8 +239,7 @@ test.describe('equine working copy and commit latency', () => {
where id in (${setAside.map((id) => `'${id}'`).join(', ')})`)
})
test.beforeEach(async ({ context }, info) => {
test.skip(isPhone(info), 'editing needs 1 024 px')
test.beforeEach(async ({ context }) => {
await routeToSandbox(context)
})
test.afterEach(async ({ context }) => {
+4 -4
View File
@@ -265,18 +265,18 @@ test.describe('editor touch path (real browser)', () => {
const box = page.getByTestId('annotation-canvas')
const touchAction = () =>
box.evaluate((el) => getComputedStyle(el).touchAction)
expect(await touchAction()).toBe('pan-x pan-y')
await expect.poll(touchAction).toBe('pan-x pan-y')
await tool(page, 'point').click()
expect(await touchAction()).toBe('none')
await expect.poll(touchAction).toBe('none')
await tool(page, 'select').click()
expect(await touchAction()).toBe('pan-x pan-y')
await expect.poll(touchAction).toBe('pan-x pan-y')
// A movable selection needs the touch itself: the browser reads touch-action at
// touchstart, so a drag of the selected marker must not be left to the pan.
await list(page)
.getByRole('button', { name: /Tactile/ })
.click()
expect(await touchAction()).toBe('none')
await expect.poll(touchAction).toBe('none')
const cx = geometryField(page, dict, 'cx')
await expect(cx).toHaveValue('500')
const from = await clientOf(page, 500, 400)
+9 -4
View File
@@ -49,16 +49,21 @@ async function createSheetFromAdmin(page: Page, tag: string): Promise<string> {
.getByRole('link', { name: dict['admin.home.all_sheets'] })
.click()
await main(page).getByRole('link', { name: dict['admin.sheets.new'] }).click()
await page.getByLabel(dict['admin.sheet_form.name_fr']).fill(`Chien ${tag}`)
await page.getByLabel(dict['admin.sheet_form.name_en']).fill(`Dog ${tag}`)
// The form is briefly replaced while the page re-reads the account's rights: a
// choice made in that instant is lost, so the species is chosen last.
// The list page has a species filter with the same label: wait for the form's heading.
await expect(
main(page).getByRole('heading', {
level: 1,
name: dict['admin.sheets.new'],
}),
).toBeVisible()
const species = page.getByLabel(dict['admin.sheet_form.species'], {
exact: true,
})
await expect(species.locator('option[value="canine"]')).toHaveCount(1)
await species.selectOption('canine')
await expect(species).toHaveValue('canine')
await page.getByLabel(dict['admin.sheet_form.name_fr']).fill(`Chien ${tag}`)
await page.getByLabel(dict['admin.sheet_form.name_en']).fill(`Dog ${tag}`)
await page
.getByRole('button', { name: dict['admin.sheet_form.submit'] })
.click()
+11 -2
View File
@@ -290,9 +290,18 @@ test.describe('editor recovery and concurrency', () => {
).toBeVisible()
await page.keyboard.press('Escape')
await expect(reading).toBeHidden()
// The late answer of the dismissed read arrives, then is dropped: no dialog returns.
const answered = page.waitForResponse((r) =>
r.url().includes('get_official_sheet_admin'),
)
release()
// The late answer of the dismissed read is dropped: no dialog comes back.
await page.waitForTimeout(500)
await answered
await page.evaluate(
() =>
new Promise((done) =>
requestAnimationFrame(() => requestAnimationFrame(done)),
),
)
await expect(
page.getByRole('dialog', { name: /enregistré la révision/ }),
).toHaveCount(0)
@@ -3,6 +3,7 @@ import type { Locator, Page, TestInfo } from '@playwright/test'
import { expect, expectAccessible, test } from '../support/browser'
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
import {
bareShape,
editorActor,
openEditor,
pointOf,
@@ -10,6 +11,7 @@ import {
seedDraft,
selectTab,
serverDocument,
serverRevision,
shapeWith,
} from '../support/editor'
@@ -21,6 +23,8 @@ const dict = fr
const isPhone = (info: TestInfo) => info.project.name === 'chromium-375'
const dialog = (page: Page) => page.getByRole('dialog')
const button = (page: Page, name: string) =>
page.getByRole('button', { name, exact: true })
async function open(page: Page, ...annotations: unknown[]) {
const actor = await editorActor('fr')
@@ -198,6 +202,37 @@ test.describe('editor structures (A4)', () => {
])
})
test('a draft stored with bare nodes loads filled: rename, save, reload clean', async ({
page,
requests,
}) => {
const actor = await editorActor('fr')
requests.forbid(actor.account.email, actor.account.password)
const seed = await seedDraft(actor, { shape: bareShape })
await openEditor(page, dict, actor, seed.sheetId)
await selectTab(page, dict, 'findings')
const items = page.getByTestId('finding-item')
await items.filter({ hasText: 'Catégorie nue' }).click()
await commitText(page.locator('#finding-name-fr'), 'Catégorie renommée')
await saveDraft(page, dict, seed.revision + 1)
const saved = await serverDocument<{
finding_zones: { categories: { reference_ids: string[] }[] }[]
}>(seed.draftId)
expect(saved.finding_zones[0].categories[0].reference_ids).toEqual([])
expect(await serverRevision(seed.draftId)).toBe(seed.revision + 1)
await page.reload()
await selectTab(page, dict, 'findings')
await expect(items.filter({ hasText: 'Catégorie renommée' })).toBeVisible()
await expect(
page.getByText(dict['editor.draft.status.unsaved'], { exact: false }),
).toHaveCount(0)
await expect(
button(page, dict['editor.draft.recovery.restore']),
).toHaveCount(0)
})
test('delete with dependents: refused with the list; without, descendants named', async ({
page,
requests,
+21 -3
View File
@@ -227,9 +227,8 @@ export async function seedDraft(
}
/**
* The categories, zone and detail view most editor specs start from. Every defaulted
* field is written out, as the core writes a document: the page reads the stored text
* as it is (an omitted `reference_ids` breaks the findings tree, see the report).
* The categories, zone and detail view most editor specs start from, written in full.
* `bareShape` below omits the defaulted fields (the loader fills them from the core).
*/
export function standardShape(document: Record<string, unknown>) {
document.categories = [
@@ -272,6 +271,25 @@ export function standardShape(document: Record<string, unknown>) {
})
}
/** Like `standardShape`, but nodes and categories omit what the core defaults. */
export function bareShape(document: Record<string, unknown>) {
standardShape(document)
document.finding_zones = [
{
id: 'zone-bare',
name: text('Zone nue'),
categories: [
{
id: 'fcat-bare',
kind: 'dysfunction',
name: text('Catégorie nue'),
children: [{ id: 'node-bare', name: text('Constat nu') }],
},
],
},
]
}
export const draftPath = (sheetId: string) =>
`/app/admin/sheets/${sheetId}/draft`
+8 -5
View File
@@ -8,8 +8,13 @@
import { chromium, type FullConfig } from '@playwright/test'
import { fr } from '@/i18n/fr'
import { stepUpAdmin } from './admin'
import { draftPath, editorActor, seedDraft, standardShape } from './editor'
import { routeToSandbox } from './sandbox'
import {
draftPath,
editorActor,
secondSession,
seedDraft,
standardShape,
} from './editor'
import { signIn } from './shell'
const TABS = [
@@ -27,9 +32,7 @@ export default async function warmUp(config: FullConfig): Promise<void> {
const actor = await editorActor('fr')
const seed = await seedDraft(actor, { shape: standardShape })
const browser = await chromium.launch()
const context = await browser.newContext({ baseURL, locale: 'fr-FR' })
await routeToSandbox(context)
const page = await context.newPage()
const { page } = await secondSession(browser, baseURL, 'fr-FR')
await signIn(page, actor.account, fr)
await page.goto('/app/admin')
await stepUpAdmin(page, fr, actor.secret)
+35 -3
View File
@@ -13,6 +13,7 @@ import { edit, insert } from '../helpers/editorFixtures'
import {
baseText,
openReady,
serverHas,
resetStore,
store,
} from '../helpers/editorHarness'
@@ -113,9 +114,6 @@ describe('findings tree model', () => {
},
]
await openReady({ text: JSON.stringify(stored) })
const { documentText, savedText, unsaved } = store.getState()
expect(unsaved).toBe(false)
expect(documentText).toBe(savedText)
const n2 = doc().finding_zones[0].categories[0].children[0].children[0]
expect(n2).toMatchObject({
reference_ids: [],
@@ -126,6 +124,40 @@ describe('findings tree model', () => {
expect(screen.getAllByRole('treeitem').length).toBeGreaterThan(0)
})
it('a reload that brings bare nodes keeps the filled text, not dirty', async () => {
await openReady()
const stored = JSON.parse(baseText()) as Record<string, unknown>
stored.finding_zones = [
{
id: 'z',
name: name('Z'),
categories: [
{
id: 'c',
kind: 'dysfunction',
name: name('C'),
children: [{ id: 'n1', name: name('N1') }],
},
],
},
]
serverHas(JSON.stringify(stored), 7)
expect(
await store.getState().reloadServerDraft({ confirmed: true }),
).toEqual({
ok: true,
})
const state = store.getState()
expect(state.unsaved).toBe(false)
expect(state.savedText).toBe(state.documentText)
expect(state.savedRevision).toBe(7)
expect(doc().finding_zones[0].categories[0].children[0]).toMatchObject({
reference_ids: [],
children: [],
review_status: 'inherited',
})
})
it('maps the WAI-ARIA keys', async () => {
await openReady({ text: treeText() })
const all = buildItems(doc())