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

threadQueueControlPresentation.test.ts

98 lines3.2 KB

1import { formatAssistantCitationHref } from "@t3tools/shared/assistantCitations";
2import { describe, expect, it } from "vite-plus/test";
3​
4import {
5 resolveThreadQueueRowControls,
6 resolveQueueDropBeforeRunId,
7} from "./threadQueueControlPresentation";
8​
9describe("threadQueueControlPresentation", () => {
10 it.each([
11 { busy: false, isEditing: false, expected: true },
12 { busy: true, isEditing: false, expected: false },
13 { busy: false, isEditing: true, expected: false },
14 ])(
15 "gates sending a stopped thread's queued message with $busy busy and $isEditing editing",
16 ({ busy, isEditing, expected }) => {
17 const controls = resolveThreadQueueRowControls({
18 busy,
19 isEditing,
20 canPromoteToSteer: false,
21 canSendNow: true,
22 canReorder: false,
23 index: 0,
24 queuedCount: 1,
25 text: "Queued message",
26 });
27​
28 expect(controls.canSend).toBe(expected);
29 },
30 );
31​
32 it("shows an assistant quote as its quoted text", () => {
33 const href = formatAssistantCitationHref({
34 version: 1,
35 environmentId: "environment:test" as never,
36 threadId: "thread:test" as never,
37 messageId: "message:assistant" as never,
38 text: "Retry the sync after the lock clears.",
39 start: 0,
40 end: 37,
41 prefix: "",
42 suffix: "",
43 });
44 const controls = resolveThreadQueueRowControls({
45 busy: false,
46 canPromoteToSteer: true,
47 canSendNow: false,
48 canReorder: true,
49 index: 0,
50 queuedCount: 1,
51 text: `[Assistant quote](${href}) Can we add a backoff here?`,
52 });
53​
54 expect(controls.displayText).toBe(
55 "Retry the sync after the lock clears. Can we add a backoff here?",
56 );
57 });
58​
59 it("keeps the row already open in the composer from being reopened or steered", () => {
60 const editing = resolveThreadQueueRowControls({
61 busy: false,
62 canPromoteToSteer: true,
63 canSendNow: false,
64 canReorder: true,
65 index: 1,
66 isEditing: true,
67 queuedCount: 3,
68 text: "Being edited",
69 });
70​
71 expect(editing.isEditing).toBe(true);
72 expect(editing.canEdit).toBe(false);
73 expect(editing.canSend).toBe(false);
74 expect(editing.canMoveUp).toBe(true);
75 expect(editing.canDismiss).toBe(true);
76 });
77});
78​
79describe("queue drag insertion", () => {
80 const rows = [
81 { id: "first" as never, y: 0, height: 80 },
82 { id: "second" as never, y: 80, height: 140 },
83 { id: "third" as never, y: 220, height: 80 },
84 ];
85​
86 it("moves between variable-height rows and to either end", () => {
87 expect(resolveQueueDropBeforeRunId(rows, rows[0]!.id, 140)).toBe("third");
88 expect(resolveQueueDropBeforeRunId(rows, rows[0]!.id, 300)).toBeNull();
89 expect(resolveQueueDropBeforeRunId(rows, rows[2]!.id, -300)).toBe("first");
90 });
91​
92 it("does not send a reorder for an unchanged or unmeasured drop", () => {
93 expect(resolveQueueDropBeforeRunId(rows, rows[1]!.id, 0)).toBeUndefined();
94 expect(resolveQueueDropBeforeRunId(rows, rows[2]!.id, 20)).toBeUndefined();
95 expect(resolveQueueDropBeforeRunId([{ id: rows[0]!.id }], rows[0]!.id, 10)).toBeUndefined();
96 expect(resolveQueueDropBeforeRunId(rows, "missing" as never, 100)).toBeUndefined();
97 });
98});