import { describe, expect, it } from "vitest"; import { createFixtureNotifications } from "$lib/notifications.svelte"; import { notifications } from "$lib/components/notifications/mock"; import type { NotificationSummary } from "$lib/components/notifications/types"; const rows: NotificationSummary[] = notifications.map((notification, index) => ({ ...notification, uri: `at://mock/notif/${index}`, read: index % 2 === 1 })); const unreadRow = rows.find((row) => !row.read)!; const readRow = rows.find((row) => row.read)!; const baseline = rows.filter((row) => !row.read).length; const readOf = ( service: { overlay(rows: NotificationSummary[]): NotificationSummary[] }, uri: string ) => service.overlay(rows).find((row) => row.uri === uri)!.read; describe("notification read state", () => { it("moves the count with the row it marked", async () => { const service = createFixtureNotifications(rows); expect(service.unread).toBe(baseline); await service.setRead(unreadRow.uri, true); expect(service.unread).toBe(baseline - 1); expect(readOf(service, unreadRow.uri)).toBe(true); await service.setRead(unreadRow.uri, false); expect(service.unread).toBe(baseline); expect(readOf(service, unreadRow.uri)).toBe(false); }); it("ignores a mark that changes nothing", async () => { const service = createFixtureNotifications(rows); await service.setRead(unreadRow.uri, true); await service.setRead(unreadRow.uri, true); await service.setRead(readRow.uri, true); expect(service.unread).toBe(baseline - 1); }); it("empties the count and every known row on mark all read", async () => { const service = createFixtureNotifications(rows); await service.markAllRead(); expect(service.unread).toBe(0); expect(service.overlay(rows).every((row) => row.read)).toBe(true); }); });