test(editor): reference dialog, filter and the owner journey, specs follow the dialog
This commit is contained in:
1 parent
7a64daf251
commit
8b42816270
20 files changed
+1546
-1171
No files matched your search
@@ -1,9 +1,14 @@
|
||||
/** Lot F: the Références tab and Vertèbres. */
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { cleanup, render, screen, within } from '@testing-library/react'
|
||||
import {
|
||||
cleanup,
|
||||
render,
|
||||
screen,
|
||||
waitFor,
|
||||
within,
|
||||
} from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import type { AnatomicalSheetDocument } from '@faunosteo/core-wasm/types'
|
||||
import ReferencesTab from '@/components/editor/tabs/ReferencesTab'
|
||||
import RegionsSection from '@/components/editor/annotations/sections/RegionsSection'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { edit, insert, point } from '../helpers/editorFixtures'
|
||||
@@ -13,6 +18,7 @@ import {
|
||||
resetStore,
|
||||
store,
|
||||
} from '../helpers/editorHarness'
|
||||
import ReferencesHost from '../helpers/referencesHost'
|
||||
|
||||
vi.mock('@/lib/supabase', () => ({ getSupabaseClient: () => ({}) }))
|
||||
vi.mock('@faunosteo/supabase', async (orig) => ({
|
||||
@@ -44,16 +50,24 @@ describe('Références', () => {
|
||||
it('adds a reference only with a type and a citation', async () => {
|
||||
await openReady()
|
||||
const user = userEvent.setup()
|
||||
render(<ReferencesTab {...props} />)
|
||||
render(<ReferencesHost {...props} />)
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Ajouter une référence' }),
|
||||
)
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Ajouter la référence' }),
|
||||
)
|
||||
expect(screen.getByRole('alert')).toHaveTextContent('Choisissez un type')
|
||||
expect(screen.getByLabelText('Type')).toHaveAccessibleDescription(
|
||||
'Ce champ est obligatoire.',
|
||||
)
|
||||
expect(doc().references).toEqual([])
|
||||
await user.selectOptions(screen.getByLabelText('Type'), 'web')
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Ajouter la référence' }),
|
||||
)
|
||||
expect(screen.getByLabelText('Citation')).toHaveAccessibleDescription(
|
||||
'Ce champ est obligatoire.',
|
||||
)
|
||||
await user.type(screen.getByLabelText('Citation'), 'Anatomie du cheval')
|
||||
await user.click(
|
||||
screen.getByRole('button', { name: 'Ajouter la référence' }),
|
||||
@@ -68,23 +82,24 @@ describe('Références', () => {
|
||||
expect(doc().references[0].id).toMatch(/^ref-[a-z2-7]{10}$/)
|
||||
})
|
||||
|
||||
it('edits a field in a tile, applies it on blur, and reorders with the arrows', async () => {
|
||||
it('edits a reference in its dialog, one command on « Enregistrer », and reorders with the arrows', async () => {
|
||||
const text = insert(
|
||||
insert(baseText(), reference('ref-a', 'Alpha')),
|
||||
reference('ref-b', 'Beta'),
|
||||
)
|
||||
await openReady({ text })
|
||||
const user = userEvent.setup()
|
||||
render(<ReferencesTab {...props} />)
|
||||
render(<ReferencesHost {...props} />)
|
||||
await user.click(screen.getByRole('button', { name: /^Alpha/ }))
|
||||
await user.click(screen.getByRole('button', { name: 'Modifier' }))
|
||||
const url = screen.getByLabelText('Adresse web (URL)', {
|
||||
selector: '#tab-reference-0-ref-a-url',
|
||||
})
|
||||
const url = screen.getByLabelText('Adresse web (URL)')
|
||||
await user.type(url, 'https://example.org')
|
||||
await user.tab()
|
||||
expect(doc().references[0].url).toBeNull()
|
||||
await user.click(screen.getByRole('button', { name: 'Enregistrer' }))
|
||||
await waitFor(() =>
|
||||
expect(document.querySelector('dialog[open]')).toBeNull(),
|
||||
)
|
||||
expect(doc().references[0].url).toBe('https://example.org')
|
||||
await user.click(screen.getByRole('button', { name: 'Terminer' }))
|
||||
await user.click(screen.getByRole('button', { name: /^Beta/ }))
|
||||
await user.click(screen.getAllByRole('button', { name: 'Monter' })[1])
|
||||
expect(doc().references.map((r) => r.id)).toEqual(['ref-b', 'ref-a'])
|
||||
@@ -118,7 +133,7 @@ describe('Références', () => {
|
||||
})
|
||||
await openReady({ text })
|
||||
const user = userEvent.setup()
|
||||
render(<ReferencesTab {...props} />)
|
||||
render(<ReferencesHost {...props} />)
|
||||
await user.click(screen.getByRole('button', { name: /^Alpha/ }))
|
||||
expect(screen.queryByRole('button', { name: 'Supprimer' })).toBeNull()
|
||||
expect(screen.getByText(/Pour supprimer cette référence/)).toBeTruthy()
|
||||
@@ -133,7 +148,7 @@ describe('Références', () => {
|
||||
it('read-only shows the facts and no control that changes the draft', async () => {
|
||||
await openReady({ text: insert(baseText(), reference('ref-a', 'Alpha')) })
|
||||
const user = userEvent.setup()
|
||||
render(<ReferencesTab {...props} readOnly />)
|
||||
render(<ReferencesHost {...props} readOnly />)
|
||||
await user.click(screen.getByRole('button', { name: /^Alpha/ }))
|
||||
expect(screen.getByText('Aucun')).toBeTruthy()
|
||||
expect(screen.queryByRole('textbox', { name: 'Citation' })).toBeNull()
|
||||
|
||||
Reference in new issue
Block a user