Open History to see the last commit
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 isRunning: false,
13 supports: { settlement: true, snooze: true, pinning: true, titleRegeneration: true },
14 snoozePresets: [
15 { id: "hour", label: "In 1 hour", whenLabel: "3:00 PM", snoozedUntil: "2026-08-07T15:00:00Z" },
16 ],
17};
18
19function ids(state: ThreadActionMenuState): string[] {
20 return buildThreadActionMenuItems(state).map((item) => item.id);
21}
22
23describe("buildThreadActionMenuItems", () => {
24 it("hides lifecycle items when the environment lacks the capabilities", () => {
25 expect(
26 ids({
27 ...baseState,
28 supports: { settlement: false, snooze: false, pinning: false, titleRegeneration: false },
29 }),
30 ).toEqual(["rename", "mark-unread", "copy-path", "copy-thread-id", "archive", "delete"]);
31 });
32
33 it("includes branch items only for threads with a branch", () => {
34 const withBranch = ids({ ...baseState, branch: "feat/menu" });
35 expect(withBranch).toContain("new-thread-on-branch");
36 expect(withBranch).toContain("copy-branch");
37 expect(ids(baseState)).not.toContain("new-thread-on-branch");
38 expect(ids(baseState)).not.toContain("copy-branch");
39 });
40
41 it("flips lifecycle labels with thread state", () => {
42 expect(ids({ ...baseState, isPinned: true, isSettled: true, isSnoozed: true })).toEqual(
43 expect.arrayContaining(["unpin", "unsettle", "unsnooze"]),
44 );
45 expect(ids(baseState)).toEqual(expect.arrayContaining(["pin", "settle", "snooze"]));
46 });
47
48 it("disables snooze when the thread cannot snooze, keeping presets visible", () => {
49 const snooze = buildThreadActionMenuItems({ ...baseState, canSnoozeNow: false }).find(
50 (item) => item.id === "snooze",
51 );
52 expect(snooze?.disabled).toBe(true);
53 expect(snooze?.children?.map((child) => child.id)).toEqual(["snooze:hour"]);
54 });
55
56 it("disables title regeneration while one is in flight", () => {
57 const item = buildThreadActionMenuItems({ ...baseState, isRegeneratingTitle: true }).find(
58 (candidate) => candidate.id === "regenerate-title",
59 );
60 expect(item).toMatchObject({ label: "Regenerating…", disabled: true });
61 });
62
63 it("marks delete as destructive and keeps it last", () => {
64 const items = buildThreadActionMenuItems({ ...baseState, branch: "main" });
65 expect(items.at(-1)).toMatchObject({ id: "delete", destructive: true });
66 });
67
68 it("offers archive as a non-destructive action right before delete", () => {
69 const items = buildThreadActionMenuItems(baseState);
70 const archiveItem = items.at(-2);
71 expect(archiveItem?.id).toBe("archive");
72 expect(archiveItem?.destructive).toBeFalsy();
73 expect(items.at(-1)?.id).toBe("delete");
74 });
75
76 it("keeps archive available even when the environment lacks every other capability", () => {
77 expect(
78 ids({
79 ...baseState,
80 supports: { settlement: false, snooze: false, pinning: false, titleRegeneration: false },
81 }),
82 ).toContain("archive");
83 });
84
85 it("disables archive while the thread is running", () => {
86 const archiveItem = buildThreadActionMenuItems({ ...baseState, isRunning: true }).find(
87 (item) => item.id === "archive",
88 );
89 expect(archiveItem?.disabled).toBe(true);
90 });
91});