openclaw/apps/web/app/workspace/workspace-switch.test.ts
kumarabhirup 3c2138e4bd
feat(web): add workspace-switch component
New workspace-switch component and tests for workspace selection UI.
2026-03-03 13:47:02 -08:00

37 lines
1.4 KiB
TypeScript

import { describe, it, expect, vi } from "vitest";
import { resetWorkspaceStateOnSwitch } from "./workspace-switch";
describe("resetWorkspaceStateOnSwitch", () => {
it("clears file/chat state and forces a fresh main chat session", () => {
const deps = {
setBrowseDir: vi.fn(),
setActivePath: vi.fn(),
setContent: vi.fn(),
setChatSidebarPreview: vi.fn(),
setShowChatSidebar: vi.fn(),
setActiveSessionId: vi.fn(),
setActiveSubagentKey: vi.fn(),
resetMainChat: vi.fn(),
replaceUrlToWorkspace: vi.fn(),
reconnectWorkspaceWatcher: vi.fn(),
refreshSessions: vi.fn(),
refreshContext: vi.fn(),
};
resetWorkspaceStateOnSwitch(deps);
expect(deps.setBrowseDir).toHaveBeenCalledWith(null);
expect(deps.setActivePath).toHaveBeenCalledWith(null);
expect(deps.setContent).toHaveBeenCalledWith({ kind: "none" });
expect(deps.setChatSidebarPreview).toHaveBeenCalledWith(null);
expect(deps.setShowChatSidebar).toHaveBeenCalledWith(true);
expect(deps.setActiveSessionId).toHaveBeenCalledWith(null);
expect(deps.setActiveSubagentKey).toHaveBeenCalledWith(null);
expect(deps.resetMainChat).toHaveBeenCalledTimes(1);
expect(deps.replaceUrlToWorkspace).toHaveBeenCalledTimes(1);
expect(deps.reconnectWorkspaceWatcher).toHaveBeenCalledTimes(1);
expect(deps.refreshSessions).toHaveBeenCalledTimes(1);
expect(deps.refreshContext).toHaveBeenCalledTimes(1);
});
});