Open History to see the last commit
1import { createElement } from "react";
2import { renderToStaticMarkup } from "react-dom/server";
3import { describe, expect, it, vi } from "vite-plus/test";
4
5vi.mock("~/hooks/useSettings", () => ({
6 useEnvironmentIdentificationMode: () => "none",
7}));
8vi.mock("../SidebarStageBackdrop", () => ({
9 StageBackdropButtonArt: () => null,
10 useSidebarStageBackdropVariant: () => null,
11}));
12
13import { ComposerPrimaryActions, formatPendingPrimaryActionLabel } from "./ComposerPrimaryActions";
14
15function renderPendingActions(isRunning: boolean) {
16 return renderToStaticMarkup(
17 createElement(ComposerPrimaryActions, {
18 compact: true,
19 pendingAction: {
20 questionIndex: 0,
21 isLastQuestion: true,
22 canAdvance: true,
23 isResponding: false,
24 isComplete: true,
25 },
26 isRunning,
27 showPlanFollowUpPrompt: false,
28 promptHasText: false,
29 isSendBusy: false,
30 sendDisabledReason: null,
31 isConnecting: false,
32 isEnvironmentUnavailable: false,
33 isPreparingWorktree: false,
34 hasSendableContent: false,
35 onPreviousPendingQuestion: () => {},
36 onInterrupt: () => {},
37 onImplementPlanInNewThread: () => {},
38 }),
39 );
40}
41
42function renderStandaloneStop() {
43 return renderToStaticMarkup(
44 createElement(ComposerPrimaryActions, {
45 compact: true,
46 pendingAction: null,
47 isRunning: true,
48 showPlanFollowUpPrompt: false,
49 promptHasText: false,
50 isSendBusy: false,
51 sendDisabledReason: null,
52 isConnecting: false,
53 isEnvironmentUnavailable: false,
54 isPreparingWorktree: false,
55 hasSendableContent: false,
56 onPreviousPendingQuestion: () => {},
57 onInterrupt: () => {},
58 onImplementPlanInNewThread: () => {},
59 }),
60 );
61}
62
63describe("formatPendingPrimaryActionLabel", () => {
64 it("returns 'Submitting...' while responding", () => {
65 expect(
66 formatPendingPrimaryActionLabel({
67 compact: false,
68 isLastQuestion: false,
69 isResponding: true,
70 questionIndex: 0,
71 }),
72 ).toBe("Submitting...");
73 });
74
75 it("returns 'Submitting...' while responding regardless of other flags", () => {
76 expect(
77 formatPendingPrimaryActionLabel({
78 compact: true,
79 isLastQuestion: true,
80 isResponding: true,
81 questionIndex: 3,
82 }),
83 ).toBe("Submitting...");
84 });
85
86 it("returns 'Submit' in compact mode on the last question", () => {
87 expect(
88 formatPendingPrimaryActionLabel({
89 compact: true,
90 isLastQuestion: true,
91 isResponding: false,
92 questionIndex: 0,
93 }),
94 ).toBe("Submit");
95 });
96
97 it("returns 'Next' in compact mode when not the last question", () => {
98 expect(
99 formatPendingPrimaryActionLabel({
100 compact: true,
101 isLastQuestion: false,
102 isResponding: false,
103 questionIndex: 1,
104 }),
105 ).toBe("Next");
106 });
107
108 it("returns 'Next question' when not the last question", () => {
109 expect(
110 formatPendingPrimaryActionLabel({
111 compact: false,
112 isLastQuestion: false,
113 isResponding: false,
114 questionIndex: 0,
115 }),
116 ).toBe("Next question");
117 });
118
119 it("returns singular 'Submit answer' on the last question when it is the only question", () => {
120 expect(
121 formatPendingPrimaryActionLabel({
122 compact: false,
123 isLastQuestion: true,
124 isResponding: false,
125 questionIndex: 0,
126 }),
127 ).toBe("Submit answer");
128 });
129
130 it("returns plural 'Submit answers' on the last question when there are multiple questions", () => {
131 expect(
132 formatPendingPrimaryActionLabel({
133 compact: false,
134 isLastQuestion: true,
135 isResponding: false,
136 questionIndex: 1,
137 }),
138 ).toBe("Submit answers");
139 });
140
141 it("returns plural 'Submit answers' for higher question indices", () => {
142 expect(
143 formatPendingPrimaryActionLabel({
144 compact: false,
145 isLastQuestion: true,
146 isResponding: false,
147 questionIndex: 5,
148 }),
149 ).toBe("Submit answers");
150 });
151});
152
153describe("ComposerPrimaryActions", () => {
154 it("offers Stop generation while a running turn is waiting for user input", () => {
155 expect(renderPendingActions(true)).toContain('aria-label="Stop generation"');
156 });
157
158 it("does not offer Stop generation for a pending request without a running turn", () => {
159 expect(renderPendingActions(false)).not.toContain('aria-label="Stop generation"');
160 });
161
162 it("matches the small pending action size without changing the standalone size", () => {
163 expect(renderPendingActions(true)).toContain("size-8 sm:size-7");
164 expect(renderStandaloneStop()).toContain("size-8 sm:h-8 sm:w-8");
165 expect(renderStandaloneStop()).not.toContain("sm:size-7");
166 });
167});