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

threadActionMenu.logic.test.ts

66 lines2.6 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import { buildThreadActionMenuItems, type ThreadActionMenuState } from "./threadActionMenu.logic";
4​
5const baseState: ThreadActionMenuState = {
6 branch: null,
7 isPinned: false,
8 isSettled: false,
9 isSnoozed: false,
10 canSnoozeNow: true,
11 isRegeneratingTitle: false,
12 supports: { settlement: true, snooze: true, pinning: true, titleRegeneration: true },
13 snoozePresets: [
14 { id: "hour", label: "In 1 hour", whenLabel: "3:00 PM", snoozedUntil: "2026-08-07T15:00:00Z" },
15 ],
16};
17​
18function ids(state: ThreadActionMenuState): string[] {
19 return buildThreadActionMenuItems(state).map((item) => item.id);
21​
22describe("buildThreadActionMenuItems", () => {
23 it("hides lifecycle items when the environment lacks the capabilities", () => {
24 expect(
25 ids({
26 ...baseState,
27 supports: { settlement: false, snooze: false, pinning: false, titleRegeneration: false },
28 }),
29 ).toEqual(["rename", "mark-unread", "copy-path", "copy-thread-id", "delete"]);
30 });
31​
32 it("includes branch items only for threads with a branch", () => {
33 const withBranch = ids({ ...baseState, branch: "feat/menu" });
34 expect(withBranch).toContain("new-thread-on-branch");
35 expect(withBranch).toContain("copy-branch");
36 expect(ids(baseState)).not.toContain("new-thread-on-branch");
37 expect(ids(baseState)).not.toContain("copy-branch");
38 });
39​
40 it("flips lifecycle labels with thread state", () => {
41 expect(ids({ ...baseState, isPinned: true, isSettled: true, isSnoozed: true })).toEqual(
42 expect.arrayContaining(["unpin", "unsettle", "unsnooze"]),
43 );
44 expect(ids(baseState)).toEqual(expect.arrayContaining(["pin", "settle", "snooze"]));
45 });
46​
47 it("disables snooze when the thread cannot snooze, keeping presets visible", () => {
48 const snooze = buildThreadActionMenuItems({ ...baseState, canSnoozeNow: false }).find(
49 (item) => item.id === "snooze",
50 );
51 expect(snooze?.disabled).toBe(true);
52 expect(snooze?.children?.map((child) => child.id)).toEqual(["snooze:hour"]);
53 });
54​
55 it("disables title regeneration while one is in flight", () => {
56 const item = buildThreadActionMenuItems({ ...baseState, isRegeneratingTitle: true }).find(
57 (candidate) => candidate.id === "regenerate-title",
58 );
59 expect(item).toMatchObject({ label: "Regenerating…", disabled: true });
60 });
61​
62 it("marks delete as destructive and keeps it last", () => {
63 const items = buildThreadActionMenuItems({ ...baseState, branch: "main" });
64 expect(items.at(-1)).toMatchObject({ id: "delete", destructive: true });
65 });
66});