import { describe, it, expect, beforeEach, vi } from "vitest"; // Mock chrome.storage.local before importing the module under test. const store: Record = {}; vi.stubGlobal("chrome", { storage: { local: { get: vi.fn(async (key: string) => ({ [key]: store[key] })), set: vi.fn(async (entries: Record) => { Object.assign(store, entries); }), }, }, }); // Import after globals are stubbed so the module captures the mock. const { PEACH_VERSION, CURRENT_NOTES, hasReleaseNotes, shouldShowWhatsNew, markWhatsNewSeen, } = await import("./release-notes"); describe("release-notes", () => { beforeEach(() => { Object.keys(store).forEach((k) => delete store[k]); vi.clearAllMocks(); }); it("PEACH_VERSION is a non-empty string", () => { expect(typeof PEACH_VERSION).toBe("string"); expect(PEACH_VERSION.length).toBeGreaterThan(0); }); it("CURRENT_NOTES has entries for the V4 release", () => { expect(CURRENT_NOTES.length).toBeGreaterThan(0); const breaking = CURRENT_NOTES.find((n) => n.breaking); expect(breaking).toBeDefined(); expect(breaking!.body.toLowerCase()).toContain("android"); }); it("hasReleaseNotes returns true when notes exist", () => { expect(hasReleaseNotes()).toBe(true); }); it("shouldShowWhatsNew returns true when stored version differs", async () => { store["peach_whats_new_seen"] = "0.0.1"; expect(await shouldShowWhatsNew()).toBe(true); }); it("shouldShowWhatsNew returns false when stored version matches", async () => { store["peach_whats_new_seen"] = PEACH_VERSION; expect(await shouldShowWhatsNew()).toBe(false); }); it("shouldShowWhatsNew returns false on a fresh install (nothing seen yet)", async () => { expect(await shouldShowWhatsNew()).toBe(false); }); it("markWhatsNewSeen stores the current version and suppresses reshowing", async () => { // Simulate an upgrade from a previously-seen older version. store["peach_whats_new_seen"] = "0.0.1"; expect(await shouldShowWhatsNew()).toBe(true); await markWhatsNewSeen(); expect(await shouldShowWhatsNew()).toBe(false); expect(store["peach_whats_new_seen"]).toBe(PEACH_VERSION); }); it("a version bump re-triggers the screen", async () => { await markWhatsNewSeen(); expect(await shouldShowWhatsNew()).toBe(false); // Simulate an older stored version (as if the user upgraded) store["peach_whats_new_seen"] = "5.0.0"; expect(await shouldShowWhatsNew()).toBe(true); }); });