learn and share notes on atproto (wip) 馃
malfestio.stormlightlabs.org/
readability
solid
axum
atproto
srs
1import type { Note } from "$lib/model";
2import { cleanup, render, screen } from "@solidjs/testing-library";
3import { JSX } from "solid-js";
4import { afterEach, describe, expect, it, vi } from "vitest";
5import { BacklinksPanel } from "../BacklinksPanel";
6
7vi.mock(
8 "@solidjs/router",
9 () => ({ A: (props: { href: string; children: JSX.Element }) => <a href={props.href}>{props.children}</a> }),
10);
11
12describe("BacklinksPanel", () => {
13 afterEach(() => {
14 cleanup();
15 vi.clearAllMocks();
16 });
17
18 const mockBacklinks: Note[] = [{
19 id: "note-1",
20 owner_did: "did:plc:test",
21 title: "First Backlink",
22 body: "Content",
23 tags: [],
24 visibility: { type: "Private" },
25 created_at: "2026-01-01T00:00:00Z",
26 updated_at: "2026-01-01T00:00:00Z",
27 }, {
28 id: "note-2",
29 owner_did: "did:plc:test",
30 title: "Second Backlink",
31 body: "Content",
32 tags: [],
33 visibility: { type: "Private" },
34 created_at: "2026-01-01T00:00:00Z",
35 updated_at: "2026-01-01T00:00:00Z",
36 }];
37
38 it("renders heading title", () => {
39 render(() => <BacklinksPanel backlinks={[]} />);
40 expect(screen.getByText("Backlinks")).toBeInTheDocument();
41 });
42
43 it("shows empty state when no backlinks", () => {
44 render(() => <BacklinksPanel backlinks={[]} />);
45 expect(screen.getByText("No incoming links")).toBeInTheDocument();
46 });
47
48 it("renders all backlinks", () => {
49 render(() => <BacklinksPanel backlinks={mockBacklinks} />);
50 expect(screen.getByText("First Backlink")).toBeInTheDocument();
51 expect(screen.getByText("Second Backlink")).toBeInTheDocument();
52 });
53
54 it("displays backlink count", () => {
55 render(() => <BacklinksPanel backlinks={mockBacklinks} />);
56 expect(screen.getByText("(2)")).toBeInTheDocument();
57 });
58
59 it("renders backlinks as navigation links", () => {
60 render(() => <BacklinksPanel backlinks={mockBacklinks} />);
61 const firstLink = screen.getByRole("link", { name: /First Backlink/ });
62 expect(firstLink).toHaveAttribute("href", "/notes/note-1");
63 });
64});