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 renderSendButton(sendDisabledReason: string | null = null) {
48 return renderToStaticMarkup(
49 createElement(ComposerPrimaryActions, {
50 compact: true,
51 pendingAction: null,
52 isRunning: false,
53 showPlanFollowUpPrompt: false,
54 promptHasText: true,
55 isSendBusy: false,
56 sendDisabledReason,
57 isConnecting: false,
58 isEnvironmentUnavailable: false,
59 isPreparingWorktree: false,
60 hasSendableContent: true,
61 onPreviousPendingQuestion: () => {},
62 onInterrupt: () => {},
63 onImplementPlanInNewThread: () => {},
64 }),
65 );
66}
67
68afterEach(() => {
69 stageArtworkState.mode = "none";
70 stageArtworkState.variant = null;
71});
72
73describe("ComposerPrimaryActions", () => {
74 it("disables and labels the send button while feedback is uploading", () => {
75 const markup = renderSendButton("Sending feedback");
76
77 expect(markup).toContain("disabled");
78 expect(markup).toContain('aria-label="Sending feedback"');
79 });
80
81 it("offers Stop generation while a running turn is waiting for user input", () => {
82 expect(renderPendingActions(true)).toContain('aria-label="Stop generation"');
83 });
84
85 it("does not offer Stop generation for a pending request without a running turn", () => {
86 expect(renderPendingActions(false)).not.toContain('aria-label="Stop generation"');
87 });
88
89 it("renders stage artwork inside the send button when artwork identification is active", () => {
90 stageArtworkState.mode = "artwork";
91 stageArtworkState.variant = "nightly";
92
93 const markup = renderSendButton();
94
95 expect(markup).toContain("stage-nightly");
96 });
97
98 it("hides stage artwork when artwork identification is inactive", () => {
99 stageArtworkState.variant = "nightly";
100
101 const markup = renderSendButton();
102
103 expect(markup).not.toContain("stage-nightly");
104 });
105});