import { describe, expect, it } from "vitest"; import { notificationHref, notificationPhrase, notificationTarget } from "#lib/components/notifications/notification.ts"; import type { NotificationSummary } from "#lib/components/notifications/types.ts"; 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/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"); }); }); describe("notificationPhrase", () => { it("ends without a preposition when the repo sits elsewhere", () => { expect(notificationPhrase(summary())).toBe("opened an issue"); }); it("leads into the repo when it follows", () => { expect(notificationPhrase(summary(), true)).toBe("opened an issue on"); expect(notificationPhrase(summary({ type: "repo_starred" }), true)).toBe("starred"); expect(notificationPhrase(summary({ type: "user_mentioned" }), true)).toBe( "mentioned you on an issue in" ); }); it("adds no preposition without a repo", () => { expect(notificationPhrase(summary({ repo: undefined }), true)).toBe("opened an issue"); }); }); describe("notificationTarget", () => { it("titles a row with owner/repo", () => { expect(notificationTarget(summary())).toBe("alice.test/core"); }); it("drops the owner when asked", () => { expect(notificationTarget(summary(), false)).toBe("core"); }); it("leaves a repo-less row untitled", () => { expect(notificationTarget(summary({ repo: undefined }))).toBe(""); }); });