fix(editor): Task 6 round 1, draft store tests, dead rescue
This commit is contained in:
1 parent
f0e49fd447
commit
270444e2ec
4 files changed
+66
-4
No files matched your search
@@ -11,6 +11,7 @@ import {
|
||||
import userEvent from '@testing-library/user-event'
|
||||
import type { Location, NavigateFunction } from 'react-router-dom'
|
||||
import { ENTRY_KEY, type HistoryEntry } from '@/editor/history/entry'
|
||||
import { useCitationDraft } from '@/editor/findings/citationDraft'
|
||||
import { useLocaleStore } from '@/state/localeStore'
|
||||
import { edit, insert } from '../helpers/editorFixtures'
|
||||
import { defaultView } from '@/editor/navigation'
|
||||
@@ -563,7 +564,7 @@ const reference = (id: string, citation: string) => ({
|
||||
})
|
||||
|
||||
/** Node A cites Alpha; Beta is cited by nobody. */
|
||||
function citingText(): string {
|
||||
function citingText(ids = ['ref-a']): string {
|
||||
let text = insert(sheetText(), reference('ref-a', 'Alpha'))
|
||||
text = insert(text, reference('ref-b', 'Beta'))
|
||||
const key = {
|
||||
@@ -574,7 +575,7 @@ function citingText(): string {
|
||||
const node = JSON.parse(text).finding_zones[0].categories[0].children[0]
|
||||
const element = {
|
||||
kind: 'finding_node',
|
||||
value: { ...node, reference_ids: ['ref-a'] },
|
||||
value: { ...node, reference_ids: ids },
|
||||
}
|
||||
return edit(text, { op: 'update', key, element } as never)
|
||||
}
|
||||
@@ -686,4 +687,60 @@ describe('citing references lives in the edit form (owner item 1)', () => {
|
||||
expect(sheet.queryByRole('button', { name: /^Retirer/ })).toBeNull()
|
||||
expect(nodeIds()).toEqual(['ref-a'])
|
||||
})
|
||||
|
||||
it('the published draft returns to null on « Abandonner » and on save', async () => {
|
||||
const user = await mount(1280, citingText())
|
||||
await openFinding(user, /Node A/)
|
||||
await modify(user)
|
||||
await cite(user, 'Beta')
|
||||
expect(useCitationDraft.getState().draft?.ids).toEqual(['ref-a', 'ref-b'])
|
||||
await user.click(inDialog().getByRole('button', { name: 'Annuler' }))
|
||||
await user.click(inDialog().getByRole('button', { name: 'Abandonner' }))
|
||||
expect(useCitationDraft.getState().draft).toBeNull()
|
||||
await modify(user)
|
||||
await cite(user, 'Beta')
|
||||
await save(user)
|
||||
expect(useCitationDraft.getState().draft).toBeNull()
|
||||
})
|
||||
|
||||
it('a Retirer-only change counts and lists the draft, the document stays', async () => {
|
||||
const user = await mount(1280, citingText(['ref-a', 'ref-b']))
|
||||
await openFinding(user, /Node A/)
|
||||
await modify(user)
|
||||
await user.click(inDialog().getByRole('button', { name: 'Retirer Alpha' }))
|
||||
await user.click(inDialog().getByRole('button', { name: '1 référence' }))
|
||||
await waitFor(() => expect(panelOpen()).not.toBeNull())
|
||||
const sheet = within(panelOpen()!)
|
||||
expect(sheet.getByText(/1 référence citée/)).toBeVisible()
|
||||
expect(sheet.getByText(/Beta/)).toBeVisible()
|
||||
expect(sheet.queryByText(/Alpha/)).toBeNull()
|
||||
expect(nodeIds()).toEqual(['ref-a', 'ref-b'])
|
||||
})
|
||||
|
||||
it('a read-only flip keeps a citation-only draft, never dropped silently', async () => {
|
||||
const user = await mount(1280, citingText())
|
||||
await openFinding(user, /Node A/)
|
||||
await modify(user)
|
||||
await cite(user, 'Beta')
|
||||
act(() => {
|
||||
setWidth(900)
|
||||
window.dispatchEvent(new Event('resize'))
|
||||
})
|
||||
expect(findingDialog()).not.toBeNull()
|
||||
expect(
|
||||
inDialog().getByRole('button', { name: '2 références' }),
|
||||
).toBeVisible()
|
||||
expect(inDialog().queryByLabelText('Citer une référence')).toBeNull()
|
||||
expect(
|
||||
inDialog().getByRole('button', { name: 'Enregistrer' }),
|
||||
).toBeDisabled()
|
||||
expect(nodeIds()).toEqual(['ref-a'])
|
||||
act(() => {
|
||||
setWidth(1280)
|
||||
window.dispatchEvent(new Event('resize'))
|
||||
})
|
||||
expect(
|
||||
inDialog().getByRole('button', { name: '2 références' }),
|
||||
).toBeVisible()
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user