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