Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ComposerPrimaryActions.test.tsx

141 lines4.4 KB

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 );
46​
47function renderRunningActions(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 onPreviousPendingQuestion: () => {},
62 onInterrupt: () => {},
63 onImplementPlanInNewThread: () => {},
64 }),
65 );
67​
68function renderSendButton(sendDisabledReason: string | null = null) {
69 return renderToStaticMarkup(
70 createElement(ComposerPrimaryActions, {
71 compact: true,
72 pendingAction: null,
73 isRunning: false,
74 showPlanFollowUpPrompt: false,
75 promptHasText: true,
76 isSendBusy: false,
77 sendDisabledReason,
78 isConnecting: false,
79 isEnvironmentUnavailable: false,
80 isPreparingWorktree: false,
81 hasSendableContent: true,
82 onPreviousPendingQuestion: () => {},
83 onInterrupt: () => {},
84 onImplementPlanInNewThread: () => {},
85 }),
86 );
88​
89afterEach(() => {
90 stageArtworkState.mode = "none";
91 stageArtworkState.variant = null;
92});
93​
94describe("ComposerPrimaryActions", () => {
95 it("disables and labels the send button while feedback is uploading", () => {
96 const markup = renderSendButton("Sending feedback");
97​
98 expect(markup).toContain("disabled");
99 expect(markup).toContain('aria-label="Sending feedback"');
100 });
101​
102 it("offers Stop generation while a running turn is waiting for user input", () => {
103 expect(renderPendingActions(true)).toContain('aria-label="Stop generation"');
104 });
105​
106 it("does not offer Stop generation for a pending request without a running turn", () => {
107 expect(renderPendingActions(false)).not.toContain('aria-label="Stop generation"');
108 });
109​
110 it("renders stage artwork inside the send button when artwork identification is active", () => {
111 stageArtworkState.mode = "artwork";
112 stageArtworkState.variant = "nightly";
113​
114 const markup = renderSendButton();
115​
116 expect(markup).toContain("stage-nightly");
117 });
118​
119 it("hides stage artwork when artwork identification is inactive", () => {
120 stageArtworkState.variant = "nightly";
121​
122 const markup = renderSendButton();
123​
124 expect(markup).not.toContain("stage-nightly");
125 });
126​
127 it("renders a queue action alongside stop while running with a sendable draft", () => {
128 const markup = renderRunningActions(true);
129​
130 expect(markup).toContain('aria-label="Stop generation"');
131 expect(markup).toContain('aria-label="Queue message"');
132 expect(markup).toContain('type="submit"');
133 });
134​
135 it("keeps stop as the only action while running with an empty composer", () => {
136 const markup = renderRunningActions(false);
137​
138 expect(markup).toContain('aria-label="Stop generation"');
139 expect(markup).not.toContain('aria-label="Queue message"');
140 });
141});