feat(editor): creation on the drawing then the creation dialog
U2 Task 7 (A2, A4, A5, A7, A12, A15; R-3, R-4, R-12, R-13, R-14). The work store's `creation` owns the new shape, its form, its view and F: a click with the point tool, a closed tracing or a keyboard « Ajouter … » opens « Nouveau point / zone / accès », a modal without a history layer over the right column, mounted beside EditOnly so a read-only flip keeps it (« Créer », « Replacer », « Reprendre » off). A new zone or link is a creation from its first vertex. The ghost takes the form's category colour; the point tool previews under a mouse; the canvas carries data-creating (other markers dimmed, unselectable). « Replacer le point » / « Reprendre le tracé » hide the dialog and keep the form; the strip offers « Revenir aux propriétés », « Retirer le dernier sommet », « Abandonner ». « Créer »: one insert, tool back to « Sélectionner », the new element selected, « Point créé · Défaire », focus on its row. ✕, Échap, « Abandonner » and Back always ask « Abandonner la création ? » (DiscardConfirm inside the dialog; DrawingGuardDialog elsewhere); answerDrawing drops the creation. Undo, its shortcuts and the line's « Défaire » are inactive during a creation. missingFields replaces formProblem (MissingSummary shared with the edit form); the C26 notice has no numbers. CreationPanel, formProblem, withGeometry and the keys required.fields, required.names and create_cancel are gone; GeometryGroup is imported by RepairDialog only. Removed or rewritten assertions: - tab « holds a point at the frame centre »: « Centre x » = 50 -> the ghost circle cx = 50; plus tool back to Sélectionner, « Point créé », one undo step. - tab « refuses a creation without laterality »: the general line « Choisissez la catégorie et la latéralité » -> only « Choisissez une latéralité. » and « À compléter : Latéralité. », focus on it. - tab « applies the geometry group to a pending zone »: removed (A8, no coordinate field) -> « places a triangle at the centre: the ghost shows it, Créer inserts it »; vertex edits after Créer are the e2e keyboard test. - tab C26 « proposes C »: « x = 15, y = 15 » in the notice -> the R-4 text, the notice inside the dialog; cancel test « Centre x » = 0 -> ghost cx = 0. - tab « offers the correction when the core refuses a pending point » (typed cx 98): removed, no typed coordinate is possible; the verdict path stays covered by the C26 click tests and correctionFor units. - tab H5 « a typed radius shows the core issue »: removed (A8); the size refusal is the slider's (Task 4 tests). - tab H6 « a second click moves the pending point »: -> « Replacer le point », then the click moves the ghost, the form kept. - tab H7 « Centre x/y » = 30/50 -> ghost cx/cy. - tab tracing Enter: « x du sommet 3 » -> ghost points; « drops the tracing on Escape » -> Escape asks first (board 32 row 3), Continuer keeps, Abandonner drops; new « Annuler le tracé acts at once ». - keep-alive « a pending creation is kept and focused » and « a tracing … is kept and focused »: the tab now asks first (R-12) -> « Continuer » keeps the tracing / the form, « Abandonner » goes. - sections « its panel takes the focus » -> its dialog's [data-creation-focus] takes it. - no-loss « pending creation with its name » (hidden with the body) -> the dialog stays across the crossing, read-only, Créer off (R-14). - point-edit A5 « Rayon » = 7 / 9 -> ghost r = 7 / 9. - e2e editor-annotations keyboard test « numeric position » (cx field 250) -> UX_TESTS Keyboard: zone added, vertex added and removed, moved by the move mode, validated, saved. The « Fermer le tracé » step runs under expectNoShift again (shortcut removed). - e2e editor-geometry C26: the proposed x, y read from the notice text -> from the overlay's correction circle; the R-4 text checked in the dialog. - e2e editor-deselect « Escape cancels the tracing only » -> Escape asks, « Abandonner » cancels it, the selection kept. - e2e editor-shell-crossing « keeps its tool and its pending creation » (field hidden) -> the dialog stays read-only, Créer off, then editable on widening.
This commit is contained in:
1 parent
2d58da7d01
commit
4d2c64f57f
50 files changed
+3050
-1181
No files matched your search
@@ -1,4 +1,5 @@
|
||||
/** U2 Task 6: the Annotations tab with a real navigation, so its properties dialog opens. */
|
||||
import DrawingGuardDialog from '@/components/editor/annotations/DrawingGuardDialog'
|
||||
import AnnotationsTab, {
|
||||
type AnnotationsTabProps,
|
||||
} from '@/components/editor/tabs/AnnotationsTab'
|
||||
@@ -20,6 +21,8 @@ export function LayeredTab(
|
||||
return (
|
||||
<AnnounceContext value={nav.announce}>
|
||||
<AnnotationsTab {...props} annotationLayer={annotationLayerOf(nav)} />
|
||||
{/* The workspace's drawing question (R-12), as EditorWorkspace mounts it. */}
|
||||
<DrawingGuardDialog />
|
||||
<p data-testid="live-region">{nav.live}</p>
|
||||
</AnnounceContext>
|
||||
)
|
||||
|
||||
@@ -18,8 +18,11 @@ import {
|
||||
setModePreview,
|
||||
startMove,
|
||||
startRedraw,
|
||||
useAnnotationWork,
|
||||
} from '@/editor/annotations/workStore'
|
||||
import { useLeaveGuardStore } from '@/state/leaveGuardStore'
|
||||
import { emptyForm } from '@/editor/annotations/creation'
|
||||
import { traceVertex } from '@/editor/annotations/creationWork'
|
||||
|
||||
const user = fakeUser()
|
||||
const OTHER = 'bbbbbbbb-0000-0000-0000-000000000002'
|
||||
@@ -203,3 +206,44 @@ describe('SignOutButton and a started redraw (R-12)', () => {
|
||||
expect(screen.queryByRole('dialog')).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
describe('SignOutButton during a creation (R-12, A12)', () => {
|
||||
beforeEach(() => {
|
||||
useLeaveGuardStore.getState().setAsk(guardDrawing)
|
||||
// A tracing with one vertex: no dialog, a shape exists.
|
||||
traceVertex(
|
||||
{
|
||||
viewId: 'v',
|
||||
frame: null,
|
||||
origin: 'tool',
|
||||
form: emptyForm({ categories: [] } as never),
|
||||
},
|
||||
'zone',
|
||||
[1, 1],
|
||||
)
|
||||
})
|
||||
afterEach(() => {
|
||||
useLeaveGuardStore.getState().setAsk(null)
|
||||
resetWork()
|
||||
})
|
||||
|
||||
it('asks « Abandonner la création ? »; « Continuer » keeps it, « Abandonner » signs out', async () => {
|
||||
render(
|
||||
<MemoryRouter>
|
||||
<SignOutButton />
|
||||
<DrawingGuardDialog />
|
||||
</MemoryRouter>,
|
||||
)
|
||||
await click()
|
||||
expect(
|
||||
screen.getByRole('dialog', { name: 'Abandonner la création ?' }),
|
||||
).toBeInTheDocument()
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Continuer' }))
|
||||
expect(signOut).not.toHaveBeenCalled()
|
||||
expect(useAnnotationWork.getState().creation).not.toBeNull()
|
||||
await click()
|
||||
await userEvent.click(screen.getByRole('button', { name: 'Abandonner' }))
|
||||
await waitFor(() => expect(signOut).toHaveBeenCalledTimes(1))
|
||||
expect(useAnnotationWork.getState().creation).toBeNull()
|
||||
})
|
||||
})
|
||||
@@ -207,6 +207,7 @@ describe('an edit on the drawing (U2 Task 5: the numeric group left the panel)',
|
||||
})
|
||||
})
|
||||
|
||||
/** The creation dialog's form (U2 Task 7: no side panel, no coordinate field, A8). */
|
||||
async function fillCreation(user: ReturnType<typeof userEvent.setup>) {
|
||||
const panel = await screen.findByTestId('annotation-creation')
|
||||
await user.type(within(panel).getByLabelText('Nom (FR)'), 'Nuque')
|
||||
@@ -218,6 +219,10 @@ async function fillCreation(user: ReturnType<typeof userEvent.setup>) {
|
||||
return panel
|
||||
}
|
||||
|
||||
/** The ghost of the new shape: its filled shape, drawn by the overlay. */
|
||||
const ghostShape = () =>
|
||||
screen.getByTestId('overlay-ghost').querySelector('circle, polygon')!
|
||||
|
||||
describe('the keyboard creation path', () => {
|
||||
it('holds a point at the frame centre, asks the required fields, then inserts once', async () => {
|
||||
await mount({ text: drawnText() })
|
||||
@@ -228,8 +233,11 @@ describe('the keyboard creation path', () => {
|
||||
).toBeEnabled(),
|
||||
)
|
||||
await user.click(screen.getByRole('button', { name: 'Ajouter un point' }))
|
||||
expect(
|
||||
await screen.findByRole('dialog', { name: 'Nouveau point' }),
|
||||
).toBeInTheDocument()
|
||||
const panel = await fillCreation(user)
|
||||
expect(within(panel).getByLabelText('Centre x')).toHaveValue('50')
|
||||
expect(ghostShape()).toHaveAttribute('cx', '50')
|
||||
expect(within(panel).getByLabelText('Latéralité')).toHaveValue('unpaired')
|
||||
expect(annotations()).toHaveLength(0)
|
||||
await user.click(within(panel).getByRole('button', { name: 'Créer' }))
|
||||
@@ -240,10 +248,16 @@ describe('the keyboard creation path', () => {
|
||||
laterality: 'unpaired',
|
||||
geometry: { type: 'circle', cx: 50, cy: 50 },
|
||||
})
|
||||
// A7: the new point selected (the strip offers its properties).
|
||||
// A7: back to « Sélectionner », the new point selected, « Point créé · Défaire ».
|
||||
expect(
|
||||
await screen.findByRole('button', { name: 'Propriétés' }),
|
||||
).toBeInTheDocument()
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Sélectionner et déplacer' }),
|
||||
).toHaveAttribute('aria-pressed', 'true')
|
||||
expect(screen.getByTestId('gesture-line')).toHaveTextContent('Point créé')
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
|
||||
expect(store.getState().undo).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('refuses a creation without laterality and creates nothing', async () => {
|
||||
@@ -259,13 +273,22 @@ describe('the keyboard creation path', () => {
|
||||
await user.type(within(panel).getByLabelText('Nom (FR)'), 'A')
|
||||
await user.type(within(panel).getByLabelText('Nom (EN)'), 'B')
|
||||
await user.click(within(panel).getByRole('button', { name: 'Créer' }))
|
||||
expect(within(panel).getByRole('alert')).toHaveTextContent(
|
||||
'Choisissez la catégorie et la latéralité',
|
||||
)
|
||||
// R-3, board 33 B: only the missing field is named, under it and in the summary.
|
||||
const alerts = within(panel).getAllByRole('alert')
|
||||
expect(alerts.map((a) => a.textContent)).toEqual([
|
||||
'Choisissez une latéralité.',
|
||||
'À compléter : Latéralité.',
|
||||
])
|
||||
expect(
|
||||
within(panel).getByText('Choisissez une latéralité.'),
|
||||
).toBeInTheDocument()
|
||||
expect(within(panel).queryByText(/Choisissez une catégorie/)).toBeNull()
|
||||
expect(within(panel).queryByText(/Saisissez/)).toBeNull()
|
||||
expect(within(panel).getByLabelText('Latéralité')).toHaveFocus()
|
||||
expect(annotations()).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('applies the geometry group to a pending zone, the core deciding at « Créer »', async () => {
|
||||
it('places a triangle at the centre: the ghost shows it, « Créer » inserts it (A8: no field)', async () => {
|
||||
await mount({ text: drawnText() })
|
||||
const user = userEvent.setup()
|
||||
await waitFor(() =>
|
||||
@@ -275,14 +298,14 @@ describe('the keyboard creation path', () => {
|
||||
)
|
||||
await user.click(screen.getByRole('button', { name: 'Ajouter une zone' }))
|
||||
const panel = await fillCreation(user)
|
||||
const x = within(panel).getByLabelText('x du sommet 1')
|
||||
await user.clear(x)
|
||||
await user.type(x, '500{Enter}')
|
||||
expect(within(panel).getByLabelText('x du sommet 1')).toHaveValue('500')
|
||||
expect(within(panel).queryByLabelText('x du sommet 1')).toBeNull()
|
||||
expect(
|
||||
within(panel).getByText('Zone tracée, 3 sommets'),
|
||||
).toBeInTheDocument()
|
||||
expect(ghostShape().tagName).toBe('polygon')
|
||||
await user.click(within(panel).getByRole('button', { name: 'Créer' }))
|
||||
expect(annotations()).toHaveLength(0)
|
||||
expect(within(panel).getByRole('alert')).toBeInTheDocument()
|
||||
expect(within(panel).getByLabelText('x du sommet 1')).toHaveValue('500')
|
||||
expect(annotations()[0]).toMatchObject({ kind: 'zone' })
|
||||
expect(annotations()[0].geometry).toMatchObject({ type: 'polygon' })
|
||||
})
|
||||
})
|
||||
|
||||
@@ -301,8 +324,12 @@ describe('the point tool and the corrected position (C26)', () => {
|
||||
)
|
||||
const user = await clickCorner()
|
||||
const notice = await screen.findByTestId('correction-notice')
|
||||
// R-4: the notice is in the dialog, without numbers.
|
||||
expect(
|
||||
screen.getByRole('dialog', { name: 'Nouveau point' }),
|
||||
).toContainElement(notice)
|
||||
expect(notice).toHaveTextContent(
|
||||
'Position corrigée proposée : x = 15, y = 15.',
|
||||
"Le point ne tient pas à l'endroit choisi : la position corrigée est proposée sur le dessin.",
|
||||
)
|
||||
expect(screen.getByTestId('overlay-click-cross')).toBeInTheDocument()
|
||||
const panel = await fillCreation(user)
|
||||
@@ -316,7 +343,7 @@ describe('the point tool and the corrected position (C26)', () => {
|
||||
cy: 15,
|
||||
r: 15,
|
||||
})
|
||||
expect(panel).not.toBeInTheDocument()
|
||||
await waitFor(() => expect(panel).not.toBeInTheDocument())
|
||||
expect(screen.queryByTestId('overlay-click-cross')).toBeNull()
|
||||
await screen.findByRole('button', { name: 'Propriétés' })
|
||||
expect(shownCircle()).toHaveAttribute('cx', '15')
|
||||
@@ -332,28 +359,8 @@ describe('the point tool and the corrected position (C26)', () => {
|
||||
await user.click(within(notice).getByRole('button', { name: 'Annuler' }))
|
||||
expect(screen.queryByTestId('correction-notice')).toBeNull()
|
||||
expect(screen.queryByTestId('overlay-click-cross')).toBeNull()
|
||||
const panel = screen.getByTestId('annotation-creation')
|
||||
expect(within(panel).getByLabelText('Centre x')).toHaveValue('0')
|
||||
expect(annotations()).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('offers the correction when the core refuses a pending point', async () => {
|
||||
await mount({ text: drawnText() })
|
||||
const user = userEvent.setup()
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Ajouter un point' }),
|
||||
).toBeEnabled(),
|
||||
)
|
||||
await user.click(screen.getByRole('button', { name: 'Ajouter un point' }))
|
||||
const panel = await fillCreation(user)
|
||||
const cx = within(panel).getByLabelText('Centre x')
|
||||
await user.clear(cx)
|
||||
await user.type(cx, '98{Enter}')
|
||||
await user.click(within(panel).getByRole('button', { name: 'Créer' }))
|
||||
expect(await screen.findByTestId('correction-notice')).toHaveTextContent(
|
||||
'x = 85',
|
||||
)
|
||||
expect(screen.getByTestId('annotation-creation')).toBeInTheDocument()
|
||||
expect(ghostShape()).toHaveAttribute('cx', '0')
|
||||
expect(annotations()).toHaveLength(0)
|
||||
})
|
||||
|
||||
@@ -590,8 +597,11 @@ describe('tracing a zone or a link', () => {
|
||||
screen.getByRole('button', { name: 'Fermer le tracé' }),
|
||||
).toBeEnabled()
|
||||
fireEvent.keyDown(screen.getByTestId('annotation-canvas'), { key: 'Enter' })
|
||||
expect(
|
||||
await screen.findByRole('dialog', { name: 'Nouvelle zone' }),
|
||||
).toBeInTheDocument()
|
||||
const panel = await fillCreation(user)
|
||||
expect(within(panel).getByLabelText('x du sommet 3')).toHaveValue('50')
|
||||
expect(ghostShape()).toHaveAttribute('points', triangle.join(' '))
|
||||
await user.click(within(panel).getByRole('button', { name: 'Créer' }))
|
||||
expect(annotations()[0]).toMatchObject({
|
||||
kind: 'zone',
|
||||
@@ -599,21 +609,48 @@ describe('tracing a zone or a link', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('drops the tracing on Escape with nothing created', async () => {
|
||||
it('Escape on a tracing asks first (board 32 row 3); « Abandonner » drops it', async () => {
|
||||
await mount({ text: drawnText() })
|
||||
await waitFor(() =>
|
||||
expect(screen.getByRole('button', { name: 'Zone' })).toBeEnabled(),
|
||||
)
|
||||
await userEvent.setup().click(screen.getByRole('button', { name: 'Zone' }))
|
||||
const user = userEvent.setup()
|
||||
await user.click(screen.getByRole('button', { name: 'Zone' }))
|
||||
clickAt(20, 20)
|
||||
expect(screen.getByText('1 sommet posé')).toBeInTheDocument()
|
||||
fireEvent.keyDown(screen.getByTestId('annotation-canvas'), {
|
||||
key: 'Escape',
|
||||
})
|
||||
const ask = await screen.findByRole('dialog', {
|
||||
name: 'Abandonner la création ?',
|
||||
})
|
||||
await user.click(within(ask).getByRole('button', { name: 'Continuer' }))
|
||||
expect(screen.getByText('1 sommet posé')).toBeInTheDocument()
|
||||
fireEvent.keyDown(screen.getByTestId('annotation-canvas'), {
|
||||
key: 'Escape',
|
||||
})
|
||||
await user.click(
|
||||
within(
|
||||
await screen.findByRole('dialog', { name: 'Abandonner la création ?' }),
|
||||
).getByRole('button', { name: 'Abandonner' }),
|
||||
)
|
||||
expect(screen.queryByText('1 sommet posé')).toBeNull()
|
||||
expect(annotations()).toHaveLength(0)
|
||||
})
|
||||
|
||||
it('« Annuler le tracé » is an explicit cancel: it acts at once', async () => {
|
||||
await mount({ text: drawnText() })
|
||||
await waitFor(() =>
|
||||
expect(screen.getByRole('button', { name: 'Zone' })).toBeEnabled(),
|
||||
)
|
||||
const user = userEvent.setup()
|
||||
await user.click(screen.getByRole('button', { name: 'Zone' }))
|
||||
clickAt(20, 20)
|
||||
await user.click(screen.getByRole('button', { name: 'Annuler le tracé' }))
|
||||
expect(screen.queryByRole('dialog')).toBeNull()
|
||||
expect(screen.queryByText('1 sommet posé')).toBeNull()
|
||||
})
|
||||
|
||||
it('closes on a click at the first vertex once three are placed', async () => {
|
||||
await mount({ text: drawnText() })
|
||||
await waitFor(() =>
|
||||
@@ -792,42 +829,17 @@ describe('a second click with the point tool (H6)', () => {
|
||||
await user.click(screen.getByRole('button', { name: 'Point' }))
|
||||
pressAt(screen.getByTestId('annotation-canvas'), 50, 50)
|
||||
const panel = await fillCreation(user)
|
||||
// « Replacer le point »: the dialog hides, the next click moves the ghost and shows it.
|
||||
await user.click(
|
||||
within(panel).getByRole('button', { name: 'Replacer le point' }),
|
||||
)
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
|
||||
expect(ghostShape()).toHaveAttribute('cx', '50')
|
||||
pressAt(screen.getByTestId('annotation-canvas'), 60, 40)
|
||||
await waitFor(() =>
|
||||
expect(within(panel).getByLabelText('Centre x')).toHaveValue('60'),
|
||||
)
|
||||
expect(within(panel).getByLabelText('Nom (FR)')).toHaveValue('Nuque')
|
||||
expect(within(panel).getByLabelText('Latéralité')).toHaveValue('unpaired')
|
||||
expect(screen.getByTestId('annotation-creation')).toBe(panel)
|
||||
})
|
||||
})
|
||||
|
||||
describe('a typed radius (H5)', () => {
|
||||
it('shows the core issue, not a corrected position', async () => {
|
||||
const drawing = svgBytes('0 0 5000 5000')
|
||||
sb.getSheetVersion.mockResolvedValue({
|
||||
...versionAnswer(drawnText(), 3),
|
||||
drawings: [{ asset_id: ASSET, sha256: drawing.sha256 }],
|
||||
} as never)
|
||||
sb.downloadSheetDrawing.mockResolvedValue(drawing.bytes)
|
||||
store.getState().open(VERSION, USER, { canEdit: true })
|
||||
await waitFor(() => expect(store.getState().status).toBe('ready'))
|
||||
render(<AnnotationsTab {...props} />)
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Ajouter un point' }),
|
||||
).toBeEnabled(),
|
||||
)
|
||||
const user = userEvent.setup()
|
||||
await user.click(screen.getByRole('button', { name: 'Ajouter un point' }))
|
||||
const panel = await fillCreation(user)
|
||||
const r = within(panel).getByLabelText('Rayon')
|
||||
await user.clear(r)
|
||||
await user.type(r, '1{Enter}')
|
||||
await user.click(within(panel).getByRole('button', { name: 'Créer' }))
|
||||
expect(screen.queryByTestId('correction-notice')).toBeNull()
|
||||
expect(within(panel).getByRole('alert')).toBeInTheDocument()
|
||||
expect(annotations()).toHaveLength(0)
|
||||
const again = await screen.findByTestId('annotation-creation')
|
||||
expect(ghostShape()).toHaveAttribute('cx', '60')
|
||||
expect(within(again).getByLabelText('Nom (FR)')).toHaveValue('Nuque')
|
||||
expect(within(again).getByLabelText('Latéralité')).toHaveValue('unpaired')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -853,9 +865,9 @@ describe('the frame follows the view (H7)', () => {
|
||||
).toBeEnabled(),
|
||||
)
|
||||
await user.click(screen.getByRole('button', { name: 'Ajouter un point' }))
|
||||
const panel = await screen.findByTestId('annotation-creation')
|
||||
expect(within(panel).getByLabelText('Centre x')).toHaveValue('30')
|
||||
expect(within(panel).getByLabelText('Centre y')).toHaveValue('50')
|
||||
await screen.findByTestId('annotation-creation')
|
||||
expect(ghostShape()).toHaveAttribute('cx', '30')
|
||||
expect(ghostShape()).toHaveAttribute('cy', '50')
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1870,6 +1882,7 @@ describe('the strip', () => {
|
||||
const { result } = renderHook(() =>
|
||||
usePlacement({
|
||||
ui: { ...initialUi, hint: 'Refusé' },
|
||||
tracing: null,
|
||||
dispatch,
|
||||
frame: null,
|
||||
doc,
|
||||
|
||||
@@ -0,0 +1,314 @@
|
||||
/** U2 Task 7: creation on the drawing, then the creation dialog (A2, A4, A5, A7, A12, A15). */
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
act,
|
||||
cleanup,
|
||||
fireEvent,
|
||||
render,
|
||||
screen,
|
||||
waitFor,
|
||||
within,
|
||||
} from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import HistoryButtons from '@/components/editor/HistoryButtons'
|
||||
import { useUndoShortcuts } from '@/editor/useUndoShortcuts'
|
||||
import { useAnnotationWork } from '@/editor/annotations/workStore'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { drawnText, insert, point } from '../helpers/editorFixtures'
|
||||
import { LayeredTab } from '../helpers/annotationLayer'
|
||||
import { openReady, pressAt, resetStore, store } from '../helpers/editorHarness'
|
||||
|
||||
vi.mock('@/lib/supabase', () => ({ getSupabaseClient: () => ({}) }))
|
||||
vi.mock('@faunosteo/supabase', async (orig) => ({
|
||||
...(await orig<typeof import('@faunosteo/supabase')>()),
|
||||
getSheetVersion: vi.fn(),
|
||||
downloadSheetDrawing: vi.fn(),
|
||||
saveSheetDraft: vi.fn(),
|
||||
getOfficialSheetAdmin: vi.fn(),
|
||||
submitSheetReview: vi.fn(),
|
||||
}))
|
||||
|
||||
const props = {
|
||||
readOnly: false,
|
||||
navigate: vi.fn(),
|
||||
reloadSheet: vi.fn(),
|
||||
section: 'drawing' as const,
|
||||
visited: ['drawing'] as const,
|
||||
onOpenSection: vi.fn(),
|
||||
onBack: vi.fn(),
|
||||
}
|
||||
|
||||
/** Screen = drawing: the overlay's inverse CTM is the identity in the page under test. */
|
||||
function stubCtm(): void {
|
||||
const identity = { a: 1, b: 0, c: 0, d: 1, e: 0, f: 0 }
|
||||
Object.defineProperty(window.SVGElement.prototype, 'getScreenCTM', {
|
||||
configurable: true,
|
||||
value: () => ({ ...identity, inverse: () => identity }),
|
||||
})
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
stubCtm()
|
||||
})
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
resetStore()
|
||||
})
|
||||
|
||||
/** A second category, coloured, so the ghost's colour can follow the form (A4). */
|
||||
function twoCategories(): string {
|
||||
return insert(insert(drawnText(), point('anno-a', 20, 20, 5)), {
|
||||
kind: 'category',
|
||||
value: { id: 'cat-b', name: { fr: 'Os', en: 'Bone' }, color: '#aa3366' },
|
||||
} as never)
|
||||
}
|
||||
|
||||
/** The tab with the header's history controls, as the workspace shows them. */
|
||||
function Page() {
|
||||
useUndoShortcuts(true)
|
||||
return (
|
||||
<>
|
||||
<HistoryButtons />
|
||||
<LayeredTab {...props} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
async function mount(text = twoCategories()) {
|
||||
await openReady({ text })
|
||||
render(<Page />)
|
||||
await waitFor(() =>
|
||||
expect(screen.getByRole('button', { name: 'Point' })).toBeEnabled(),
|
||||
)
|
||||
return userEvent.setup()
|
||||
}
|
||||
|
||||
const canvas = () => screen.getByTestId('annotation-canvas')
|
||||
const ghost = () => screen.getByTestId('overlay-ghost')
|
||||
const creation = () => useAnnotationWork.getState().creation
|
||||
const annotations = () => store.getState().previewState!.document.annotations
|
||||
const dialog = (name = 'Nouveau point') => screen.findByRole('dialog', { name })
|
||||
|
||||
async function placePoint(user: ReturnType<typeof userEvent.setup>) {
|
||||
await user.click(screen.getByRole('button', { name: 'Point' }))
|
||||
pressAt(canvas(), 50, 50)
|
||||
return dialog()
|
||||
}
|
||||
|
||||
describe('the creation dialog asks before leaving, always (A12)', () => {
|
||||
it('✕ with nothing typed asks; « Continuer » keeps the shape', async () => {
|
||||
const user = await mount()
|
||||
const shown = await placePoint(user)
|
||||
await user.click(within(shown).getByRole('button', { name: 'Fermer' }))
|
||||
const ask = within(shown).getByRole('group', {
|
||||
name: 'Abandonner la création ?',
|
||||
})
|
||||
await user.click(within(ask).getByRole('button', { name: 'Continuer' }))
|
||||
expect(screen.getByRole('dialog', { name: 'Nouveau point' })).toBe(shown)
|
||||
expect(creation()).not.toBeNull()
|
||||
expect(ghost()).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('Échap with nothing typed asks inside the dialog, never the workspace question', async () => {
|
||||
const user = await mount()
|
||||
const shown = await placePoint(user)
|
||||
await user.keyboard('{Escape}')
|
||||
expect(
|
||||
within(shown).getByRole('group', { name: 'Abandonner la création ?' }),
|
||||
).toBeInTheDocument()
|
||||
expect(screen.getAllByRole('dialog')).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('« Abandonner » asks, then clears the creation; the focus goes to the tool', async () => {
|
||||
const user = await mount()
|
||||
const shown = await placePoint(user)
|
||||
await user.click(within(shown).getByRole('button', { name: 'Abandonner' }))
|
||||
expect(creation()).not.toBeNull()
|
||||
const ask = within(shown).getByRole('group', {
|
||||
name: 'Abandonner la création ?',
|
||||
})
|
||||
await user.click(within(ask).getByRole('button', { name: 'Abandonner' }))
|
||||
expect(creation()).toBeNull()
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
|
||||
expect(screen.queryByTestId('overlay-ghost')).toBeNull()
|
||||
await waitFor(() =>
|
||||
expect(screen.getByRole('button', { name: 'Point' })).toHaveFocus(),
|
||||
)
|
||||
expect(annotations()).toHaveLength(1)
|
||||
})
|
||||
|
||||
it('a keyboard creation abandoned gives the focus back to its « Ajouter … » button', async () => {
|
||||
const user = await mount()
|
||||
await user.click(screen.getByRole('button', { name: 'Ajouter une zone' }))
|
||||
const shown = await dialog('Nouvelle zone')
|
||||
await user.click(within(shown).getByRole('button', { name: 'Abandonner' }))
|
||||
await user.click(
|
||||
within(
|
||||
within(shown).getByRole('group', { name: 'Abandonner la création ?' }),
|
||||
).getByRole('button', { name: 'Abandonner' }),
|
||||
)
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Ajouter une zone' }),
|
||||
).toHaveFocus(),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('placing and the form (A4, A5)', () => {
|
||||
it('the category prefilled, the laterality without default; a category recolours the ghost', async () => {
|
||||
const user = await mount()
|
||||
const shown = await placePoint(user)
|
||||
expect(within(shown).getByLabelText('Catégorie')).toHaveValue('cat-a')
|
||||
expect(within(shown).getByLabelText('Latéralité')).toHaveValue('')
|
||||
expect(within(shown).queryByLabelText('Couleur')).toBeNull()
|
||||
expect(ghost()).toHaveAttribute('data-colour', 'var(--color-accent)')
|
||||
await user.selectOptions(within(shown).getByLabelText('Catégorie'), 'cat-b')
|
||||
expect(ghost()).toHaveAttribute('data-colour', '#aa3366')
|
||||
})
|
||||
|
||||
it('the point tool previews the next point under a mouse, never under a finger', async () => {
|
||||
const user = await mount()
|
||||
await user.click(screen.getByRole('button', { name: 'Point' }))
|
||||
const at = { clientX: 40, clientY: 30 }
|
||||
fireEvent.pointerMove(canvas(), { ...at, pointerType: 'touch' })
|
||||
expect(screen.queryByTestId('overlay-point-preview')).toBeNull()
|
||||
fireEvent.pointerMove(canvas(), { ...at, pointerType: 'mouse' })
|
||||
const preview = screen.getByTestId('overlay-point-preview')
|
||||
// A5: the view's most used size (the only point has r = 5).
|
||||
expect(preview.querySelector('circle')).toHaveAttribute('r', '5')
|
||||
expect(preview.querySelector('circle')).toHaveAttribute('cx', '40')
|
||||
fireEvent.pointerLeave(canvas())
|
||||
expect(screen.queryByTestId('overlay-point-preview')).toBeNull()
|
||||
})
|
||||
|
||||
it('a link shows « Vue ouverte »', async () => {
|
||||
const text = insert(twoCategories(), {
|
||||
kind: 'view',
|
||||
value: {
|
||||
kind: 'detail',
|
||||
id: 'view-det',
|
||||
name: { fr: 'Tête', en: 'Head' },
|
||||
svg_asset_id: null,
|
||||
view_box: { min_x: 10, min_y: 10, width: 80, height: 80 },
|
||||
parent_view_id: 'view-main',
|
||||
},
|
||||
} as never)
|
||||
const user = await mount(text)
|
||||
await user.click(screen.getByRole('button', { name: 'Ajouter un accès' }))
|
||||
const shown = await dialog('Nouvel accès')
|
||||
expect(within(shown).getByLabelText('Vue ouverte')).toBeInTheDocument()
|
||||
expect(
|
||||
within(shown).getByText('Accès tracé, 3 sommets'),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('« Reprendre le tracé » and « Revenir aux propriétés » (board 04 C)', () => {
|
||||
it('keeps the vertices and the form; a new vertex, then the dialog again', async () => {
|
||||
const user = await mount()
|
||||
await user.click(screen.getByRole('button', { name: 'Zone' }))
|
||||
;[
|
||||
[20, 20],
|
||||
[80, 20],
|
||||
[50, 80],
|
||||
].forEach(([x, y]) => pressAt(canvas(), x, y))
|
||||
await user.click(screen.getByRole('button', { name: 'Fermer le tracé' }))
|
||||
let shown = await dialog('Nouvelle zone')
|
||||
await user.type(within(shown).getByLabelText('Nom (FR)'), 'Tibia')
|
||||
await user.click(
|
||||
within(shown).getByRole('button', { name: 'Reprendre le tracé' }),
|
||||
)
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
|
||||
const strip = screen.getByTestId('edit-strip')
|
||||
expect(strip).toHaveTextContent('Tracé repris, saisie gardée')
|
||||
expect(
|
||||
within(strip).getByRole('button', { name: 'Retirer le dernier sommet' }),
|
||||
).toBeEnabled()
|
||||
pressAt(canvas(), 30, 60)
|
||||
await user.click(
|
||||
within(strip).getByRole('button', { name: 'Revenir aux propriétés' }),
|
||||
)
|
||||
shown = await dialog('Nouvelle zone')
|
||||
expect(within(shown).getByLabelText('Nom (FR)')).toHaveValue('Tibia')
|
||||
expect(
|
||||
within(shown).getByText('Zone tracée, 4 sommets'),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
|
||||
describe('« Créer » (A7, board 32)', () => {
|
||||
it('one insert, one undo; « Sélectionner », the new zone selected, its row focused', async () => {
|
||||
const user = await mount()
|
||||
await user.click(screen.getByRole('button', { name: 'Zone' }))
|
||||
;[
|
||||
[20, 20],
|
||||
[80, 20],
|
||||
[50, 80],
|
||||
].forEach(([x, y]) => pressAt(canvas(), x, y))
|
||||
fireEvent.keyDown(canvas(), { key: 'Enter' })
|
||||
const shown = await dialog('Nouvelle zone')
|
||||
await user.type(within(shown).getByLabelText('Nom (FR)'), 'Tibia')
|
||||
await user.type(within(shown).getByLabelText('Nom (EN)'), 'Tibia')
|
||||
await user.selectOptions(within(shown).getByLabelText('Latéralité'), 'left')
|
||||
const before = store.getState().undo.length
|
||||
await user.click(within(shown).getByRole('button', { name: 'Créer' }))
|
||||
expect(store.getState().undo).toHaveLength(before + 1)
|
||||
const created = annotations().find((a) => a.kind === 'zone')!
|
||||
expect(created).toMatchObject({ name: { fr: 'Tibia', en: 'Tibia' } })
|
||||
expect(screen.getByTestId('gesture-line')).toHaveTextContent('Zone créée')
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Sélectionner et déplacer' }),
|
||||
).toHaveAttribute('aria-pressed', 'true')
|
||||
await waitFor(() =>
|
||||
expect(document.activeElement).toHaveAttribute(
|
||||
'data-focus-key',
|
||||
JSON.stringify({ kind: 'annotation', id: created.id }),
|
||||
),
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('during a creation (A12, R-13)', () => {
|
||||
it('the other markers are dimmed; undo is inactive; « Défaire » leaves the line', async () => {
|
||||
const user = await mount()
|
||||
// A kept gesture first, so the line under the drawing offers « Défaire ».
|
||||
await user.click(screen.getByRole('button', { name: 'Point' }))
|
||||
pressAt(canvas(), 50, 50)
|
||||
const shown = await dialog()
|
||||
await user.type(within(shown).getByLabelText('Nom (FR)'), 'A')
|
||||
await user.type(within(shown).getByLabelText('Nom (EN)'), 'B')
|
||||
await user.selectOptions(within(shown).getByLabelText('Latéralité'), 'left')
|
||||
await user.click(within(shown).getByRole('button', { name: 'Créer' }))
|
||||
const line = screen.getByTestId('gesture-line')
|
||||
expect(within(line).getByRole('button', { name: /Défaire/ })).toBeTruthy()
|
||||
expect(canvas()).not.toHaveAttribute('data-creating')
|
||||
// A tracing: no dialog, the page itself is live.
|
||||
await user.click(screen.getByRole('button', { name: 'Zone' }))
|
||||
pressAt(canvas(), 20, 80)
|
||||
expect(canvas()).toHaveAttribute('data-creating')
|
||||
expect(within(line).queryByRole('button', { name: /Défaire/ })).toBeNull()
|
||||
const undo = screen.getByRole('button', { name: /Défaire la dernière/ })
|
||||
expect(undo).toHaveAttribute('aria-disabled', 'true')
|
||||
const depth = store.getState().undo.length
|
||||
await user.click(undo)
|
||||
fireEvent.keyDown(window, { key: 'z', ctrlKey: true })
|
||||
expect(store.getState().undo).toHaveLength(depth)
|
||||
expect(creation()).not.toBeNull()
|
||||
})
|
||||
|
||||
it('Escape while the point is replaced asks « Abandonner la création ? »', async () => {
|
||||
const user = await mount()
|
||||
const shown = await placePoint(user)
|
||||
await user.click(
|
||||
within(shown).getByRole('button', { name: 'Replacer le point' }),
|
||||
)
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
|
||||
act(() => canvas().focus())
|
||||
fireEvent.keyDown(document.body, { key: 'Escape' })
|
||||
expect(
|
||||
await screen.findByRole('dialog', { name: 'Abandonner la création ?' }),
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
})
|
||||
@@ -28,12 +28,22 @@ import { defaultView, targetOfKey } from '@/editor/navigation'
|
||||
import { useEditorNavigation } from '@/editor/useEditorNavigation'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import DrawingGuardDialog from '@/components/editor/annotations/DrawingGuardDialog'
|
||||
import CreationDialog from '@/components/editor/annotations/CreationDialog'
|
||||
import { drawnText } from '../helpers/editorFixtures'
|
||||
import {
|
||||
markRedraw,
|
||||
resetWork,
|
||||
setModePreview,
|
||||
startMove,
|
||||
startRedraw,
|
||||
useAnnotationWork,
|
||||
} from '@/editor/annotations/workStore'
|
||||
import { emptyForm } from '@/editor/annotations/creation'
|
||||
import {
|
||||
placePending,
|
||||
replacePoint,
|
||||
traceVertex,
|
||||
} from '@/editor/annotations/creationWork'
|
||||
|
||||
afterEach(cleanup)
|
||||
|
||||
@@ -477,6 +487,212 @@ describe('the drawing guard (R-12): a move mode and the navigations', () => {
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* U2 Task 7 (R-12, A12): every guard site asks during a creation, and for a move mode or a
|
||||
* redraw once work has started; with nothing started a mode ends at once.
|
||||
*/
|
||||
describe('the drawing guard at every site: creation, move, redraw', () => {
|
||||
const STORED = { type: 'circle' as const, cx: 1, cy: 2, r: 3 }
|
||||
afterEach(() => act(() => resetWork()))
|
||||
const tabShown = () => screen.getByRole('tab', { selected: true })
|
||||
const start = {
|
||||
viewId: 'v',
|
||||
frame: null,
|
||||
origin: 'tool' as const,
|
||||
form: emptyForm({ categories: [] } as never),
|
||||
}
|
||||
const point = {
|
||||
kind: 'point' as const,
|
||||
geometry: { type: 'circle' as const, cx: 5, cy: 5, r: 2 },
|
||||
}
|
||||
const WORK = {
|
||||
// A point being replaced: no dialog, nothing typed, still asked (A12).
|
||||
creation: () => {
|
||||
placePending(start, point)
|
||||
replacePoint()
|
||||
},
|
||||
tracing: () => traceVertex(start, 'zone', [1, 1]),
|
||||
move: () => {
|
||||
startMove('a', 'doc')
|
||||
setModePreview({ ...STORED, cx: 9 }, STORED)
|
||||
},
|
||||
redraw: () => {
|
||||
startRedraw('a', 'doc')
|
||||
markRedraw(true)
|
||||
},
|
||||
}
|
||||
const TITLE = {
|
||||
creation: 'Abandonner la création ?',
|
||||
tracing: 'Abandonner la création ?',
|
||||
move: 'Abandonner le déplacement ?',
|
||||
redraw: 'Abandonner le nouveau tracé ?',
|
||||
}
|
||||
const left = () => {
|
||||
const work = useAnnotationWork.getState()
|
||||
return work.creation === null && work.mode === null
|
||||
}
|
||||
type Kind = keyof typeof WORK
|
||||
const kinds = Object.keys(WORK) as Kind[]
|
||||
|
||||
async function asks(kind: Kind, run: () => Promise<void>) {
|
||||
const user = userEvent.setup()
|
||||
await run()
|
||||
const dialog = screen.getByRole('dialog', { name: TITLE[kind] })
|
||||
await user.click(within(dialog).getByRole('button', { name: 'Continuer' }))
|
||||
expect(left()).toBe(false)
|
||||
return user
|
||||
}
|
||||
|
||||
it.each(kinds)(
|
||||
'%s: a tab click asks; « Continuer » keeps, « Abandonner » goes',
|
||||
async (kind) => {
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
mount()
|
||||
act(() => WORK[kind]())
|
||||
const user = await asks(kind, () =>
|
||||
userEvent.setup().click(screen.getByRole('tab', { name: 'Constats' })),
|
||||
)
|
||||
expect(tabShown()).toHaveTextContent('Général')
|
||||
await user.click(screen.getByRole('tab', { name: 'Constats' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Abandonner' }))
|
||||
expect(tabShown()).toHaveTextContent('Constats')
|
||||
expect(left()).toBe(true)
|
||||
},
|
||||
)
|
||||
|
||||
it.each(kinds)(
|
||||
'%s: an arrow-key tab move asks the same way',
|
||||
async (kind) => {
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
mount()
|
||||
const general = screen.getByRole('tab', { name: 'Général' })
|
||||
act(() => general.focus())
|
||||
act(() => WORK[kind]())
|
||||
await asks(kind, async () => {
|
||||
fireEvent.keyDown(general, { key: 'ArrowRight' })
|
||||
})
|
||||
expect(tabShown()).toHaveTextContent('Général')
|
||||
},
|
||||
)
|
||||
|
||||
it.each(kinds)('%s: a section entry asks the same way', async (kind) => {
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
mount()
|
||||
act(() => WORK[kind]())
|
||||
const user = await asks(kind, () =>
|
||||
userEvent.setup().click(screen.getByRole('button', { name: 'section' })),
|
||||
)
|
||||
await user.click(screen.getByRole('button', { name: 'section' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Abandonner' }))
|
||||
expect(left()).toBe(true)
|
||||
})
|
||||
|
||||
it.each(kinds)('%s: a Back asks and keeps the view', async (kind) => {
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
const user = userEvent.setup()
|
||||
mount()
|
||||
await user.click(screen.getByRole('tab', { name: 'Constats' }))
|
||||
act(() => WORK[kind]())
|
||||
act(() => navigate(-1))
|
||||
expect(tabShown()).toHaveTextContent('Constats')
|
||||
await user.click(
|
||||
within(screen.getByRole('dialog', { name: TITLE[kind] })).getByRole(
|
||||
'button',
|
||||
{ name: 'Abandonner' },
|
||||
),
|
||||
)
|
||||
expect(left()).toBe(true)
|
||||
})
|
||||
|
||||
it.each(['move', 'redraw'] as const)(
|
||||
'%s with nothing started: tab, arrow key and section act at once',
|
||||
async (kind) => {
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
const user = userEvent.setup()
|
||||
mount()
|
||||
const begin = () =>
|
||||
kind === 'move' ? startMove('a', 'doc') : startRedraw('a', 'doc')
|
||||
act(() => begin())
|
||||
const general = screen.getByRole('tab', { name: 'Général' })
|
||||
act(() => general.focus())
|
||||
fireEvent.keyDown(general, { key: 'ArrowRight' })
|
||||
expect(tabShown()).not.toHaveTextContent('Général')
|
||||
expect(useAnnotationWork.getState().mode).toBeNull()
|
||||
act(() => begin())
|
||||
await user.click(screen.getByRole('button', { name: 'section' }))
|
||||
expect(useAnnotationWork.getState().mode).toBeNull()
|
||||
expect(screen.queryByRole('dialog')).toBeNull()
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
/**
|
||||
* U2 Task 7: the creation dialog is a modal without a history layer. A Back while it is
|
||||
* open is refused, and its « Abandonner la création ? » shows inside it. (Under happy-dom
|
||||
* the refusal is reached through the drawing guard; the browser's modal branch is proved
|
||||
* by the e2e in editor-annotations.spec.ts.)
|
||||
*/
|
||||
describe('a Back on the creation dialog', () => {
|
||||
afterEach(() => act(() => resetWork()))
|
||||
const doc = JSON.parse(drawnText())
|
||||
function CreationPage() {
|
||||
const nav = useEditorNavigation('annotations')
|
||||
navigate = useNavigate()
|
||||
location = useLocation()
|
||||
useEditorHistory(nav, owner, defaultView('annotations'))
|
||||
return (
|
||||
<>
|
||||
<EditorTabs
|
||||
active={nav.state.tab}
|
||||
tier="wide"
|
||||
onSelect={nav.selectTab}
|
||||
/>
|
||||
<CreationDialog doc={doc} readOnly={false} anchor={{ current: null }} />
|
||||
<DrawingGuardDialog />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
it('with nothing typed it asks inside the dialog; « Continuer » keeps the shape', async () => {
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
const user = userEvent.setup()
|
||||
render(
|
||||
<MemoryRouter initialEntries={['/x']}>
|
||||
<CreationPage />
|
||||
</MemoryRouter>,
|
||||
)
|
||||
// An entry of this editor to go Back to.
|
||||
await user.click(screen.getByRole('tab', { name: 'Constats' }))
|
||||
act(() =>
|
||||
placePending(
|
||||
{
|
||||
viewId: 'view-main',
|
||||
frame: null,
|
||||
origin: 'tool',
|
||||
form: emptyForm(doc),
|
||||
},
|
||||
{ kind: 'point', geometry: { type: 'circle', cx: 50, cy: 50, r: 5 } },
|
||||
),
|
||||
)
|
||||
const dialog = await screen.findByRole('dialog', { name: 'Nouveau point' })
|
||||
act(() => navigate(-1))
|
||||
const ask = within(dialog).getByRole('group', {
|
||||
name: 'Abandonner la création ?',
|
||||
})
|
||||
// One question, inside the dialog: the workspace's own stays closed.
|
||||
expect(screen.getAllByRole('dialog')).toHaveLength(1)
|
||||
await user.click(within(ask).getByRole('button', { name: 'Continuer' }))
|
||||
expect(useAnnotationWork.getState().creation).not.toBeNull()
|
||||
expect(
|
||||
within(dialog).queryByRole('group', { name: /Abandonner/ }),
|
||||
).toBeNull()
|
||||
act(() => navigate(-1))
|
||||
await user.click(within(dialog).getByRole('button', { name: 'Abandonner' }))
|
||||
expect(useAnnotationWork.getState().creation).toBeNull()
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
|
||||
})
|
||||
})
|
||||
|
||||
/** U2 Task 6: the annotation properties dialog is a layer of the browser history. */
|
||||
describe('the annotation layer and the history', () => {
|
||||
function AnnotationPage({ dirty }: { dirty: boolean }) {
|
||||
|
||||
@@ -469,49 +469,38 @@ describe('a request reaches only its owner', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('« Aller à » while a creation or a tracing is in progress', () => {
|
||||
const liveText = () =>
|
||||
document.querySelector('p[aria-live="polite"]')?.textContent ?? ''
|
||||
|
||||
describe('a tab while a creation or a tracing is in progress', () => {
|
||||
function bareAnnotationText(): string {
|
||||
const bare = point('anno-bare', 10, 10, 2)
|
||||
const value = { ...bare.value, geometry: null, name: name('Sans tracé') }
|
||||
return insert(drawnText(), { kind: 'annotation', value } as typeof bare)
|
||||
}
|
||||
|
||||
async function gotoBare(
|
||||
user: ReturnType<typeof userEvent.setup>,
|
||||
start: () => Promise<void>,
|
||||
) {
|
||||
// U2 Task 7 (R-12, A12): a creation no longer waits for « Aller à » in the background;
|
||||
// the tab that would leave it asks first. « Continuer » keeps it, « Abandonner » goes.
|
||||
it('a tracing from the Zone tool: the tab asks first, « Continuer » keeps it', async () => {
|
||||
const user = await mount(bareAnnotationText())
|
||||
const drawing = inPlace('annotations.drawing')
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
inPlace('annotations.drawing').getByRole('button', { name: 'Zone' }),
|
||||
).toBeEnabled(),
|
||||
expect(drawing.getByRole('button', { name: 'Zone' })).toBeEnabled(),
|
||||
)
|
||||
await start()
|
||||
await user.click(drawing.getByRole('button', { name: 'Zone' }))
|
||||
pressAt(screen.getByTestId('annotation-canvas'), 20, 20)
|
||||
await user.click(tab(/Vérification/))
|
||||
const ask = await screen.findByRole('dialog', {
|
||||
name: 'Abandonner la création ?',
|
||||
})
|
||||
await user.click(within(ask).getByRole('button', { name: 'Continuer' }))
|
||||
expect(tab('Annotations')).toHaveAttribute('aria-selected', 'true')
|
||||
expect(drawing.getByTestId('tracing-commands')).toBeVisible()
|
||||
await user.click(tab(/Vérification/))
|
||||
await user.click(
|
||||
inPlace('verification').getAllByRole('button', {
|
||||
name: 'Aller à Sans tracé',
|
||||
})[0],
|
||||
within(
|
||||
await screen.findByRole('dialog', { name: 'Abandonner la création ?' }),
|
||||
).getByRole('button', { name: 'Abandonner' }),
|
||||
)
|
||||
}
|
||||
|
||||
it('a tracing from the Zone tool is kept and focused', async () => {
|
||||
const user = await mount(bareAnnotationText())
|
||||
await gotoBare(user, async () => {
|
||||
await user.click(
|
||||
inPlace('annotations.drawing').getByRole('button', { name: 'Zone' }),
|
||||
)
|
||||
pressAt(screen.getByTestId('annotation-canvas'), 20, 20)
|
||||
})
|
||||
expect(tab('Annotations')).toHaveAttribute('aria-selected', 'true')
|
||||
const bar = within(place('annotations.drawing')).getByTestId(
|
||||
'tracing-commands',
|
||||
)
|
||||
expect(bar).toBeVisible()
|
||||
await waitFor(() => expect(document.activeElement).toBe(bar))
|
||||
expect(liveText()).toContain('tracé est en cours')
|
||||
expect(tab(/Vérification/)).toHaveAttribute('aria-selected', 'true')
|
||||
expect(useAnnotationWork.getState().creation).toBeNull()
|
||||
})
|
||||
|
||||
// U2 Task 5 (R-12): « Remplacer par un polygone » is a redraw mode. With nothing placed a
|
||||
@@ -557,22 +546,32 @@ describe('« Aller à » while a creation or a tracing is in progress', () => {
|
||||
expect(drawing.getByTestId('tracing-commands')).toBeVisible()
|
||||
})
|
||||
|
||||
it('a pending creation is kept and focused', async () => {
|
||||
it('a point being replaced (dialog hidden): the tab asks, « Continuer » keeps the form', async () => {
|
||||
const user = await mount(bareAnnotationText())
|
||||
await gotoBare(user, async () => {
|
||||
await user.click(
|
||||
inPlace('annotations.drawing').getByRole('button', {
|
||||
name: 'Ajouter un point',
|
||||
}),
|
||||
)
|
||||
})
|
||||
const panel = within(place('annotations.drawing')).getByTestId(
|
||||
'annotation-creation',
|
||||
)
|
||||
expect(panel).toBeVisible()
|
||||
const drawing = inPlace('annotations.drawing')
|
||||
await waitFor(() =>
|
||||
expect(document.activeElement).toHaveAttribute('data-creation-heading'),
|
||||
expect(
|
||||
drawing.getByRole('button', { name: 'Ajouter un point' }),
|
||||
).toBeEnabled(),
|
||||
)
|
||||
expect(liveText()).toContain('création est en cours')
|
||||
await user.click(drawing.getByRole('button', { name: 'Ajouter un point' }))
|
||||
const dialog = await screen.findByRole('dialog', { name: 'Nouveau point' })
|
||||
await user.type(within(dialog).getByLabelText('Nom (FR)'), 'Nuque')
|
||||
await user.click(
|
||||
within(dialog).getByRole('button', { name: 'Replacer le point' }),
|
||||
)
|
||||
await waitFor(() => expect(screen.queryByRole('dialog')).toBeNull())
|
||||
await user.click(tab(/Vérification/))
|
||||
await user.click(
|
||||
within(
|
||||
await screen.findByRole('dialog', { name: 'Abandonner la création ?' }),
|
||||
).getByRole('button', { name: 'Continuer' }),
|
||||
)
|
||||
expect(tab('Annotations')).toHaveAttribute('aria-selected', 'true')
|
||||
await user.click(
|
||||
drawing.getByRole('button', { name: 'Revenir aux propriétés' }),
|
||||
)
|
||||
const back = await screen.findByRole('dialog', { name: 'Nouveau point' })
|
||||
expect(within(back).getByLabelText('Nom (FR)')).toHaveValue('Nuque')
|
||||
})
|
||||
})
|
||||
@@ -215,7 +215,8 @@ describe('typed values come back after a 1 024 px crossing', () => {
|
||||
expect(store.getState().unsaved).toBe(false)
|
||||
})
|
||||
|
||||
it('the annotation edit body: tool, pending creation with its name', async () => {
|
||||
// U2 Task 7 (R-14): the creation dialog is mounted outside the edit-only body.
|
||||
it('a creation open: a crossing keeps the dialog, its form and the ghost, « Créer » off', async () => {
|
||||
const user = await mount(baseText())
|
||||
const drawing = within(place('annotations.drawing'))
|
||||
await waitFor(() =>
|
||||
@@ -223,19 +224,26 @@ describe('typed values come back after a 1 024 px crossing', () => {
|
||||
)
|
||||
await user.click(drawing.getByRole('button', { name: 'Zone' }))
|
||||
await user.click(drawing.getByRole('button', { name: 'Ajouter un point' }))
|
||||
const name = await screen.findByLabelText('Nom (FR)')
|
||||
const dialog = await screen.findByRole('dialog', { name: 'Nouveau point' })
|
||||
const name = within(dialog).getByLabelText('Nom (FR)')
|
||||
await user.type(name, 'Futur point')
|
||||
cross(800)
|
||||
expect(name.closest('[hidden]')).not.toBeNull()
|
||||
expect(screen.queryByRole('region', { name: 'Nouveau point' })).toBeNull()
|
||||
expect(screen.queryByRole('button', { name: 'Zone' })).toBeNull()
|
||||
const kept = screen.getByRole('dialog', { name: 'Nouveau point' })
|
||||
expect(within(kept).getByLabelText('Nom (FR)')).toHaveValue('Futur point')
|
||||
expect(within(kept).getByLabelText('Nom (FR)')).toHaveAttribute('readonly')
|
||||
expect(within(kept).getByRole('button', { name: 'Créer' })).toBeDisabled()
|
||||
expect(
|
||||
within(kept).getByRole('button', { name: 'Replacer le point' }),
|
||||
).toBeDisabled()
|
||||
expect(screen.getByTestId('overlay-ghost')).toBeInTheDocument()
|
||||
cross(1280)
|
||||
expect(screen.getByLabelText('Nom (FR)')).toBe(name)
|
||||
expect(name).toHaveValue('Futur point')
|
||||
expect(drawing.getByRole('button', { name: 'Zone' })).toHaveAttribute(
|
||||
'aria-pressed',
|
||||
'true',
|
||||
const back = screen.getByRole('dialog', { name: 'Nouveau point' })
|
||||
expect(within(back).getByLabelText('Nom (FR)')).toHaveValue('Futur point')
|
||||
expect(within(back).getByLabelText('Nom (FR)')).not.toHaveAttribute(
|
||||
'readonly',
|
||||
)
|
||||
expect(within(back).getByRole('button', { name: 'Créer' })).toBeEnabled()
|
||||
expect(screen.getByTestId('overlay-ghost')).toBeInTheDocument()
|
||||
expect(store.getState().unsaved).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -459,8 +459,11 @@ describe('A5: a new point takes the most used size', () => {
|
||||
await mount(sized())
|
||||
const user = userEvent.setup()
|
||||
await user.click(screen.getByRole('button', { name: 'Ajouter un point' }))
|
||||
const panel = await screen.findByTestId('annotation-creation')
|
||||
expect(within(panel).getByLabelText('Rayon')).toHaveValue('7')
|
||||
await screen.findByTestId('annotation-creation')
|
||||
// A8: no « Rayon » field; the ghost under the dialog has the size.
|
||||
expect(
|
||||
screen.getByTestId('overlay-ghost').querySelector('circle'),
|
||||
).toHaveAttribute('r', '7')
|
||||
})
|
||||
|
||||
it('the Point tool shows the slider at that size; a new size feeds the click', async () => {
|
||||
@@ -599,8 +602,10 @@ describe('A5 through the Point tool click', () => {
|
||||
const user = userEvent.setup()
|
||||
await user.click(screen.getByRole('button', { name: 'Point' }))
|
||||
pressAt(screen.getByTestId('annotation-canvas'), 50, 80)
|
||||
const panel = await screen.findByTestId('annotation-creation')
|
||||
expect(within(panel).getByLabelText('Rayon')).toHaveValue('7')
|
||||
await screen.findByTestId('annotation-creation')
|
||||
expect(
|
||||
screen.getByTestId('overlay-ghost').querySelector('circle'),
|
||||
).toHaveAttribute('r', '7')
|
||||
})
|
||||
|
||||
it('a size chosen on the slider before the click feeds it', async () => {
|
||||
@@ -609,8 +614,10 @@ describe('A5 through the Point tool click', () => {
|
||||
await user.click(screen.getByRole('button', { name: 'Point' }))
|
||||
fireEvent.change(slider(), { target: { value: '9' } })
|
||||
pressAt(screen.getByTestId('annotation-canvas'), 50, 80)
|
||||
const panel = await screen.findByTestId('annotation-creation')
|
||||
expect(within(panel).getByLabelText('Rayon')).toHaveValue('9')
|
||||
await screen.findByTestId('annotation-creation')
|
||||
expect(
|
||||
screen.getByTestId('overlay-ghost').querySelector('circle'),
|
||||
).toHaveAttribute('r', '9')
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
@@ -259,11 +259,11 @@ describe('« Aller à » an annotation while something is in progress', () => {
|
||||
return { consumed, announce }
|
||||
}
|
||||
|
||||
it('a pending creation is kept: its panel takes the focus, the live region says why', async () => {
|
||||
it('a pending creation is kept: its dialog takes the focus, the live region says why', async () => {
|
||||
const { consumed, announce } = await withProgress(addPoint)
|
||||
await waitFor(() => expect(consumed).toHaveBeenCalledWith(7, 'kept'))
|
||||
expect(screen.getByTestId('annotation-creation')).toBeInTheDocument()
|
||||
expect(document.activeElement).toHaveAttribute('data-creation-heading')
|
||||
expect(document.activeElement).toHaveAttribute('data-creation-focus')
|
||||
expect(announce).toHaveBeenCalledWith(
|
||||
expect.stringContaining('création est en cours'),
|
||||
)
|
||||
|
||||
@@ -35,6 +35,8 @@ import { useLeaveGuardStore } from '@/state/leaveGuardStore'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { fr } from '@/i18n/fr'
|
||||
import DrawingGuardDialog from '@/components/editor/annotations/DrawingGuardDialog'
|
||||
import { emptyForm } from '@/editor/annotations/creation'
|
||||
import { traceVertex } from '@/editor/annotations/creationWork'
|
||||
import { guardDrawing } from '@/editor/annotations/drawingGuard'
|
||||
import {
|
||||
guardWork,
|
||||
@@ -409,6 +411,32 @@ describe('AppLayout and a started move on the drawing (R-12)', () => {
|
||||
).toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('during a creation a link asks « Abandonner la création ? » (R-12)', async () => {
|
||||
const user = userEvent.setup()
|
||||
mountDraft()
|
||||
act(() =>
|
||||
traceVertex(
|
||||
{
|
||||
viewId: 'v',
|
||||
frame: null,
|
||||
origin: 'tool',
|
||||
form: emptyForm({ categories: [] } as never),
|
||||
},
|
||||
'zone',
|
||||
[1, 1],
|
||||
),
|
||||
)
|
||||
await user.click(account())
|
||||
const ask = screen.getByRole('dialog', { name: 'Abandonner la création ?' })
|
||||
await user.click(within(ask).getByRole('button', { name: 'Continuer' }))
|
||||
expect(screen.queryByText(/account page/)).toBeNull()
|
||||
expect(useAnnotationWork.getState().creation).not.toBeNull()
|
||||
await user.click(account())
|
||||
await user.click(screen.getByRole('button', { name: 'Abandonner' }))
|
||||
expect(await screen.findByText(/account page/)).toBeInTheDocument()
|
||||
expect(useAnnotationWork.getState().creation).toBeNull()
|
||||
})
|
||||
|
||||
it('a download link is never taken, even with a started move', async () => {
|
||||
const user = userEvent.setup()
|
||||
mountDraft()
|
||||
|
||||
Reference in new issue
Block a user