@terreno/ui 0.23.1 → 0.25.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/AIRequestExplorer.js +6 -1
- package/dist/AIRequestExplorer.js.map +1 -1
- package/dist/ActionSheet.d.ts +1 -0
- package/dist/ActionSheet.js +3 -0
- package/dist/ActionSheet.js.map +1 -1
- package/dist/AiSuggestionBox.d.ts +11 -0
- package/dist/AiSuggestionBox.js +50 -23
- package/dist/AiSuggestionBox.js.map +1 -1
- package/dist/Common.d.ts +25 -1
- package/dist/Common.js.map +1 -1
- package/dist/CustomSelectField.js +2 -2
- package/dist/CustomSelectField.js.map +1 -1
- package/dist/FilePickerButton.js +2 -1
- package/dist/FilePickerButton.js.map +1 -1
- package/dist/PickerSelect.d.ts +10 -2
- package/dist/PickerSelect.js +91 -17
- package/dist/PickerSelect.js.map +1 -1
- package/dist/SelectBadge.js +1 -1
- package/dist/SelectBadge.js.map +1 -1
- package/dist/SelectField.js +9 -9
- package/dist/SelectField.js.map +1 -1
- package/dist/WebDropdownMenu.d.ts +36 -5
- package/dist/WebDropdownMenu.js +211 -29
- package/dist/WebDropdownMenu.js.map +1 -1
- package/dist/createWebPortal.d.ts +7 -0
- package/dist/createWebPortal.js +3 -0
- package/dist/createWebPortal.js.map +1 -0
- package/dist/createWebPortal.native.d.ts +7 -0
- package/dist/createWebPortal.native.js +2 -0
- package/dist/createWebPortal.native.js.map +1 -0
- package/dist/fieldElements/FieldHelperText.js +1 -1
- package/dist/fieldElements/FieldHelperText.js.map +1 -1
- package/dist/icons/SparklesIcon.d.ts +7 -0
- package/dist/icons/SparklesIcon.js +32 -0
- package/dist/icons/SparklesIcon.js.map +1 -0
- package/dist/icons/index.d.ts +1 -0
- package/dist/icons/index.js +1 -0
- package/dist/icons/index.js.map +1 -1
- package/package.json +2 -2
- package/src/AIRequestExplorer.tsx +6 -1
- package/src/ActionSheet.test.tsx +198 -2
- package/src/ActionSheet.tsx +4 -0
- package/src/AiSuggestionBox.test.tsx +184 -15
- package/src/AiSuggestionBox.tsx +72 -55
- package/src/Common.ts +28 -1
- package/src/CustomSelectField.test.tsx +13 -3
- package/src/CustomSelectField.tsx +2 -0
- package/src/EmojiSelector.test.tsx +153 -0
- package/src/FilePickerButton.tsx +2 -1
- package/src/Modal.test.tsx +47 -0
- package/src/PickerSelect.test.tsx +253 -14
- package/src/PickerSelect.tsx +206 -49
- package/src/SelectBadge.tsx +1 -0
- package/src/SelectBadge.web.test.tsx +10 -0
- package/src/SelectField.tsx +19 -15
- package/src/WebDropdownMenu.test.tsx +449 -0
- package/src/WebDropdownMenu.tsx +405 -60
- package/src/__snapshots__/AddressField.test.tsx.snap +2088 -665
- package/src/__snapshots__/AiSuggestionBox.test.tsx.snap +489 -102
- package/src/__snapshots__/CustomSelectField.test.tsx.snap +2118 -1369
- package/src/__snapshots__/Field.test.tsx.snap +3787 -1806
- package/src/__snapshots__/HeightField.test.tsx.snap +3 -0
- package/src/__snapshots__/PickerSelect.test.tsx.snap +7 -7
- package/src/__snapshots__/SelectField.test.tsx.snap +1548 -1102
- package/src/__snapshots__/Slider.test.tsx.snap +3 -0
- package/src/__snapshots__/TextArea.test.tsx.snap +3 -0
- package/src/__snapshots__/TextField.test.tsx.snap +3 -0
- package/src/__snapshots__/TimezonePicker.test.tsx.snap +2499 -1353
- package/src/createWebPortal.native.ts +8 -0
- package/src/createWebPortal.test.tsx +13 -0
- package/src/createWebPortal.ts +10 -0
- package/src/fieldElements/FieldHelperText.tsx +4 -2
- package/src/fieldElements/__snapshots__/FieldHelperText.test.tsx.snap +3 -0
- package/src/icons/SparklesIcon.test.tsx +16 -0
- package/src/icons/SparklesIcon.tsx +38 -0
- package/src/icons/__snapshots__/SparklesIcon.test.tsx.snap +47 -0
- package/src/icons/index.ts +1 -0
- package/src/table/TableBadge.test.tsx +19 -11
- package/src/table/__snapshots__/TableBadge.test.tsx.snap +226 -175
- package/src/types/react-dom.d.ts +5 -0
package/src/ActionSheet.test.tsx
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
2
|
-
import {beforeAll, describe, expect, it, mock} from "bun:test";
|
|
2
|
+
import {afterAll, afterEach, beforeAll, describe, expect, it, mock} from "bun:test";
|
|
3
3
|
import {act, render} from "@testing-library/react-native";
|
|
4
4
|
import {createRef} from "react";
|
|
5
5
|
import {Text} from "react-native";
|
|
6
6
|
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
ActionSheet,
|
|
9
|
+
getDeviceHeight,
|
|
10
|
+
getElevation,
|
|
11
|
+
resetActionSheetDeviceHeightCacheForTests,
|
|
12
|
+
waitAsync,
|
|
13
|
+
} from "./ActionSheet";
|
|
8
14
|
import {ThemeProvider} from "./Theme";
|
|
9
15
|
|
|
10
16
|
beforeAll(() => {
|
|
@@ -16,6 +22,10 @@ beforeAll(() => {
|
|
|
16
22
|
};
|
|
17
23
|
});
|
|
18
24
|
|
|
25
|
+
afterAll(() => {
|
|
26
|
+
resetActionSheetDeviceHeightCacheForTests();
|
|
27
|
+
});
|
|
28
|
+
|
|
19
29
|
describe("ActionSheet", () => {
|
|
20
30
|
it("component is defined", () => {
|
|
21
31
|
expect(ActionSheet).toBeDefined();
|
|
@@ -888,4 +898,190 @@ describe("ActionSheet", () => {
|
|
|
888
898
|
await expect((ref.current as any)._onScrollBegin()).resolves.toBeUndefined();
|
|
889
899
|
});
|
|
890
900
|
});
|
|
901
|
+
|
|
902
|
+
describe("handleChildScrollEnd with setTimeout recoiling", () => {
|
|
903
|
+
it("resets isRecoiling after timeout when scrolling back to initial position", async () => {
|
|
904
|
+
const ref = createRef<ActionSheet>();
|
|
905
|
+
render(
|
|
906
|
+
<ThemeProvider>
|
|
907
|
+
<ActionSheet gestureEnabled initialOffsetFromBottom={0.5} ref={ref} springOffset={10}>
|
|
908
|
+
<Text>Content</Text>
|
|
909
|
+
</ActionSheet>
|
|
910
|
+
</ThemeProvider>
|
|
911
|
+
);
|
|
912
|
+
(ref.current as any).actionSheetHeight = 100;
|
|
913
|
+
// scrollOffset ≈ 100*0.5 + deviceHeight*0.15 ≈ 150
|
|
914
|
+
// Need offsetY > scrollOffset - 100, so offsetY = 120 works
|
|
915
|
+
(ref.current as any).offsetY = 120;
|
|
916
|
+
(ref.current as any).prevScroll = 200;
|
|
917
|
+
await act(async () => {
|
|
918
|
+
await (ref.current as any).handleChildScrollEnd();
|
|
919
|
+
});
|
|
920
|
+
expect((ref.current as any).isRecoiling).toBe(true);
|
|
921
|
+
await act(async () => {
|
|
922
|
+
await new Promise((r) => setTimeout(r, 600));
|
|
923
|
+
});
|
|
924
|
+
expect((ref.current as any).isRecoiling).toBe(false);
|
|
925
|
+
});
|
|
926
|
+
});
|
|
927
|
+
|
|
928
|
+
describe("handleChildScrollEnd additional coverage", () => {
|
|
929
|
+
it("recoils when offset is near prevScroll", async () => {
|
|
930
|
+
const ref = createRef<ActionSheet>();
|
|
931
|
+
render(
|
|
932
|
+
<ThemeProvider>
|
|
933
|
+
<ActionSheet ref={ref} springOffset={5}>
|
|
934
|
+
<Text>Content</Text>
|
|
935
|
+
</ActionSheet>
|
|
936
|
+
</ThemeProvider>
|
|
937
|
+
);
|
|
938
|
+
(ref.current as any).offsetY = 98;
|
|
939
|
+
(ref.current as any).prevScroll = 100;
|
|
940
|
+
await act(async () => {
|
|
941
|
+
await (ref.current as any).handleChildScrollEnd();
|
|
942
|
+
});
|
|
943
|
+
expect((ref.current as any).isRecoiling).toBe(true);
|
|
944
|
+
await act(async () => {
|
|
945
|
+
await new Promise((r) => setTimeout(r, 600));
|
|
946
|
+
});
|
|
947
|
+
expect((ref.current as any).isRecoiling).toBe(false);
|
|
948
|
+
});
|
|
949
|
+
|
|
950
|
+
it("recoils when within scroll threshold of initial position", async () => {
|
|
951
|
+
const ref = createRef<ActionSheet>();
|
|
952
|
+
render(
|
|
953
|
+
<ThemeProvider>
|
|
954
|
+
<ActionSheet gestureEnabled ref={ref} springOffset={100}>
|
|
955
|
+
<Text>Content</Text>
|
|
956
|
+
</ActionSheet>
|
|
957
|
+
</ThemeProvider>
|
|
958
|
+
);
|
|
959
|
+
const instance = ref.current as any;
|
|
960
|
+
instance.actionSheetHeight = 500;
|
|
961
|
+
instance.prevScroll = 300;
|
|
962
|
+
instance.offsetY = 250;
|
|
963
|
+
instance.isRecoiling = false;
|
|
964
|
+
instance.currentOffsetFromBottom = 1;
|
|
965
|
+
|
|
966
|
+
await act(async () => {
|
|
967
|
+
await instance.handleChildScrollEnd();
|
|
968
|
+
});
|
|
969
|
+
await act(async () => {
|
|
970
|
+
await new Promise((r) => setTimeout(r, 600));
|
|
971
|
+
});
|
|
972
|
+
expect(instance.isRecoiling).toBe(false);
|
|
973
|
+
});
|
|
974
|
+
|
|
975
|
+
it("hides modal when scrolled far past threshold", async () => {
|
|
976
|
+
const ref = createRef<ActionSheet>();
|
|
977
|
+
const onClose = mock(() => {});
|
|
978
|
+
render(
|
|
979
|
+
<ThemeProvider>
|
|
980
|
+
<ActionSheet gestureEnabled onClose={onClose} ref={ref} springOffset={50}>
|
|
981
|
+
<Text>Content</Text>
|
|
982
|
+
</ActionSheet>
|
|
983
|
+
</ThemeProvider>
|
|
984
|
+
);
|
|
985
|
+
const instance = ref.current as any;
|
|
986
|
+
instance.actionSheetHeight = 500;
|
|
987
|
+
instance.prevScroll = 300;
|
|
988
|
+
instance.offsetY = 100;
|
|
989
|
+
instance.isRecoiling = false;
|
|
990
|
+
instance.isClosing = false;
|
|
991
|
+
|
|
992
|
+
await act(async () => {
|
|
993
|
+
await instance.handleChildScrollEnd();
|
|
994
|
+
});
|
|
995
|
+
expect(instance.isClosing).toBe(true);
|
|
996
|
+
});
|
|
997
|
+
|
|
998
|
+
it("recoils back to previous position when not past threshold", async () => {
|
|
999
|
+
const ref = createRef<ActionSheet>();
|
|
1000
|
+
render(
|
|
1001
|
+
<ThemeProvider>
|
|
1002
|
+
<ActionSheet gestureEnabled ref={ref} springOffset={100}>
|
|
1003
|
+
<Text>Content</Text>
|
|
1004
|
+
</ActionSheet>
|
|
1005
|
+
</ThemeProvider>
|
|
1006
|
+
);
|
|
1007
|
+
const instance = ref.current as any;
|
|
1008
|
+
instance.actionSheetHeight = 500;
|
|
1009
|
+
instance.prevScroll = 300;
|
|
1010
|
+
instance.offsetY = 290;
|
|
1011
|
+
instance.isRecoiling = false;
|
|
1012
|
+
|
|
1013
|
+
await act(async () => {
|
|
1014
|
+
await instance.handleChildScrollEnd();
|
|
1015
|
+
});
|
|
1016
|
+
await act(async () => {
|
|
1017
|
+
await new Promise((r) => setTimeout(r, 600));
|
|
1018
|
+
});
|
|
1019
|
+
expect(instance.isRecoiling).toBe(false);
|
|
1020
|
+
});
|
|
1021
|
+
|
|
1022
|
+
it("bounces back when scrolling up beyond prevScroll", async () => {
|
|
1023
|
+
const ref = createRef<ActionSheet>();
|
|
1024
|
+
render(
|
|
1025
|
+
<ThemeProvider>
|
|
1026
|
+
<ActionSheet gestureEnabled ref={ref}>
|
|
1027
|
+
<Text>Content</Text>
|
|
1028
|
+
</ActionSheet>
|
|
1029
|
+
</ThemeProvider>
|
|
1030
|
+
);
|
|
1031
|
+
const instance = ref.current as any;
|
|
1032
|
+
instance.prevScroll = 200;
|
|
1033
|
+
instance.offsetY = 195;
|
|
1034
|
+
instance._scrollTo = mock(() => {});
|
|
1035
|
+
await instance.handleChildScrollEnd();
|
|
1036
|
+
expect(instance.isRecoiling).toBe(true);
|
|
1037
|
+
await act(async () => {
|
|
1038
|
+
await new Promise((r) => setTimeout(r, 600));
|
|
1039
|
+
});
|
|
1040
|
+
expect(instance.isRecoiling).toBe(false);
|
|
1041
|
+
});
|
|
1042
|
+
});
|
|
1043
|
+
|
|
1044
|
+
describe("_onDeviceLayout timeout callback execution", () => {
|
|
1045
|
+
afterEach(() => {
|
|
1046
|
+
resetActionSheetDeviceHeightCacheForTests();
|
|
1047
|
+
});
|
|
1048
|
+
|
|
1049
|
+
it("updates state after layout timeout fires with drawUnderStatusBar", async () => {
|
|
1050
|
+
const ref = createRef<ActionSheet>();
|
|
1051
|
+
render(
|
|
1052
|
+
<ThemeProvider>
|
|
1053
|
+
<ActionSheet drawUnderStatusBar ref={ref}>
|
|
1054
|
+
<Text>Content</Text>
|
|
1055
|
+
</ActionSheet>
|
|
1056
|
+
</ThemeProvider>
|
|
1057
|
+
);
|
|
1058
|
+
await act(async () => {
|
|
1059
|
+
(ref.current as any)._onDeviceLayout({
|
|
1060
|
+
nativeEvent: {layout: {height: 800, width: 400}},
|
|
1061
|
+
});
|
|
1062
|
+
// measure() has a 100ms timeout on iOS; on android it uses StatusBar.currentHeight
|
|
1063
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
1064
|
+
});
|
|
1065
|
+
// The callback should have run and set deviceLayoutCalled
|
|
1066
|
+
expect((ref.current as any).deviceLayoutCalled).toBe(true);
|
|
1067
|
+
});
|
|
1068
|
+
|
|
1069
|
+
it("updates state after layout timeout fires without drawUnderStatusBar on android", async () => {
|
|
1070
|
+
const ref = createRef<ActionSheet>();
|
|
1071
|
+
render(
|
|
1072
|
+
<ThemeProvider>
|
|
1073
|
+
<ActionSheet ref={ref} statusBarTranslucent>
|
|
1074
|
+
<Text>Content</Text>
|
|
1075
|
+
</ActionSheet>
|
|
1076
|
+
</ThemeProvider>
|
|
1077
|
+
);
|
|
1078
|
+
await act(async () => {
|
|
1079
|
+
(ref.current as any)._onDeviceLayout({
|
|
1080
|
+
nativeEvent: {layout: {height: 900, width: 400}},
|
|
1081
|
+
});
|
|
1082
|
+
await new Promise((r) => setTimeout(r, 200));
|
|
1083
|
+
});
|
|
1084
|
+
expect((ref.current as any).deviceLayoutCalled).toBe(true);
|
|
1085
|
+
});
|
|
1086
|
+
});
|
|
891
1087
|
});
|
package/src/ActionSheet.tsx
CHANGED
|
@@ -96,6 +96,10 @@ const dummyData = ["dummy"];
|
|
|
96
96
|
let safeAreaPaddingTop = Platform.OS === "android" ? StatusBar.currentHeight || 0 : 0;
|
|
97
97
|
let calculatedDeviceHeight = Dimensions.get("window").height;
|
|
98
98
|
|
|
99
|
+
export const resetActionSheetDeviceHeightCacheForTests = (): void => {
|
|
100
|
+
calculatedDeviceHeight = Dimensions.get("window").height;
|
|
101
|
+
};
|
|
102
|
+
|
|
99
103
|
type State = {
|
|
100
104
|
modalVisible: boolean;
|
|
101
105
|
scrollable: boolean;
|
|
@@ -1,9 +1,22 @@
|
|
|
1
1
|
import {describe, expect, it, mock} from "bun:test";
|
|
2
|
-
import {fireEvent} from "@testing-library/react-native";
|
|
2
|
+
import {act, fireEvent} from "@testing-library/react-native";
|
|
3
|
+
import type {ReactTestInstance} from "react-test-renderer";
|
|
3
4
|
|
|
5
|
+
import {AiSuggestionBox} from "./AiSuggestionBox";
|
|
4
6
|
import {TextArea} from "./TextArea";
|
|
5
7
|
import {renderWithTheme} from "./test-utils";
|
|
6
8
|
|
|
9
|
+
/**
|
|
10
|
+
* Presses a Button-backed element and waits out the press handler's async haptic +
|
|
11
|
+
* leading-edge debounce so the onClick side effects have applied before asserting.
|
|
12
|
+
*/
|
|
13
|
+
const pressButton = async (element: ReactTestInstance): Promise<void> => {
|
|
14
|
+
await act(async () => {
|
|
15
|
+
fireEvent.press(element);
|
|
16
|
+
await new Promise((resolve) => setTimeout(resolve, 100));
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
|
|
7
20
|
describe("AiSuggestionBox in TextArea", () => {
|
|
8
21
|
describe("not-started state", () => {
|
|
9
22
|
it("should render default not-started text", () => {
|
|
@@ -100,7 +113,7 @@ describe("AiSuggestionBox in TextArea", () => {
|
|
|
100
113
|
expect(getByText("Add to note")).toBeTruthy();
|
|
101
114
|
});
|
|
102
115
|
|
|
103
|
-
it("should call onAdd when Add to note is pressed", () => {
|
|
116
|
+
it("should call onAdd when Add to note is pressed", async () => {
|
|
104
117
|
const mockOnAdd = mock(() => {});
|
|
105
118
|
const {getByLabelText} = renderWithTheme(
|
|
106
119
|
<TextArea
|
|
@@ -115,11 +128,11 @@ describe("AiSuggestionBox in TextArea", () => {
|
|
|
115
128
|
/>
|
|
116
129
|
);
|
|
117
130
|
|
|
118
|
-
|
|
131
|
+
await pressButton(getByLabelText("Add to note"));
|
|
119
132
|
expect(mockOnAdd).toHaveBeenCalledTimes(1);
|
|
120
133
|
});
|
|
121
134
|
|
|
122
|
-
it("should collapse when Hide is pressed", () => {
|
|
135
|
+
it("should collapse when Hide is pressed", async () => {
|
|
123
136
|
const {getByLabelText, getByText, queryByText} = renderWithTheme(
|
|
124
137
|
<TextArea
|
|
125
138
|
aiSuggestion={{
|
|
@@ -135,14 +148,14 @@ describe("AiSuggestionBox in TextArea", () => {
|
|
|
135
148
|
|
|
136
149
|
expect(getByText("Suggestion text")).toBeTruthy();
|
|
137
150
|
|
|
138
|
-
|
|
151
|
+
await pressButton(getByLabelText("Hide"));
|
|
139
152
|
|
|
140
153
|
expect(queryByText("Suggestion text")).toBeNull();
|
|
141
154
|
expect(getByText("AI-generated note (hidden)")).toBeTruthy();
|
|
142
155
|
expect(getByText("Show")).toBeTruthy();
|
|
143
156
|
});
|
|
144
157
|
|
|
145
|
-
it("should expand when Show is pressed after collapsing", () => {
|
|
158
|
+
it("should expand when Show is pressed after collapsing", async () => {
|
|
146
159
|
const {getByLabelText, getByText} = renderWithTheme(
|
|
147
160
|
<TextArea
|
|
148
161
|
aiSuggestion={{
|
|
@@ -156,15 +169,15 @@ describe("AiSuggestionBox in TextArea", () => {
|
|
|
156
169
|
/>
|
|
157
170
|
);
|
|
158
171
|
|
|
159
|
-
|
|
172
|
+
await pressButton(getByLabelText("Hide"));
|
|
160
173
|
expect(getByText("AI-generated note (hidden)")).toBeTruthy();
|
|
161
174
|
|
|
162
|
-
|
|
175
|
+
await pressButton(getByLabelText("Show"));
|
|
163
176
|
expect(getByText("Suggestion text")).toBeTruthy();
|
|
164
177
|
expect(getByText("AI-generated note")).toBeTruthy();
|
|
165
178
|
});
|
|
166
179
|
|
|
167
|
-
it("should call onHide when Hide is pressed", () => {
|
|
180
|
+
it("should call onHide when Hide is pressed", async () => {
|
|
168
181
|
const mockOnHide = mock(() => {});
|
|
169
182
|
const {getByLabelText} = renderWithTheme(
|
|
170
183
|
<TextArea
|
|
@@ -180,11 +193,11 @@ describe("AiSuggestionBox in TextArea", () => {
|
|
|
180
193
|
/>
|
|
181
194
|
);
|
|
182
195
|
|
|
183
|
-
|
|
196
|
+
await pressButton(getByLabelText("Hide"));
|
|
184
197
|
expect(mockOnHide).toHaveBeenCalledTimes(1);
|
|
185
198
|
});
|
|
186
199
|
|
|
187
|
-
it("should call onShow when Show is pressed", () => {
|
|
200
|
+
it("should call onShow when Show is pressed", async () => {
|
|
188
201
|
const mockOnShow = mock(() => {});
|
|
189
202
|
const {getByLabelText} = renderWithTheme(
|
|
190
203
|
<TextArea
|
|
@@ -200,15 +213,57 @@ describe("AiSuggestionBox in TextArea", () => {
|
|
|
200
213
|
/>
|
|
201
214
|
);
|
|
202
215
|
|
|
203
|
-
|
|
204
|
-
|
|
216
|
+
await pressButton(getByLabelText("Hide"));
|
|
217
|
+
await pressButton(getByLabelText("Show"));
|
|
218
|
+
expect(mockOnShow).toHaveBeenCalledTimes(1);
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
describe("hidden state", () => {
|
|
223
|
+
it("should render collapsed with the hidden heading", () => {
|
|
224
|
+
const {getByText, queryByText} = renderWithTheme(
|
|
225
|
+
<TextArea
|
|
226
|
+
aiSuggestion={{
|
|
227
|
+
onAdd: () => {},
|
|
228
|
+
status: "hidden",
|
|
229
|
+
text: "Hidden suggestion",
|
|
230
|
+
}}
|
|
231
|
+
onChange={() => {}}
|
|
232
|
+
value=""
|
|
233
|
+
/>
|
|
234
|
+
);
|
|
235
|
+
|
|
236
|
+
expect(getByText("AI-generated note (hidden)")).toBeTruthy();
|
|
237
|
+
expect(getByText("Show")).toBeTruthy();
|
|
238
|
+
expect(queryByText("Hidden suggestion")).toBeNull();
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it("should call onShow and expand when Show is pressed", async () => {
|
|
242
|
+
const mockOnShow = mock(() => {});
|
|
243
|
+
const {getByLabelText, getByText} = renderWithTheme(
|
|
244
|
+
<TextArea
|
|
245
|
+
aiSuggestion={{
|
|
246
|
+
onAdd: () => {},
|
|
247
|
+
onShow: mockOnShow,
|
|
248
|
+
status: "hidden",
|
|
249
|
+
text: "Hidden suggestion",
|
|
250
|
+
}}
|
|
251
|
+
onChange={() => {}}
|
|
252
|
+
testID="test"
|
|
253
|
+
value=""
|
|
254
|
+
/>
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
await pressButton(getByLabelText("Show"));
|
|
258
|
+
|
|
205
259
|
expect(mockOnShow).toHaveBeenCalledTimes(1);
|
|
260
|
+
expect(getByText("Hidden suggestion")).toBeTruthy();
|
|
206
261
|
});
|
|
207
262
|
});
|
|
208
263
|
|
|
209
264
|
describe("added state", () => {
|
|
210
|
-
it("should render added heading", () => {
|
|
211
|
-
const {getByText} = renderWithTheme(
|
|
265
|
+
it("should render collapsed with the added heading", () => {
|
|
266
|
+
const {getByText, queryByText} = renderWithTheme(
|
|
212
267
|
<TextArea
|
|
213
268
|
aiSuggestion={{
|
|
214
269
|
onAdd: () => {},
|
|
@@ -221,7 +276,104 @@ describe("AiSuggestionBox in TextArea", () => {
|
|
|
221
276
|
);
|
|
222
277
|
|
|
223
278
|
expect(getByText("AI-generated note added!")).toBeTruthy();
|
|
279
|
+
expect(getByText("Show")).toBeTruthy();
|
|
280
|
+
expect(queryByText("Added suggestion")).toBeNull();
|
|
281
|
+
});
|
|
282
|
+
|
|
283
|
+
it("should expand locally on Show without persisting, keeping Add to note available", async () => {
|
|
284
|
+
const mockOnShow = mock(() => {});
|
|
285
|
+
const {getByLabelText, getByText} = renderWithTheme(
|
|
286
|
+
<TextArea
|
|
287
|
+
aiSuggestion={{
|
|
288
|
+
onAdd: () => {},
|
|
289
|
+
onShow: mockOnShow,
|
|
290
|
+
status: "added",
|
|
291
|
+
text: "Added suggestion",
|
|
292
|
+
}}
|
|
293
|
+
onChange={() => {}}
|
|
294
|
+
testID="test"
|
|
295
|
+
value=""
|
|
296
|
+
/>
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
await pressButton(getByLabelText("Show"));
|
|
300
|
+
|
|
301
|
+
// Expanding an added suggestion must not call onShow — that would reset the
|
|
302
|
+
// persisted acceptance record.
|
|
303
|
+
expect(mockOnShow).not.toHaveBeenCalled();
|
|
224
304
|
expect(getByText("Added suggestion")).toBeTruthy();
|
|
305
|
+
expect(getByText("Add to note")).toBeTruthy();
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it("should collapse locally on Hide without persisting", async () => {
|
|
309
|
+
const mockOnHide = mock(() => {});
|
|
310
|
+
const {getByLabelText, getByText} = renderWithTheme(
|
|
311
|
+
<TextArea
|
|
312
|
+
aiSuggestion={{
|
|
313
|
+
onAdd: () => {},
|
|
314
|
+
onHide: mockOnHide,
|
|
315
|
+
status: "added",
|
|
316
|
+
text: "Added suggestion",
|
|
317
|
+
}}
|
|
318
|
+
onChange={() => {}}
|
|
319
|
+
testID="test"
|
|
320
|
+
value=""
|
|
321
|
+
/>
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
await pressButton(getByLabelText("Show"));
|
|
325
|
+
await pressButton(getByLabelText("Hide"));
|
|
326
|
+
|
|
327
|
+
expect(mockOnHide).not.toHaveBeenCalled();
|
|
328
|
+
expect(getByText("AI-generated note added!")).toBeTruthy();
|
|
329
|
+
});
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
describe("collapse behavior across status transitions", () => {
|
|
333
|
+
it("should collapse when the status transitions from ready to added", () => {
|
|
334
|
+
const {getByText, queryByText, rerender} = renderWithTheme(
|
|
335
|
+
<AiSuggestionBox onAdd={() => {}} status="ready" text="Suggestion text" />
|
|
336
|
+
);
|
|
337
|
+
|
|
338
|
+
expect(getByText("Suggestion text")).toBeTruthy();
|
|
339
|
+
|
|
340
|
+
rerender(<AiSuggestionBox onAdd={() => {}} status="added" text="Suggestion text" />);
|
|
341
|
+
|
|
342
|
+
expect(getByText("AI-generated note added!")).toBeTruthy();
|
|
343
|
+
expect(queryByText("Suggestion text")).toBeNull();
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
it("should keep the box expanded when a stale hide lands after a newer Show click", async () => {
|
|
347
|
+
const mockOnHide = mock(() => {});
|
|
348
|
+
const mockOnShow = mock(() => {});
|
|
349
|
+
const suggestion = {
|
|
350
|
+
onAdd: () => {},
|
|
351
|
+
onHide: mockOnHide,
|
|
352
|
+
onShow: mockOnShow,
|
|
353
|
+
text: "Suggestion text",
|
|
354
|
+
};
|
|
355
|
+
const {getByLabelText, getByText, queryByText, rerender} = renderWithTheme(
|
|
356
|
+
<AiSuggestionBox status="ready" {...suggestion} />
|
|
357
|
+
);
|
|
358
|
+
|
|
359
|
+
await pressButton(getByLabelText("Hide"));
|
|
360
|
+
expect(mockOnHide).toHaveBeenCalledTimes(1);
|
|
361
|
+
|
|
362
|
+
await pressButton(getByLabelText("Show"));
|
|
363
|
+
// A Show clicked while the hide is still in flight must persist the un-hide too,
|
|
364
|
+
// so the backend converges on the user's latest choice.
|
|
365
|
+
expect(mockOnShow).toHaveBeenCalledTimes(1);
|
|
366
|
+
expect(getByText("Suggestion text")).toBeTruthy();
|
|
367
|
+
|
|
368
|
+
// The earlier hide's refetch lands after the newer Show click — the box must not
|
|
369
|
+
// snap back to collapsed.
|
|
370
|
+
rerender(<AiSuggestionBox status="hidden" {...suggestion} />);
|
|
371
|
+
expect(getByText("Suggestion text")).toBeTruthy();
|
|
372
|
+
expect(queryByText("AI-generated note (hidden)")).toBeNull();
|
|
373
|
+
|
|
374
|
+
// The show mutation then lands and the box stays expanded.
|
|
375
|
+
rerender(<AiSuggestionBox status="ready" {...suggestion} />);
|
|
376
|
+
expect(getByText("Suggestion text")).toBeTruthy();
|
|
225
377
|
});
|
|
226
378
|
});
|
|
227
379
|
|
|
@@ -353,6 +505,23 @@ describe("AiSuggestionBox in TextArea", () => {
|
|
|
353
505
|
expect(component.toJSON()).toMatchSnapshot();
|
|
354
506
|
});
|
|
355
507
|
|
|
508
|
+
it("should match snapshot for hidden state", () => {
|
|
509
|
+
const component = renderWithTheme(
|
|
510
|
+
<TextArea
|
|
511
|
+
aiSuggestion={{
|
|
512
|
+
feedback: null,
|
|
513
|
+
onAdd: () => {},
|
|
514
|
+
status: "hidden",
|
|
515
|
+
text: "AI-generated suggestion text.",
|
|
516
|
+
}}
|
|
517
|
+
onChange={() => {}}
|
|
518
|
+
testID="test"
|
|
519
|
+
value=""
|
|
520
|
+
/>
|
|
521
|
+
);
|
|
522
|
+
expect(component.toJSON()).toMatchSnapshot();
|
|
523
|
+
});
|
|
524
|
+
|
|
356
525
|
it("should match snapshot for added state", () => {
|
|
357
526
|
const component = renderWithTheme(
|
|
358
527
|
<TextArea
|