feat(editor): cite references from the finding edit form only
This commit is contained in:
1 parent
afc1051313
commit
f0e49fd447
16 files changed
+519
-395
No files matched your search
@@ -102,8 +102,8 @@ function sheetText(): string {
|
||||
|
||||
type User = ReturnType<typeof userEvent.setup>
|
||||
|
||||
async function mount(width = 1280): Promise<User> {
|
||||
serverHas(sheetText(), 3)
|
||||
async function mount(width = 1280, text = sheetText()): Promise<User> {
|
||||
serverHas(text, 3)
|
||||
const user = userEvent.setup()
|
||||
mountDraft({ width, probe })
|
||||
await screen.findByRole('heading', { level: 1, name: 'Brouillon, version 4' })
|
||||
@@ -556,3 +556,134 @@ describe('final review: the category creation title', () => {
|
||||
expect(title.textContent).not.toContain('editor.')
|
||||
})
|
||||
})
|
||||
|
||||
const reference = (id: string, citation: string) => ({
|
||||
kind: 'reference' as const,
|
||||
value: { id, type: 'book' as const, citation, url: null, doi: null },
|
||||
})
|
||||
|
||||
/** Node A cites Alpha; Beta is cited by nobody. */
|
||||
function citingText(): string {
|
||||
let text = insert(sheetText(), reference('ref-a', 'Alpha'))
|
||||
text = insert(text, reference('ref-b', 'Beta'))
|
||||
const key = {
|
||||
kind: 'finding',
|
||||
zone_id: 'zone-a',
|
||||
path: ['fcat-a', 'fnode-a'],
|
||||
} as const
|
||||
const node = JSON.parse(text).finding_zones[0].categories[0].children[0]
|
||||
const element = {
|
||||
kind: 'finding_node',
|
||||
value: { ...node, reference_ids: ['ref-a'] },
|
||||
}
|
||||
return edit(text, { op: 'update', key, element } as never)
|
||||
}
|
||||
|
||||
const nodeIds = () =>
|
||||
doc().finding_zones[0].categories[0].children[0].reference_ids
|
||||
const cite = (user: User, label: string) =>
|
||||
user.selectOptions(inDialog().getByLabelText('Citer une référence'), label)
|
||||
const save = (user: User) =>
|
||||
user.click(inDialog().getByRole('button', { name: 'Enregistrer' }))
|
||||
const panelOpen = () => screen.queryByTestId('editor-citations-panel')
|
||||
|
||||
describe('citing references lives in the edit form (owner item 1)', () => {
|
||||
it('the view has no cite control and no remove; the trigger opens the sheet', async () => {
|
||||
const user = await mount(1280, citingText())
|
||||
await openFinding(user, /Node A/)
|
||||
expect(inDialog().queryByLabelText('Citer une référence')).toBeNull()
|
||||
expect(inDialog().queryByRole('button', { name: /^Retirer/ })).toBeNull()
|
||||
expect(
|
||||
inDialog().getByRole('button', { name: '1 référence' }),
|
||||
).toBeVisible()
|
||||
})
|
||||
|
||||
it('a family view lists its citations read-only', async () => {
|
||||
let text = insert(sheetText(), reference('ref-a', 'Alpha'))
|
||||
const key = { kind: 'finding', zone_id: 'zone-a', path: ['fcat-a'] }
|
||||
const cat = JSON.parse(text).finding_zones[0].categories[0]
|
||||
const element = {
|
||||
kind: 'finding_category',
|
||||
value: { ...cat, reference_ids: ['ref-a'] },
|
||||
}
|
||||
text = edit(text, { op: 'update', key, element } as never)
|
||||
const user = await mount(1280, text)
|
||||
await openFinding(user, /Cat A/)
|
||||
expect(inDialog().getByText('Alpha')).toBeVisible()
|
||||
expect(inDialog().queryByRole('button', { name: /^Retirer/ })).toBeNull()
|
||||
expect(inDialog().queryByLabelText('Citer une référence')).toBeNull()
|
||||
})
|
||||
|
||||
it('the form stages a cite and a remove, written only by « Enregistrer »', async () => {
|
||||
const user = await mount(1280, citingText())
|
||||
await openFinding(user, /Node A/)
|
||||
await modify(user)
|
||||
const before = entries()
|
||||
await cite(user, 'Beta')
|
||||
await user.click(inDialog().getByRole('button', { name: 'Retirer Alpha' }))
|
||||
expect(nodeIds()).toEqual(['ref-a'])
|
||||
expect(entries()).toBe(before)
|
||||
expect(
|
||||
inDialog().getByRole('button', { name: '1 référence' }),
|
||||
).toBeVisible()
|
||||
await save(user)
|
||||
expect(nodeIds()).toEqual(['ref-b'])
|
||||
expect(entries()).toBe(before + 1)
|
||||
})
|
||||
|
||||
it('one undo restores the names and the citations together', async () => {
|
||||
const user = await mount(1280, citingText())
|
||||
await openFinding(user, /Node A/)
|
||||
await modify(user)
|
||||
await user.clear(nameField())
|
||||
await user.type(nameField(), 'Renommé')
|
||||
await cite(user, 'Beta')
|
||||
await save(user)
|
||||
expect(doc().finding_zones[0].categories[0].children[0].name.fr).toBe(
|
||||
'Renommé',
|
||||
)
|
||||
expect(nodeIds()).toEqual(['ref-a', 'ref-b'])
|
||||
act(() => void store.getState().undoStep())
|
||||
expect(doc().finding_zones[0].categories[0].children[0].name.fr).toBe(
|
||||
'Node A',
|
||||
)
|
||||
expect(nodeIds()).toEqual(['ref-a'])
|
||||
})
|
||||
|
||||
it('a cite then its remove is pristine: « Enregistrer » writes nothing', async () => {
|
||||
const user = await mount(1280, citingText())
|
||||
await openFinding(user, /Node A/)
|
||||
await modify(user)
|
||||
const before = entries()
|
||||
await cite(user, 'Beta')
|
||||
await user.click(inDialog().getByRole('button', { name: 'Retirer Beta' }))
|
||||
await save(user)
|
||||
expect(entries()).toBe(before)
|
||||
})
|
||||
|
||||
it('« Annuler » with only a citation change asks, « Abandonner » writes nothing', async () => {
|
||||
const user = await mount(1280, citingText())
|
||||
await openFinding(user, /Node A/)
|
||||
await modify(user)
|
||||
const before = entries()
|
||||
await cite(user, 'Beta')
|
||||
await user.click(inDialog().getByRole('button', { name: 'Annuler' }))
|
||||
expect(inDialog().getByText('Abandonner les modifications ?')).toBeVisible()
|
||||
await user.click(inDialog().getByRole('button', { name: 'Abandonner' }))
|
||||
expect(entries()).toBe(before)
|
||||
expect(nodeIds()).toEqual(['ref-a'])
|
||||
})
|
||||
|
||||
it('the sheet opened from the form lists the draft and cannot remove', async () => {
|
||||
const user = await mount(1280, citingText())
|
||||
await openFinding(user, /Node A/)
|
||||
await modify(user)
|
||||
await cite(user, 'Beta')
|
||||
await user.click(inDialog().getByRole('button', { name: '2 références' }))
|
||||
await waitFor(() => expect(panelOpen()).not.toBeNull())
|
||||
const sheet = within(panelOpen()!)
|
||||
expect(sheet.getByText(/2 références citées/)).toBeVisible()
|
||||
expect(sheet.queryByRole('button', { name: /^Retirer/ })).toBeNull()
|
||||
expect(nodeIds()).toEqual(['ref-a'])
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user