返回 oh-my-ppt
merge-preview-window.test.ts
根目录 / tests / unit / session / merge-preview-window.test.ts
1 import { describe, expect, it } from 'vitest'
2 import { selectPreviewWindowIds } from '../../../src/renderer/src/components/session-detail/hooks/preview-window-utils'
3
4 describe('selectPreviewWindowIds', () => {
5 it('keeps only the nearest previews within the hard limit', () => {
6 const result = selectPreviewWindowIds(
7 [
8 { id: 'page-4', distance: 400 },
9 { id: 'page-2', distance: 20 },
10 { id: 'page-1', distance: 10 },
11 { id: 'page-3', distance: 30 }
12 ],
13 3
14 )
15
16 expect(Array.from(result)).toEqual(['page-1', 'page-2', 'page-3'])
17 })
18
19 it('drops invalid candidates', () => {
20 expect(
21 Array.from(
22 selectPreviewWindowIds(
23 [
24 { id: 'page-1', distance: Number.NaN },
25 { id: '', distance: 0 },
26 { id: 'page-2', distance: 1 }
27 ],
28 2
29 )
30 )
31 ).toEqual(['page-2'])
32 })
33
34 it('supports closing the preview window completely', () => {
35 expect(Array.from(selectPreviewWindowIds([{ id: 'page-1', distance: 0 }], 0))).toEqual([])
36 })
37 })
38
38 lines TYPESCRIPT