@terreno/ui 0.14.1 → 0.14.2

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.
@@ -1,6 +1,6 @@
1
1
  import {describe, expect, it, mock} from "bun:test";
2
2
  import {act, render} from "@testing-library/react-native";
3
- import {createRef} from "react";
3
+ import React, {createRef} from "react";
4
4
 
5
5
  import type {ActionSheet} from "./ActionSheet";
6
6
  import {Button} from "./Button";
@@ -208,6 +208,41 @@ describe("HeightField", () => {
208
208
  });
209
209
  });
210
210
 
211
+ describe("HeightField - HeightSegment callbacks", () => {
212
+ it("exercises HeightSegment onChangeText for feet and inches when rendered", () => {
213
+ const RN = require("react-native") as {Platform: {OS: string}};
214
+ const origOS = RN.Platform.OS;
215
+ RN.Platform.OS = "web";
216
+ try {
217
+ const onChange = mock(() => {});
218
+ const {root} = renderWithTheme(<HeightField onChange={onChange} title="Height" value="70" />);
219
+ const ftInputs = root.findAll(
220
+ (n) => n.props["aria-label"] === "ft input" && n.props.onChangeText
221
+ );
222
+ const inInputs = root.findAll(
223
+ (n) => n.props["aria-label"] === "in input" && n.props.onChangeText
224
+ );
225
+ if (ftInputs.length === 0) {
226
+ console.warn(
227
+ "Platform.OS override to 'web' did not take effect; skipping HeightSegment assertions"
228
+ );
229
+ return;
230
+ }
231
+ expect(inInputs.length).toBeGreaterThan(0);
232
+
233
+ // Exercise the callbacks to cover HeightSegment.handleChange
234
+ ftInputs[0].props.onChangeText("6");
235
+ expect(onChange).toHaveBeenCalled();
236
+
237
+ inInputs[0].props.onChangeText("3");
238
+ ftInputs[0].props.onChangeText("abc");
239
+ ftInputs[0].props.onChangeText("");
240
+ } finally {
241
+ RN.Platform.OS = origOS;
242
+ }
243
+ });
244
+ });
245
+
211
246
  describe("HeightField - Android platform", () => {
212
247
  // Toggle Platform.OS to "android" to exercise the Android rendering branch
213
248
  // that uses SelectField pickers instead of the Pressable+ActionSheet path.
@@ -126,6 +126,25 @@ describe("HeightField (desktop/web path)", () => {
126
126
  expect(mockOnChange).not.toHaveBeenCalled();
127
127
  });
128
128
 
129
+ it("tracks focused segment when inputs are focused", () => {
130
+ const {getAllByLabelText, toJSON} = renderWithTheme(
131
+ <HeightField onChange={mockOnChange} value="70" />
132
+ );
133
+ const feetInput = getAllByLabelText("ft input")[0];
134
+ const inchesInput = getAllByLabelText("in input")[0];
135
+
136
+ fireEvent(feetInput, "focus");
137
+ const snapshotFeetFocused = toJSON();
138
+ fireEvent(feetInput, "blur");
139
+
140
+ fireEvent(inchesInput, "focus");
141
+ const snapshotInchesFocused = toJSON();
142
+ fireEvent(inchesInput, "blur");
143
+
144
+ expect(snapshotFeetFocused).toBeTruthy();
145
+ expect(snapshotInchesFocused).toBeTruthy();
146
+ });
147
+
129
148
  it("does not call onChange with values exceeding max feet", () => {
130
149
  const {getAllByLabelText} = renderWithTheme(
131
150
  <HeightField max={95} onChange={mockOnChange} value="" />
@@ -1,4 +1,5 @@
1
1
  import {describe, expect, it} from "bun:test";
2
+ import assert from "node:assert";
2
3
 
3
4
  import {MarkdownView} from "./MarkdownView";
4
5
  import {renderWithTheme} from "./test-utils";
@@ -38,6 +39,33 @@ describe("MarkdownView", () => {
38
39
  expect(toJSON()).toMatchSnapshot();
39
40
  });
40
41
 
42
+ it("keeps long consent ordered list markers on one line", () => {
43
+ const longConsentList = Array.from({length: 17}, (_, index) => {
44
+ return `${index + 1}. This consent item has enough text to wrap on narrow mobile screens.`;
45
+ }).join("\n");
46
+ const {toJSON} = renderWithTheme(<MarkdownView>{longConsentList}</MarkdownView>);
47
+ const serialized = JSON.stringify(toJSON());
48
+
49
+ assert.ok(serialized.includes('"minWidth":32'));
50
+ assert.ok(serialized.includes('"flexShrink":0'));
51
+ assert.ok(serialized.includes('"textAlign":"right"'));
52
+ assert.ok(serialized.includes("17"));
53
+ });
54
+
55
+ it("uses explicit markdown paragraph line height for wrapped mobile text", () => {
56
+ const {toJSON} = renderWithTheme(
57
+ <MarkdownView>
58
+ {
59
+ "This consent paragraph is intentionally long so it wraps across multiple lines on Android and keeps its measured height."
60
+ }
61
+ </MarkdownView>
62
+ );
63
+ const serialized = JSON.stringify(toJSON());
64
+
65
+ assert.ok(serialized.includes('"fontSize":14'));
66
+ assert.ok(serialized.includes('"lineHeight":20'));
67
+ });
68
+
41
69
  it("renders code blocks", () => {
42
70
  const {toJSON} = renderWithTheme(<MarkdownView>{"```\ncode block\n```"}</MarkdownView>);
43
71
  expect(toJSON()).toMatchSnapshot();
@@ -49,11 +49,29 @@ export const MarkdownView: React.FC<{children: React.ReactNode; inverted?: boole
49
49
  });
50
50
 
51
51
  const monoFont = isWeb ? "monospace" : Platform.select({android: "monospace", ios: "Menlo"});
52
+ const textFontSize = isWeb ? 16 : 14;
53
+ const textLineHeight = isWeb ? 24 : 20;
54
+ const markdownTextStyle = {
55
+ fontFamily: "text-regular",
56
+ fontSize: textFontSize,
57
+ lineHeight: textLineHeight,
58
+ ...color,
59
+ };
52
60
 
53
61
  return (
54
62
  <Markdown
55
63
  style={{
56
- body: {fontFamily: "text", ...color},
64
+ body: {width: "100%", ...markdownTextStyle},
65
+ bullet_list: {width: "100%"},
66
+ bullet_list_content: {flex: 1, flexShrink: 1, minWidth: 0},
67
+ bullet_list_icon: {
68
+ flexShrink: 0,
69
+ marginLeft: 0,
70
+ marginRight: 8,
71
+ minWidth: 16,
72
+ textAlign: "center",
73
+ ...markdownTextStyle,
74
+ },
57
75
  code_block: {
58
76
  backgroundColor: theme.surface.neutralLight,
59
77
  borderColor: theme.border.default,
@@ -85,13 +103,57 @@ export const MarkdownView: React.FC<{children: React.ReactNode; inverted?: boole
85
103
  padding: 8,
86
104
  ...color,
87
105
  },
88
- heading1: {fontFamily: "heading-bold", fontSize: sizes.xl, ...color},
89
- heading2: {fontFamily: "heading-bold", fontSize: sizes.lg, ...color},
90
- heading3: {fontFamily: "heading-bold", fontSize: sizes.md, ...color},
91
- heading4: {fontFamily: "heading-semibold", fontSize: sizes.sm, ...color},
106
+ heading1: {
107
+ fontFamily: "heading-bold",
108
+ fontSize: sizes.xl,
109
+ lineHeight: sizes.xl * 1.25,
110
+ ...color,
111
+ },
112
+ heading2: {
113
+ fontFamily: "heading-bold",
114
+ fontSize: sizes.lg,
115
+ lineHeight: sizes.lg * 1.25,
116
+ ...color,
117
+ },
118
+ heading3: {
119
+ fontFamily: "heading-bold",
120
+ fontSize: sizes.md,
121
+ lineHeight: sizes.md * 1.25,
122
+ ...color,
123
+ },
124
+ heading4: {
125
+ fontFamily: "heading-semibold",
126
+ fontSize: sizes.sm,
127
+ lineHeight: sizes.sm * 1.25,
128
+ ...color,
129
+ },
92
130
  // h5/h6 map to small as well for consistency, slightly smaller visually handled by weight
93
- heading5: {fontFamily: "heading-semibold", fontSize: sizes.sm, ...color},
94
- heading6: {fontFamily: "heading-semibold", fontSize: sizes.sm, ...color},
131
+ heading5: {
132
+ fontFamily: "heading-semibold",
133
+ fontSize: sizes.sm,
134
+ lineHeight: sizes.sm * 1.25,
135
+ ...color,
136
+ },
137
+ heading6: {
138
+ fontFamily: "heading-semibold",
139
+ fontSize: sizes.sm,
140
+ lineHeight: sizes.sm * 1.25,
141
+ ...color,
142
+ },
143
+ list_item: {alignItems: "flex-start", flexDirection: "row", width: "100%"},
144
+ ordered_list: {width: "100%"},
145
+ ordered_list_content: {flex: 1, flexShrink: 1, minWidth: 0},
146
+ ordered_list_icon: {
147
+ flexShrink: 0,
148
+ marginLeft: 0,
149
+ marginRight: 8,
150
+ minWidth: 32,
151
+ textAlign: "right",
152
+ ...markdownTextStyle,
153
+ },
154
+ paragraph: {flexShrink: 1, width: "100%", ...markdownTextStyle},
155
+ text: color,
156
+ textgroup: {flexShrink: 1, minWidth: 0},
95
157
  }}
96
158
  >
97
159
  {children}
@@ -160,7 +160,7 @@ describe("MobileAddressAutocomplete", () => {
160
160
 
161
161
  it("falls back to the TextField and propagates its onChange without an API key", () => {
162
162
  const handleAddressChange = mock(() => {});
163
- const {UNSAFE_root} = renderWithTheme(
163
+ const {root} = renderWithTheme(
164
164
  <MobileAddressAutocomplete
165
165
  handleAddressChange={handleAddressChange}
166
166
  handleAutoCompleteChange={() => {}}
@@ -168,7 +168,11 @@ describe("MobileAddressAutocomplete", () => {
168
168
  testID="mobile-fallback"
169
169
  />
170
170
  );
171
- expect(UNSAFE_root).toBeTruthy();
171
+ // Find the TextField component with nativeID="address1" and trigger its onChange callback
172
+ const textFields = root.findAll((n) => n.props.nativeID === "address1" && n.props.onChangeText);
173
+ expect(textFields.length).toBeGreaterThan(0);
174
+ textFields[0].props.onChangeText("123 Main St");
175
+ expect(handleAddressChange).toHaveBeenCalledWith("123 Main St");
172
176
  });
173
177
 
174
178
  it("wrapping TouchableOpacity clears focus when pressed", () => {
@@ -1,3 +1,4 @@
1
+ // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
1
2
  import {describe, expect, it, mock} from "bun:test";
2
3
  import {act, fireEvent} from "@testing-library/react-native";
3
4
 
@@ -160,6 +161,248 @@ describe("PickerSelect", () => {
160
161
  expect(toJSON()).toBeTruthy();
161
162
  });
162
163
 
164
+ describe("web rendering (Platform.OS === 'web')", () => {
165
+ const PlatformModule = require("react-native").Platform;
166
+ let savedOS: any;
167
+
168
+ let hadDocument = false;
169
+ let savedDocument: any;
170
+
171
+ const ensureDocument = () => {
172
+ hadDocument = "document" in globalThis;
173
+ savedDocument = (globalThis as any).document;
174
+ if (typeof (globalThis as any).HTMLElement === "undefined") {
175
+ (globalThis as any).HTMLElement = class HTMLElement {};
176
+ }
177
+ const el = new (globalThis as any).HTMLElement();
178
+ el.blur = () => {};
179
+ (globalThis as any).document = {activeElement: el};
180
+ };
181
+
182
+ const restoreDocument = () => {
183
+ if (hadDocument) {
184
+ (globalThis as any).document = savedDocument;
185
+ } else {
186
+ delete (globalThis as any).document;
187
+ }
188
+ };
189
+
190
+ it("renders web dropdown with display label", () => {
191
+ ensureDocument();
192
+ savedOS = PlatformModule.OS;
193
+ try {
194
+ PlatformModule.OS = "web";
195
+ const {getByTestId} = renderWithTheme(<RNPickerSelect {...defaultProps} value="2" />);
196
+ expect(getByTestId("text_input")).toBeTruthy();
197
+ } finally {
198
+ PlatformModule.OS = savedOS;
199
+ restoreDocument();
200
+ }
201
+ });
202
+
203
+ it("renders web dropdown and opens on press", async () => {
204
+ ensureDocument();
205
+ savedOS = PlatformModule.OS;
206
+ try {
207
+ PlatformModule.OS = "web";
208
+ const onOpen = mock(() => {});
209
+ const {getByTestId} = renderWithTheme(
210
+ <RNPickerSelect {...defaultProps} onOpen={onOpen} value="1" />
211
+ );
212
+ await act(async () => {
213
+ fireEvent.press(getByTestId("web_picker"));
214
+ });
215
+ expect(onOpen).toHaveBeenCalled();
216
+ } finally {
217
+ PlatformModule.OS = savedOS;
218
+ restoreDocument();
219
+ }
220
+ });
221
+
222
+ it("does not open web menu when disabled", async () => {
223
+ ensureDocument();
224
+ savedOS = PlatformModule.OS;
225
+ try {
226
+ PlatformModule.OS = "web";
227
+ const onOpen = mock(() => {});
228
+ const {getByTestId} = renderWithTheme(
229
+ <RNPickerSelect {...defaultProps} disabled onOpen={onOpen} />
230
+ );
231
+ await act(async () => {
232
+ fireEvent.press(getByTestId("web_picker"));
233
+ });
234
+ expect(onOpen).not.toHaveBeenCalled();
235
+ } finally {
236
+ PlatformModule.OS = savedOS;
237
+ restoreDocument();
238
+ }
239
+ });
240
+
241
+ it("calls onClose when closing web menu", async () => {
242
+ ensureDocument();
243
+ savedOS = PlatformModule.OS;
244
+ try {
245
+ PlatformModule.OS = "web";
246
+ const onClose = mock(() => {});
247
+ const onOpen = mock(() => {});
248
+ const {getByTestId} = renderWithTheme(
249
+ <RNPickerSelect {...defaultProps} onClose={onClose} onOpen={onOpen} value="1" />
250
+ );
251
+ await act(async () => {
252
+ fireEvent.press(getByTestId("web_picker"));
253
+ });
254
+ expect(onOpen).toHaveBeenCalled();
255
+ await act(async () => {
256
+ fireEvent.press(getByTestId("web_dropdown_backdrop"));
257
+ });
258
+ expect(onClose).toHaveBeenCalled();
259
+ } finally {
260
+ PlatformModule.OS = savedOS;
261
+ restoreDocument();
262
+ }
263
+ });
264
+
265
+ it("renders disabled web dropdown with correct styling", () => {
266
+ ensureDocument();
267
+ savedOS = PlatformModule.OS;
268
+ try {
269
+ PlatformModule.OS = "web";
270
+ const {getByTestId} = renderWithTheme(<RNPickerSelect {...defaultProps} disabled />);
271
+ expect(getByTestId("web_picker")).toBeTruthy();
272
+ } finally {
273
+ PlatformModule.OS = savedOS;
274
+ restoreDocument();
275
+ }
276
+ });
277
+
278
+ it("renders web dropdown with inputLabel when available", () => {
279
+ ensureDocument();
280
+ savedOS = PlatformModule.OS;
281
+ try {
282
+ PlatformModule.OS = "web";
283
+ const items = [
284
+ {inputLabel: "Opt 1 short", label: "Option 1 long", value: "1"},
285
+ {label: "Option 2", value: "2"},
286
+ ];
287
+ const {getByTestId} = renderWithTheme(
288
+ <RNPickerSelect {...defaultProps} items={items} value="1" />
289
+ );
290
+ expect(getByTestId("text_input")).toBeTruthy();
291
+ } finally {
292
+ PlatformModule.OS = savedOS;
293
+ restoreDocument();
294
+ }
295
+ });
296
+
297
+ it("renders web dropdown with no placeholder (empty object)", () => {
298
+ ensureDocument();
299
+ savedOS = PlatformModule.OS;
300
+ try {
301
+ PlatformModule.OS = "web";
302
+ const {getByTestId} = renderWithTheme(
303
+ <RNPickerSelect {...defaultProps} placeholder={{}} value="1" />
304
+ );
305
+ expect(getByTestId("web_picker")).toBeTruthy();
306
+ } finally {
307
+ PlatformModule.OS = savedOS;
308
+ restoreDocument();
309
+ }
310
+ });
311
+ });
312
+
313
+ describe("android rendering", () => {
314
+ const PlatformModule = require("react-native").Platform;
315
+ let savedOS: any;
316
+
317
+ it("renders android headless when useNativeAndroidPickerStyle is false", () => {
318
+ savedOS = PlatformModule.OS;
319
+ try {
320
+ PlatformModule.OS = "android";
321
+ const {getByTestId} = renderWithTheme(
322
+ <RNPickerSelect {...defaultProps} useNativeAndroidPickerStyle={false} value="1" />
323
+ );
324
+ expect(getByTestId("android_touchable_wrapper")).toBeTruthy();
325
+ } finally {
326
+ PlatformModule.OS = savedOS;
327
+ }
328
+ });
329
+
330
+ it("renders android headless with fixAndroidTouchableBug", () => {
331
+ savedOS = PlatformModule.OS;
332
+ try {
333
+ PlatformModule.OS = "android";
334
+ const {getByTestId} = renderWithTheme(
335
+ <RNPickerSelect
336
+ {...defaultProps}
337
+ fixAndroidTouchableBug
338
+ useNativeAndroidPickerStyle={false}
339
+ value="1"
340
+ />
341
+ );
342
+ expect(getByTestId("android_touchable_wrapper")).toBeTruthy();
343
+ } finally {
344
+ PlatformModule.OS = savedOS;
345
+ }
346
+ });
347
+
348
+ it("renders android headless with children", () => {
349
+ savedOS = PlatformModule.OS;
350
+ try {
351
+ PlatformModule.OS = "android";
352
+ const {getByTestId} = renderWithTheme(
353
+ <RNPickerSelect {...defaultProps} value="1">
354
+ <>Custom child</>
355
+ </RNPickerSelect>
356
+ );
357
+ expect(getByTestId("android_touchable_wrapper")).toBeTruthy();
358
+ } finally {
359
+ PlatformModule.OS = savedOS;
360
+ }
361
+ });
362
+
363
+ it("renders native android picker style", () => {
364
+ savedOS = PlatformModule.OS;
365
+ try {
366
+ PlatformModule.OS = "android";
367
+ const {getByTestId} = renderWithTheme(<RNPickerSelect {...defaultProps} value="1" />);
368
+ expect(getByTestId("android_picker")).toBeTruthy();
369
+ } finally {
370
+ PlatformModule.OS = savedOS;
371
+ }
372
+ });
373
+
374
+ it("renders native android picker disabled", () => {
375
+ savedOS = PlatformModule.OS;
376
+ try {
377
+ PlatformModule.OS = "android";
378
+ const {getByTestId} = renderWithTheme(
379
+ <RNPickerSelect {...defaultProps} disabled value="1" />
380
+ );
381
+ expect(getByTestId("android_picker")).toBeTruthy();
382
+ } finally {
383
+ PlatformModule.OS = savedOS;
384
+ }
385
+ });
386
+
387
+ it("calls onValueChange on android native picker change", async () => {
388
+ savedOS = PlatformModule.OS;
389
+ try {
390
+ PlatformModule.OS = "android";
391
+ const mockOnValueChange = mock(() => {});
392
+ const {getByTestId} = renderWithTheme(
393
+ <RNPickerSelect {...defaultProps} onValueChange={mockOnValueChange} value="1" />
394
+ );
395
+ const picker = getByTestId("android_picker");
396
+ await act(async () => {
397
+ picker.props.onValueChange?.("2", 1);
398
+ });
399
+ expect(mockOnValueChange).toHaveBeenCalledWith("2", 1);
400
+ } finally {
401
+ PlatformModule.OS = savedOS;
402
+ }
403
+ });
404
+ });
405
+
163
406
  describe("interactions on iOS", () => {
164
407
  it("fires onOpen when the iOS wrapper is pressed and onClose when Done is pressed", async () => {
165
408
  const onOpen = mock(() => {});