~james/core

core/web/src/lib/components/notifications/notification.test.ts -rw-r--r-- 2.5 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 15 hours ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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> = {}): 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("");
	});
});