@terreno/ui 57.20.0 → 57.22.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 +81 -0
- package/dist/Common.d.ts +60 -27
- 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 +2 -2
- package/dist/DataTable.js.map +1 -1
- package/dist/DateTimeField.js +6 -6
- package/dist/DateTimeField.js.map +1 -1
- package/dist/HeightField.js +8 -8
- package/dist/HeightField.js.map +1 -1
- package/dist/OtpField.js +4 -4
- package/dist/OtpField.js.map +1 -1
- package/dist/PickerSelect.js +9 -9
- package/dist/PickerSelect.js.map +1 -1
- package/dist/TapToEdit.d.ts +1 -1
- package/dist/TapToEdit.d.ts.map +1 -1
- package/dist/TapToEdit.js.map +1 -1
- package/dist/TextField.js +4 -4
- package/dist/TextField.js.map +1 -1
- package/dist/Theme.d.ts.map +1 -1
- package/dist/Theme.js +16 -0
- package/dist/Theme.js.map +1 -1
- package/package.json +4 -2
- package/src/ActionSheet.test.tsx +13 -13
- package/src/AddressField.test.tsx +9 -3
- package/src/AnnouncementNavigator.test.tsx +4 -4
- package/src/Badge.test.tsx +1 -1
- package/src/Banner.test.tsx +0 -1
- package/src/Box.test.tsx +82 -74
- package/src/Button.test.tsx +11 -6
- package/src/Card.test.tsx +2 -2
- package/src/Common.ts +65 -29
- package/src/ConflictSheet.test.tsx +5 -5
- package/src/ConsentFormScreen.test.tsx +3 -1
- package/src/ConsentNavigator.test.tsx +1 -2
- package/src/CustomSelectField.test.tsx +16 -4
- package/src/DataTable.test.tsx +4 -4
- package/src/DataTable.tsx +2 -1
- package/src/DataTableVirtualizationRegression.test.tsx +1 -0
- package/src/DateTimeActionSheet.test.tsx +2 -0
- package/src/DateTimeField.test.tsx +3 -12
- package/src/DateTimeField.tsx +6 -6
- package/src/DismissButton.test.tsx +22 -4
- package/src/EmailField.test.tsx +13 -22
- package/src/EmojiSelector.test.tsx +2 -2
- package/src/ErrorBoundary.test.tsx +5 -3
- package/src/Field.test.tsx +20 -44
- package/src/GPTChat.test.tsx +24 -16
- package/src/Heading.test.tsx +1 -1
- package/src/HeightField.tsx +8 -8
- package/src/Icon.test.tsx +2 -2
- package/src/Image.test.tsx +1 -1
- package/src/Link.test.tsx +11 -4
- package/src/MarkdownView.test.tsx +1 -1
- package/src/MobileAddressAutoComplete.test.tsx +2 -1
- package/src/Modal.test.tsx +7 -2
- package/src/ModalSheet.test.tsx +5 -4
- package/src/MultiselectField.test.tsx +17 -3
- package/src/NumberField.test.tsx +14 -14
- package/src/NumberPickerActionSheet.test.tsx +1 -1
- package/src/OpenAPIContext.test.tsx +4 -4
- package/src/OpenAPIRenderRegression.test.tsx +1 -1
- package/src/OtpField.tsx +4 -4
- package/src/P0RenderRegression.test.tsx +7 -1
- package/src/P1RenderRegression.test.tsx +1 -0
- package/src/P2ButtonRenderRegression.test.tsx +1 -0
- package/src/Page.test.tsx +1 -1
- package/src/PhoneNumberField.test.tsx +14 -38
- package/src/PickerSelect.tsx +9 -9
- package/src/Popover.test.tsx +2 -2
- package/src/RadioField.test.tsx +7 -2
- package/src/SegmentedControl.test.tsx +21 -12
- package/src/SidebarNavigation.test.tsx +18 -6
- package/src/Signature.test.tsx +20 -23
- package/src/Slider.test.tsx +1 -1
- package/src/SplitPage.test.tsx +15 -5
- package/src/TapToEdit.test.tsx +38 -15
- package/src/TapToEdit.tsx +1 -1
- package/src/TerrenoFontProvider.test.tsx +1 -1
- package/src/Text.test.tsx +4 -4
- package/src/TextField.test.tsx +82 -9
- package/src/TextField.tsx +4 -4
- package/src/Theme.test.tsx +49 -0
- package/src/Theme.tsx +16 -0
- package/src/Toast.test.tsx +5 -5
- package/src/ToastNotifications.test.tsx +73 -70
- package/src/ToastNotifications.webModal.test.tsx +2 -2
- package/src/Tooltip.test.tsx +3 -3
- package/src/UnifiedAddressAutoComplete.test.tsx +1 -1
- package/src/UserInactivity.test.tsx +4 -2
- package/src/WebAddressAutocomplete.test.tsx +12 -12
- package/src/WebDropdownMenu.test.tsx +16 -15
- package/src/__snapshots__/Card.test.tsx.snap +1 -1
- package/src/__snapshots__/DismissButton.test.tsx.snap +3 -3
- package/src/__snapshots__/Field.test.tsx.snap +4 -2
- package/src/__snapshots__/Heading.test.tsx.snap +1 -1
- package/src/__snapshots__/Image.test.tsx.snap +1 -1
- package/src/__snapshots__/Page.test.tsx.snap +2 -2
- package/src/__snapshots__/Text.test.tsx.snap +1 -1
- package/src/asks/AskCard.test.tsx +16 -13
- package/src/asks/AskFiles.test.tsx +5 -1
- package/src/asks/askFileRefs.test.ts +1 -1
- package/src/asks/askSummary.test.ts +2 -2
- package/src/benchmarks/importTiming.ts +1 -1
- package/src/blocks/BlocksView.test.tsx +20 -11
- package/src/bunSetup.ts +1 -1
- package/src/dataTableFilters.test.tsx +1 -1
- package/src/isolated/ListDetailLayout.isolated.tsx +2 -4
- package/src/login/LoginScreen.test.tsx +6 -6
- package/src/security/PasswordCard.test.tsx +3 -3
- package/src/signUp/SignUpScreen.test.tsx +4 -4
- package/src/table/tableContext.test.tsx +5 -5
- package/src/test-utils.tsx +56 -1
- package/src/testing/reactDomServer.d.ts +7 -0
- package/src/useConsentForms.test.ts +1 -1
package/src/Signature.test.tsx
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {afterEach, describe, expect, it, mock} from "bun:test";
|
|
2
2
|
import {act, fireEvent} from "@testing-library/react-native";
|
|
3
3
|
import {View} from "react-native";
|
|
4
|
+
import type {ReactTestInstance} from "react-test-renderer";
|
|
4
5
|
|
|
5
6
|
import {Signature} from "./Signature";
|
|
6
|
-
import {renderWithTheme} from "./test-utils";
|
|
7
|
+
import {findAllByHostType, findByHostType, renderWithTheme} from "./test-utils";
|
|
7
8
|
|
|
8
9
|
const createMockContext = (): Record<string, ReturnType<typeof mock>> => ({
|
|
9
10
|
beginPath: mock(() => {}),
|
|
@@ -14,14 +15,10 @@ const createMockContext = (): Record<string, ReturnType<typeof mock>> => ({
|
|
|
14
15
|
});
|
|
15
16
|
|
|
16
17
|
const patchCanvasRefs = (
|
|
17
|
-
container:
|
|
18
|
-
findAll: (
|
|
19
|
-
predicate: (node: {type: string}) => boolean
|
|
20
|
-
) => Array<{props: Record<string, unknown>}>;
|
|
21
|
-
},
|
|
18
|
+
container: ReactTestInstance,
|
|
22
19
|
ctx: Record<string, ReturnType<typeof mock>>
|
|
23
20
|
): HTMLCanvasElement => {
|
|
24
|
-
const canvasNodes = container
|
|
21
|
+
const canvasNodes = findAllByHostType(container, "canvas");
|
|
25
22
|
const canvasNode = canvasNodes[0];
|
|
26
23
|
const canvas = {
|
|
27
24
|
getContext: mock(() => ctx),
|
|
@@ -65,8 +62,8 @@ describe("Signature", () => {
|
|
|
65
62
|
|
|
66
63
|
it("scales the web canvas to the available container width", () => {
|
|
67
64
|
const mockOnChange = mock(() => {});
|
|
68
|
-
const {
|
|
69
|
-
const canvas =
|
|
65
|
+
const {UNSAFE_root} = renderWithTheme(<Signature onChange={mockOnChange} />);
|
|
66
|
+
const canvas = findByHostType(UNSAFE_root, "canvas");
|
|
70
67
|
expect(canvas.props.style).toMatchObject({maxWidth: "100%", width: "100%"});
|
|
71
68
|
});
|
|
72
69
|
|
|
@@ -81,8 +78,8 @@ describe("Signature", () => {
|
|
|
81
78
|
const mockOnChange = mock(() => {});
|
|
82
79
|
const moveTo = mock(() => {});
|
|
83
80
|
const lineTo = mock(() => {});
|
|
84
|
-
const {
|
|
85
|
-
const canvas =
|
|
81
|
+
const {UNSAFE_root} = renderWithTheme(<Signature onChange={mockOnChange} />);
|
|
82
|
+
const canvas = findByHostType(UNSAFE_root, "canvas");
|
|
86
83
|
canvas.props.ref.current = {
|
|
87
84
|
clientHeight: 180,
|
|
88
85
|
clientWidth: 150,
|
|
@@ -131,7 +128,7 @@ describe("Signature", () => {
|
|
|
131
128
|
|
|
132
129
|
patchCanvasRefs(UNSAFE_root, ctx);
|
|
133
130
|
|
|
134
|
-
const canvasNodes = UNSAFE_root
|
|
131
|
+
const canvasNodes = findAllByHostType(UNSAFE_root, "canvas");
|
|
135
132
|
const canvasProps = canvasNodes[0].props as Record<string, (...args: unknown[]) => void>;
|
|
136
133
|
|
|
137
134
|
act(() => {
|
|
@@ -153,7 +150,7 @@ describe("Signature", () => {
|
|
|
153
150
|
|
|
154
151
|
patchCanvasRefs(UNSAFE_root, ctx);
|
|
155
152
|
|
|
156
|
-
const canvasNodes = UNSAFE_root
|
|
153
|
+
const canvasNodes = findAllByHostType(UNSAFE_root, "canvas");
|
|
157
154
|
const canvasProps = canvasNodes[0].props as Record<string, (...args: unknown[]) => void>;
|
|
158
155
|
|
|
159
156
|
act(() => {
|
|
@@ -181,7 +178,7 @@ describe("Signature", () => {
|
|
|
181
178
|
|
|
182
179
|
patchCanvasRefs(UNSAFE_root, ctx);
|
|
183
180
|
|
|
184
|
-
const canvasNodes = UNSAFE_root
|
|
181
|
+
const canvasNodes = findAllByHostType(UNSAFE_root, "canvas");
|
|
185
182
|
const canvasProps = canvasNodes[0].props as Record<string, (...args: unknown[]) => void>;
|
|
186
183
|
|
|
187
184
|
act(() => {
|
|
@@ -202,7 +199,7 @@ describe("Signature", () => {
|
|
|
202
199
|
|
|
203
200
|
const canvas = patchCanvasRefs(UNSAFE_root, ctx);
|
|
204
201
|
|
|
205
|
-
const canvasNodes = UNSAFE_root
|
|
202
|
+
const canvasNodes = findAllByHostType(UNSAFE_root, "canvas");
|
|
206
203
|
const canvasProps = canvasNodes[0].props as Record<string, (...args: unknown[]) => void>;
|
|
207
204
|
|
|
208
205
|
// Start drawing
|
|
@@ -243,7 +240,7 @@ describe("Signature", () => {
|
|
|
243
240
|
|
|
244
241
|
patchCanvasRefs(UNSAFE_root, ctx);
|
|
245
242
|
|
|
246
|
-
const canvasNodes = UNSAFE_root
|
|
243
|
+
const canvasNodes = findAllByHostType(UNSAFE_root, "canvas");
|
|
247
244
|
const canvasProps = canvasNodes[0].props as Record<string, (...args: unknown[]) => void>;
|
|
248
245
|
|
|
249
246
|
// pointerDown without any move (no drawing)
|
|
@@ -273,7 +270,7 @@ describe("Signature", () => {
|
|
|
273
270
|
|
|
274
271
|
patchCanvasRefs(UNSAFE_root, ctx);
|
|
275
272
|
|
|
276
|
-
const canvasNodes = UNSAFE_root
|
|
273
|
+
const canvasNodes = findAllByHostType(UNSAFE_root, "canvas");
|
|
277
274
|
const canvasProps = canvasNodes[0].props as Record<string, (...args: unknown[]) => void>;
|
|
278
275
|
|
|
279
276
|
act(() => {
|
|
@@ -295,7 +292,7 @@ describe("Signature", () => {
|
|
|
295
292
|
|
|
296
293
|
patchCanvasRefs(UNSAFE_root, ctx);
|
|
297
294
|
|
|
298
|
-
const canvasNodes = UNSAFE_root
|
|
295
|
+
const canvasNodes = findAllByHostType(UNSAFE_root, "canvas");
|
|
299
296
|
const canvasProps = canvasNodes[0].props as Record<string, (...args: unknown[]) => void>;
|
|
300
297
|
|
|
301
298
|
// Draw something
|
|
@@ -331,7 +328,7 @@ describe("Signature", () => {
|
|
|
331
328
|
|
|
332
329
|
patchCanvasRefs(UNSAFE_root, ctx);
|
|
333
330
|
|
|
334
|
-
const canvasNodes = UNSAFE_root
|
|
331
|
+
const canvasNodes = findAllByHostType(UNSAFE_root, "canvas");
|
|
335
332
|
const canvasProps = canvasNodes[0].props as Record<string, (...args: unknown[]) => void>;
|
|
336
333
|
|
|
337
334
|
// Draw
|
|
@@ -366,10 +363,10 @@ describe("Signature", () => {
|
|
|
366
363
|
it("ignores pointer down when the canvas ref is missing", () => {
|
|
367
364
|
const mockOnChange = mock(() => {});
|
|
368
365
|
const mockOnStart = mock(() => {});
|
|
369
|
-
const {
|
|
366
|
+
const {UNSAFE_root} = renderWithTheme(
|
|
370
367
|
<Signature onChange={mockOnChange} onStart={mockOnStart} />
|
|
371
368
|
);
|
|
372
|
-
const canvas =
|
|
369
|
+
const canvas = findByHostType(UNSAFE_root, "canvas");
|
|
373
370
|
canvas.props.ref.current = null;
|
|
374
371
|
|
|
375
372
|
act(() => {
|
|
@@ -385,8 +382,8 @@ describe("Signature", () => {
|
|
|
385
382
|
it("falls back to raw offsets when the canvas has no measurable size", () => {
|
|
386
383
|
const mockOnChange = mock(() => {});
|
|
387
384
|
const moveTo = mock(() => {});
|
|
388
|
-
const {
|
|
389
|
-
const canvas =
|
|
385
|
+
const {UNSAFE_root} = renderWithTheme(<Signature onChange={mockOnChange} />);
|
|
386
|
+
const canvas = findByHostType(UNSAFE_root, "canvas");
|
|
390
387
|
canvas.props.ref.current = {
|
|
391
388
|
clientHeight: 0,
|
|
392
389
|
clientWidth: 0,
|
package/src/Slider.test.tsx
CHANGED
package/src/SplitPage.test.tsx
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import {afterAll, afterEach, beforeEach, describe, expect, it, mock, spyOn} from "bun:test";
|
|
2
2
|
import {act, fireEvent} from "@testing-library/react-native";
|
|
3
3
|
import {forwardRef, type ReactElement, type ReactNode, type Ref, useImperativeHandle} from "react";
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
type ScaledSize,
|
|
6
|
+
ScrollView,
|
|
7
|
+
type StyleProp,
|
|
8
|
+
StyleSheet,
|
|
9
|
+
useWindowDimensions,
|
|
10
|
+
View,
|
|
11
|
+
type ViewStyle,
|
|
12
|
+
} from "react-native";
|
|
5
13
|
import type {ReactTestInstance} from "react-test-renderer";
|
|
6
14
|
|
|
7
15
|
import {getRounding, getSpacing} from "./Common";
|
|
@@ -53,11 +61,13 @@ const setWindowWidth = (width: number): (() => void) => {
|
|
|
53
61
|
};
|
|
54
62
|
};
|
|
55
63
|
|
|
56
|
-
const styleWidth = (style:
|
|
64
|
+
const styleWidth = (style: StyleProp<ViewStyle>): ViewStyle["width"] =>
|
|
65
|
+
StyleSheet.flatten(style)?.width;
|
|
57
66
|
|
|
58
|
-
const styleBorderRadius = (style:
|
|
67
|
+
const styleBorderRadius = (style: StyleProp<ViewStyle>): ViewStyle["borderRadius"] =>
|
|
68
|
+
StyleSheet.flatten(style)?.borderRadius;
|
|
59
69
|
|
|
60
|
-
const flattenedStyle = (style:
|
|
70
|
+
const flattenedStyle = (style: StyleProp<ViewStyle>): ViewStyle => {
|
|
61
71
|
return StyleSheet.flatten(style) ?? {};
|
|
62
72
|
};
|
|
63
73
|
|
|
@@ -1102,7 +1112,7 @@ describe("SplitPage", () => {
|
|
|
1102
1112
|
const expectClippingPane = (
|
|
1103
1113
|
pane: ReactTestInstance,
|
|
1104
1114
|
borderRadius: number,
|
|
1105
|
-
width:
|
|
1115
|
+
width: ViewStyle["width"]
|
|
1106
1116
|
): void => {
|
|
1107
1117
|
const style = flattenedStyle(pane.props.style);
|
|
1108
1118
|
expect(style.borderRadius).toBe(borderRadius);
|
package/src/TapToEdit.test.tsx
CHANGED
|
@@ -8,14 +8,14 @@ import {renderWithTheme} from "./test-utils";
|
|
|
8
8
|
describe("TapToEdit", () => {
|
|
9
9
|
it("renders correctly with text value", () => {
|
|
10
10
|
const {toJSON} = renderWithTheme(
|
|
11
|
-
<TapToEdit setValue={() => {}} title="Name" value="John Doe" />
|
|
11
|
+
<TapToEdit setValue={() => {}} title="Name" type="text" value="John Doe" />
|
|
12
12
|
);
|
|
13
13
|
expect(toJSON()).toMatchSnapshot();
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
it("displays title and value", () => {
|
|
17
17
|
const {getByText} = renderWithTheme(
|
|
18
|
-
<TapToEdit setValue={() => {}} title="Email" value="test@example.com" />
|
|
18
|
+
<TapToEdit setValue={() => {}} title="Email" type="text" value="test@example.com" />
|
|
19
19
|
);
|
|
20
20
|
expect(getByText("Email")).toBeTruthy();
|
|
21
21
|
expect(getByText("test@example.com")).toBeTruthy();
|
|
@@ -23,21 +23,27 @@ describe("TapToEdit", () => {
|
|
|
23
23
|
|
|
24
24
|
it("renders non-editable when editable is false", () => {
|
|
25
25
|
const {toJSON} = renderWithTheme(
|
|
26
|
-
<TapToEdit editable={false} title="Read Only" value="Cannot edit this" />
|
|
26
|
+
<TapToEdit editable={false} title="Read Only" type="text" value="Cannot edit this" />
|
|
27
27
|
);
|
|
28
28
|
expect(toJSON()).toMatchSnapshot();
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
it("renders edit icon when editable", () => {
|
|
32
32
|
const {toJSON} = renderWithTheme(
|
|
33
|
-
<TapToEdit
|
|
33
|
+
<TapToEdit
|
|
34
|
+
editable
|
|
35
|
+
setValue={() => {}}
|
|
36
|
+
title="Editable Field"
|
|
37
|
+
type="text"
|
|
38
|
+
value="Click to edit"
|
|
39
|
+
/>
|
|
34
40
|
);
|
|
35
41
|
expect(toJSON()).toMatchSnapshot();
|
|
36
42
|
});
|
|
37
43
|
|
|
38
44
|
it("shows editing mode when isEditing is true", () => {
|
|
39
45
|
const {toJSON} = renderWithTheme(
|
|
40
|
-
<TapToEdit isEditing setValue={() => {}} title="Field" value="Editing..." />
|
|
46
|
+
<TapToEdit isEditing setValue={() => {}} title="Field" type="text" value="Editing..." />
|
|
41
47
|
);
|
|
42
48
|
expect(toJSON()).toMatchSnapshot();
|
|
43
49
|
});
|
|
@@ -49,6 +55,7 @@ describe("TapToEdit", () => {
|
|
|
49
55
|
onlyShowHelperTextWhileEditing={false}
|
|
50
56
|
setValue={() => {}}
|
|
51
57
|
title="Name"
|
|
58
|
+
type="text"
|
|
52
59
|
value=""
|
|
53
60
|
/>
|
|
54
61
|
);
|
|
@@ -75,6 +82,7 @@ describe("TapToEdit", () => {
|
|
|
75
82
|
editable={false}
|
|
76
83
|
title="Custom"
|
|
77
84
|
transform={(val) => `Transformed: ${val}`}
|
|
85
|
+
type="text"
|
|
78
86
|
value="data"
|
|
79
87
|
/>
|
|
80
88
|
);
|
|
@@ -95,7 +103,13 @@ describe("TapToEdit", () => {
|
|
|
95
103
|
|
|
96
104
|
it("renders multiselect type as comma-joined string", () => {
|
|
97
105
|
const {getByText} = renderWithTheme(
|
|
98
|
-
<TapToEdit
|
|
106
|
+
<TapToEdit
|
|
107
|
+
editable={false}
|
|
108
|
+
options={[]}
|
|
109
|
+
title="Tags"
|
|
110
|
+
type="multiselect"
|
|
111
|
+
value={["a", "b", "c"]}
|
|
112
|
+
/>
|
|
99
113
|
);
|
|
100
114
|
expect(getByText("a, b, c")).toBeTruthy();
|
|
101
115
|
});
|
|
@@ -177,14 +191,14 @@ describe("TapToEdit", () => {
|
|
|
177
191
|
|
|
178
192
|
it("throws when editable is true and setValue is not provided", () => {
|
|
179
193
|
expect(() =>
|
|
180
|
-
renderWithTheme(<TapToEdit editable title="Required Save" value="foo" />)
|
|
194
|
+
renderWithTheme(<TapToEdit editable title="Required Save" type="text" value="foo" />)
|
|
181
195
|
).toThrow();
|
|
182
196
|
});
|
|
183
197
|
|
|
184
198
|
it("enters editing mode when Edit button is pressed", async () => {
|
|
185
199
|
const setValue = mock(() => {});
|
|
186
200
|
const {getByLabelText, queryByText} = renderWithTheme(
|
|
187
|
-
<TapToEdit setValue={setValue} title="Name" value="Jane" />
|
|
201
|
+
<TapToEdit setValue={setValue} title="Name" type="text" value="Jane" />
|
|
188
202
|
);
|
|
189
203
|
await act(async () => {
|
|
190
204
|
fireEvent.press(getByLabelText("Edit"));
|
|
@@ -196,7 +210,7 @@ describe("TapToEdit", () => {
|
|
|
196
210
|
it("calls setValue with initial value and exits editing on Cancel", async () => {
|
|
197
211
|
const setValue = mock(() => {});
|
|
198
212
|
const {getByLabelText, getByText} = renderWithTheme(
|
|
199
|
-
<TapToEdit setValue={setValue} title="Name" value="Jane" />
|
|
213
|
+
<TapToEdit setValue={setValue} title="Name" type="text" value="Jane" />
|
|
200
214
|
);
|
|
201
215
|
await act(async () => {
|
|
202
216
|
fireEvent.press(getByLabelText("Edit"));
|
|
@@ -210,7 +224,7 @@ describe("TapToEdit", () => {
|
|
|
210
224
|
it("reverts to original value (not edited value) when Cancel is pressed", async () => {
|
|
211
225
|
const setValue = mock((_v: unknown) => {});
|
|
212
226
|
const {getByLabelText, getByText} = renderWithTheme(
|
|
213
|
-
<TapToEdit setValue={setValue} title="Name" value="Jane" />
|
|
227
|
+
<TapToEdit setValue={setValue} title="Name" type="text" value="Jane" />
|
|
214
228
|
);
|
|
215
229
|
await act(async () => {
|
|
216
230
|
fireEvent.press(getByLabelText("Edit"));
|
|
@@ -227,7 +241,14 @@ describe("TapToEdit", () => {
|
|
|
227
241
|
const setValue = mock(() => {});
|
|
228
242
|
const onSave = mock(() => Promise.resolve());
|
|
229
243
|
const {getByLabelText, getByText} = renderWithTheme(
|
|
230
|
-
<TapToEdit
|
|
244
|
+
<TapToEdit
|
|
245
|
+
onSave={onSave}
|
|
246
|
+
setValue={setValue}
|
|
247
|
+
showClearButton
|
|
248
|
+
title="Name"
|
|
249
|
+
type="text"
|
|
250
|
+
value="Jane"
|
|
251
|
+
/>
|
|
231
252
|
);
|
|
232
253
|
await act(async () => {
|
|
233
254
|
fireEvent.press(getByLabelText("Edit"));
|
|
@@ -243,7 +264,7 @@ describe("TapToEdit", () => {
|
|
|
243
264
|
const setValue = mock(() => {});
|
|
244
265
|
const onSave = mock(() => Promise.resolve());
|
|
245
266
|
const {getByLabelText, getByText} = renderWithTheme(
|
|
246
|
-
<TapToEdit onSave={onSave} setValue={setValue} title="Name" value="Jane" />
|
|
267
|
+
<TapToEdit onSave={onSave} setValue={setValue} title="Name" type="text" value="Jane" />
|
|
247
268
|
);
|
|
248
269
|
await act(async () => {
|
|
249
270
|
fireEvent.press(getByLabelText("Edit"));
|
|
@@ -261,7 +282,7 @@ describe("TapToEdit", () => {
|
|
|
261
282
|
console.error = errorMock;
|
|
262
283
|
|
|
263
284
|
const {getByLabelText, getByText} = renderWithTheme(
|
|
264
|
-
<TapToEdit setValue={setValue} title="Name" value="Jane" />
|
|
285
|
+
<TapToEdit setValue={setValue} title="Name" type="text" value="Jane" />
|
|
265
286
|
);
|
|
266
287
|
await act(async () => {
|
|
267
288
|
fireEvent.press(getByLabelText("Edit"));
|
|
@@ -389,6 +410,7 @@ describe("TapToEdit - additional function coverage", () => {
|
|
|
389
410
|
editable={false}
|
|
390
411
|
helperText="Should be hidden in title"
|
|
391
412
|
title="Field"
|
|
413
|
+
type="text"
|
|
392
414
|
value="val"
|
|
393
415
|
/>
|
|
394
416
|
);
|
|
@@ -406,7 +428,7 @@ describe("TapToEdit - additional function coverage", () => {
|
|
|
406
428
|
|
|
407
429
|
it("forwards testID to the edit control", () => {
|
|
408
430
|
const {getByTestId} = renderWithTheme(
|
|
409
|
-
<TapToEdit setValue={() => {}} testID="profile.name" title="Name" value="Jane" />
|
|
431
|
+
<TapToEdit setValue={() => {}} testID="profile.name" title="Name" type="text" value="Jane" />
|
|
410
432
|
);
|
|
411
433
|
expect(getByTestId("profile.name.edit-clickable")).toBeTruthy();
|
|
412
434
|
});
|
|
@@ -419,6 +441,7 @@ describe("TapToEdit - additional function coverage", () => {
|
|
|
419
441
|
showClearButton
|
|
420
442
|
testID="profile.name"
|
|
421
443
|
title="Name"
|
|
444
|
+
type="text"
|
|
422
445
|
value="Jane"
|
|
423
446
|
/>
|
|
424
447
|
);
|
|
@@ -435,7 +458,7 @@ describe("TapToEdit - additional function coverage", () => {
|
|
|
435
458
|
|
|
436
459
|
it("does not set action testIDs when testID is omitted", async () => {
|
|
437
460
|
const {getByLabelText, queryByTestId} = renderWithTheme(
|
|
438
|
-
<TapToEdit setValue={() => {}} showClearButton title="Name" value="Jane" />
|
|
461
|
+
<TapToEdit setValue={() => {}} showClearButton title="Name" type="text" value="Jane" />
|
|
439
462
|
);
|
|
440
463
|
|
|
441
464
|
expect(queryByTestId("undefined.edit-clickable")).toBeNull();
|
package/src/TapToEdit.tsx
CHANGED
|
@@ -27,7 +27,7 @@ const TapToEditTitle: FC<{
|
|
|
27
27
|
);
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
-
export const formatAddress = (address: AddressInterface
|
|
30
|
+
export const formatAddress = (address: Partial<AddressInterface>, asString = false): string => {
|
|
31
31
|
let city = "";
|
|
32
32
|
if (address?.city) {
|
|
33
33
|
city = address?.state || address.zipcode ? `${address.city}, ` : `${address.city}`;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import {describe, it, type mock} from "bun:test";
|
|
2
2
|
import {useFonts as useTextFonts} from "@expo-google-fonts/nunito";
|
|
3
3
|
import {useFonts as useHeadingFonts} from "@expo-google-fonts/titillium-web";
|
|
4
4
|
import {render} from "@testing-library/react-native";
|
package/src/Text.test.tsx
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import {describe, expect, it, spyOn} from "bun:test";
|
|
2
2
|
import {render} from "@testing-library/react-native";
|
|
3
3
|
import {createRef} from "react";
|
|
4
|
-
import type {Text as NativeText} from "react-native";
|
|
4
|
+
import type {Text as NativeText, TextProps} from "react-native";
|
|
5
5
|
|
|
6
6
|
import {Text} from "./Text";
|
|
7
7
|
import {ThemeProvider} from "./Theme";
|
|
8
|
-
import {renderWithTheme} from "./test-utils";
|
|
8
|
+
import {elementProps, renderWithTheme} from "./test-utils";
|
|
9
9
|
|
|
10
10
|
describe("Text", () => {
|
|
11
11
|
it("renders correctly with default props", () => {
|
|
@@ -116,7 +116,7 @@ describe("Text", () => {
|
|
|
116
116
|
|
|
117
117
|
// Color tests
|
|
118
118
|
it("renders with secondary color", () => {
|
|
119
|
-
const {toJSON} = renderWithTheme(<Text color="
|
|
119
|
+
const {toJSON} = renderWithTheme(<Text color="secondaryDark">Secondary color</Text>);
|
|
120
120
|
expect(toJSON()).toMatchSnapshot();
|
|
121
121
|
});
|
|
122
122
|
|
|
@@ -177,7 +177,7 @@ describe("Text", () => {
|
|
|
177
177
|
</Text>,
|
|
178
178
|
{
|
|
179
179
|
createNodeMock: (element) =>
|
|
180
|
-
element.
|
|
180
|
+
elementProps<TextProps>(element).accessibilityRole === "header" ? nativeText : null,
|
|
181
181
|
wrapper: ThemeProvider,
|
|
182
182
|
}
|
|
183
183
|
);
|
package/src/TextField.test.tsx
CHANGED
|
@@ -5,6 +5,7 @@ import type {ReactElement} from "react";
|
|
|
5
5
|
import type {TextInput} from "react-native";
|
|
6
6
|
import type {TextFieldProps} from "./Common";
|
|
7
7
|
import {TextField} from "./TextField";
|
|
8
|
+
import {defaultThemePrimitives, useTheme} from "./Theme";
|
|
8
9
|
import {renderWithTheme} from "./test-utils";
|
|
9
10
|
|
|
10
11
|
describe("TextField", () => {
|
|
@@ -399,21 +400,25 @@ describe("TextField", () => {
|
|
|
399
400
|
const originalRequestAnimationFrame = globalThis.requestAnimationFrame;
|
|
400
401
|
const originalSetTimeout = globalThis.setTimeout;
|
|
401
402
|
let scheduledRefocus: (() => void) | undefined;
|
|
402
|
-
const setTimeoutSpy = spyOn(globalThis, "setTimeout").mockImplementation(
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
403
|
+
const setTimeoutSpy = spyOn(globalThis, "setTimeout").mockImplementation(((
|
|
404
|
+
handler: () => void,
|
|
405
|
+
timeout?: number,
|
|
406
|
+
...args: unknown[]
|
|
407
|
+
) => {
|
|
408
|
+
scheduledRefocus = handler;
|
|
409
|
+
return originalSetTimeout(() => {}, timeout, ...args);
|
|
410
|
+
}) as unknown as typeof setTimeout);
|
|
408
411
|
reactNative.Platform.OS = "web";
|
|
409
|
-
|
|
412
|
+
(
|
|
413
|
+
globalThis as {requestAnimationFrame?: typeof requestAnimationFrame}
|
|
414
|
+
).requestAnimationFrame = undefined;
|
|
410
415
|
|
|
411
416
|
try {
|
|
412
417
|
const {getByDisplayValue, getByTestId} = renderWithTheme(
|
|
413
418
|
<TextField onChange={mockOnChange} testID="pw" type="password" value="hunter2" />
|
|
414
419
|
);
|
|
415
420
|
const input = getByDisplayValue("hunter2");
|
|
416
|
-
const webInput = {focus: () =>
|
|
421
|
+
const webInput = {focus: (): void => {}};
|
|
417
422
|
const ref = (input.props as unknown as {ref?: (value: TextInput | null) => void}).ref;
|
|
418
423
|
assert.isFunction(ref);
|
|
419
424
|
const focusSpy = mock(() => {});
|
|
@@ -770,8 +775,10 @@ describe("TextField", () => {
|
|
|
770
775
|
|
|
771
776
|
it("warns for not-yet-supported field types", () => {
|
|
772
777
|
const warnSpy = spyOn(console, "warn").mockImplementation(() => {});
|
|
778
|
+
// TextFieldProps excludes numberRange; untyped callers can still pass it.
|
|
779
|
+
const unsupportedType = "numberRange" as unknown as TextFieldProps["type"];
|
|
773
780
|
try {
|
|
774
|
-
renderWithTheme(<TextField onChange={mockOnChange} type=
|
|
781
|
+
renderWithTheme(<TextField onChange={mockOnChange} type={unsupportedType} value="" />);
|
|
775
782
|
expect(warnSpy).toHaveBeenCalledWith("numberRange is not yet supported");
|
|
776
783
|
} finally {
|
|
777
784
|
warnSpy.mockRestore();
|
|
@@ -1167,4 +1174,70 @@ describe("TextField", () => {
|
|
|
1167
1174
|
}
|
|
1168
1175
|
});
|
|
1169
1176
|
});
|
|
1177
|
+
|
|
1178
|
+
describe("field theming", () => {
|
|
1179
|
+
type ThemeContextValue = ReturnType<typeof useTheme>;
|
|
1180
|
+
|
|
1181
|
+
const renderWithFieldTheme = (
|
|
1182
|
+
props: Partial<TextFieldProps> = {}
|
|
1183
|
+
): {captured: () => ThemeContextValue | undefined; findBox: (color: string) => unknown[]} => {
|
|
1184
|
+
let captured: ThemeContextValue | undefined;
|
|
1185
|
+
const Capture = (): null => {
|
|
1186
|
+
captured = useTheme();
|
|
1187
|
+
return null;
|
|
1188
|
+
};
|
|
1189
|
+
const view = renderWithTheme(
|
|
1190
|
+
<>
|
|
1191
|
+
<Capture />
|
|
1192
|
+
<TextField onChange={() => {}} testID="themed-field" value="" {...props} />
|
|
1193
|
+
</>
|
|
1194
|
+
);
|
|
1195
|
+
const findBox = (color: string): unknown[] =>
|
|
1196
|
+
view.UNSAFE_root.findAll(
|
|
1197
|
+
(node) =>
|
|
1198
|
+
typeof node.type === "string" &&
|
|
1199
|
+
node.props.style?.backgroundColor === color &&
|
|
1200
|
+
node.props.style?.borderRadius === 4
|
|
1201
|
+
);
|
|
1202
|
+
return {captured: () => captured, findBox};
|
|
1203
|
+
};
|
|
1204
|
+
|
|
1205
|
+
it("paints the input box from field.background and field.border", () => {
|
|
1206
|
+
const {captured, findBox} = renderWithFieldTheme();
|
|
1207
|
+
act(() => {
|
|
1208
|
+
captured()?.setTheme({field: {background: "primary000", border: "primary500"}});
|
|
1209
|
+
});
|
|
1210
|
+
const boxes = findBox(defaultThemePrimitives.primary000) as {
|
|
1211
|
+
props: {style: {borderColor: string}};
|
|
1212
|
+
}[];
|
|
1213
|
+
assert.isAbove(boxes.length, 0);
|
|
1214
|
+
assert.equal(boxes[0].props.style.borderColor, defaultThemePrimitives.primary500);
|
|
1215
|
+
});
|
|
1216
|
+
|
|
1217
|
+
it("paints a disabled input from field.backgroundDisabled and field.borderDisabled", () => {
|
|
1218
|
+
const {captured, findBox} = renderWithFieldTheme({disabled: true});
|
|
1219
|
+
act(() => {
|
|
1220
|
+
captured()?.setTheme({
|
|
1221
|
+
field: {backgroundDisabled: "accent050", borderDisabled: "accent700"},
|
|
1222
|
+
});
|
|
1223
|
+
});
|
|
1224
|
+
const boxes = findBox(defaultThemePrimitives.accent050) as {
|
|
1225
|
+
props: {style: {borderColor: string}};
|
|
1226
|
+
}[];
|
|
1227
|
+
assert.isAbove(boxes.length, 0);
|
|
1228
|
+
assert.equal(boxes[0].props.style.borderColor, defaultThemePrimitives.accent700);
|
|
1229
|
+
});
|
|
1230
|
+
|
|
1231
|
+
it("paints an error border from field.borderError", () => {
|
|
1232
|
+
const {captured, findBox} = renderWithFieldTheme({errorText: "Required"});
|
|
1233
|
+
act(() => {
|
|
1234
|
+
captured()?.setTheme({field: {borderError: "warning200"}});
|
|
1235
|
+
});
|
|
1236
|
+
const boxes = findBox(defaultThemePrimitives.neutral000) as {
|
|
1237
|
+
props: {style: {borderColor: string}};
|
|
1238
|
+
}[];
|
|
1239
|
+
assert.isAbove(boxes.length, 0);
|
|
1240
|
+
assert.equal(boxes[0].props.style.borderColor, defaultThemePrimitives.warning200);
|
|
1241
|
+
});
|
|
1242
|
+
});
|
|
1170
1243
|
});
|
package/src/TextField.tsx
CHANGED
|
@@ -213,11 +213,11 @@ export const TextField: FC<TextFieldProps> = ({
|
|
|
213
213
|
const visibilityToggleWebProps =
|
|
214
214
|
Platform.OS === "web" ? {onMouseDown: preventVisibilityToggleBlur} : {};
|
|
215
215
|
|
|
216
|
-
let borderColor = focused ? theme.
|
|
216
|
+
let borderColor = focused ? theme.field.borderFocus : theme.field.border;
|
|
217
217
|
if (disabled) {
|
|
218
|
-
borderColor = theme.
|
|
218
|
+
borderColor = theme.field.borderDisabled;
|
|
219
219
|
} else if (errorText && !focused) {
|
|
220
|
-
borderColor = theme.
|
|
220
|
+
borderColor = theme.field.borderError;
|
|
221
221
|
}
|
|
222
222
|
const borderWidth = focused ? 3 : errorText ? 2 : 1;
|
|
223
223
|
|
|
@@ -327,7 +327,7 @@ export const TextField: FC<TextFieldProps> = ({
|
|
|
327
327
|
)}
|
|
328
328
|
<View
|
|
329
329
|
style={{
|
|
330
|
-
backgroundColor: disabled ? theme.
|
|
330
|
+
backgroundColor: disabled ? theme.field.backgroundDisabled : theme.field.background,
|
|
331
331
|
borderColor,
|
|
332
332
|
borderRadius: 4,
|
|
333
333
|
borderWidth,
|
package/src/Theme.test.tsx
CHANGED
|
@@ -352,6 +352,55 @@ describe("Theme", () => {
|
|
|
352
352
|
expect(theme?.border?.default).toBeDefined();
|
|
353
353
|
});
|
|
354
354
|
|
|
355
|
+
it("maps field tokens to the colors fields used before field theming", () => {
|
|
356
|
+
const captureTheme = (colorScheme: ThemeColorScheme): ThemeValue | undefined => {
|
|
357
|
+
let theme: ThemeValue | undefined;
|
|
358
|
+
const Capture = () => {
|
|
359
|
+
theme = useTheme().theme;
|
|
360
|
+
return null;
|
|
361
|
+
};
|
|
362
|
+
render(
|
|
363
|
+
<ThemeProvider colorScheme={colorScheme}>
|
|
364
|
+
<Capture />
|
|
365
|
+
</ThemeProvider>
|
|
366
|
+
);
|
|
367
|
+
return theme;
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
for (const colorScheme of ["light", "dark"] as const) {
|
|
371
|
+
const theme = captureTheme(colorScheme);
|
|
372
|
+
assert.deepEqual(theme?.field, {
|
|
373
|
+
background: theme?.surface.base,
|
|
374
|
+
backgroundDisabled: theme?.surface.neutralLight,
|
|
375
|
+
border: theme?.border.dark,
|
|
376
|
+
borderDisabled: theme?.border.activeNeutral,
|
|
377
|
+
borderError: theme?.border.error,
|
|
378
|
+
borderFocus: theme?.border.focus,
|
|
379
|
+
});
|
|
380
|
+
}
|
|
381
|
+
});
|
|
382
|
+
|
|
383
|
+
it("overrides field tokens without changing surface or border tokens", () => {
|
|
384
|
+
let captured: ThemeContextValue | undefined;
|
|
385
|
+
const Capture = () => {
|
|
386
|
+
captured = useTheme();
|
|
387
|
+
return null;
|
|
388
|
+
};
|
|
389
|
+
render(
|
|
390
|
+
<ThemeProvider>
|
|
391
|
+
<Capture />
|
|
392
|
+
</ThemeProvider>
|
|
393
|
+
);
|
|
394
|
+
act(() => {
|
|
395
|
+
captured?.setTheme({field: {background: "primary000", border: "primary500"}});
|
|
396
|
+
});
|
|
397
|
+
assert.equal(captured?.theme.field.background, defaultThemePrimitives.primary000);
|
|
398
|
+
assert.equal(captured?.theme.field.border, defaultThemePrimitives.primary500);
|
|
399
|
+
assert.equal(captured?.theme.field.borderFocus, defaultThemePrimitives.primary200);
|
|
400
|
+
assert.equal(captured?.theme.surface.base, defaultThemePrimitives.neutral000);
|
|
401
|
+
assert.equal(captured?.theme.border.dark, defaultThemePrimitives.neutral500);
|
|
402
|
+
});
|
|
403
|
+
|
|
355
404
|
it("provides spacing values", () => {
|
|
356
405
|
let theme: ThemeValue | undefined;
|
|
357
406
|
const Capture = () => {
|
package/src/Theme.tsx
CHANGED
|
@@ -103,6 +103,14 @@ export const lightThemeConfig: TerrenoThemeConfig = {
|
|
|
103
103
|
warning: "warning100",
|
|
104
104
|
},
|
|
105
105
|
|
|
106
|
+
field: {
|
|
107
|
+
background: "neutral000",
|
|
108
|
+
backgroundDisabled: "neutral300",
|
|
109
|
+
border: "neutral500",
|
|
110
|
+
borderDisabled: "neutral700",
|
|
111
|
+
borderError: "error100",
|
|
112
|
+
borderFocus: "primary200",
|
|
113
|
+
},
|
|
106
114
|
// These will continue to throw errors until we have a proper font system in place.
|
|
107
115
|
// TODO: currently to use these, you need to set fontFamily to "text" or "heading",
|
|
108
116
|
// not theme.font.primary or theme.font.title.
|
|
@@ -184,6 +192,14 @@ export const darkThemeConfig: TerrenoThemeConfig = {
|
|
|
184
192
|
success: "success050",
|
|
185
193
|
warning: "warning050",
|
|
186
194
|
},
|
|
195
|
+
field: {
|
|
196
|
+
background: "neutral800",
|
|
197
|
+
backgroundDisabled: "neutral600",
|
|
198
|
+
border: "neutral300",
|
|
199
|
+
borderDisabled: "neutral100",
|
|
200
|
+
borderError: "error050",
|
|
201
|
+
borderFocus: "primary200",
|
|
202
|
+
},
|
|
187
203
|
status: {
|
|
188
204
|
active: "success050",
|
|
189
205
|
away: "neutral300",
|