release-notes.test.ts

2.4 KB · raw

1import { describe, it, expect, beforeEach, vi } from "vitest";23// Mock chrome.storage.local before importing the module under test.4const store: Record<string, unknown> = {};56vi.stubGlobal("chrome", {7  storage: {8    local: {9      get: vi.fn(async (key: string) => ({ [key]: store[key] })),10      set: vi.fn(async (entries: Record<string, unknown>) => {11        Object.assign(store, entries);12      }),13    },14  },15});1617// Import after globals are stubbed so the module captures the mock.18const {19  PEACH_VERSION,20  CURRENT_NOTES,21  hasReleaseNotes,22  shouldShowWhatsNew,23  markWhatsNewSeen,24} = await import("./release-notes");2526describe("release-notes", () => {27  beforeEach(() => {28    Object.keys(store).forEach((k) => delete store[k]);29    vi.clearAllMocks();30  });3132  it("PEACH_VERSION is a non-empty string", () => {33    expect(typeof PEACH_VERSION).toBe("string");34    expect(PEACH_VERSION.length).toBeGreaterThan(0);35  });3637  it("CURRENT_NOTES has entries for the V4 release", () => {38    expect(CURRENT_NOTES.length).toBeGreaterThan(0);39    const breaking = CURRENT_NOTES.find((n) => n.breaking);40    expect(breaking).toBeDefined();41    expect(breaking!.body.toLowerCase()).toContain("android");42  });4344  it("hasReleaseNotes returns true when notes exist", () => {45    expect(hasReleaseNotes()).toBe(true);46  });4748  it("shouldShowWhatsNew returns true when stored version differs", async () => {49    store["peach_whats_new_seen"] = "0.0.1";50    expect(await shouldShowWhatsNew()).toBe(true);51  });5253  it("shouldShowWhatsNew returns false when stored version matches", async () => {54    store["peach_whats_new_seen"] = PEACH_VERSION;55    expect(await shouldShowWhatsNew()).toBe(false);56  });5758  it("shouldShowWhatsNew returns true when nothing has been seen yet", async () => {59    expect(await shouldShowWhatsNew()).toBe(true);60  });6162  it("markWhatsNewSeen stores the current version and suppresses reshowing", async () => {63    expect(await shouldShowWhatsNew()).toBe(true);64    await markWhatsNewSeen();65    expect(await shouldShowWhatsNew()).toBe(false);66    expect(store["peach_whats_new_seen"]).toBe(PEACH_VERSION);67  });6869  it("a version bump re-triggers the screen", async () => {70    await markWhatsNewSeen();71    expect(await shouldShowWhatsNew()).toBe(false);72    // Simulate an older stored version (as if the user upgraded)73    store["peach_whats_new_seen"] = "5.0.0";74    expect(await shouldShowWhatsNew()).toBe(true);75  });76});