@terreno/ui 58.0.5 → 58.1.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/CHANGELOG.md +58 -0
- package/dist/AiSuggestionBox.js +3 -3
- package/dist/AiSuggestionBox.js.map +1 -1
- package/dist/Common.d.ts +38 -0
- package/dist/Common.d.ts.map +1 -1
- package/dist/Common.js.map +1 -1
- package/dist/DataTable.d.ts.map +1 -1
- package/dist/DataTable.js +3 -1
- package/dist/DataTable.js.map +1 -1
- package/dist/DraggableList.d.ts +7 -4
- package/dist/DraggableList.d.ts.map +1 -1
- package/dist/DraggableList.js +206 -4
- package/dist/DraggableList.js.map +1 -1
- package/dist/FeedbackCommentField.d.ts +8 -0
- package/dist/FeedbackCommentField.d.ts.map +1 -0
- package/dist/FeedbackCommentField.js +39 -0
- package/dist/FeedbackCommentField.js.map +1 -0
- package/dist/GPTChat.d.ts +15 -1
- package/dist/GPTChat.d.ts.map +1 -1
- package/dist/GPTChat.js +148 -43
- package/dist/GPTChat.js.map +1 -1
- package/dist/LabeledCheckBox.d.ts +3 -2
- package/dist/LabeledCheckBox.d.ts.map +1 -1
- package/dist/LabeledCheckBox.js +3 -2
- package/dist/LabeledCheckBox.js.map +1 -1
- package/dist/TextField.d.ts.map +1 -1
- package/dist/TextField.js +10 -7
- package/dist/TextField.js.map +1 -1
- package/dist/ThumbsUpDownButtons.d.ts +9 -0
- package/dist/ThumbsUpDownButtons.d.ts.map +1 -0
- package/dist/ThumbsUpDownButtons.js +60 -0
- package/dist/ThumbsUpDownButtons.js.map +1 -0
- package/dist/ThumbsUpDownFeedback.d.ts +3 -2
- package/dist/ThumbsUpDownFeedback.d.ts.map +1 -1
- package/dist/ThumbsUpDownFeedback.js +10 -52
- package/dist/ThumbsUpDownFeedback.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/AiSuggestionBox.tsx +3 -3
- package/src/Common.ts +39 -0
- package/src/DataTable.test.tsx +31 -0
- package/src/DataTable.tsx +3 -1
- package/src/DraggableList.test.tsx +141 -1
- package/src/DraggableList.tsx +359 -6
- package/src/FeedbackCommentField.test.tsx +107 -0
- package/src/FeedbackCommentField.tsx +74 -0
- package/src/GPTChat.test.tsx +327 -14
- package/src/GPTChat.tsx +463 -259
- package/src/LabeledCheckBox.tsx +3 -2
- package/src/TextField.test.tsx +126 -1
- package/src/TextField.tsx +13 -7
- package/src/ThumbsUpDownButtons.tsx +120 -0
- package/src/ThumbsUpDownFeedback.test.tsx +154 -1
- package/src/ThumbsUpDownFeedback.tsx +26 -101
- package/src/__snapshots__/DataTable.test.tsx.snap +28 -28
- package/src/index.tsx +1 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import {type FC, useCallback, useState} from "react";
|
|
2
|
+
|
|
3
|
+
import {Box} from "./Box";
|
|
4
|
+
import {Button} from "./Button";
|
|
5
|
+
import type {FeedbackCommentFieldProps} from "./Common";
|
|
6
|
+
import {Text} from "./Text";
|
|
7
|
+
import {TextField} from "./TextField";
|
|
8
|
+
|
|
9
|
+
const DEFAULT_PLACEHOLDER = "Tell us more (optional)";
|
|
10
|
+
const SENT_TEXT = "Thanks for the feedback";
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* An optional free-text comment under a rating, e.g. "what went wrong?" after a thumbs down.
|
|
14
|
+
* Sends the trimmed text once, then shows a short thank-you in place of the field.
|
|
15
|
+
*/
|
|
16
|
+
export const FeedbackCommentField: FC<FeedbackCommentFieldProps> = ({
|
|
17
|
+
onSubmit,
|
|
18
|
+
placeholder = DEFAULT_PLACEHOLDER,
|
|
19
|
+
sentComment,
|
|
20
|
+
testID,
|
|
21
|
+
}) => {
|
|
22
|
+
const [text, setText] = useState("");
|
|
23
|
+
const [isSending, setIsSending] = useState(false);
|
|
24
|
+
const [isSent, setIsSent] = useState(false);
|
|
25
|
+
const trimmed = text.trim();
|
|
26
|
+
|
|
27
|
+
const handleSend = useCallback(async (): Promise<void> => {
|
|
28
|
+
if (!trimmed || isSending) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
setIsSending(true);
|
|
32
|
+
try {
|
|
33
|
+
await onSubmit(trimmed);
|
|
34
|
+
setIsSent(true);
|
|
35
|
+
} catch (error) {
|
|
36
|
+
console.warn("Failed to send feedback comment", error);
|
|
37
|
+
} finally {
|
|
38
|
+
setIsSending(false);
|
|
39
|
+
}
|
|
40
|
+
}, [isSending, onSubmit, trimmed]);
|
|
41
|
+
|
|
42
|
+
if (isSent || sentComment) {
|
|
43
|
+
return (
|
|
44
|
+
<Box testID={testID ? `${testID}-sent` : undefined}>
|
|
45
|
+
<Text color="secondaryLight" size="sm">
|
|
46
|
+
{SENT_TEXT}
|
|
47
|
+
</Text>
|
|
48
|
+
</Box>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return (
|
|
53
|
+
<Box gap={2} testID={testID}>
|
|
54
|
+
<TextField
|
|
55
|
+
multiline
|
|
56
|
+
onChange={setText}
|
|
57
|
+
placeholder={placeholder}
|
|
58
|
+
rows={2}
|
|
59
|
+
testID={testID ? `${testID}-input` : undefined}
|
|
60
|
+
value={text}
|
|
61
|
+
/>
|
|
62
|
+
<Box alignItems="end">
|
|
63
|
+
<Button
|
|
64
|
+
disabled={!trimmed || isSending}
|
|
65
|
+
loading={isSending}
|
|
66
|
+
onClick={handleSend}
|
|
67
|
+
testID={testID ? `${testID}-send` : undefined}
|
|
68
|
+
text="Send"
|
|
69
|
+
variant="secondary"
|
|
70
|
+
/>
|
|
71
|
+
</Box>
|
|
72
|
+
</Box>
|
|
73
|
+
);
|
|
74
|
+
};
|
package/src/GPTChat.test.tsx
CHANGED
|
@@ -9,8 +9,10 @@ import {
|
|
|
9
9
|
ActivityIndicator,
|
|
10
10
|
Platform,
|
|
11
11
|
Pressable,
|
|
12
|
+
type ScaledSize,
|
|
12
13
|
ScrollView,
|
|
13
14
|
type TextProps,
|
|
15
|
+
useWindowDimensions,
|
|
14
16
|
} from "react-native";
|
|
15
17
|
|
|
16
18
|
import type {AskSubmission, ChatAsk, ChatAskState} from "./asks/askTypes";
|
|
@@ -50,6 +52,12 @@ afterAll(() => {
|
|
|
50
52
|
mock.module("./IconButton", () => ({IconButton: mock(() => null)}));
|
|
51
53
|
});
|
|
52
54
|
|
|
55
|
+
// The clipboard mocks come from bunSetup.ts and are shared, so later files must not see these calls.
|
|
56
|
+
afterEach(() => {
|
|
57
|
+
mockedSetImageAsync.mockClear();
|
|
58
|
+
mockedSetStringAsync.mockClear();
|
|
59
|
+
});
|
|
60
|
+
|
|
53
61
|
// Box and IconButton presses run through an async haptic call, so state updates land in a
|
|
54
62
|
// microtask after the event.
|
|
55
63
|
const press = async (element: Parameters<typeof fireEvent.press>[0]): Promise<void> => {
|
|
@@ -330,22 +338,103 @@ describe("GPTChat", () => {
|
|
|
330
338
|
assert.isOk(getByText("0/1 MCP"));
|
|
331
339
|
});
|
|
332
340
|
|
|
333
|
-
it("lists
|
|
334
|
-
const {getByTestId, getByText} = renderChat({
|
|
335
|
-
mcpTools: [
|
|
341
|
+
it("lists each tool, what it does, and the arguments it accepts", async () => {
|
|
342
|
+
const {getByTestId, getByText, queryByText} = renderChat({
|
|
343
|
+
mcpTools: [
|
|
344
|
+
{
|
|
345
|
+
description: "Reads files",
|
|
346
|
+
inputSchema: {
|
|
347
|
+
properties: {
|
|
348
|
+
path: {description: "File to read", type: "string"},
|
|
349
|
+
},
|
|
350
|
+
required: ["path"],
|
|
351
|
+
type: "object",
|
|
352
|
+
},
|
|
353
|
+
name: "readFile",
|
|
354
|
+
},
|
|
355
|
+
{name: "writeFile"},
|
|
356
|
+
],
|
|
336
357
|
});
|
|
337
358
|
|
|
338
359
|
await press(getByTestId("gpt-tools-button"));
|
|
339
360
|
|
|
361
|
+
assert.isOk(getByText(/assistant can call these tools/));
|
|
340
362
|
assert.isOk(getByText("readFile"));
|
|
341
363
|
assert.isOk(getByText("Reads files"));
|
|
342
364
|
assert.isOk(getByText("writeFile"));
|
|
365
|
+
assert.isNull(queryByText("path (string) · required"));
|
|
366
|
+
assert.isNull(queryByText("None. The assistant calls it with an empty input."));
|
|
367
|
+
|
|
368
|
+
await press(getByTestId("gpt-tools-arguments-toggle"));
|
|
369
|
+
|
|
370
|
+
assert.isOk(getByText("path (string) · required"));
|
|
371
|
+
assert.isOk(getByText("File to read"));
|
|
372
|
+
assert.isOk(getByText("None. The assistant calls it with an empty input."));
|
|
343
373
|
});
|
|
344
374
|
|
|
345
|
-
it("
|
|
346
|
-
const
|
|
375
|
+
it("toggles arguments with Space and keeps the list inside a short window", async () => {
|
|
376
|
+
const setWindow = useWindowDimensions as (() => ScaledSize) & {
|
|
377
|
+
mockImplementation: (impl: () => ScaledSize) => void;
|
|
378
|
+
};
|
|
379
|
+
setWindow.mockImplementation(() => ({fontScale: 1, height: 500, scale: 2, width: 375}));
|
|
380
|
+
try {
|
|
381
|
+
const {getByTestId, getByText} = renderChat({
|
|
382
|
+
mcpTools: [
|
|
383
|
+
{
|
|
384
|
+
inputSchema: {
|
|
385
|
+
properties: {path: {type: "string"}},
|
|
386
|
+
required: ["path"],
|
|
387
|
+
type: "object",
|
|
388
|
+
},
|
|
389
|
+
name: "readFile",
|
|
390
|
+
},
|
|
391
|
+
],
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
await press(getByTestId("gpt-tools-button"));
|
|
395
|
+
assert.equal(getByTestId("gpt-tools-scroll").props.style.maxHeight, 280);
|
|
396
|
+
fireEvent(getByTestId("gpt-tools-arguments-toggle"), "keyDown", {
|
|
397
|
+
key: " ",
|
|
398
|
+
preventDefault: () => {},
|
|
399
|
+
});
|
|
400
|
+
assert.isOk(getByText("path (string) · required"));
|
|
401
|
+
} finally {
|
|
402
|
+
setWindow.mockImplementation(() => ({fontScale: 1, height: 812, scale: 2, width: 375}));
|
|
403
|
+
}
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
it("reopens the tools list with arguments hidden", async () => {
|
|
407
|
+
const {getByLabelText, getByTestId, queryByText} = renderChat({
|
|
408
|
+
mcpTools: [
|
|
409
|
+
{
|
|
410
|
+
inputSchema: {properties: {path: {type: "string"}}, required: ["path"], type: "object"},
|
|
411
|
+
name: "readFile",
|
|
412
|
+
},
|
|
413
|
+
],
|
|
414
|
+
});
|
|
415
|
+
|
|
416
|
+
await press(getByTestId("gpt-tools-button"));
|
|
417
|
+
await press(getByTestId("gpt-tools-arguments-toggle"));
|
|
418
|
+
assert.isOk(queryByText("path (string) · required"));
|
|
419
|
+
|
|
420
|
+
await press(getByLabelText("Close modal"));
|
|
421
|
+
await press(getByTestId("gpt-tools-button"));
|
|
422
|
+
|
|
423
|
+
assert.isNull(queryByText("path (string) · required"));
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
it("renders no action row for an empty assistant message", () => {
|
|
427
|
+
const {queryByTestId} = renderChat({
|
|
428
|
+
currentMessages: [{content: " ", role: "assistant"}],
|
|
429
|
+
onRateFeedback: () => {},
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
assert.isNull(queryByTestId("gpt-message-actions-0"));
|
|
433
|
+
});
|
|
347
434
|
|
|
348
|
-
|
|
435
|
+
it("hides the tools button when no tools are published", () => {
|
|
436
|
+
assert.isNull(renderChat().queryByTestId("gpt-tools-button"));
|
|
437
|
+
assert.isNull(renderChat({mcpTools: []}).queryByTestId("gpt-composer-tools"));
|
|
349
438
|
});
|
|
350
439
|
|
|
351
440
|
it("omits the mascot when the consumer does not pass one", () => {
|
|
@@ -555,13 +644,43 @@ describe("GPTChat", () => {
|
|
|
555
644
|
];
|
|
556
645
|
const {getByLabelText, getByText} = renderChat({currentMessages: messages});
|
|
557
646
|
|
|
558
|
-
await press(getByLabelText("
|
|
559
|
-
await press(getByLabelText("
|
|
647
|
+
await press(getByLabelText("Tool: readFile"));
|
|
648
|
+
await press(getByLabelText("Tool: writeFile"));
|
|
560
649
|
|
|
561
650
|
assert.isOk(getByText("done"));
|
|
562
651
|
assert.isOk(getByText(/"ok": true/));
|
|
563
652
|
});
|
|
564
653
|
|
|
654
|
+
it("combines a tool call and its result into one scrolling row", async () => {
|
|
655
|
+
const longResult = `row\n${"patient\n".repeat(80)}`;
|
|
656
|
+
const messages: GPTChatMessage[] = [
|
|
657
|
+
{
|
|
658
|
+
content: "",
|
|
659
|
+
role: "tool-call",
|
|
660
|
+
toolCall: {args: {limit: 50}, toolCallId: "users-1", toolName: "users_list"},
|
|
661
|
+
},
|
|
662
|
+
{
|
|
663
|
+
content: "",
|
|
664
|
+
role: "tool-result",
|
|
665
|
+
toolResult: {result: longResult, toolCallId: "users-1", toolName: "users_list"},
|
|
666
|
+
},
|
|
667
|
+
];
|
|
668
|
+
const {getAllByLabelText, getByLabelText, getByTestId, getByText, queryByLabelText} =
|
|
669
|
+
renderChat({
|
|
670
|
+
currentMessages: messages,
|
|
671
|
+
});
|
|
672
|
+
|
|
673
|
+
assert.lengthOf(getAllByLabelText("Tool: users_list"), 1);
|
|
674
|
+
assert.isNull(queryByLabelText("Result: users_list"));
|
|
675
|
+
await press(getByLabelText("Tool: users_list"));
|
|
676
|
+
|
|
677
|
+
const body = getByTestId("gpt-tool-body-users-1");
|
|
678
|
+
const style = [body.props.style].flat(Infinity);
|
|
679
|
+
assert.isTrue(style.some((entry) => entry?.maxHeight === 240));
|
|
680
|
+
assert.isOk(getByText(/"limit": 50/));
|
|
681
|
+
assert.isOk(getByText(/patient/));
|
|
682
|
+
});
|
|
683
|
+
|
|
565
684
|
it("renders image and file content parts", () => {
|
|
566
685
|
const messages: GPTChatMessage[] = [
|
|
567
686
|
{
|
|
@@ -704,9 +823,10 @@ describe("GPTChat", () => {
|
|
|
704
823
|
assert.equal(mockedSetStringAsync.mock.calls.length, 0);
|
|
705
824
|
});
|
|
706
825
|
|
|
707
|
-
it("
|
|
826
|
+
it("keeps a single copy button when a reply includes text and an image", async () => {
|
|
827
|
+
mockedSetStringAsync.mockClear();
|
|
708
828
|
mockedSetImageAsync.mockClear();
|
|
709
|
-
const {getByTestId} = renderChat({
|
|
829
|
+
const {getByTestId, queryByTestId} = renderChat({
|
|
710
830
|
currentMessages: [
|
|
711
831
|
{
|
|
712
832
|
content: "Here you go",
|
|
@@ -716,9 +836,39 @@ describe("GPTChat", () => {
|
|
|
716
836
|
],
|
|
717
837
|
});
|
|
718
838
|
|
|
719
|
-
|
|
839
|
+
assert.isNull(queryByTestId("gpt-copy-image"));
|
|
840
|
+
await press(getByTestId("gpt-copy-msg-0"));
|
|
720
841
|
|
|
721
|
-
assert.deepEqual(
|
|
842
|
+
assert.deepEqual(mockedSetStringAsync.mock.calls, [["Here you go"]]);
|
|
843
|
+
assert.equal(mockedSetImageAsync.mock.calls.length, 0);
|
|
844
|
+
});
|
|
845
|
+
|
|
846
|
+
it("puts image copy and download on the same row as the ratings", () => {
|
|
847
|
+
const originalOS = Platform.OS;
|
|
848
|
+
Platform.OS = "web";
|
|
849
|
+
try {
|
|
850
|
+
const {getByTestId, queryByTestId} = renderChat({
|
|
851
|
+
currentMessages: [
|
|
852
|
+
{
|
|
853
|
+
content: "",
|
|
854
|
+
contentParts: [
|
|
855
|
+
{mimeType: "image/png", type: "image", url: "data:image/png;base64,AAAA"},
|
|
856
|
+
],
|
|
857
|
+
role: "assistant",
|
|
858
|
+
},
|
|
859
|
+
],
|
|
860
|
+
onRateFeedback: () => {},
|
|
861
|
+
});
|
|
862
|
+
const actions = getByTestId("gpt-message-actions-0");
|
|
863
|
+
|
|
864
|
+
assert.isOk(within(actions).getByTestId("gpt-copy-msg-0"));
|
|
865
|
+
assert.isOk(within(actions).getByTestId("gpt-download-image-0"));
|
|
866
|
+
assert.isOk(within(actions).getByTestId("gpt-rate-up-0"));
|
|
867
|
+
assert.isOk(within(actions).getByTestId("gpt-rate-down-0"));
|
|
868
|
+
assert.isNull(queryByTestId("gpt-copy-image"));
|
|
869
|
+
} finally {
|
|
870
|
+
Platform.OS = originalOS;
|
|
871
|
+
}
|
|
722
872
|
});
|
|
723
873
|
|
|
724
874
|
it("grows the composer up to a maximum height and resets after sending", async () => {
|
|
@@ -1307,7 +1457,7 @@ describe("GPTChat asks", () => {
|
|
|
1307
1457
|
});
|
|
1308
1458
|
|
|
1309
1459
|
it("still shows tool results that do not belong to an ask", () => {
|
|
1310
|
-
const {getByText} = renderChat({
|
|
1460
|
+
const {getByLabelText, getByText} = renderChat({
|
|
1311
1461
|
currentMessages: [
|
|
1312
1462
|
askMessage(planAsk({status: "answered"})),
|
|
1313
1463
|
askResultMessage({action: "decline"}),
|
|
@@ -1320,7 +1470,7 @@ describe("GPTChat asks", () => {
|
|
|
1320
1470
|
});
|
|
1321
1471
|
|
|
1322
1472
|
assert.isOk(getByText("You skipped this question."));
|
|
1323
|
-
assert.isOk(
|
|
1473
|
+
assert.isOk(getByLabelText("Tool: lookup"));
|
|
1324
1474
|
});
|
|
1325
1475
|
|
|
1326
1476
|
it("shows the errors for the matching ask inline", () => {
|
|
@@ -1726,3 +1876,166 @@ blocks:
|
|
|
1726
1876
|
assert.isNull(queryByText("The preview appears when this reply finishes."));
|
|
1727
1877
|
});
|
|
1728
1878
|
});
|
|
1879
|
+
|
|
1880
|
+
describe("GPTChat rating comments and copy signal", () => {
|
|
1881
|
+
// The clipboard mock is shared through the preload; leave it clean for later suites.
|
|
1882
|
+
afterEach(() => {
|
|
1883
|
+
mockedSetStringAsync.mockClear();
|
|
1884
|
+
mockedSetStringAsync.mockImplementation(async () => undefined);
|
|
1885
|
+
});
|
|
1886
|
+
|
|
1887
|
+
const ratedDown: GPTChatMessage[] = [
|
|
1888
|
+
{content: "It is Monday", rating: "down", role: "assistant"},
|
|
1889
|
+
];
|
|
1890
|
+
|
|
1891
|
+
it("shows the comment field for a message rated down and sends the comment with its index", async () => {
|
|
1892
|
+
const onRateComment = mock((_index: number, _comment: string) => {});
|
|
1893
|
+
const {getByTestId} = renderChat({
|
|
1894
|
+
currentMessages: ratedDown,
|
|
1895
|
+
onRateComment,
|
|
1896
|
+
onRateFeedback: () => {},
|
|
1897
|
+
});
|
|
1898
|
+
|
|
1899
|
+
fireEvent.changeText(getByTestId("gpt-rating-comment-0-input"), "Wrong date");
|
|
1900
|
+
await press(getByTestId("gpt-rating-comment-0-send"));
|
|
1901
|
+
|
|
1902
|
+
assert.deepEqual(onRateComment.mock.calls, [[0, "Wrong date"]]);
|
|
1903
|
+
});
|
|
1904
|
+
|
|
1905
|
+
it("shows the comment field for a message rated up", () => {
|
|
1906
|
+
const {getByTestId} = renderChat({
|
|
1907
|
+
currentMessages: [{content: "Nice", rating: "up", role: "assistant"}],
|
|
1908
|
+
onRateComment: () => {},
|
|
1909
|
+
onRateFeedback: () => {},
|
|
1910
|
+
});
|
|
1911
|
+
|
|
1912
|
+
assert.isOk(getByTestId("gpt-rating-comment-0-input"));
|
|
1913
|
+
});
|
|
1914
|
+
|
|
1915
|
+
it("keeps the existing rating buttons next to the comment field", () => {
|
|
1916
|
+
const {getByTestId} = renderChat({
|
|
1917
|
+
currentMessages: ratedDown,
|
|
1918
|
+
onRateComment: () => {},
|
|
1919
|
+
onRateFeedback: () => {},
|
|
1920
|
+
});
|
|
1921
|
+
|
|
1922
|
+
assert.isOk(getByTestId("gpt-rate-up-0"));
|
|
1923
|
+
assert.isOk(getByTestId("gpt-rate-down-0"));
|
|
1924
|
+
});
|
|
1925
|
+
|
|
1926
|
+
it("shows no comment field on an unrated message", () => {
|
|
1927
|
+
const {queryByTestId} = renderChat({
|
|
1928
|
+
currentMessages: [{content: "Unrated", role: "assistant"}],
|
|
1929
|
+
onRateComment: () => {},
|
|
1930
|
+
onRateFeedback: () => {},
|
|
1931
|
+
});
|
|
1932
|
+
|
|
1933
|
+
assert.isNull(queryByTestId("gpt-rating-comment-0-input"));
|
|
1934
|
+
});
|
|
1935
|
+
|
|
1936
|
+
it("shows the sent state when the message already has a rating comment", () => {
|
|
1937
|
+
const {getByTestId, queryByTestId} = renderChat({
|
|
1938
|
+
currentMessages: [
|
|
1939
|
+
{content: "It is Monday", rating: "down", ratingComment: "Wrong date", role: "assistant"},
|
|
1940
|
+
],
|
|
1941
|
+
onRateComment: () => {},
|
|
1942
|
+
onRateFeedback: () => {},
|
|
1943
|
+
});
|
|
1944
|
+
|
|
1945
|
+
assert.isOk(getByTestId("gpt-rating-comment-0-sent"));
|
|
1946
|
+
assert.isNull(queryByTestId("gpt-rating-comment-0-input"));
|
|
1947
|
+
});
|
|
1948
|
+
|
|
1949
|
+
it("shows no comment field without onRateComment", () => {
|
|
1950
|
+
const {queryByTestId} = renderChat({currentMessages: ratedDown, onRateFeedback: () => {}});
|
|
1951
|
+
|
|
1952
|
+
assert.isNull(queryByTestId("gpt-rating-comment-0-input"));
|
|
1953
|
+
});
|
|
1954
|
+
|
|
1955
|
+
it("does not send an empty comment", async () => {
|
|
1956
|
+
const onRateComment = mock((_index: number, _comment: string) => {});
|
|
1957
|
+
const {getByTestId} = renderChat({
|
|
1958
|
+
currentMessages: ratedDown,
|
|
1959
|
+
onRateComment,
|
|
1960
|
+
onRateFeedback: () => {},
|
|
1961
|
+
});
|
|
1962
|
+
|
|
1963
|
+
fireEvent.changeText(getByTestId("gpt-rating-comment-0-input"), " ");
|
|
1964
|
+
await press(getByTestId("gpt-rating-comment-0-send"));
|
|
1965
|
+
|
|
1966
|
+
assert.equal(onRateComment.mock.calls.length, 0);
|
|
1967
|
+
});
|
|
1968
|
+
|
|
1969
|
+
it("uses the stored prompt index when a hidden ask result row precedes the rated message", async () => {
|
|
1970
|
+
const onRateComment = mock((_index: number, _comment: string) => {});
|
|
1971
|
+
const messages: GPTChatMessage[] = [
|
|
1972
|
+
{
|
|
1973
|
+
content: "Tool result: ask_choice",
|
|
1974
|
+
role: "tool-result",
|
|
1975
|
+
toolResult: {result: {ok: true}, toolCallId: "c1", toolName: "ask_choice"},
|
|
1976
|
+
},
|
|
1977
|
+
{content: "Answer", rating: "down", role: "assistant"},
|
|
1978
|
+
];
|
|
1979
|
+
const {getByTestId, queryByTestId} = renderChat({
|
|
1980
|
+
currentMessages: messages,
|
|
1981
|
+
onRateComment,
|
|
1982
|
+
onRateFeedback: () => {},
|
|
1983
|
+
});
|
|
1984
|
+
|
|
1985
|
+
assert.isNull(queryByTestId("gpt-rating-comment-0-input"));
|
|
1986
|
+
fireEvent.changeText(getByTestId("gpt-rating-comment-1-input"), "Off");
|
|
1987
|
+
await press(getByTestId("gpt-rating-comment-1-send"));
|
|
1988
|
+
|
|
1989
|
+
assert.deepEqual(onRateComment.mock.calls, [[1, "Off"]]);
|
|
1990
|
+
});
|
|
1991
|
+
|
|
1992
|
+
it("calls onMessageSignal with copied once after Copy message succeeds", async () => {
|
|
1993
|
+
mockedSetStringAsync.mockClear();
|
|
1994
|
+
const onMessageSignal = mock((_index: number, _signal: "copied") => {});
|
|
1995
|
+
const {getByTestId} = renderChat({
|
|
1996
|
+
currentMessages: [{content: "Copy me", role: "assistant"}],
|
|
1997
|
+
onMessageSignal,
|
|
1998
|
+
});
|
|
1999
|
+
|
|
2000
|
+
await press(getByTestId("gpt-copy-msg-0"));
|
|
2001
|
+
|
|
2002
|
+
assert.deepEqual(mockedSetStringAsync.mock.calls, [["Copy me"]]);
|
|
2003
|
+
assert.deepEqual(onMessageSignal.mock.calls, [[0, "copied"]]);
|
|
2004
|
+
});
|
|
2005
|
+
|
|
2006
|
+
it("does not call onMessageSignal when the clipboard write fails", async () => {
|
|
2007
|
+
mockedSetStringAsync.mockClear();
|
|
2008
|
+
mockedSetStringAsync.mockImplementationOnce(async () => {
|
|
2009
|
+
throw new Error("clipboard denied");
|
|
2010
|
+
});
|
|
2011
|
+
const onMessageSignal = mock((_index: number, _signal: "copied") => {});
|
|
2012
|
+
const {getByTestId} = renderChat({
|
|
2013
|
+
currentMessages: [{content: "Copy me", role: "assistant"}],
|
|
2014
|
+
onMessageSignal,
|
|
2015
|
+
});
|
|
2016
|
+
|
|
2017
|
+
try {
|
|
2018
|
+
await press(getByTestId("gpt-copy-msg-0"));
|
|
2019
|
+
} catch (error) {
|
|
2020
|
+
// The failed copy may surface its rejection; only the signal matters here.
|
|
2021
|
+
assert.instanceOf(error, Error);
|
|
2022
|
+
}
|
|
2023
|
+
assert.equal(onMessageSignal.mock.calls.length, 0);
|
|
2024
|
+
|
|
2025
|
+
// A later successful copy still signals, so the failure did not just disable the prop.
|
|
2026
|
+
await press(getByTestId("gpt-copy-msg-0"));
|
|
2027
|
+
assert.deepEqual(onMessageSignal.mock.calls, [[0, "copied"]]);
|
|
2028
|
+
});
|
|
2029
|
+
|
|
2030
|
+
it("copies without onMessageSignal and shows no comment field", async () => {
|
|
2031
|
+
mockedSetStringAsync.mockClear();
|
|
2032
|
+
const {getByTestId, queryByTestId} = renderChat({
|
|
2033
|
+
currentMessages: [{content: "Copy me", role: "assistant"}],
|
|
2034
|
+
});
|
|
2035
|
+
|
|
2036
|
+
await press(getByTestId("gpt-copy-msg-0"));
|
|
2037
|
+
|
|
2038
|
+
assert.deepEqual(mockedSetStringAsync.mock.calls, [["Copy me"]]);
|
|
2039
|
+
assert.isNull(queryByTestId("gpt-rating-comment-0-input"));
|
|
2040
|
+
});
|
|
2041
|
+
});
|