Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

composerChipPresentation.test.ts

80 lines3.3 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3describe("composerChipSizeSuffix", () => {
4 it("labels attachment records with a human size, matching web's chip", async () => {
5 const { composerChipSizeSuffix } = await import("./composerChipPresentation");
6 expect(composerChipSizeSuffix({ kind: "file", sizeBytes: 1024 })).toBe("1 KB");
7 expect(composerChipSizeSuffix({ kind: "file", sizeBytes: 3_700_000 })).toBe("3.5 MB");
8 expect(composerChipSizeSuffix({ kind: "image", sizeBytes: 2048 })).toBe("2 KB");
9 });
10​
11 it("adds nothing for records that carry no bytes", async () => {
12 const { composerChipSizeSuffix } = await import("./composerChipPresentation");
13 expect(composerChipSizeSuffix({ kind: "terminal" })).toBe("");
14 expect(composerChipSizeSuffix({ kind: "file" })).toBe("");
15 expect(composerChipSizeSuffix(undefined)).toBe("");
16 });
17});
18​
19describe("contextChipPresentation image detection", () => {
20 it("treats a picture attached through the file picker as an image", async () => {
21 const { contextChipPresentation } = await import("./composerChipPresentation");
22 expect(
23 contextChipPresentation("file", { kind: "file", name: "IMG_4997.PNG", mimeType: "" }),
24 ).toEqual({ accent: "#d55665", symbol: "photo" });
25 expect(
26 contextChipPresentation("file", {
27 kind: "file",
28 name: "shot",
29 mimeType: "image/jpeg",
30 }),
31 ).toEqual({ accent: "#d55665", symbol: "photo" });
32 });
33​
34 it("leaves genuine documents and videos alone", async () => {
35 const { contextChipPresentation } = await import("./composerChipPresentation");
36 expect(
37 contextChipPresentation("file", { kind: "file", name: "notes.txt", mimeType: "text/plain" }),
38 ).toEqual({ accent: "#0090cd", symbol: "doc" });
39 expect(
40 contextChipPresentation("file", { kind: "file", name: "clip.mp4", mimeType: "video/mp4" }),
41 ).toEqual({ accent: "#d06217", symbol: "play.rectangle" });
42 });
43});
44​
45describe("pull request chip status", () => {
46 const chip = async (state: string, isDraft = false) => {
47 const { contextChipPresentation } = await import("./composerChipPresentation");
48 return contextChipPresentation("review-comment", {
49 kind: "review-comment",
50 sectionId: "pull-request:10978",
51 pullRequest: { state, isDraft },
52 });
53 };
54​
55 it("colours a pull request by its state, the way web and the forge do", async () => {
56 expect((await chip("open")).accent).toBe("#009f6e");
57 expect((await chip("open", true)).accent).toBe("#7f8793");
58 expect((await chip("merged")).accent).toBe("#8a70dd");
59 expect((await chip("closed")).accent).toBe("#d55665");
60 });
61​
62 it("keeps one glyph across every state, so only colour carries the status", async () => {
63 const symbols = await Promise.all(
64 [chip("open"), chip("open", true), chip("merged"), chip("closed")].map(
65 async (pending) => (await pending).symbol,
66 ),
67 );
68 expect(new Set(symbols)).toEqual(new Set(["git-pull-request"]));
69 });
70​
71 it("falls back to the generic pull request chip when the state is unknown", async () => {
72 const { contextChipPresentation } = await import("./composerChipPresentation");
73 expect(
74 contextChipPresentation("review-comment", {
75 kind: "review-comment",
76 sectionId: "pull-request:1",
77 }).accent,
78 ).toBe("#7079e4");
79 });
80});