mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-04-30 03:00:41 -04:00
test(frontend/copilot): cover localStorage initialiser branches with resetModules
The copilotChatMode and copilotLlmModel store fields are initialised from localStorage via IIFEs that run once at module-load time. The existing tests reset state with setState() which bypasses the initialiser, leaving the 'fast' and 'advanced' branches uncovered for codecov patch. Use vi.resetModules() + dynamic import to get a fresh store instance with pre-populated localStorage, covering both initialiser branches.
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { describe, expect, it, beforeEach, vi } from "vitest";
|
||||
import { describe, expect, it, beforeEach, afterEach, vi } from "vitest";
|
||||
import { useCopilotUIStore } from "../store";
|
||||
|
||||
vi.mock("@sentry/nextjs", () => ({
|
||||
@@ -243,3 +243,24 @@ describe("useCopilotUIStore", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("useCopilotUIStore localStorage initialisation", () => {
|
||||
afterEach(() => {
|
||||
vi.resetModules();
|
||||
window.localStorage.clear();
|
||||
});
|
||||
|
||||
it("reads fast chat mode from localStorage on store creation", async () => {
|
||||
window.localStorage.setItem("copilot-mode", "fast");
|
||||
vi.resetModules();
|
||||
const { useCopilotUIStore: fresh } = await import("../store");
|
||||
expect(fresh.getState().copilotChatMode).toBe("fast");
|
||||
});
|
||||
|
||||
it("reads advanced model from localStorage on store creation", async () => {
|
||||
window.localStorage.setItem("copilot-model", "advanced");
|
||||
vi.resetModules();
|
||||
const { useCopilotUIStore: fresh } = await import("../store");
|
||||
expect(fresh.getState().copilotLlmModel).toBe("advanced");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user