// @vitest-environment jsdom // // A toast with an action (the list page's "Undo") outlives a short toast setting: its button is the // only way back, so it gets ACTION_TTL_MIN at least (owner, E28 S3e2). The setting still wins when it // is longer, "never" still means never, and a plain toast keeps the reader's time. import { describe, it, expect, afterEach, beforeEach, vi } from "vitest"; import { ACTION_TTL_MIN, clearAll, configureNotifications, getActiveToasts, notify, } from "./notifications"; beforeEach(() => vi.useFakeTimers()); afterEach(() => { clearAll(); configureNotifications({ durationMs: 6000 }); vi.useRealTimers(); }); const undo = { label: "Undo", onClick: () => {} }; const shown = (id: number) => getActiveToasts().some((n) => n.id === id); describe("an action toast's lifetime", () => { it("stays for the floor when the reader's toasts last 3 s", () => { configureNotifications({ durationMs: 3000 }); const plain = notify({ message: "plain" }); const withUndo = notify({ message: "removed", action: undo }); vi.advanceTimersByTime(3001); expect(shown(plain)).toBe(false); expect(shown(withUndo)).toBe(true); vi.advanceTimersByTime(ACTION_TTL_MIN - 3001); expect(shown(withUndo)).toBe(false); }); it("keeps a longer setting", () => { configureNotifications({ durationMs: 12000 }); const id = notify({ message: "removed", action: undo }); vi.advanceTimersByTime(ACTION_TTL_MIN + 1); expect(shown(id)).toBe(true); vi.advanceTimersByTime(12000 - ACTION_TTL_MIN); expect(shown(id)).toBe(false); }); it("never dismisses when the reader chose never", () => { configureNotifications({ durationMs: 0 }); const id = notify({ message: "removed", action: undo }); vi.advanceTimersByTime(60000); expect(shown(id)).toBe(true); }); });