feat(editor): « Citer » button and family labels in references
This commit is contained in:
1 parent
240c2ba0e7
commit
8c3fcca0b9
16 files changed
+507
-53
No files matched your search
@@ -1,6 +1,13 @@
|
||||
/** Rev 5 Task 12: the references dialog's edit mode (draft, save, guards, stacked dialogs). */
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { act, cleanup, screen, waitFor, within } from '@testing-library/react'
|
||||
import {
|
||||
act,
|
||||
cleanup,
|
||||
fireEvent,
|
||||
screen,
|
||||
waitFor,
|
||||
within,
|
||||
} from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import type { Location, NavigateFunction } from 'react-router-dom'
|
||||
import { flushAfterModals } from '@/components/ui/afterModalsClosed'
|
||||
@@ -182,11 +189,13 @@ const removeRow = (user: User, citation: RegExp) =>
|
||||
name: new RegExp(`^Retirer ${citation.source}`),
|
||||
}),
|
||||
)
|
||||
const cite = (user: User, id: string) =>
|
||||
user.selectOptions(
|
||||
inCitations().getByLabelText('Citer une référence existante'),
|
||||
id,
|
||||
)
|
||||
const select = () =>
|
||||
inCitations().getByLabelText('Citer une référence existante')
|
||||
/** Rev 6: a choice in the select, then « Citer ». */
|
||||
async function cite(user: User, id: string) {
|
||||
await user.selectOptions(select(), id)
|
||||
await user.click(button('Citer'))
|
||||
}
|
||||
|
||||
describe('the « Modifier » of the references dialog', () => {
|
||||
it('edit mode: no history entry, no « Tout afficher », no « Aller à »', async () => {
|
||||
@@ -295,6 +304,93 @@ describe('the draft', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('« Citer » (Rev 6)', () => {
|
||||
const citeButton = () => button('Citer')
|
||||
const pendingLine =
|
||||
'Référence choisie mais pas encore citée : choisissez « Citer » ou revenez au choix vide.'
|
||||
|
||||
it('a choice or an arrow key leaves the draft clean: ✕ closes without a question', async () => {
|
||||
const user = await mount()
|
||||
await editCitations(user)
|
||||
expect(citeButton()).toBeDisabled()
|
||||
await user.selectOptions(select(), 'ref-b')
|
||||
fireEvent.keyDown(select(), { key: 'ArrowDown' })
|
||||
fireEvent.change(select(), { target: { value: 'ref-b' } })
|
||||
expect(rows()).toEqual(['ref-a', 'ref-c'])
|
||||
expect(citeButton()).toBeEnabled()
|
||||
await user.click(button('Fermer'))
|
||||
await waitFor(() => expect(citations()).toBeUndefined())
|
||||
expect(undos()).toBe(0)
|
||||
})
|
||||
|
||||
it('« Citer » cites once, resets and focuses the select, stays in edit mode', async () => {
|
||||
const user = await mount()
|
||||
await editCitations(user)
|
||||
await user.selectOptions(select(), 'ref-b')
|
||||
expect(citeButton()).toHaveAttribute('type', 'button')
|
||||
await user.click(citeButton())
|
||||
expect(rows()).toEqual(['ref-a', 'ref-c', 'ref-b'])
|
||||
expect(select()).toHaveValue('')
|
||||
expect(select()).toHaveFocus()
|
||||
expect(citeButton()).toBeDisabled()
|
||||
await user.click(citeButton())
|
||||
expect(rows()).toEqual(['ref-a', 'ref-c', 'ref-b'])
|
||||
expect(
|
||||
inCitations().getByRole('heading', {
|
||||
name: 'Modifier les références du constat',
|
||||
}),
|
||||
).toBeVisible()
|
||||
expect(undos()).toBe(0)
|
||||
})
|
||||
|
||||
it('a choice no longer offered goes back to the placeholder', async () => {
|
||||
const user = await mount()
|
||||
await editCitations(user)
|
||||
await user.selectOptions(select(), 'ref-b')
|
||||
act(() => {
|
||||
store.getState().commit({
|
||||
op: 'remove',
|
||||
key: { kind: 'reference', id: 'ref-b' },
|
||||
})
|
||||
})
|
||||
await waitFor(() => expect(select()).toHaveValue(''))
|
||||
expect(citeButton()).toBeDisabled()
|
||||
})
|
||||
|
||||
it('« Enregistrer » with a choice not cited refuses: the line, focus on « Citer »', async () => {
|
||||
const user = await mount()
|
||||
await editCitations(user)
|
||||
await user.selectOptions(select(), 'ref-b')
|
||||
await user.click(button('Enregistrer'))
|
||||
expect(undos()).toBe(0)
|
||||
expect(inCitations().getByRole('alert')).toHaveTextContent(pendingLine)
|
||||
expect(citeButton()).toHaveFocus()
|
||||
expect(
|
||||
inCitations().getByRole('heading', {
|
||||
name: 'Modifier les références du constat',
|
||||
}),
|
||||
).toBeVisible()
|
||||
await user.selectOptions(select(), '')
|
||||
expect(inCitations().queryByText(pendingLine)).toBeNull()
|
||||
await user.click(button('Enregistrer'))
|
||||
await waitFor(() => expect(button('Modifier')).toHaveFocus())
|
||||
expect(undos()).toBe(0)
|
||||
})
|
||||
|
||||
it('read only: no select and no « Citer »', async () => {
|
||||
const user = await mount()
|
||||
await editCitations(user)
|
||||
act(() => {
|
||||
setWidth(900)
|
||||
window.dispatchEvent(new Event('resize'))
|
||||
})
|
||||
expect(inCitations().queryByRole('button', { name: 'Citer' })).toBeNull()
|
||||
expect(
|
||||
inCitations().queryByLabelText('Citer une référence existante'),
|
||||
).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
const live = () =>
|
||||
document.querySelector('p.sr-only[aria-live="polite"]')!.textContent ?? ''
|
||||
|
||||
|
||||
Reference in new issue
Block a user