343 lines
13 KiB
TypeScript
343 lines
13 KiB
TypeScript
import { fr } from '@/i18n/fr'
|
|
import type { Page, TestInfo } from '@playwright/test'
|
|
import { expect, test } from '../support/browser'
|
|
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
|
|
import {
|
|
closeFinding,
|
|
editorActor,
|
|
expectNoDialog,
|
|
findingDialog,
|
|
historyButton,
|
|
openEditor,
|
|
openFinding,
|
|
openTab,
|
|
place,
|
|
revealFinding,
|
|
seedDraft,
|
|
serverDocument,
|
|
showCitations,
|
|
standardShape,
|
|
} from '../support/editor'
|
|
|
|
// R2 UX finish, task 2 (R2F-3, R2F-4): the finding dialog (view, edit, creation), its
|
|
// browser-history entries, its guards, the read-only flip and the gone rule, and the
|
|
// layers' order after Back and Forward. The top-layer, focus and history rules are the
|
|
// browser's, so they are proved here and not in happy-dom.
|
|
|
|
const dict = fr
|
|
|
|
const isPhone = (info: TestInfo) => info.project.name === 'chromium-375'
|
|
const dialog = (page: Page) => findingDialog(page)
|
|
const inDialog = (page: Page, name: string) =>
|
|
dialog(page).getByRole('button', { name, exact: true })
|
|
const edit = (page: Page) => inDialog(page, dict['editor.findings.edit'])
|
|
const save = (page: Page) => inDialog(page, dict['editor.findings.save'])
|
|
const nameFr = (page: Page) =>
|
|
dialog(page).getByLabel(dict['editor.general.name_fr'])
|
|
const confirmText = (page: Page) =>
|
|
dialog(page).getByText(dict['editor.findings.discard_ask'])
|
|
const undo = (page: Page) => historyButton(page, dict, 'undo')
|
|
const rows = (page: Page) => page.getByTestId('finding-item')
|
|
|
|
async function open(page: Page) {
|
|
const actor = await editorActor('fr')
|
|
const seed = await seedDraft(actor, { shape: standardShape })
|
|
await openEditor(page, dict, actor, seed.sheetId)
|
|
return seed
|
|
}
|
|
|
|
/** The history entry on top names a finding layer (the adapter writes a moment after a click). */
|
|
async function layerWritten(page: Page, layer: 'finding' | 'none') {
|
|
await page.waitForFunction((wanted) => {
|
|
const view = history.state?.usr?.editorEntry?.view
|
|
return wanted === 'none' ? view?.finding === null : !!view?.finding
|
|
}, layer)
|
|
}
|
|
|
|
/** Whether the sheet is the dialog on top at the right edge of the viewport. */
|
|
const sheetOnTop = (page: Page) =>
|
|
page.evaluate(() => {
|
|
const top = document.elementFromPoint(window.innerWidth - 40, 100)
|
|
return !!top?.closest('dialog')?.querySelector('[data-place="citations"]')
|
|
})
|
|
|
|
test.describe('finding dialog', () => {
|
|
test.use({ locale: 'fr-FR', actionTimeout: 15_000 })
|
|
test.beforeEach(async ({ context }, info) => {
|
|
test.skip(isPhone(info), 'editing needs 1 024 px') // floor-guard: allow C16 editing needs >= 1024 px; phone read-only covered in editor-citations
|
|
await routeToSandbox(context)
|
|
})
|
|
test.afterEach(async ({ context }) => {
|
|
await dropLateReplays(context)
|
|
})
|
|
|
|
test('a click, Enter and Space open the dialog; the tree, its expansion and the scroll stay; the row holds the focus', async ({
|
|
page,
|
|
}) => {
|
|
test.setTimeout(150_000)
|
|
await open(page)
|
|
await openTab(page, dict, 'findings')
|
|
const row = await revealFinding(page, 'Constat A')
|
|
await expect(row).toBeVisible()
|
|
await page.evaluate(() => {
|
|
const spacer = document.createElement('div')
|
|
spacer.style.height = '4000px'
|
|
document.body.append(spacer)
|
|
window.scrollTo(0, 250)
|
|
})
|
|
const before = {
|
|
rows: await rows(page).count(),
|
|
y: await page.evaluate(() => window.scrollY),
|
|
}
|
|
await row.evaluate((element: HTMLElement) =>
|
|
element.focus({ preventScroll: true }),
|
|
)
|
|
await page.keyboard.press('Enter')
|
|
await expect(dialog(page)).toBeVisible()
|
|
await page.keyboard.press('Escape')
|
|
await expectNoDialog(page)
|
|
await expect(row).toBeFocused()
|
|
await page.keyboard.press('Space')
|
|
await expect(dialog(page)).toBeVisible()
|
|
await closeFinding(page, dict)
|
|
await expect(row).toBeFocused()
|
|
await row.click()
|
|
await expect(dialog(page)).toBeVisible()
|
|
await page.keyboard.press('Escape')
|
|
await expectNoDialog(page)
|
|
expect(await rows(page).count()).toBe(before.rows)
|
|
expect(
|
|
Math.abs((await page.evaluate(() => window.scrollY)) - before.y),
|
|
).toBeLessThanOrEqual(2)
|
|
await expect(row).toBeFocused()
|
|
})
|
|
|
|
test('a pristine « Enregistrer » writes nothing, a changed one writes one entry', async ({
|
|
page,
|
|
}) => {
|
|
test.setTimeout(150_000)
|
|
const seed = await open(page)
|
|
await openFinding(page, dict, 'Dysfonction A')
|
|
await edit(page).click()
|
|
await save(page).click()
|
|
await expect(edit(page)).toBeFocused()
|
|
await closeFinding(page, dict)
|
|
await expect(undo(page)).toHaveAttribute('aria-disabled', 'true')
|
|
await openFinding(page, dict, 'Dysfonction A')
|
|
await edit(page).click()
|
|
await nameFr(page).fill('Dysfonction renommée')
|
|
await save(page).click()
|
|
await expect(dialog(page).getByRole('status')).toHaveText(
|
|
dict['editor.findings.saved'],
|
|
)
|
|
await closeFinding(page, dict)
|
|
await expect(undo(page)).toHaveAttribute('aria-disabled', 'false')
|
|
await undo(page).click()
|
|
await expect(rows(page).filter({ hasText: 'Dysfonction A' })).toBeVisible()
|
|
await expect(undo(page)).toHaveAttribute('aria-disabled', 'true')
|
|
expect(
|
|
(
|
|
await serverDocument<{
|
|
finding_zones: { categories: { name: { fr: string } }[] }[]
|
|
}>(seed.draftId)
|
|
).finding_zones[0].categories[0].name.fr,
|
|
).toBe('Dysfonction A')
|
|
})
|
|
|
|
test('« Abandonner » and a width flip commit nothing; 1280, 900, 1280 keeps the draft and the focus', async ({
|
|
page,
|
|
}) => {
|
|
test.setTimeout(150_000)
|
|
await open(page)
|
|
await openFinding(page, dict, 'Dysfonction A')
|
|
await edit(page).click()
|
|
await nameFr(page).fill('Dysfonction brouillon')
|
|
await expect(nameFr(page)).toBeFocused()
|
|
await page.setViewportSize({ width: 900, height: 800 })
|
|
await expect(nameFr(page)).toHaveAttribute('readonly', '')
|
|
await expect(nameFr(page)).toHaveAttribute('aria-readonly', 'true')
|
|
await expect(nameFr(page)).toBeFocused()
|
|
await expect(
|
|
page.getByText(dict['editor.findings.flip_narrow']),
|
|
).toBeVisible()
|
|
await expect(save(page)).toBeDisabled()
|
|
await page.setViewportSize({ width: 1280, height: 800 })
|
|
await expect(nameFr(page)).not.toHaveAttribute('readonly', '')
|
|
await expect(nameFr(page)).toHaveValue('Dysfonction brouillon')
|
|
await expect(nameFr(page)).toBeFocused()
|
|
await inDialog(page, dict['editor.findings.cancel']).click()
|
|
await expect(confirmText(page)).toBeVisible()
|
|
await expect(
|
|
inDialog(page, dict['editor.findings.keep_typing']),
|
|
).toBeFocused()
|
|
await inDialog(page, dict['editor.findings.discard']).click()
|
|
await expect(edit(page)).toBeVisible()
|
|
await closeFinding(page, dict)
|
|
await expect(undo(page)).toHaveAttribute('aria-disabled', 'true')
|
|
await expect(rows(page).filter({ hasText: 'Dysfonction A' })).toBeVisible()
|
|
})
|
|
|
|
test('a dirty Escape and a dirty Back ask, the dialog and the draft stay; « Abandonner » pops one entry', async ({
|
|
page,
|
|
}) => {
|
|
test.setTimeout(150_000)
|
|
await open(page)
|
|
await openFinding(page, dict, 'Dysfonction A')
|
|
await layerWritten(page, 'finding')
|
|
await edit(page).click()
|
|
await nameFr(page).fill('Dysfonction brouillon')
|
|
await page.keyboard.press('Escape')
|
|
await expect(confirmText(page)).toBeVisible()
|
|
await expect(dialog(page)).toBeVisible()
|
|
await inDialog(page, dict['editor.findings.keep_typing']).click()
|
|
await expect(nameFr(page)).toHaveValue('Dysfonction brouillon')
|
|
await page.goBack()
|
|
await expect(confirmText(page)).toBeVisible()
|
|
await expect(dialog(page)).toBeVisible()
|
|
await inDialog(page, dict['editor.findings.keep_typing']).click()
|
|
await expect(nameFr(page)).toHaveValue('Dysfonction brouillon')
|
|
await page.keyboard.press('Escape')
|
|
await inDialog(page, dict['editor.findings.discard']).click()
|
|
await expectNoDialog(page)
|
|
await layerWritten(page, 'none')
|
|
// One entry went: the next Back leaves the tab, no orphan entry of the dialog is left.
|
|
await page.goBack()
|
|
await expect(page.getByRole('tab', { selected: true })).toHaveText(
|
|
new RegExp(`^${dict['editor.tab.annotations']}`),
|
|
)
|
|
})
|
|
|
|
test('deleting from the dialog closes it and lands on the nearest row', async ({
|
|
page,
|
|
}) => {
|
|
test.setTimeout(150_000)
|
|
await open(page)
|
|
await openFinding(page, dict, 'Constat A')
|
|
await inDialog(page, dict['editor.action.delete']).click()
|
|
await page
|
|
.locator('dialog[open]')
|
|
.last()
|
|
.getByRole('button', { name: dict['editor.delete.confirm'] })
|
|
.click()
|
|
await expectNoDialog(page)
|
|
const parent = page.getByRole('treeitem', { name: /Dysfonction A/ })
|
|
await expect(parent).toBeFocused()
|
|
await expect(parent).toHaveAttribute('aria-selected', 'true')
|
|
})
|
|
|
|
test('after a deletion the first Back moves and one « Défaire » restores the row', async ({
|
|
page,
|
|
}) => {
|
|
test.setTimeout(150_000)
|
|
await open(page)
|
|
await openFinding(page, dict, 'Constat A')
|
|
await inDialog(page, dict['editor.action.delete']).click()
|
|
await page
|
|
.locator('dialog[open]')
|
|
.last()
|
|
.getByRole('button', { name: dict['editor.delete.confirm'] })
|
|
.click()
|
|
await expectNoDialog(page)
|
|
await layerWritten(page, 'none')
|
|
await undo(page).click()
|
|
const row = page.getByRole('treeitem', { name: /Constat A/ })
|
|
await expect(row).toBeVisible()
|
|
await expect(row).toHaveAttribute('aria-selected', 'true')
|
|
await expect(row).toBeFocused()
|
|
await page.goBack()
|
|
await expect(page.getByRole('tab', { selected: true })).toHaveText(
|
|
new RegExp(`^${dict['editor.tab.annotations']}`),
|
|
)
|
|
})
|
|
|
|
test('a creation is a layer: « Créer » shows the new element, a Back goes to the tree', async ({
|
|
page,
|
|
}) => {
|
|
test.setTimeout(150_000)
|
|
await open(page)
|
|
await openTab(page, dict, 'findings')
|
|
await page
|
|
.getByRole('button', { name: dict['editor.findings.add_zone'] })
|
|
.click()
|
|
await layerWritten(page, 'finding')
|
|
await page.locator('#finding-new-name-fr').fill('Zone B')
|
|
await page.locator('#finding-new-name-en').fill('Zone B en')
|
|
await page
|
|
.getByRole('button', { name: dict['editor.findings.create'] })
|
|
.click()
|
|
await expect(
|
|
dialog(page).getByRole('heading', { name: 'Zone B' }),
|
|
).toBeVisible()
|
|
await expect(edit(page)).toBeVisible()
|
|
await page.goBack()
|
|
await expectNoDialog(page)
|
|
await expect(rows(page).filter({ hasText: 'Zone B' })).toBeVisible()
|
|
})
|
|
|
|
test('an element that vanished under a restored entry closes its dialog and says so', async ({
|
|
page,
|
|
}) => {
|
|
test.setTimeout(150_000)
|
|
await open(page)
|
|
await openTab(page, dict, 'findings')
|
|
await page
|
|
.getByRole('button', { name: dict['editor.findings.add_zone'] })
|
|
.click()
|
|
await page.locator('#finding-new-name-fr').fill('Zone B')
|
|
await page.locator('#finding-new-name-en').fill('Zone B en')
|
|
await page
|
|
.getByRole('button', { name: dict['editor.findings.create'] })
|
|
.click()
|
|
await expect(edit(page)).toBeVisible()
|
|
await closeFinding(page, dict)
|
|
await undo(page).click()
|
|
await expect(rows(page).filter({ hasText: 'Zone B' })).toHaveCount(0)
|
|
// Forward restores the entry of the dead zone: its dialog closes at once.
|
|
await page.goForward()
|
|
await expectNoDialog(page)
|
|
await expect(page.locator('p[aria-live="polite"]')).toHaveText(
|
|
dict['editor.findings.gone'],
|
|
)
|
|
})
|
|
|
|
test('Back and Forward walk the layers, the sheet is on top each time (owner steps 1 to 4)', async ({
|
|
page,
|
|
}) => {
|
|
test.setTimeout(150_000)
|
|
await open(page)
|
|
// 1. the finding dialog, 2. its sheet, 3. « Tout afficher », 4. the references tab.
|
|
await openFinding(page, dict, 'Constat A')
|
|
await layerWritten(page, 'finding')
|
|
await showCitations(page)
|
|
expect(await sheetOnTop(page)).toBe(true)
|
|
await page
|
|
.getByRole('button', { name: dict['editor.references.panel_show_all'] })
|
|
.click()
|
|
await expectNoDialog(page)
|
|
await expect(place(page, 'references')).toBeVisible()
|
|
await page.waitForFunction(
|
|
() => history.state?.usr?.editorEntry?.view?.tab === 'references',
|
|
)
|
|
await page.goBack()
|
|
await expect(page.locator('dialog[open]')).toHaveCount(2)
|
|
expect(await sheetOnTop(page)).toBe(true)
|
|
await page.goBack()
|
|
await expect(page.locator('dialog[open]')).toHaveCount(1)
|
|
await expect(dialog(page)).toBeVisible()
|
|
await expect(page.locator('[data-citations-trigger]')).toBeFocused()
|
|
await page.goBack()
|
|
await expectNoDialog(page)
|
|
await expect(
|
|
page.getByRole('treeitem', { name: 'Constat A' }),
|
|
).toBeFocused()
|
|
await page.goForward()
|
|
await expect(page.locator('dialog[open]')).toHaveCount(1)
|
|
await page.goForward()
|
|
await expect(page.locator('dialog[open]')).toHaveCount(2)
|
|
expect(await sheetOnTop(page)).toBe(true)
|
|
await page.goForward()
|
|
await expectNoDialog(page)
|
|
await expect(place(page, 'references')).toBeVisible()
|
|
})
|
|
})
|