diff --git a/apps/app/tests/unit/canvas.bands.test.tsx b/apps/app/tests/unit/canvas.bands.test.tsx index 6f7cc7f4..909978d6 100644 --- a/apps/app/tests/unit/canvas.bands.test.tsx +++ b/apps/app/tests/unit/canvas.bands.test.tsx @@ -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( + 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('') + }) +}) diff --git a/apps/app/tests/unit/editor-annotations-tab.test.tsx b/apps/app/tests/unit/editor-annotations-tab.test.tsx index bbfc9b40..a542585a 100644 --- a/apps/app/tests/unit/editor-annotations-tab.test.tsx +++ b/apps/app/tests/unit/editor-annotations-tab.test.tsx @@ -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() }) })