import { describe, it, expect } from 'vitest' import { openPreviewTab, closePreviewTab } from '../src/previewtabs' describe('preview tabs', () => { it('opens a new tab and re-activates an existing one without duplicating it', () => { const first = openPreviewTab([], { id: 'a', name: '甲.docx' }) const second = openPreviewTab(first.tabs, { id: 'b', name: '乙.pptx' }) expect(second.tabs.map(t => t.id)).toEqual(['a', 'b']) expect(second.activeId).toBe('b') const again = openPreviewTab(second.tabs, { id: 'a', name: '甲.docx' }) expect(again.tabs).toHaveLength(2) expect(again.activeId).toBe('a') }) it('closing the active tab selects the neighbor, and closing another keeps the active tab', () => { const tabs = [{ id: 'a', name: '甲' }, { id: 'b', name: '乙' }, { id: 'c', name: '丙' }] const closedB = closePreviewTab(tabs, 'b', 'b') expect(closedB.tabs.map(t => t.id)).toEqual(['a', 'c']) expect(closedB.activeId).toBe('c') const closedA = closePreviewTab(closedB.tabs, 'c', 'a') expect(closedA.activeId).toBe('c') expect(closePreviewTab([{ id: 'a', name: '甲' }], 'a', 'a')).toEqual({ tabs: [], activeId: null }) }) })