fix(app): closed hash and canonical-form drawing messages, split crop and drawing views

This commit is contained in:
bchanot committed 2026-11-04 13:34:02 +01:00
1 parent 7bf1404946
commit 1bbf97e65b
16 files changed
+487 -248

No files matched your search

@@ -12,7 +12,10 @@ import { SheetFailure } from '@faunosteo/supabase'
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
import ViewsTab from '@/components/editor/tabs/ViewsTab'
import { cleanSvg } from '@/editor/core/cleaning'
import { MAX_DRAWING_BYTES } from '@/editor/drawingUpload'
import { createHash } from 'node:crypto'
import { getDict } from '@/i18n'
import { uploadErrorMessage } from '@/editor/uploadMessages'
import { MAX_DRAWING_BYTES, attachToView } from '@/editor/drawingUpload'
import { useLocaleStore } from '@/state/localeStore'
import { ASSET } from '../helpers/editorFixtures'
import { openReady, resetStore, sb, store } from '../helpers/editorHarness'
@@ -139,13 +142,11 @@ describe('drawing upload flow', () => {
expect(
within(dialog).getByTestId('cleaning-preview').querySelector('svg'),
).not.toBeNull()
await userEvent
.setup()
.click(
within(dialog).getByRole('button', {
name: 'Nettoyer et utiliser cette version',
}),
)
await userEvent.setup().click(
within(dialog).getByRole('button', {
name: 'Nettoyer et utiliser cette version',
}),
)
await waitFor(() => expect(mainAsset()).toBe(NEW_ASSET))
expect(sb.uploadSheetDrawing).toHaveBeenCalledTimes(1)
})
@@ -255,6 +256,35 @@ describe('drawing upload flow', () => {
expect(mainAsset()).toBe(ASSET)
})
it('a held drawing outside the stored form is refused at attach as svg_not_canonical', async () => {
const bytes = new TextEncoder().encode(
svg('0 0 200 100', ' <rect width="4" height="4"/>'),
)
const sha256 = createHash('sha256').update(bytes).digest('hex')
expect(
store.getState().addDrawing({ assetId: NEW_ASSET, sha256, bytes }).ok,
).toBe(true)
expect(attachToView('view-main', NEW_ASSET)).toEqual({
ok: false,
error: { code: 'svg_not_canonical' },
})
expect(mainAsset()).toBe(ASSET)
})
it('phrases svg_not_canonical and the new reader reasons', () => {
const t = (key: string) => getDict('fr')[key as never] as string
const context = { doc: null, locale: 'fr' as const }
expect(
uploadErrorMessage(t, { code: 'svg_not_canonical' }, context),
).toMatch(/pas sous la forme enregistrée/)
const reason = (value: string) =>
uploadErrorMessage(t, { code: 'svg_rejected', reason: value }, context)
expect(reason('processing_instruction')).toMatch(
/instruction de traitement/,
)
expect(reason('removed <script>')).toMatch(/éléments à retirer/)
})
it('a refused frame change leaves the drawing uploaded and held, the view unchanged', async () => {
serverGets(svg('0 0 20 20'))
await pick(svg('0 0 20 20'))