@terreno/ui 0.16.1 → 0.17.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/package.json
CHANGED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import {afterAll, beforeAll, describe, expect, it, mock} from "bun:test";
|
|
2
|
+
import {act} from "@testing-library/react-native";
|
|
3
|
+
import {Platform} from "react-native";
|
|
4
|
+
|
|
5
|
+
import {SelectBadge} from "./SelectBadge";
|
|
6
|
+
import {renderWithTheme} from "./test-utils";
|
|
7
|
+
|
|
8
|
+
// Force Platform.OS to "android" for this file so SelectBadge takes the
|
|
9
|
+
// renderPicker branch (native Picker overlay) instead of the iOS modal.
|
|
10
|
+
const originalOS = Platform.OS;
|
|
11
|
+
beforeAll(() => {
|
|
12
|
+
Object.defineProperty(Platform, "OS", {configurable: true, value: "android"});
|
|
13
|
+
});
|
|
14
|
+
afterAll(() => {
|
|
15
|
+
Object.defineProperty(Platform, "OS", {configurable: true, value: originalOS});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe("SelectBadge (android)", () => {
|
|
19
|
+
const options = [
|
|
20
|
+
{label: "Option A", value: "a"},
|
|
21
|
+
{label: "Option B", value: "b"},
|
|
22
|
+
{label: "Option C", value: "c"},
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
it("renders the Android-native Picker overlay", () => {
|
|
26
|
+
const {UNSAFE_getAllByProps, toJSON} = renderWithTheme(
|
|
27
|
+
<SelectBadge onChange={() => {}} options={options} value="a" />
|
|
28
|
+
);
|
|
29
|
+
// The Android picker should be rendered (not the iOS modal or web dropdown)
|
|
30
|
+
expect(toJSON()).toBeTruthy();
|
|
31
|
+
// Find the picker by its selectedValue prop (Android overlay renders a Picker directly)
|
|
32
|
+
const pickers = UNSAFE_getAllByProps({selectedValue: "a"});
|
|
33
|
+
expect(pickers.length).toBeGreaterThan(0);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("invokes onChange when Android picker value changes", () => {
|
|
37
|
+
const handleChange = mock((_val: string) => {});
|
|
38
|
+
const {UNSAFE_getAllByProps} = renderWithTheme(
|
|
39
|
+
<SelectBadge onChange={handleChange} options={options} value="a" />
|
|
40
|
+
);
|
|
41
|
+
const pickers = UNSAFE_getAllByProps({selectedValue: "a"});
|
|
42
|
+
const picker = pickers.find(
|
|
43
|
+
(p: {props?: {onValueChange?: (v: string) => void}}) =>
|
|
44
|
+
typeof p.props?.onValueChange === "function"
|
|
45
|
+
);
|
|
46
|
+
expect(picker).toBeDefined();
|
|
47
|
+
act(() => {
|
|
48
|
+
if (picker) {
|
|
49
|
+
picker.props.onValueChange("b");
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
expect(handleChange).toHaveBeenCalledWith("b");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("renders with disabled prop on Android", () => {
|
|
56
|
+
const {UNSAFE_getAllByProps} = renderWithTheme(
|
|
57
|
+
<SelectBadge disabled onChange={() => {}} options={options} value="a" />
|
|
58
|
+
);
|
|
59
|
+
const pickers = UNSAFE_getAllByProps({enabled: false});
|
|
60
|
+
expect(pickers.length).toBeGreaterThan(0);
|
|
61
|
+
});
|
|
62
|
+
});
|
package/src/SelectBadge.test.tsx
CHANGED
|
@@ -137,6 +137,22 @@ describe("SelectBadge", () => {
|
|
|
137
137
|
expect(handleChange).toHaveBeenCalledWith("b");
|
|
138
138
|
});
|
|
139
139
|
|
|
140
|
+
it("closes picker without calling onChange when Save is pressed with empty value", () => {
|
|
141
|
+
const handleChange = mock((_val: string) => {});
|
|
142
|
+
const {getByLabelText} = renderWithTheme(
|
|
143
|
+
<SelectBadge onChange={handleChange} options={defaultOptions} value="" />
|
|
144
|
+
);
|
|
145
|
+
// Open the iOS picker modal
|
|
146
|
+
act(() => {
|
|
147
|
+
fireEvent.press(getByLabelText("Open select badge options"));
|
|
148
|
+
});
|
|
149
|
+
// Press Save without changing value (iosDisplayValue is "" which is falsy)
|
|
150
|
+
act(() => {
|
|
151
|
+
fireEvent.press(getByLabelText("Save selected value"));
|
|
152
|
+
});
|
|
153
|
+
expect(handleChange).not.toHaveBeenCalled();
|
|
154
|
+
});
|
|
155
|
+
|
|
140
156
|
it("does not call onChange when iOS picker is dismissed", () => {
|
|
141
157
|
const handleChange = mock((_val: string) => {});
|
|
142
158
|
const {getByLabelText} = renderWithTheme(
|