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

ComposerPrimaryActions.test.ts

138 lines3.7 KB

1import { describe, expect, it } from "vite-plus/test";
2import { renderToStaticMarkup } from "react-dom/server";
3import { createElement } from "react";
4​
5import { ComposerPrimaryActions, formatPendingPrimaryActionLabel } from "./ComposerPrimaryActions";
6​
7const activeTurnProps = {
8 compact: false,
9 pendingAction: null,
10 showPlanFollowUpPrompt: false,
11 promptHasText: false,
12 isSendBusy: false,
13 isConnecting: false,
14 isEnvironmentUnavailable: false,
15 isPreparingWorktree: false,
16 preserveComposerFocusOnPointerDown: false,
17 onPreviousPendingQuestion: () => {},
18 onInterrupt: () => {},
19 onImplementPlanInNewThread: () => {},
20} as const;
21​
22describe("formatPendingPrimaryActionLabel", () => {
23 it("returns 'Submitting...' while responding", () => {
24 expect(
25 formatPendingPrimaryActionLabel({
26 compact: false,
27 isLastQuestion: false,
28 isResponding: true,
29 questionIndex: 0,
30 }),
31 ).toBe("Submitting...");
32 });
33​
34 it("returns 'Submitting...' while responding regardless of other flags", () => {
35 expect(
36 formatPendingPrimaryActionLabel({
37 compact: true,
38 isLastQuestion: true,
39 isResponding: true,
40 questionIndex: 3,
41 }),
42 ).toBe("Submitting...");
43 });
44​
45 it("returns 'Submit' in compact mode on the last question", () => {
46 expect(
47 formatPendingPrimaryActionLabel({
48 compact: true,
49 isLastQuestion: true,
50 isResponding: false,
51 questionIndex: 0,
52 }),
53 ).toBe("Submit");
54 });
55​
56 it("returns 'Next' in compact mode when not the last question", () => {
57 expect(
58 formatPendingPrimaryActionLabel({
59 compact: true,
60 isLastQuestion: false,
61 isResponding: false,
62 questionIndex: 1,
63 }),
64 ).toBe("Next");
65 });
66​
67 it("returns 'Next question' when not the last question", () => {
68 expect(
69 formatPendingPrimaryActionLabel({
70 compact: false,
71 isLastQuestion: false,
72 isResponding: false,
73 questionIndex: 0,
74 }),
75 ).toBe("Next question");
76 });
77​
78 it("returns singular 'Submit answer' on the last question when it is the only question", () => {
79 expect(
80 formatPendingPrimaryActionLabel({
81 compact: false,
82 isLastQuestion: true,
83 isResponding: false,
84 questionIndex: 0,
85 }),
86 ).toBe("Submit answer");
87 });
88​
89 it("returns plural 'Submit answers' on the last question when there are multiple questions", () => {
90 expect(
91 formatPendingPrimaryActionLabel({
92 compact: false,
93 isLastQuestion: true,
94 isResponding: false,
95 questionIndex: 1,
96 }),
97 ).toBe("Submit answers");
98 });
99​
100 it("returns plural 'Submit answers' for higher question indices", () => {
101 expect(
102 formatPendingPrimaryActionLabel({
103 compact: false,
104 isLastQuestion: true,
105 isResponding: false,
106 questionIndex: 5,
107 }),
108 ).toBe("Submit answers");
109 });
110});
111​
112describe("active-turn primary action", () => {
113 it("shows stop while the active composer is empty", () => {
114 const markup = renderToStaticMarkup(
115 createElement(ComposerPrimaryActions, {
116 ...activeTurnProps,
117 isRunning: true,
118 hasSendableContent: false,
119 }),
120 );
121​
122 expect(markup).toContain('aria-label="Stop generation"');
123 expect(markup).not.toContain("steer active turn");
124 });
125​
126 it("replaces stop with send while the active composer has content", () => {
127 const markup = renderToStaticMarkup(
128 createElement(ComposerPrimaryActions, {
129 ...activeTurnProps,
130 isRunning: true,
131 hasSendableContent: true,
132 }),
133 );
134​
135 expect(markup).toContain('aria-label="Send message to steer active turn"');
136 expect(markup).not.toContain('aria-label="Stop generation"');
137 });
138});