@terreno/ui 57.9.0 → 57.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -0
- package/README.md +2 -0
- package/dist/Button.d.ts.map +1 -1
- package/dist/Button.js +20 -5
- package/dist/Button.js.map +1 -1
- package/dist/Common.d.ts +74 -1
- package/dist/Common.d.ts.map +1 -1
- package/dist/Common.js.map +1 -1
- package/dist/DataTable.js +1 -1
- package/dist/DataTable.js.map +1 -1
- package/dist/DateTimeActionSheet.js +1 -1
- package/dist/DateTimeActionSheet.js.map +1 -1
- package/dist/DateTimeField.d.ts.map +1 -1
- package/dist/DateTimeField.js +91 -18
- package/dist/DateTimeField.js.map +1 -1
- package/dist/FilePickerButton.d.ts +15 -1
- package/dist/FilePickerButton.d.ts.map +1 -1
- package/dist/FilePickerButton.js +26 -9
- package/dist/FilePickerButton.js.map +1 -1
- package/dist/GPTChat.d.ts +57 -1
- package/dist/GPTChat.d.ts.map +1 -1
- package/dist/GPTChat.js +199 -7
- package/dist/GPTChat.js.map +1 -1
- package/dist/HtmlFrame.d.ts +11 -0
- package/dist/HtmlFrame.d.ts.map +1 -0
- package/dist/HtmlFrame.js +29 -0
- package/dist/HtmlFrame.js.map +1 -0
- package/dist/SplitPage.d.ts +2 -2
- package/dist/SplitPage.d.ts.map +1 -1
- package/dist/SplitPage.js +17 -5
- package/dist/SplitPage.js.map +1 -1
- package/dist/Text.d.ts +1 -1
- package/dist/Text.d.ts.map +1 -1
- package/dist/Text.js +2 -2
- package/dist/Text.js.map +1 -1
- package/dist/asks/AskCard.d.ts +34 -0
- package/dist/asks/AskCard.d.ts.map +1 -0
- package/dist/asks/AskCard.js +91 -0
- package/dist/asks/AskCard.js.map +1 -0
- package/dist/asks/AskChoice.d.ts +11 -0
- package/dist/asks/AskChoice.d.ts.map +1 -0
- package/dist/asks/AskChoice.js +146 -0
- package/dist/asks/AskChoice.js.map +1 -0
- package/dist/asks/AskConfirm.d.ts +15 -0
- package/dist/asks/AskConfirm.d.ts.map +1 -0
- package/dist/asks/AskConfirm.js +17 -0
- package/dist/asks/AskConfirm.js.map +1 -0
- package/dist/asks/AskFiles.d.ts +18 -0
- package/dist/asks/AskFiles.d.ts.map +1 -0
- package/dist/asks/AskFiles.js +149 -0
- package/dist/asks/AskFiles.js.map +1 -0
- package/dist/asks/AskForm.d.ts +27 -0
- package/dist/asks/AskForm.d.ts.map +1 -0
- package/dist/asks/AskForm.js +146 -0
- package/dist/asks/AskForm.js.map +1 -0
- package/dist/asks/AskMarkdown.d.ts +25 -0
- package/dist/asks/AskMarkdown.d.ts.map +1 -0
- package/dist/asks/AskMarkdown.js +73 -0
- package/dist/asks/AskMarkdown.js.map +1 -0
- package/dist/asks/SimpleAskCard.d.ts +23 -0
- package/dist/asks/SimpleAskCard.d.ts.map +1 -0
- package/dist/asks/SimpleAskCard.js +32 -0
- package/dist/asks/SimpleAskCard.js.map +1 -0
- package/dist/asks/askControls.d.ts +33 -0
- package/dist/asks/askControls.d.ts.map +1 -0
- package/dist/asks/askControls.js +30 -0
- package/dist/asks/askControls.js.map +1 -0
- package/dist/asks/askFileRefs.d.ts +26 -0
- package/dist/asks/askFileRefs.d.ts.map +1 -0
- package/dist/asks/askFileRefs.js +75 -0
- package/dist/asks/askFileRefs.js.map +1 -0
- package/dist/asks/askFormDraft.d.ts +60 -0
- package/dist/asks/askFormDraft.d.ts.map +1 -0
- package/dist/asks/askFormDraft.js +224 -0
- package/dist/asks/askFormDraft.js.map +1 -0
- package/dist/asks/askSummary.d.ts +10 -0
- package/dist/asks/askSummary.d.ts.map +1 -0
- package/dist/asks/askSummary.js +138 -0
- package/dist/asks/askSummary.js.map +1 -0
- package/dist/asks/askTypes.d.ts +21 -0
- package/dist/asks/askTypes.d.ts.map +1 -0
- package/dist/asks/askTypes.js +2 -0
- package/dist/asks/askTypes.js.map +1 -0
- package/dist/asks/simpleCardButtonVariants.d.ts +5 -0
- package/dist/asks/simpleCardButtonVariants.d.ts.map +1 -0
- package/dist/asks/simpleCardButtonVariants.js +8 -0
- package/dist/asks/simpleCardButtonVariants.js.map +1 -0
- package/dist/blocks/BlocksError.d.ts +8 -0
- package/dist/blocks/BlocksError.d.ts.map +1 -0
- package/dist/blocks/BlocksError.js +14 -0
- package/dist/blocks/BlocksError.js.map +1 -0
- package/dist/blocks/BlocksView.d.ts +10 -0
- package/dist/blocks/BlocksView.d.ts.map +1 -0
- package/dist/blocks/BlocksView.js +90 -0
- package/dist/blocks/BlocksView.js.map +1 -0
- package/dist/blocks/blockRenderers.d.ts +25 -0
- package/dist/blocks/blockRenderers.d.ts.map +1 -0
- package/dist/blocks/blockRenderers.js +136 -0
- package/dist/blocks/blockRenderers.js.map +1 -0
- package/dist/blocks/datasetToPoints.d.ts +22 -0
- package/dist/blocks/datasetToPoints.d.ts.map +1 -0
- package/dist/blocks/datasetToPoints.js +28 -0
- package/dist/blocks/datasetToPoints.js.map +1 -0
- package/dist/blocks/useBlockSelections.d.ts +6 -0
- package/dist/blocks/useBlockSelections.d.ts.map +1 -0
- package/dist/blocks/useBlockSelections.js +10 -0
- package/dist/blocks/useBlockSelections.js.map +1 -0
- package/dist/blocks/useResolvedDatasets.d.ts +18 -0
- package/dist/blocks/useResolvedDatasets.d.ts.map +1 -0
- package/dist/blocks/useResolvedDatasets.js +59 -0
- package/dist/blocks/useResolvedDatasets.js.map +1 -0
- package/dist/blocks/useResolvedImages.d.ts +15 -0
- package/dist/blocks/useResolvedImages.d.ts.map +1 -0
- package/dist/blocks/useResolvedImages.js +66 -0
- package/dist/blocks/useResolvedImages.js.map +1 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts +6 -0
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts.map +1 -1
- package/dist/lazyBoundaries/heavyOptionalExports.js +4 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
- package/dist/table/TableHeaderCell.js +1 -1
- package/dist/table/TableHeaderCell.js.map +1 -1
- package/package.json +2 -1
- package/src/Button.test.tsx +101 -0
- package/src/Button.tsx +35 -5
- package/src/Common.ts +73 -0
- package/src/DataTable.tsx +1 -1
- package/src/DateTimeActionSheet.tsx +1 -1
- package/src/DateTimeField.test.tsx +185 -2
- package/src/DateTimeField.tsx +107 -17
- package/src/DonutChart.test.tsx +5 -10
- package/src/FilePickerButton.test.tsx +56 -3
- package/src/FilePickerButton.tsx +83 -17
- package/src/GPTChat.test.tsx +758 -2
- package/src/GPTChat.tsx +517 -7
- package/src/HtmlFrame.tsx +60 -0
- package/src/LineChart.test.tsx +5 -10
- package/src/SplitPage.test.tsx +55 -0
- package/src/SplitPage.tsx +13 -7
- package/src/Text.test.tsx +22 -0
- package/src/Text.tsx +10 -1
- package/src/__snapshots__/Button.test.tsx.snap +1 -1
- package/src/__snapshots__/SplitPage.test.tsx.snap +14 -0
- package/src/asks/AskCard.test.tsx +1428 -0
- package/src/asks/AskCard.tsx +240 -0
- package/src/asks/AskChoice.tsx +368 -0
- package/src/asks/AskConfirm.tsx +42 -0
- package/src/asks/AskFiles.test.tsx +347 -0
- package/src/asks/AskFiles.tsx +246 -0
- package/src/asks/AskForm.tsx +334 -0
- package/src/asks/AskMarkdown.tsx +176 -0
- package/src/asks/SimpleAskCard.test.tsx +253 -0
- package/src/asks/SimpleAskCard.tsx +82 -0
- package/src/asks/askControls.tsx +98 -0
- package/src/asks/askFileRefs.test.ts +155 -0
- package/src/asks/askFileRefs.ts +98 -0
- package/src/asks/askFormDraft.test.ts +347 -0
- package/src/asks/askFormDraft.ts +309 -0
- package/src/asks/askSummary.test.ts +255 -0
- package/src/asks/askSummary.ts +160 -0
- package/src/asks/askTypes.ts +25 -0
- package/src/asks/asksUseTerrenoComponents.test.ts +55 -0
- package/src/asks/simpleCardButtonVariants.ts +14 -0
- package/src/blocks/BlocksError.tsx +28 -0
- package/src/blocks/BlocksView.test.tsx +607 -0
- package/src/blocks/BlocksView.tsx +125 -0
- package/src/blocks/blockRenderers.tsx +288 -0
- package/src/blocks/datasetToPoints.test.ts +31 -0
- package/src/blocks/datasetToPoints.ts +48 -0
- package/src/blocks/useBlockSelections.ts +13 -0
- package/src/blocks/useResolvedDatasets.ts +78 -0
- package/src/blocks/useResolvedImages.ts +81 -0
- package/src/bunSetup.ts +0 -6
- package/src/index.tsx +7 -0
- package/src/isolated/HtmlFrame.isolated.tsx +54 -0
- package/src/lazyBoundaries/heavyOptionalExports.test.tsx +2 -0
- package/src/lazyBoundaries/heavyOptionalExports.tsx +14 -0
- package/src/table/TableHeaderCell.tsx +1 -1
|
@@ -0,0 +1,1428 @@
|
|
|
1
|
+
import {afterEach, describe, it, mock, spyOn} from "bun:test";
|
|
2
|
+
import {
|
|
3
|
+
type ChoiceAskInput,
|
|
4
|
+
type ConfirmAskInput,
|
|
5
|
+
type FormAskInput,
|
|
6
|
+
type MarkdownAskInput,
|
|
7
|
+
toSimpleCard,
|
|
8
|
+
} from "@terreno/blocks";
|
|
9
|
+
import {act, fireEvent, render, waitFor, within} from "@testing-library/react-native";
|
|
10
|
+
import {assert} from "chai";
|
|
11
|
+
import {createRef} from "react";
|
|
12
|
+
import type {Text as NativeText} from "react-native";
|
|
13
|
+
import {ThemeProvider} from "../Theme";
|
|
14
|
+
import {TimezonePicker} from "../TimezonePicker";
|
|
15
|
+
import {renderWithTheme} from "../test-utils";
|
|
16
|
+
import {AskCard, type AskCardProps} from "./AskCard";
|
|
17
|
+
import type {AskSubmission, ChatAsk} from "./askTypes";
|
|
18
|
+
|
|
19
|
+
const PLAN_INPUT: ChoiceAskInput = {
|
|
20
|
+
default: ["team"],
|
|
21
|
+
options: [
|
|
22
|
+
{description: "$0, one seat", id: "starter", label: "Starter"},
|
|
23
|
+
{description: "$20 per seat", id: "team", label: "Team"},
|
|
24
|
+
{id: "enterprise", label: "Enterprise"},
|
|
25
|
+
],
|
|
26
|
+
prompt: "Which plan should I set up for your workspace?",
|
|
27
|
+
select: "one",
|
|
28
|
+
submitLabel: "Set up plan",
|
|
29
|
+
title: "Choose a plan",
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const REGION_INPUT: ChoiceAskInput = {
|
|
33
|
+
options: [
|
|
34
|
+
{description: "Oregon", id: "west", label: "West"},
|
|
35
|
+
{id: "central", label: "Central"},
|
|
36
|
+
{id: "east", label: "East"},
|
|
37
|
+
{id: "europe", label: "Europe"},
|
|
38
|
+
{id: "asia", label: "Asia"},
|
|
39
|
+
],
|
|
40
|
+
prompt: "Where should the data live?",
|
|
41
|
+
select: "one",
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const COUNTRY_IDS = ["ar", "au", "br", "ca", "de", "es", "fr", "in", "it", "jp", "mx", "us"];
|
|
45
|
+
|
|
46
|
+
const COUNTRY_INPUT: ChoiceAskInput = {
|
|
47
|
+
options: COUNTRY_IDS.map((id) => ({id, label: `Country ${id.toUpperCase()}`})),
|
|
48
|
+
prompt: "Which country are you in?",
|
|
49
|
+
select: "one",
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const pendingAsk = (input: ChoiceAskInput, state: Partial<ChatAsk> = {}): ChatAsk => ({
|
|
53
|
+
input,
|
|
54
|
+
kind: "choice",
|
|
55
|
+
status: "pending",
|
|
56
|
+
toolCallId: "call_1",
|
|
57
|
+
...state,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
const ARCHIVE_INPUT: ConfirmAskInput = {
|
|
61
|
+
confirmLabel: "Archive 12 chats",
|
|
62
|
+
denyLabel: "Keep them",
|
|
63
|
+
destructive: true,
|
|
64
|
+
prompt: "Archive the 12 chats older than 90 days?",
|
|
65
|
+
title: "Archive old chats",
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
const REPORT_INPUT: ConfirmAskInput = {prompt: "Send the weekly report to the team now?"};
|
|
69
|
+
|
|
70
|
+
const pendingConfirm = (input: ConfirmAskInput, state: Partial<ChatAsk> = {}): ChatAsk =>
|
|
71
|
+
({input, kind: "confirm", status: "pending", toolCallId: "call_1", ...state}) as ChatAsk;
|
|
72
|
+
|
|
73
|
+
const DRAFT = "# We're live\n\nToday we launched.";
|
|
74
|
+
|
|
75
|
+
const DRAFT_INPUT: MarkdownAskInput = {
|
|
76
|
+
initial: DRAFT,
|
|
77
|
+
maxLength: 60,
|
|
78
|
+
minLength: 10,
|
|
79
|
+
placeholder: "Write the announcement",
|
|
80
|
+
prompt: "Here is a draft announcement. Edit anything, then send it back.",
|
|
81
|
+
submitLabel: "Send it back",
|
|
82
|
+
title: "Launch announcement",
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const pendingMarkdown = (input: MarkdownAskInput, state: Partial<ChatAsk> = {}): ChatAsk =>
|
|
86
|
+
({input, kind: "markdown", status: "pending", toolCallId: "call_1", ...state}) as ChatAsk;
|
|
87
|
+
|
|
88
|
+
const INVOICE_INPUT: FormAskInput = {
|
|
89
|
+
fields: [
|
|
90
|
+
{
|
|
91
|
+
helperText: "As it appears on the invoice.",
|
|
92
|
+
id: "company",
|
|
93
|
+
label: "Company name",
|
|
94
|
+
maxLength: 120,
|
|
95
|
+
required: true,
|
|
96
|
+
type: "text",
|
|
97
|
+
},
|
|
98
|
+
{id: "seats", integer: true, label: "Seats", max: 500, min: 1, type: "number"},
|
|
99
|
+
{id: "start", label: "Start date", type: "date"},
|
|
100
|
+
{
|
|
101
|
+
id: "region",
|
|
102
|
+
label: "Region",
|
|
103
|
+
options: [
|
|
104
|
+
{id: "us", label: "US"},
|
|
105
|
+
{id: "eu", label: "EU"},
|
|
106
|
+
],
|
|
107
|
+
type: "select",
|
|
108
|
+
},
|
|
109
|
+
{default: true, id: "notify", label: "Email me the invoice", type: "boolean"},
|
|
110
|
+
],
|
|
111
|
+
prompt: "A few details for the invoice.",
|
|
112
|
+
submitLabel: "Send details",
|
|
113
|
+
title: "Invoice details",
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const DEFAULTS_INPUT: FormAskInput = {
|
|
117
|
+
fields: [
|
|
118
|
+
{default: "Ring twice.", id: "notes", label: "Notes", type: "textarea"},
|
|
119
|
+
{id: "email", label: "Email", required: true, type: "email"},
|
|
120
|
+
{default: "https://example.com", id: "site", label: "Website", type: "url"},
|
|
121
|
+
{id: "phone", label: "Phone", type: "phone"},
|
|
122
|
+
{default: "09:30", id: "reminder", label: "Reminder", type: "time"},
|
|
123
|
+
{default: "2026-10-01T09:30:00Z", id: "meeting", label: "Meeting", type: "datetime"},
|
|
124
|
+
{
|
|
125
|
+
default: "express",
|
|
126
|
+
id: "shipping",
|
|
127
|
+
label: "Shipping",
|
|
128
|
+
options: [
|
|
129
|
+
{id: "standard", label: "Standard"},
|
|
130
|
+
{id: "express", label: "Express"},
|
|
131
|
+
],
|
|
132
|
+
type: "select",
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
default: ["email"],
|
|
136
|
+
id: "channels",
|
|
137
|
+
label: "Channels",
|
|
138
|
+
options: [
|
|
139
|
+
{id: "email", label: "Email"},
|
|
140
|
+
{id: "sms", label: "Text message"},
|
|
141
|
+
],
|
|
142
|
+
type: "multiselect",
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
prompt: "Check the details.",
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const pendingForm = (input: FormAskInput, state: Partial<ChatAsk> = {}): ChatAsk =>
|
|
149
|
+
({input, kind: "form", status: "pending", toolCallId: "call_1", ...state}) as ChatAsk;
|
|
150
|
+
|
|
151
|
+
const renderCard = (props: Partial<AskCardProps> & Pick<AskCardProps, "ask">) =>
|
|
152
|
+
renderWithTheme(<AskCard onSubmit={mock(async () => {})} {...props} />);
|
|
153
|
+
|
|
154
|
+
// Button presses await a haptic call before running onClick, so let those microtasks settle.
|
|
155
|
+
const press = async (element: Parameters<typeof fireEvent.press>[0]): Promise<void> => {
|
|
156
|
+
await act(async () => {
|
|
157
|
+
fireEvent.press(element);
|
|
158
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
159
|
+
});
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
const isDisabled = (element: {props: {accessibilityState?: {disabled?: boolean}}}): boolean =>
|
|
163
|
+
element.props.accessibilityState?.disabled === true;
|
|
164
|
+
|
|
165
|
+
const deferred = (): {promise: Promise<void>; resolve: () => void} => {
|
|
166
|
+
let resolve = (): void => {};
|
|
167
|
+
const promise = new Promise<void>((done) => {
|
|
168
|
+
resolve = done;
|
|
169
|
+
});
|
|
170
|
+
return {promise, resolve};
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
describe("AskCard", () => {
|
|
174
|
+
afterEach(() => {
|
|
175
|
+
mock.restore();
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
it("shows the title and the question", () => {
|
|
179
|
+
const {getByText} = renderCard({ask: pendingAsk(PLAN_INPUT)});
|
|
180
|
+
assert.isOk(getByText("Choose a plan"));
|
|
181
|
+
assert.isOk(getByText("Which plan should I set up for your workspace?"));
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
describe("quick replies", () => {
|
|
185
|
+
it("renders the simple card's option buttons, default first, then Skip", () => {
|
|
186
|
+
const simple = toSimpleCard({input: PLAN_INPUT, kind: "choice", toolCallId: "call_1"});
|
|
187
|
+
const {getAllByTestId, queryByTestId} = renderCard({ask: pendingAsk(PLAN_INPUT, {simple})});
|
|
188
|
+
|
|
189
|
+
const buttonIds = getAllByTestId(/^ask-card-button-/).map((button) => button.props.testID);
|
|
190
|
+
assert.deepEqual(buttonIds, [
|
|
191
|
+
"ask-card-button-option:team",
|
|
192
|
+
"ask-card-button-option:starter",
|
|
193
|
+
"ask-card-button-option:enterprise",
|
|
194
|
+
"ask-card-button-skip",
|
|
195
|
+
]);
|
|
196
|
+
assert.isNull(queryByTestId("ask-card-submit"));
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it("answers on tap with the tapped button's exact response", async () => {
|
|
200
|
+
const onSubmit = mock(async (_submission: AskSubmission) => {});
|
|
201
|
+
const {getByTestId} = renderCard({ask: pendingAsk(PLAN_INPUT), onSubmit});
|
|
202
|
+
|
|
203
|
+
await press(getByTestId("ask-card-button-option:starter"));
|
|
204
|
+
|
|
205
|
+
assert.deepEqual(onSubmit.mock.calls[0]?.[0], {
|
|
206
|
+
response: {action: "accept", content: {selected: ["starter"]}},
|
|
207
|
+
toolCallId: "call_1",
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("shows option descriptions, which the buttons cannot hold", () => {
|
|
212
|
+
const {getByText} = renderCard({ask: pendingAsk(PLAN_INPUT)});
|
|
213
|
+
assert.isOk(getByText("Starter — $0, one seat"));
|
|
214
|
+
assert.isOk(getByText("Team — $20 per seat"));
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it("uses radio buttons when a label is too long to show in full on a button", () => {
|
|
218
|
+
const input: ChoiceAskInput = {
|
|
219
|
+
options: [
|
|
220
|
+
{id: "short", label: "Short"},
|
|
221
|
+
{id: "long", label: "A label that runs past twenty characters"},
|
|
222
|
+
],
|
|
223
|
+
prompt: "Pick one",
|
|
224
|
+
select: "one",
|
|
225
|
+
};
|
|
226
|
+
const {getByText, queryByTestId} = renderCard({ask: pendingAsk(input)});
|
|
227
|
+
assert.isOk(getByText("Choose one"));
|
|
228
|
+
assert.isNull(queryByTestId("ask-card-quick-replies"));
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it("hides Skip when the ask cannot be declined", () => {
|
|
232
|
+
const {queryByTestId} = renderCard({
|
|
233
|
+
ask: pendingAsk({...PLAN_INPUT, allowDecline: false}),
|
|
234
|
+
});
|
|
235
|
+
assert.isOk(queryByTestId("ask-card-button-option:team"));
|
|
236
|
+
assert.isNull(queryByTestId("ask-card-button-skip"));
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
describe("radio buttons", () => {
|
|
241
|
+
it("keeps Submit disabled until an option is chosen, then sends that option", async () => {
|
|
242
|
+
const onSubmit = mock(async (_submission: AskSubmission) => {});
|
|
243
|
+
const {getByTestId, getByText} = renderCard({
|
|
244
|
+
ask: pendingAsk(REGION_INPUT),
|
|
245
|
+
onSubmit,
|
|
246
|
+
});
|
|
247
|
+
assert.isOk(getByText("Choose one"));
|
|
248
|
+
assert.isTrue(isDisabled(getByTestId("ask-card-submit")));
|
|
249
|
+
|
|
250
|
+
await press(within(getByTestId("ask-card-radio")).getByLabelText("West — Oregon"));
|
|
251
|
+
assert.isFalse(isDisabled(getByTestId("ask-card-submit")));
|
|
252
|
+
await press(getByTestId("ask-card-submit"));
|
|
253
|
+
|
|
254
|
+
assert.deepEqual(onSubmit.mock.calls[0]?.[0], {
|
|
255
|
+
response: {action: "accept", content: {selected: ["west"]}},
|
|
256
|
+
toolCallId: "call_1",
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
it("preselects the default so Submit is ready", async () => {
|
|
261
|
+
const onSubmit = mock(async (_submission: AskSubmission) => {});
|
|
262
|
+
const {getByTestId, getByText} = renderCard({
|
|
263
|
+
ask: pendingAsk({...REGION_INPUT, default: ["east"], submitLabel: "Use region"}),
|
|
264
|
+
onSubmit,
|
|
265
|
+
});
|
|
266
|
+
assert.isOk(getByText("Use region"));
|
|
267
|
+
|
|
268
|
+
await press(getByTestId("ask-card-submit"));
|
|
269
|
+
|
|
270
|
+
assert.deepEqual(onSubmit.mock.calls[0]?.[0]?.response, {
|
|
271
|
+
action: "accept",
|
|
272
|
+
content: {selected: ["east"]},
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
it("declines when the user presses Skip", async () => {
|
|
277
|
+
const onSubmit = mock(async (_submission: AskSubmission) => {});
|
|
278
|
+
const {getByTestId} = renderCard({ask: pendingAsk(REGION_INPUT), onSubmit});
|
|
279
|
+
|
|
280
|
+
await press(getByTestId("ask-card-button-skip"));
|
|
281
|
+
|
|
282
|
+
assert.deepEqual(onSubmit.mock.calls[0]?.[0], {
|
|
283
|
+
response: {action: "decline"},
|
|
284
|
+
toolCallId: "call_1",
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
it("hides Skip when the ask cannot be declined", () => {
|
|
289
|
+
const {queryByTestId} = renderCard({
|
|
290
|
+
ask: pendingAsk({...REGION_INPUT, allowDecline: false}),
|
|
291
|
+
});
|
|
292
|
+
assert.isOk(queryByTestId("ask-card-submit"));
|
|
293
|
+
assert.isNull(queryByTestId("ask-card-button-skip"));
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
describe("searchable select", () => {
|
|
298
|
+
it("is used above eight options and sends the chosen option", async () => {
|
|
299
|
+
const onSubmit = mock(async (_submission: AskSubmission) => {});
|
|
300
|
+
const {getByTestId, queryByLabelText} = renderCard({
|
|
301
|
+
ask: pendingAsk(COUNTRY_INPUT),
|
|
302
|
+
onSubmit,
|
|
303
|
+
});
|
|
304
|
+
assert.isNull(queryByLabelText("Country CA"));
|
|
305
|
+
assert.isTrue(isDisabled(getByTestId("ask-card-submit")));
|
|
306
|
+
|
|
307
|
+
await press(getByTestId("web_picker"));
|
|
308
|
+
assert.isOk(getByTestId("web_dropdown_search"));
|
|
309
|
+
await press(getByTestId("web_dropdown_option_ca"));
|
|
310
|
+
await press(getByTestId("ask-card-submit"));
|
|
311
|
+
|
|
312
|
+
assert.deepEqual(onSubmit.mock.calls[0]?.[0]?.response, {
|
|
313
|
+
action: "accept",
|
|
314
|
+
content: {selected: ["ca"]},
|
|
315
|
+
});
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
|
|
319
|
+
describe("select many", () => {
|
|
320
|
+
const TOPPINGS_INPUT: ChoiceAskInput = {
|
|
321
|
+
allowOther: true,
|
|
322
|
+
default: ["cheese"],
|
|
323
|
+
maxSelected: 2,
|
|
324
|
+
options: [
|
|
325
|
+
{id: "cheese", label: "Extra cheese"},
|
|
326
|
+
{description: "Button and cremini", id: "mushrooms", label: "Mushrooms"},
|
|
327
|
+
{id: "olives", label: "Olives"},
|
|
328
|
+
],
|
|
329
|
+
otherLabel: "Another topping",
|
|
330
|
+
prompt: "Which toppings should I add?",
|
|
331
|
+
select: "many",
|
|
332
|
+
submitLabel: "Add toppings",
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
it("renders checkboxes, the Other field, and the selection bounds, not quick replies", () => {
|
|
336
|
+
const {getByLabelText, getByTestId, getByText, queryByTestId} = renderCard({
|
|
337
|
+
ask: pendingAsk(TOPPINGS_INPUT),
|
|
338
|
+
});
|
|
339
|
+
assert.isOk(getByTestId("ask-card-multiselect"));
|
|
340
|
+
assert.isOk(getByLabelText("Mushrooms — Button and cremini"));
|
|
341
|
+
assert.isOk(getByText("Another topping"));
|
|
342
|
+
assert.isOk(getByTestId("ask-card-other"));
|
|
343
|
+
assert.isOk(getByText("Choose 1 to 2. Another topping counts as one choice."));
|
|
344
|
+
assert.isNull(queryByTestId("ask-card-quick-replies"));
|
|
345
|
+
assert.isNull(queryByTestId("ask-card-button-use-default"));
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
it("preselects the default and sends the selected ids in option order", async () => {
|
|
349
|
+
const onSubmit = mock(async (_submission: AskSubmission) => {});
|
|
350
|
+
const {getByLabelText, getByTestId} = renderCard({
|
|
351
|
+
ask: pendingAsk({...TOPPINGS_INPUT, allowOther: undefined, otherLabel: undefined}),
|
|
352
|
+
onSubmit,
|
|
353
|
+
});
|
|
354
|
+
assert.isFalse(isDisabled(getByTestId("ask-card-submit")));
|
|
355
|
+
|
|
356
|
+
await press(getByLabelText("Olives"));
|
|
357
|
+
await press(getByLabelText("Extra cheese"));
|
|
358
|
+
await press(getByLabelText("Extra cheese"));
|
|
359
|
+
await press(getByTestId("ask-card-submit"));
|
|
360
|
+
|
|
361
|
+
assert.deepEqual(onSubmit.mock.calls[0]?.[0], {
|
|
362
|
+
response: {action: "accept", content: {selected: ["cheese", "olives"]}},
|
|
363
|
+
toolCallId: "call_1",
|
|
364
|
+
});
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
it("sends the trimmed Other text, counted as one choice", async () => {
|
|
368
|
+
const onSubmit = mock(async (_submission: AskSubmission) => {});
|
|
369
|
+
const {getByTestId} = renderCard({ask: pendingAsk(TOPPINGS_INPUT), onSubmit});
|
|
370
|
+
|
|
371
|
+
await act(async () => {
|
|
372
|
+
fireEvent.changeText(getByTestId("ask-card-other"), " Basil ");
|
|
373
|
+
});
|
|
374
|
+
await press(getByTestId("ask-card-submit"));
|
|
375
|
+
|
|
376
|
+
assert.deepEqual(onSubmit.mock.calls[0]?.[0]?.response, {
|
|
377
|
+
action: "accept",
|
|
378
|
+
content: {other: "Basil", selected: ["cheese"]},
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it("keeps Submit disabled and says why when the choices pass maxSelected", async () => {
|
|
383
|
+
const {getByLabelText, getByTestId, getByText} = renderCard({
|
|
384
|
+
ask: pendingAsk(TOPPINGS_INPUT),
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
await press(getByLabelText("Olives"));
|
|
388
|
+
assert.isFalse(isDisabled(getByTestId("ask-card-submit")));
|
|
389
|
+
await act(async () => {
|
|
390
|
+
fireEvent.changeText(getByTestId("ask-card-other"), "Basil");
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
assert.isTrue(isDisabled(getByTestId("ask-card-submit")));
|
|
394
|
+
assert.isOk(getByText("You chose 3. Choose at most 2."));
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
it("keeps Submit disabled until the answer meets minSelected", async () => {
|
|
398
|
+
const {getByLabelText, getByTestId} = renderCard({
|
|
399
|
+
ask: pendingAsk({...TOPPINGS_INPUT, default: undefined, minSelected: 2}),
|
|
400
|
+
});
|
|
401
|
+
assert.isTrue(isDisabled(getByTestId("ask-card-submit")));
|
|
402
|
+
|
|
403
|
+
await press(getByLabelText("Olives"));
|
|
404
|
+
assert.isTrue(isDisabled(getByTestId("ask-card-submit")));
|
|
405
|
+
await press(getByLabelText("Extra cheese"));
|
|
406
|
+
assert.isFalse(isDisabled(getByTestId("ask-card-submit")));
|
|
407
|
+
});
|
|
408
|
+
|
|
409
|
+
it("keeps Submit disabled while the Other text is too long", async () => {
|
|
410
|
+
const {getByTestId, getByText} = renderCard({ask: pendingAsk(TOPPINGS_INPUT)});
|
|
411
|
+
|
|
412
|
+
await act(async () => {
|
|
413
|
+
fireEvent.changeText(getByTestId("ask-card-other"), "b".repeat(501));
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
assert.isTrue(isDisabled(getByTestId("ask-card-submit")));
|
|
417
|
+
assert.isOk(getByText("Keep this to 500 characters or fewer."));
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
it("shows a server error on the Other field inline, and other errors below", () => {
|
|
421
|
+
const {getByTestId, getByText} = renderCard({
|
|
422
|
+
ask: pendingAsk(TOPPINGS_INPUT),
|
|
423
|
+
errors: [
|
|
424
|
+
{
|
|
425
|
+
code: "SELECTION_COUNT",
|
|
426
|
+
fix: "Send 1 to 2 options in content.selected. Other counts as one choice.",
|
|
427
|
+
message: "Choose 1 to 2 options; the answer selects 3, counting Other.",
|
|
428
|
+
path: "content.selected",
|
|
429
|
+
},
|
|
430
|
+
{
|
|
431
|
+
code: "TOO_SHORT",
|
|
432
|
+
fix: "Put visible text in content.other.",
|
|
433
|
+
message: "content.other is empty.",
|
|
434
|
+
path: "content.other",
|
|
435
|
+
},
|
|
436
|
+
],
|
|
437
|
+
});
|
|
438
|
+
assert.isOk(getByText("content.other is empty."));
|
|
439
|
+
const errorList = within(getByTestId("ask-card-errors"));
|
|
440
|
+
assert.isOk(
|
|
441
|
+
errorList.getByText("Choose 1 to 2 options; the answer selects 3, counting Other.")
|
|
442
|
+
);
|
|
443
|
+
assert.isNull(errorList.queryByText("content.other is empty."));
|
|
444
|
+
});
|
|
445
|
+
|
|
446
|
+
it("declines when the user presses Skip, and hides Skip when the ask cannot be declined", async () => {
|
|
447
|
+
const onSubmit = mock(async (_submission: AskSubmission) => {});
|
|
448
|
+
const {getByTestId} = renderCard({ask: pendingAsk(TOPPINGS_INPUT), onSubmit});
|
|
449
|
+
await press(getByTestId("ask-card-button-skip"));
|
|
450
|
+
assert.deepEqual(onSubmit.mock.calls[0]?.[0]?.response, {action: "decline"});
|
|
451
|
+
|
|
452
|
+
const required = renderCard({ask: pendingAsk({...TOPPINGS_INPUT, allowDecline: false})});
|
|
453
|
+
assert.isNull(required.queryByTestId("ask-card-button-skip"));
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
it("lists the options as plain text when the host takes no answers", () => {
|
|
457
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
458
|
+
<AskCard ask={pendingAsk(TOPPINGS_INPUT)} />
|
|
459
|
+
);
|
|
460
|
+
assert.isOk(getByTestId("ask-card-options"));
|
|
461
|
+
assert.isNull(queryByTestId("ask-card-multiselect"));
|
|
462
|
+
assert.isTrue(isDisabled(getByTestId("ask-card-submit")));
|
|
463
|
+
assert.isTrue(isDisabled(getByTestId("ask-card-button-skip")));
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
it("summarizes the answer with the chosen labels and the Other text", () => {
|
|
467
|
+
const {getByText} = renderCard({
|
|
468
|
+
ask: pendingAsk(TOPPINGS_INPUT, {
|
|
469
|
+
response: {action: "accept", content: {other: "Basil", selected: ["olives"]}},
|
|
470
|
+
status: "answered",
|
|
471
|
+
}),
|
|
472
|
+
});
|
|
473
|
+
assert.isOk(getByText("You chose: Olives. Another topping: Basil"));
|
|
474
|
+
});
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
describe("confirm", () => {
|
|
478
|
+
// The variant each answer button renders with, read from the Button element that gets it.
|
|
479
|
+
const buttonVariants = (root: ReturnType<typeof renderCard>): [string, string][] =>
|
|
480
|
+
root
|
|
481
|
+
.getAllByTestId(/^ask-card-button-/)
|
|
482
|
+
.map((element) => element.props.testID as string)
|
|
483
|
+
.map((testID) => {
|
|
484
|
+
const [button] = root
|
|
485
|
+
.UNSAFE_queryAllByProps({testID})
|
|
486
|
+
.filter((instance) => instance.props.variant !== undefined);
|
|
487
|
+
return [testID, button?.props.variant];
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
it("shows the approve button first as destructive, then the deny button, with no Skip", () => {
|
|
491
|
+
const card = renderCard({ask: pendingConfirm(ARCHIVE_INPUT)});
|
|
492
|
+
|
|
493
|
+
assert.isOk(card.getByText("Archive old chats"));
|
|
494
|
+
assert.isOk(card.getByText("Archive the 12 chats older than 90 days?"));
|
|
495
|
+
assert.deepEqual(buttonVariants(card), [
|
|
496
|
+
["ask-card-button-approve", "destructive"],
|
|
497
|
+
["ask-card-button-deny", "ghost"],
|
|
498
|
+
]);
|
|
499
|
+
assert.isOk(
|
|
500
|
+
within(card.getByTestId("ask-card-button-approve")).getByText("Archive 12 chats")
|
|
501
|
+
);
|
|
502
|
+
assert.isOk(within(card.getByTestId("ask-card-button-deny")).getByText("Keep them"));
|
|
503
|
+
for (const button of card.getAllByTestId(/^ask-card-button-/)) {
|
|
504
|
+
assert.include(button.props.style, {maxWidth: "100%"});
|
|
505
|
+
}
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
it("uses the primary style and the default labels when the ask is not destructive", () => {
|
|
509
|
+
const card = renderCard({ask: pendingConfirm(REPORT_INPUT)});
|
|
510
|
+
|
|
511
|
+
assert.deepEqual(buttonVariants(card), [
|
|
512
|
+
["ask-card-button-approve", "primary"],
|
|
513
|
+
["ask-card-button-deny", "ghost"],
|
|
514
|
+
]);
|
|
515
|
+
assert.isOk(within(card.getByTestId("ask-card-button-approve")).getByText("Confirm"));
|
|
516
|
+
assert.isOk(within(card.getByTestId("ask-card-button-deny")).getByText("Cancel"));
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
it.each([
|
|
520
|
+
{buttonId: "approve", confirmed: true},
|
|
521
|
+
{buttonId: "deny", confirmed: false},
|
|
522
|
+
])("sends {confirmed: $confirmed} from the $buttonId button", async ({buttonId, confirmed}) => {
|
|
523
|
+
const onSubmit = mock(async (_submission: AskSubmission) => {});
|
|
524
|
+
const {getByTestId} = renderCard({ask: pendingConfirm(ARCHIVE_INPUT), onSubmit});
|
|
525
|
+
|
|
526
|
+
await press(getByTestId(`ask-card-button-${buttonId}`));
|
|
527
|
+
|
|
528
|
+
assert.deepEqual(onSubmit.mock.calls[0]?.[0], {
|
|
529
|
+
response: {action: "accept", content: {confirmed}},
|
|
530
|
+
toolCallId: "call_1",
|
|
531
|
+
});
|
|
532
|
+
});
|
|
533
|
+
|
|
534
|
+
it("adds Skip last when allowDecline is true, and it declines", async () => {
|
|
535
|
+
const onSubmit = mock(async (_submission: AskSubmission) => {});
|
|
536
|
+
const card = renderCard({
|
|
537
|
+
ask: pendingConfirm({...REPORT_INPUT, allowDecline: true}),
|
|
538
|
+
onSubmit,
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
assert.deepEqual(
|
|
542
|
+
card.getAllByTestId(/^ask-card-button-/).map((button) => button.props.testID),
|
|
543
|
+
["ask-card-button-approve", "ask-card-button-deny", "ask-card-button-skip"]
|
|
544
|
+
);
|
|
545
|
+
await press(card.getByTestId("ask-card-button-skip"));
|
|
546
|
+
assert.deepEqual(onSubmit.mock.calls[0]?.[0], {
|
|
547
|
+
response: {action: "decline"},
|
|
548
|
+
toolCallId: "call_1",
|
|
549
|
+
});
|
|
550
|
+
});
|
|
551
|
+
|
|
552
|
+
it("shows the pressed button loading and blocks the other until the host finishes", async () => {
|
|
553
|
+
const pending = deferred();
|
|
554
|
+
const onSubmit = mock((_submission: AskSubmission) => pending.promise);
|
|
555
|
+
const {getByTestId} = renderCard({ask: pendingConfirm(ARCHIVE_INPUT), onSubmit});
|
|
556
|
+
|
|
557
|
+
await press(getByTestId("ask-card-button-approve"));
|
|
558
|
+
assert.lengthOf(
|
|
559
|
+
getByTestId("ask-card-button-approve").findAll((node) => node.type === "ActivityIndicator"),
|
|
560
|
+
1
|
|
561
|
+
);
|
|
562
|
+
assert.isTrue(isDisabled(getByTestId("ask-card-button-deny")));
|
|
563
|
+
await press(getByTestId("ask-card-button-deny"));
|
|
564
|
+
assert.lengthOf(onSubmit.mock.calls, 1);
|
|
565
|
+
|
|
566
|
+
await act(async () => {
|
|
567
|
+
pending.resolve();
|
|
568
|
+
await pending.promise;
|
|
569
|
+
});
|
|
570
|
+
assert.isFalse(isDisabled(getByTestId("ask-card-button-deny")));
|
|
571
|
+
});
|
|
572
|
+
|
|
573
|
+
it("disables both buttons when the host takes no answers", () => {
|
|
574
|
+
const {getByTestId} = renderWithTheme(<AskCard ask={pendingConfirm(ARCHIVE_INPUT)} />);
|
|
575
|
+
assert.isTrue(isDisabled(getByTestId("ask-card-button-approve")));
|
|
576
|
+
assert.isTrue(isDisabled(getByTestId("ask-card-button-deny")));
|
|
577
|
+
});
|
|
578
|
+
|
|
579
|
+
it("shows server errors for the last answer inline", () => {
|
|
580
|
+
const {getByText} = renderCard({
|
|
581
|
+
ask: pendingConfirm(ARCHIVE_INPUT),
|
|
582
|
+
errors: [
|
|
583
|
+
{
|
|
584
|
+
code: "DECLINE_NOT_ALLOWED",
|
|
585
|
+
fix: 'Answer with action "accept".',
|
|
586
|
+
message: "This ask cannot be skipped.",
|
|
587
|
+
path: "action",
|
|
588
|
+
},
|
|
589
|
+
],
|
|
590
|
+
});
|
|
591
|
+
assert.isOk(getByText("This ask cannot be skipped."));
|
|
592
|
+
});
|
|
593
|
+
|
|
594
|
+
it.each([
|
|
595
|
+
{confirmed: true, summary: "You confirmed: Archive 12 chats"},
|
|
596
|
+
{confirmed: false, summary: "You declined: Keep them"},
|
|
597
|
+
])("summarizes an answer of confirmed $confirmed with its label", ({confirmed, summary}) => {
|
|
598
|
+
const {getByText, queryByTestId} = renderCard({
|
|
599
|
+
ask: pendingConfirm(ARCHIVE_INPUT, {
|
|
600
|
+
response: {action: "accept", content: {confirmed}},
|
|
601
|
+
status: "answered",
|
|
602
|
+
}),
|
|
603
|
+
});
|
|
604
|
+
assert.isOk(getByText(summary));
|
|
605
|
+
assert.isNull(queryByTestId("ask-card-button-approve"));
|
|
606
|
+
});
|
|
607
|
+
|
|
608
|
+
it("says a confirm with matching labels cannot be shown", () => {
|
|
609
|
+
const {getByTestId, queryByTestId} = renderCard({
|
|
610
|
+
ask: pendingConfirm({...REPORT_INPUT, confirmLabel: "Cancel"}),
|
|
611
|
+
});
|
|
612
|
+
assert.isOk(getByTestId("ask-card-invalid"));
|
|
613
|
+
assert.isNull(queryByTestId("ask-card-button-approve"));
|
|
614
|
+
});
|
|
615
|
+
});
|
|
616
|
+
|
|
617
|
+
describe("markdown", () => {
|
|
618
|
+
const typeDraft = (root: ReturnType<typeof renderCard>, text: string): void => {
|
|
619
|
+
act(() => {
|
|
620
|
+
fireEvent.changeText(root.getByTestId("ask-card-editor-input"), text);
|
|
621
|
+
});
|
|
622
|
+
};
|
|
623
|
+
|
|
624
|
+
it("starts the editor from the draft and shows the length hint, Submit, and Skip", () => {
|
|
625
|
+
const card = renderCard({ask: pendingMarkdown(DRAFT_INPUT)});
|
|
626
|
+
|
|
627
|
+
assert.isOk(card.getByText("Launch announcement"));
|
|
628
|
+
assert.equal(card.getByTestId("ask-card-editor-input").props.value, DRAFT);
|
|
629
|
+
assert.isOk(card.getByText(`${DRAFT.length} / 60 characters. At least 10.`));
|
|
630
|
+
assert.isOk(within(card.getByTestId("ask-card-submit")).getByText("Send it back"));
|
|
631
|
+
assert.isFalse(isDisabled(card.getByTestId("ask-card-submit")));
|
|
632
|
+
assert.isOk(card.getByTestId("ask-card-button-skip"));
|
|
633
|
+
});
|
|
634
|
+
|
|
635
|
+
it("sends the draft unchanged with changed false", async () => {
|
|
636
|
+
const onSubmit = mock(async (_submission: AskSubmission) => {});
|
|
637
|
+
const card = renderCard({ask: pendingMarkdown(DRAFT_INPUT), onSubmit});
|
|
638
|
+
|
|
639
|
+
await press(card.getByTestId("ask-card-submit"));
|
|
640
|
+
|
|
641
|
+
assert.deepEqual(onSubmit.mock.calls[0]?.[0], {
|
|
642
|
+
response: {action: "accept", content: {changed: false, markdown: DRAFT}},
|
|
643
|
+
toolCallId: "call_1",
|
|
644
|
+
});
|
|
645
|
+
});
|
|
646
|
+
|
|
647
|
+
it("sends an edit with changed true, and changed false again once the edit is undone", async () => {
|
|
648
|
+
const onSubmit = mock(async (_submission: AskSubmission) => {});
|
|
649
|
+
const card = renderCard({ask: pendingMarkdown(DRAFT_INPUT), onSubmit});
|
|
650
|
+
|
|
651
|
+
typeDraft(card, "# We're live\n\nWe launched today.");
|
|
652
|
+
await press(card.getByTestId("ask-card-submit"));
|
|
653
|
+
typeDraft(card, DRAFT);
|
|
654
|
+
await press(card.getByTestId("ask-card-submit"));
|
|
655
|
+
|
|
656
|
+
assert.deepEqual(
|
|
657
|
+
onSubmit.mock.calls.map((call) => call[0].response),
|
|
658
|
+
[
|
|
659
|
+
{
|
|
660
|
+
action: "accept",
|
|
661
|
+
content: {changed: true, markdown: "# We're live\n\nWe launched today."},
|
|
662
|
+
},
|
|
663
|
+
{action: "accept", content: {changed: false, markdown: DRAFT}},
|
|
664
|
+
]
|
|
665
|
+
);
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
it("keeps Submit disabled and says why while the text is longer than maxLength", () => {
|
|
669
|
+
const card = renderCard({ask: pendingMarkdown(DRAFT_INPUT)});
|
|
670
|
+
|
|
671
|
+
typeDraft(card, "x".repeat(61));
|
|
672
|
+
|
|
673
|
+
assert.isTrue(isDisabled(card.getByTestId("ask-card-submit")));
|
|
674
|
+
assert.isOk(card.getByText("Keep this to 60 characters or fewer."));
|
|
675
|
+
assert.isOk(card.getByText("61 / 60 characters. At least 10."));
|
|
676
|
+
});
|
|
677
|
+
|
|
678
|
+
it("keeps Submit disabled until the text meets minLength", () => {
|
|
679
|
+
const card = renderCard({ask: pendingMarkdown({...DRAFT_INPUT, initial: undefined})});
|
|
680
|
+
|
|
681
|
+
assert.equal(card.getByTestId("ask-card-editor-input").props.value, "");
|
|
682
|
+
assert.isTrue(isDisabled(card.getByTestId("ask-card-submit")));
|
|
683
|
+
typeDraft(card, " short ");
|
|
684
|
+
assert.isTrue(isDisabled(card.getByTestId("ask-card-submit")));
|
|
685
|
+
typeDraft(card, "Long enough now");
|
|
686
|
+
assert.isFalse(isDisabled(card.getByTestId("ask-card-submit")));
|
|
687
|
+
});
|
|
688
|
+
|
|
689
|
+
it("declines with Skip, and hides Skip when the ask cannot be declined", async () => {
|
|
690
|
+
const onSubmit = mock(async (_submission: AskSubmission) => {});
|
|
691
|
+
const card = renderCard({ask: pendingMarkdown(DRAFT_INPUT), onSubmit});
|
|
692
|
+
await press(card.getByTestId("ask-card-button-skip"));
|
|
693
|
+
assert.deepEqual(onSubmit.mock.calls[0]?.[0]?.response, {action: "decline"});
|
|
694
|
+
|
|
695
|
+
const required = renderCard({ask: pendingMarkdown({...DRAFT_INPUT, allowDecline: false})});
|
|
696
|
+
assert.isNull(required.queryByTestId("ask-card-button-skip"));
|
|
697
|
+
});
|
|
698
|
+
|
|
699
|
+
it("shows a server error on the text in the editor, and other errors below", () => {
|
|
700
|
+
const card = renderCard({
|
|
701
|
+
ask: pendingMarkdown(DRAFT_INPUT),
|
|
702
|
+
errors: [
|
|
703
|
+
{
|
|
704
|
+
code: "CHANGED_MISMATCH",
|
|
705
|
+
fix: "Set content.changed to false.",
|
|
706
|
+
message: "The text is the same as the draft, but changed is true.",
|
|
707
|
+
path: "content.changed",
|
|
708
|
+
},
|
|
709
|
+
{
|
|
710
|
+
code: "TOO_LONG",
|
|
711
|
+
fix: "Shorten content.markdown to 60 characters or fewer.",
|
|
712
|
+
message: "The text is 61 characters, but this ask allows at most 60.",
|
|
713
|
+
path: "content.markdown",
|
|
714
|
+
},
|
|
715
|
+
],
|
|
716
|
+
});
|
|
717
|
+
|
|
718
|
+
assert.isOk(card.getByText("The text is 61 characters, but this ask allows at most 60."));
|
|
719
|
+
assert.isOk(
|
|
720
|
+
within(card.getByTestId("ask-card-errors")).getByText(
|
|
721
|
+
"The text is the same as the draft, but changed is true."
|
|
722
|
+
)
|
|
723
|
+
);
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
it("disables the editor, Submit, and Skip when the host takes no answers", () => {
|
|
727
|
+
const {getByTestId} = renderWithTheme(<AskCard ask={pendingMarkdown(DRAFT_INPUT)} />);
|
|
728
|
+
assert.isFalse(getByTestId("ask-card-editor-input").props.editable);
|
|
729
|
+
assert.isTrue(isDisabled(getByTestId("ask-card-submit")));
|
|
730
|
+
assert.isTrue(isDisabled(getByTestId("ask-card-button-skip")));
|
|
731
|
+
});
|
|
732
|
+
|
|
733
|
+
it("says a markdown ask with minLength above maxLength cannot be shown", () => {
|
|
734
|
+
const {getByTestId, queryByTestId} = renderCard({
|
|
735
|
+
ask: pendingMarkdown({...DRAFT_INPUT, minLength: 100}),
|
|
736
|
+
});
|
|
737
|
+
assert.isOk(getByTestId("ask-card-invalid"));
|
|
738
|
+
assert.isNull(queryByTestId("ask-card-editor"));
|
|
739
|
+
});
|
|
740
|
+
|
|
741
|
+
it("summarizes an edit with its length and shows the text it sent", () => {
|
|
742
|
+
const {getByTestId, getByText, queryByTestId} = renderCard({
|
|
743
|
+
ask: pendingMarkdown(DRAFT_INPUT, {
|
|
744
|
+
response: {action: "accept", content: {changed: true, markdown: "We launched today."}},
|
|
745
|
+
status: "answered",
|
|
746
|
+
}),
|
|
747
|
+
});
|
|
748
|
+
|
|
749
|
+
assert.isOk(getByText("You edited the draft (18 characters)"));
|
|
750
|
+
assert.isOk(within(getByTestId("ask-card-answer")).getByText("We launched today."));
|
|
751
|
+
assert.isNull(queryByTestId("ask-card-answer-toggle"));
|
|
752
|
+
assert.isNull(queryByTestId("ask-card-editor"));
|
|
753
|
+
});
|
|
754
|
+
|
|
755
|
+
it("summarizes an approved draft", () => {
|
|
756
|
+
const {getByTestId, getByText} = renderCard({
|
|
757
|
+
ask: pendingMarkdown(DRAFT_INPUT, {
|
|
758
|
+
response: {action: "accept", content: {changed: false, markdown: DRAFT}},
|
|
759
|
+
status: "answered",
|
|
760
|
+
}),
|
|
761
|
+
});
|
|
762
|
+
assert.isOk(getByText("You approved the draft as is"));
|
|
763
|
+
assert.isOk(getByTestId("ask-card-answer"));
|
|
764
|
+
});
|
|
765
|
+
|
|
766
|
+
it("collapses a long answer to a preview until the user shows all of it", async () => {
|
|
767
|
+
const longAnswer = `${"word ".repeat(80)}THE END`;
|
|
768
|
+
const card = renderCard({
|
|
769
|
+
ask: pendingMarkdown(
|
|
770
|
+
{prompt: "Write it."},
|
|
771
|
+
{
|
|
772
|
+
response: {action: "accept", content: {changed: true, markdown: longAnswer}},
|
|
773
|
+
status: "answered",
|
|
774
|
+
}
|
|
775
|
+
),
|
|
776
|
+
});
|
|
777
|
+
const answerText = (): string => JSON.stringify(card.toJSON());
|
|
778
|
+
|
|
779
|
+
assert.isOk(card.getByText("You edited the draft (407 characters)"));
|
|
780
|
+
await waitFor(() => {
|
|
781
|
+
assert.include(answerText(), "…");
|
|
782
|
+
});
|
|
783
|
+
assert.notInclude(answerText(), "THE END");
|
|
784
|
+
await press(card.getByTestId("ask-card-answer-toggle"));
|
|
785
|
+
await waitFor(() => {
|
|
786
|
+
assert.include(answerText(), "THE END");
|
|
787
|
+
});
|
|
788
|
+
assert.isOk(within(card.getByTestId("ask-card-answer-toggle")).getByText("Show less"));
|
|
789
|
+
});
|
|
790
|
+
|
|
791
|
+
it("summarizes a skipped draft without the answer box", () => {
|
|
792
|
+
const {getByText, queryByTestId} = renderCard({
|
|
793
|
+
ask: pendingMarkdown(DRAFT_INPUT, {response: {action: "decline"}, status: "answered"}),
|
|
794
|
+
});
|
|
795
|
+
assert.isOk(getByText("You skipped this question."));
|
|
796
|
+
assert.isNull(queryByTestId("ask-card-answer"));
|
|
797
|
+
});
|
|
798
|
+
});
|
|
799
|
+
|
|
800
|
+
describe("form", () => {
|
|
801
|
+
const typeInto = (root: ReturnType<typeof renderCard>, testID: string, text: string): void => {
|
|
802
|
+
act(() => {
|
|
803
|
+
fireEvent.changeText(root.getByTestId(testID), text);
|
|
804
|
+
});
|
|
805
|
+
};
|
|
806
|
+
|
|
807
|
+
it("renders one labelled control per field, marks required fields, and shows helper text", () => {
|
|
808
|
+
const card = renderCard({ask: pendingForm(INVOICE_INPUT)});
|
|
809
|
+
|
|
810
|
+
assert.isOk(card.getByText("Invoice details"));
|
|
811
|
+
assert.isOk(card.getByText("Company name (required)"));
|
|
812
|
+
assert.isOk(card.getByText("As it appears on the invoice."));
|
|
813
|
+
assert.isOk(card.getByTestId("ask-card-field-company"));
|
|
814
|
+
assert.isOk(card.getByTestId("ask-card-field-seats"));
|
|
815
|
+
assert.isOk(card.getByTestId("ask-card-field-start"));
|
|
816
|
+
assert.isOk(within(card.getByTestId("ask-card-form-field-region")).getByText("Region"));
|
|
817
|
+
assert.isOk(card.getByTestId("ask-card-field-notify.switch"));
|
|
818
|
+
assert.isOk(within(card.getByTestId("ask-card-submit")).getByText("Send details"));
|
|
819
|
+
assert.isOk(card.getByTestId("ask-card-button-skip"));
|
|
820
|
+
});
|
|
821
|
+
|
|
822
|
+
it("keeps Submit disabled until required fields are filled, then sends the typed values", async () => {
|
|
823
|
+
const onSubmit = mock(async (_submission: AskSubmission) => {});
|
|
824
|
+
const card = renderCard({ask: pendingForm(INVOICE_INPUT), onSubmit});
|
|
825
|
+
assert.isTrue(isDisabled(card.getByTestId("ask-card-submit")));
|
|
826
|
+
|
|
827
|
+
typeInto(card, "ask-card-field-company", " Acme Corp ");
|
|
828
|
+
typeInto(card, "ask-card-field-seats", "12");
|
|
829
|
+
await press(card.getByTestId("ask-card-field-notify.switch"));
|
|
830
|
+
assert.isFalse(isDisabled(card.getByTestId("ask-card-submit")));
|
|
831
|
+
await press(card.getByTestId("ask-card-submit"));
|
|
832
|
+
|
|
833
|
+
assert.deepEqual(onSubmit.mock.calls[0]?.[0], {
|
|
834
|
+
response: {
|
|
835
|
+
action: "accept",
|
|
836
|
+
content: {values: {company: "Acme Corp", notify: false, seats: 12}},
|
|
837
|
+
},
|
|
838
|
+
toolCallId: "call_1",
|
|
839
|
+
});
|
|
840
|
+
});
|
|
841
|
+
|
|
842
|
+
it("sends a date typed into the date field as YYYY-MM-DD", async () => {
|
|
843
|
+
const onSubmit = mock(async (_submission: AskSubmission) => {});
|
|
844
|
+
const card = renderCard({ask: pendingForm(INVOICE_INPUT), onSubmit});
|
|
845
|
+
const start = within(card.getByTestId("ask-card-form-field-start"));
|
|
846
|
+
|
|
847
|
+
typeInto(card, "ask-card-field-company", "Acme");
|
|
848
|
+
act(() => {
|
|
849
|
+
fireEvent.changeText(start.getByPlaceholderText("MM"), "10");
|
|
850
|
+
fireEvent.changeText(start.getByPlaceholderText("DD"), "01");
|
|
851
|
+
fireEvent.changeText(start.getByPlaceholderText("YYYY"), "2026");
|
|
852
|
+
});
|
|
853
|
+
act(() => {
|
|
854
|
+
fireEvent(start.getByPlaceholderText("YYYY"), "blur");
|
|
855
|
+
});
|
|
856
|
+
await press(card.getByTestId("ask-card-submit"));
|
|
857
|
+
|
|
858
|
+
assert.deepEqual(onSubmit.mock.calls[0]?.[0]?.response, {
|
|
859
|
+
action: "accept",
|
|
860
|
+
content: {values: {company: "Acme", notify: true, start: "2026-10-01"}},
|
|
861
|
+
});
|
|
862
|
+
});
|
|
863
|
+
|
|
864
|
+
it("shows why a field is invalid once the user edits it, and keeps Submit disabled", () => {
|
|
865
|
+
const card = renderCard({ask: pendingForm(INVOICE_INPUT)});
|
|
866
|
+
assert.isNull(card.queryByText("This field is required."));
|
|
867
|
+
|
|
868
|
+
typeInto(card, "ask-card-field-company", "Acme");
|
|
869
|
+
typeInto(card, "ask-card-field-seats", "900");
|
|
870
|
+
assert.isOk(card.getByText("Enter a number from 1 to 500."));
|
|
871
|
+
assert.isTrue(isDisabled(card.getByTestId("ask-card-submit")));
|
|
872
|
+
|
|
873
|
+
typeInto(card, "ask-card-field-seats", "1.5");
|
|
874
|
+
assert.isOk(card.getByText("Enter a whole number."));
|
|
875
|
+
typeInto(card, "ask-card-field-company", " ");
|
|
876
|
+
assert.isOk(card.getByText("This field is required."));
|
|
877
|
+
});
|
|
878
|
+
|
|
879
|
+
it("starts from the defaults and sends every field type in its answer format", async () => {
|
|
880
|
+
const onSubmit = mock(async (_submission: AskSubmission) => {});
|
|
881
|
+
const card = renderCard({ask: pendingForm(DEFAULTS_INPUT), onSubmit});
|
|
882
|
+
assert.isTrue(isDisabled(card.getByTestId("ask-card-submit")));
|
|
883
|
+
|
|
884
|
+
typeInto(card, "ask-card-field-phone", "(415) 555-2671");
|
|
885
|
+
typeInto(card, "ask-card-field-email", "ada@example.com");
|
|
886
|
+
assert.isFalse(isDisabled(card.getByTestId("ask-card-submit")));
|
|
887
|
+
await press(card.getByTestId("ask-card-submit"));
|
|
888
|
+
|
|
889
|
+
assert.deepEqual(onSubmit.mock.calls[0]?.[0]?.response, {
|
|
890
|
+
action: "accept",
|
|
891
|
+
content: {
|
|
892
|
+
values: {
|
|
893
|
+
channels: ["email"],
|
|
894
|
+
email: "ada@example.com",
|
|
895
|
+
meeting: "2026-10-01T09:30:00Z",
|
|
896
|
+
notes: "Ring twice.",
|
|
897
|
+
phone: "+14155552671",
|
|
898
|
+
reminder: "09:30",
|
|
899
|
+
shipping: "express",
|
|
900
|
+
site: "https://example.com",
|
|
901
|
+
},
|
|
902
|
+
},
|
|
903
|
+
});
|
|
904
|
+
});
|
|
905
|
+
|
|
906
|
+
it("keeps Submit disabled while the date holds an unfinished entry, and sends it once complete", async () => {
|
|
907
|
+
const onSubmit = mock(async (_submission: AskSubmission) => {});
|
|
908
|
+
const card = renderCard({ask: pendingForm(INVOICE_INPUT), onSubmit});
|
|
909
|
+
const start = within(card.getByTestId("ask-card-form-field-start"));
|
|
910
|
+
const typeDate = (month: string, dayOfMonth: string, fullYear: string): void => {
|
|
911
|
+
act(() => {
|
|
912
|
+
fireEvent.changeText(start.getByPlaceholderText("MM"), month);
|
|
913
|
+
fireEvent.changeText(start.getByPlaceholderText("DD"), dayOfMonth);
|
|
914
|
+
fireEvent.changeText(start.getByPlaceholderText("YYYY"), fullYear);
|
|
915
|
+
});
|
|
916
|
+
act(() => {
|
|
917
|
+
fireEvent(start.getByPlaceholderText("YYYY"), "blur");
|
|
918
|
+
});
|
|
919
|
+
};
|
|
920
|
+
typeInto(card, "ask-card-field-company", "Acme");
|
|
921
|
+
assert.isFalse(isDisabled(card.getByTestId("ask-card-submit")));
|
|
922
|
+
|
|
923
|
+
typeDate("0", "5", "026");
|
|
924
|
+
assert.isOk(card.getByText("Enter a complete date, or clear it."));
|
|
925
|
+
assert.isTrue(isDisabled(card.getByTestId("ask-card-submit")));
|
|
926
|
+
|
|
927
|
+
typeDate("10", "15", "2026");
|
|
928
|
+
assert.isNull(card.queryByText("Enter a complete date, or clear it."));
|
|
929
|
+
await press(card.getByTestId("ask-card-submit"));
|
|
930
|
+
assert.deepEqual(onSubmit.mock.calls[0]?.[0]?.response, {
|
|
931
|
+
action: "accept",
|
|
932
|
+
content: {values: {company: "Acme", notify: true, start: "2026-10-15"}},
|
|
933
|
+
});
|
|
934
|
+
});
|
|
935
|
+
|
|
936
|
+
it("keeps Submit disabled after the user clears a datetime's hour", () => {
|
|
937
|
+
const card = renderCard({ask: pendingForm(DEFAULTS_INPUT)});
|
|
938
|
+
typeInto(card, "ask-card-field-email", "ada@example.com");
|
|
939
|
+
const meeting = within(card.getByTestId("ask-card-form-field-meeting"));
|
|
940
|
+
|
|
941
|
+
act(() => {
|
|
942
|
+
fireEvent.changeText(meeting.getByPlaceholderText("hh"), "");
|
|
943
|
+
});
|
|
944
|
+
assert.isOk(card.getByText("Enter a complete date and time, or clear it."));
|
|
945
|
+
assert.isTrue(isDisabled(card.getByTestId("ask-card-submit")));
|
|
946
|
+
});
|
|
947
|
+
|
|
948
|
+
it("keeps Submit disabled while number or phone text does not parse", () => {
|
|
949
|
+
const card = renderCard({ask: pendingForm(DEFAULTS_INPUT)});
|
|
950
|
+
typeInto(card, "ask-card-field-email", "ada@example.com");
|
|
951
|
+
assert.isFalse(isDisabled(card.getByTestId("ask-card-submit")));
|
|
952
|
+
|
|
953
|
+
typeInto(card, "ask-card-field-phone", "555-01");
|
|
954
|
+
assert.isOk(card.getByText("Enter a valid phone number."));
|
|
955
|
+
assert.isTrue(isDisabled(card.getByTestId("ask-card-submit")));
|
|
956
|
+
typeInto(card, "ask-card-field-phone", "");
|
|
957
|
+
|
|
958
|
+
const invoice = renderCard({ask: pendingForm(INVOICE_INPUT)});
|
|
959
|
+
typeInto(invoice, "ask-card-field-company", "Acme");
|
|
960
|
+
typeInto(invoice, "ask-card-field-seats", "12abc");
|
|
961
|
+
assert.isOk(invoice.getByText("Enter a whole number."));
|
|
962
|
+
assert.isTrue(isDisabled(invoice.getByTestId("ask-card-submit")));
|
|
963
|
+
});
|
|
964
|
+
|
|
965
|
+
it("drops the date only when the user clears every part of it", async () => {
|
|
966
|
+
const onSubmit = mock(async (_submission: AskSubmission) => {});
|
|
967
|
+
const card = renderCard({ask: pendingForm(INVOICE_INPUT), onSubmit});
|
|
968
|
+
const start = within(card.getByTestId("ask-card-form-field-start"));
|
|
969
|
+
typeInto(card, "ask-card-field-company", "Acme");
|
|
970
|
+
act(() => {
|
|
971
|
+
fireEvent.changeText(start.getByPlaceholderText("MM"), "10");
|
|
972
|
+
});
|
|
973
|
+
assert.isTrue(isDisabled(card.getByTestId("ask-card-submit")));
|
|
974
|
+
|
|
975
|
+
act(() => {
|
|
976
|
+
fireEvent.changeText(start.getByPlaceholderText("MM"), "");
|
|
977
|
+
});
|
|
978
|
+
assert.isNull(card.queryByText("Enter a complete date, or clear it."));
|
|
979
|
+
await press(card.getByTestId("ask-card-submit"));
|
|
980
|
+
assert.deepEqual(onSubmit.mock.calls[0]?.[0]?.response, {
|
|
981
|
+
action: "accept",
|
|
982
|
+
content: {values: {company: "Acme", notify: true}},
|
|
983
|
+
});
|
|
984
|
+
});
|
|
985
|
+
|
|
986
|
+
it("keeps Submit disabled while a time or datetime holds an unfinished entry", async () => {
|
|
987
|
+
const onSubmit = mock(async (_submission: AskSubmission) => {});
|
|
988
|
+
const card = renderCard({ask: pendingForm(DEFAULTS_INPUT), onSubmit});
|
|
989
|
+
typeInto(card, "ask-card-field-email", "ada@example.com");
|
|
990
|
+
const reminder = within(card.getByTestId("ask-card-form-field-reminder"));
|
|
991
|
+
const meeting = within(card.getByTestId("ask-card-form-field-meeting"));
|
|
992
|
+
|
|
993
|
+
act(() => {
|
|
994
|
+
fireEvent.changeText(reminder.getByPlaceholderText("hh"), "");
|
|
995
|
+
});
|
|
996
|
+
assert.isOk(card.getByText("Enter a complete time, or clear it."));
|
|
997
|
+
act(() => {
|
|
998
|
+
fireEvent.changeText(meeting.getByPlaceholderText("MM"), "13");
|
|
999
|
+
});
|
|
1000
|
+
assert.isOk(card.getByText("Enter a complete date and time, or clear it."));
|
|
1001
|
+
assert.isTrue(isDisabled(card.getByTestId("ask-card-submit")));
|
|
1002
|
+
|
|
1003
|
+
act(() => {
|
|
1004
|
+
fireEvent.changeText(reminder.getByPlaceholderText("hh"), "10");
|
|
1005
|
+
fireEvent.changeText(meeting.getByPlaceholderText("MM"), "10");
|
|
1006
|
+
});
|
|
1007
|
+
act(() => {
|
|
1008
|
+
fireEvent(reminder.getByPlaceholderText("hh"), "blur");
|
|
1009
|
+
});
|
|
1010
|
+
assert.isNull(card.queryByText("Enter a complete time, or clear it."));
|
|
1011
|
+
assert.isNull(card.queryByText("Enter a complete date and time, or clear it."));
|
|
1012
|
+
await press(card.getByTestId("ask-card-submit"));
|
|
1013
|
+
assert.deepInclude(
|
|
1014
|
+
(onSubmit.mock.calls[0]?.[0]?.response as {content: {values: Record<string, unknown>}})
|
|
1015
|
+
?.content?.values ?? {},
|
|
1016
|
+
{meeting: "2026-10-01T09:30:00Z", reminder: "10:30"}
|
|
1017
|
+
);
|
|
1018
|
+
});
|
|
1019
|
+
|
|
1020
|
+
it("keeps Submit disabled when the hour of an on-the-hour time is cleared, and keeps the time", async () => {
|
|
1021
|
+
const onSubmit = mock(async (_submission: AskSubmission) => {});
|
|
1022
|
+
const input: FormAskInput = {
|
|
1023
|
+
fields: [{default: "09:00", id: "reminder", label: "Reminder", type: "time"}],
|
|
1024
|
+
prompt: "When should I remind you?",
|
|
1025
|
+
};
|
|
1026
|
+
const card = renderCard({ask: pendingForm(input), onSubmit});
|
|
1027
|
+
const reminder = within(card.getByTestId("ask-card-form-field-reminder"));
|
|
1028
|
+
assert.equal(reminder.getByPlaceholderText("mm").props.value, "00");
|
|
1029
|
+
|
|
1030
|
+
act(() => {
|
|
1031
|
+
fireEvent.changeText(reminder.getByPlaceholderText("hh"), "");
|
|
1032
|
+
});
|
|
1033
|
+
assert.isOk(card.getByText("Enter a complete time, or clear it."));
|
|
1034
|
+
assert.isTrue(isDisabled(card.getByTestId("ask-card-submit")));
|
|
1035
|
+
|
|
1036
|
+
act(() => {
|
|
1037
|
+
fireEvent.changeText(reminder.getByPlaceholderText("hh"), "11");
|
|
1038
|
+
});
|
|
1039
|
+
act(() => {
|
|
1040
|
+
fireEvent(reminder.getByPlaceholderText("hh"), "blur");
|
|
1041
|
+
});
|
|
1042
|
+
assert.isNull(card.queryByText("Enter a complete time, or clear it."));
|
|
1043
|
+
await press(card.getByTestId("ask-card-submit"));
|
|
1044
|
+
assert.deepEqual(onSubmit.mock.calls[0]?.[0]?.response, {
|
|
1045
|
+
action: "accept",
|
|
1046
|
+
content: {values: {reminder: "11:00"}},
|
|
1047
|
+
});
|
|
1048
|
+
});
|
|
1049
|
+
|
|
1050
|
+
it("clears a time and a datetime cleared minute first, so Submit sends neither", async () => {
|
|
1051
|
+
const onSubmit = mock(async (_submission: AskSubmission) => {});
|
|
1052
|
+
const input: FormAskInput = {
|
|
1053
|
+
fields: [
|
|
1054
|
+
{default: "09:30", id: "reminder", label: "Reminder", type: "time"},
|
|
1055
|
+
{default: "2026-10-01T13:30:00Z", id: "meeting", label: "Meeting", type: "datetime"},
|
|
1056
|
+
],
|
|
1057
|
+
prompt: "When should I remind you?",
|
|
1058
|
+
};
|
|
1059
|
+
const card = renderCard({ask: pendingForm(input), onSubmit});
|
|
1060
|
+
const segments = {
|
|
1061
|
+
meeting: ["mm", "MM", "DD", "YYYY", "hh"],
|
|
1062
|
+
reminder: ["mm", "hh"],
|
|
1063
|
+
};
|
|
1064
|
+
for (const [id, placeholders] of Object.entries(segments)) {
|
|
1065
|
+
const field = within(card.getByTestId(`ask-card-form-field-${id}`));
|
|
1066
|
+
for (const placeholder of placeholders) {
|
|
1067
|
+
act(() => {
|
|
1068
|
+
fireEvent.changeText(field.getByPlaceholderText(placeholder), "");
|
|
1069
|
+
});
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1073
|
+
assert.isNull(card.queryByText("Enter a complete time, or clear it."));
|
|
1074
|
+
assert.isNull(card.queryByText("Enter a complete date and time, or clear it."));
|
|
1075
|
+
await press(card.getByTestId("ask-card-submit"));
|
|
1076
|
+
assert.deepEqual(onSubmit.mock.calls[0]?.[0]?.response, {
|
|
1077
|
+
action: "accept",
|
|
1078
|
+
content: {values: {}},
|
|
1079
|
+
});
|
|
1080
|
+
});
|
|
1081
|
+
|
|
1082
|
+
it("keeps the shown time when the user picks another time zone", async () => {
|
|
1083
|
+
const onSubmit = mock(async (_submission: AskSubmission) => {});
|
|
1084
|
+
const card = renderCard({ask: pendingForm(DEFAULTS_INPUT), onSubmit});
|
|
1085
|
+
typeInto(card, "ask-card-field-email", "ada@example.com");
|
|
1086
|
+
for (const id of ["reminder", "meeting"]) {
|
|
1087
|
+
const picker = within(card.getByTestId(`ask-card-form-field-${id}`)).UNSAFE_getByType(
|
|
1088
|
+
TimezonePicker
|
|
1089
|
+
);
|
|
1090
|
+
act(() => {
|
|
1091
|
+
picker.props.onChange("America/Los_Angeles");
|
|
1092
|
+
});
|
|
1093
|
+
}
|
|
1094
|
+
await press(card.getByTestId("ask-card-submit"));
|
|
1095
|
+
|
|
1096
|
+
// Tests run in America/New_York, where the 09:30Z meeting shows as 05:30.
|
|
1097
|
+
assert.deepInclude(onSubmit.mock.calls[0]?.[0]?.response, {
|
|
1098
|
+
content: {
|
|
1099
|
+
values: {
|
|
1100
|
+
channels: ["email"],
|
|
1101
|
+
email: "ada@example.com",
|
|
1102
|
+
meeting: "2026-10-01T05:30:00-07:00",
|
|
1103
|
+
notes: "Ring twice.",
|
|
1104
|
+
reminder: "09:30",
|
|
1105
|
+
shipping: "express",
|
|
1106
|
+
site: "https://example.com",
|
|
1107
|
+
},
|
|
1108
|
+
},
|
|
1109
|
+
});
|
|
1110
|
+
});
|
|
1111
|
+
|
|
1112
|
+
it("shows server errors on their fields, and errors for no field below", () => {
|
|
1113
|
+
const card = renderCard({
|
|
1114
|
+
ask: pendingForm(INVOICE_INPUT),
|
|
1115
|
+
errors: [
|
|
1116
|
+
{
|
|
1117
|
+
code: "REQUIRED_FIELD",
|
|
1118
|
+
fix: 'Fill in "Company name" (content.values.company).',
|
|
1119
|
+
message: '"Company name" is required.',
|
|
1120
|
+
path: "content.values.company",
|
|
1121
|
+
},
|
|
1122
|
+
{
|
|
1123
|
+
code: "INVALID_DATE",
|
|
1124
|
+
fix: 'Write content.values.start as YYYY-MM-DD, such as "2026-10-01".',
|
|
1125
|
+
message: 'content.values.start "2026-02-30" is not a real date in YYYY-MM-DD.',
|
|
1126
|
+
path: "content.values.start",
|
|
1127
|
+
},
|
|
1128
|
+
{
|
|
1129
|
+
code: "UNKNOWN_KEY",
|
|
1130
|
+
fix: 'Remove "plan" from content.values.',
|
|
1131
|
+
message: '"plan" is not the id of any field in this form.',
|
|
1132
|
+
path: "content.values.plan",
|
|
1133
|
+
},
|
|
1134
|
+
],
|
|
1135
|
+
});
|
|
1136
|
+
|
|
1137
|
+
assert.isOk(card.getByText("This field is required."));
|
|
1138
|
+
assert.isOk(card.getByText("Enter a real date."));
|
|
1139
|
+
assert.isOk(
|
|
1140
|
+
within(card.getByTestId("ask-card-errors")).getByText(
|
|
1141
|
+
'"plan" is not the id of any field in this form.'
|
|
1142
|
+
)
|
|
1143
|
+
);
|
|
1144
|
+
});
|
|
1145
|
+
|
|
1146
|
+
it("declines with Skip, and hides Skip when the ask cannot be declined", async () => {
|
|
1147
|
+
const onSubmit = mock(async (_submission: AskSubmission) => {});
|
|
1148
|
+
const card = renderCard({ask: pendingForm(INVOICE_INPUT), onSubmit});
|
|
1149
|
+
await press(card.getByTestId("ask-card-button-skip"));
|
|
1150
|
+
assert.deepEqual(onSubmit.mock.calls[0]?.[0]?.response, {action: "decline"});
|
|
1151
|
+
|
|
1152
|
+
const required = renderCard({ask: pendingForm({...INVOICE_INPUT, allowDecline: false})});
|
|
1153
|
+
assert.isNull(required.queryByTestId("ask-card-button-skip"));
|
|
1154
|
+
});
|
|
1155
|
+
|
|
1156
|
+
it("disables the fields, Submit, and Skip when the host takes no answers", () => {
|
|
1157
|
+
const {getByTestId} = renderWithTheme(<AskCard ask={pendingForm(INVOICE_INPUT)} />);
|
|
1158
|
+
assert.isTrue(getByTestId("ask-card-field-company").props.readOnly);
|
|
1159
|
+
assert.isTrue(isDisabled(getByTestId("ask-card-submit")));
|
|
1160
|
+
assert.isTrue(isDisabled(getByTestId("ask-card-button-skip")));
|
|
1161
|
+
});
|
|
1162
|
+
|
|
1163
|
+
it("says a form with a default its field rejects cannot be shown", () => {
|
|
1164
|
+
const {getByTestId, queryByTestId} = renderCard({
|
|
1165
|
+
ask: pendingForm({
|
|
1166
|
+
fields: [{default: 0, id: "seats", label: "Seats", min: 1, type: "number"}],
|
|
1167
|
+
prompt: "How many?",
|
|
1168
|
+
}),
|
|
1169
|
+
});
|
|
1170
|
+
assert.isOk(getByTestId("ask-card-invalid"));
|
|
1171
|
+
assert.isNull(queryByTestId("ask-card-field-seats"));
|
|
1172
|
+
});
|
|
1173
|
+
|
|
1174
|
+
it("summarizes a sent form with the number of fields and a label: value list", () => {
|
|
1175
|
+
const {getByTestId, getByText, queryByTestId} = renderCard({
|
|
1176
|
+
ask: pendingForm(INVOICE_INPUT, {
|
|
1177
|
+
response: {
|
|
1178
|
+
action: "accept",
|
|
1179
|
+
content: {values: {company: "Acme", notify: true, region: "eu", start: "2026-10-01"}},
|
|
1180
|
+
},
|
|
1181
|
+
status: "answered",
|
|
1182
|
+
}),
|
|
1183
|
+
});
|
|
1184
|
+
|
|
1185
|
+
assert.isOk(getByText("You sent the form (4 fields)"));
|
|
1186
|
+
const answer = within(getByTestId("ask-card-answer"));
|
|
1187
|
+
assert.isOk(answer.getByText("Company name"));
|
|
1188
|
+
assert.isOk(answer.getByText("Acme"));
|
|
1189
|
+
assert.isOk(answer.getByText("Region"));
|
|
1190
|
+
assert.isOk(answer.getByText("EU"));
|
|
1191
|
+
assert.isOk(answer.getByText("Start date"));
|
|
1192
|
+
assert.isOk(answer.getByText("Oct 1, 2026"));
|
|
1193
|
+
assert.isOk(answer.getByText("Email me the invoice"));
|
|
1194
|
+
assert.isOk(answer.getByText("Yes"));
|
|
1195
|
+
assert.isNull(answer.queryByText("Seats"));
|
|
1196
|
+
assert.isNull(queryByTestId("ask-card-field-company"));
|
|
1197
|
+
});
|
|
1198
|
+
|
|
1199
|
+
it("summarizes a skipped form without the answer list", () => {
|
|
1200
|
+
const {getByText, queryByTestId} = renderCard({
|
|
1201
|
+
ask: pendingForm(INVOICE_INPUT, {response: {action: "decline"}, status: "answered"}),
|
|
1202
|
+
});
|
|
1203
|
+
assert.isOk(getByText("You skipped this question."));
|
|
1204
|
+
assert.isNull(queryByTestId("ask-card-answer"));
|
|
1205
|
+
});
|
|
1206
|
+
});
|
|
1207
|
+
|
|
1208
|
+
it("lets every button wrap a long label to fit a narrow chat instead of overflowing it", () => {
|
|
1209
|
+
const quickReplies = renderCard({ask: pendingAsk(PLAN_INPUT)}).getAllByTestId(
|
|
1210
|
+
/^ask-card-button-/
|
|
1211
|
+
);
|
|
1212
|
+
const form = renderCard({ask: pendingAsk(REGION_INPUT)});
|
|
1213
|
+
const buttons = [
|
|
1214
|
+
...quickReplies,
|
|
1215
|
+
form.getByTestId("ask-card-submit"),
|
|
1216
|
+
form.getByTestId("ask-card-button-skip"),
|
|
1217
|
+
];
|
|
1218
|
+
|
|
1219
|
+
assert.lengthOf(buttons, 6);
|
|
1220
|
+
for (const button of buttons) {
|
|
1221
|
+
assert.include(button.props.style, {maxWidth: "100%"});
|
|
1222
|
+
}
|
|
1223
|
+
});
|
|
1224
|
+
|
|
1225
|
+
it("shows errors for the last answer inline", () => {
|
|
1226
|
+
const {getByTestId, getByText} = renderCard({
|
|
1227
|
+
ask: pendingAsk(REGION_INPUT),
|
|
1228
|
+
errors: [
|
|
1229
|
+
{
|
|
1230
|
+
code: "OPTION_NOT_OFFERED",
|
|
1231
|
+
fix: "Use the id of one of the ask's options.",
|
|
1232
|
+
message: '"north" is not one of the offered options.',
|
|
1233
|
+
path: "content.selected[0]",
|
|
1234
|
+
},
|
|
1235
|
+
],
|
|
1236
|
+
});
|
|
1237
|
+
assert.isOk(getByTestId("ask-card-errors"));
|
|
1238
|
+
assert.isOk(getByText('"north" is not one of the offered options.'));
|
|
1239
|
+
});
|
|
1240
|
+
|
|
1241
|
+
it("shows the pressed button loading and blocks other answers until the host finishes", async () => {
|
|
1242
|
+
const pending = deferred();
|
|
1243
|
+
const onSubmit = mock((_submission: AskSubmission) => pending.promise);
|
|
1244
|
+
const {getByTestId} = renderCard({ask: pendingAsk(PLAN_INPUT), onSubmit});
|
|
1245
|
+
|
|
1246
|
+
await press(getByTestId("ask-card-button-option:team"));
|
|
1247
|
+
const spinners = getByTestId("ask-card-button-option:team").findAll(
|
|
1248
|
+
(node) => node.type === "ActivityIndicator"
|
|
1249
|
+
);
|
|
1250
|
+
assert.lengthOf(spinners, 1);
|
|
1251
|
+
assert.isTrue(isDisabled(getByTestId("ask-card-button-option:team")));
|
|
1252
|
+
assert.isTrue(isDisabled(getByTestId("ask-card-button-option:starter")));
|
|
1253
|
+
assert.isTrue(isDisabled(getByTestId("ask-card-button-skip")));
|
|
1254
|
+
await press(getByTestId("ask-card-button-option:starter"));
|
|
1255
|
+
assert.lengthOf(onSubmit.mock.calls, 1);
|
|
1256
|
+
|
|
1257
|
+
await act(async () => {
|
|
1258
|
+
pending.resolve();
|
|
1259
|
+
await pending.promise;
|
|
1260
|
+
});
|
|
1261
|
+
assert.isFalse(isDisabled(getByTestId("ask-card-button-option:starter")));
|
|
1262
|
+
});
|
|
1263
|
+
|
|
1264
|
+
it("stays answerable when the host's submit fails", async () => {
|
|
1265
|
+
const warn = spyOn(console, "warn").mockImplementation(() => {});
|
|
1266
|
+
const onSubmit = mock(async (_submission: AskSubmission) => {
|
|
1267
|
+
throw new Error("network down");
|
|
1268
|
+
});
|
|
1269
|
+
const {getByTestId} = renderCard({ask: pendingAsk(PLAN_INPUT), onSubmit});
|
|
1270
|
+
|
|
1271
|
+
await press(getByTestId("ask-card-button-option:team"));
|
|
1272
|
+
|
|
1273
|
+
assert.lengthOf(warn.mock.calls, 1);
|
|
1274
|
+
assert.isFalse(isDisabled(getByTestId("ask-card-button-option:team")));
|
|
1275
|
+
});
|
|
1276
|
+
|
|
1277
|
+
it("says the answer was not sent when the host's submit fails, until the next try", async () => {
|
|
1278
|
+
spyOn(console, "warn").mockImplementation(() => {});
|
|
1279
|
+
const retry = deferred();
|
|
1280
|
+
const onSubmit = mock(async (_submission: AskSubmission) => {});
|
|
1281
|
+
onSubmit.mockImplementationOnce(async () => {
|
|
1282
|
+
throw new Error("network down");
|
|
1283
|
+
});
|
|
1284
|
+
onSubmit.mockImplementationOnce(() => retry.promise);
|
|
1285
|
+
const {getByTestId, queryByTestId} = renderCard({ask: pendingAsk(PLAN_INPUT), onSubmit});
|
|
1286
|
+
|
|
1287
|
+
await press(getByTestId("ask-card-button-option:team"));
|
|
1288
|
+
|
|
1289
|
+
assert.isOk(
|
|
1290
|
+
within(getByTestId("ask-card-submit-error")).getByText(
|
|
1291
|
+
"Your answer could not be sent. Try again."
|
|
1292
|
+
)
|
|
1293
|
+
);
|
|
1294
|
+
await press(getByTestId("ask-card-button-option:starter"));
|
|
1295
|
+
assert.isNull(queryByTestId("ask-card-submit-error"));
|
|
1296
|
+
assert.lengthOf(onSubmit.mock.calls, 2);
|
|
1297
|
+
await act(async () => {
|
|
1298
|
+
retry.resolve();
|
|
1299
|
+
});
|
|
1300
|
+
assert.isNull(queryByTestId("ask-card-submit-error"));
|
|
1301
|
+
});
|
|
1302
|
+
|
|
1303
|
+
it("shows the question as an accessible header the host can focus through promptRef", () => {
|
|
1304
|
+
const promptRef = createRef<NativeText>();
|
|
1305
|
+
const prompt = {focus: (): void => {}};
|
|
1306
|
+
const {getByRole} = render(
|
|
1307
|
+
<AskCard ask={pendingAsk(PLAN_INPUT)} onSubmit={async () => {}} promptRef={promptRef} />,
|
|
1308
|
+
{
|
|
1309
|
+
createNodeMock: (element) => (element.props.accessibilityRole === "header" ? prompt : null),
|
|
1310
|
+
wrapper: ThemeProvider,
|
|
1311
|
+
}
|
|
1312
|
+
);
|
|
1313
|
+
|
|
1314
|
+
assert.isOk(getByRole("header", {name: "Which plan should I set up for your workspace?"}));
|
|
1315
|
+
assert.strictEqual(promptRef.current, prompt as unknown as NativeText);
|
|
1316
|
+
});
|
|
1317
|
+
|
|
1318
|
+
it("disables its controls when the host takes no answers", () => {
|
|
1319
|
+
const {getByTestId} = renderWithTheme(<AskCard ask={pendingAsk(PLAN_INPUT)} />);
|
|
1320
|
+
assert.isTrue(isDisabled(getByTestId("ask-card-button-option:team")));
|
|
1321
|
+
assert.isTrue(isDisabled(getByTestId("ask-card-button-skip")));
|
|
1322
|
+
});
|
|
1323
|
+
|
|
1324
|
+
it("lists radio options as plain text when the host takes no answers", () => {
|
|
1325
|
+
const {getByTestId, getByText, queryByLabelText} = renderWithTheme(
|
|
1326
|
+
<AskCard ask={pendingAsk(REGION_INPUT)} />
|
|
1327
|
+
);
|
|
1328
|
+
|
|
1329
|
+
const options = getByTestId("ask-card-options");
|
|
1330
|
+
assert.isOk(getByText("West — Oregon"));
|
|
1331
|
+
assert.isNull(queryByLabelText("West — Oregon"));
|
|
1332
|
+
assert.lengthOf(
|
|
1333
|
+
options.findAll((node) => typeof node.props.onPress === "function"),
|
|
1334
|
+
0
|
|
1335
|
+
);
|
|
1336
|
+
assert.isTrue(isDisabled(getByTestId("ask-card-submit")));
|
|
1337
|
+
assert.isTrue(isDisabled(getByTestId("ask-card-button-skip")));
|
|
1338
|
+
});
|
|
1339
|
+
|
|
1340
|
+
it("summarizes an answered ask in one line without controls", () => {
|
|
1341
|
+
const {getByTestId, getByText, queryByTestId} = renderCard({
|
|
1342
|
+
ask: pendingAsk(PLAN_INPUT, {
|
|
1343
|
+
response: {action: "accept", content: {selected: ["team"]}},
|
|
1344
|
+
status: "answered",
|
|
1345
|
+
}),
|
|
1346
|
+
});
|
|
1347
|
+
assert.isOk(getByTestId("ask-card-summary"));
|
|
1348
|
+
assert.isOk(getByText("You chose: Team"));
|
|
1349
|
+
assert.isNull(queryByTestId("ask-card-quick-replies"));
|
|
1350
|
+
assert.isNull(queryByTestId("ask-card-button-option:team"));
|
|
1351
|
+
});
|
|
1352
|
+
|
|
1353
|
+
it("summarizes a cancelled ask", () => {
|
|
1354
|
+
const {getByText} = renderCard({
|
|
1355
|
+
ask: pendingAsk(PLAN_INPUT, {
|
|
1356
|
+
response: {action: "cancel", reason: "user_sent_message"},
|
|
1357
|
+
status: "cancelled",
|
|
1358
|
+
}),
|
|
1359
|
+
});
|
|
1360
|
+
assert.isOk(getByText("Not answered: you sent a message instead."));
|
|
1361
|
+
});
|
|
1362
|
+
|
|
1363
|
+
it("says a malformed ask cannot be shown instead of rendering controls", () => {
|
|
1364
|
+
const input = {
|
|
1365
|
+
...REGION_INPUT,
|
|
1366
|
+
options: [
|
|
1367
|
+
{id: "same", label: "One"},
|
|
1368
|
+
{id: "same", label: "Two"},
|
|
1369
|
+
],
|
|
1370
|
+
};
|
|
1371
|
+
const {getByTestId, queryByTestId} = renderCard({ask: pendingAsk(input)});
|
|
1372
|
+
assert.isOk(getByTestId("ask-card-invalid"));
|
|
1373
|
+
assert.isNull(queryByTestId("ask-card-submit"));
|
|
1374
|
+
});
|
|
1375
|
+
});
|
|
1376
|
+
|
|
1377
|
+
describe("AskCard with a saved ask the wire left incomplete", () => {
|
|
1378
|
+
const ANSWERED = "You answered this question.";
|
|
1379
|
+
const kinds: Array<{content: Record<string, unknown>; input: unknown; kind: ChatAsk["kind"]}> = [
|
|
1380
|
+
{content: {selected: ["team"]}, input: PLAN_INPUT, kind: "choice"},
|
|
1381
|
+
{content: {confirmed: true}, input: REPORT_INPUT, kind: "confirm"},
|
|
1382
|
+
{content: {changed: true, markdown: DRAFT}, input: DRAFT_INPUT, kind: "markdown"},
|
|
1383
|
+
{content: {values: {amount: 120}}, input: INVOICE_INPUT, kind: "form"},
|
|
1384
|
+
{content: {files: []}, input: {prompt: "Upload the receipt."}, kind: "files"},
|
|
1385
|
+
];
|
|
1386
|
+
const savedAsk = (state: Record<string, unknown>): ChatAsk =>
|
|
1387
|
+
({status: "answered", toolCallId: "call_1", ...state}) as unknown as ChatAsk;
|
|
1388
|
+
|
|
1389
|
+
for (const {content, input, kind} of kinds) {
|
|
1390
|
+
it(`shows the generic line for a ${kind} answered with empty input`, () => {
|
|
1391
|
+
const {getByTestId} = renderCard({
|
|
1392
|
+
ask: savedAsk({input: {}, kind, response: {action: "accept", content}}),
|
|
1393
|
+
});
|
|
1394
|
+
assert.isOk(within(getByTestId("ask-card-summary")).getByText(ANSWERED));
|
|
1395
|
+
});
|
|
1396
|
+
|
|
1397
|
+
it(`shows the generic line for a ${kind} answered with no input`, () => {
|
|
1398
|
+
const {getByTestId} = renderCard({
|
|
1399
|
+
ask: savedAsk({kind, response: {action: "accept", content}}),
|
|
1400
|
+
});
|
|
1401
|
+
assert.isOk(within(getByTestId("ask-card-summary")).getByText(ANSWERED));
|
|
1402
|
+
});
|
|
1403
|
+
|
|
1404
|
+
it(`shows the generic line for a ${kind} accepted with no content`, () => {
|
|
1405
|
+
const {getByTestId, queryByTestId} = renderCard({
|
|
1406
|
+
ask: savedAsk({input, kind, response: {action: "accept"}}),
|
|
1407
|
+
});
|
|
1408
|
+
assert.isOk(within(getByTestId("ask-card-summary")).getByText(ANSWERED));
|
|
1409
|
+
assert.isNull(queryByTestId("ask-card-answer"));
|
|
1410
|
+
});
|
|
1411
|
+
|
|
1412
|
+
it(`shows the generic line for a ${kind} accepted with content that is not an object`, () => {
|
|
1413
|
+
const {getByTestId} = renderCard({
|
|
1414
|
+
ask: savedAsk({input, kind, response: {action: "accept", content: "yes"}}),
|
|
1415
|
+
});
|
|
1416
|
+
assert.isOk(within(getByTestId("ask-card-summary")).getByText(ANSWERED));
|
|
1417
|
+
});
|
|
1418
|
+
|
|
1419
|
+
it(`shows the cancelled line for a ${kind} cancelled with no input and an odd reason`, () => {
|
|
1420
|
+
const {getByTestId} = renderCard({
|
|
1421
|
+
ask: savedAsk({kind, response: {action: "cancel", reason: 5}, status: "cancelled"}),
|
|
1422
|
+
});
|
|
1423
|
+
assert.isOk(
|
|
1424
|
+
within(getByTestId("ask-card-summary")).getByText("This question was cancelled.")
|
|
1425
|
+
);
|
|
1426
|
+
});
|
|
1427
|
+
}
|
|
1428
|
+
});
|