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
@@ -178,16 +178,17 @@ describe('opening', () => {
|
||||
expect(panel()).toHaveAttribute('aria-labelledby', 'editor-citations-title')
|
||||
})
|
||||
|
||||
it('a family keeps its inline list: no trigger, no panel', async () => {
|
||||
it('a family lists its citations read-only: no trigger, no Retirer, no panel', async () => {
|
||||
const user = await mount()
|
||||
await select(user, /Cat A/)
|
||||
const detail = screen.getByRole('tabpanel', { name: 'Constats' })
|
||||
expect(
|
||||
within(detail).queryByRole('button', { name: /références?$/ }),
|
||||
).toBeNull()
|
||||
expect(within(detail).getByText('Barone, Ostéologie')).toBeVisible()
|
||||
expect(
|
||||
within(detail).getAllByRole('button', { name: /^Retirer / }),
|
||||
).toHaveLength(2)
|
||||
within(detail).queryByRole('button', { name: /^Retirer/ }),
|
||||
).toBeNull()
|
||||
expect(hasPanel()).toBe(false)
|
||||
})
|
||||
|
||||
@@ -204,7 +205,7 @@ describe('opening', () => {
|
||||
expect(panel()).not.toHaveTextContent('Denoix')
|
||||
})
|
||||
|
||||
it('an open tile marks the current finding and offers Modifier and « Retirer de ce constat »', async () => {
|
||||
it('an open tile marks the current finding and offers Modifier only', async () => {
|
||||
const user = await mount()
|
||||
await openFromFinding(user)
|
||||
await user.click(within(panel()).getByRole('button', { name: /^Barone/ }))
|
||||
@@ -214,10 +215,12 @@ describe('opening', () => {
|
||||
within(tile).getAllByRole('button', { name: /^Aller à / }),
|
||||
).toHaveLength(2)
|
||||
expect(within(tile).getByRole('button', { name: 'Modifier' })).toBeVisible()
|
||||
expect(
|
||||
within(tile).getByRole('button', { name: 'Retirer de ce constat' }),
|
||||
).toBeVisible()
|
||||
for (const absent of ['Supprimer', 'Monter', 'Descendre']) {
|
||||
for (const absent of [
|
||||
'Retirer de ce constat',
|
||||
'Supprimer',
|
||||
'Monter',
|
||||
'Descendre',
|
||||
]) {
|
||||
expect(within(panel()).queryByRole('button', { name: absent })).toBeNull()
|
||||
}
|
||||
})
|
||||
@@ -486,101 +489,26 @@ describe('the library and the history around the panel', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('« Retirer de ce constat »', () => {
|
||||
const retire = (user: User, at = 0) =>
|
||||
user.click(
|
||||
within(panel()).getAllByRole('button', { name: 'Retirer de ce constat' })[
|
||||
at
|
||||
],
|
||||
)
|
||||
|
||||
async function openTile(user: User, citation: RegExp) {
|
||||
await user.click(within(panel()).getByRole('button', { name: citation }))
|
||||
}
|
||||
|
||||
it('removes only that id, the reference stays, one undo restores it with the status', async () => {
|
||||
describe('the sheet cannot remove a citation (the edit form does)', () => {
|
||||
it('no tile offers « Retirer de ce constat »', async () => {
|
||||
const user = await mount()
|
||||
act(() => {
|
||||
store.getState().commit({
|
||||
op: 'set_status',
|
||||
key: {
|
||||
kind: 'finding',
|
||||
zone_id: 'zone-a',
|
||||
path: ['fcat-a', 'fnode-a'],
|
||||
},
|
||||
status: 'reviewed',
|
||||
})
|
||||
})
|
||||
expect(nodeA().review_status).toBe('reviewed')
|
||||
await openFromFinding(user)
|
||||
const history = store.getState().undo.length
|
||||
await openTile(user, /^Barone/)
|
||||
await retire(user)
|
||||
expect(nodeA().reference_ids).toEqual(['ref-c'])
|
||||
expect(nodeA().review_status).toBe('to_confirm')
|
||||
expect(doc().references).toHaveLength(3)
|
||||
expect(store.getState().undo.length).toBe(history + 1)
|
||||
expect(tiles()).toHaveLength(1)
|
||||
expect(panel()).toHaveTextContent('1 référence citée par ce constat')
|
||||
act(() => void store.getState().undoStep())
|
||||
expect(nodeA().reference_ids).toEqual(['ref-a', 'ref-c'])
|
||||
expect(nodeA().review_status).toBe('reviewed')
|
||||
expect(tiles()).toHaveLength(2)
|
||||
})
|
||||
|
||||
it('the focus goes to the next tile, else the previous, else the heading', async () => {
|
||||
const ids = ['ref-a', 'ref-b', 'ref-c']
|
||||
const user = await mount(1280, nodeText(ids))
|
||||
await openFromFinding(user, '3 références')
|
||||
const header = (at: number) => () =>
|
||||
tiles()[at].querySelector('button') as HTMLElement
|
||||
await openTile(user, /^Barone/)
|
||||
await retire(user)
|
||||
await focusIs(header(0))
|
||||
expect(header(0)().textContent).toContain('Denoix')
|
||||
await openTile(user, /^Code rural/)
|
||||
await retire(user, 0)
|
||||
await focusIs(header(0))
|
||||
expect(tiles()).toHaveLength(1)
|
||||
await openTile(user, /^Denoix/)
|
||||
await retire(user)
|
||||
await focusIs(heading)
|
||||
})
|
||||
|
||||
it('the last citation gone: the panel stays with its line and « Tout afficher »', async () => {
|
||||
const user = await mount(1280, nodeText(['ref-a']))
|
||||
await openFromFinding(user, '1 référence')
|
||||
await user.click(within(panel()).getByRole('button', { name: /^Barone/ }))
|
||||
await retire(user)
|
||||
expect(panel()).toHaveTextContent(
|
||||
'Ce constat ne cite plus aucune référence.',
|
||||
)
|
||||
expect(
|
||||
within(panel()).getByRole('button', {
|
||||
name: "Tout afficher dans l'onglet Références",
|
||||
}),
|
||||
).toBeVisible()
|
||||
expect(hasPanel()).toBe(true)
|
||||
await user.click(closeButton())
|
||||
await closed()
|
||||
// the trigger is gone with its count: the focus stays inside the finding dialog
|
||||
expect(findingDialog()!.contains(document.activeElement)).toBe(true)
|
||||
within(panel()).queryByRole('button', { name: /^Retirer/ }),
|
||||
).toBeNull()
|
||||
expect(nodeA().reference_ids).toEqual(['ref-a', 'ref-c'])
|
||||
})
|
||||
|
||||
it('a dangling id is a « Référence introuvable » row with Retirer, counted like the rest', async () => {
|
||||
it('a dangling id is a « Référence introuvable » row, counted, without Retirer', async () => {
|
||||
const user = await mount(1280, nodeText(['ref-a', 'ref-gone']))
|
||||
await openFromFinding(user)
|
||||
expect(panel()).toHaveTextContent('2 références citées par ce constat')
|
||||
expect(tiles()).toHaveLength(2)
|
||||
expect(tiles()[1]).toHaveTextContent('Référence introuvable')
|
||||
await user.click(
|
||||
within(tiles()[1] as HTMLElement).getByRole('button', {
|
||||
name: /^Retirer/,
|
||||
}),
|
||||
)
|
||||
expect(nodeA().reference_ids).toEqual(['ref-a'])
|
||||
expect(tiles()).toHaveLength(1)
|
||||
await focusIs(() => tiles()[0].querySelector('button')!)
|
||||
expect(
|
||||
within(panel()).queryByRole('button', { name: /^Retirer/ }),
|
||||
).toBeNull()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user