fix(editor): draft notice after the reference dialog, locale list
This commit is contained in:
1 parent
1d119c3684
commit
ee7912768c
7 files changed
+156
-17
No files matched your search
@@ -4,12 +4,14 @@ import {
|
||||
act,
|
||||
cleanup,
|
||||
fireEvent,
|
||||
render,
|
||||
screen,
|
||||
waitFor,
|
||||
within,
|
||||
} from '@testing-library/react'
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import type { Location, NavigateFunction } from 'react-router-dom'
|
||||
import CitationsEditForm from '@/components/editor/references/CitationsEditForm'
|
||||
import { flushAfterModals } from '@/components/ui/afterModalsClosed'
|
||||
import { ENTRY_KEY, type HistoryEntry } from '@/editor/history/entry'
|
||||
import {
|
||||
@@ -21,6 +23,7 @@ import { useLocaleStore } from '@/state/localeStore'
|
||||
import { edit, insert } from '../helpers/editorFixtures'
|
||||
import {
|
||||
baseText,
|
||||
openReady,
|
||||
resetStore,
|
||||
serverHas,
|
||||
SHEET,
|
||||
@@ -648,6 +651,9 @@ describe('the reference dialog over the edit mode', () => {
|
||||
await waitFor(() => expect(referenceDialog()).toBeUndefined())
|
||||
expect(rows()).toEqual(['ref-a', 'ref-c', pendingId])
|
||||
expect(within(pendingRow()).getByText('Neuf 2')).toBeVisible()
|
||||
await waitFor(() =>
|
||||
expect(status()).toBe('Nouvelle référence modifiée : Neuf 2'),
|
||||
)
|
||||
expect(library()).not.toContain('Neuf 2')
|
||||
await user.click(button('Enregistrer'))
|
||||
expect(library().filter((c) => c.startsWith('Neuf'))).toEqual(['Neuf 2'])
|
||||
@@ -730,6 +736,92 @@ describe('the reference dialog over the edit mode', () => {
|
||||
expect(library()).not.toContain('Neuf')
|
||||
expect(undos()).toBe(0)
|
||||
})
|
||||
|
||||
it('a refused save names several pending references as a list of the locale', async () => {
|
||||
const user = await mount()
|
||||
await editCitations(user)
|
||||
await user.click(button('Nouvelle référence'))
|
||||
await createPending(user, 'Neuf')
|
||||
await user.click(button('Nouvelle référence'))
|
||||
await createPending(user, 'Vieux')
|
||||
minted.push('ref-a', 'ref-c', 'ref-a', 'ref-c')
|
||||
await user.click(button('Enregistrer'))
|
||||
const alert = inCitations().getByRole('alert')
|
||||
expect(alert).toHaveTextContent('Neuf et Vieux')
|
||||
expect(alert).not.toHaveTextContent(';')
|
||||
})
|
||||
|
||||
it('the creation notice is set once the reference dialog is gone, never under it', async () => {
|
||||
const user = await mount()
|
||||
await editCitations(user)
|
||||
await user.click(button('Nouvelle référence'))
|
||||
await waitFor(() => expect(referenceDialog()).toBeDefined())
|
||||
await user.selectOptions(inReference().getByLabelText('Type'), 'book')
|
||||
await user.type(inReference().getByLabelText('Citation'), 'Neuf')
|
||||
const seen: string[] = []
|
||||
const observer = new MutationObserver(() => {
|
||||
if (referenceDialog()) seen.push(status() ?? '')
|
||||
})
|
||||
observer.observe(document.body, {
|
||||
subtree: true,
|
||||
childList: true,
|
||||
characterData: true,
|
||||
})
|
||||
await user.click(
|
||||
inReference().getByRole('button', { name: 'Ajouter la référence' }),
|
||||
)
|
||||
await waitFor(() => expect(referenceDialog()).toBeUndefined())
|
||||
await waitFor(() => expect(status()).toContain('Neuf'))
|
||||
observer.disconnect()
|
||||
expect(seen.filter((text) => text !== '')).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('a save of the edit form when its element is unreadable', () => {
|
||||
it('is a refusal on the save line: the draft stays, nothing written', async () => {
|
||||
await openReady({ text: sheetText() })
|
||||
const pending = {
|
||||
id: 'ref-p',
|
||||
type: 'book',
|
||||
citation: 'Neuf',
|
||||
doi: null,
|
||||
url: null,
|
||||
} as const
|
||||
const start = vi.fn(
|
||||
(_opener: unknown, cite?: (value: typeof pending) => void) =>
|
||||
cite?.(pending),
|
||||
)
|
||||
const guards = {
|
||||
register: vi.fn(),
|
||||
ask: () => ({ allowed: true }),
|
||||
askAll: () => ({ allowed: true }),
|
||||
holdLeave: vi.fn(),
|
||||
takeLeave: () => null,
|
||||
}
|
||||
const onDone = vi.fn()
|
||||
const user = userEvent.setup()
|
||||
render(
|
||||
<CitationsEditForm
|
||||
citedBy={{ ...nodeKey, path: ['fcat-a', 'fnode-gone'] }}
|
||||
readOnly={false}
|
||||
guards={guards}
|
||||
references={{ open: vi.fn(), start }}
|
||||
onDone={onDone}
|
||||
onNotice={vi.fn()}
|
||||
onDiscardClose={vi.fn()}
|
||||
/>,
|
||||
)
|
||||
await user.click(screen.getByRole('button', { name: 'Nouvelle référence' }))
|
||||
await user.click(screen.getByRole('button', { name: 'Enregistrer' }))
|
||||
const alert = screen.getByRole('alert')
|
||||
expect(alert).toHaveTextContent("Ce constat n'existe plus")
|
||||
expect(alert).toHaveTextContent(
|
||||
'Nouvelle référence non enregistrée, toujours dans le brouillon : Neuf',
|
||||
)
|
||||
expect(onDone).not.toHaveBeenCalled()
|
||||
expect(screen.getByText('Neuf')).toBeVisible()
|
||||
expect(undos()).toBe(0)
|
||||
})
|
||||
})
|
||||
|
||||
describe('a finding draft and a references draft on the same element', () => {
|
||||
|
||||
Reference in new issue
Block a user