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 ?? ''
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ const ref = (id: string, citation: string, url = '', doi = '') =>
|
||||
},
|
||||
}) as const
|
||||
|
||||
function sheetText(): string {
|
||||
function sheetText(family = ['ref-a', 'ref-b']): string {
|
||||
let text = baseText()
|
||||
text = insert(text, ref('ref-a', 'Barone, Ostéologie'))
|
||||
text = insert(text, ref('ref-b', 'Denoix', 'https://exemple.org/Épaule'))
|
||||
@@ -77,7 +77,7 @@ function sheetText(): string {
|
||||
kind: 'dysfunction',
|
||||
name: name('Cat A'),
|
||||
description: {},
|
||||
reference_ids: ['ref-a', 'ref-b'],
|
||||
reference_ids: family,
|
||||
review_status: 'to_confirm',
|
||||
children: [],
|
||||
},
|
||||
@@ -86,8 +86,8 @@ function sheetText(): string {
|
||||
}
|
||||
|
||||
/** The sheet plus one finding node under Cat A (default: citing ref-a and ref-c). */
|
||||
function nodeText(ids = ['ref-a', 'ref-c']): string {
|
||||
return edit(sheetText(), {
|
||||
function nodeText(ids = ['ref-a', 'ref-c'], family?: string[]): string {
|
||||
return edit(sheetText(family), {
|
||||
op: 'insert',
|
||||
parent: { kind: 'finding', zone_id: 'zone-a', path: ['fcat-a'] },
|
||||
element: {
|
||||
@@ -590,3 +590,115 @@ describe('the panel review fixes', () => {
|
||||
await focusIs(heading)
|
||||
})
|
||||
})
|
||||
|
||||
describe('the family wording (Rev 6)', () => {
|
||||
const familyHeading = (name: string) =>
|
||||
within(citationsDialog()).getByRole('heading', { name })
|
||||
const chip = () => screen.getByTestId('editor-references-filter')
|
||||
const showAll = (user: User) =>
|
||||
user.click(
|
||||
within(panel()).getByRole('button', {
|
||||
name: "Tout afficher dans l'onglet Références",
|
||||
}),
|
||||
)
|
||||
|
||||
it('a family: dialog title, count, its own tile row, edit title', async () => {
|
||||
const user = await mount()
|
||||
await select(user, /Cat A/)
|
||||
await user.click(trigger())
|
||||
await focusIs(closeButton)
|
||||
expect(familyHeading('Références de la famille')).toBeVisible()
|
||||
expect(panel()).toHaveTextContent('2 références citées par cette famille')
|
||||
await user.click(within(panel()).getByRole('button', { name: /^Barone/ }))
|
||||
const tile = tiles()[0] as HTMLElement
|
||||
expect(within(tile).getByText('cette famille')).toBeInTheDocument()
|
||||
expect(within(tile).queryByText('famille')).toBeNull()
|
||||
await user.click(
|
||||
within(citationsDialog()).getByRole('button', { name: 'Modifier' }),
|
||||
)
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
familyHeading('Modifier les références de la famille'),
|
||||
).toBeVisible(),
|
||||
)
|
||||
})
|
||||
|
||||
it('a finding keeps the finding wording', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
expect(heading()).toBeVisible()
|
||||
expect(panel()).toHaveTextContent('2 références citées par ce constat')
|
||||
})
|
||||
|
||||
it('an empty family: the empty line, then the filtered tab names the family', async () => {
|
||||
const user = await mount(1280, nodeText(['ref-a', 'ref-c'], []))
|
||||
await select(user, /Cat A/)
|
||||
await user.click(trigger('0 référence'))
|
||||
await focusIs(closeButton)
|
||||
expect(panel()).toHaveTextContent('Cette famille ne cite aucune référence.')
|
||||
await showAll(user)
|
||||
await closed()
|
||||
expect(chip()).toHaveTextContent('Références de la famille : Cat A')
|
||||
expect(
|
||||
within(chip()).getByRole('button', {
|
||||
name: 'Retirer le filtre de la famille Cat A',
|
||||
}),
|
||||
).toBeVisible()
|
||||
expect(
|
||||
within(chip()).getByRole('button', { name: 'Revenir à la famille' }),
|
||||
).toBeVisible()
|
||||
expect(screen.getByTestId('editor-references-no-result')).toHaveTextContent(
|
||||
'Cette famille ne cite aucune référence.',
|
||||
)
|
||||
})
|
||||
|
||||
it('a filtered family removed by an undo says the family is gone', async () => {
|
||||
const user = await mount()
|
||||
act(() => {
|
||||
store.getState().commit({
|
||||
op: 'insert',
|
||||
parent: { kind: 'zone', id: 'zone-a' },
|
||||
element: {
|
||||
kind: 'finding_category',
|
||||
value: {
|
||||
id: 'fcat-b',
|
||||
kind: 'dysfunction',
|
||||
name: name('Cat B'),
|
||||
description: {},
|
||||
reference_ids: ['ref-c'],
|
||||
review_status: 'to_confirm',
|
||||
children: [],
|
||||
},
|
||||
},
|
||||
})
|
||||
})
|
||||
await select(user, /Cat B/)
|
||||
await user.click(trigger('1 référence'))
|
||||
await showAll(user)
|
||||
await closed()
|
||||
expect(chip()).toHaveTextContent('Références de la famille : Cat B')
|
||||
act(() => {
|
||||
store.getState().undoStep()
|
||||
})
|
||||
await waitFor(() =>
|
||||
expect(live()).toHaveTextContent(
|
||||
"La famille n'existe plus : le filtre est retiré",
|
||||
),
|
||||
)
|
||||
})
|
||||
|
||||
it('a family that vanishes closes its dialog and says the family is gone', async () => {
|
||||
const user = await mount()
|
||||
await select(user, /Cat A/)
|
||||
act(() => {
|
||||
store.getState().commit({
|
||||
op: 'remove',
|
||||
key: { kind: 'finding', zone_id: 'zone-a', path: ['fcat-a'] },
|
||||
})
|
||||
})
|
||||
await waitFor(() => expect(findingDialog()).toBeNull())
|
||||
await waitFor(() =>
|
||||
expect(live()).toHaveTextContent("Cette famille n'existe plus"),
|
||||
)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user