diff --git a/apps/app/e2e/support/editor.ts b/apps/app/e2e/support/editor.ts
index 4271a835..06114dbf 100644
--- a/apps/app/e2e/support/editor.ts
+++ b/apps/app/e2e/support/editor.ts
@@ -502,8 +502,11 @@ export async function pickAnnotation(
name: dict['editor.annotations.show_all'],
exact: true,
})
+ const list = annotationList(page, dict)
+ // Either the card (nothing selected) or the properties panel has settled.
+ await expect(all.or(list)).toBeVisible()
if (await all.isVisible()) await all.click()
- await annotationList(page, dict).getByRole('button', { name }).click()
+ await list.getByRole('button', { name }).click()
}
export const toolButton = (page: Page, dict: Dict, id: string) =>
diff --git a/apps/app/src/components/editor/annotations/AnnotationList.tsx b/apps/app/src/components/editor/annotations/AnnotationList.tsx
index 49b116b2..596d8507 100644
--- a/apps/app/src/components/editor/annotations/AnnotationList.tsx
+++ b/apps/app/src/components/editor/annotations/AnnotationList.tsx
@@ -58,12 +58,12 @@ function Row({
}
/** « Sans catégorie » or the category: swatch, name and the count of rows shown. */
-function GroupTitle({ group }: { group: AnnotationGroup }) {
+function GroupTitle({ group, id }: { group: AnnotationGroup; id: string }) {
const t = useT()
const locale = useLocaleStore((s) => s.locale)
const { category } = group
return (
-
+
void
}) {
const t = useT()
return (
- {groups.map((group) => (
- -
-
-
- {group.annotations.map((annotation) => (
-
- ))}
-
-
- ))}
+ {groups.map((group) => {
+ const id = `${idPrefix}overview-group-${group.category?.id ?? 'none'}`
+ return (
+ -
+
+
+ {group.annotations.map((annotation) => (
+
+ ))}
+
+
+ )
+ })}
)
}
diff --git a/apps/app/src/components/editor/annotations/OverviewPanel.tsx b/apps/app/src/components/editor/annotations/OverviewPanel.tsx
index e4995f76..b1d30f8d 100644
--- a/apps/app/src/components/editor/annotations/OverviewPanel.tsx
+++ b/apps/app/src/components/editor/annotations/OverviewPanel.tsx
@@ -227,6 +227,7 @@ function AnnotationsCard(props: OverviewPanelProps) {
) : (
diff --git a/apps/app/tests/unit/editor-overview.test.tsx b/apps/app/tests/unit/editor-overview.test.tsx
index cab04c3f..52603205 100644
--- a/apps/app/tests/unit/editor-overview.test.tsx
+++ b/apps/app/tests/unit/editor-overview.test.tsx
@@ -1,6 +1,12 @@
/** V1-2.6 U1 Lot C: board 01's « Annotations de la vue » card, in edit and read-only. */
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
-import { cleanup, render, screen, waitFor, within } from '@testing-library/react'
+import {
+ cleanup,
+ render,
+ screen,
+ waitFor,
+ within,
+} from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import type { Annotation } from '@faunosteo/core-wasm/types'
import AnnotationsTab from '@/components/editor/tabs/AnnotationsTab'
@@ -28,7 +34,12 @@ const props = {
onBack: vi.fn(),
}
-const named = (id: string, fr: string, category: string, view = 'view-main') => {
+const named = (
+ id: string,
+ fr: string,
+ category: string,
+ view = 'view-main',
+) => {
const base = point(id, 50, 50, 5, view).value as Annotation
return {
kind: 'annotation',
@@ -69,8 +80,15 @@ async function mount(readOnly = false) {
await screen.findByRole('list', { name: 'Annotations de la vue' })
}
-const card = () => screen.getByRole('list', { name: 'Annotations de la vue' })
+const overview = () =>
+ screen.getByRole('region', { name: 'Aperçu de la fiche' })
+const card = () =>
+ within(overview()).getByRole('list', { name: 'Annotations de la vue' })
const rows = () => within(card()).getAllByRole('button')
+const chip = (name: string) =>
+ within(screen.getByRole('group', { name: 'Vues' })).getByRole('button', {
+ name,
+ })
describe.each([
['edit', false],
@@ -78,25 +96,28 @@ describe.each([
])('the annotation card (%s)', (_mode, readOnly) => {
it('groups the rows by category in document order, with a count per group', async () => {
await mount(readOnly)
- const titles = within(card())
- .getAllByRole('listitem')
- .filter((item) => item.querySelector('ul'))
- .map((item) => item.querySelector('p')?.textContent)
- expect(titles).toEqual(['N1', 'Os1'])
- expect(rows().map((b) => b.textContent)).toEqual([
- expect.stringContaining('Genou'),
- expect.stringContaining('Épaule'),
- ])
+ const groups = within(card()).getAllByRole('list')
+ expect(groups).toHaveLength(2)
+ const [first, second] = groups
+ expect(first).toHaveAccessibleName('N 1')
+ expect(second).toHaveAccessibleName('Os 1')
+ expect(within(first).getByRole('button')).toHaveTextContent('Genou')
+ expect(within(second).getByRole('button')).toHaveTextContent('Épaule')
})
it('filters on the displayed name, ignoring case and accents', async () => {
await mount(readOnly)
const user = userEvent.setup()
- await user.type(screen.getByRole('searchbox', { name: 'Filtrer par nom' }), 'EPAULE')
+ const field = within(overview()).getByRole('searchbox', {
+ name: 'Filtrer par nom',
+ })
+ await user.type(field, 'EPAULE')
expect(rows()).toHaveLength(1)
expect(rows()[0]).toHaveTextContent('Épaule')
- await user.type(screen.getByRole('searchbox'), 'zzz')
- expect(screen.getByText('Aucune annotation ne correspond.')).toBeInTheDocument()
+ await user.type(field, 'zzz')
+ expect(
+ within(overview()).getByText('Aucune annotation ne correspond.'),
+ ).toBeInTheDocument()
})
it('a row selects the annotation; « Toutes les annotations » returns with focus on its row', async () => {
@@ -104,28 +125,46 @@ describe.each([
const user = userEvent.setup()
await user.click(rows()[1])
expect(await screen.findByTestId('annotation-properties')).toBeVisible()
- await user.click(screen.getByRole('button', { name: 'Toutes les annotations' }))
- expect(screen.getByTestId('annotation-overview')).toBeVisible()
+ await user.click(
+ screen.getByRole('button', { name: 'Toutes les annotations' }),
+ )
+ expect(overview()).toBeVisible()
await waitFor(() => expect(document.activeElement).toBe(rows()[1]))
})
it('a view row switches the canvas view', async () => {
await mount(readOnly)
const user = userEvent.setup()
- const views = screen.getByRole('region', { name: 'Aperçu de la fiche' })
- await user.click(within(views).getByRole('button', { name: /^Tête/ }))
- expect(within(views).getByRole('button', { name: /^Tête/ })).toHaveAttribute(
- 'aria-current',
- 'true',
- )
- expect(screen.getByText('Aucune annotation dans cette vue.')).toBeInTheDocument()
+ expect(chip('Tête')).toHaveAttribute('aria-pressed', 'false')
+ await user.click(within(overview()).getByRole('button', { name: /^Tête/ }))
+ expect(
+ within(overview()).getByRole('button', { name: /^Tête/ }),
+ ).toHaveAttribute('aria-current', 'true')
+ expect(chip('Tête')).toHaveAttribute('aria-pressed', 'true')
+ expect(
+ within(overview()).getByText('Aucune annotation dans cette vue.'),
+ ).toBeInTheDocument()
+ })
+})
+
+describe('« Sans catégorie »', () => {
+ it('a group appears only for an annotation whose category is not in the document', async () => {
+ let text = insert(drawnText(), named('stray', 'Perdue', 'ghost'))
+ text = insert(text, named('a2', 'Genou', 'cat-a'))
+ await openReady({ text })
+ render()
+ await screen.findByRole('list', { name: 'Annotations de la vue' })
+ const groups = within(card()).getAllByRole('list')
+ expect(groups).toHaveLength(2)
+ expect(groups[1]).toHaveAccessibleName('Sans catégorie 1')
+ expect(within(groups[1]).getByRole('button')).toHaveTextContent('Perdue')
})
})
describe('the side column', () => {
it('sits beside the canvas from lg (1 024 px), not xl', async () => {
await mount()
- const grid = screen.getByTestId('annotation-overview').closest('.grid')
+ const grid = overview().closest('.grid')
expect(grid?.className).toContain('lg:grid-cols-[minmax(0,1fr)_22rem]')
expect(grid?.className).not.toContain('xl:')
})