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,174 @@
|
||||
import { fr } from '@/i18n/fr'
|
||||
import type { Page, TestInfo } from '@playwright/test'
|
||||
import { expect, expectAccessible, test } from '../support/browser'
|
||||
import { dropLateReplays, routeToSandbox } from '../support/sandbox'
|
||||
import {
|
||||
DRAWING_SVG,
|
||||
editorActor,
|
||||
openEditor,
|
||||
seedDraft,
|
||||
selectTab,
|
||||
standardShape,
|
||||
serverDocument,
|
||||
saveDraft,
|
||||
} from '../support/editor'
|
||||
|
||||
// V1-2.6 A2 (contract C16, C20): a drawing imported into a view. A hostile file is
|
||||
// refused, an Inkscape export is cleaned after a preview, a valid file is attached, a
|
||||
// detail view shows the drawing by crop. Both upload outcomes (the object is new, or the
|
||||
// same bytes are already stored) end on the same screen.
|
||||
|
||||
const dict = fr
|
||||
|
||||
const INKSCAPE_SVG =
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" ' +
|
||||
'xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape" ' +
|
||||
'xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd" ' +
|
||||
'viewBox="0 0 400 300" inkscape:version="1.3">' +
|
||||
'<sodipodi:namedview id="base" inkscape:zoom="0.5"/>' +
|
||||
'<metadata id="m1"><x:xmpmeta xmlns:x="adobe:ns:meta/"/></metadata>' +
|
||||
'<style>.a{fill:#c96}</style>' +
|
||||
'<rect class="a" x="20" y="20" width="360" height="260"/></svg>'
|
||||
|
||||
const HOSTILE_SVG =
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 400 300">' +
|
||||
'<script>alert(1)</script><rect x="20" y="20" width="360" height="260"/></svg>'
|
||||
|
||||
const file = (svg: string, name = 'dessin.svg') => ({
|
||||
name,
|
||||
mimeType: 'image/svg+xml',
|
||||
buffer: Buffer.from(svg),
|
||||
})
|
||||
|
||||
const isPhone = (info: TestInfo) => info.project.name === 'chromium-375'
|
||||
|
||||
const mainFile = (page: Page) => page.getByTestId('view-main-file')
|
||||
const mainDrawing = (page: Page) => page.getByTestId('view-main-drawing')
|
||||
|
||||
test.describe('editor drawings (A2)', () => {
|
||||
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('hostile file refused, nothing added, no cleaning box', async ({
|
||||
page,
|
||||
requests,
|
||||
}) => {
|
||||
const actor = await editorActor('fr')
|
||||
requests.forbid(actor.account.email, actor.account.password)
|
||||
const seed = await seedDraft(actor, { drawing: null })
|
||||
await openEditor(page, dict, actor, seed.sheetId)
|
||||
await selectTab(page, dict, 'views')
|
||||
await expect(
|
||||
mainDrawing(page).getByText(dict['editor.views.drawing.none']),
|
||||
).toBeVisible()
|
||||
|
||||
await mainFile(page).setInputFiles(file(HOSTILE_SVG, 'hostile.svg'))
|
||||
await expect(
|
||||
page.getByText(dict['editor.upload.err.svg_active_content']),
|
||||
).toBeVisible()
|
||||
await expect(
|
||||
page.getByRole('dialog', { name: dict['editor.cleaning.title'] }),
|
||||
).toHaveCount(0)
|
||||
await expect(
|
||||
mainDrawing(page).getByText(dict['editor.views.drawing.none']),
|
||||
).toBeVisible()
|
||||
await expect(page.getByText(dict['editor.upload.done'])).toHaveCount(0)
|
||||
await expectAccessible(page, 'the refused drawing')
|
||||
})
|
||||
|
||||
test('Inkscape export: preview, cancel adds nothing, confirm cleans and attaches', async ({
|
||||
page,
|
||||
requests,
|
||||
}) => {
|
||||
const actor = await editorActor('fr')
|
||||
requests.forbid(actor.account.email, actor.account.password)
|
||||
const seed = await seedDraft(actor, { drawing: null })
|
||||
await openEditor(page, dict, actor, seed.sheetId)
|
||||
await selectTab(page, dict, 'views')
|
||||
|
||||
await mainFile(page).setInputFiles(file(INKSCAPE_SVG, 'inkscape.svg'))
|
||||
const dialog = page.getByRole('dialog', {
|
||||
name: dict['editor.cleaning.title'],
|
||||
})
|
||||
await expect(dialog).toBeVisible()
|
||||
await expect(
|
||||
dialog.getByTestId('cleaning-preview').locator('svg'),
|
||||
).toBeVisible()
|
||||
await expect(dialog.getByText(dict['editor.cleaning.style'])).toBeVisible()
|
||||
await expectAccessible(page, 'the cleaning box')
|
||||
await dialog
|
||||
.getByRole('button', { name: dict['editor.cleaning.cancel'] })
|
||||
.click()
|
||||
await expect(dialog).toBeHidden()
|
||||
await expect(
|
||||
mainDrawing(page).getByText(dict['editor.views.drawing.none']),
|
||||
).toBeVisible()
|
||||
|
||||
await mainFile(page).setInputFiles(file(INKSCAPE_SVG, 'inkscape.svg'))
|
||||
await dialog
|
||||
.getByRole('button', { name: dict['editor.cleaning.confirm'] })
|
||||
.click()
|
||||
await expect(page.getByText(dict['editor.upload.done'])).toBeVisible()
|
||||
await expect(
|
||||
mainDrawing(page).getByText(dict['editor.views.drawing.ok']),
|
||||
).toBeVisible()
|
||||
await saveDraft(page, dict, seed.revision + 1)
|
||||
const saved = await serverDocument<{
|
||||
views: { svg_asset_id: string | null }[]
|
||||
}>(seed.draftId)
|
||||
expect(saved.views[0].svg_asset_id).not.toBeNull()
|
||||
})
|
||||
|
||||
test('valid file attached; a detail view shows it by crop; the same bytes attach twice', async ({
|
||||
page,
|
||||
requests,
|
||||
}) => {
|
||||
const actor = await editorActor('fr')
|
||||
requests.forbid(actor.account.email, actor.account.password)
|
||||
const seed = await seedDraft(actor, { drawing: null, shape: standardShape })
|
||||
await openEditor(page, dict, actor, seed.sheetId)
|
||||
await selectTab(page, dict, 'views')
|
||||
|
||||
await mainFile(page).setInputFiles(file(DRAWING_SVG, 'valide.svg'))
|
||||
await expect(page.getByText(dict['editor.upload.done'])).toBeVisible()
|
||||
await expect(
|
||||
mainDrawing(page).getByText(dict['editor.views.drawing.ok']),
|
||||
).toBeVisible()
|
||||
|
||||
// The detail view crops the main drawing: its own drawing line says it is inherited.
|
||||
const detail = page.getByRole('listitem', { name: 'Détail A' })
|
||||
await expect(
|
||||
detail.getByText(dict['editor.views.drawing.inherited']),
|
||||
).toBeVisible()
|
||||
|
||||
// The same bytes attached to the detail view: the stored object already exists.
|
||||
await detail
|
||||
.getByTestId('view-detail-a-file')
|
||||
.setInputFiles(file(DRAWING_SVG))
|
||||
await expect(
|
||||
detail.getByText(dict['editor.views.drawing.ok']),
|
||||
).toBeVisible()
|
||||
await detail
|
||||
.getByRole('button', { name: dict['editor.views.drawing.use_parent'] })
|
||||
.click()
|
||||
await expect(
|
||||
detail.getByText(dict['editor.views.drawing.inherited']),
|
||||
).toBeVisible()
|
||||
|
||||
await selectTab(page, dict, 'annotations')
|
||||
await page
|
||||
.getByRole('group', { name: dict['editor.annotations.views'] })
|
||||
.getByRole('button', { name: 'Détail A' })
|
||||
.click()
|
||||
await expect(
|
||||
page.getByTestId('annotation-canvas-drawing').locator('svg').first(),
|
||||
).toBeVisible()
|
||||
await expect(page.getByTestId('annotation-overlay')).toBeAttached()
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user