Files
ComfyUI_frontend/src/platform/workspace/composables/useWorkspaceSwitch.test.ts
Christian Byrne d65d8ec06e [backport core/1.41] fix: remove workspace switching confirmation dialog (#9250) (#9564)
Backport of #9250 to core/1.41.

Cherry-pick of merge commit 2875f897 applied cleanly (auto-merge on
locale files).

**Original PR:** https://github.com/Comfy-Org/ComfyUI_frontend/pull/9250
**Pipeline ticket:** 15e1f241-efaa-4fe5-88ca-4ccc7bfb3345

┆Issue is synchronized with this [Notion
page](https://www.notion.so/PR-9564-backport-core-1-41-fix-remove-workspace-switching-confirmation-dialog-9250-31d6d73d3650818b86eeeedc79b3d6c5)
by [Unito](https://www.unito.io)
2026-03-07 18:18:18 -08:00

70 lines
1.9 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { useWorkspaceSwitch } from '@/platform/workspace/composables/useWorkspaceSwitch'
import type { WorkspaceWithRole } from '@/platform/workspace/api/workspaceApi'
const mockSwitchWorkspace = vi.hoisted(() => vi.fn())
const mockActiveWorkspace = vi.hoisted(() => ({
value: null as WorkspaceWithRole | null
}))
vi.mock('@/platform/workspace/stores/teamWorkspaceStore', () => ({
useTeamWorkspaceStore: () => ({
switchWorkspace: mockSwitchWorkspace
})
}))
vi.mock('pinia', () => ({
storeToRefs: () => ({
activeWorkspace: mockActiveWorkspace
})
}))
describe('useWorkspaceSwitch', () => {
beforeEach(() => {
vi.clearAllMocks()
mockActiveWorkspace.value = {
id: 'workspace-1',
name: 'Test Workspace',
type: 'personal',
role: 'owner',
created_at: '2026-01-01T00:00:00Z',
joined_at: '2026-01-01T00:00:00Z'
}
})
afterEach(() => {
vi.unstubAllGlobals()
})
describe('switchWorkspace', () => {
it('returns true immediately if switching to the same workspace', async () => {
const { switchWorkspace } = useWorkspaceSwitch()
const result = await switchWorkspace('workspace-1')
expect(result).toBe(true)
expect(mockSwitchWorkspace).not.toHaveBeenCalled()
})
it('switches directly to the new workspace', async () => {
mockSwitchWorkspace.mockResolvedValue(undefined)
const { switchWorkspace } = useWorkspaceSwitch()
const result = await switchWorkspace('workspace-2')
expect(result).toBe(true)
expect(mockSwitchWorkspace).toHaveBeenCalledWith('workspace-2')
})
it('returns false if switchWorkspace throws an error', async () => {
mockSwitchWorkspace.mockRejectedValue(new Error('Switch failed'))
const { switchWorkspace } = useWorkspaceSwitch()
const result = await switchWorkspace('workspace-2')
expect(result).toBe(false)
})
})
})