From 432202c2599a90ec3fbfb98ed334d595c3b8de06 Mon Sep 17 00:00:00 2001 From: majdyz Date: Wed, 15 Apr 2026 15:10:34 +0700 Subject: [PATCH] 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. --- .../copilot/__tests__/store.test.ts | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/store.test.ts b/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/store.test.ts index 061815a3f8..fd95bbdb2c 100644 --- a/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/store.test.ts +++ b/autogpt_platform/frontend/src/app/(platform)/copilot/__tests__/store.test.ts @@ -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"); + }); +});