mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 13:47:19 +08:00
66 lines
2.1 KiB
TypeScript
66 lines
2.1 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
import { useConversationStore } from "#/stores/conversation-store";
|
|
|
|
const defaultConversationState = {
|
|
selectedTab: "editor" as const,
|
|
rightPanelShown: true,
|
|
unpinnedTabs: [] as string[],
|
|
conversationMode: "code" as const,
|
|
};
|
|
|
|
const mockGetConversationState = vi.fn((_id: string) => defaultConversationState);
|
|
const mockSetConversationState = vi.fn();
|
|
|
|
vi.mock("#/utils/conversation-local-storage", () => ({
|
|
getConversationState: (id: string) => mockGetConversationState(id),
|
|
setConversationState: (id: string, updates: object) =>
|
|
mockSetConversationState(id, updates),
|
|
}));
|
|
|
|
const CONV_ID = "conv-test-1";
|
|
|
|
describe("conversation store", () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
mockGetConversationState.mockReturnValue(defaultConversationState);
|
|
Object.defineProperty(window, "location", {
|
|
value: { pathname: `/conversations/${CONV_ID}` },
|
|
writable: true,
|
|
});
|
|
useConversationStore.setState({
|
|
conversationMode: "code",
|
|
planContent: null,
|
|
subConversationTaskId: null,
|
|
shouldHideSuggestions: false,
|
|
});
|
|
});
|
|
|
|
describe("setConversationMode", () => {
|
|
it("updates store state and persists via setConversationState when conversation ID is in location", () => {
|
|
useConversationStore.getState().setConversationMode("plan");
|
|
|
|
expect(useConversationStore.getState().conversationMode).toBe("plan");
|
|
expect(mockSetConversationState).toHaveBeenCalledWith(CONV_ID, {
|
|
conversationMode: "plan",
|
|
});
|
|
});
|
|
});
|
|
|
|
describe("resetConversationState", () => {
|
|
it("sets conversationMode from getConversationState", () => {
|
|
useConversationStore.setState({ conversationMode: "plan" });
|
|
mockGetConversationState.mockReturnValue({
|
|
selectedTab: "editor",
|
|
rightPanelShown: true,
|
|
unpinnedTabs: [],
|
|
conversationMode: "code",
|
|
});
|
|
|
|
useConversationStore.getState().resetConversationState();
|
|
|
|
expect(useConversationStore.getState().conversationMode).toBe("code");
|
|
expect(mockGetConversationState).toHaveBeenCalledWith(CONV_ID);
|
|
});
|
|
});
|
|
});
|