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

threadActionMenu.logic.test.ts

82 lines3.3 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 sessionStatus: "ready",
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);
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(["reload-session", "rename", "mark-unread", "copy-path", "copy-thread-id", "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("offers session reload without interrupting an active turn", () => {
64 const ready = buildThreadActionMenuItems(baseState).find(
65 (candidate) => candidate.id === "reload-session",
66 );
67 expect(ready).toMatchObject({ label: "Reload agent session", disabled: false });
68​
69 const running = buildThreadActionMenuItems({ ...baseState, sessionStatus: "running" }).find(
70 (candidate) => candidate.id === "reload-session",
71 );
72 expect(running).toMatchObject({ label: "Reload agent session", disabled: true });
73​
74 expect(ids({ ...baseState, sessionStatus: "stopped" })).not.toContain("reload-session");
75 expect(ids({ ...baseState, sessionStatus: null })).not.toContain("reload-session");
76 });
77​
78 it("marks delete as destructive and keeps it last", () => {
79 const items = buildThreadActionMenuItems({ ...baseState, branch: "main" });
80 expect(items.at(-1)).toMatchObject({ id: "delete", destructive: true });
81 });
82});