test(editor): V1-2.6 browser journeys on the sandbox, touch drag and findings fixes
This commit is contained in:
1 parent
7bbd096a16
commit
5097fd7484
18 files changed
+3010
-8
No files matched your search
@@ -0,0 +1,376 @@
|
||||
import { fr } from '@/i18n/fr'
|
||||
import type { Locator, Page, TestInfo } from '@playwright/test'
|
||||
import { sql } from '../../../../packages/supabase/tests/sandbox/stack'
|
||||
import { stepUpAdmin } from '../support/admin'
|
||||
import { expect, expectAccessible, test } from '../support/browser'
|
||||
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
|
||||
import {
|
||||
annotationList,
|
||||
clickDrawing,
|
||||
createFromPanel,
|
||||
creationPanel,
|
||||
DRAWING_SVG,
|
||||
editorActor,
|
||||
fillCreation,
|
||||
geometryField,
|
||||
saveDraft,
|
||||
secondSession,
|
||||
selectTab,
|
||||
toolButton,
|
||||
openDraft,
|
||||
} from '../support/editor'
|
||||
import { signIn } from '../support/shell'
|
||||
|
||||
// V1-2.6 journey (contract C26 to C30; the steps of docs/development/V1-2-6_OWNER_TRIAL.md
|
||||
// §4, with two editor accounts): a non-equine sheet created from the administration,
|
||||
// a drawing, a detail view, findings, categories, points, zones and a link, the save,
|
||||
// a reload with the beforeunload dialog and the recovery offer, a conflict with the
|
||||
// other account, the submission and the round read back in SQL.
|
||||
|
||||
const dict = fr
|
||||
|
||||
const isPhone = (info: TestInfo) => info.project.name === 'chromium-375'
|
||||
const main = (page: Page) => page.getByRole('main')
|
||||
|
||||
async function commitText(field: Locator, value: string) {
|
||||
await field.fill(value)
|
||||
await field.press('Enter')
|
||||
}
|
||||
|
||||
const clickDialog = (dialog: Locator, name: string) =>
|
||||
dialog.getByRole('button', { name, exact: true }).click()
|
||||
|
||||
const clickButton = (page: Page, name: string) =>
|
||||
page.getByRole('button', { name, exact: true }).click()
|
||||
|
||||
async function createSheetFromAdmin(page: Page, tag: string): Promise<string> {
|
||||
await page
|
||||
.locator('section[aria-labelledby="admin-sheets-title"]')
|
||||
.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.
|
||||
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
|
||||
.getByRole('button', { name: dict['admin.sheet_form.submit'] })
|
||||
.click()
|
||||
// The creation opens the new draft in the editor directly (the guide's 4.1 says the
|
||||
// sheet « apparaît » and is « ouvrable dans l'éditeur »: no overview step).
|
||||
await expect(page).toHaveURL(/\/app\/admin\/sheets\/[0-9a-f-]{36}\/draft$/)
|
||||
const id = new URL(page.url()).pathname.split('/')[4] ?? ''
|
||||
await expect(
|
||||
page.getByRole('heading', { level: 1, name: 'Brouillon, version 1' }),
|
||||
).toBeVisible()
|
||||
return id
|
||||
}
|
||||
|
||||
async function importDrawing(page: Page) {
|
||||
await selectTab(page, dict, 'views')
|
||||
await page.getByTestId('view-view-main-file').setInputFiles({
|
||||
name: 'valide.svg',
|
||||
mimeType: 'image/svg+xml',
|
||||
buffer: Buffer.from(DRAWING_SVG),
|
||||
})
|
||||
await expect(page.getByText(dict['editor.upload.done'])).toBeVisible()
|
||||
await page.locator('#view-new-fr').fill('Détail essai')
|
||||
await page.locator('#view-new-en').fill('Trial detail')
|
||||
const crop = { min_x: '100', min_y: '100', width: '300', height: '240' }
|
||||
for (const [key, value] of Object.entries(crop))
|
||||
await page.locator(`#view-new-crop-${key}`).fill(value)
|
||||
await clickButton(page, dict['editor.views.add'])
|
||||
await expect(
|
||||
page.getByRole('listitem', { name: 'Détail essai' }),
|
||||
).toBeVisible()
|
||||
}
|
||||
|
||||
async function createFindings(page: Page) {
|
||||
await selectTab(page, dict, 'general')
|
||||
await page.locator('#category-new-fr').fill('Catégorie essai')
|
||||
await page.locator('#category-new-en').fill('Trial category')
|
||||
await clickButton(page, dict['editor.general.category_add'])
|
||||
await selectTab(page, dict, 'findings')
|
||||
const create = () => clickButton(page, dict['editor.findings.create'])
|
||||
const names = async (frName: string, enName: string) => {
|
||||
await page.locator('#finding-new-name-fr').fill(frName)
|
||||
await page.locator('#finding-new-name-en').fill(enName)
|
||||
}
|
||||
await clickButton(page, dict['editor.findings.add_zone'])
|
||||
await names('Zone essai', 'Trial zone')
|
||||
await create()
|
||||
await clickButton(page, dict['editor.findings.add_category'])
|
||||
await page.locator('#finding-new-kind').selectOption('dysfunction')
|
||||
await names('Dysfonction essai', 'Trial dysfunction')
|
||||
await create()
|
||||
await clickButton(page, dict['editor.findings.add_node'])
|
||||
await names('Constat essai', 'Trial finding')
|
||||
await create()
|
||||
await expect(
|
||||
page.getByTestId('finding-item').filter({ hasText: 'Constat essai' }),
|
||||
).toBeVisible()
|
||||
}
|
||||
|
||||
async function createAnnotations(page: Page) {
|
||||
await selectTab(page, dict, 'annotations')
|
||||
const trace = async (points: number[][]) => {
|
||||
for (const [x, y] of points) await clickDrawing(page, x, y)
|
||||
await clickButton(page, dict['editor.annotations.trace_close'])
|
||||
}
|
||||
await toolButton(page, dict, 'point').click()
|
||||
await clickDrawing(page, 300, 300)
|
||||
await fillCreation(page, dict, { fr: 'Point essai', en: 'Trial point' })
|
||||
await creationPanel(page)
|
||||
.getByLabel(dict['editor.annotations.zone'])
|
||||
.selectOption({ label: 'Zone essai' })
|
||||
await createFromPanel(page, dict)
|
||||
await toolButton(page, dict, 'zone').click()
|
||||
await trace([
|
||||
[600, 200],
|
||||
[800, 200],
|
||||
[700, 400],
|
||||
])
|
||||
await fillCreation(page, dict, { fr: 'Zone dessinée', en: 'Drawn zone' })
|
||||
await creationPanel(page)
|
||||
.getByLabel(dict['editor.annotations.zone'])
|
||||
.selectOption({ label: 'Zone essai' })
|
||||
await createFromPanel(page, dict)
|
||||
await toolButton(page, dict, 'link').click()
|
||||
await trace([
|
||||
[150, 500],
|
||||
[350, 500],
|
||||
[250, 700],
|
||||
])
|
||||
await fillCreation(page, dict, { fr: 'Accès essai', en: 'Trial access' })
|
||||
await creationPanel(page)
|
||||
.getByLabel(dict['editor.annotations.opens'])
|
||||
.selectOption({ label: 'Détail essai' })
|
||||
await createFromPanel(page, dict)
|
||||
}
|
||||
|
||||
/** Guide 4.4: a click near the edge proposes a position; a far value is refused. */
|
||||
async function repairGeometry(page: Page) {
|
||||
await toolButton(page, dict, 'point').click()
|
||||
await clickDrawing(page, 3, 3)
|
||||
await fillCreation(page, dict, { fr: 'Point de bord', en: 'Edge point' })
|
||||
await creationPanel(page)
|
||||
.getByRole('button', { name: dict['editor.annotations.create'] })
|
||||
.click()
|
||||
const correction = page.getByTestId('correction-notice')
|
||||
await expect(correction).toBeVisible()
|
||||
await correction
|
||||
.getByRole('button', { name: dict['editor.annotations.correction_use'] })
|
||||
.click()
|
||||
await expect(
|
||||
annotationList(page, dict).getByText('Point de bord'),
|
||||
).toBeVisible()
|
||||
const cx = geometryField(page, dict, 'cx')
|
||||
await cx.fill('9999')
|
||||
await cx.press('Enter')
|
||||
await expect(
|
||||
page.getByText(dict['editor.annotations.geometry.unapplied']),
|
||||
).toBeVisible()
|
||||
await clickButton(page, dict['editor.annotations.geometry.revert'])
|
||||
await expect(
|
||||
page.getByText(dict['editor.annotations.geometry.unapplied']),
|
||||
).toHaveCount(0)
|
||||
}
|
||||
|
||||
/** Guide 4.5: an unsaved change, a reload (beforeunload accepted), the offer, a restore. */
|
||||
async function reloadAndRestore(page: Page, sheetId: string) {
|
||||
const kinds: string[] = []
|
||||
page.on('dialog', (dialog) => {
|
||||
kinds.push(dialog.type())
|
||||
void dialog.accept()
|
||||
})
|
||||
await page.reload()
|
||||
expect(kinds).toContain('beforeunload')
|
||||
await expect(
|
||||
page.getByText(dict['editor.draft.recovery.restore'], { exact: true }),
|
||||
).toBeVisible()
|
||||
await expect(
|
||||
page.getByText('Une copie locale temporaire de ce brouillon existe', {
|
||||
exact: false,
|
||||
}),
|
||||
).toBeVisible()
|
||||
expect(page.url()).toContain(sheetId)
|
||||
await clickButton(page, dict['editor.draft.recovery.restore'])
|
||||
await expect(
|
||||
page.getByText(dict['editor.draft.status.unsaved'], { exact: false }),
|
||||
).toBeVisible()
|
||||
}
|
||||
|
||||
test.describe('editor journey (owner trial steps)', () => {
|
||||
test.use({ locale: 'fr-FR', actionTimeout: 15_000 })
|
||||
test.beforeEach(async ({ context }, info) => {
|
||||
test.skip(isPhone(info), 'editing needs 1 024 px')
|
||||
await routeToSandbox(context)
|
||||
})
|
||||
test.afterEach(async ({ context }) => {
|
||||
await dropLateReplays(context)
|
||||
})
|
||||
|
||||
test('creation to submission with two editor accounts', async ({
|
||||
page,
|
||||
browser,
|
||||
baseURL,
|
||||
requests,
|
||||
}) => {
|
||||
test.setTimeout(240_000)
|
||||
const [a, b] = [await editorActor('fr'), await editorActor('fr')]
|
||||
for (const actor of [a, b])
|
||||
requests.forbid(actor.account.email, actor.account.password)
|
||||
const tag = a.account.id.slice(0, 8)
|
||||
await signIn(page, a.account, dict)
|
||||
await page.goto('/app/admin')
|
||||
await stepUpAdmin(page, dict, a.secret)
|
||||
|
||||
const sheetId = await createSheetFromAdmin(page, tag)
|
||||
await importDrawing(page)
|
||||
await createFindings(page)
|
||||
await createAnnotations(page)
|
||||
await repairGeometry(page)
|
||||
// Undo and redo the numeric repair path's last creation.
|
||||
await page
|
||||
.getByRole('button', {
|
||||
name: dict['editor.annotations.undo'],
|
||||
exact: true,
|
||||
})
|
||||
.click()
|
||||
await page
|
||||
.getByRole('button', {
|
||||
name: dict['editor.annotations.redo'],
|
||||
exact: true,
|
||||
})
|
||||
.click()
|
||||
await expectAccessible(page, 'the editor with annotations')
|
||||
await saveDraft(page, dict, 1)
|
||||
|
||||
// 4.5: a rename left unsaved survives a reload through the recovery copy.
|
||||
await selectTab(page, dict, 'general')
|
||||
const name = page.getByLabel(dict['editor.general.name_fr'], {
|
||||
exact: true,
|
||||
})
|
||||
await commitText(name, `Chien révisé ${tag}`)
|
||||
await reloadAndRestore(page, sheetId)
|
||||
await saveDraft(page, dict, 2)
|
||||
|
||||
// 4.6: the other account saves first; the conflict names its revision.
|
||||
const second = await secondSession(browser, baseURL ?? '', 'fr-FR')
|
||||
await signIn(second.page, b.account, dict)
|
||||
await second.page.goto('/app/admin')
|
||||
await stepUpAdmin(second.page, dict, b.secret)
|
||||
await openDraft(second.page, dict, sheetId)
|
||||
await selectTab(second.page, dict, 'general')
|
||||
await commitText(
|
||||
second.page.getByLabel(dict['editor.general.name_en'], { exact: true }),
|
||||
`Dog by B ${tag}`,
|
||||
)
|
||||
await saveDraft(second.page, dict, 3)
|
||||
await selectTab(page, dict, 'general')
|
||||
await commitText(
|
||||
page.getByLabel(dict['editor.general.name_en'], { exact: true }),
|
||||
`Dog by A ${tag}`,
|
||||
)
|
||||
await clickButton(page, dict['common.save'])
|
||||
const conflict = page.getByRole('dialog', {
|
||||
name: dict['editor.draft.conflict.known'].replace('{revision}', '3'),
|
||||
})
|
||||
await expect(conflict).toBeVisible()
|
||||
await expectAccessible(page, 'the conflict dialog')
|
||||
await clickDialog(conflict, dict['editor.draft.conflict.reload'])
|
||||
await expect(conflict).toContainText('révision 3')
|
||||
await clickDialog(conflict, dict['editor.draft.conflict.reload'])
|
||||
await expect(conflict).toBeHidden()
|
||||
await expect(
|
||||
page.getByText(
|
||||
dict['editor.draft.status.revision'].replace('{revision}', '3'),
|
||||
{
|
||||
exact: true,
|
||||
},
|
||||
),
|
||||
).toBeVisible()
|
||||
|
||||
// The conflict again, resolved by keeping this version after the confirmation.
|
||||
await commitText(
|
||||
second.page.getByLabel(dict['editor.general.name_en'], { exact: true }),
|
||||
`Dog by B again ${tag}`,
|
||||
)
|
||||
await saveDraft(second.page, dict, 4)
|
||||
await commitText(
|
||||
page.getByLabel(dict['editor.general.name_en'], { exact: true }),
|
||||
`Dog by A ${tag}`,
|
||||
)
|
||||
await clickButton(page, dict['common.save'])
|
||||
const again = page.getByRole('dialog', {
|
||||
name: dict['editor.draft.conflict.known'].replace('{revision}', '4'),
|
||||
})
|
||||
await clickDialog(again, dict['editor.draft.conflict.keep'])
|
||||
await expect(again).toContainText('Remplacer la révision 4')
|
||||
await clickDialog(again, dict['editor.draft.conflict.keep'])
|
||||
await expect(again).toBeHidden()
|
||||
await expect(
|
||||
page.getByText(
|
||||
dict['editor.draft.status.revision'].replace('{revision}', '5'),
|
||||
{
|
||||
exact: true,
|
||||
},
|
||||
),
|
||||
).toBeVisible()
|
||||
await second.context.close()
|
||||
|
||||
await selectTab(page, dict, 'verification')
|
||||
|
||||
// 4.7: elements to confirm are information, never an error; « Aller à » selects.
|
||||
const verification = page.getByTestId('editor-tab-verification')
|
||||
await expect(
|
||||
verification.getByText(
|
||||
dict['editor.verification.errors'].replace('{count}', '0'),
|
||||
),
|
||||
).toBeVisible()
|
||||
await expect(
|
||||
verification.getByText(dict['editor.verification.to_confirm_info']),
|
||||
).toBeVisible()
|
||||
await expect(
|
||||
page.getByRole('tab', { name: dict['editor.tab.verification'] }),
|
||||
).not.toContainText(/\d/)
|
||||
await expectAccessible(page, 'the verification tab')
|
||||
await verification
|
||||
.getByRole('button', {
|
||||
name: dict['editor.verification.goto'].replace(
|
||||
'{tab}',
|
||||
'Point de bord',
|
||||
),
|
||||
})
|
||||
.click()
|
||||
await expect(page.getByTestId('annotation-selection-tag')).toContainText(
|
||||
'Point de bord',
|
||||
)
|
||||
await selectTab(page, dict, 'verification')
|
||||
await page
|
||||
.getByLabel(dict['editor.verification.note'])
|
||||
.fill('Premier jet complet, éléments à confirmer.')
|
||||
await clickButton(page, dict['editor.verification.submit'])
|
||||
await expect(
|
||||
page.getByText(dict['editor.draft.read_only'], { exact: true }),
|
||||
).toBeVisible()
|
||||
await expect(
|
||||
page.getByText('vérification en cours', { exact: false }),
|
||||
).toBeVisible()
|
||||
const draftId = await sql(
|
||||
`select id from public.anatomical_sheet_versions where sheet_id = '${sheetId}' and status = 'draft'`,
|
||||
)
|
||||
expect(
|
||||
await sql(
|
||||
`select status from public.anatomical_sheet_reviews where version_id = '${draftId}'`,
|
||||
),
|
||||
).toBe('verifying')
|
||||
await expectAccessible(page, 'the frozen draft')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user