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
@@ -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