release-notes.test.ts

3.7 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 | string[]) => (Array.isArray(key)10        ? Object.fromEntries(key.map((item) => [item, store[item]]))11        : { [key]: store[key] })),12      set: vi.fn(async (entries: Record<string, unknown>) => {13        Object.assign(store, entries);14      }),15      remove: vi.fn(async (key: string | string[]) => {16        for (const item of Array.isArray(key) ? key : [key]) delete store[item];17      }),18    },19  },20});2122// Import after globals are stubbed so the module captures the mock.23const {24  PEACH_VERSION,25  RELEASES,26  importantReleasesSince,27  selectImportantReleases,28  pendingImportantReleases,29  recordInstalledVersion,30  hasReleaseNotes,31  shouldShowWhatsNew,32  markWhatsNewSeen,33} = await import("./release-notes");3435describe("release-notes", () => {36  beforeEach(() => {37    Object.keys(store).forEach((k) => delete store[k]);38    vi.clearAllMocks();39  });4041  it("PEACH_VERSION is a non-empty string", () => {42    expect(typeof PEACH_VERSION).toBe("string");43    expect(PEACH_VERSION.length).toBeGreaterThan(0);44  });4546  it("RELEASES has a versioned breaking V4 entry", () => {47    const breaking = RELEASES.find((release) => release.importance === "breaking");48    expect(breaking).toBeDefined();49    expect(breaking!.notes.some((note) => note.body.toLowerCase().includes("android"))).toBe(true);50  });5152  it("hasReleaseNotes returns true when notes exist", () => {53    expect(hasReleaseNotes()).toBe(true);54  });5556  it("combines every important release newer than the installed version", () => {57    expect(importantReleasesSince("5.0.0").map((release) => release.version)).toEqual(["5.1.3"]);58  });5960  it("combines several important patches across a skipped upgrade interval", () => {61    const selected = selectImportantReleases([62      { version: "3.0.0", releasedAt: "2026-03-03", importance: "critical", notes: [] },63      { version: "2.1.0", releasedAt: "2026-02-02", notes: [] },64      { version: "2.0.0", releasedAt: "2026-02-01", importance: "breaking", notes: [] },65      { version: "1.5.0", releasedAt: "2026-01-15", importance: "critical", notes: [] },66    ], "1.0.0", "3.0.0");67    expect(selected.map((release) => release.version)).toEqual(["3.0.0", "2.0.0", "1.5.0"]);68  });6970  it("shouldShowWhatsNew returns true when an important release was skipped", async () => {71    store["peach_release_notes_from"] = "5.0.0";72    expect(await shouldShowWhatsNew()).toBe(true);73  });7475  it("routine patches do not show the interruptive view", async () => {76    store["peach_release_notes_from"] = "5.2.4";77    expect(await shouldShowWhatsNew()).toBe(false);78  });7980  it("preserves the earliest upgrade boundary across multiple updates", async () => {81    await recordInstalledVersion({ reason: "update", previousVersion: "5.0.0" } as chrome.runtime.InstalledDetails);82    await recordInstalledVersion({ reason: "update", previousVersion: "5.1.0" } as chrome.runtime.InstalledDetails);83    expect(store["peach_release_notes_from"]).toBe("5.0.0");84    expect((await pendingImportantReleases()).map((release) => release.version)).toEqual(["5.1.3"]);85  });8687  it("shouldShowWhatsNew returns false on a fresh install (nothing seen yet)", async () => {88    expect(await shouldShowWhatsNew()).toBe(false);89  });9091  it("markWhatsNewSeen stores the current version and suppresses reshowing", async () => {92    store["peach_release_notes_from"] = "5.0.0";93    expect(await shouldShowWhatsNew()).toBe(true);94    await markWhatsNewSeen();95    expect(await shouldShowWhatsNew()).toBe(false);96    expect(store["peach_release_notes_from"]).toBeUndefined();97  });98});