diff --git a/apps/app/tests/unit/editor-overview.test.tsx b/apps/app/tests/unit/editor-overview.test.tsx index 52603205..754b2ecb 100644 --- a/apps/app/tests/unit/editor-overview.test.tsx +++ b/apps/app/tests/unit/editor-overview.test.tsx @@ -84,6 +84,15 @@ const overview = () => screen.getByRole('region', { name: 'Aperçu de la fiche' }) const card = () => within(overview()).getByRole('list', { name: 'Annotations de la vue' }) +/** The visible body: the read-only twin hides the kept edit one. */ +const body = () => + screen + .getAllByTestId('editor-tab-annotations') + .find((el) => !el.closest('[hidden]'))! +const canvas = (readOnly: boolean) => + within(body()).getByTestId( + readOnly ? 'catalogue-canvas' : 'annotation-canvas', + ) const rows = () => within(card()).getAllByRole('button') const chip = (name: string) => within(screen.getByRole('group', { name: 'Vues' })).getByRole('button', { @@ -124,7 +133,9 @@ describe.each([ await mount(readOnly) const user = userEvent.setup() await user.click(rows()[1]) - expect(await screen.findByTestId('annotation-properties')).toBeVisible() + expect( + await within(body()).findByTestId('annotation-properties'), + ).toBeVisible() await user.click( screen.getByRole('button', { name: 'Toutes les annotations' }), ) @@ -135,12 +146,15 @@ describe.each([ it('a view row switches the canvas view', async () => { await mount(readOnly) const user = userEvent.setup() + const name = (view: string) => (readOnly ? `Dessin : ${view}` : view) + expect(canvas(readOnly)).not.toHaveAccessibleName(name('Tête')) 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(canvas(readOnly)).toHaveAccessibleName(name('Tête')) expect( within(overview()).getByText('Aucune annotation dans cette vue.'), ).toBeInTheDocument()