@terreno/ui 0.26.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/dist/ActionSheet.js.map +1 -1
- package/dist/Box.js +2 -0
- package/dist/Box.js.map +1 -1
- package/dist/Common.js.map +1 -1
- package/dist/ConsentNavigator.js.map +1 -1
- package/dist/DateTimeField.js +1 -0
- package/dist/DateTimeField.js.map +1 -1
- package/dist/EmailField.js +1 -1
- package/dist/EmailField.js.map +1 -1
- package/dist/Modal.js +7 -2
- package/dist/Modal.js.map +1 -1
- package/dist/Page.js +1 -0
- package/dist/Page.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/ToastNotifications.js.map +1 -1
- package/dist/Unifier.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/Box.test.tsx +56 -0
- package/src/Box.tsx +4 -0
- package/src/Button.test.tsx +34 -0
- package/src/Common.ts +23 -0
- package/src/ConsentNavigator.test.tsx +1 -0
- package/src/ConsentNavigator.tsx +1 -0
- package/src/DataTable.test.tsx +1 -0
- package/src/DateTimeField.test.tsx +1 -0
- package/src/DateTimeField.tsx +1 -0
- package/src/EmailField.tsx +1 -1
- package/src/Modal.test.tsx +261 -66
- package/src/Modal.tsx +7 -2
- package/src/ModalSheet.test.tsx +7 -6
- package/src/Page.tsx +1 -0
- package/src/PickerSelect.test.tsx +1 -0
- package/src/SelectBadge.test.tsx +1 -2
- 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/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/__snapshots__/DataTable.test.tsx.snap +0 -148
- 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/types/react-native-swiper-flatlist.d.ts +1 -0
- package/src/useSubmitConsent.test.ts +2 -1
- package/src/useSubmitConsent.ts +2 -2
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/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/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/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 (
|
package/src/SplitPage.test.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
2
1
|
import {afterAll, afterEach, beforeEach, describe, expect, it, mock} from "bun:test";
|
|
3
2
|
import {act} from "@testing-library/react-native";
|
|
4
3
|
import {View} from "react-native";
|
|
4
|
+
import type {ReactTestInstance} from "react-test-renderer";
|
|
5
5
|
|
|
6
6
|
import {SplitPage} from "./SplitPage";
|
|
7
7
|
import {renderWithTheme} from "./test-utils";
|
|
@@ -353,7 +353,7 @@ describe("SplitPage", () => {
|
|
|
353
353
|
fireEvent.press(boxes[0]);
|
|
354
354
|
});
|
|
355
355
|
const iconButtons = UNSAFE_root.findAll(
|
|
356
|
-
(n:
|
|
356
|
+
(n: ReactTestInstance) => n.props?.onClick && n.props?.iconName === "xmark"
|
|
357
357
|
);
|
|
358
358
|
if (iconButtons.length > 0) {
|
|
359
359
|
await act(async () => {
|
|
@@ -362,7 +362,7 @@ describe("SplitPage", () => {
|
|
|
362
362
|
expect(onSelectionChange).toHaveBeenCalledWith(undefined);
|
|
363
363
|
} else {
|
|
364
364
|
const closeButtons = UNSAFE_root.findAll(
|
|
365
|
-
(n:
|
|
365
|
+
(n: ReactTestInstance) => n.props?.accessibilityLabel === "close"
|
|
366
366
|
);
|
|
367
367
|
if (closeButtons.length > 0) {
|
|
368
368
|
await act(async () => {
|
|
@@ -449,7 +449,9 @@ describe("SplitPage", () => {
|
|
|
449
449
|
<View testID="child-c" />
|
|
450
450
|
</SplitPage>
|
|
451
451
|
);
|
|
452
|
-
const segmented = UNSAFE_root.findAll(
|
|
452
|
+
const segmented = UNSAFE_root.findAll(
|
|
453
|
+
(n: ReactTestInstance) => n.props?.onChange && n.props?.items
|
|
454
|
+
);
|
|
453
455
|
if (segmented.length > 0) {
|
|
454
456
|
await act(async () => {
|
|
455
457
|
segmented[0].props.onChange(2);
|
package/src/SplitPage.tsx
CHANGED
|
@@ -40,6 +40,7 @@ export const SplitPage = ({
|
|
|
40
40
|
const elementArray = Children.toArray(children).filter((c) => c !== null);
|
|
41
41
|
|
|
42
42
|
const onItemSelect = useCallback(
|
|
43
|
+
// noExplicitAny: SplitPage accepts heterogeneous list item shapes from consumers; the generic propagates from listViewData
|
|
43
44
|
// biome-ignore lint/suspicious/noExplicitAny: SplitPage accepts heterogeneous list item shapes from consumers; the generic propagates from listViewData
|
|
44
45
|
async (item: ListRenderItemInfo<any>): Promise<void> => {
|
|
45
46
|
setSelectedId(item.index);
|
|
@@ -70,6 +71,7 @@ export const SplitPage = ({
|
|
|
70
71
|
return null;
|
|
71
72
|
}
|
|
72
73
|
|
|
74
|
+
// noExplicitAny: SplitPage accepts heterogeneous list item shapes from consumers; the generic propagates from listViewData
|
|
73
75
|
// biome-ignore lint/suspicious/noExplicitAny: SplitPage accepts heterogeneous list item shapes from consumers; the generic propagates from listViewData
|
|
74
76
|
const renderItem = (itemInfo: ListRenderItemInfo<any>) => {
|
|
75
77
|
return (
|
|
@@ -300,6 +302,7 @@ export const SplitPage = ({
|
|
|
300
302
|
width="100%"
|
|
301
303
|
>
|
|
302
304
|
{loading === true && (
|
|
305
|
+
// noExplicitAny: Spinner color is a token enum but the legacy code passes theme.text.primary (a resolved hex string); preserving original behavior
|
|
303
306
|
// biome-ignore lint/suspicious/noExplicitAny: Spinner color is a token enum but the legacy code passes theme.text.primary (a resolved hex string); preserving original behavior
|
|
304
307
|
<Spinner color={theme.text.primary as any} size="md" />
|
|
305
308
|
)}
|
package/src/TapToEdit.test.tsx
CHANGED
package/src/TapToEdit.tsx
CHANGED
|
@@ -84,6 +84,7 @@ export const TapToEdit: FC<TapToEditProps> = ({
|
|
|
84
84
|
const helperText: string | undefined = propsHelperText;
|
|
85
85
|
|
|
86
86
|
// TODO: Auto focus on input when editing for field types other than text for accessibility
|
|
87
|
+
// noExplicitAny: inputRef references various RN input components (TextInput, etc.) depending on the field type
|
|
87
88
|
// biome-ignore lint/suspicious/noExplicitAny: inputRef references various RN input components (TextInput, etc.) depending on the field type
|
|
88
89
|
const inputRef = useRef<any>(null);
|
|
89
90
|
|
|
@@ -120,6 +121,7 @@ export const TapToEdit: FC<TapToEditProps> = ({
|
|
|
120
121
|
row={fieldProps?.type === "textarea" ? 5 : undefined}
|
|
121
122
|
type={(fieldProps?.type ?? "text") as NonNullable<FieldProps["type"]>}
|
|
122
123
|
value={value}
|
|
124
|
+
// noExplicitAny: fieldProps is a discriminated union (FieldProps) but the spread loses narrowing; type-checking each variant individually is impractical here
|
|
123
125
|
// biome-ignore lint/suspicious/noExplicitAny: fieldProps is a discriminated union (FieldProps) but the spread loses narrowing; type-checking each variant individually is impractical here
|
|
124
126
|
{...(fieldProps as any)}
|
|
125
127
|
/>
|
package/src/Text.test.tsx
CHANGED
|
@@ -60,6 +60,35 @@ describe("Text", () => {
|
|
|
60
60
|
expect(toJSON()).toMatchSnapshot();
|
|
61
61
|
});
|
|
62
62
|
|
|
63
|
+
it("uses the medium-italic font family for larger italic text", () => {
|
|
64
|
+
const {getByText} = renderWithTheme(
|
|
65
|
+
<Text italic size="lg">
|
|
66
|
+
Large italic
|
|
67
|
+
</Text>
|
|
68
|
+
);
|
|
69
|
+
expect((getByText("Large italic").props.style as {fontFamily?: string}).fontFamily).toBe(
|
|
70
|
+
"text-medium-italic"
|
|
71
|
+
);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("uses the bold-italic font family for larger bold italic text", () => {
|
|
75
|
+
const {getByText} = renderWithTheme(
|
|
76
|
+
<Text bold italic size="xl">
|
|
77
|
+
Large bold italic
|
|
78
|
+
</Text>
|
|
79
|
+
);
|
|
80
|
+
expect((getByText("Large bold italic").props.style as {fontFamily?: string}).fontFamily).toBe(
|
|
81
|
+
"text-bold-italic"
|
|
82
|
+
);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("uses the medium font family for larger plain text", () => {
|
|
86
|
+
const {getByText} = renderWithTheme(<Text size="2xl">Extra large plain</Text>);
|
|
87
|
+
expect((getByText("Extra large plain").props.style as {fontFamily?: string}).fontFamily).toBe(
|
|
88
|
+
"text-medium"
|
|
89
|
+
);
|
|
90
|
+
});
|
|
91
|
+
|
|
63
92
|
it("renders underlined text", () => {
|
|
64
93
|
const {toJSON} = renderWithTheme(<Text underline>Underlined text</Text>);
|
|
65
94
|
expect(toJSON()).toMatchSnapshot();
|
package/src/TextField.test.tsx
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {afterEach, beforeEach, describe, expect, it, mock} from "bun:test";
|
|
1
|
+
import {afterEach, beforeEach, describe, expect, it, mock, spyOn} from "bun:test";
|
|
2
2
|
import {act, fireEvent, userEvent} from "@testing-library/react-native";
|
|
3
3
|
import {TextField} from "./TextField";
|
|
4
4
|
import {renderWithTheme} from "./test-utils";
|
|
@@ -484,4 +484,60 @@ describe("TextField", () => {
|
|
|
484
484
|
expect(component.toJSON()).toMatchSnapshot();
|
|
485
485
|
});
|
|
486
486
|
});
|
|
487
|
+
|
|
488
|
+
describe("platform, unsupported types, and content sizing", () => {
|
|
489
|
+
const PlatformModule = require("react-native").Platform;
|
|
490
|
+
|
|
491
|
+
it("renders with the web outline style when running on web", () => {
|
|
492
|
+
const savedOS = PlatformModule.OS;
|
|
493
|
+
try {
|
|
494
|
+
PlatformModule.OS = "web";
|
|
495
|
+
const {getByDisplayValue} = renderWithTheme(
|
|
496
|
+
<TextField onChange={mockOnChange} value="web value" />
|
|
497
|
+
);
|
|
498
|
+
expect(getByDisplayValue("web value")).toBeTruthy();
|
|
499
|
+
} finally {
|
|
500
|
+
PlatformModule.OS = savedOS;
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
it("warns for not-yet-supported field types", () => {
|
|
505
|
+
const warnSpy = spyOn(console, "warn").mockImplementation(() => {});
|
|
506
|
+
try {
|
|
507
|
+
renderWithTheme(<TextField onChange={mockOnChange} type="numberRange" value="" />);
|
|
508
|
+
expect(warnSpy).toHaveBeenCalledWith("numberRange is not yet supported");
|
|
509
|
+
} finally {
|
|
510
|
+
warnSpy.mockRestore();
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
it("ignores content size changes when grow is disabled", () => {
|
|
515
|
+
const {getByDisplayValue} = renderWithTheme(
|
|
516
|
+
<TextField multiline onChange={mockOnChange} value="" />
|
|
517
|
+
);
|
|
518
|
+
const input = getByDisplayValue("");
|
|
519
|
+
// Without `grow`, onContentSizeChange returns early and must not throw.
|
|
520
|
+
expect(() =>
|
|
521
|
+
fireEvent(input, "contentSizeChange", {nativeEvent: {contentSize: {height: 999}}})
|
|
522
|
+
).not.toThrow();
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
it("grows to the reported content height when grow is enabled", () => {
|
|
526
|
+
const {getByDisplayValue} = renderWithTheme(
|
|
527
|
+
<TextField grow multiline onChange={mockOnChange} value="" />
|
|
528
|
+
);
|
|
529
|
+
const input = getByDisplayValue("");
|
|
530
|
+
expect(() =>
|
|
531
|
+
fireEvent(input, "contentSizeChange", {nativeEvent: {contentSize: {height: 120}}})
|
|
532
|
+
).not.toThrow();
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
it("invokes the onFocus callback when the input is focused", () => {
|
|
536
|
+
const {getByDisplayValue} = renderWithTheme(
|
|
537
|
+
<TextField onChange={mockOnChange} onFocus={mockOnFocus} value="" />
|
|
538
|
+
);
|
|
539
|
+
fireEvent(getByDisplayValue(""), "focus");
|
|
540
|
+
expect(mockOnFocus).toHaveBeenCalledTimes(1);
|
|
541
|
+
});
|
|
542
|
+
});
|
|
487
543
|
});
|