Open History to see the last commit
1import { formatAssistantCitationHref } from "@t3tools/shared/assistantCitations";
2import { describe, expect, it } from "vite-plus/test";
3
4import {
5 REMOVE_QUEUED_MESSAGE_ACCESSIBILITY_LABEL,
6 buildCancelQueuedRunCommand,
7 resolveQueueDragBeforeRunId,
8 resolveThreadQueueRowControls,
9 resolveQueueDropBeforeRunId,
10} from "./threadQueueControlPresentation";
11import { threadDragGapOffset } from "./threadDragGap";
12
13describe("threadQueueControlPresentation", () => {
14 it("shows an assistant quote as its quoted text", () => {
15 const href = formatAssistantCitationHref({
16 version: 1,
17 environmentId: "environment:test" as never,
18 threadId: "thread:test" as never,
19 messageId: "message:assistant" as never,
20 text: "Retry the sync after the lock clears.",
21 start: 0,
22 end: 37,
23 prefix: "",
24 suffix: "",
25 });
26 const controls = resolveThreadQueueRowControls({
27 busy: false,
28 canPromoteToSteer: true,
29 canReorder: true,
30 index: 0,
31 queuedCount: 1,
32 text: `[Assistant quote](${href}) Can we add a backoff here?`,
33 });
34
35 expect(controls.displayText).toBe(
36 "Retry the sync after the lock clears. Can we add a backoff here?",
37 );
38 });
39
40 it("preserves queue reorder and steer controls with removal", () => {
41 const controls = resolveThreadQueueRowControls({
42 busy: false,
43 canPromoteToSteer: true,
44 canReorder: true,
45 index: 1,
46 queuedCount: 3,
47 text: "Please review the follow-up change.",
48 });
49
50 expect(controls.displayText).toBe("Please review the follow-up change.");
51 expect(controls.canMoveUp).toBe(true);
52 expect(controls.canMoveDown).toBe(true);
53 expect(controls.canSteer).toBe(true);
54 expect(controls.canDismiss).toBe(true);
55 expect(controls.dismissAccessibilityLabel).toBe(REMOVE_QUEUED_MESSAGE_ACCESSIBILITY_LABEL);
56 });
57
58 it("disables edge reorder controls and busy dismissal", () => {
59 const first = resolveThreadQueueRowControls({
60 busy: false,
61 canPromoteToSteer: false,
62 canReorder: true,
63 index: 0,
64 queuedCount: 2,
65 text: "First",
66 });
67 const busy = resolveThreadQueueRowControls({
68 busy: true,
69 canPromoteToSteer: true,
70 canReorder: true,
71 index: 0,
72 queuedCount: 1,
73 text: "Queued message",
74 });
75
76 expect(first.canMoveUp).toBe(false);
77 expect(first.canMoveDown).toBe(true);
78 expect(first.canSteer).toBe(false);
79 expect(busy.canDismiss).toBe(false);
80 expect(busy.canMoveUp).toBe(false);
81 expect(busy.canSteer).toBe(false);
82 });
83
84 it("keeps the row already open in the composer from being reopened or steered", () => {
85 const editing = resolveThreadQueueRowControls({
86 busy: false,
87 canPromoteToSteer: true,
88 canReorder: true,
89 index: 1,
90 isEditing: true,
91 queuedCount: 3,
92 text: "Being edited",
93 });
94
95 expect(editing.isEditing).toBe(true);
96 expect(editing.canEdit).toBe(false);
97 expect(editing.canSteer).toBe(false);
98 expect(editing.canMoveUp).toBe(true);
99 expect(editing.canDismiss).toBe(true);
100 });
101
102 it("builds cancelQueuedRun command arguments for removal", () => {
103 expect(
104 buildCancelQueuedRunCommand({
105 environmentId: "environment:test" as never,
106 runId: "run:queued" as never,
107 threadId: "thread:test" as never,
108 }),
109 ).toEqual({
110 environmentId: "environment:test",
111 input: {
112 runId: "run:queued",
113 threadId: "thread:test",
114 },
115 });
116 });
117});
118
119describe("queue drag insertion", () => {
120 const rows = [
121 { id: "first" as never, y: 0, height: 80 },
122 { id: "second" as never, y: 80, height: 140 },
123 { id: "third" as never, y: 220, height: 80 },
124 ];
125
126 it("moves between variable-height rows and to either end", () => {
127 expect(resolveQueueDropBeforeRunId(rows, rows[0]!.id, 140)).toBe("third");
128 expect(resolveQueueDropBeforeRunId(rows, rows[0]!.id, 300)).toBeNull();
129 expect(resolveQueueDropBeforeRunId(rows, rows[2]!.id, -300)).toBe("first");
130 });
131
132 it("opens the destination gap while the dragged row crosses other rows", () => {
133 const offsets = (runId: (typeof rows)[number]["id"], translation: number) => {
134 const before = resolveQueueDragBeforeRunId(rows, runId, translation);
135 if (before === undefined) return;
136 const source = rows.find((row) => row.id === runId)!;
137 const last = rows.at(-1)!;
138 const insertion =
139 before === null ? last.y + last.height : rows.find((row) => row.id === before)!.y;
140 return rows.map((row) => threadDragGapOffset(row.y, source.y, source.height, insertion));
141 };
142
143 expect(resolveQueueDragBeforeRunId(rows, rows[0]!.id, 0)).toBe(rows[1]!.id);
144 expect(offsets(rows[0]!.id, 140)).toEqual([0, -80, 0]);
145 expect(offsets(rows[0]!.id, 300)).toEqual([0, -80, -80]);
146 expect(offsets(rows[2]!.id, -300)).toEqual([80, 80, 0]);
147 expect(offsets(rows[1]!.id, 0)).toEqual([0, 0, 0]);
148 });
149
150 it("does not send a reorder for an unchanged or unmeasured drop", () => {
151 expect(resolveQueueDropBeforeRunId(rows, rows[1]!.id, 0)).toBeUndefined();
152 expect(resolveQueueDropBeforeRunId(rows, rows[2]!.id, 20)).toBeUndefined();
153 expect(resolveQueueDropBeforeRunId([{ id: rows[0]!.id }], rows[0]!.id, 10)).toBeUndefined();
154 expect(resolveQueueDropBeforeRunId(rows, "missing" as never, 100)).toBeUndefined();
155 });
156});