~james/core

core/web/src/lib/components/notifications/NotificationItem.test.ts -rw-r--r-- 1.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
import { describe, expect, it } from "vitest";
import { render } from "svelte/server";
import NotificationItem from "#lib/components/notifications/NotificationItem.svelte";
import { notifications } from "#lib/components/notifications/mock.ts";
import type { NotificationSummary } from "#lib/components/notifications/types.ts";

const rowOf = (type: NotificationSummary["type"]): NotificationSummary => {
	const found = notifications.find((notification) => notification.type === type);
	if (!found) throw new Error(`no ${type} fixture to render`);
	return found;
};

const markup = (notification: NotificationSummary): string =>
	render(NotificationItem, { props: { notification, onToggleRead: () => {} } }).body;

const insideTheLink = (html: string): string => {
	const open = html.indexOf("<a ");
	const close = html.indexOf("</a>", open);
	if (open < 0 || close < 0) throw new Error("the row rendered no link");
	return html.slice(open, close);
};

describe("a notification row", () => {
	it("no control sits inside the link, since anchors can't wrap buttons", () => {
		const html = markup(rowOf("pull_merged"));

		expect(insideTheLink(html)).not.toContain("<button");
		expect(html.split("<a ")).toHaveLength(2);
	});

	it("one link stretches across the row instead of wrapping it", () => {
		expect(insideTheLink(markup(rowOf("user_mentioned")))).toContain("after:inset-0");
	});

	it("keeps just its read toggle", () => {
		expect(markup(rowOf("pull_merged")).split("<button")).toHaveLength(2);
	});
});