Focus held by any element that a crossing hides or unmounts (button, tool, canvas, link) goes to the shown tab, decided by the element leaving the page, not by tag; a field still commits first; visible focus stays. History pair: remembered field must be connected, and a pointer-down off a field keeps it. TextField.commit compares with the latest committed value. Open-panel axe settles and checks dialogs like the other places. R-24: no assertion rewritten or deleted; one Chromium case and three unit tests added.
398 lines
13 KiB
TypeScript
398 lines
13 KiB
TypeScript
import { fr } from '@/i18n/fr'
|
|
import type { Locator, Page, TestInfo } from '@playwright/test'
|
|
import { expect, test } from '../support/browser'
|
|
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
|
|
import {
|
|
INKSCAPE_EXPORT,
|
|
clientOf,
|
|
closeReferences,
|
|
copyKeyOf,
|
|
editorActor,
|
|
geometryField,
|
|
historyButton,
|
|
openEditor,
|
|
openReferences,
|
|
openSection,
|
|
pickAnnotation,
|
|
place,
|
|
pointOf,
|
|
saveLine,
|
|
seedDraft,
|
|
selectTab,
|
|
shapeWith,
|
|
standardShape,
|
|
storedCopy,
|
|
UNSAVED_LINE,
|
|
} from '../support/editor'
|
|
|
|
// V1-2.6 U1 H (AC11, AC21): a width change across 1 024 px in a real browser. Every
|
|
// edit-only part keeps what was typed, nothing is editable or focused below the threshold,
|
|
// the unsaved work stays, dialogs that confirm an edit close, a drag in flight commits
|
|
// nothing. Queries go to the visible place or by role; hidden parts stay in the DOM.
|
|
|
|
const dict = fr
|
|
|
|
const isPhone = (info: TestInfo) => info.project.name === 'chromium-375'
|
|
const active = (page: Page) => page.locator(':focus')
|
|
const dialogs = (page: Page) => page.locator('dialog[open]')
|
|
const NARROW = { width: 800, height: 900 }
|
|
const WIDE = { width: 1280, height: 900 }
|
|
|
|
const spareCategory = (document: Record<string, unknown>) => {
|
|
standardShape(document)
|
|
;(document.categories as unknown[]).push({
|
|
id: 'cat-spare',
|
|
name: { fr: 'Libre', en: 'Free' },
|
|
color: null,
|
|
})
|
|
}
|
|
|
|
async function open(page: Page, shape = shapeWith()) {
|
|
const actor = await editorActor('fr')
|
|
const seed = await seedDraft(actor, { shape })
|
|
await openEditor(page, dict, actor, seed.sheetId)
|
|
return { ...seed, actor }
|
|
}
|
|
|
|
async function commitName(page: Page, value: string) {
|
|
await selectTab(page, dict, 'general')
|
|
await page.locator('#general-name-fr').fill(value)
|
|
await page.locator('#general-name-fr').press('Enter')
|
|
}
|
|
|
|
/** The editor is read-only in this page: no save, no text field, no edit toolbar. */
|
|
async function expectReadOnly(page: Page) {
|
|
await expect(
|
|
page.getByRole('button', { name: dict['common.save'], exact: true }),
|
|
).toHaveCount(0)
|
|
await expect(page.getByRole('textbox')).toHaveCount(0)
|
|
await expect(
|
|
page.getByRole('toolbar', { name: dict['editor.annotations.tools'] }),
|
|
).toHaveCount(0)
|
|
for (const kind of ['undo', 'redo'] as const) {
|
|
await expect(historyButton(page, dict, kind)).toHaveAttribute(
|
|
'aria-disabled',
|
|
'true',
|
|
)
|
|
}
|
|
}
|
|
|
|
/** A real crossing: the dialogs are gone and nothing is left to animate before the checks. */
|
|
async function cross(page: Page, size: { width: number; height: number }) {
|
|
await page.setViewportSize(size)
|
|
await expect(dialogs(page)).toHaveCount(0)
|
|
}
|
|
|
|
/**
|
|
* Types in `field` with no blur, crosses below 1 024 px, checks the part left the page and
|
|
* the focus sits on a named tab, widens, and checks the typed value is back untouched.
|
|
*/
|
|
async function keepsTypedValue(
|
|
page: Page,
|
|
field: Locator,
|
|
addButton: string,
|
|
tab: string,
|
|
) {
|
|
await field.fill('Saisie')
|
|
await cross(page, NARROW)
|
|
await expect(field).toBeHidden()
|
|
await expect(
|
|
page.getByRole('button', { name: addButton, exact: true }),
|
|
).toHaveCount(0)
|
|
await expectReadOnly(page)
|
|
await expect(active(page)).toHaveAttribute('id', `editor-tab-${tab}`)
|
|
await cross(page, WIDE)
|
|
await expect(field).toBeVisible()
|
|
await expect(field).toHaveValue('Saisie')
|
|
await expect(saveLine(page)).not.toHaveText(UNSAVED_LINE)
|
|
}
|
|
|
|
test.describe('editor shell, width crossing (H)', () => {
|
|
test.use({ locale: 'fr-FR', actionTimeout: 15_000 })
|
|
test.beforeEach(async ({ context }, info) => {
|
|
test.skip(isPhone(info), 'the widths are set by the tests themselves') // floor-guard: allow C16 editing needs >= 1024 px; phone read-only covered in editor-access
|
|
await routeToSandbox(context)
|
|
})
|
|
test.afterEach(async ({ context }) => {
|
|
await dropLateReplays(context)
|
|
})
|
|
|
|
test('the category, region and detail view forms keep their typed text', async ({
|
|
page,
|
|
}) => {
|
|
await open(page)
|
|
await openSection(page, dict, 'categories')
|
|
await keepsTypedValue(
|
|
page,
|
|
page.locator('#category-new-fr'),
|
|
dict['editor.general.category_add'],
|
|
'annotations',
|
|
)
|
|
await openSection(page, dict, 'regions')
|
|
await keepsTypedValue(
|
|
page,
|
|
page.locator('#region-new-code'),
|
|
dict['editor.vertebra.add'],
|
|
'annotations',
|
|
)
|
|
await openSection(page, dict, 'views')
|
|
await keepsTypedValue(
|
|
page,
|
|
page.locator('#view-new-fr'),
|
|
dict['editor.views.add'],
|
|
'annotations',
|
|
)
|
|
})
|
|
|
|
test('the crop group editor keeps its typed numbers, its read-only twin has its own ids', async ({
|
|
page,
|
|
}) => {
|
|
await open(page)
|
|
await openSection(page, dict, 'views')
|
|
await place(page, 'annotations.views')
|
|
.getByRole('button', { name: dict['editor.views.crop.toggle'] })
|
|
.first()
|
|
.click()
|
|
const field = page.locator('#view-detail-a-crop-min_x')
|
|
await field.fill('7x')
|
|
await cross(page, NARROW)
|
|
await expect(field).toBeHidden()
|
|
await expect(page.locator('#ro-view-detail-a-crop-min_x')).toBeVisible()
|
|
await cross(page, WIDE)
|
|
await expect(field).toHaveValue('7x')
|
|
const ids = await page.evaluate(() => {
|
|
const all = [...document.querySelectorAll('[id]')].map((e) => e.id)
|
|
return all.filter((id, i) => all.indexOf(id) !== i)
|
|
})
|
|
expect(ids).toEqual([])
|
|
})
|
|
|
|
test('the findings creation form and the submission note keep their typed text', async ({
|
|
page,
|
|
}) => {
|
|
await open(page)
|
|
await selectTab(page, dict, 'findings')
|
|
await page
|
|
.getByRole('button', { name: dict['editor.findings.add_zone'] })
|
|
.click()
|
|
await keepsTypedValue(
|
|
page,
|
|
page.locator('#finding-new-name-fr'),
|
|
dict['editor.findings.add_zone'],
|
|
'findings',
|
|
)
|
|
await selectTab(page, dict, 'verification')
|
|
await keepsTypedValue(
|
|
page,
|
|
page.locator('#verification-note'),
|
|
dict['editor.verification.submit'],
|
|
'verification',
|
|
)
|
|
})
|
|
|
|
test('the references form keeps its typed text with the panel open', async ({
|
|
page,
|
|
}) => {
|
|
await open(page)
|
|
await openReferences(page, dict)
|
|
await keepsTypedValue(
|
|
page,
|
|
page.locator('#reference-new-citation'),
|
|
dict['editor.reference.add'],
|
|
'annotations',
|
|
)
|
|
await expect(place(page, 'references')).toBeVisible()
|
|
await expect(place(page, 'references').getByRole('searchbox')).toBeVisible()
|
|
})
|
|
|
|
test('the annotation edit body keeps its tool and its pending creation', async ({
|
|
page,
|
|
}) => {
|
|
await open(page)
|
|
await selectTab(page, dict, 'annotations')
|
|
const zone = page.getByRole('button', {
|
|
name: dict['editor.annotations.tool.zone'],
|
|
exact: true,
|
|
})
|
|
await expect(zone).toBeEnabled()
|
|
await zone.click()
|
|
await page
|
|
.getByRole('button', { name: dict['editor.annotations.add.point'] })
|
|
.click()
|
|
const name = page.getByLabel(dict['editor.annotations.name_fr'])
|
|
await name.fill('Futur point')
|
|
await cross(page, NARROW)
|
|
await expect(name).toBeHidden()
|
|
await expect(zone).toHaveCount(0)
|
|
await expect(active(page)).toHaveAttribute('id', 'editor-tab-annotations')
|
|
await cross(page, WIDE)
|
|
await expect(name).toHaveValue('Futur point')
|
|
await expect(zone).toHaveAttribute('aria-pressed', 'true')
|
|
await expect(saveLine(page)).not.toHaveText(UNSAVED_LINE)
|
|
})
|
|
|
|
test('a section open: read-only below the threshold, unsaved work kept, edit back on widening', async ({
|
|
page,
|
|
}) => {
|
|
const { actor, draftId } = await open(page)
|
|
await commitName(page, 'Nom conservé')
|
|
await openSection(page, dict, 'categories')
|
|
await page.locator('#category-new-fr').fill('Brouillon')
|
|
await cross(page, NARROW)
|
|
await expectReadOnly(page)
|
|
await expect(place(page, 'annotations.categories')).toBeVisible()
|
|
await expect(saveLine(page)).toHaveText(
|
|
dict['editor.draft.status.unsaved_count_one'].replace('{count}', '1'),
|
|
)
|
|
expect(
|
|
await storedCopy(page, copyKeyOf(actor.account.id, draftId)),
|
|
).not.toBeNull()
|
|
await cross(page, WIDE)
|
|
await expect(
|
|
page.getByRole('button', { name: dict['common.save'], exact: true }),
|
|
).toBeEnabled()
|
|
await expect(historyButton(page, dict, 'undo')).toHaveAttribute(
|
|
'aria-disabled',
|
|
'false',
|
|
)
|
|
await expect(page.locator('#category-new-fr')).toHaveValue('Brouillon')
|
|
await expect(saveLine(page)).toHaveText(UNSAVED_LINE)
|
|
})
|
|
|
|
test('the panel open: read-only below the threshold, unsaved work kept, edit back on widening', async ({
|
|
page,
|
|
}) => {
|
|
await open(page)
|
|
await commitName(page, 'Nom conservé')
|
|
await openReferences(page, dict)
|
|
await page.locator('#reference-new-citation').fill('Smith 1999')
|
|
await cross(page, NARROW)
|
|
await expectReadOnly(page)
|
|
await expect(place(page, 'references')).toBeVisible()
|
|
await expect(saveLine(page)).toHaveText(UNSAVED_LINE)
|
|
await cross(page, WIDE)
|
|
await expect(page.locator('#reference-new-citation')).toHaveValue(
|
|
'Smith 1999',
|
|
)
|
|
await expect(
|
|
page.getByRole('button', { name: dict['common.save'], exact: true }),
|
|
).toBeEnabled()
|
|
await closeReferences(page, dict)
|
|
})
|
|
|
|
test('text typed without a blur is unsaved after the crossing and the copy is written', async ({
|
|
page,
|
|
}) => {
|
|
const { actor, draftId } = await open(page)
|
|
await selectTab(page, dict, 'general')
|
|
await page.locator('#general-name-fr').fill('Sans quitter le champ')
|
|
await cross(page, NARROW)
|
|
await expect(saveLine(page)).toHaveText(
|
|
dict['editor.draft.status.unsaved_count_one'].replace('{count}', '1'),
|
|
)
|
|
await expect
|
|
.poll(() => storedCopy(page, copyKeyOf(actor.account.id, draftId)))
|
|
.not.toBeNull()
|
|
})
|
|
|
|
test('a focused drawing tool hands its focus to the shown tab on a crossing', async ({
|
|
page,
|
|
}) => {
|
|
await open(page)
|
|
await selectTab(page, dict, 'annotations')
|
|
const zone = page.getByRole('button', {
|
|
name: dict['editor.annotations.tool.zone'],
|
|
exact: true,
|
|
})
|
|
await expect(zone).toBeEnabled()
|
|
await zone.focus()
|
|
await cross(page, NARROW)
|
|
await expect(active(page)).toHaveAttribute('id', 'editor-tab-annotations')
|
|
})
|
|
|
|
test('a drag across the crossing commits nothing', async ({ page }) => {
|
|
await open(
|
|
page,
|
|
shapeWith(
|
|
pointOf('anno-free', 'main', { cx: 120, cy: 120, r: 6 }, 'Point libre'),
|
|
),
|
|
)
|
|
await selectTab(page, dict, 'annotations')
|
|
await pickAnnotation(page, dict, 'Point libre')
|
|
const cx = geometryField(page, dict, 'cx')
|
|
const before = await cx.inputValue()
|
|
const from = await clientOf(page, 120, 120)
|
|
const to = await clientOf(page, 200, 160)
|
|
await page.mouse.move(from.x, from.y)
|
|
await page.mouse.down()
|
|
await page.mouse.move(to.x, to.y, { steps: 6 })
|
|
await cross(page, NARROW)
|
|
await page.mouse.up()
|
|
await cross(page, WIDE)
|
|
await expect(geometryField(page, dict, 'cx')).toHaveValue(before)
|
|
await expect(saveLine(page)).not.toHaveText(UNSAVED_LINE)
|
|
await expect(historyButton(page, dict, 'undo')).toHaveAttribute(
|
|
'aria-disabled',
|
|
'true',
|
|
)
|
|
})
|
|
|
|
test('a delete confirmation and the discard confirmation close when the editor turns read-only', async ({
|
|
page,
|
|
}) => {
|
|
await open(page, spareCategory)
|
|
await openSection(page, dict, 'categories')
|
|
await page
|
|
.getByRole('listitem')
|
|
.filter({ has: page.locator('#category-cat-spare-name-fr') })
|
|
.getByRole('button', { name: dict['editor.action.delete'] })
|
|
.click()
|
|
await expect(dialogs(page)).toHaveCount(1)
|
|
await cross(page, NARROW)
|
|
await cross(page, WIDE)
|
|
await expect(dialogs(page)).toHaveCount(0)
|
|
await expect(page.locator('#category-cat-spare-name-fr')).toHaveCount(1)
|
|
await expect(saveLine(page)).not.toHaveText(UNSAVED_LINE)
|
|
|
|
await commitName(page, 'Nom à abandonner')
|
|
await page
|
|
.getByRole('button', { name: dict['editor.draft.discard'], exact: true })
|
|
.click()
|
|
await expect(dialogs(page)).toHaveCount(1)
|
|
await cross(page, NARROW)
|
|
await cross(page, WIDE)
|
|
await expect(saveLine(page)).toHaveText(UNSAVED_LINE)
|
|
})
|
|
|
|
test('a decision withheld while the panel was open waits for « Reprendre »; tabs keep the focus', async ({
|
|
page,
|
|
}) => {
|
|
const actor = await editorActor('fr')
|
|
const seed = await seedDraft(actor, { drawing: null, shape: standardShape })
|
|
await openEditor(page, dict, actor, seed.sheetId)
|
|
await openSection(page, dict, 'views')
|
|
await openReferences(page, dict)
|
|
await page.getByTestId('view-main-file').setInputFiles({
|
|
name: 'inkscape.svg',
|
|
mimeType: 'image/svg+xml',
|
|
buffer: INKSCAPE_EXPORT,
|
|
})
|
|
await expect(
|
|
page.getByText(dict['editor.views.pending.cleaning']),
|
|
).toBeVisible()
|
|
await closeReferences(page, dict)
|
|
await expect(dialogs(page)).toHaveCount(0)
|
|
await selectTab(page, dict, 'general')
|
|
await page.getByRole('tab', { name: dict['editor.tab.general'] }).focus()
|
|
await page.keyboard.press('ArrowRight')
|
|
await expect(active(page)).toHaveAttribute('id', 'editor-tab-annotations')
|
|
await expect(dialogs(page)).toHaveCount(0)
|
|
await page
|
|
.getByRole('button', { name: dict['editor.views.pending.resume'] })
|
|
.click()
|
|
await expect(
|
|
page.getByRole('dialog', { name: dict['editor.cleaning.title'] }),
|
|
).toBeVisible()
|
|
})
|
|
})
|