~james/core

core/web/src/lib/components/profile/profileLinks.test.ts -rw-r--r-- 1.2 KiB
452f17b7 — james chore(import): snapshot james.dad.town/core at f70c71c7696a 16 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
import { describe, expect, it } from "vitest";
import { profileLinkTarget } from "#lib/components/profile/profileLinks.ts";

describe("profileLinkTarget", () => {
	it("labels web links by host", () => {
		expect(profileLinkTarget("https://ops.sub.example.co.uk/about?x=1")).toEqual({
			href: "https://ops.sub.example.co.uk/about?x=1",
			label: "ops.sub.example.co.uk",
			external: true
		});
	});

	it("opens account links on tangled", () => {
		expect(profileLinkTarget("at://did:plc:abc")).toEqual({
			href: "/did:plc:abc",
			label: "did:plc:abc",
			external: false
		});
		expect(profileLinkTarget("did:plc:abc")?.href).toBe("/did:plc:abc");
	});

	it("opens record links in an atproto browser", () => {
		expect(profileLinkTarget("at://did:plc:abc/app.bsky.feed.post/3kabc")).toEqual({
			href: "https://pdsls.dev/at://did:plc:abc/app.bsky.feed.post/3kabc",
			label: "did:plc:abc/app.bsky.feed.post/3kabc",
			external: true
		});
	});

	it("refuses schemes that cannot be followed safely", () => {
		expect(profileLinkTarget("javascript:alert(1)")).toBeNull();
		expect(profileLinkTarget("ftp://files.example.com")).toBeNull();
		expect(profileLinkTarget("settings")).toBeNull();
	});
});