@terreno/ui 0.25.0 → 0.27.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 -0
- package/dist/ActionSheet.js.map +1 -1
- package/dist/AiSuggestionBox.js +1 -1
- package/dist/AiSuggestionBox.js.map +1 -1
- package/dist/Avatar.js +4 -1
- package/dist/Avatar.js.map +1 -1
- package/dist/BooleanField.js +2 -1
- package/dist/BooleanField.js.map +1 -1
- package/dist/Box.js +2 -0
- package/dist/Box.js.map +1 -1
- package/dist/Common.d.ts +7 -1
- package/dist/Common.js +1 -1
- package/dist/Common.js.map +1 -1
- package/dist/ConsentNavigator.js.map +1 -1
- package/dist/CustomSelectField.js +1 -1
- package/dist/CustomSelectField.js.map +1 -1
- package/dist/DateTimeField.js +4 -1
- package/dist/DateTimeField.js.map +1 -1
- package/dist/EmailField.js +1 -1
- package/dist/EmailField.js.map +1 -1
- package/dist/HeightField.js +3 -1
- package/dist/HeightField.js.map +1 -1
- package/dist/IconButton.js +10 -1
- package/dist/IconButton.js.map +1 -1
- package/dist/MarkdownEditorField.js +3 -1
- package/dist/MarkdownEditorField.js.map +1 -1
- package/dist/Modal.js +7 -2
- package/dist/Modal.js.map +1 -1
- package/dist/MultiselectField.js +2 -1
- package/dist/MultiselectField.js.map +1 -1
- package/dist/Page.js +1 -0
- package/dist/Page.js.map +1 -1
- package/dist/Permissions.d.ts +1 -1
- package/dist/Permissions.js +2 -2
- package/dist/Permissions.js.map +1 -1
- package/dist/SelectField.js +3 -1
- package/dist/SelectField.js.map +1 -1
- package/dist/SplitPage.js +3 -0
- package/dist/SplitPage.js.map +1 -1
- package/dist/SplitPage.native.js +2 -0
- package/dist/SplitPage.native.js.map +1 -1
- package/dist/TapToEdit.js +1 -0
- package/dist/TapToEdit.js.map +1 -1
- package/dist/TextField.js +3 -1
- package/dist/TextField.js.map +1 -1
- package/dist/ToastNotifications.js.map +1 -1
- package/dist/Unifier.js.map +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.js +6 -2
- package/dist/index.js.map +1 -1
- package/dist/useSubmitConsent.d.ts +1 -1
- package/dist/useSubmitConsent.js +1 -1
- package/dist/useSubmitConsent.js.map +1 -1
- package/package.json +2 -2
- package/src/ActionSheet.test.tsx +1 -0
- package/src/ActionSheet.tsx +2 -0
- package/src/AiSuggestionBox.tsx +1 -1
- package/src/Avatar.tsx +4 -1
- package/src/Badge.test.tsx +1 -2
- package/src/BooleanField.tsx +2 -1
- package/src/Box.test.tsx +56 -0
- package/src/Box.tsx +4 -0
- package/src/Button.test.tsx +34 -0
- package/src/Common.ts +31 -1
- package/src/ConsentNavigator.test.tsx +1 -0
- package/src/ConsentNavigator.tsx +1 -0
- package/src/CustomSelectField.tsx +1 -1
- package/src/DataTable.test.tsx +1 -0
- package/src/DateTimeField.test.tsx +1 -0
- package/src/DateTimeField.tsx +4 -1
- package/src/EmailField.tsx +1 -1
- package/src/HeightField.tsx +3 -1
- package/src/IconButton.test.tsx +26 -0
- package/src/IconButton.tsx +10 -0
- package/src/MarkdownEditorField.tsx +3 -1
- package/src/Modal.test.tsx +261 -66
- package/src/Modal.tsx +7 -2
- package/src/ModalSheet.test.tsx +7 -6
- package/src/MultiselectField.tsx +2 -1
- package/src/Page.tsx +1 -0
- package/src/Permissions.ts +2 -2
- package/src/PickerSelect.test.tsx +1 -0
- package/src/SelectBadge.test.tsx +1 -2
- package/src/SelectField.tsx +3 -1
- package/src/Signature.test.tsx +52 -0
- package/src/SplitPage.native.tsx +2 -0
- package/src/SplitPage.test.tsx +6 -4
- package/src/SplitPage.tsx +3 -0
- package/src/TapToEdit.test.tsx +1 -0
- package/src/TapToEdit.tsx +2 -0
- package/src/Text.test.tsx +29 -0
- package/src/TextField.test.tsx +57 -1
- package/src/TextField.tsx +3 -1
- package/src/ToastNotifications.test.tsx +1 -0
- package/src/ToastNotifications.tsx +1 -0
- package/src/Tooltip.test.tsx +1 -1
- package/src/Unifier.ts +1 -0
- package/src/UpgradeRequiredScreen.test.tsx +40 -0
- package/src/UserInactivity.test.tsx +44 -1
- package/src/WebDropdownMenu.test.tsx +116 -1
- package/src/__snapshots__/DataTable.test.tsx.snap +0 -148
- package/src/__snapshots__/IconButton.test.tsx.snap +4 -0
- package/src/__snapshots__/InfoModalIcon.test.tsx.snap +255 -1088
- package/src/__snapshots__/Modal.test.tsx.snap +950 -1108
- package/src/bunSetup.ts +24 -0
- package/src/createWebPortal.test.tsx +17 -0
- package/src/index.tsx +18 -2
- package/src/types/react-native-swiper-flatlist.d.ts +1 -0
- package/src/useSubmitConsent.test.ts +2 -1
- package/src/useSubmitConsent.ts +2 -2
- package/dist/fieldElements/index.d.ts +0 -3
- package/dist/fieldElements/index.js +0 -4
- package/dist/fieldElements/index.js.map +0 -1
- package/dist/icons/index.d.ts +0 -5
- package/dist/icons/index.js +0 -6
- package/dist/icons/index.js.map +0 -1
- package/dist/login/index.d.ts +0 -2
- package/dist/login/index.js +0 -2
- package/dist/login/index.js.map +0 -1
- package/dist/signUp/index.d.ts +0 -6
- package/dist/signUp/index.js +0 -6
- package/dist/signUp/index.js.map +0 -1
- package/dist/testing/index.d.ts +0 -2
- package/dist/testing/index.js +0 -3
- package/dist/testing/index.js.map +0 -1
- package/src/fieldElements/index.tsx +0 -3
- package/src/icons/index.ts +0 -5
- package/src/login/index.ts +0 -2
- package/src/signUp/index.ts +0 -13
- package/src/testing/index.ts +0 -2
package/src/IconButton.test.tsx
CHANGED
|
@@ -157,6 +157,32 @@ describe("IconButton", () => {
|
|
|
157
157
|
expect(toJSON()).toMatchSnapshot();
|
|
158
158
|
});
|
|
159
159
|
|
|
160
|
+
it("renders primary variant in active state", () => {
|
|
161
|
+
const {toJSON} = renderWithTheme(
|
|
162
|
+
<IconButton
|
|
163
|
+
accessibilityLabel="Test"
|
|
164
|
+
iconName="check"
|
|
165
|
+
onClick={() => {}}
|
|
166
|
+
state="active"
|
|
167
|
+
variant="primary"
|
|
168
|
+
/>
|
|
169
|
+
);
|
|
170
|
+
expect(toJSON()).toMatchSnapshot();
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("renders ghost variant in active state", () => {
|
|
174
|
+
const {toJSON} = renderWithTheme(
|
|
175
|
+
<IconButton
|
|
176
|
+
accessibilityLabel="Test"
|
|
177
|
+
iconName="check"
|
|
178
|
+
onClick={() => {}}
|
|
179
|
+
state="active"
|
|
180
|
+
variant="ghost"
|
|
181
|
+
/>
|
|
182
|
+
);
|
|
183
|
+
expect(toJSON()).toMatchSnapshot();
|
|
184
|
+
});
|
|
185
|
+
|
|
160
186
|
describe("custom icons", () => {
|
|
161
187
|
// IconButton renders `null` under the bun/react-test-renderer harness (all of
|
|
162
188
|
// its snapshots are null), so we verify the custom-icon code path renders
|
package/src/IconButton.tsx
CHANGED
|
@@ -57,6 +57,7 @@ const IconButtonComponent: FC<IconButtonProps> = ({
|
|
|
57
57
|
indicatorText,
|
|
58
58
|
loading: propsLoading = false,
|
|
59
59
|
size = "default",
|
|
60
|
+
state = "default",
|
|
60
61
|
testID,
|
|
61
62
|
variant = "primary",
|
|
62
63
|
withConfirmation = false,
|
|
@@ -99,6 +100,15 @@ const IconButtonComponent: FC<IconButtonProps> = ({
|
|
|
99
100
|
color = theme.surface.secondaryDark;
|
|
100
101
|
}
|
|
101
102
|
|
|
103
|
+
if (!disabled && state === "active") {
|
|
104
|
+
if (variant === "primary") {
|
|
105
|
+
backgroundColor = theme.primitives.primary600;
|
|
106
|
+
} else {
|
|
107
|
+
backgroundColor = theme.surface.primary;
|
|
108
|
+
color = theme.text.inverted;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
102
112
|
const indicatorColor = indicator ? theme.surface[indicator] : undefined;
|
|
103
113
|
|
|
104
114
|
return (
|
|
@@ -4,7 +4,9 @@ import {Platform, Pressable, Text as RNText, ScrollView, TextInput, View} from "
|
|
|
4
4
|
|
|
5
5
|
import {Box} from "./Box";
|
|
6
6
|
import type {ErrorTextProps, HelperTextProps} from "./Common";
|
|
7
|
-
import {FieldError
|
|
7
|
+
import {FieldError} from "./fieldElements/FieldError";
|
|
8
|
+
import {FieldHelperText} from "./fieldElements/FieldHelperText";
|
|
9
|
+
import {FieldTitle} from "./fieldElements/FieldTitle";
|
|
8
10
|
import {MarkdownView} from "./MarkdownView";
|
|
9
11
|
import {Text} from "./Text";
|
|
10
12
|
import {useTheme} from "./Theme";
|
package/src/Modal.test.tsx
CHANGED
|
@@ -1,10 +1,15 @@
|
|
|
1
|
-
import {afterEach, describe, expect, it, mock} from "bun:test";
|
|
1
|
+
import {afterEach, beforeEach, describe, expect, it, mock, spyOn} from "bun:test";
|
|
2
2
|
import {fireEvent} from "@testing-library/react-native";
|
|
3
|
+
import {assert} from "chai";
|
|
4
|
+
// Import Platform the same way the source modules do (ESM named import) so the web blur effect
|
|
5
|
+
// (which reads Platform.OS directly in Modal.tsx) observes the value the test sets.
|
|
6
|
+
import {Platform as ImportedPlatform} from "react-native";
|
|
7
|
+
import {Gesture} from "react-native-gesture-handler";
|
|
3
8
|
|
|
4
|
-
import {isMobileDevice} from "./MediaQuery";
|
|
5
9
|
import {Modal} from "./Modal";
|
|
6
10
|
import {Text} from "./Text";
|
|
7
11
|
import {renderWithTheme} from "./test-utils";
|
|
12
|
+
import * as Utilities from "./Utilities";
|
|
8
13
|
|
|
9
14
|
// Minimal shape of a test instance returned by UNSAFE_getAllByType that we rely on here.
|
|
10
15
|
interface PressableTestInstance {
|
|
@@ -16,7 +21,135 @@ interface PressableTestInstance {
|
|
|
16
21
|
};
|
|
17
22
|
}
|
|
18
23
|
|
|
24
|
+
/**
|
|
25
|
+
* Finds the web-only translucent backdrop Pressable in a rendered Modal tree.
|
|
26
|
+
*
|
|
27
|
+
* The web branch renders a full-screen Pressable whose style sets a semi-transparent
|
|
28
|
+
* `rgba(...)` backgroundColor; the native ActionSheet branch has no such element. Tests use
|
|
29
|
+
* its presence/absence to assert which presentation branch rendered.
|
|
30
|
+
*
|
|
31
|
+
* @param pressables - All Pressable test instances found in the rendered tree.
|
|
32
|
+
* @returns The backdrop Pressable if present, otherwise undefined.
|
|
33
|
+
*/
|
|
34
|
+
const findBackdropPressable = (
|
|
35
|
+
pressables: PressableTestInstance[]
|
|
36
|
+
): PressableTestInstance | undefined => {
|
|
37
|
+
return pressables.find((node) => {
|
|
38
|
+
const style = node.props.style;
|
|
39
|
+
if (Array.isArray(style)) {
|
|
40
|
+
return style.some((s) => s?.backgroundColor?.includes?.("rgba"));
|
|
41
|
+
}
|
|
42
|
+
return style?.backgroundColor?.includes?.("rgba");
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Collects every reachable react-native `Platform` mock object.
|
|
48
|
+
*
|
|
49
|
+
* `Platform.OS` is read through `import {Platform} from "react-native"` in more than one source
|
|
50
|
+
* module (`Modal.tsx` directly, and `Utilities.tsx#isNative`). Depending on module resolution
|
|
51
|
+
* those bindings can map to either the top-level react-native mock or the internal
|
|
52
|
+
* `Libraries/Utilities/Platform` mock, and CI has shown them diverging (mutating one left the
|
|
53
|
+
* other untouched). Gathering all of them lets a single setter drive the platform branch
|
|
54
|
+
* deterministically regardless of which object a given module captured.
|
|
55
|
+
*/
|
|
56
|
+
const collectPlatformObjects = (): {OS: string}[] => {
|
|
57
|
+
const objects: {OS: string}[] = [];
|
|
58
|
+
const push = (candidate: unknown): void => {
|
|
59
|
+
if (
|
|
60
|
+
candidate &&
|
|
61
|
+
typeof candidate === "object" &&
|
|
62
|
+
"OS" in (candidate as Record<string, unknown>) &&
|
|
63
|
+
!objects.includes(candidate as {OS: string})
|
|
64
|
+
) {
|
|
65
|
+
objects.push(candidate as {OS: string});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
// The ESM binding the source files use must come first.
|
|
69
|
+
push(ImportedPlatform);
|
|
70
|
+
const rn = require("react-native") as {Platform?: unknown; default?: {Platform?: unknown}};
|
|
71
|
+
push(rn.Platform);
|
|
72
|
+
push(rn.default?.Platform);
|
|
73
|
+
try {
|
|
74
|
+
// Only the module's `default` object is mutable; the namespace's own `OS` binding is a
|
|
75
|
+
// readonly ES module export and must not be pushed.
|
|
76
|
+
const libPlatform = require("react-native/Libraries/Utilities/Platform") as {
|
|
77
|
+
default?: unknown;
|
|
78
|
+
};
|
|
79
|
+
push(libPlatform.default);
|
|
80
|
+
} catch {
|
|
81
|
+
// The internal Platform module may not be resolvable; the top-level mock still covers it.
|
|
82
|
+
}
|
|
83
|
+
return objects;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
const platformObjects = collectPlatformObjects();
|
|
87
|
+
const originalPlatformOS = platformObjects.map((platform) => platform.OS);
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Sets `Platform.OS` on every reachable Platform mock so both `Modal` and `isNative` observe it.
|
|
91
|
+
*
|
|
92
|
+
* @param os - The platform value to apply (e.g. "web", "ios", "android").
|
|
93
|
+
*/
|
|
94
|
+
const setPlatformOS = (os: string): void => {
|
|
95
|
+
for (const platform of platformObjects) {
|
|
96
|
+
try {
|
|
97
|
+
platform.OS = os;
|
|
98
|
+
} catch {
|
|
99
|
+
// Skip any binding that is not writable; other bindings still drive the branch.
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Restores `Platform.OS` on every reachable Platform mock to the value captured at load time.
|
|
106
|
+
*/
|
|
107
|
+
const restorePlatformOS = (): void => {
|
|
108
|
+
platformObjects.forEach((platform, index) => {
|
|
109
|
+
try {
|
|
110
|
+
platform.OS = originalPlatformOS[index] ?? "ios";
|
|
111
|
+
} catch {
|
|
112
|
+
// Skip any binding that is not writable.
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
let isNativeSpy: ReturnType<typeof spyOn> | undefined;
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Forces `isNative()` to a fixed value so the Modal's platform branch is deterministic.
|
|
121
|
+
*
|
|
122
|
+
* Spying on the `Utilities.isNative` export drives the exact live binding `Modal.tsx` calls,
|
|
123
|
+
* which is reliable across environments (unlike mutating react-native's Platform.OS, whose mock
|
|
124
|
+
* object identity can diverge per module on CI).
|
|
125
|
+
*
|
|
126
|
+
* @param value - true to render the native ActionSheet branch, false for the web dialog branch.
|
|
127
|
+
*/
|
|
128
|
+
const forceIsNative = (value: boolean): void => {
|
|
129
|
+
isNativeSpy = spyOn(Utilities, "isNative").mockReturnValue(value);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Restores the real `isNative()` implementation after a forced value.
|
|
134
|
+
*/
|
|
135
|
+
const restoreIsNative = (): void => {
|
|
136
|
+
isNativeSpy?.mockRestore();
|
|
137
|
+
isNativeSpy = undefined;
|
|
138
|
+
};
|
|
139
|
+
|
|
19
140
|
describe("Modal", () => {
|
|
141
|
+
// These tests exercise the default native (ActionSheet) presentation; pin the platform and
|
|
142
|
+
// force isNative() so the branch is deterministic and not left to ambient Platform.OS state.
|
|
143
|
+
beforeEach(() => {
|
|
144
|
+
setPlatformOS("ios");
|
|
145
|
+
forceIsNative(true);
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
afterEach(() => {
|
|
149
|
+
restorePlatformOS();
|
|
150
|
+
restoreIsNative();
|
|
151
|
+
});
|
|
152
|
+
|
|
20
153
|
it("renders correctly when visible", () => {
|
|
21
154
|
const {toJSON} = renderWithTheme(
|
|
22
155
|
<Modal onDismiss={() => {}} title="Test Modal" visible>
|
|
@@ -302,6 +435,44 @@ describe("Modal", () => {
|
|
|
302
435
|
|
|
303
436
|
expect(handleSecondary).toHaveBeenCalled();
|
|
304
437
|
});
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
describe("Modal web platform", () => {
|
|
441
|
+
const globalScope = globalThis as {document?: unknown; HTMLElement?: unknown};
|
|
442
|
+
const originalDocument = globalScope.document;
|
|
443
|
+
const originalHTMLElement = globalScope.HTMLElement;
|
|
444
|
+
|
|
445
|
+
class FakeHTMLElement {
|
|
446
|
+
blur = mock(() => {});
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// The web branch runs a blur useEffect that reads `document.activeElement` and checks
|
|
450
|
+
// `instanceof HTMLElement`, so every web test needs Platform.OS === "web" (across every
|
|
451
|
+
// Platform binding, see setPlatformOS) plus a document and HTMLElement stub before rendering.
|
|
452
|
+
beforeEach(() => {
|
|
453
|
+
setPlatformOS("web");
|
|
454
|
+
forceIsNative(false);
|
|
455
|
+
globalScope.HTMLElement = FakeHTMLElement;
|
|
456
|
+
globalScope.document = {activeElement: null};
|
|
457
|
+
});
|
|
458
|
+
|
|
459
|
+
afterEach(() => {
|
|
460
|
+
restorePlatformOS();
|
|
461
|
+
restoreIsNative();
|
|
462
|
+
globalScope.document = originalDocument;
|
|
463
|
+
globalScope.HTMLElement = originalHTMLElement;
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
it("renders the web RNModal backdrop on web", () => {
|
|
467
|
+
const {UNSAFE_getAllByType} = renderWithTheme(
|
|
468
|
+
<Modal onDismiss={() => {}} title="Web Modal" visible>
|
|
469
|
+
<Text>Content</Text>
|
|
470
|
+
</Modal>
|
|
471
|
+
);
|
|
472
|
+
const {Pressable} = require("react-native");
|
|
473
|
+
const pressables: PressableTestInstance[] = UNSAFE_getAllByType(Pressable);
|
|
474
|
+
expect(findBackdropPressable(pressables)).toBeTruthy();
|
|
475
|
+
});
|
|
305
476
|
|
|
306
477
|
it("dismisses when the backdrop is pressed and persistOnBackgroundClick is false", () => {
|
|
307
478
|
const handleDismiss = mock(() => {});
|
|
@@ -313,13 +484,7 @@ describe("Modal", () => {
|
|
|
313
484
|
// Find the backdrop Pressable (first Pressable in tree with a style that includes backgroundColor).
|
|
314
485
|
const {Pressable} = require("react-native");
|
|
315
486
|
const pressables: PressableTestInstance[] = UNSAFE_getAllByType(Pressable);
|
|
316
|
-
const backdrop = pressables
|
|
317
|
-
const style = node.props.style;
|
|
318
|
-
if (Array.isArray(style)) {
|
|
319
|
-
return style.some((s) => s?.backgroundColor?.includes?.("rgba"));
|
|
320
|
-
}
|
|
321
|
-
return style?.backgroundColor?.includes?.("rgba");
|
|
322
|
-
});
|
|
487
|
+
const backdrop = findBackdropPressable(pressables);
|
|
323
488
|
expect(backdrop).toBeTruthy();
|
|
324
489
|
backdrop?.props.onPress?.();
|
|
325
490
|
expect(handleDismiss).toHaveBeenCalled();
|
|
@@ -355,28 +520,8 @@ describe("Modal", () => {
|
|
|
355
520
|
inner?.props.onPress?.({stopPropagation});
|
|
356
521
|
expect(stopPropagation).not.toHaveBeenCalled();
|
|
357
522
|
});
|
|
358
|
-
});
|
|
359
|
-
|
|
360
|
-
describe("Modal web platform", () => {
|
|
361
|
-
const RN = require("react-native") as {Platform: {OS: string}};
|
|
362
|
-
const originalOS = RN.Platform.OS;
|
|
363
|
-
const globalScope = globalThis as {document?: unknown; HTMLElement?: unknown};
|
|
364
|
-
const originalDocument = globalScope.document;
|
|
365
|
-
const originalHTMLElement = globalScope.HTMLElement;
|
|
366
|
-
|
|
367
|
-
class FakeHTMLElement {
|
|
368
|
-
blur = mock(() => {});
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
afterEach(() => {
|
|
372
|
-
RN.Platform.OS = originalOS;
|
|
373
|
-
globalScope.document = originalDocument;
|
|
374
|
-
globalScope.HTMLElement = originalHTMLElement;
|
|
375
|
-
});
|
|
376
523
|
|
|
377
524
|
it("blurs the focused element when opened on web", () => {
|
|
378
|
-
RN.Platform.OS = "web";
|
|
379
|
-
globalScope.HTMLElement = FakeHTMLElement;
|
|
380
525
|
const active = new FakeHTMLElement();
|
|
381
526
|
globalScope.document = {activeElement: active};
|
|
382
527
|
|
|
@@ -390,8 +535,6 @@ describe("Modal web platform", () => {
|
|
|
390
535
|
});
|
|
391
536
|
|
|
392
537
|
it("does not blur when the active element is not an HTMLElement", () => {
|
|
393
|
-
RN.Platform.OS = "web";
|
|
394
|
-
globalScope.HTMLElement = FakeHTMLElement;
|
|
395
538
|
globalScope.document = {activeElement: {}};
|
|
396
539
|
|
|
397
540
|
const {toJSON} = renderWithTheme(
|
|
@@ -404,46 +547,98 @@ describe("Modal web platform", () => {
|
|
|
404
547
|
});
|
|
405
548
|
});
|
|
406
549
|
|
|
407
|
-
|
|
550
|
+
// The Modal selects its presentation via isNative() (Platform.OS in ios/android), NOT screen
|
|
551
|
+
// size, so these run the native branch explicitly for each native platform. Android is the
|
|
552
|
+
// platform where the original tablet bug occurred, so it must be covered directly rather than
|
|
553
|
+
// relying on the default "ios" test platform.
|
|
554
|
+
describe("Modal native presentation", () => {
|
|
408
555
|
afterEach(() => {
|
|
409
|
-
(
|
|
410
|
-
|
|
556
|
+
restorePlatformOS();
|
|
557
|
+
restoreIsNative();
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
for (const platform of ["ios", "android"] as const) {
|
|
561
|
+
it(`uses the ActionSheet (no web backdrop) on ${platform}`, () => {
|
|
562
|
+
setPlatformOS(platform);
|
|
563
|
+
forceIsNative(true);
|
|
564
|
+
const {UNSAFE_getAllByType, getByText} = renderWithTheme(
|
|
565
|
+
<Modal
|
|
566
|
+
onDismiss={() => {}}
|
|
567
|
+
primaryButtonOnClick={() => {}}
|
|
568
|
+
primaryButtonText="Save"
|
|
569
|
+
title="Native Modal"
|
|
570
|
+
visible
|
|
571
|
+
>
|
|
572
|
+
<Text>Native Content</Text>
|
|
573
|
+
</Modal>
|
|
574
|
+
);
|
|
575
|
+
// Content mounts via the ActionSheet branch...
|
|
576
|
+
expect(getByText("Native Modal")).toBeTruthy();
|
|
577
|
+
// ...and the web-only translucent backdrop Pressable must NOT be present.
|
|
578
|
+
const {Pressable} = require("react-native");
|
|
579
|
+
const pressables: PressableTestInstance[] = UNSAFE_getAllByType(Pressable);
|
|
580
|
+
expect(findBackdropPressable(pressables)).toBeUndefined();
|
|
581
|
+
});
|
|
411
582
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
<
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
583
|
+
it(`renders nothing when not visible on ${platform}`, () => {
|
|
584
|
+
setPlatformOS(platform);
|
|
585
|
+
forceIsNative(true);
|
|
586
|
+
const {queryByText} = renderWithTheme(
|
|
587
|
+
<Modal onDismiss={() => {}} title="Hidden Native Modal" visible={false}>
|
|
588
|
+
<Text>Native Content</Text>
|
|
589
|
+
</Modal>
|
|
590
|
+
);
|
|
591
|
+
// The ActionSheet stays closed (mock tracks setModalVisible), so no content is shown.
|
|
592
|
+
expect(queryByText("Hidden Native Modal")).toBeNull();
|
|
593
|
+
expect(queryByText("Native Content")).toBeNull();
|
|
594
|
+
});
|
|
595
|
+
}
|
|
596
|
+
});
|
|
597
|
+
|
|
598
|
+
interface CapturedGesture {
|
|
599
|
+
onEnd: {mock: {calls: [(event: {translationY: number}) => void][]}};
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
describe("Modal drag-to-close gesture", () => {
|
|
603
|
+
// The drag handle only renders in the native ActionSheet branch, so force native.
|
|
604
|
+
beforeEach(() => {
|
|
605
|
+
setPlatformOS("ios");
|
|
606
|
+
forceIsNative(true);
|
|
420
607
|
});
|
|
421
608
|
|
|
422
|
-
|
|
423
|
-
(
|
|
424
|
-
|
|
425
|
-
<Modal
|
|
426
|
-
onDismiss={() => {}}
|
|
427
|
-
primaryButtonOnClick={() => {}}
|
|
428
|
-
primaryButtonText="Save"
|
|
429
|
-
secondaryButtonOnClick={() => {}}
|
|
430
|
-
secondaryButtonText="Cancel"
|
|
431
|
-
title="Mobile Actions"
|
|
432
|
-
visible
|
|
433
|
-
>
|
|
434
|
-
<Text>Content</Text>
|
|
435
|
-
</Modal>
|
|
436
|
-
);
|
|
437
|
-
expect(toJSON()).toBeTruthy();
|
|
609
|
+
afterEach(() => {
|
|
610
|
+
restorePlatformOS();
|
|
611
|
+
restoreIsNative();
|
|
438
612
|
});
|
|
439
613
|
|
|
440
|
-
it("
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
614
|
+
it("dismisses only when dragged down past the threshold", () => {
|
|
615
|
+
const handleDismiss = mock(() => {});
|
|
616
|
+
let capturedGesture: CapturedGesture | undefined;
|
|
617
|
+
const originalPan = Gesture.Pan;
|
|
618
|
+
(Gesture as {Pan: () => unknown}).Pan = () => {
|
|
619
|
+
capturedGesture = originalPan() as unknown as CapturedGesture;
|
|
620
|
+
return capturedGesture;
|
|
621
|
+
};
|
|
622
|
+
|
|
623
|
+
try {
|
|
624
|
+
renderWithTheme(
|
|
625
|
+
<Modal onDismiss={handleDismiss} title="Draggable" visible>
|
|
626
|
+
<Text>Body</Text>
|
|
627
|
+
</Modal>
|
|
628
|
+
);
|
|
629
|
+
|
|
630
|
+
const onEnd = capturedGesture?.onEnd.mock.calls[0][0];
|
|
631
|
+
assert.isDefined(onEnd);
|
|
632
|
+
|
|
633
|
+
// A small drag stays below the threshold and should not dismiss.
|
|
634
|
+
onEnd?.({translationY: 5});
|
|
635
|
+
assert.lengthOf(handleDismiss.mock.calls, 0);
|
|
636
|
+
|
|
637
|
+
// A drag past the threshold dismisses via runOnJS(handleDismiss).
|
|
638
|
+
onEnd?.({translationY: 40});
|
|
639
|
+
assert.lengthOf(handleDismiss.mock.calls, 1);
|
|
640
|
+
} finally {
|
|
641
|
+
(Gesture as {Pan: () => unknown}).Pan = originalPan;
|
|
642
|
+
}
|
|
448
643
|
});
|
|
449
644
|
});
|
package/src/Modal.tsx
CHANGED
|
@@ -15,7 +15,6 @@ import {Button} from "./Button";
|
|
|
15
15
|
import type {ModalProps, TerrenoTheme} from "./Common";
|
|
16
16
|
import {Heading} from "./Heading";
|
|
17
17
|
import {Icon} from "./Icon";
|
|
18
|
-
import {isMobileDevice} from "./MediaQuery";
|
|
19
18
|
import {Text} from "./Text";
|
|
20
19
|
import {useTheme} from "./Theme";
|
|
21
20
|
import {resolveModalTestIDsFromProps, toTestProps} from "./testing/resolveTestId";
|
|
@@ -247,7 +246,13 @@ export const Modal: FC<ModalProps> = ({
|
|
|
247
246
|
}
|
|
248
247
|
}, [visible]);
|
|
249
248
|
|
|
250
|
-
|
|
249
|
+
// Choose the presentation by platform, not by screen size. The web branch below relies on DOM
|
|
250
|
+
// semantics (nested Pressables using `e.stopPropagation()` and a `cursor` style) that native
|
|
251
|
+
// platforms do not implement, so it must only run on web. Keying this off screen size instead
|
|
252
|
+
// sent native *tablets* (width >= "sm") down the web branch: on Android the nested Pressables
|
|
253
|
+
// fight over the touch responder, producing repeated press animations and a Confirm button that
|
|
254
|
+
// never fires. All native devices (phones and tablets) use the ActionSheet presentation.
|
|
255
|
+
const isMobile = isNative();
|
|
251
256
|
const sizePx = getModalSize(size);
|
|
252
257
|
|
|
253
258
|
const modalContentProps = {
|
package/src/ModalSheet.test.tsx
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
2
1
|
import {describe, expect, it, mock} from "bun:test";
|
|
3
2
|
import {forwardRef, useRef} from "react";
|
|
4
3
|
import {Text, View} from "react-native";
|
|
@@ -8,11 +7,13 @@ import {renderWithTheme} from "./test-utils";
|
|
|
8
7
|
|
|
9
8
|
// Mock react-native-modalize
|
|
10
9
|
mock.module("react-native-modalize", () => ({
|
|
11
|
-
Modalize: forwardRef
|
|
12
|
-
|
|
13
|
-
{
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
Modalize: forwardRef<React.ElementRef<typeof View>, {children: React.ReactNode}>(
|
|
11
|
+
({children}, ref) => (
|
|
12
|
+
<View ref={ref} testID="modalize">
|
|
13
|
+
{children}
|
|
14
|
+
</View>
|
|
15
|
+
)
|
|
16
|
+
),
|
|
16
17
|
}));
|
|
17
18
|
|
|
18
19
|
describe("ModalSheet", () => {
|
package/src/MultiselectField.tsx
CHANGED
|
@@ -3,7 +3,8 @@ import {TouchableOpacity, View} from "react-native";
|
|
|
3
3
|
|
|
4
4
|
import {CheckBox} from "./CheckBox";
|
|
5
5
|
import type {MultiselectFieldProps} from "./Common";
|
|
6
|
-
import {FieldError
|
|
6
|
+
import {FieldError} from "./fieldElements/FieldError";
|
|
7
|
+
import {FieldHelperText} from "./fieldElements/FieldHelperText";
|
|
7
8
|
import {Heading} from "./Heading";
|
|
8
9
|
import {isMobileDevice} from "./MediaQuery";
|
|
9
10
|
import {Text} from "./Text";
|
package/src/Page.tsx
CHANGED
|
@@ -12,6 +12,7 @@ import {Spinner} from "./Spinner";
|
|
|
12
12
|
import {Text} from "./Text";
|
|
13
13
|
|
|
14
14
|
export class Page extends React.Component<PageProps, {}> {
|
|
15
|
+
// noExplicitAny: ActionSheet class is defined in ActionSheet.tsx which imports from Common.ts indirectly; using its type here would create a circular dependency
|
|
15
16
|
// biome-ignore lint/suspicious/noExplicitAny: ActionSheet class is defined in ActionSheet.tsx which imports from Common.ts indirectly; using its type here would create a circular dependency
|
|
16
17
|
actionSheetRef: React.RefObject<any> = React.createRef();
|
|
17
18
|
|
package/src/Permissions.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// import Permissions from "react-native-permissions";
|
|
4
4
|
import type {PermissionKind, PermissionStatus} from "./Common";
|
|
5
5
|
|
|
6
|
-
export async
|
|
6
|
+
export const requestPermissions = async (_kind: PermissionKind): Promise<PermissionStatus> => {
|
|
7
7
|
return new Promise((_resolve, _reject) => {
|
|
8
8
|
return "denied";
|
|
9
9
|
});
|
|
@@ -43,4 +43,4 @@ export async function requestPermissions(_kind: PermissionKind): Promise<Permiss
|
|
|
43
43
|
// return reject(MAP_RESULTS[response]);
|
|
44
44
|
// }
|
|
45
45
|
// });
|
|
46
|
-
}
|
|
46
|
+
};
|
package/src/SelectBadge.test.tsx
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
2
1
|
import {describe, expect, it, mock} from "bun:test";
|
|
3
2
|
import {act, fireEvent} from "@testing-library/react-native";
|
|
4
3
|
|
|
@@ -28,7 +27,7 @@ describe("SelectBadge", () => {
|
|
|
28
27
|
|
|
29
28
|
it("displays placeholder when no value", () => {
|
|
30
29
|
const {getByText} = renderWithTheme(
|
|
31
|
-
<SelectBadge onChange={() => {}} options={defaultOptions} value={undefined
|
|
30
|
+
<SelectBadge onChange={() => {}} options={defaultOptions} value={undefined} />
|
|
32
31
|
);
|
|
33
32
|
expect(getByText("---")).toBeTruthy();
|
|
34
33
|
});
|
package/src/SelectField.tsx
CHANGED
|
@@ -2,7 +2,9 @@ import type {FC} from "react";
|
|
|
2
2
|
import {View} from "react-native";
|
|
3
3
|
|
|
4
4
|
import type {SelectFieldProps} from "./Common";
|
|
5
|
-
import {FieldError
|
|
5
|
+
import {FieldError} from "./fieldElements/FieldError";
|
|
6
|
+
import {FieldHelperText} from "./fieldElements/FieldHelperText";
|
|
7
|
+
import {FieldTitle} from "./fieldElements/FieldTitle";
|
|
6
8
|
import {RNPickerSelect} from "./PickerSelect";
|
|
7
9
|
import {resolveFieldTestIDsFromProps} from "./testing/resolveTestId";
|
|
8
10
|
|
package/src/Signature.test.tsx
CHANGED
|
@@ -362,4 +362,56 @@ describe("Signature", () => {
|
|
|
362
362
|
expect(mockOnChange).toHaveBeenCalledWith("");
|
|
363
363
|
expect(ctx.fillRect).toHaveBeenCalled();
|
|
364
364
|
});
|
|
365
|
+
|
|
366
|
+
it("ignores pointer down when the canvas ref is missing", () => {
|
|
367
|
+
const mockOnChange = mock(() => {});
|
|
368
|
+
const mockOnStart = mock(() => {});
|
|
369
|
+
const {UNSAFE_getByType} = renderWithTheme(
|
|
370
|
+
<Signature onChange={mockOnChange} onStart={mockOnStart} />
|
|
371
|
+
);
|
|
372
|
+
const canvas = UNSAFE_getByType("canvas");
|
|
373
|
+
canvas.props.ref.current = null;
|
|
374
|
+
|
|
375
|
+
act(() => {
|
|
376
|
+
canvas.props.onPointerDown({
|
|
377
|
+
nativeEvent: {offsetX: 10, offsetY: 20},
|
|
378
|
+
pointerId: 1,
|
|
379
|
+
});
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
expect(mockOnStart).not.toHaveBeenCalled();
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
it("falls back to raw offsets when the canvas has no measurable size", () => {
|
|
386
|
+
const mockOnChange = mock(() => {});
|
|
387
|
+
const moveTo = mock(() => {});
|
|
388
|
+
const {UNSAFE_getByType} = renderWithTheme(<Signature onChange={mockOnChange} />);
|
|
389
|
+
const canvas = UNSAFE_getByType("canvas");
|
|
390
|
+
canvas.props.ref.current = {
|
|
391
|
+
clientHeight: 0,
|
|
392
|
+
clientWidth: 0,
|
|
393
|
+
getBoundingClientRect: () => ({height: 0, width: 0}),
|
|
394
|
+
getContext: () => ({
|
|
395
|
+
beginPath: mock(() => {}),
|
|
396
|
+
fillRect: mock(() => {}),
|
|
397
|
+
lineCap: "round",
|
|
398
|
+
lineJoin: "round",
|
|
399
|
+
lineTo: mock(() => {}),
|
|
400
|
+
moveTo,
|
|
401
|
+
stroke: mock(() => {}),
|
|
402
|
+
}),
|
|
403
|
+
height: 0,
|
|
404
|
+
setPointerCapture: mock(() => {}),
|
|
405
|
+
width: 0,
|
|
406
|
+
} as unknown as HTMLCanvasElement;
|
|
407
|
+
|
|
408
|
+
act(() => {
|
|
409
|
+
canvas.props.onPointerDown({
|
|
410
|
+
nativeEvent: {offsetX: 42, offsetY: 24},
|
|
411
|
+
pointerId: 1,
|
|
412
|
+
});
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
expect(moveTo).toHaveBeenCalledWith(42, 24);
|
|
416
|
+
});
|
|
365
417
|
});
|
package/src/SplitPage.native.tsx
CHANGED
|
@@ -34,6 +34,7 @@ export const SplitPage = ({
|
|
|
34
34
|
const {width} = Dimensions.get("window");
|
|
35
35
|
|
|
36
36
|
const onItemSelect = useCallback(
|
|
37
|
+
// noExplicitAny: SplitPage accepts heterogeneous list item shapes from consumers; the generic propagates from listViewData
|
|
37
38
|
// biome-ignore lint/suspicious/noExplicitAny: SplitPage accepts heterogeneous list item shapes from consumers; the generic propagates from listViewData
|
|
38
39
|
async (item: ListRenderItemInfo<any>) => {
|
|
39
40
|
setSelectedId(item.index);
|
|
@@ -59,6 +60,7 @@ export const SplitPage = ({
|
|
|
59
60
|
return null;
|
|
60
61
|
}
|
|
61
62
|
|
|
63
|
+
// noExplicitAny: SplitPage accepts heterogeneous list item shapes from consumers; the generic propagates from listViewData
|
|
62
64
|
// biome-ignore lint/suspicious/noExplicitAny: SplitPage accepts heterogeneous list item shapes from consumers; the generic propagates from listViewData
|
|
63
65
|
const renderItem = (itemInfo: ListRenderItemInfo<any>) => {
|
|
64
66
|
return (
|