feat(editor): session tag in history, confirm before leaving
This commit is contained in:
1 parent
4018344ffc
commit
07bebbc855
19 files changed
+844
-76
No files matched your search
@@ -0,0 +1,163 @@
|
||||
import { fr } from '@/i18n/fr'
|
||||
import type { BrowserContext, Page, TestInfo } from '@playwright/test'
|
||||
import { stepUpAdmin } from '../support/admin'
|
||||
import { expect, test } from '../support/browser'
|
||||
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
|
||||
import { signIn } from '../support/shell'
|
||||
import {
|
||||
draftPath,
|
||||
draftTitle,
|
||||
editorActor,
|
||||
findingDialog,
|
||||
openFinding,
|
||||
openTab,
|
||||
referenceDialog,
|
||||
seedDraft,
|
||||
standardShape,
|
||||
startReference,
|
||||
} from '../support/editor'
|
||||
|
||||
// R2 UX finish, task 8 (criteria 22, 23): a jump of several entries in the browser's
|
||||
// history (the history menu) that leaves the editor while a dialog holds changes asks
|
||||
// « Abandonner les modifications ? » before anything is lost. Chromium's Navigation API
|
||||
// lets the page cancel it; the jump is the history menu's own (CDP
|
||||
// Page.navigateToHistoryEntry: page.goBack() waits for a commit that never comes once
|
||||
// cancelled). The entries carry a session tag, never the account id.
|
||||
|
||||
const dict = fr
|
||||
|
||||
const isPhone = (info: TestInfo) => info.project.name === 'chromium-375'
|
||||
const overviewPath = (sheetId: string) => `/app/admin/sheets/${sheetId}`
|
||||
const confirmText = dict['editor.findings.discard_ask']
|
||||
const leftNotice = dict['editor.leave.draft_dropped']
|
||||
|
||||
/**
|
||||
* The overview, then the draft through its link: one document, so the jump back to the
|
||||
* overview is a same-document traversal the page can cancel.
|
||||
*/
|
||||
async function open(page: Page) {
|
||||
const actor = await editorActor('fr')
|
||||
const seed = await seedDraft(actor, { shape: standardShape })
|
||||
await signIn(page, actor.account, dict)
|
||||
await page.goto('/app/admin')
|
||||
await stepUpAdmin(page, dict, actor.secret)
|
||||
await page.goto(overviewPath(seed.sheetId))
|
||||
await page
|
||||
.getByRole('link', { name: dict['admin.overview.open_draft'] })
|
||||
.click()
|
||||
await expect(
|
||||
page.getByRole('heading', { level: 1, name: draftTitle(dict) }),
|
||||
).toBeVisible()
|
||||
return seed.sheetId
|
||||
}
|
||||
|
||||
/** The history menu's jump to the last entry of the overview, several entries back. */
|
||||
async function jumpToOverview(
|
||||
context: BrowserContext,
|
||||
page: Page,
|
||||
sheetId: string,
|
||||
) {
|
||||
const cdp = await context.newCDPSession(page)
|
||||
const { entries, currentIndex } = await cdp.send('Page.getNavigationHistory')
|
||||
const target = entries
|
||||
.slice(0, currentIndex)
|
||||
.filter((e) => new URL(e.url).pathname === overviewPath(sheetId))
|
||||
.pop()
|
||||
if (!target) throw new Error('no overview entry in the history')
|
||||
expect(currentIndex - entries.indexOf(target)).toBeGreaterThan(1)
|
||||
await cdp.send('Page.navigateToHistoryEntry', { entryId: target.id })
|
||||
await cdp.detach()
|
||||
}
|
||||
|
||||
const leftFlags = (page: Page) =>
|
||||
page.evaluate(
|
||||
() =>
|
||||
Object.keys(sessionStorage).filter((k) =>
|
||||
k.startsWith('faunosteo:editor:left-draft:'),
|
||||
).length,
|
||||
)
|
||||
|
||||
test.describe('leaving the editor by a history jump', () => {
|
||||
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; the guard is the same at every width
|
||||
await routeToSandbox(context)
|
||||
})
|
||||
test.afterEach(async ({ context }) => {
|
||||
await dropLateReplays(context)
|
||||
})
|
||||
|
||||
test('a dirty finding dialog asks first, then keeps it or goes', async ({
|
||||
page,
|
||||
context,
|
||||
}) => {
|
||||
test.setTimeout(150_000)
|
||||
const sheetId = await open(page)
|
||||
await openFinding(page, dict, 'Dysfonction A')
|
||||
const dialog = findingDialog(page)
|
||||
await dialog
|
||||
.getByRole('button', { name: dict['editor.findings.edit'], exact: true })
|
||||
.click()
|
||||
const name = dialog.getByLabel(dict['editor.general.name_fr'])
|
||||
await name.fill('Dysfonction brouillon')
|
||||
const entry = await page.evaluate(() => history.state?.usr?.editorEntry)
|
||||
expect(entry?.tag).toMatch(/^[0-9a-f]{32}$/)
|
||||
expect(Object.keys(entry ?? {})).not.toContain('userId')
|
||||
|
||||
await jumpToOverview(context, page, sheetId)
|
||||
await expect(dialog.getByText(confirmText)).toBeVisible()
|
||||
expect(new URL(page.url()).pathname).toBe(draftPath(sheetId))
|
||||
await dialog
|
||||
.getByRole('button', { name: dict['editor.findings.keep_typing'] })
|
||||
.click()
|
||||
await expect(name).toHaveValue('Dysfonction brouillon')
|
||||
expect(new URL(page.url()).pathname).toBe(draftPath(sheetId))
|
||||
|
||||
await jumpToOverview(context, page, sheetId)
|
||||
await expect(dialog.getByText(confirmText)).toBeVisible()
|
||||
await dialog
|
||||
.getByRole('button', { name: dict['editor.findings.discard'] })
|
||||
.click()
|
||||
await expect(page).toHaveURL(
|
||||
(url) => url.pathname === overviewPath(sheetId),
|
||||
)
|
||||
expect(await leftFlags(page)).toBe(0)
|
||||
await page
|
||||
.getByRole('link', { name: dict['admin.overview.open_draft'] })
|
||||
.click()
|
||||
await expect(
|
||||
page.getByRole('heading', { level: 1, name: draftTitle(dict) }),
|
||||
).toBeVisible()
|
||||
await expect(page.getByText(leftNotice)).toHaveCount(0)
|
||||
})
|
||||
|
||||
test('a dirty reference dialog asks the same before the jump goes', async ({
|
||||
page,
|
||||
context,
|
||||
}) => {
|
||||
test.setTimeout(150_000)
|
||||
const sheetId = await open(page)
|
||||
await openTab(page, dict, 'references')
|
||||
await startReference(page, dict)
|
||||
const form = referenceDialog(page)
|
||||
await form.locator('#reference-form-type').selectOption('manual')
|
||||
await form.locator('#reference-form-citation').fill('Brouillon')
|
||||
await jumpToOverview(context, page, sheetId)
|
||||
await expect(form.getByText(confirmText)).toBeVisible()
|
||||
expect(new URL(page.url()).pathname).toBe(draftPath(sheetId))
|
||||
await form
|
||||
.getByRole('button', { name: dict['editor.findings.keep_typing'] })
|
||||
.click()
|
||||
await expect(form.locator('#reference-form-citation')).toHaveValue(
|
||||
'Brouillon',
|
||||
)
|
||||
await jumpToOverview(context, page, sheetId)
|
||||
await form
|
||||
.getByRole('button', { name: dict['editor.findings.discard'] })
|
||||
.click()
|
||||
await expect(page).toHaveURL(
|
||||
(url) => url.pathname === overviewPath(sheetId),
|
||||
)
|
||||
expect(await leftFlags(page)).toBe(0)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user