fix(editor): Task 1 review round 1, section back pops, scroll proof
This commit is contained in:
1 parent
792394d3b2
commit
8e4f02620a
7 files changed
+251
-64
No files matched your search
@@ -68,6 +68,14 @@ describe('readEntry and ownership', () => {
|
||||
expect(ownedEntry(stateOf(entry()), { ...mine, userId: 'V' })).toBeNull()
|
||||
})
|
||||
|
||||
it('refuses an owner without a sheet or an account', () => {
|
||||
const blank = entry({ sheetId: '', userId: '' })
|
||||
expect(ownedEntry(stateOf(blank), { sheetId: '', userId: '' })).toBeNull()
|
||||
expect(
|
||||
ownedEntry(stateOf(entry()), { sheetId: 'S', userId: '' }),
|
||||
).toBeNull()
|
||||
})
|
||||
|
||||
it('keeps only navigation: nothing typed survives the read', () => {
|
||||
const raw = { ...entry(), draft: 'typed text', term: 'search' }
|
||||
expect(JSON.stringify(readEntry(stateOf(raw)))).not.toContain('typed')
|
||||
@@ -92,6 +100,21 @@ describe('planWrite', () => {
|
||||
expect(planWrite(onAnnotations, views, false)).toBe('push')
|
||||
})
|
||||
|
||||
it('goes back for a section left for its drawing, else replaces', () => {
|
||||
const drawing = view('annotations')
|
||||
const inSection = entry({
|
||||
view: view('annotations', { section: 'views' }),
|
||||
below: drawing,
|
||||
})
|
||||
expect(planWrite(inSection, drawing, false)).toBe('back')
|
||||
const reloaded = entry({ view: inSection.view, below: null })
|
||||
expect(planWrite(reloaded, drawing, false)).toBe('replace')
|
||||
// another section, or another tab, is a step forward
|
||||
const regions = view('annotations', { section: 'regions' })
|
||||
expect(planWrite(inSection, regions, false)).toBe('push')
|
||||
expect(planWrite(inSection, view('general'), false)).toBe('push')
|
||||
})
|
||||
|
||||
it('goes back for a layer removed when the entry holds the view below', () => {
|
||||
const layer = view('findings', { reference: { create: true } })
|
||||
const opened = entry({ view: layer, below: view('findings') })
|
||||
|
||||
@@ -128,6 +128,21 @@ describe('the announcer', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('the announcer, a wait that never fires', () => {
|
||||
it('does not hold later messages back', async () => {
|
||||
const user = userEvent.setup()
|
||||
mount()
|
||||
const dialog = document.createElement('dialog')
|
||||
dialog.setAttribute('open', '')
|
||||
document.body.append(dialog)
|
||||
await user.click(screen.getByRole('button', { name: 'say one' }))
|
||||
// the dialog goes without ModalDialog's cleanup: nothing flushes the queue
|
||||
dialog.remove()
|
||||
await user.click(screen.getByRole('button', { name: 'say two' }))
|
||||
expect(screen.getByTestId('live')).toHaveTextContent('one. two')
|
||||
})
|
||||
})
|
||||
|
||||
describe('useBeforeUnload', () => {
|
||||
it('asks while dirty and stops when clean', () => {
|
||||
const { rerender } = renderHook(({ dirty }) => useBeforeUnload(dirty), {
|
||||
|
||||
@@ -99,7 +99,7 @@ describe('mount', () => {
|
||||
})
|
||||
|
||||
describe('tab and section moves', () => {
|
||||
it('a tab click pushes, Back and Forward restore it, the tab button holds the focus', async () => {
|
||||
it('a tab click pushes, Back and Forward restore it, the tab holds focus', async () => {
|
||||
const user = userEvent.setup()
|
||||
mountDraft({ probe })
|
||||
await ready()
|
||||
@@ -132,22 +132,24 @@ describe('tab and section moves', () => {
|
||||
expect(selected()).not.toBe('Constats')
|
||||
})
|
||||
|
||||
it('an Annotations section pushes, « Retour au dessin » too, Back returns to the section', async () => {
|
||||
// R-24: the first version of this case expected « Retour au dessin » to push and Back to
|
||||
// return to the section; R2F-1 makes it a removal (a pop), so no duplicate entry remains.
|
||||
it('a section is an entry; « Retour au dessin » pops it: no duplicate', async () => {
|
||||
const user = userEvent.setup()
|
||||
mountDraft({ probe })
|
||||
mountDraft({ probe, entries: ['/app/admin', path] })
|
||||
await ready()
|
||||
await user.click(tab('Annotations'))
|
||||
await waitFor(() => expect(written()?.view.tab).toBe('annotations'))
|
||||
const drawing = written()?.id
|
||||
await user.click(screen.getByRole('button', { name: 'Vues' }))
|
||||
await waitFor(() => expect(written()?.view.section).toBe('views'))
|
||||
expect(written()?.below?.section).toBe('drawing')
|
||||
await user.click(screen.getByRole('button', { name: 'Retour au dessin' }))
|
||||
await waitFor(() => expect(written()?.view.section).toBe('drawing'))
|
||||
await waitFor(() => expect(written()?.id).toBe(drawing))
|
||||
expect(written()?.view.section).toBe('drawing')
|
||||
// one more Back leaves the drawing for the entry before it, not for the section
|
||||
back()
|
||||
await waitFor(() =>
|
||||
expect(
|
||||
screen.getByRole('button', { name: 'Retour au dessin' }),
|
||||
).toBeVisible(),
|
||||
)
|
||||
expect(written()?.view.section).toBe('views')
|
||||
await waitFor(() => expect(selected()).not.toBe('Annotations'))
|
||||
})
|
||||
|
||||
it('a move that changes nothing writes nothing', async () => {
|
||||
@@ -161,7 +163,57 @@ describe('tab and section moves', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('scroll', () => {
|
||||
const scrollAt = (y: number) =>
|
||||
Object.defineProperty(window, 'scrollY', { configurable: true, value: y })
|
||||
afterEach(() => scrollAt(0))
|
||||
|
||||
it('takes the offset in the move, restores it on Back', async () => {
|
||||
const scrollTo = vi.spyOn(window, 'scrollTo').mockImplementation(() => {})
|
||||
const user = userEvent.setup()
|
||||
mountDraft({ probe })
|
||||
await ready()
|
||||
await waitFor(() => expect(written()).toBeTruthy())
|
||||
scrollAt(300)
|
||||
await user.click(tab('Constats'))
|
||||
await waitFor(() => expect(written()?.view.tab).toBe('findings'))
|
||||
scrollAt(40)
|
||||
back()
|
||||
await waitFor(() => expect(scrollTo).toHaveBeenCalledWith(0, 300))
|
||||
back(1)
|
||||
await waitFor(() => expect(scrollTo).toHaveBeenCalledWith(0, 40))
|
||||
})
|
||||
|
||||
it('is manual while the editor is mounted, as it was after', async () => {
|
||||
window.history.scrollRestoration = 'auto'
|
||||
const view = mountDraft({ probe })
|
||||
await ready()
|
||||
expect(window.history.scrollRestoration).toBe('manual')
|
||||
view.unmount()
|
||||
expect(window.history.scrollRestoration).toBe('auto')
|
||||
})
|
||||
})
|
||||
|
||||
describe('a Back that must not unmount what is on screen', () => {
|
||||
it('also refuses to replace a foreign entry while a dialog is open', async () => {
|
||||
const entries = [{ pathname: path, state: foreign({ sheetId: 'x' }) }, path]
|
||||
mountDraft({ probe, entries })
|
||||
await ready()
|
||||
await waitFor(() => expect(written()?.sheetId).toBe(SHEET))
|
||||
const before = selected()
|
||||
const dialog = document.createElement('dialog')
|
||||
dialog.setAttribute('open', '')
|
||||
document.body.append(dialog)
|
||||
const id = written()?.id
|
||||
back()
|
||||
await waitFor(() => expect(written()?.id).not.toBe(id))
|
||||
expect(selected()).toBe(before)
|
||||
expect(written()?.sheetId).toBe(SHEET)
|
||||
// pushed again above the landed entry, not replaced by a first entry
|
||||
expect(written()?.below).not.toBeNull()
|
||||
dialog.remove()
|
||||
})
|
||||
|
||||
it('keeps the view and pushes it again while a dialog is open', async () => {
|
||||
const user = userEvent.setup()
|
||||
mountDraft({ probe })
|
||||
|
||||
Reference in new issue
Block a user