This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

core / web / src / lib / components / repo / CommitHeader.stories.svelte
3.8 kB 116 lines
1<script module lang="ts"> 2 import { defineMeta, type StoryContext } from "@storybook/addon-svelte-csf"; 3 import { expect } from "storybook/test"; 4 import type { CommitDetail } from "$lib/api/repo"; 5 import CommitHeader from "./CommitHeader.svelte"; 6 7 const fullCommit: CommitDetail = { 8 hash: "0123456789abcdef0123456789abcdef01234567", 9 shortHash: "01234567", 10 subject: "add a storybook fixture", 11 body: "the appview shows the body directly, no expander.\n\nit keeps line breaks too.", 12 authorName: "dawn", 13 authorEmail: "dawn@example.test", 14 authorWhen: "2026-07-28T09:00:00Z", 15 committerName: "cheri", 16 committerEmail: "cheri@example.test", 17 committerWhen: "2026-07-28T10:00:00Z", 18 // the api layer already dedupes repeated trailers 19 coAuthors: [{ name: "riley", email: "riley@example.test" }] 20 }; 21 22 const minimalCommit: CommitDetail = { 23 hash: "abcdef0123456789abcdef0123456789abcdef01", 24 shortHash: "abcdef01", 25 subject: "document the repository view", 26 body: "", 27 authorName: "dawn", 28 authorEmail: "dawn@example.test", 29 authorWhen: "2026-07-27T09:00:00Z", 30 committerName: "dawn", 31 committerEmail: "dawn@example.test", 32 committerWhen: "2026-07-27T09:00:00Z", 33 coAuthors: [] 34 }; 35 36 const noEmails: CommitDetail = { 37 ...minimalCommit, 38 subject: "signed off without an address", 39 authorEmail: "", 40 committerEmail: "" 41 }; 42 43 type PlayContext = Pick< 44 StoryContext<Record<string, unknown>>, 45 "canvas" | "canvasElement" | "userEvent" 46 >; 47 48 const fullMetadata = async ({ canvas, canvasElement }: PlayContext) => { 49 await expect(canvas.queryByRole("button")).toBeNull(); 50 await expect(canvas.getByText(/the appview shows the body directly/)).toBeVisible(); 51 await expect(canvas.getByText(/it keeps line breaks too/)).toBeVisible(); 52 53 const author = canvas.getByRole("link", { name: "dawn" }); 54 await expect(author).toHaveAttribute("href", "mailto:dawn@example.test"); 55 await expect(canvasElement.querySelector("svg")).not.toBeNull(); 56 57 await expect(canvas.getAllByText("co-author")).toHaveLength(1); 58 await expect(canvas.getByRole("link", { name: "riley" })).toHaveAttribute( 59 "href", 60 "mailto:riley@example.test" 61 ); 62 await expect(canvas.getByText("committer")).toBeVisible(); 63 await expect(canvas.getByText("cheri")).toBeVisible(); 64 65 await expect(canvas.getByText(/\(.*2026.*\)/)).toBeInTheDocument(); 66 67 await expect(canvas.getByText("change-id")).toBeVisible(); 68 69 // anchored so the commit's own hash doesn't match too 70 const parent = canvas.getByRole("link", { name: /^abcdef01/ }); 71 await expect(parent).toHaveAttribute( 72 "href", 73 "/dawn/tangled/commit/abcdef0123456789abcdef0123456789abcdef01" 74 ); 75 }; 76 77 const hidesAbsentRows = async ({ canvas }: PlayContext) => { 78 await expect(canvas.getByText("author")).toBeVisible(); 79 await expect(canvas.queryByText("committer")).toBeNull(); 80 await expect(canvas.queryByText("parent")).toBeNull(); 81 await expect(canvas.queryByText("change-id")).toBeNull(); 82 await expect(canvas.queryByRole("button")).toBeNull(); 83 }; 84 85 const namesStayWithoutMailto = async ({ canvas }: PlayContext) => { 86 await expect(canvas.getByText("dawn")).toBeVisible(); 87 await expect(canvas.queryByRole("link", { name: "dawn" })).toBeNull(); 88 }; 89 90 const { Story } = defineMeta({ 91 title: "Repo/CommitHeader", 92 component: CommitHeader, 93 tags: ["autodocs"], 94 args: { 95 ownerHandle: "dawn", 96 repoName: "tangled", 97 commit: fullCommit, 98 parent: "abcdef0123456789abcdef0123456789abcdef01", 99 changeId: "kqpuwoxzrnvs" 100 } 101 }); 102</script> 103 104<Story name="Full metadata" play={fullMetadata} /> 105 106<Story 107 name="Minimal commit" 108 args={{ commit: minimalCommit, parent: "", changeId: "" }} 109 play={hidesAbsentRows} 110/> 111 112<Story 113 name="No emails" 114 args={{ commit: noEmails, parent: "", changeId: "" }} 115 play={namesStayWithoutMailto} 116/>