This repository has no description
1<script module lang="ts">
2 import { defineMeta, type StoryContext } from "@storybook/addon-svelte-csf";
3 import { expect, fn, userEvent } from "storybook/test";
4 import CommitLogView from "./CommitLogView.svelte";
5 import type { CommitSummary } from "./types";
6
7 const commit = (index: number): CommitSummary => ({
8 hash: `${String(index).padStart(8, "0")}56789abcdef0123456789abcdef01234567`.slice(0, 40),
9 shortHash: String(index).padStart(8, "0"),
10 subject: `commit number ${index}`,
11 body: index === 1 ? "a longer explanation hidden behind the disclosure." : "",
12 authorName: "dawn",
13 authorEmail: "dawn@tangled.org",
14 when: "2026-07-28T09:00:00Z"
15 });
16 const commits = Array.from({ length: 12 }, (_, index) => commit(index + 1));
17 const onPageChange = fn();
18 type PlayContext = Pick<StoryContext<Record<string, unknown>>, "canvas">;
19
20 const firstPage = async ({ canvas }: PlayContext) => {
21 await expect(canvas.getByRole("button", { name: "Previous page" })).toBeDisabled();
22 const next = canvas.getByRole("button", { name: "Next page" });
23 await expect(next).toBeEnabled();
24 await expect(canvas.getByRole("button", { name: "Page 1" })).toHaveAttribute(
25 "aria-current",
26 "page"
27 );
28 await userEvent.click(next);
29 await expect(onPageChange).toHaveBeenCalledWith(2);
30
31 await expect(canvas.getAllByTitle("Copy SHA")).toHaveLength(commits.length);
32 await expect(canvas.getAllByTitle("Browse repository at this commit")).toHaveLength(
33 commits.length * 2
34 );
35
36 const chip = canvas.getAllByRole("link", { name: commits[0].shortHash })[0];
37 await expect(chip).toHaveAttribute("href", `/dawn/tangled/commit/${commits[0].hash}`);
38 const tree = canvas.getAllByTitle("Browse repository at this commit")[0];
39 await expect(tree).toHaveAttribute("href", `/dawn/tangled/tree/${commits[0].hash}`);
40 };
41
42 const middlePage = async ({ canvas }: PlayContext) => {
43 await expect(canvas.getByRole("button", { name: "Previous page" })).toBeEnabled();
44 await expect(canvas.getByRole("button", { name: "Next page" })).toBeEnabled();
45 await expect(canvas.getByRole("button", { name: "Page 4" })).toHaveAttribute(
46 "aria-current",
47 "page"
48 );
49 };
50
51 const bodyExpand = async ({ canvas }: PlayContext) => {
52 // desktop and mobile rows each render a toggle
53 const toggle = canvas.getAllByRole("button", { name: "Toggle commit body" })[0];
54 await expect(canvas.queryByText(/a longer explanation/)).toBeNull();
55 await userEvent.click(toggle);
56 await expect(toggle).toHaveAttribute("aria-expanded", "true");
57 await expect(canvas.getAllByText(/a longer explanation/).length).toBeGreaterThan(0);
58 };
59
60 const emptyLog = async ({ canvas }: PlayContext) => {
61 await expect(canvas.getByText("No commits at main.")).toBeVisible();
62 await expect(canvas.queryByRole("navigation", { name: "Pagination" })).toBeNull();
63 };
64
65 const { Story } = defineMeta({
66 title: "Repo/CommitLogView",
67 component: CommitLogView,
68 tags: ["autodocs"],
69 args: {
70 ownerHandle: "dawn",
71 repoName: "tangled",
72 ref: "main",
73 commits,
74 tagsByCommit: {
75 [commits[0].hash]: ["v1.0.0"]
76 },
77 page: 1,
78 pageCount: 5,
79 onPageChange
80 }
81 });
82</script>
83
84<Story name="First page" play={firstPage} />
85<Story name="Middle page" args={{ page: 4 }} play={middlePage} />
86<Story name="Expandable body" play={bodyExpand} />
87<Story name="Empty log" args={{ commits: [], pageCount: 1 }} play={emptyLog} />