1import { describe, it, expect, beforeEach, vi } from "vitest";234const 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});212223const {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 expect(breaking!.notes.some((note) => note.body.toLowerCase().includes("revoke") && note.body.toLowerCase().includes("pair"))).toBe(true);51 });5253 it("hasReleaseNotes returns true when notes exist", () => {54 expect(hasReleaseNotes()).toBe(true);55 });5657 it("combines every important release newer than the installed version", () => {58 expect(importantReleasesSince("5.0.0").map((release) => release.version)).toEqual(["5.1.3"]);59 });6061 it("combines several important patches across a skipped upgrade interval", () => {62 const selected = selectImportantReleases([63 { version: "3.0.0", releasedAt: "2026-03-03", importance: "critical", notes: [] },64 { version: "2.1.0", releasedAt: "2026-02-02", notes: [] },65 { version: "2.0.0", releasedAt: "2026-02-01", importance: "breaking", notes: [] },66 { version: "1.5.0", releasedAt: "2026-01-15", importance: "critical", notes: [] },67 ], "1.0.0", "3.0.0");68 expect(selected.map((release) => release.version)).toEqual(["3.0.0", "2.0.0", "1.5.0"]);69 });7071 it("shouldShowWhatsNew returns true when an important release was skipped", async () => {72 store["peach_release_notes_from"] = "5.0.0";73 expect(await shouldShowWhatsNew()).toBe(true);74 });7576 it("routine patches do not show the interruptive view", async () => {77 store["peach_release_notes_from"] = "5.2.4";78 expect(await shouldShowWhatsNew()).toBe(false);79 });8081 it("preserves the earliest upgrade boundary across multiple updates", async () => {82 await recordInstalledVersion({ reason: "update", previousVersion: "5.0.0" } as chrome.runtime.InstalledDetails);83 await recordInstalledVersion({ reason: "update", previousVersion: "5.1.0" } as chrome.runtime.InstalledDetails);84 expect(store["peach_release_notes_from"]).toBe("5.0.0");85 expect((await pendingImportantReleases()).map((release) => release.version)).toEqual(["5.1.3"]);86 });8788 it("shouldShowWhatsNew returns false on a fresh install (nothing seen yet)", async () => {89 expect(await shouldShowWhatsNew()).toBe(false);90 });9192 it("markWhatsNewSeen stores the current version and suppresses reshowing", async () => {93 store["peach_release_notes_from"] = "5.0.0";94 expect(await shouldShowWhatsNew()).toBe(true);95 await markWhatsNewSeen();96 expect(await shouldShowWhatsNew()).toBe(false);97 expect(store["peach_release_notes_from"]).toBeUndefined();98 });99});