import { describe, expect, it } from 'vitest' import { closeModule, initialWorkspace, openModule, restoreWorkspace } from './workspace' describe('openModule', () => { it('opens each module once and activates an existing tab', () => { const opened = openModule(initialWorkspace, 'tasks') const reopened = openModule(opened, 'tasks') expect(reopened.openTabs).toEqual(['dashboard', 'tasks']) expect(reopened.activeTab).toBe('tasks') }) }) describe('closeModule', () => { it('activates the nearest tab on the left after closing the active tab', () => { const result = closeModule( { openTabs: ['dashboard', 'releases', 'tasks'], activeTab: 'tasks' }, 'tasks', ) expect(result).toEqual({ openTabs: ['dashboard', 'releases'], activeTab: 'releases' }) }) it('keeps the dashboard tab pinned', () => { const result = closeModule( { openTabs: ['dashboard', 'tasks'], activeTab: 'dashboard' }, 'dashboard', ) expect(result).toEqual({ openTabs: ['dashboard', 'tasks'], activeTab: 'dashboard' }) }) }) describe('restoreWorkspace', () => { it('restores open tabs and the active tab from saved state', () => { const result = restoreWorkspace( JSON.stringify({ openTabs: ['dashboard', 'tasks', 'releases'], activeTab: 'tasks' }), ) expect(result).toEqual({ openTabs: ['dashboard', 'tasks', 'releases'], activeTab: 'tasks' }) }) it('drops superseded source-link and pending-file tabs from saved state', () => { const result = restoreWorkspace( JSON.stringify({ openTabs: ['dashboard', 'sources', 'knowledge', 'settings'], activeTab: 'knowledge' }), ) expect(result).toEqual({ openTabs: ['dashboard', 'settings'], activeTab: 'dashboard' }) }) })