1import { describe, expect, it } from "vite-plus/test";
2
3import { resolveComposerSendPresentation } from "./composerSendPresentation";
4
5const idle = {
6 editingQueuedMessage: false,
7 running: false,
8 canSteer: false,
9 followUpBehavior: "queue",
10 deliveryDeferred: false,
11} as const;
12
13describe("resolveComposerSendPresentation", () => {
14 it("sends plainly while the thread is idle", () => {
15 const presentation = resolveComposerSendPresentation(idle);
16
17 expect(presentation.label).toBe("Send");
18 expect(presentation.icon).toBe("arrow.up");
19 expect(presentation.offersFollowUpChoice).toBe(false);
20 expect(presentation.action).toBeNull();
21 });
22
23 it("says Queue while the outbox is holding the message back", () => {
24 expect(resolveComposerSendPresentation({ ...idle, deliveryDeferred: true }).label).toBe(
25 "Queue",
26 );
27 });
28
29 it("follows the configured behavior once a turn is running", () => {
30 const queueing = resolveComposerSendPresentation({
31 ...idle,
32 running: true,
33 canSteer: true,
34 followUpBehavior: "queue",
35 });
36 const steering = resolveComposerSendPresentation({
37 ...idle,
38 running: true,
39 canSteer: true,
40 followUpBehavior: "steer",
41 });
42
43 expect(queueing.label).toBe("Queue");
44 expect(queueing.icon).toBe("list.number");
45 expect(queueing.action).toBe("queue");
46 expect(queueing.alternate).toBe("steer");
47 expect(steering.label).toBe("Steer");
48 expect(steering.icon).toBe("arrow.turn.left.up");
49 expect(steering.action).toBe("steer");
50 expect(steering.alternate).toBe("queue");
51 expect(steering.offersFollowUpChoice).toBe(true);
52 });
53
54 it("never promises steering the provider cannot do", () => {
55 const presentation = resolveComposerSendPresentation({
56 ...idle,
57 running: true,
58 canSteer: false,
59 followUpBehavior: "steer",
60 });
61
62 expect(presentation.label).toBe("Queue");
63 expect(presentation.action).toBe("queue");
64 expect(presentation.alternate).toBeNull();
65 expect(presentation.offersFollowUpChoice).toBe(false);
66 });
67
68 it("keeps the save affordance while a queued message is being edited", () => {
69 const presentation = resolveComposerSendPresentation({
70 ...idle,
71 editingQueuedMessage: true,
72 running: true,
73 canSteer: true,
74 followUpBehavior: "steer",
75 });
76
77 expect(presentation.label).toBe("Update queued message");
78 expect(presentation.icon).toBe("checkmark");
79 expect(presentation.offersFollowUpChoice).toBe(false);
80 });
81});