Open History to see the last commit
1import { createElement } from "react";
2import { renderToStaticMarkup } from "react-dom/server";
3import { afterEach, describe, expect, it, vi } from "vite-plus/test";
4
5const stageArtworkState = vi.hoisted(() => ({
6 mode: "none" as "artwork" | "none",
7 variant: null as "nightly" | "dev" | null,
8}));
9
10vi.mock("~/hooks/useSettings", () => ({
11 useEnvironmentIdentificationMode: () => stageArtworkState.mode,
12}));
13vi.mock("../SidebarStageBackdrop", () => ({
14 StageBackdropButtonArt: ({ variant }: { variant: string }) => `stage-${variant}`,
15 useSidebarStageBackdropVariant: (enabled = true) => (enabled ? stageArtworkState.variant : null),
16}));
17
18import { ComposerPrimaryActions } from "./ComposerPrimaryActions";
19
20function renderPendingActions(isRunning: boolean) {
21 return renderToStaticMarkup(
22 createElement(ComposerPrimaryActions, {
23 compact: true,
24 pendingAction: {
25 questionIndex: 0,
26 isLastQuestion: true,
27 canAdvance: true,
28 isResponding: false,
29 isComplete: true,
30 },
31 isRunning,
32 showPlanFollowUpPrompt: false,
33 promptHasText: false,
34 isSendBusy: false,
35 sendDisabledReason: null,
36 isConnecting: false,
37 isEnvironmentUnavailable: false,
38 isPreparingWorktree: false,
39 hasSendableContent: false,
40 onPreviousPendingQuestion: () => {},
41 onInterrupt: () => {},
42 onImplementPlanInNewThread: () => {},
43 }),
44 );
45}
46
47function renderRunningActions(showSendWhileRunning: boolean, hasSendableContent: boolean) {
48 return renderToStaticMarkup(
49 createElement(ComposerPrimaryActions, {
50 compact: true,
51 pendingAction: null,
52 isRunning: true,
53 showPlanFollowUpPrompt: false,
54 promptHasText: hasSendableContent,
55 isSendBusy: false,
56 sendDisabledReason: null,
57 isConnecting: false,
58 isEnvironmentUnavailable: false,
59 isPreparingWorktree: false,
60 hasSendableContent,
61 showSendWhileRunning,
62 onPreviousPendingQuestion: () => {},
63 onInterrupt: () => {},
64 onImplementPlanInNewThread: () => {},
65 }),
66 );
67}
68
69function renderSendButton(sendDisabledReason: string | null = null) {
70 return renderToStaticMarkup(
71 createElement(ComposerPrimaryActions, {
72 compact: true,
73 pendingAction: null,
74 isRunning: false,
75 showPlanFollowUpPrompt: false,
76 promptHasText: true,
77 isSendBusy: false,
78 sendDisabledReason,
79 isConnecting: false,
80 isEnvironmentUnavailable: false,
81 isPreparingWorktree: false,
82 hasSendableContent: true,
83 onPreviousPendingQuestion: () => {},
84 onInterrupt: () => {},
85 onImplementPlanInNewThread: () => {},
86 }),
87 );
88}
89
90afterEach(() => {
91 stageArtworkState.mode = "none";
92 stageArtworkState.variant = null;
93});
94
95describe("ComposerPrimaryActions", () => {
96 it("disables and labels the send button while feedback is uploading", () => {
97 const markup = renderSendButton("Sending feedback");
98
99 expect(markup).toContain("disabled");
100 expect(markup).toContain('aria-label="Sending feedback"');
101 });
102
103 it("offers Stop generation while a running turn is waiting for user input", () => {
104 expect(renderPendingActions(true)).toContain('aria-label="Stop generation"');
105 });
106
107 it("does not offer Stop generation for a pending request without a running turn", () => {
108 expect(renderPendingActions(false)).not.toContain('aria-label="Stop generation"');
109 });
110
111 it("renders stage artwork inside the send button when artwork identification is active", () => {
112 stageArtworkState.mode = "artwork";
113 stageArtworkState.variant = "nightly";
114
115 const markup = renderSendButton();
116
117 expect(markup).toContain("stage-nightly");
118 });
119
120 it("hides stage artwork when artwork identification is inactive", () => {
121 stageArtworkState.variant = "nightly";
122
123 const markup = renderSendButton();
124
125 expect(markup).not.toContain("stage-nightly");
126 });
127
128 it("only renders stop while running when Enter-to-send is available", () => {
129 const markup = renderRunningActions(false, true);
130
131 expect(markup).toContain('aria-label="Stop generation"');
132 expect(markup).not.toContain('aria-label="Send message"');
133 });
134
135 it("renders send alongside stop while running when Enter-to-send is unavailable", () => {
136 const markup = renderRunningActions(true, true);
137
138 expect(markup).toContain('aria-label="Stop generation"');
139 expect(markup).toContain('aria-label="Send message"');
140 expect(markup).toContain('type="submit"');
141 });
142
143 it("keeps stop as the only action while running with an empty composer", () => {
144 const markup = renderRunningActions(true, false);
145
146 expect(markup).toContain('aria-label="Stop generation"');
147 expect(markup).not.toContain('aria-label="Send message"');
148 });
149});