feat(editor): finding dialog and citations side sheet in the history
Constats opens each element in one modal dialog (view, edit with a local draft, creation) driven by the editor view layer of the browser history. The citations panel becomes a modal side sheet stacked over it; its geometry, exit machinery and page inertness are removed. Back and Forward restore the layers, a dirty form asks first.
This commit is contained in:
1 parent
8e4f02620a
commit
18085cecf8
50 files changed
+2642
-1504
No files matched your search
@@ -1,4 +1,4 @@
|
||||
/** R2F-1/2: guard stack, announcer queue, a Back refused while the citations panel is open. */
|
||||
/** R2F-1/2: guard stack, announcer queue, a Back over the finding layers. */
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import {
|
||||
act,
|
||||
@@ -46,8 +46,12 @@ function Page({ guard }: { guard?: () => { allowed: boolean } }) {
|
||||
return (
|
||||
<>
|
||||
<EditorTabs active={nav.state.tab} tier="wide" onSelect={nav.selectTab} />
|
||||
<button onClick={() => nav.openFinding(finding)}>open</button>
|
||||
<button onClick={() => nav.openCitations(finding)}>cite</button>
|
||||
<button onClick={() => nav.registerCanLeave(guard ?? null)}>guard</button>
|
||||
<button onClick={() => nav.guards.register('finding', guard ?? null)}>
|
||||
guard
|
||||
</button>
|
||||
<p data-testid="layer">{JSON.stringify(nav.state.finding)}</p>
|
||||
<button onClick={() => nav.announce('one')}>say one</button>
|
||||
<button onClick={() => nav.announce('two')}>say two</button>
|
||||
<p data-testid="live">{nav.live}</p>
|
||||
@@ -62,24 +66,63 @@ const mount = (guard?: () => { allowed: boolean }) =>
|
||||
</MemoryRouter>,
|
||||
)
|
||||
|
||||
describe('a Back while the citations panel is open', () => {
|
||||
it('keeps the page where it is, asks the dirty layer, and pushes the view again', async () => {
|
||||
describe('a Back over the finding layers', () => {
|
||||
async function openSheet(guard?: () => { allowed: boolean }) {
|
||||
useLocaleStore.setState({ locale: 'fr' })
|
||||
const user = userEvent.setup()
|
||||
const guard = vi.fn(() => ({ allowed: false }))
|
||||
mount(guard)
|
||||
await user.click(screen.getByRole('button', { name: 'guard' }))
|
||||
if (guard) await user.click(screen.getByRole('button', { name: 'guard' }))
|
||||
await user.click(screen.getByRole('tab', { name: 'Constats' }))
|
||||
await user.click(screen.getByRole('button', { name: 'open' }))
|
||||
await user.click(screen.getByRole('button', { name: 'cite' }))
|
||||
const before = entry().id
|
||||
return user
|
||||
}
|
||||
const layer = () => JSON.parse(screen.getByTestId('layer').textContent!)
|
||||
|
||||
it('closes the sheet first, then the dialog, one layer per entry', async () => {
|
||||
await openSheet()
|
||||
expect(layer()).toMatchObject({ citations: true })
|
||||
expect(entry().below?.finding).toMatchObject({ citations: false })
|
||||
act(() => navigate(-1))
|
||||
expect(guard).toHaveBeenCalledWith(false)
|
||||
expect(layer()).toMatchObject({ citations: false })
|
||||
act(() => navigate(-1))
|
||||
expect(layer()).toBeNull()
|
||||
expect(screen.getByRole('tab', { selected: true })).toHaveTextContent(
|
||||
'Constats',
|
||||
)
|
||||
})
|
||||
|
||||
it('a dirty layer keeps the page where it is: asked, the view pushed again', async () => {
|
||||
const guard = vi.fn(() => ({ allowed: false }))
|
||||
await openSheet(guard)
|
||||
const before = entry().id
|
||||
act(() => navigate(-1))
|
||||
expect(guard).toHaveBeenCalledWith(false)
|
||||
expect(layer()).toMatchObject({ citations: true })
|
||||
expect(entry().id).not.toBe(before)
|
||||
expect(entry().view.tab).toBe('findings')
|
||||
expect(entry().below?.tab).toBe('general')
|
||||
expect(entry().view.finding).toMatchObject({ citations: true })
|
||||
expect(entry().below?.finding).toMatchObject({ citations: false })
|
||||
})
|
||||
|
||||
it('a modal that is no layer refuses the Back too', async () => {
|
||||
await openSheet()
|
||||
const dialog = document.createElement('dialog')
|
||||
dialog.setAttribute('open', '')
|
||||
document.body.append(dialog)
|
||||
act(() => navigate(-1))
|
||||
expect(layer()).toMatchObject({ citations: true })
|
||||
dialog.remove()
|
||||
})
|
||||
|
||||
it('a layer dialog open does not refuse it', async () => {
|
||||
await openSheet()
|
||||
const dialog = document.createElement('dialog')
|
||||
dialog.setAttribute('open', '')
|
||||
dialog.setAttribute('data-layer', '')
|
||||
document.body.append(dialog)
|
||||
act(() => navigate(-1))
|
||||
expect(layer()).toMatchObject({ citations: false })
|
||||
dialog.remove()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user