test(anatomy): cover band clip on resize, restore mocks in afterEach
This commit is contained in:
1 parent
93c68e6027
commit
0c58491661
2 files changed
+54
-1
No files matched your search
@@ -30,6 +30,7 @@ beforeEach(() => {
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
vi.restoreAllMocks()
|
||||
vi.unstubAllGlobals()
|
||||
})
|
||||
|
||||
const expected = (id: string) => {
|
||||
@@ -84,3 +85,55 @@ describe('CatalogueCanvas bands (D7)', () => {
|
||||
expect(drawing.className).not.toContain('frame-band')
|
||||
})
|
||||
})
|
||||
|
||||
describe('CatalogueCanvas bands on resize (D7)', () => {
|
||||
/** A ResizeObserver whose callbacks the test fires by hand. */
|
||||
function stubObserver() {
|
||||
const callbacks: (() => void)[] = []
|
||||
vi.stubGlobal(
|
||||
'ResizeObserver',
|
||||
class {
|
||||
constructor(callback: () => void) {
|
||||
callbacks.push(callback)
|
||||
}
|
||||
observe() {}
|
||||
disconnect() {}
|
||||
},
|
||||
)
|
||||
return () => callbacks.forEach((callback) => callback())
|
||||
}
|
||||
|
||||
const mountView = (id: string) =>
|
||||
render(
|
||||
<CatalogueCanvas
|
||||
preview={preview}
|
||||
viewId={id}
|
||||
viewName={id}
|
||||
detail={id !== 'main'}
|
||||
selectedId={null}
|
||||
onAnnotation={() => undefined}
|
||||
/>,
|
||||
)
|
||||
|
||||
it('recomputes the clip of a detail view to the new box', async () => {
|
||||
const fire = stubObserver()
|
||||
const { container } = mountView('wide')
|
||||
await waitFor(() => expect(clipOf(container)).toBe(expected('wide')))
|
||||
vi.spyOn(HTMLElement.prototype, 'clientWidth', 'get').mockReturnValue(200)
|
||||
vi.spyOn(HTMLElement.prototype, 'clientHeight', 'get').mockReturnValue(400)
|
||||
fire()
|
||||
const [, , w, h] = FRAMES.wide.split(' ').map(Number)
|
||||
const resized = bandClip(bandInsets({ w: 200, h: 400 }, { w, h }))
|
||||
expect(resized).not.toBe(expected('wide'))
|
||||
expect(clipOf(container)).toBe(resized)
|
||||
})
|
||||
|
||||
it('sets nothing on the main view', async () => {
|
||||
const fire = stubObserver()
|
||||
const { container } = mountView('main')
|
||||
await waitFor(() => expect(clipOf(container)).toBe(''))
|
||||
vi.spyOn(HTMLElement.prototype, 'clientWidth', 'get').mockReturnValue(200)
|
||||
fire()
|
||||
expect(clipOf(container)).toBe('')
|
||||
})
|
||||
})
|
||||
@@ -101,6 +101,7 @@ beforeEach(() => {
|
||||
afterEach(() => {
|
||||
cleanup()
|
||||
resetStore()
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
const text = () => insert(drawnText(), named('anno-a', 50, 50, 5))
|
||||
@@ -926,7 +927,6 @@ describe('detail views between neutral bands (D7)', () => {
|
||||
expect(expected(10, 30)).not.toBe(expected(70, 10))
|
||||
await user.click(screen.getByRole('button', { name: 'Vue principale' }))
|
||||
await waitFor(() => expect(clip()).toBe(''))
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Reference in new issue
Block a user