import { describe, expect, it } from "vitest"; import { notificationHref, notificationTarget } from "$lib/components/notifications/notification"; import type { NotificationSummary } from "$lib/components/notifications/types"; const summary = (overrides: Partial = {}): NotificationSummary => ({ uri: "at://did:plc:owner/sh.tangled.repo.issue/abc", type: "issue_created", read: false, createdAt: "2026-01-01T00:00:00.000Z", actor: { did: "did:plc:owner", handle: "alice.test" }, repo: { ownerHandle: "alice.test", name: "core" }, subject: { kind: "issue", uri: "at://did:plc:owner/sh.tangled.repo.issue/abc", number: "abc", title: "a bug" }, ...overrides }); describe("notificationHref", () => { it("links a named repo issue to its owner/repo path", () => { expect(notificationHref(summary())).toBe( "/alice.test/core/issues/at://did:plc:owner/sh.tangled.repo.issue/abc" ); }); it("links a repo-only notification to the owner/repo path", () => { expect(notificationHref(summary({ subject: undefined }))).toBe("/alice.test/core"); }); it("links a did-addressed repo by its did, without an owner/name guess", () => { expect( notificationHref( summary({ repo: { ownerHandle: "alice.test", name: "did:plc:abc123" } }) ) ).toBe("/did:plc:abc123"); }); it("falls back to the actor's page when there is no repo", () => { expect(notificationHref(summary({ repo: undefined }))).toBe("/alice.test"); }); it("links collaboration offer to its repository", () => { expect( notificationHref(summary({ type: "collaborator_invited", subject: undefined })) ).toBe("/alice.test/core"); }); }); describe("notificationTarget", () => { it("titles a row with owner/repo", () => { expect(notificationTarget(summary())).toBe("alice.test/core"); }); it("leaves a repo-less row untitled", () => { expect(notificationTarget(summary({ repo: undefined }))).toBe(""); }); });