test(client): align resize fixtures and restore branch coverage

This commit is contained in:
imccyu committed 2026-09-22 22:08:50 +08:00
1 parent fad9e27706
commit f6966f8fab
6 files changed
+33 -10

No files matched your search

@@ -393,7 +393,7 @@ function paginate(
events: readonly SessionEvent[],
beforeSeq: SessionLogOffsetType | undefined,
maxMessages: number,
throughSeq: SessionSeqCursor = events.at(-1)?.seq ?? -1,
throughSeq: SessionSeqCursor,
turnWindow?: SessionPageRequest['turnWindow'],
): { readonly events: SessionEvent[]; readonly hasMore: boolean } {
const end = SessionLogOffset(Math.min(throughSeq + 1, beforeSeq ?? throughSeq + 1))
@@ -193,13 +193,19 @@ it('closes help even when the browser reports no previously focused element', ()
it.each([false, true])('only offers a description tooltip when the card clips it: %s', (overflow) => {
vi.spyOn(Element.prototype, 'scrollHeight', 'get').mockReturnValue(overflow ? 400 : 80)
vi.spyOn(Element.prototype, 'clientHeight', 'get').mockReturnValue(80)
const disconnect = vi.fn()
vi.stubGlobal('ResizeObserver', class { observe() {} disconnect = disconnect })
const disconnect = vi.spyOn(ResizeObserver.prototype, 'disconnect')
vi.useFakeTimers()
view({ rows: [{ id: 'mine', isDefault: false, description: 'Preset description' }] })
fireEvent.mouseEnter(screen.getByText('Preset description'))
act(() => { vi.advanceTimersByTime(400) })
expect(screen.queryByRole('tooltip')?.textContent ?? null).toBe(overflow ? 'Preset description' : null)
cleanup()
expect(disconnect).toHaveBeenCalledOnce()
expect(disconnect).toHaveBeenCalledTimes(overflow ? 2 : 1)
})
it('renders descriptions and allows selection without resize observation', () => {
vi.stubGlobal('ResizeObserver', undefined)
const actions = view({ rows: [{ id: 'mine', name: 'Mine', isDefault: false, description: 'Preset description' }] })
expect(screen.getByText('Preset description')).toBeTruthy()
fireEvent.click(screen.getByRole('button', { name: `${en.setDefault}: Mine` }))
expect(actions.makeDefault).toHaveBeenCalledWith('mine')
})
@@ -1,12 +1,8 @@
/** jsdom omits resize observation and font loading; layout tests drive their own measurements. */
/** jsdom font-loading events; layout tests drive their own measurements. */
import { beforeEach, afterEach, vi } from 'vitest'
const fonts = Object.getOwnPropertyDescriptor(document, 'fonts')
beforeEach(() => {
vi.stubGlobal('ResizeObserver', class {
observe(): void {}
disconnect(): void {}
})
Object.defineProperty(document, 'fonts', { configurable: true, value: new EventTarget() })
})
afterEach(() => {
@@ -462,7 +462,8 @@ describe('DockSurface', () => {
expect(document.querySelector('[data-dockkit-split-button]')).toBeNull()
})
it('names the chip box\'s hidden sides in data-dockkit-strip-scroll as it scrolls', () => {
it.each([true, false])('names the chip box\'s hidden sides as it scrolls with resize observation: %s', (observed) => {
if (!observed) vi.stubGlobal('ResizeObserver', undefined)
let scrollLeft = 0
const descriptors = ['scrollLeft', 'scrollWidth', 'clientWidth'].map(name =>
[name, Object.getOwnPropertyDescriptor(Element.prototype, name)] as const)
@@ -48,6 +48,9 @@ describe('Tooltip', () => {
const bubble = view.container.querySelector<HTMLElement>('[role="tooltip"]')!
expect(measured.mock.contexts).toEqual([anchor])
expect(bubble.style.visibility).toBe('hidden')
fireEvent(window, new Event('resize'))
expect(bubble.style.visibility).toBe('hidden')
expect(measured.mock.contexts).toEqual([anchor])
bubbleSize = { inlineSize: 100, blockSize: 20 }
act(() => { observers[0]!.deliver() })
expect(screen.getByRole('tooltip').style.left).toBe('62px')
@@ -66,6 +66,23 @@ it('resolves missing and small content to 100 percent', () => {
expect(fitWidthZoom(200, 100, 24)).toBe(1)
})
it('fits the initial pane and allows fixed zoom without resize observation', () => {
vi.stubGlobal('ResizeObserver', undefined)
const onPreference = vi.fn()
render(<ZoomViewport preference={FIT_WIDTH} intrinsicWidth={1000} horizontalInset={20}
labels={{ controls: 'Zoom controls', menu: 'Choose zoom', out: 'Zoom out', into: 'Zoom in',
fitWidth: 'Fit width', value: percent => `${String(percent)}%` }} signal={new AbortController().signal}
scrollportRef={() => {}} onPreference={onPreference}>
<div className={zoomSurfaceClass} />
</ZoomViewport>)
const menu = screen.getByRole('button', { name: 'Choose zoom' })
expect(menu.textContent).toContain('48%')
fireEvent.click(menu)
fireEvent.click(screen.getByRole('menuitem', { name: '100%' }))
expect(onPreference).toHaveBeenCalledExactlyOnceWith({ kind: 'fixed', scale: 1 })
expect(menu.textContent).toContain('100%')
})
it('keeps a centred surface point under the pointer while crossing into overflow', () => {
const onPreference = vi.fn()
const view = render(<ZoomViewport preference={{ kind: 'fixed', scale: 0.5 }} intrinsicWidth={400}