@terreno/ui 57.2.0 → 57.3.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/.ai/guidelines/core.md +1 -1
- package/README.md +17 -8
- package/dist/ActionSheet.d.ts +3 -3
- package/dist/ActionSheet.js +2 -2
- package/dist/ActionSheet.js.map +1 -1
- package/dist/Box.d.ts +1 -1
- package/dist/Box.js +219 -177
- package/dist/Box.js.map +1 -1
- package/dist/Button.js +101 -34
- package/dist/Button.js.map +1 -1
- package/dist/Common.d.ts +119 -9
- package/dist/Common.js.map +1 -1
- package/dist/ConsentFormScreen.js +46 -12
- package/dist/ConsentFormScreen.js.map +1 -1
- package/dist/ConsentNavigator.d.ts +5 -1
- package/dist/ConsentNavigator.js.map +1 -1
- package/dist/DataTable.d.ts +2 -2
- package/dist/DataTable.js +203 -44
- package/dist/DataTable.js.map +1 -1
- package/dist/DataTableHeaderInfoMarkdown.d.ts +6 -0
- package/dist/DataTableHeaderInfoMarkdown.js +7 -0
- package/dist/DataTableHeaderInfoMarkdown.js.map +1 -0
- package/dist/EmojiSelector.d.ts +2 -46
- package/dist/EmojiSelector.js +46 -56
- package/dist/EmojiSelector.js.map +1 -1
- package/dist/GPTChat.js +1 -1
- package/dist/GPTChat.js.map +1 -1
- package/dist/Heading.d.ts +5 -2
- package/dist/Heading.js +6 -8
- package/dist/Heading.js.map +1 -1
- package/dist/Hyperlink.js.map +1 -1
- package/dist/Icon.d.ts +1 -2
- package/dist/Icon.js +4 -1
- package/dist/Icon.js.map +1 -1
- package/dist/MarkdownView.d.ts +6 -3
- package/dist/MarkdownView.js +45 -43
- package/dist/MarkdownView.js.map +1 -1
- package/dist/MediaQuery.d.ts +5 -3
- package/dist/MediaQuery.js +9 -40
- package/dist/MediaQuery.js.map +1 -1
- package/dist/OpenAPIContext.js +7 -6
- package/dist/OpenAPIContext.js.map +1 -1
- package/dist/Page.js +7 -1
- package/dist/Page.js.map +1 -1
- package/dist/PickerSelect.js +8 -1
- package/dist/PickerSelect.js.map +1 -1
- package/dist/Popover.d.ts +12 -0
- package/dist/Popover.js +37 -0
- package/dist/Popover.js.map +1 -0
- package/dist/PortalHost.js +10 -1
- package/dist/PortalHost.js.map +1 -1
- package/dist/ResponsiveBreakpoint.d.ts +65 -0
- package/dist/ResponsiveBreakpoint.js +111 -0
- package/dist/ResponsiveBreakpoint.js.map +1 -0
- package/dist/SplitPage.d.ts +2 -2
- package/dist/SplitPage.js +7 -12
- package/dist/SplitPage.js.map +1 -1
- package/dist/SplitPage.native.d.ts +2 -2
- package/dist/SplitPage.native.js +1 -6
- package/dist/SplitPage.native.js.map +1 -1
- package/dist/TapToEdit.js +12 -10
- package/dist/TapToEdit.js.map +1 -1
- package/dist/TerrenoFontProvider.d.ts +7 -0
- package/dist/TerrenoFontProvider.js +27 -0
- package/dist/TerrenoFontProvider.js.map +1 -0
- package/dist/TerrenoProvider.js +4 -2
- package/dist/TerrenoProvider.js.map +1 -1
- package/dist/Text.d.ts +5 -2
- package/dist/Text.js +6 -11
- package/dist/Text.js.map +1 -1
- package/dist/TextFieldNumberActionSheet.js +9 -2
- package/dist/TextFieldNumberActionSheet.js.map +1 -1
- package/dist/Theme.js +10 -8
- package/dist/Theme.js.map +1 -1
- package/dist/ToastNotifications.d.ts +4 -2
- package/dist/ToastNotifications.js.map +1 -1
- package/dist/Tooltip.d.ts +4 -3
- package/dist/Tooltip.js +14 -3
- package/dist/Tooltip.js.map +1 -1
- package/dist/Unifier.d.ts +26 -1
- package/dist/Unifier.js.map +1 -1
- package/dist/WebAddressAutocomplete.js +6 -1
- package/dist/WebAddressAutocomplete.js.map +1 -1
- package/dist/emojiCategories.d.ts +46 -0
- package/dist/emojiCategories.js +47 -0
- package/dist/emojiCategories.js.map +1 -0
- package/dist/index.d.ts +13 -13
- package/dist/index.js +2 -13
- package/dist/index.js.map +1 -1
- package/dist/lazyBoundaries/createLazyComponentExport.d.ts +6 -0
- package/dist/lazyBoundaries/createLazyComponentExport.js +35 -0
- package/dist/lazyBoundaries/createLazyComponentExport.js.map +1 -0
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts +41 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js +43 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -0
- package/dist/login/LoginScreen.d.ts +1 -0
- package/dist/login/LoginScreen.js +4 -2
- package/dist/login/LoginScreen.js.map +1 -1
- package/dist/login/loginTypes.d.ts +2 -0
- package/package.json +40 -1
- package/src/AIRequestExplorer.test.tsx +141 -0
- package/src/ActionSheet.tsx +9 -7
- package/src/AttachmentPreview.test.tsx +80 -0
- package/src/Box.test.tsx +97 -10
- package/src/Box.tsx +263 -200
- package/src/Button.test.tsx +207 -0
- package/src/Button.tsx +146 -48
- package/src/Common.ts +124 -25
- package/src/ConsentFormScreen.markdownGate.test.tsx +129 -0
- package/src/ConsentFormScreen.test.tsx +145 -8
- package/src/ConsentFormScreen.tsx +74 -25
- package/src/ConsentNavigator.tsx +13 -5
- package/src/DataTable.tsx +418 -147
- package/src/DataTableHeaderInfoMarkdown.test.tsx +21 -0
- package/src/DataTableHeaderInfoMarkdown.tsx +17 -0
- package/src/DataTableVirtualizationRegression.test.tsx +266 -0
- package/src/DateTimeField.test.tsx +54 -0
- package/src/EmojiSelector.test.tsx +33 -42
- package/src/EmojiSelector.tsx +60 -57
- package/src/FilePickerButton.test.tsx +167 -0
- package/src/FilterAccordion.test.tsx +37 -0
- package/src/FilterBoolean.test.tsx +96 -0
- package/src/FilterSelectMenu.test.tsx +23 -0
- package/src/GPTChat.test.tsx +696 -0
- package/src/GPTChat.tsx +2 -2
- package/src/GPTMemoryModal.test.tsx +67 -0
- package/src/Heading.tsx +8 -14
- package/src/HeightActionSheet.test.tsx +6 -9
- package/src/Hyperlink.tsx +5 -18
- package/src/Icon.tsx +6 -2
- package/src/MarkdownEditor.test.tsx +134 -0
- package/src/MarkdownEditorField.test.tsx +124 -0
- package/src/MarkdownView.test.tsx +55 -11
- package/src/MarkdownView.tsx +149 -150
- package/src/MediaQuery.ts +30 -34
- package/src/OpenAPIContext.tsx +36 -29
- package/src/OpenAPIRenderRegression.test.tsx +200 -0
- package/src/P0RenderRegression.test.tsx +214 -0
- package/src/P1RenderRegression.test.tsx +141 -0
- package/src/P2ButtonRenderRegression.test.tsx +158 -0
- package/src/Page.test.tsx +13 -0
- package/src/Page.tsx +25 -5
- package/src/PickerSelect.test.tsx +38 -0
- package/src/PickerSelect.tsx +7 -0
- package/src/Popover.test.tsx +151 -0
- package/src/Popover.tsx +211 -0
- package/src/PortalHost.tsx +12 -6
- package/src/ResponsiveBreakpoint.test.tsx +184 -0
- package/src/ResponsiveBreakpoint.tsx +195 -0
- package/src/RootImportRegression.test.tsx +62 -0
- package/src/SplitPage.native.tsx +5 -9
- package/src/SplitPage.tsx +16 -19
- package/src/TapToEdit.test.tsx +45 -0
- package/src/TapToEdit.tsx +23 -18
- package/src/TerrenoFontProvider.test.tsx +38 -0
- package/src/TerrenoFontProvider.tsx +50 -0
- package/src/TerrenoProvider.tsx +6 -1
- package/src/Text.tsx +8 -21
- package/src/TextFieldNumberActionSheet.test.tsx +100 -0
- package/src/TextFieldNumberActionSheet.tsx +11 -2
- package/src/Theme.test.tsx +27 -0
- package/src/Theme.tsx +15 -10
- package/src/Toast.tsx +1 -1
- package/src/ToastNotifications.tsx +4 -4
- package/src/Tooltip.test.tsx +64 -0
- package/src/Tooltip.tsx +18 -4
- package/src/Unifier.ts +26 -3
- package/src/WebAddressAutocomplete.tsx +6 -2
- package/src/__snapshots__/ActionSheet.test.tsx.snap +0 -36
- package/src/__snapshots__/AddressField.test.tsx.snap +1 -0
- package/src/__snapshots__/AttachmentPreview.test.tsx.snap +225 -0
- package/src/__snapshots__/CustomSelectField.test.tsx.snap +7 -0
- package/src/__snapshots__/DataTable.test.tsx.snap +793 -250
- package/src/__snapshots__/DecimalRangeActionSheet.test.tsx.snap +0 -8
- package/src/__snapshots__/EmojiSelector.test.tsx.snap +35555 -30
- package/src/__snapshots__/Field.test.tsx.snap +7 -0
- package/src/__snapshots__/FilterSelectMenu.test.tsx.snap +1 -0
- package/src/__snapshots__/HeightActionSheet.test.tsx.snap +0 -8
- package/src/__snapshots__/HeightField.test.tsx.snap +0 -20
- package/src/__snapshots__/NumberPickerActionSheet.test.tsx.snap +0 -8
- package/src/__snapshots__/Page.test.tsx.snap +13 -1
- package/src/__snapshots__/PickerSelect.test.tsx.snap +7 -0
- package/src/__snapshots__/SelectField.test.tsx.snap +6 -0
- package/src/__snapshots__/TimezonePicker.test.tsx.snap +6 -0
- package/src/benchmarks/importGraph.test.ts +71 -0
- package/src/benchmarks/importGraph.ts +136 -0
- package/src/benchmarks/importTiming.test.ts +42 -0
- package/src/benchmarks/importTiming.ts +86 -0
- package/src/bunSetup.ts +174 -32
- package/src/emojiCategories.test.ts +23 -0
- package/src/emojiCategories.ts +46 -0
- package/src/index.tsx +27 -13
- package/src/lazyBoundaries/createLazyComponentExport.test.tsx +104 -0
- package/src/lazyBoundaries/createLazyComponentExport.tsx +63 -0
- package/src/lazyBoundaries/heavyOptionalExports.test.tsx +33 -0
- package/src/lazyBoundaries/heavyOptionalExports.tsx +106 -0
- package/src/login/LoginScreen.test.tsx +9 -2
- package/src/login/LoginScreen.tsx +6 -2
- package/src/login/loginTypes.ts +2 -0
- package/src/table/TableDate.test.tsx +35 -1
- package/src/table/__snapshots__/TableBadge.test.tsx.snap +1 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import {act, render, waitFor} from "@testing-library/react-native";
|
|
2
|
+
import {assert} from "chai";
|
|
3
|
+
import type React from "react";
|
|
4
|
+
import {useEffect} from "react";
|
|
5
|
+
|
|
6
|
+
import {Box} from "./Box";
|
|
7
|
+
import {Heading} from "./Heading";
|
|
8
|
+
import {MarkdownView} from "./MarkdownView";
|
|
9
|
+
import {Text} from "./Text";
|
|
10
|
+
import {ThemeProvider, useTheme} from "./Theme";
|
|
11
|
+
|
|
12
|
+
interface ThemeMutationProps {
|
|
13
|
+
surfaceBase: "neutral000" | "error100";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const ThemeMutation: React.FC<ThemeMutationProps> = ({surfaceBase}) => {
|
|
17
|
+
const {setTheme, theme} = useTheme();
|
|
18
|
+
|
|
19
|
+
// Keep the provider mutation driven by props so rerender tests exercise context propagation.
|
|
20
|
+
useEffect((): void => {
|
|
21
|
+
const desiredColor = surfaceBase === "neutral000" ? "#FFFFFF" : "#D33232";
|
|
22
|
+
if (theme.surface.base === desiredColor) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
setTheme({surface: {base: surfaceBase}});
|
|
26
|
+
}, [setTheme, surfaceBase, theme.surface.base]);
|
|
27
|
+
|
|
28
|
+
return null;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const renderP0 = (element: React.ReactElement): ReturnType<typeof render> => {
|
|
32
|
+
return render(<ThemeProvider>{element}</ThemeProvider>);
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
describe("P0 component rerender regression coverage", () => {
|
|
36
|
+
it("updates Box layout and theme props without retaining stale styles", () => {
|
|
37
|
+
const result = renderP0(
|
|
38
|
+
<Box color="base" padding={1} testID="box">
|
|
39
|
+
first
|
|
40
|
+
</Box>
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
result.rerender(
|
|
44
|
+
<ThemeProvider>
|
|
45
|
+
<Box color="error" padding={4} testID="box">
|
|
46
|
+
second
|
|
47
|
+
</Box>
|
|
48
|
+
</ThemeProvider>
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
const box = result.getByTestId("box");
|
|
52
|
+
assert.equal(box.props.style.padding, 16);
|
|
53
|
+
assert.equal(box.props.style.backgroundColor, "#BD1111");
|
|
54
|
+
assert.include(box.children, "second");
|
|
55
|
+
assert.notInclude(box.children, "first");
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("does not leak border-adjusted sizing through the shared Box style map", () => {
|
|
59
|
+
const result = render(
|
|
60
|
+
<ThemeProvider>
|
|
61
|
+
<Box border="default" height={80} testID="bordered" width={100} />
|
|
62
|
+
<Box height={80} testID="plain" width={100} />
|
|
63
|
+
</ThemeProvider>
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
assert.equal(result.getByTestId("bordered").props.style.width, 104);
|
|
67
|
+
assert.equal(result.getByTestId("bordered").props.style.height, 84);
|
|
68
|
+
assert.equal(result.getByTestId("plain").props.style.width, 100);
|
|
69
|
+
assert.equal(result.getByTestId("plain").props.style.height, 80);
|
|
70
|
+
|
|
71
|
+
result.rerender(
|
|
72
|
+
<ThemeProvider>
|
|
73
|
+
<Box height={80} testID="bordered" width={100} />
|
|
74
|
+
<Box border="default" height={80} testID="plain" width={100} />
|
|
75
|
+
</ThemeProvider>
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
assert.equal(result.getByTestId("bordered").props.style.width, 100);
|
|
79
|
+
assert.equal(result.getByTestId("bordered").props.style.height, 80);
|
|
80
|
+
assert.equal(result.getByTestId("plain").props.style.width, 104);
|
|
81
|
+
assert.equal(result.getByTestId("plain").props.style.height, 84);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("switches Box host behavior when onClick changes", () => {
|
|
85
|
+
const onClick = (): void => {};
|
|
86
|
+
const result = renderP0(<Box testID="box" />);
|
|
87
|
+
|
|
88
|
+
assert.exists(result.getByTestId("box"));
|
|
89
|
+
result.rerender(
|
|
90
|
+
<ThemeProvider>
|
|
91
|
+
<Box onClick={onClick} testID="box" />
|
|
92
|
+
</ThemeProvider>
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
assert.exists(result.getByTestId("box-clickable"));
|
|
96
|
+
assert.isNull(result.queryByTestId("box"));
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("keeps a Box imperative handle stable and usable across rerenders", () => {
|
|
100
|
+
interface BoxHandle {
|
|
101
|
+
scrollTo: (y: number) => void;
|
|
102
|
+
scrollToEnd: () => void;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const boxRef = {current: null} as React.RefObject<BoxHandle | null>;
|
|
106
|
+
const result = renderP0(<Box padding={1} ref={boxRef} scroll />);
|
|
107
|
+
|
|
108
|
+
result.rerender(
|
|
109
|
+
<ThemeProvider>
|
|
110
|
+
<Box padding={2} ref={boxRef} scroll />
|
|
111
|
+
</ThemeProvider>
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
assert.exists(boxRef.current);
|
|
115
|
+
assert.isFunction(boxRef.current?.scrollTo);
|
|
116
|
+
assert.isFunction(boxRef.current?.scrollToEnd);
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
it("updates Text content, typography, color, and truncation props", () => {
|
|
120
|
+
const result = renderP0(
|
|
121
|
+
<Text color="primary" size="sm" testID="text">
|
|
122
|
+
first
|
|
123
|
+
</Text>
|
|
124
|
+
);
|
|
125
|
+
|
|
126
|
+
result.rerender(
|
|
127
|
+
<ThemeProvider>
|
|
128
|
+
<Text bold color="error" numberOfLines={2} size="xl" skipLinking testID="text">
|
|
129
|
+
second
|
|
130
|
+
</Text>
|
|
131
|
+
</ThemeProvider>
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
const text = result.getByTestId("text");
|
|
135
|
+
assert.equal(text.props.style.color, "#BD1111");
|
|
136
|
+
assert.equal(text.props.style.fontFamily, "text-bold");
|
|
137
|
+
assert.equal(text.props.style.fontSize, 18);
|
|
138
|
+
assert.equal(text.props.numberOfLines, 2);
|
|
139
|
+
assert.include(text.children, "second");
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
it("updates Heading children and presentation props", () => {
|
|
143
|
+
const result = renderP0(
|
|
144
|
+
<Heading color="primary" size="sm" testID="heading">
|
|
145
|
+
first
|
|
146
|
+
</Heading>
|
|
147
|
+
);
|
|
148
|
+
|
|
149
|
+
result.rerender(
|
|
150
|
+
<ThemeProvider>
|
|
151
|
+
<Heading align="right" color="error" size="2xl" testID="heading">
|
|
152
|
+
second
|
|
153
|
+
</Heading>
|
|
154
|
+
</ThemeProvider>
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
const heading = result.getByTestId("heading");
|
|
158
|
+
assert.equal(heading.props.style.color, "#BD1111");
|
|
159
|
+
assert.equal(heading.props.style.fontSize, 32);
|
|
160
|
+
assert.equal(heading.props.style.textAlign, "right");
|
|
161
|
+
assert.include(heading.children, "second");
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("updates MarkdownView content and inverted theme styles", async () => {
|
|
165
|
+
const result = renderP0(<MarkdownView>{"**first**"}</MarkdownView>);
|
|
166
|
+
await waitFor(() => {
|
|
167
|
+
assert.include(JSON.stringify(result.toJSON()), "first");
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
await act(async () => {
|
|
171
|
+
result.rerender(
|
|
172
|
+
<ThemeProvider>
|
|
173
|
+
<MarkdownView inverted>{"# second"}</MarkdownView>
|
|
174
|
+
</ThemeProvider>
|
|
175
|
+
);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
await waitFor(() => {
|
|
179
|
+
const serialized = JSON.stringify(result.toJSON());
|
|
180
|
+
assert.include(serialized, "second");
|
|
181
|
+
assert.include(serialized, "#FFFFFF");
|
|
182
|
+
assert.notInclude(serialized, "first");
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it("propagates theme updates through memoization boundaries", async () => {
|
|
187
|
+
const result = render(
|
|
188
|
+
<ThemeProvider>
|
|
189
|
+
<ThemeMutation surfaceBase="neutral000" />
|
|
190
|
+
<Box color="base" testID="themed-box">
|
|
191
|
+
<Text color="primary" testID="themed-text">
|
|
192
|
+
themed
|
|
193
|
+
</Text>
|
|
194
|
+
</Box>
|
|
195
|
+
</ThemeProvider>
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
result.rerender(
|
|
199
|
+
<ThemeProvider>
|
|
200
|
+
<ThemeMutation surfaceBase="error100" />
|
|
201
|
+
<Box color="base" testID="themed-box">
|
|
202
|
+
<Text color="primary" testID="themed-text">
|
|
203
|
+
themed
|
|
204
|
+
</Text>
|
|
205
|
+
</Box>
|
|
206
|
+
</ThemeProvider>
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
await act(async (): Promise<void> => {});
|
|
210
|
+
|
|
211
|
+
assert.equal(result.getByTestId("themed-box").props.style.backgroundColor, "#D33232");
|
|
212
|
+
assert.equal(result.getByTestId("themed-text").props.style.color, "#1C1C1C");
|
|
213
|
+
});
|
|
214
|
+
});
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import {act, render} from "@testing-library/react-native";
|
|
2
|
+
import {assert} from "chai";
|
|
3
|
+
import type React from "react";
|
|
4
|
+
import {useEffect} from "react";
|
|
5
|
+
import {View} from "react-native";
|
|
6
|
+
|
|
7
|
+
import type {CustomIconProps, DataTableCellData, DataTableColumn, IconRegistryMap} from "./Common";
|
|
8
|
+
import {DataTable} from "./DataTable";
|
|
9
|
+
import {Icon} from "./Icon";
|
|
10
|
+
import {IconRegistryProvider} from "./IconRegistry";
|
|
11
|
+
import {ThemeProvider, useTheme} from "./Theme";
|
|
12
|
+
|
|
13
|
+
interface ThemeMutationProps {
|
|
14
|
+
textPrimary: "neutral900" | "error100";
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const ThemeMutation: React.FC<ThemeMutationProps> = ({textPrimary}) => {
|
|
18
|
+
const {setTheme, theme} = useTheme();
|
|
19
|
+
|
|
20
|
+
// Drive the theme from props so memoized icons must still follow context updates.
|
|
21
|
+
useEffect((): void => {
|
|
22
|
+
const desiredColor = textPrimary === "neutral900" ? "#1C1C1C" : "#D33232";
|
|
23
|
+
if (theme.text.primary === desiredColor) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
setTheme({text: {primary: textPrimary}});
|
|
27
|
+
}, [setTheme, textPrimary, theme.text.primary]);
|
|
28
|
+
|
|
29
|
+
return null;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
describe("P1 component rerender regression coverage", () => {
|
|
33
|
+
it("skips equivalent DataTable renders and preserves changed cell values", () => {
|
|
34
|
+
const columns: DataTableColumn[] = [{columnType: "counted", title: "Value", width: 120}];
|
|
35
|
+
const baselineData: DataTableCellData[][] = [[{value: "first"}]];
|
|
36
|
+
const changedData: DataTableCellData[][] = [[{value: "second"}]];
|
|
37
|
+
let renderCount = 0;
|
|
38
|
+
const CountedCell: React.FC<{cellData: DataTableCellData}> = ({cellData}) => {
|
|
39
|
+
renderCount += 1;
|
|
40
|
+
return <View accessibilityLabel={String(cellData.value)} />;
|
|
41
|
+
};
|
|
42
|
+
const customColumnComponentMap = {counted: CountedCell};
|
|
43
|
+
const result = render(
|
|
44
|
+
<ThemeProvider>
|
|
45
|
+
<DataTable
|
|
46
|
+
columns={columns}
|
|
47
|
+
customColumnComponentMap={customColumnComponentMap}
|
|
48
|
+
data={baselineData}
|
|
49
|
+
/>
|
|
50
|
+
</ThemeProvider>
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
assert.equal(renderCount, 1);
|
|
54
|
+
result.rerender(
|
|
55
|
+
<ThemeProvider>
|
|
56
|
+
<DataTable
|
|
57
|
+
columns={columns}
|
|
58
|
+
customColumnComponentMap={customColumnComponentMap}
|
|
59
|
+
data={baselineData}
|
|
60
|
+
/>
|
|
61
|
+
</ThemeProvider>
|
|
62
|
+
);
|
|
63
|
+
assert.equal(renderCount, 1);
|
|
64
|
+
|
|
65
|
+
result.rerender(
|
|
66
|
+
<ThemeProvider>
|
|
67
|
+
<DataTable
|
|
68
|
+
columns={columns}
|
|
69
|
+
customColumnComponentMap={customColumnComponentMap}
|
|
70
|
+
data={changedData}
|
|
71
|
+
/>
|
|
72
|
+
</ThemeProvider>
|
|
73
|
+
);
|
|
74
|
+
assert.equal(renderCount, 2);
|
|
75
|
+
assert.exists(result.getByLabelText("second"));
|
|
76
|
+
assert.isNull(result.queryByLabelText("first"));
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it("skips equivalent Icon renders and preserves changed icon props", () => {
|
|
80
|
+
let renderCount = 0;
|
|
81
|
+
const CountedIcon: React.FC<CustomIconProps> = ({color, size, testID}) => {
|
|
82
|
+
renderCount += 1;
|
|
83
|
+
return <View accessibilityLabel={`${color}:${size}`} testID={testID} />;
|
|
84
|
+
};
|
|
85
|
+
const icons: IconRegistryMap = {testCustomIcon: CountedIcon};
|
|
86
|
+
const result = render(
|
|
87
|
+
<ThemeProvider>
|
|
88
|
+
<IconRegistryProvider icons={icons}>
|
|
89
|
+
<Icon iconName="testCustomIcon" size="md" testID="counted-icon" />
|
|
90
|
+
</IconRegistryProvider>
|
|
91
|
+
</ThemeProvider>
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
assert.equal(renderCount, 1);
|
|
95
|
+
result.rerender(
|
|
96
|
+
<ThemeProvider>
|
|
97
|
+
<IconRegistryProvider icons={icons}>
|
|
98
|
+
<Icon iconName="testCustomIcon" size="md" testID="counted-icon" />
|
|
99
|
+
</IconRegistryProvider>
|
|
100
|
+
</ThemeProvider>
|
|
101
|
+
);
|
|
102
|
+
assert.equal(renderCount, 1);
|
|
103
|
+
|
|
104
|
+
result.rerender(
|
|
105
|
+
<ThemeProvider>
|
|
106
|
+
<IconRegistryProvider icons={icons}>
|
|
107
|
+
<Icon iconName="testCustomIcon" size="lg" testID="counted-icon" />
|
|
108
|
+
</IconRegistryProvider>
|
|
109
|
+
</ThemeProvider>
|
|
110
|
+
);
|
|
111
|
+
assert.equal(renderCount, 2);
|
|
112
|
+
assert.equal(result.getByTestId("counted-icon").props.accessibilityLabel, "#1C1C1C:20");
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("propagates theme changes through the memoized Icon boundary", async () => {
|
|
116
|
+
const ThemeAwareIcon: React.FC<CustomIconProps> = ({color, testID}) => {
|
|
117
|
+
return <View accessibilityLabel={color} testID={testID} />;
|
|
118
|
+
};
|
|
119
|
+
const icons: IconRegistryMap = {testCustomIcon: ThemeAwareIcon};
|
|
120
|
+
const result = render(
|
|
121
|
+
<ThemeProvider>
|
|
122
|
+
<ThemeMutation textPrimary="neutral900" />
|
|
123
|
+
<IconRegistryProvider icons={icons}>
|
|
124
|
+
<Icon iconName="testCustomIcon" testID="themed-icon" />
|
|
125
|
+
</IconRegistryProvider>
|
|
126
|
+
</ThemeProvider>
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
result.rerender(
|
|
130
|
+
<ThemeProvider>
|
|
131
|
+
<ThemeMutation textPrimary="error100" />
|
|
132
|
+
<IconRegistryProvider icons={icons}>
|
|
133
|
+
<Icon iconName="testCustomIcon" testID="themed-icon" />
|
|
134
|
+
</IconRegistryProvider>
|
|
135
|
+
</ThemeProvider>
|
|
136
|
+
);
|
|
137
|
+
await act(async (): Promise<void> => {});
|
|
138
|
+
|
|
139
|
+
assert.equal(result.getByTestId("themed-icon").props.accessibilityLabel, "#D33232");
|
|
140
|
+
});
|
|
141
|
+
});
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import {act, fireEvent, render} from "@testing-library/react-native";
|
|
2
|
+
import {assert} from "chai";
|
|
3
|
+
import type React from "react";
|
|
4
|
+
import {useEffect} from "react";
|
|
5
|
+
import {View} from "react-native";
|
|
6
|
+
|
|
7
|
+
import {Button} from "./Button";
|
|
8
|
+
import type {CustomIconProps, IconRegistryMap} from "./Common";
|
|
9
|
+
import {IconRegistryProvider} from "./IconRegistry";
|
|
10
|
+
import {ThemeProvider, useTheme} from "./Theme";
|
|
11
|
+
|
|
12
|
+
interface ThemeMutationProps {
|
|
13
|
+
surfaceSecondaryDark: "secondary800" | "error100";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const handlePress = async (): Promise<void> => {};
|
|
17
|
+
|
|
18
|
+
const ThemeMutation: React.FC<ThemeMutationProps> = ({surfaceSecondaryDark}) => {
|
|
19
|
+
const {setTheme, theme} = useTheme();
|
|
20
|
+
|
|
21
|
+
// Drive the theme from props so memoized buttons must still follow context updates.
|
|
22
|
+
useEffect((): void => {
|
|
23
|
+
const desiredColor = surfaceSecondaryDark === "secondary800" ? "#092E3A" : "#D33232";
|
|
24
|
+
if (theme.surface.secondaryDark === desiredColor) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
setTheme({surface: {secondaryDark: surfaceSecondaryDark}});
|
|
28
|
+
}, [setTheme, surfaceSecondaryDark, theme.surface.secondaryDark]);
|
|
29
|
+
|
|
30
|
+
return null;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
describe("P2 Button rerender regression coverage", () => {
|
|
34
|
+
it("skips equivalent renders and preserves changed button props", () => {
|
|
35
|
+
let renderCount = 0;
|
|
36
|
+
const CountedIcon: React.FC<CustomIconProps> = ({color, size, testID}) => {
|
|
37
|
+
renderCount += 1;
|
|
38
|
+
return <View accessibilityLabel={`${color}:${size}`} testID={testID} />;
|
|
39
|
+
};
|
|
40
|
+
const icons: IconRegistryMap = {testCustomIcon: CountedIcon};
|
|
41
|
+
const result = render(
|
|
42
|
+
<ThemeProvider>
|
|
43
|
+
<IconRegistryProvider icons={icons}>
|
|
44
|
+
<Button
|
|
45
|
+
iconName="testCustomIcon"
|
|
46
|
+
onClick={handlePress}
|
|
47
|
+
testID="counted-button"
|
|
48
|
+
text="Initial"
|
|
49
|
+
/>
|
|
50
|
+
</IconRegistryProvider>
|
|
51
|
+
</ThemeProvider>
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
assert.equal(renderCount, 1);
|
|
55
|
+
result.rerender(
|
|
56
|
+
<ThemeProvider>
|
|
57
|
+
<IconRegistryProvider icons={icons}>
|
|
58
|
+
<Button
|
|
59
|
+
iconName="testCustomIcon"
|
|
60
|
+
onClick={handlePress}
|
|
61
|
+
testID="counted-button"
|
|
62
|
+
text="Initial"
|
|
63
|
+
/>
|
|
64
|
+
</IconRegistryProvider>
|
|
65
|
+
</ThemeProvider>
|
|
66
|
+
);
|
|
67
|
+
assert.equal(renderCount, 1);
|
|
68
|
+
|
|
69
|
+
result.rerender(
|
|
70
|
+
<ThemeProvider>
|
|
71
|
+
<IconRegistryProvider icons={icons}>
|
|
72
|
+
<Button
|
|
73
|
+
iconName="testCustomIcon"
|
|
74
|
+
onClick={handlePress}
|
|
75
|
+
testID="counted-button"
|
|
76
|
+
text="Changed"
|
|
77
|
+
/>
|
|
78
|
+
</IconRegistryProvider>
|
|
79
|
+
</ThemeProvider>
|
|
80
|
+
);
|
|
81
|
+
assert.equal(renderCount, 2);
|
|
82
|
+
assert.exists(result.getByText("Changed"));
|
|
83
|
+
assert.isNull(result.queryByText("Initial"));
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("propagates theme changes through the memoized Button boundary", async () => {
|
|
87
|
+
const ThemeAwareIcon: React.FC<CustomIconProps> = ({color, testID}) => {
|
|
88
|
+
return <View accessibilityLabel={color} testID={testID} />;
|
|
89
|
+
};
|
|
90
|
+
const icons: IconRegistryMap = {testCustomIcon: ThemeAwareIcon};
|
|
91
|
+
const result = render(
|
|
92
|
+
<ThemeProvider>
|
|
93
|
+
<ThemeMutation surfaceSecondaryDark="secondary800" />
|
|
94
|
+
<IconRegistryProvider icons={icons}>
|
|
95
|
+
<Button
|
|
96
|
+
iconName="testCustomIcon"
|
|
97
|
+
onClick={handlePress}
|
|
98
|
+
testID="themed-button"
|
|
99
|
+
text="Themed"
|
|
100
|
+
variant="ghost"
|
|
101
|
+
/>
|
|
102
|
+
</IconRegistryProvider>
|
|
103
|
+
</ThemeProvider>
|
|
104
|
+
);
|
|
105
|
+
const initialColor = result.UNSAFE_getByType(ThemeAwareIcon).props.color;
|
|
106
|
+
|
|
107
|
+
result.rerender(
|
|
108
|
+
<ThemeProvider>
|
|
109
|
+
<ThemeMutation surfaceSecondaryDark="error100" />
|
|
110
|
+
<IconRegistryProvider icons={icons}>
|
|
111
|
+
<Button
|
|
112
|
+
iconName="testCustomIcon"
|
|
113
|
+
onClick={handlePress}
|
|
114
|
+
testID="themed-button"
|
|
115
|
+
text="Themed"
|
|
116
|
+
variant="ghost"
|
|
117
|
+
/>
|
|
118
|
+
</IconRegistryProvider>
|
|
119
|
+
</ThemeProvider>
|
|
120
|
+
);
|
|
121
|
+
await act(async (): Promise<void> => {});
|
|
122
|
+
|
|
123
|
+
const changedColor = result.UNSAFE_getByType(ThemeAwareIcon).props.color;
|
|
124
|
+
assert.notEqual(changedColor, initialColor);
|
|
125
|
+
assert.equal(changedColor, "#D33232");
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("uses the latest confirmation props after a changed-prop update", async () => {
|
|
129
|
+
const result = render(
|
|
130
|
+
<ThemeProvider>
|
|
131
|
+
<Button
|
|
132
|
+
confirmationText="Initial confirmation"
|
|
133
|
+
onClick={handlePress}
|
|
134
|
+
text="Confirm"
|
|
135
|
+
withConfirmation
|
|
136
|
+
/>
|
|
137
|
+
</ThemeProvider>
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
result.rerender(
|
|
141
|
+
<ThemeProvider>
|
|
142
|
+
<Button
|
|
143
|
+
confirmationText="Changed confirmation"
|
|
144
|
+
onClick={handlePress}
|
|
145
|
+
text="Confirm"
|
|
146
|
+
withConfirmation
|
|
147
|
+
/>
|
|
148
|
+
</ThemeProvider>
|
|
149
|
+
);
|
|
150
|
+
await act(async () => {
|
|
151
|
+
fireEvent.press(result.getByText("Confirm"));
|
|
152
|
+
await Promise.resolve();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
assert.exists(await result.findByText("Changed confirmation"));
|
|
156
|
+
assert.isNull(result.queryByText("Initial confirmation"));
|
|
157
|
+
});
|
|
158
|
+
});
|
package/src/Page.test.tsx
CHANGED
|
@@ -263,6 +263,19 @@ describe("Page", () => {
|
|
|
263
263
|
expect(routerBack).toHaveBeenCalled();
|
|
264
264
|
});
|
|
265
265
|
|
|
266
|
+
it("invokes onBack instead of router.back when provided", () => {
|
|
267
|
+
const onBack = mock(() => {});
|
|
268
|
+
routerBack.mockClear();
|
|
269
|
+
const {getByTestId} = renderWithTheme(
|
|
270
|
+
<Page backButton navigation={mockNavigation} onBack={onBack} title="Page">
|
|
271
|
+
<Text>Content</Text>
|
|
272
|
+
</Page>
|
|
273
|
+
);
|
|
274
|
+
fireEvent.press(getByTestId("icon-button-chevron-left"));
|
|
275
|
+
expect(onBack).toHaveBeenCalled();
|
|
276
|
+
expect(routerBack).not.toHaveBeenCalled();
|
|
277
|
+
});
|
|
278
|
+
|
|
266
279
|
it("invokes router.back when the close button is pressed", () => {
|
|
267
280
|
routerBack.mockClear();
|
|
268
281
|
const {getByTestId} = renderWithTheme(
|
package/src/Page.tsx
CHANGED
|
@@ -20,14 +20,28 @@ export class Page extends React.Component<PageProps, {}> {
|
|
|
20
20
|
return null;
|
|
21
21
|
}
|
|
22
22
|
return (
|
|
23
|
-
<Box direction="row" display="flex" width="100%">
|
|
23
|
+
<Box direction="row" display="flex" position="relative" width="100%">
|
|
24
24
|
{this.props.backButton && (
|
|
25
|
-
<Box
|
|
25
|
+
<Box
|
|
26
|
+
alignItems="center"
|
|
27
|
+
display="block"
|
|
28
|
+
justifyContent="center"
|
|
29
|
+
paddingX={4}
|
|
30
|
+
paddingY={3}
|
|
31
|
+
position="relative"
|
|
32
|
+
zIndex={1}
|
|
33
|
+
>
|
|
26
34
|
<IconButton
|
|
27
35
|
accessibilityHint="Navigate back"
|
|
28
|
-
accessibilityLabel=""
|
|
36
|
+
accessibilityLabel="Back"
|
|
29
37
|
iconName="chevron-left"
|
|
30
|
-
onClick={() =>
|
|
38
|
+
onClick={() => {
|
|
39
|
+
if (this.props.onBack) {
|
|
40
|
+
this.props.onBack();
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
router.back();
|
|
44
|
+
}}
|
|
31
45
|
/>
|
|
32
46
|
</Box>
|
|
33
47
|
)}
|
|
@@ -42,7 +56,13 @@ export class Page extends React.Component<PageProps, {}> {
|
|
|
42
56
|
</Box>
|
|
43
57
|
)}
|
|
44
58
|
{Boolean(this.props.title) && (
|
|
45
|
-
<Box
|
|
59
|
+
<Box
|
|
60
|
+
dangerouslySetInlineStyle={{__style: {pointerEvents: "box-none"}}}
|
|
61
|
+
direction="column"
|
|
62
|
+
display="flex"
|
|
63
|
+
flex="grow"
|
|
64
|
+
justifyContent="center"
|
|
65
|
+
>
|
|
46
66
|
<Heading align="center">{this.props.title}</Heading>
|
|
47
67
|
</Box>
|
|
48
68
|
)}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {describe, expect, it, mock} from "bun:test";
|
|
2
2
|
import {act, fireEvent} from "@testing-library/react-native";
|
|
3
3
|
import {assert} from "chai";
|
|
4
|
+
import {StyleSheet} from "react-native";
|
|
4
5
|
import type {ReactTestInstance} from "react-test-renderer";
|
|
5
6
|
|
|
6
7
|
import {RNPickerSelect} from "./PickerSelect";
|
|
@@ -522,6 +523,43 @@ describe("PickerSelect", () => {
|
|
|
522
523
|
}
|
|
523
524
|
});
|
|
524
525
|
|
|
526
|
+
// A trigger label that cannot shrink below its intrinsic width overflows narrow
|
|
527
|
+
// fields (e.g. the am/pm and timezone pickers in DateTimeField) and pushes the
|
|
528
|
+
// chevron outside the field border.
|
|
529
|
+
it("lets the searchable trigger input shrink inside a narrow field", () => {
|
|
530
|
+
ensureDocument();
|
|
531
|
+
savedOS = PlatformModule.OS;
|
|
532
|
+
try {
|
|
533
|
+
PlatformModule.OS = "web";
|
|
534
|
+
const {getByTestId} = renderWithTheme(
|
|
535
|
+
<RNPickerSelect {...searchEnabledWebProps} value="1" />
|
|
536
|
+
);
|
|
537
|
+
const style = StyleSheet.flatten(getByTestId("text_input").props.style);
|
|
538
|
+
expect(style.minWidth).toBe(0);
|
|
539
|
+
expect(style.flex).toBe(1);
|
|
540
|
+
} finally {
|
|
541
|
+
PlatformModule.OS = savedOS;
|
|
542
|
+
restoreDocument();
|
|
543
|
+
}
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
it("lets the non-searchable trigger label shrink inside a narrow field", () => {
|
|
547
|
+
ensureDocument();
|
|
548
|
+
savedOS = PlatformModule.OS;
|
|
549
|
+
try {
|
|
550
|
+
PlatformModule.OS = "web";
|
|
551
|
+
const {getByTestId} = renderWithTheme(
|
|
552
|
+
<RNPickerSelect {...defaultProps} disableSearch value="1" />
|
|
553
|
+
);
|
|
554
|
+
const style = StyleSheet.flatten(getByTestId("text_input").props.style);
|
|
555
|
+
expect(style.minWidth).toBe(0);
|
|
556
|
+
expect(style.flex).toBe(1);
|
|
557
|
+
} finally {
|
|
558
|
+
PlatformModule.OS = savedOS;
|
|
559
|
+
restoreDocument();
|
|
560
|
+
}
|
|
561
|
+
});
|
|
562
|
+
|
|
525
563
|
it("selects a filtered option and reports the original option index", async () => {
|
|
526
564
|
ensureDocument();
|
|
527
565
|
savedOS = PlatformModule.OS;
|
package/src/PickerSelect.tsx
CHANGED
|
@@ -435,6 +435,9 @@ export const RNPickerSelect = ({
|
|
|
435
435
|
const baseTextInputStyle = {
|
|
436
436
|
color: disabled ? theme.text.secondaryLight : theme.text.primary,
|
|
437
437
|
flex: 1,
|
|
438
|
+
// Text inputs have an intrinsic width; without this they refuse to shrink inside
|
|
439
|
+
// narrow triggers and push the chevron outside the field border on web.
|
|
440
|
+
minWidth: 0,
|
|
438
441
|
};
|
|
439
442
|
return (
|
|
440
443
|
<View
|
|
@@ -724,6 +727,9 @@ export const RNPickerSelect = ({
|
|
|
724
727
|
flex: 1,
|
|
725
728
|
fontFamily: "text" as const,
|
|
726
729
|
fontSize: 16,
|
|
730
|
+
// Text inputs have an intrinsic width; without this they refuse to shrink inside
|
|
731
|
+
// narrow triggers and push the chevron outside the field border on web.
|
|
732
|
+
minWidth: 0,
|
|
727
733
|
paddingLeft: 0,
|
|
728
734
|
paddingRight: 8,
|
|
729
735
|
paddingVertical: 0,
|
|
@@ -804,6 +810,7 @@ export const RNPickerSelect = ({
|
|
|
804
810
|
flex: 1,
|
|
805
811
|
fontFamily: "text",
|
|
806
812
|
fontSize: 16,
|
|
813
|
+
minWidth: 0,
|
|
807
814
|
paddingRight: 8,
|
|
808
815
|
}}
|
|
809
816
|
testID="text_input"
|