Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import {
4 REMOVE_QUEUED_MESSAGE_ACCESSIBILITY_LABEL,
5 buildCancelQueuedRunCommand,
6 resolveThreadQueueRowControls,
7 resolveQueueDropBeforeRunId,
8} from "./threadQueueControlPresentation";
9
10describe("threadQueueControlPresentation", () => {
11 it("preserves queue reorder and steer controls with removal", () => {
12 const controls = resolveThreadQueueRowControls({
13 busy: false,
14 canPromoteToSteer: true,
15 canReorder: true,
16 index: 1,
17 queuedCount: 3,
18 text: "Please review the follow-up change.",
19 });
20
21 expect(controls.displayText).toBe("Please review the follow-up change.");
22 expect(controls.canMoveUp).toBe(true);
23 expect(controls.canMoveDown).toBe(true);
24 expect(controls.canSteer).toBe(true);
25 expect(controls.canDismiss).toBe(true);
26 expect(controls.dismissAccessibilityLabel).toBe(REMOVE_QUEUED_MESSAGE_ACCESSIBILITY_LABEL);
27 });
28
29 it("disables edge reorder controls and busy dismissal", () => {
30 const first = resolveThreadQueueRowControls({
31 busy: false,
32 canPromoteToSteer: false,
33 canReorder: true,
34 index: 0,
35 queuedCount: 2,
36 text: "First",
37 });
38 const busy = resolveThreadQueueRowControls({
39 busy: true,
40 canPromoteToSteer: true,
41 canReorder: true,
42 index: 0,
43 queuedCount: 1,
44 text: "Queued message",
45 });
46
47 expect(first.canMoveUp).toBe(false);
48 expect(first.canMoveDown).toBe(true);
49 expect(first.canSteer).toBe(false);
50 expect(busy.canDismiss).toBe(false);
51 expect(busy.canMoveUp).toBe(false);
52 expect(busy.canSteer).toBe(false);
53 });
54
55 it("builds cancelQueuedRun command arguments for removal", () => {
56 expect(
57 buildCancelQueuedRunCommand({
58 environmentId: "environment:test" as never,
59 runId: "run:queued" as never,
60 threadId: "thread:test" as never,
61 }),
62 ).toEqual({
63 environmentId: "environment:test",
64 input: {
65 runId: "run:queued",
66 threadId: "thread:test",
67 },
68 });
69 });
70});
71
72describe("queue drag insertion", () => {
73 const rows = [
74 { id: "first" as never, y: 0, height: 80 },
75 { id: "second" as never, y: 80, height: 140 },
76 { id: "third" as never, y: 220, height: 80 },
77 ];
78
79 it("moves between variable-height rows and to either end", () => {
80 expect(resolveQueueDropBeforeRunId(rows, rows[0]!.id, 140)).toBe("third");
81 expect(resolveQueueDropBeforeRunId(rows, rows[0]!.id, 300)).toBeNull();
82 expect(resolveQueueDropBeforeRunId(rows, rows[2]!.id, -300)).toBe("first");
83 });
84
85 it("does not send a reorder for an unchanged or unmeasured drop", () => {
86 expect(resolveQueueDropBeforeRunId(rows, rows[1]!.id, 0)).toBeUndefined();
87 expect(resolveQueueDropBeforeRunId(rows, rows[2]!.id, 20)).toBeUndefined();
88 expect(resolveQueueDropBeforeRunId([{ id: rows[0]!.id }], rows[0]!.id, 10)).toBeUndefined();
89 expect(resolveQueueDropBeforeRunId(rows, "missing" as never, 100)).toBeUndefined();
90 });
91});