@terreno/ui 57.8.0 → 57.9.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/dist/AreaChart.d.ts +1 -1
- package/dist/AreaChart.d.ts.map +1 -1
- package/dist/AreaChart.js +70 -22
- package/dist/AreaChart.js.map +1 -1
- package/dist/BarChart.d.ts.map +1 -1
- package/dist/BarChart.js +55 -13
- package/dist/BarChart.js.map +1 -1
- package/dist/ChartCard.d.ts +5 -0
- package/dist/ChartCard.d.ts.map +1 -0
- package/dist/ChartCard.js +18 -0
- package/dist/ChartCard.js.map +1 -0
- package/dist/Common.d.ts +79 -5
- package/dist/Common.d.ts.map +1 -1
- package/dist/Common.js.map +1 -1
- package/dist/DashboardGrid.d.ts +6 -2
- package/dist/DashboardGrid.d.ts.map +1 -1
- package/dist/DashboardGrid.js +43 -10
- package/dist/DashboardGrid.js.map +1 -1
- package/dist/DonutChart.d.ts.map +1 -1
- package/dist/DonutChart.js +20 -10
- package/dist/DonutChart.js.map +1 -1
- package/dist/DropdownMenuItem.d.ts +16 -0
- package/dist/DropdownMenuItem.d.ts.map +1 -0
- package/dist/DropdownMenuItem.js +11 -0
- package/dist/DropdownMenuItem.js.map +1 -0
- package/dist/FilePickerButton.d.ts.map +1 -1
- package/dist/FilePickerButton.js +70 -10
- package/dist/FilePickerButton.js.map +1 -1
- package/dist/GPTChat.d.ts.map +1 -1
- package/dist/GPTChat.js +103 -14
- package/dist/GPTChat.js.map +1 -1
- package/dist/LineChart.d.ts +1 -1
- package/dist/LineChart.d.ts.map +1 -1
- package/dist/LineChart.js +62 -21
- package/dist/LineChart.js.map +1 -1
- package/dist/Scorecard.d.ts +5 -0
- package/dist/Scorecard.d.ts.map +1 -0
- package/dist/Scorecard.js +11 -0
- package/dist/Scorecard.js.map +1 -0
- package/dist/SparklineChart.d.ts +5 -0
- package/dist/SparklineChart.d.ts.map +1 -0
- package/dist/SparklineChart.js +35 -0
- package/dist/SparklineChart.js.map +1 -0
- package/dist/TextField.d.ts.map +1 -1
- package/dist/TextField.js +12 -4
- package/dist/TextField.js.map +1 -1
- package/dist/ToastNotifications.d.ts.map +1 -1
- package/dist/ToastNotifications.js +29 -6
- package/dist/ToastNotifications.js.map +1 -1
- package/dist/WebDropdownMenu.d.ts +2 -1
- package/dist/WebDropdownMenu.d.ts.map +1 -1
- package/dist/WebDropdownMenu.js +2 -6
- package/dist/WebDropdownMenu.js.map +1 -1
- package/dist/charts/ChartFacadeContainer.d.ts +10 -0
- package/dist/charts/ChartFacadeContainer.d.ts.map +1 -0
- package/dist/charts/ChartFacadeContainer.js +10 -0
- package/dist/charts/ChartFacadeContainer.js.map +1 -0
- package/dist/charts/ChartFrame.d.ts +4 -0
- package/dist/charts/ChartFrame.d.ts.map +1 -1
- package/dist/charts/ChartFrame.js +4 -2
- package/dist/charts/ChartFrame.js.map +1 -1
- package/dist/charts/layout.d.ts +9 -2
- package/dist/charts/layout.d.ts.map +1 -1
- package/dist/charts/layout.js +28 -6
- package/dist/charts/layout.js.map +1 -1
- package/dist/charts/scales.d.ts +3 -1
- package/dist/charts/scales.d.ts.map +1 -1
- package/dist/charts/scales.js +7 -7
- package/dist/charts/scales.js.map +1 -1
- package/dist/charts/series.d.ts +15 -0
- package/dist/charts/series.d.ts.map +1 -0
- package/dist/charts/series.js +19 -0
- package/dist/charts/series.js.map +1 -0
- package/dist/charts/types/chartTypes.d.ts +7 -0
- package/dist/charts/types/chartTypes.d.ts.map +1 -1
- package/dist/dashboardGridLayout.d.ts +6 -0
- package/dist/dashboardGridLayout.d.ts.map +1 -1
- package/dist/dashboardGridLayout.js +19 -3
- package/dist/dashboardGridLayout.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts +9 -0
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts.map +1 -1
- package/dist/lazyBoundaries/heavyOptionalExports.js +6 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
- package/dist/resolveDocumentBodyPortalTarget.d.ts +7 -0
- package/dist/resolveDocumentBodyPortalTarget.d.ts.map +1 -0
- package/dist/resolveDocumentBodyPortalTarget.js +12 -0
- package/dist/resolveDocumentBodyPortalTarget.js.map +1 -0
- package/package.json +1 -1
- package/src/AIRequestExplorer.test.tsx +2 -2
- package/src/AreaChart.test.tsx +81 -0
- package/src/AreaChart.tsx +171 -62
- package/src/BarChart.test.tsx +119 -0
- package/src/BarChart.tsx +94 -20
- package/src/ChartCard.test.tsx +79 -0
- package/src/ChartCard.tsx +80 -0
- package/src/Common.ts +69 -2
- package/src/DashboardGrid.test.tsx +98 -1
- package/src/DashboardGrid.tsx +71 -20
- package/src/DonutChart.test.tsx +73 -0
- package/src/DonutChart.tsx +87 -14
- package/src/DropdownMenuItem.tsx +48 -0
- package/src/FilePickerButton.test.tsx +60 -6
- package/src/FilePickerButton.tsx +116 -28
- package/src/GPTChat.test.tsx +133 -6
- package/src/GPTChat.tsx +196 -38
- package/src/LineChart.test.tsx +104 -0
- package/src/LineChart.tsx +154 -58
- package/src/Scorecard.test.tsx +65 -0
- package/src/Scorecard.tsx +45 -0
- package/src/SparklineChart.test.tsx +69 -0
- package/src/SparklineChart.tsx +85 -0
- package/src/TextField.test.tsx +16 -0
- package/src/TextField.tsx +13 -3
- package/src/ToastNotifications.tsx +33 -6
- package/src/ToastNotifications.webModal.test.tsx +285 -0
- package/src/WebDropdownMenu.tsx +3 -7
- package/src/bunSetup.ts +1 -0
- package/src/charts/ChartFacadeContainer.tsx +35 -0
- package/src/charts/ChartFrame.tsx +39 -1
- package/src/charts/layout.test.ts +22 -1
- package/src/charts/layout.ts +37 -4
- package/src/charts/scales.test.ts +33 -0
- package/src/charts/scales.ts +10 -6
- package/src/charts/series.ts +43 -0
- package/src/charts/types/chartTypes.ts +8 -0
- package/src/dashboardGridLayout.test.ts +59 -1
- package/src/dashboardGridLayout.ts +30 -3
- package/src/index.tsx +6 -0
- package/src/lazyBoundaries/heavyOptionalExports.tsx +21 -0
- package/src/resolveDocumentBodyPortalTarget.ts +11 -0
package/src/FilePickerButton.tsx
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import {DateTime} from "luxon";
|
|
2
2
|
import React, {useCallback, useState} from "react";
|
|
3
|
+
import {Platform} from "react-native";
|
|
3
4
|
|
|
4
5
|
import {Box} from "./Box";
|
|
5
|
-
import {
|
|
6
|
+
import {DropdownMenuItem} from "./DropdownMenuItem";
|
|
7
|
+
import {DropdownPanel} from "./DropdownPanel";
|
|
6
8
|
import {IconButton} from "./IconButton";
|
|
7
|
-
import {Modal} from "./Modal";
|
|
8
9
|
|
|
9
10
|
export interface SelectedFile {
|
|
10
11
|
mimeType: string;
|
|
@@ -19,16 +20,87 @@ export interface FilePickerButtonProps {
|
|
|
19
20
|
testID?: string;
|
|
20
21
|
}
|
|
21
22
|
|
|
23
|
+
const DOCUMENT_MIME_TYPES = ["application/pdf", "text/plain", "text/csv", "application/json"];
|
|
24
|
+
|
|
25
|
+
const readFileAsDataUrl = (file: File): Promise<string> =>
|
|
26
|
+
new Promise((resolve, reject) => {
|
|
27
|
+
const reader = new FileReader();
|
|
28
|
+
reader.onerror = (): void => reject(reader.error ?? new Error("Failed to read file"));
|
|
29
|
+
reader.onload = (): void => resolve(String(reader.result));
|
|
30
|
+
reader.readAsDataURL(file);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Opens the browser file dialog. Must run synchronously inside the press handler: browsers
|
|
35
|
+
* only open a file input from a trusted user gesture, which an awaited import would lose.
|
|
36
|
+
* Files resolve as `data:` URLs so they outlive the page, unlike `blob:` object URLs.
|
|
37
|
+
*/
|
|
38
|
+
const pickFilesOnWeb = ({
|
|
39
|
+
accept,
|
|
40
|
+
multiple,
|
|
41
|
+
}: {
|
|
42
|
+
accept: string;
|
|
43
|
+
multiple: boolean;
|
|
44
|
+
}): Promise<SelectedFile[]> =>
|
|
45
|
+
new Promise((resolve) => {
|
|
46
|
+
const input = document.createElement("input");
|
|
47
|
+
input.type = "file";
|
|
48
|
+
input.accept = accept;
|
|
49
|
+
input.multiple = multiple;
|
|
50
|
+
input.style.display = "none";
|
|
51
|
+
const cleanup = (): void => {
|
|
52
|
+
input.remove();
|
|
53
|
+
};
|
|
54
|
+
input.addEventListener("change", async () => {
|
|
55
|
+
const files = Array.from(input.files ?? []);
|
|
56
|
+
cleanup();
|
|
57
|
+
try {
|
|
58
|
+
const selected = await Promise.all(
|
|
59
|
+
files.map(async (file) => ({
|
|
60
|
+
mimeType: file.type || "application/octet-stream",
|
|
61
|
+
name: file.name,
|
|
62
|
+
uri: await readFileAsDataUrl(file),
|
|
63
|
+
}))
|
|
64
|
+
);
|
|
65
|
+
resolve(selected);
|
|
66
|
+
} catch (error) {
|
|
67
|
+
console.warn("Failed to read selected files", error);
|
|
68
|
+
resolve([]);
|
|
69
|
+
}
|
|
70
|
+
});
|
|
71
|
+
input.addEventListener("cancel", () => {
|
|
72
|
+
cleanup();
|
|
73
|
+
resolve([]);
|
|
74
|
+
});
|
|
75
|
+
document.body.appendChild(input);
|
|
76
|
+
input.click();
|
|
77
|
+
});
|
|
78
|
+
|
|
22
79
|
export const FilePickerButton = ({
|
|
23
80
|
disabled = false,
|
|
24
81
|
multiple = false,
|
|
25
82
|
onFilesSelected,
|
|
26
83
|
testID,
|
|
27
84
|
}: FilePickerButtonProps): React.ReactElement => {
|
|
28
|
-
const [
|
|
85
|
+
const [isMenuOpen, setIsMenuOpen] = useState(false);
|
|
86
|
+
const triggerTestID = testID ?? "file-picker-button";
|
|
87
|
+
|
|
88
|
+
const handleWebPick = useCallback(
|
|
89
|
+
async (accept: string): Promise<void> => {
|
|
90
|
+
const files = await pickFilesOnWeb({accept, multiple});
|
|
91
|
+
if (files.length > 0) {
|
|
92
|
+
onFilesSelected(files);
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
[multiple, onFilesSelected]
|
|
96
|
+
);
|
|
29
97
|
|
|
30
98
|
const handlePickImage = useCallback(async () => {
|
|
31
|
-
|
|
99
|
+
setIsMenuOpen(false);
|
|
100
|
+
if (Platform.OS === "web") {
|
|
101
|
+
await handleWebPick("image/*");
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
32
104
|
const ImagePicker = await import("expo-image-picker");
|
|
33
105
|
const result = await ImagePicker.launchImageLibraryAsync({
|
|
34
106
|
allowsMultipleSelection: multiple,
|
|
@@ -44,14 +116,18 @@ export const FilePickerButton = ({
|
|
|
44
116
|
}));
|
|
45
117
|
onFilesSelected(files);
|
|
46
118
|
}
|
|
47
|
-
}, [multiple, onFilesSelected]);
|
|
119
|
+
}, [handleWebPick, multiple, onFilesSelected]);
|
|
48
120
|
|
|
49
121
|
const handlePickDocument = useCallback(async () => {
|
|
50
|
-
|
|
122
|
+
setIsMenuOpen(false);
|
|
123
|
+
if (Platform.OS === "web") {
|
|
124
|
+
await handleWebPick(DOCUMENT_MIME_TYPES.join(","));
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
51
127
|
const DocumentPicker = await import("expo-document-picker");
|
|
52
128
|
const result = await DocumentPicker.getDocumentAsync({
|
|
53
129
|
multiple,
|
|
54
|
-
type:
|
|
130
|
+
type: DOCUMENT_MIME_TYPES,
|
|
55
131
|
});
|
|
56
132
|
|
|
57
133
|
if (!result.canceled && result.assets.length > 0) {
|
|
@@ -62,28 +138,40 @@ export const FilePickerButton = ({
|
|
|
62
138
|
}));
|
|
63
139
|
onFilesSelected(files);
|
|
64
140
|
}
|
|
65
|
-
}, [multiple, onFilesSelected]);
|
|
141
|
+
}, [handleWebPick, multiple, onFilesSelected]);
|
|
66
142
|
|
|
67
143
|
return (
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
144
|
+
<DropdownPanel
|
|
145
|
+
align="auto"
|
|
146
|
+
isOpen={isMenuOpen}
|
|
147
|
+
onOpenChange={setIsMenuOpen}
|
|
148
|
+
renderTrigger={({toggle}) => (
|
|
149
|
+
<IconButton
|
|
150
|
+
accessibilityLabel="Attach file"
|
|
151
|
+
disabled={disabled}
|
|
152
|
+
iconName="paperclip"
|
|
153
|
+
onClick={toggle}
|
|
154
|
+
testID={triggerTestID}
|
|
155
|
+
/>
|
|
156
|
+
)}
|
|
157
|
+
showActionButtons={false}
|
|
158
|
+
testID={`${triggerTestID}-menu`}
|
|
159
|
+
width={200}
|
|
160
|
+
>
|
|
161
|
+
<Box gap={1}>
|
|
162
|
+
<DropdownMenuItem
|
|
163
|
+
iconName="image"
|
|
164
|
+
label="Photo Library"
|
|
165
|
+
onClick={handlePickImage}
|
|
166
|
+
testID={`${triggerTestID}-photo`}
|
|
167
|
+
/>
|
|
168
|
+
<DropdownMenuItem
|
|
169
|
+
iconName="file"
|
|
170
|
+
label="Document"
|
|
171
|
+
onClick={handlePickDocument}
|
|
172
|
+
testID={`${triggerTestID}-document`}
|
|
173
|
+
/>
|
|
174
|
+
</Box>
|
|
175
|
+
</DropdownPanel>
|
|
88
176
|
);
|
|
89
177
|
};
|
package/src/GPTChat.test.tsx
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {afterAll, afterEach, describe, it, mock} from "bun:test";
|
|
2
2
|
import {act, fireEvent, render, waitFor} from "@testing-library/react-native";
|
|
3
3
|
import {assert} from "chai";
|
|
4
|
+
import {setImageAsync, setStringAsync} from "expo-clipboard";
|
|
4
5
|
import React from "react";
|
|
5
6
|
import {Platform, Pressable, ScrollView} from "react-native";
|
|
6
7
|
|
|
@@ -11,8 +12,8 @@ import {Text} from "./Text";
|
|
|
11
12
|
import {ThemeProvider} from "./Theme";
|
|
12
13
|
import {renderWithTheme} from "./test-utils";
|
|
13
14
|
|
|
14
|
-
const
|
|
15
|
-
|
|
15
|
+
const mockedSetImageAsync = setImageAsync as unknown as ReturnType<typeof mock>;
|
|
16
|
+
const mockedSetStringAsync = setStringAsync as unknown as ReturnType<typeof mock>;
|
|
16
17
|
|
|
17
18
|
const pickedDocument = {mimeType: "text/plain", name: "notes.txt", uri: "file:///notes.txt"};
|
|
18
19
|
mock.module("expo-document-picker", () => ({
|
|
@@ -91,6 +92,7 @@ describe("GPTChat", () => {
|
|
|
91
92
|
|
|
92
93
|
await press(getByLabelText("Select chat: First chat"));
|
|
93
94
|
await press(getByTestId("gpt-new-chat-button"));
|
|
95
|
+
await press(getByTestId("gpt-history-menu-h2"));
|
|
94
96
|
await press(getByTestId("gpt-delete-history-h2"));
|
|
95
97
|
|
|
96
98
|
assert.deepEqual(onSelectHistory.mock.calls, [["h1"]]);
|
|
@@ -102,6 +104,7 @@ describe("GPTChat", () => {
|
|
|
102
104
|
const onUpdateTitle = mock((_id: string, _title: string) => {});
|
|
103
105
|
const {getByTestId} = renderChat({onUpdateTitle});
|
|
104
106
|
|
|
107
|
+
await press(getByTestId("gpt-history-menu-h1"));
|
|
105
108
|
await press(getByTestId("gpt-rename-history-h1"));
|
|
106
109
|
fireEvent.changeText(getByTestId("gpt-rename-input-h1"), "Renamed");
|
|
107
110
|
await press(getByTestId("gpt-rename-save-h1"));
|
|
@@ -113,6 +116,7 @@ describe("GPTChat", () => {
|
|
|
113
116
|
const onUpdateTitle = mock((_id: string, _title: string) => {});
|
|
114
117
|
const {getByTestId} = renderChat({onUpdateTitle});
|
|
115
118
|
|
|
119
|
+
await press(getByTestId("gpt-history-menu-h2"));
|
|
116
120
|
await press(getByTestId("gpt-rename-history-h2"));
|
|
117
121
|
fireEvent.changeText(getByTestId("gpt-rename-input-h2"), " ");
|
|
118
122
|
fireEvent(getByTestId("gpt-rename-input-h2"), "blur");
|
|
@@ -120,10 +124,31 @@ describe("GPTChat", () => {
|
|
|
120
124
|
assert.equal(onUpdateTitle.mock.calls.length, 0);
|
|
121
125
|
});
|
|
122
126
|
|
|
123
|
-
it("hides the rename
|
|
124
|
-
const {queryByTestId} = renderChat();
|
|
127
|
+
it("hides the rename action when renaming is not supported", async () => {
|
|
128
|
+
const {getByTestId, queryByTestId} = renderChat();
|
|
129
|
+
|
|
130
|
+
await press(getByTestId("gpt-history-menu-h1"));
|
|
125
131
|
|
|
126
132
|
assert.isNull(queryByTestId("gpt-rename-history-h1"));
|
|
133
|
+
assert.isOk(getByTestId("gpt-delete-history-h1"));
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("keeps rename and delete inside a per-row overflow menu", async () => {
|
|
137
|
+
const {getByTestId, queryByTestId} = renderChat({onUpdateTitle: () => {}});
|
|
138
|
+
|
|
139
|
+
assert.isOk(getByTestId("gpt-history-menu-h1"));
|
|
140
|
+
assert.isNull(queryByTestId("gpt-rename-history-h1"));
|
|
141
|
+
assert.isNull(queryByTestId("gpt-delete-history-h1"));
|
|
142
|
+
|
|
143
|
+
await press(getByTestId("gpt-history-menu-h1"));
|
|
144
|
+
|
|
145
|
+
assert.isOk(getByTestId("gpt-rename-history-h1"));
|
|
146
|
+
assert.isOk(getByTestId("gpt-delete-history-h1"));
|
|
147
|
+
|
|
148
|
+
await press(getByTestId("gpt-rename-history-h1"));
|
|
149
|
+
|
|
150
|
+
assert.isNull(queryByTestId("gpt-delete-history-h1"));
|
|
151
|
+
assert.isOk(getByTestId("gpt-rename-input-h1"));
|
|
127
152
|
});
|
|
128
153
|
|
|
129
154
|
it("renders a model selector only when models and a change handler are given", () => {
|
|
@@ -562,7 +587,7 @@ describe("GPTChat", () => {
|
|
|
562
587
|
});
|
|
563
588
|
|
|
564
589
|
it("copies an assistant message to the clipboard", async () => {
|
|
565
|
-
|
|
590
|
+
mockedSetStringAsync.mockClear();
|
|
566
591
|
const {getByTestId} = renderChat({
|
|
567
592
|
currentMessages: [{content: "Copy me", role: "assistant"}],
|
|
568
593
|
});
|
|
@@ -571,7 +596,63 @@ describe("GPTChat", () => {
|
|
|
571
596
|
fireEvent.press(getByTestId("gpt-copy-msg-0"));
|
|
572
597
|
});
|
|
573
598
|
|
|
574
|
-
assert.deepEqual(
|
|
599
|
+
assert.deepEqual(mockedSetStringAsync.mock.calls, [["Copy me"]]);
|
|
600
|
+
});
|
|
601
|
+
|
|
602
|
+
it("copies the image, not placeholder text, for an image-only reply", async () => {
|
|
603
|
+
mockedSetStringAsync.mockClear();
|
|
604
|
+
mockedSetImageAsync.mockClear();
|
|
605
|
+
const {getByTestId} = renderChat({
|
|
606
|
+
currentMessages: [
|
|
607
|
+
{
|
|
608
|
+
content: "",
|
|
609
|
+
contentParts: [{mimeType: "image/png", type: "image", url: "data:image/png;base64,AAAA"}],
|
|
610
|
+
role: "assistant",
|
|
611
|
+
},
|
|
612
|
+
],
|
|
613
|
+
});
|
|
614
|
+
|
|
615
|
+
await press(getByTestId("gpt-copy-msg-0"));
|
|
616
|
+
|
|
617
|
+
assert.deepEqual(mockedSetImageAsync.mock.calls, [["AAAA"]]);
|
|
618
|
+
assert.equal(mockedSetStringAsync.mock.calls.length, 0);
|
|
619
|
+
});
|
|
620
|
+
|
|
621
|
+
it("offers a copy-image action on generated images", async () => {
|
|
622
|
+
mockedSetImageAsync.mockClear();
|
|
623
|
+
const {getByTestId} = renderChat({
|
|
624
|
+
currentMessages: [
|
|
625
|
+
{
|
|
626
|
+
content: "Here you go",
|
|
627
|
+
contentParts: [{mimeType: "image/png", type: "image", url: "data:image/png;base64,BBBB"}],
|
|
628
|
+
role: "assistant",
|
|
629
|
+
},
|
|
630
|
+
],
|
|
631
|
+
});
|
|
632
|
+
|
|
633
|
+
await press(getByTestId("gpt-copy-image"));
|
|
634
|
+
|
|
635
|
+
assert.deepEqual(mockedSetImageAsync.mock.calls, [["BBBB"]]);
|
|
636
|
+
});
|
|
637
|
+
|
|
638
|
+
it("grows the composer up to a maximum height and resets after sending", async () => {
|
|
639
|
+
const {getByTestId} = renderChat();
|
|
640
|
+
const input = getByTestId("gpt-input");
|
|
641
|
+
fireEvent.changeText(input, "Long pasted notes");
|
|
642
|
+
|
|
643
|
+
fireEvent(input, "contentSizeChange", {nativeEvent: {contentSize: {height: 120, width: 100}}});
|
|
644
|
+
const grownStyle = [getByTestId("gpt-input").props.style].flat(Infinity);
|
|
645
|
+
assert.isTrue(grownStyle.some((style) => style?.height === 120));
|
|
646
|
+
|
|
647
|
+
fireEvent(getByTestId("gpt-input"), "contentSizeChange", {
|
|
648
|
+
nativeEvent: {contentSize: {height: 900, width: 100}},
|
|
649
|
+
});
|
|
650
|
+
const cappedStyle = [getByTestId("gpt-input").props.style].flat(Infinity);
|
|
651
|
+
assert.isTrue(cappedStyle.some((style) => style?.height === 200));
|
|
652
|
+
|
|
653
|
+
await press(getByTestId("gpt-submit"));
|
|
654
|
+
const resetStyle = [getByTestId("gpt-input").props.style].flat(Infinity);
|
|
655
|
+
assert.isTrue(resetStyle.some((style) => style?.height === 40));
|
|
575
656
|
});
|
|
576
657
|
|
|
577
658
|
it("disables input and the attachment picker while streaming", () => {
|
|
@@ -619,6 +700,51 @@ describe("GPTChat", () => {
|
|
|
619
700
|
assert.isNull(queryByText("Scroll to bottom"));
|
|
620
701
|
});
|
|
621
702
|
|
|
703
|
+
it("never shows scroll to bottom in an empty chat", async () => {
|
|
704
|
+
const {getByTestId, queryByText, UNSAFE_getByType} = renderChat({currentMessages: []});
|
|
705
|
+
|
|
706
|
+
fireEvent(getByTestId("gpt-viewport"), "layout", {
|
|
707
|
+
nativeEvent: {layout: {height: 200, width: 100, x: 0, y: 0}},
|
|
708
|
+
});
|
|
709
|
+
fireEvent(getByTestId("gpt-messages"), "layout", {
|
|
710
|
+
nativeEvent: {layout: {height: 600, width: 100, x: 0, y: 0}},
|
|
711
|
+
});
|
|
712
|
+
await act(async () => {
|
|
713
|
+
fireEvent.scroll(UNSAFE_getByType(ScrollView), {
|
|
714
|
+
nativeEvent: {contentOffset: {x: 0, y: 0}},
|
|
715
|
+
});
|
|
716
|
+
});
|
|
717
|
+
|
|
718
|
+
assert.isNull(queryByText("Scroll to bottom"));
|
|
719
|
+
});
|
|
720
|
+
|
|
721
|
+
it("hides scroll to bottom once the content fits the viewport", async () => {
|
|
722
|
+
const {getByTestId, getByText, queryByText, UNSAFE_getByType} = renderChat({
|
|
723
|
+
currentMessages: [{content: "Hello!", role: "assistant"}],
|
|
724
|
+
});
|
|
725
|
+
|
|
726
|
+
fireEvent(getByTestId("gpt-viewport"), "layout", {
|
|
727
|
+
nativeEvent: {layout: {height: 200, width: 100, x: 0, y: 0}},
|
|
728
|
+
});
|
|
729
|
+
fireEvent(getByTestId("gpt-messages"), "layout", {
|
|
730
|
+
nativeEvent: {layout: {height: 600, width: 100, x: 0, y: 0}},
|
|
731
|
+
});
|
|
732
|
+
await act(async () => {
|
|
733
|
+
fireEvent.scroll(UNSAFE_getByType(ScrollView), {
|
|
734
|
+
nativeEvent: {contentOffset: {x: 0, y: 0}},
|
|
735
|
+
});
|
|
736
|
+
});
|
|
737
|
+
assert.isOk(getByText("Scroll to bottom"));
|
|
738
|
+
|
|
739
|
+
await act(async () => {
|
|
740
|
+
fireEvent(getByTestId("gpt-messages"), "layout", {
|
|
741
|
+
nativeEvent: {layout: {height: 150, width: 100, x: 0, y: 0}},
|
|
742
|
+
});
|
|
743
|
+
});
|
|
744
|
+
|
|
745
|
+
assert.isNull(queryByText("Scroll to bottom"));
|
|
746
|
+
});
|
|
747
|
+
|
|
622
748
|
it("renders attachments and the attach button", () => {
|
|
623
749
|
const onAttachFiles = mock(() => {});
|
|
624
750
|
const onRemoveAttachment = mock((_index: number) => {});
|
|
@@ -668,6 +794,7 @@ describe("GPTChat", () => {
|
|
|
668
794
|
const onUpdateTitle = mock((_id: string, _title: string) => {});
|
|
669
795
|
const {getByTestId} = renderChat({onUpdateTitle});
|
|
670
796
|
|
|
797
|
+
await press(getByTestId("gpt-history-menu-h1"));
|
|
671
798
|
await press(getByTestId("gpt-rename-history-h1"));
|
|
672
799
|
fireEvent.changeText(getByTestId("gpt-rename-input-h1"), "Renamed");
|
|
673
800
|
const input = getByTestId("gpt-rename-input-h1");
|