@terreno/ui 0.14.0 → 0.14.1

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.
Files changed (79) hide show
  1. package/dist/ActionSheet.d.ts +1 -1
  2. package/dist/ActionSheet.js +2 -2
  3. package/dist/ActionSheet.js.map +1 -1
  4. package/dist/Common.d.ts +8 -2
  5. package/dist/Common.js +4 -4
  6. package/dist/Common.js.map +1 -1
  7. package/dist/ConsentFormScreen.js +3 -3
  8. package/dist/ConsentFormScreen.js.map +1 -1
  9. package/dist/DateUtilities.d.ts +25 -25
  10. package/dist/DateUtilities.js +31 -32
  11. package/dist/DateUtilities.js.map +1 -1
  12. package/dist/MediaQuery.d.ts +4 -4
  13. package/dist/MediaQuery.js +8 -8
  14. package/dist/MediaQuery.js.map +1 -1
  15. package/dist/Page.d.ts +1 -0
  16. package/dist/Page.js +6 -2
  17. package/dist/Page.js.map +1 -1
  18. package/dist/PickerSelect.d.ts +1 -1
  19. package/dist/PickerSelect.js +2 -2
  20. package/dist/PickerSelect.js.map +1 -1
  21. package/dist/TapToEdit.d.ts +1 -1
  22. package/dist/TapToEdit.js +2 -3
  23. package/dist/TapToEdit.js.map +1 -1
  24. package/dist/ToastNotifications.js +2 -2
  25. package/dist/ToastNotifications.js.map +1 -1
  26. package/dist/Tooltip.d.ts +24 -1
  27. package/dist/Tooltip.js +2 -2
  28. package/dist/Tooltip.js.map +1 -1
  29. package/dist/Unifier.d.ts +1 -1
  30. package/dist/Unifier.js +14 -11
  31. package/dist/Unifier.js.map +1 -1
  32. package/dist/Utilities.d.ts +8 -8
  33. package/dist/Utilities.js +12 -14
  34. package/dist/Utilities.js.map +1 -1
  35. package/dist/index.d.ts +1 -1
  36. package/dist/index.js +1 -1
  37. package/dist/index.js.map +1 -1
  38. package/dist/signUp/PasswordRequirements.js +3 -3
  39. package/dist/signUp/PasswordRequirements.js.map +1 -1
  40. package/dist/table/TableHeaderCell.js +1 -9
  41. package/dist/table/TableHeaderCell.js.map +1 -1
  42. package/dist/table/tableContext.d.ts +1 -1
  43. package/dist/table/tableContext.js +2 -2
  44. package/dist/table/tableContext.js.map +1 -1
  45. package/package.json +1 -1
  46. package/src/ActionSheet.tsx +2 -2
  47. package/src/Banner.test.tsx +71 -0
  48. package/src/Common.ts +10 -4
  49. package/src/ConsentFormScreen.test.tsx +22 -0
  50. package/src/ConsentFormScreen.tsx +9 -3
  51. package/src/DataTable.test.tsx +217 -0
  52. package/src/DateUtilities.tsx +37 -38
  53. package/src/HeightActionSheet.test.tsx +16 -0
  54. package/src/HeightField.test.tsx +106 -1
  55. package/src/MediaQuery.ts +8 -8
  56. package/src/MobileAddressAutoComplete.test.tsx +20 -1
  57. package/src/Page.test.tsx +28 -0
  58. package/src/Page.tsx +17 -2
  59. package/src/PickerSelect.tsx +3 -3
  60. package/src/TapToEdit.test.tsx +31 -0
  61. package/src/TapToEdit.tsx +2 -3
  62. package/src/ToastNotifications.test.tsx +738 -0
  63. package/src/ToastNotifications.tsx +2 -2
  64. package/src/Tooltip.test.tsx +587 -2
  65. package/src/Tooltip.tsx +2 -2
  66. package/src/Unifier.ts +14 -11
  67. package/src/Utilities.tsx +14 -16
  68. package/src/WebAddressAutocomplete.test.tsx +138 -0
  69. package/src/WebDropdownMenu.test.tsx +23 -0
  70. package/src/index.tsx +1 -1
  71. package/src/login/LoginScreen.test.tsx +23 -1
  72. package/src/signUp/PasswordRequirements.tsx +9 -6
  73. package/src/signUp/__snapshots__/PasswordRequirements.test.tsx.snap +50 -2
  74. package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +25 -1
  75. package/src/table/TableHeaderCell.tsx +8 -11
  76. package/src/table/TableRow.test.tsx +31 -1
  77. package/src/table/__snapshots__/TableHeaderCell.test.tsx.snap +2 -0
  78. package/src/table/tableContext.tsx +2 -2
  79. package/src/useStoredState.test.tsx +47 -0
@@ -1,5 +1,6 @@
1
1
  // biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
2
2
  import {describe, expect, it, mock} from "bun:test";
3
+ import {act} from "@testing-library/react-native";
3
4
 
4
5
  import {DataTable} from "./DataTable";
5
6
  import {Text} from "./Text";
@@ -131,4 +132,220 @@ describe("DataTable", () => {
131
132
  const {toJSON} = renderWithTheme(<DataTable columns={sampleColumns} data={[]} />);
132
133
  expect(toJSON()).toMatchSnapshot();
133
134
  });
135
+
136
+ it("handles sort cycling: none -> asc -> desc -> none", () => {
137
+ const sortableColumns = [
138
+ {columnType: "text", sortable: true, title: "Name", width: 150},
139
+ {columnType: "text", sortable: false, title: "Age", width: 100},
140
+ ];
141
+ const setSortColumn = mock((_sort?: {column: number; direction: string}) => {});
142
+ const {UNSAFE_getAllByType} = renderWithTheme(
143
+ <DataTable
144
+ columns={sortableColumns}
145
+ data={[[{value: "Alice"}, {value: "28"}]]}
146
+ setSortColumn={setSortColumn}
147
+ />
148
+ );
149
+
150
+ const {Pressable: PressableComp} = require("react-native");
151
+ const pressables = UNSAFE_getAllByType(PressableComp);
152
+ // Find the sort pressable (has hitSlop=16)
153
+ const sortPressable = pressables.find(
154
+ (p: {props: {hitSlop?: number}}) => p.props.hitSlop === 16
155
+ );
156
+ expect(sortPressable).toBeTruthy();
157
+
158
+ const {fireEvent} = require("@testing-library/react-native");
159
+ // First click: none -> asc
160
+ fireEvent.press(sortPressable!);
161
+ expect(setSortColumn).toHaveBeenCalledWith({column: 0, direction: "asc"});
162
+ });
163
+
164
+ it("handles sort from asc to desc", () => {
165
+ const sortableColumns = [{columnType: "text", sortable: true, title: "Name", width: 150}];
166
+ const setSortColumn = mock((_sort?: {column: number; direction: string}) => {});
167
+ const {UNSAFE_getAllByType} = renderWithTheme(
168
+ <DataTable
169
+ columns={sortableColumns}
170
+ data={[[{value: "Alice"}]]}
171
+ setSortColumn={setSortColumn}
172
+ sortColumn={{column: 0, direction: "asc"}}
173
+ />
174
+ );
175
+
176
+ const {Pressable: PressableComp} = require("react-native");
177
+ const pressables = UNSAFE_getAllByType(PressableComp);
178
+ const sortPressable = pressables.find(
179
+ (p: {props: {hitSlop?: number}}) => p.props.hitSlop === 16
180
+ );
181
+
182
+ const {fireEvent} = require("@testing-library/react-native");
183
+ fireEvent.press(sortPressable!);
184
+ expect(setSortColumn).toHaveBeenCalledWith({column: 0, direction: "desc"});
185
+ });
186
+
187
+ it("handles sort from desc to none", () => {
188
+ const sortableColumns = [{columnType: "text", sortable: true, title: "Name", width: 150}];
189
+ const setSortColumn = mock((_sort?: {column: number; direction: string}) => {});
190
+ const {UNSAFE_getAllByType} = renderWithTheme(
191
+ <DataTable
192
+ columns={sortableColumns}
193
+ data={[[{value: "Alice"}]]}
194
+ setSortColumn={setSortColumn}
195
+ sortColumn={{column: 0, direction: "desc"}}
196
+ />
197
+ );
198
+
199
+ const {Pressable: PressableComp} = require("react-native");
200
+ const pressables = UNSAFE_getAllByType(PressableComp);
201
+ const sortPressable = pressables.find(
202
+ (p: {props: {hitSlop?: number}}) => p.props.hitSlop === 16
203
+ );
204
+
205
+ const {fireEvent} = require("@testing-library/react-native");
206
+ fireEvent.press(sortPressable!);
207
+ expect(setSortColumn).toHaveBeenCalledWith(undefined);
208
+ });
209
+
210
+ it("handles sort on non-sortable column (no-op)", () => {
211
+ const columns = [{columnType: "text", sortable: false, title: "Name", width: 150}];
212
+ const setSortColumn = mock(() => {});
213
+ renderWithTheme(
214
+ <DataTable columns={columns} data={[[{value: "Alice"}]]} setSortColumn={setSortColumn} />
215
+ );
216
+ // No sort pressable rendered for non-sortable columns, so no action needed
217
+ expect(setSortColumn).not.toHaveBeenCalled();
218
+ });
219
+
220
+ it("syncs scroll between header and body via refs", () => {
221
+ const {UNSAFE_getAllByType} = renderWithTheme(
222
+ <DataTable columns={sampleColumns} data={sampleData} pinnedColumns={1} />
223
+ );
224
+
225
+ const {ScrollView: ScrollViewComp} = require("react-native");
226
+ const scrollViews = UNSAFE_getAllByType(ScrollViewComp);
227
+ expect(scrollViews.length).toBeGreaterThan(0);
228
+
229
+ // Inject mock scrollTo on the refs so handleScroll branches execute
230
+ const mockScrollTo = mock((_opts: {animated: boolean; x: number}) => {});
231
+ for (const sv of scrollViews) {
232
+ if (sv.props.horizontal) {
233
+ const fiber = (sv as unknown as {_fiber?: {ref?: {current: unknown}}})._fiber;
234
+ if (fiber?.ref && typeof fiber.ref === "object") {
235
+ fiber.ref.current = {scrollTo: mockScrollTo};
236
+ }
237
+ }
238
+ }
239
+
240
+ const {fireEvent} = require("@testing-library/react-native");
241
+ // Find header scroll (onScroll passes isHeader=true)
242
+ const headerScroll = scrollViews.find(
243
+ (sv: {props: {horizontal?: boolean; showsHorizontalScrollIndicator?: boolean}}) =>
244
+ sv.props.horizontal && sv.props.showsHorizontalScrollIndicator === false
245
+ );
246
+ // Find body scroll (onScroll passes isHeader=false)
247
+ const bodyScroll = scrollViews.find(
248
+ (sv: {props: {horizontal?: boolean; showsHorizontalScrollIndicator?: boolean}}) =>
249
+ sv.props.horizontal && sv.props.showsHorizontalScrollIndicator === true
250
+ );
251
+
252
+ if (headerScroll) {
253
+ fireEvent.scroll(headerScroll, {
254
+ nativeEvent: {contentOffset: {x: 50, y: 0}},
255
+ });
256
+ }
257
+ if (bodyScroll) {
258
+ fireEvent.scroll(bodyScroll, {
259
+ nativeEvent: {contentOffset: {x: 75, y: 0}},
260
+ });
261
+ }
262
+
263
+ expect(mockScrollTo).toHaveBeenCalled();
264
+ });
265
+
266
+ it("renders with custom column component map", () => {
267
+ const CustomComponent = ({cellData}: {cellData: {value: unknown}}) => (
268
+ <Text>Custom: {String(cellData.value)}</Text>
269
+ );
270
+ const customColumns = [{columnType: "custom", title: "Custom Col", width: 150}];
271
+ const customData = [[{value: "test"}]];
272
+ const {getByText} = renderWithTheme(
273
+ <DataTable
274
+ columns={customColumns}
275
+ customColumnComponentMap={{custom: CustomComponent as any}}
276
+ data={customData}
277
+ />
278
+ );
279
+ expect(getByText("Custom: test")).toBeTruthy();
280
+ });
281
+
282
+ it("renders with infoModalText on column header", () => {
283
+ const columnsWithInfo = [
284
+ {columnType: "text", infoModalText: "**Help text**", title: "Name", width: 150},
285
+ ];
286
+ const {toJSON} = renderWithTheme(
287
+ <DataTable columns={columnsWithInfo} data={[[{value: "Alice"}]]} />
288
+ );
289
+ expect(toJSON()).toBeTruthy();
290
+ });
291
+
292
+ it("renders with cell highlight", () => {
293
+ const highlightData = [[{highlight: "primary", value: "Highlighted"}]];
294
+ const {toJSON} = renderWithTheme(
295
+ <DataTable columns={[{columnType: "text", title: "Name", width: 150}]} data={highlightData} />
296
+ );
297
+ expect(toJSON()).toBeTruthy();
298
+ });
299
+
300
+ it("renders with moreContentExtraData", () => {
301
+ const MoreContent = ({rowIndex, extraInfo}: {rowIndex: number; extraInfo?: string}) => (
302
+ <Text>
303
+ Row {rowIndex}: {extraInfo}
304
+ </Text>
305
+ );
306
+ const {toJSON} = renderWithTheme(
307
+ <DataTable
308
+ columns={sampleColumns}
309
+ data={sampleData}
310
+ moreContentComponent={MoreContent as any}
311
+ moreContentExtraData={[{extraInfo: "info1"}, {extraInfo: "info2"}, {extraInfo: "info3"}]}
312
+ />
313
+ );
314
+ expect(toJSON()).toBeTruthy();
315
+ });
316
+
317
+ it("opens and dismisses more content modal via MoreButtonCell press", async () => {
318
+ const MoreContent = ({rowIndex}: {rowIndex: number}) => <Text>Detail for row {rowIndex}</Text>;
319
+ const {UNSAFE_getAllByType} = renderWithTheme(
320
+ <DataTable
321
+ columns={sampleColumns}
322
+ data={sampleData}
323
+ moreContentComponent={MoreContent as any}
324
+ />
325
+ );
326
+
327
+ const {Pressable: PressableComp} = require("react-native");
328
+ const {fireEvent} = require("@testing-library/react-native");
329
+ const pressables = UNSAFE_getAllByType(PressableComp);
330
+
331
+ // Find the info/eye icon pressable (MoreButtonCell has accessibilityHint="View details")
332
+ const moreBtn = pressables.find(
333
+ (p: {props: {accessibilityHint?: string}}) => p.props.accessibilityHint === "View details"
334
+ );
335
+ expect(moreBtn).toBeTruthy();
336
+
337
+ // Press to open modal
338
+ await act(async () => {
339
+ fireEvent.press(moreBtn!);
340
+ });
341
+
342
+ // Find the modal dismiss pressable and press it
343
+ const {Modal: ModalComp} = require("./Modal");
344
+ const modals = UNSAFE_getAllByType(ModalComp);
345
+ if (modals.length > 0 && modals[0].props.onDismiss) {
346
+ await act(async () => {
347
+ modals[0].props.onDismiss();
348
+ });
349
+ }
350
+ });
134
351
  });
@@ -7,7 +7,7 @@ const getErrorMessage = (error: unknown): string => {
7
7
  return String(error);
8
8
  };
9
9
 
10
- function getDate(date: string, {timezone}: {timezone?: string} = {}): DateTime {
10
+ const getDate = (date: string, {timezone}: {timezone?: string} = {}): DateTime => {
11
11
  if (!date) {
12
12
  throw new Error("Passed undefined");
13
13
  }
@@ -19,48 +19,48 @@ function getDate(date: string, {timezone}: {timezone?: string} = {}): DateTime {
19
19
  throw new Error(`Invalid date: ${date}`);
20
20
  }
21
21
  return clonedDate;
22
- }
22
+ };
23
23
 
24
- export function isTomorrow(date: string, {timezone}: {timezone?: string} = {}): boolean {
24
+ export const isTomorrow = (date: string, {timezone}: {timezone?: string} = {}): boolean => {
25
25
  const clonedDate = getDate(date, {timezone});
26
26
  const now = timezone ? DateTime.now().setZone(timezone) : DateTime.now();
27
27
  const diff = now.startOf("day").diff(clonedDate.startOf("day"), "days");
28
28
  return diff.days <= -1 && diff.days > -2;
29
- }
29
+ };
30
30
 
31
- export function isYesterday(date: string, {timezone}: {timezone?: string} = {}): boolean {
31
+ export const isYesterday = (date: string, {timezone}: {timezone?: string} = {}): boolean => {
32
32
  const clonedDate = getDate(date, {timezone});
33
33
  const now = timezone ? DateTime.now().setZone(timezone) : DateTime.now();
34
34
  const diff = now.startOf("day").diff(clonedDate.startOf("day"), "days");
35
35
  return diff.days <= 1 && diff.days > -1;
36
- }
36
+ };
37
37
 
38
- export function isToday(date: string, {timezone}: {timezone?: string} = {}): boolean {
38
+ export const isToday = (date: string, {timezone}: {timezone?: string} = {}): boolean => {
39
39
  const clonedDate = getDate(date, {timezone});
40
40
  const now = timezone ? DateTime.now().setZone(timezone) : DateTime.now();
41
41
  const diff = now.startOf("day").diff(clonedDate.startOf("day"), "days");
42
42
  return diff.days === 0;
43
- }
43
+ };
44
44
 
45
- export function isThisYear(date: string, {timezone}: {timezone?: string} = {}): boolean {
45
+ export const isThisYear = (date: string, {timezone}: {timezone?: string} = {}): boolean => {
46
46
  const clonedDate = getDate(date, {timezone});
47
47
  const now = timezone ? DateTime.now().setZone(timezone) : DateTime.now();
48
48
  return clonedDate.year === now.year;
49
- }
49
+ };
50
50
 
51
- export function isWithinWeek(date: string, {timezone}: {timezone?: string} = {}): boolean {
51
+ export const isWithinWeek = (date: string, {timezone}: {timezone?: string} = {}): boolean => {
52
52
  const clonedDate = getDate(date, {timezone});
53
53
  const now = timezone ? DateTime.now().setZone(timezone) : DateTime.now();
54
54
  const diff = now.startOf("day").diff(clonedDate.startOf("day"), "days");
55
55
  return diff.days > -7 && diff.days < 7;
56
- }
56
+ };
57
57
 
58
58
  // Prints a human friendly date, e.g. "Tomorrow", "Yesterday", "Monday", "June 19", "December 25,
59
59
  // 2022".
60
- export function humanDate(
60
+ export const humanDate = (
61
61
  date: string,
62
62
  {timezone, dontShowTime}: {timezone?: string; dontShowTime?: boolean} = {}
63
- ): string {
63
+ ): string => {
64
64
  let clonedDate: DateTime;
65
65
  try {
66
66
  clonedDate = getDate(date, {timezone});
@@ -87,14 +87,14 @@ export function humanDate(
87
87
  // December 25, 2022
88
88
  return clonedDate.toFormat("MMM d, yyyy");
89
89
  }
90
- }
90
+ };
91
91
 
92
92
  // Prints a human friendly date and time, e.g. "Tomorrow 9:00 AM", "Yesterday 9:00 AM", "Monday
93
93
  // 9:00 AM", "June 19 9:00 AM", "December 25, 2022 9:00 AM".
94
- export function humanDateAndTime(
94
+ export const humanDateAndTime = (
95
95
  date: string,
96
96
  {timezone, showTimezone = true}: {timezone?: string; showTimezone?: boolean} = {}
97
- ): string {
97
+ ): string => {
98
98
  let clonedDate: DateTime;
99
99
  try {
100
100
  clonedDate = getDate(date, {timezone});
@@ -128,7 +128,7 @@ export function humanDateAndTime(
128
128
  // December 25, 2022
129
129
  return `${clonedDate.toFormat("MMM d, yyyy")} ${time}`;
130
130
  }
131
- }
131
+ };
132
132
 
133
133
  // Print date in the format of M/D/YY, taking timezones into account.
134
134
  export const printDate = (
@@ -199,7 +199,7 @@ export const printOnlyDate = (
199
199
  };
200
200
 
201
201
  // Print time in the format of HH:mm A, taking timezones into account.
202
- export function printTime(
202
+ export const printTime = (
203
203
  date?: string,
204
204
  {
205
205
  timezone,
@@ -210,7 +210,7 @@ export function printTime(
210
210
  showTimezone?: boolean;
211
211
  defaultValue?: string;
212
212
  } = {defaultValue: "Invalid Date", timezone: "America/New_York"}
213
- ): string {
213
+ ): string => {
214
214
  if (!date) {
215
215
  return defaultValue ?? "Invalid Date";
216
216
  }
@@ -232,10 +232,10 @@ export function printTime(
232
232
  } else {
233
233
  return clonedDate.toLocaleString(DateTime.TIME_SIMPLE);
234
234
  }
235
- }
235
+ };
236
236
 
237
237
  // Print date in the format of M/D/YY HH:mm A, taking timezones into account.
238
- export function printDateAndTime(
238
+ export const printDateAndTime = (
239
239
  date?: string,
240
240
  {
241
241
  timezone,
@@ -246,7 +246,7 @@ export function printDateAndTime(
246
246
  showTimezone?: boolean;
247
247
  defaultValue?: string;
248
248
  } = {}
249
- ): string {
249
+ ): string => {
250
250
  if (!date) {
251
251
  return defaultValue ?? "Invalid Datetime";
252
252
  }
@@ -268,12 +268,12 @@ export function printDateAndTime(
268
268
  } else {
269
269
  return clonedDate.toLocaleString(DateTime.DATETIME_SHORT);
270
270
  }
271
- }
271
+ };
272
272
 
273
273
  // Prints a date range in the format of M/D/YY HH:mm A - M/D/YY HH:mm A EST, taking timezones into
274
274
  // account. If the dates are the same, it will print the date only once, e.g. M/D/YY HH:mm A - HH:mm
275
275
  // A EST.
276
- export function printDateRange(
276
+ export const printDateRange = (
277
277
  start: string,
278
278
  end: string,
279
279
  {
@@ -281,7 +281,7 @@ export function printDateRange(
281
281
  showTimezone = true,
282
282
  timeOnly,
283
283
  }: {timezone: string; showTimezone?: boolean; timeOnly?: boolean}
284
- ): string {
284
+ ): string => {
285
285
  const startDate = printDate(start, {showTimezone: false, timezone});
286
286
  const endDate = printDate(end, {showTimezone: false, timezone});
287
287
 
@@ -299,14 +299,14 @@ export function printDateRange(
299
299
  } else {
300
300
  return `${startDate} ${startTime} - ${endDate} ${endTime}`;
301
301
  }
302
- }
302
+ };
303
303
 
304
304
  // Print since nicely. If less than 2 months, print days, otherwise print months. If over 1 year,
305
305
  // print years.
306
- export function printSince(
306
+ export const printSince = (
307
307
  date: string,
308
308
  {timezone, showAgo = true}: {timezone?: string; showAgo?: boolean} = {}
309
- ): string {
309
+ ): string => {
310
310
  let clonedDate: DateTime;
311
311
  const ago = showAgo ? " ago" : "";
312
312
  try {
@@ -326,20 +326,20 @@ export function printSince(
326
326
  const years = Math.floor(now.diff(clonedDate, "years").years);
327
327
  return `${years} ${years === 1 ? "year" : "years"}${ago}`;
328
328
  }
329
- }
329
+ };
330
330
 
331
- export function convertNullToUndefined(value: string | null): string | undefined {
331
+ export const convertNullToUndefined = (value: string | null): string | undefined => {
332
332
  return value ?? undefined;
333
- }
333
+ };
334
334
 
335
335
  // Get the ISO date string from a date string. If the date string is undefined,
336
336
  // return undefined instead of null so MongoDB can handle it.
337
- export function getIsoDate(date: string | undefined): string | undefined {
337
+ export const getIsoDate = (date: string | undefined): string | undefined => {
338
338
  if (!date) {
339
339
  return undefined;
340
340
  }
341
341
  return convertNullToUndefined(DateTime.fromISO(date).toUTC().toISO());
342
- }
342
+ };
343
343
 
344
344
  const usTimezoneOptions = [
345
345
  {label: "Eastern", value: "America/New_York"},
@@ -351,7 +351,7 @@ const usTimezoneOptions = [
351
351
  {label: "Arizona", value: "America/Phoenix"},
352
352
  ];
353
353
 
354
- export function getTimezoneOptions(location: "USA" | "Worldwide", shortTimezone = false) {
354
+ export const getTimezoneOptions = (location: "USA" | "Worldwide", shortTimezone = false) => {
355
355
  let timezones: [string, string][];
356
356
  if (location === "USA") {
357
357
  timezones = usTimezoneOptions.map((tz) => [tz.label, tz.value]);
@@ -366,9 +366,8 @@ export function getTimezoneOptions(location: "USA" | "Worldwide", shortTimezone
366
366
  }
367
367
  return timezones.map(([name, tz]) => {
368
368
  const dateTime = DateTime.now().setZone(tz);
369
- let tzAbbr = dateTime.toFormat("ZZZZ"); // Gets timezone abbreviation like "EST", "CST", etc.
369
+ let tzAbbr = dateTime.toFormat("ZZZZ");
370
370
 
371
- // Special case for Arizona which returns MST during standard time
372
371
  if (tz === "America/Phoenix") {
373
372
  tzAbbr = "AZ";
374
373
  }
@@ -378,4 +377,4 @@ export function getTimezoneOptions(location: "USA" | "Worldwide", shortTimezone
378
377
  value: tz,
379
378
  };
380
379
  });
381
- }
380
+ };
@@ -3,6 +3,7 @@ import {act, render} from "@testing-library/react-native";
3
3
  import {createRef} from "react";
4
4
 
5
5
  import type {ActionSheet} from "./ActionSheet";
6
+ import {Button} from "./Button";
6
7
  import {HeightActionSheet} from "./HeightActionSheet";
7
8
  import {ThemeProvider} from "./Theme";
8
9
 
@@ -86,4 +87,19 @@ describe("HeightActionSheet", () => {
86
87
  });
87
88
  expect(handleChange).toHaveBeenCalled();
88
89
  });
90
+
91
+ it("calls the Done button onClick handler directly", () => {
92
+ const actionSheetRef = createRef<ActionSheet>();
93
+ const {UNSAFE_root} = render(
94
+ <ThemeProvider>
95
+ <HeightActionSheet actionSheetRef={actionSheetRef} onChange={() => {}} value="60" />
96
+ </ThemeProvider>
97
+ );
98
+ const buttons = UNSAFE_root.findAllByType(Button as never);
99
+ const doneBtn = buttons.find((b) => b.props.text === "Done");
100
+ expect(doneBtn).toBeTruthy();
101
+ act(() => {
102
+ doneBtn!.props.onClick();
103
+ });
104
+ });
89
105
  });
@@ -1,8 +1,9 @@
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 {fireEvent} from "@testing-library/react-native";
3
3
  import {HeightActionSheet} from "./HeightActionSheet";
4
4
  import {HeightField} from "./HeightField";
5
5
  import {renderWithTheme} from "./test-utils";
6
+ import * as Utilities from "./Utilities";
6
7
 
7
8
  describe("HeightField", () => {
8
9
  let mockOnChange: ReturnType<typeof mock>;
@@ -274,3 +275,107 @@ describe("HeightField - Android platform", () => {
274
275
  expect(onChange).toHaveBeenCalledWith("63");
275
276
  });
276
277
  });
278
+
279
+ describe("HeightField - Desktop platform", () => {
280
+ const {Platform} = require("react-native") as {Platform: {OS: string}};
281
+ const originalOS = Platform.OS;
282
+ let isNativeSpy: ReturnType<typeof spyOn>;
283
+
284
+ beforeEach(() => {
285
+ Platform.OS = "web";
286
+ isNativeSpy = spyOn(Utilities, "isNative").mockReturnValue(false);
287
+ });
288
+
289
+ afterEach(() => {
290
+ Platform.OS = originalOS;
291
+ isNativeSpy.mockRestore();
292
+ });
293
+
294
+ it("fires handleBlur on HeightSegment and calls onChange", () => {
295
+ const onChange = mock(() => {});
296
+ const {getByLabelText} = renderWithTheme(<HeightField onChange={onChange} value="70" />);
297
+ const feetInput = getByLabelText("ft input");
298
+ fireEvent(feetInput, "blur");
299
+ expect(onChange).toHaveBeenCalled();
300
+ });
301
+
302
+ it("handles text input change in feet segment", () => {
303
+ const onChange = mock(() => {});
304
+ const {getByLabelText} = renderWithTheme(<HeightField onChange={onChange} value="70" />);
305
+ const feetInput = getByLabelText("ft input");
306
+ fireEvent.changeText(feetInput, "6");
307
+ expect(onChange).toHaveBeenCalled();
308
+ });
309
+
310
+ it("handles clearing feet input to empty", () => {
311
+ const onChange = mock(() => {});
312
+ const {getByLabelText} = renderWithTheme(<HeightField onChange={onChange} value="70" />);
313
+ const feetInput = getByLabelText("ft input");
314
+ fireEvent.changeText(feetInput, "");
315
+ expect(onChange).toHaveBeenCalled();
316
+ });
317
+
318
+ it("calls onChange with empty when both feet and inches are cleared", () => {
319
+ const onChange = mock(() => {});
320
+ const {getByLabelText} = renderWithTheme(<HeightField onChange={onChange} value="" />);
321
+ const feetInput = getByLabelText("ft input");
322
+ fireEvent.changeText(feetInput, "");
323
+ expect(onChange).toHaveBeenCalledWith("");
324
+ });
325
+
326
+ it("renders HeightSegment in disabled state", () => {
327
+ const onChange = mock(() => {});
328
+ const {getByLabelText} = renderWithTheme(
329
+ <HeightField disabled onChange={onChange} value="70" />
330
+ );
331
+ expect(getByLabelText("ft input")).toBeTruthy();
332
+ });
333
+
334
+ it("renders HeightSegment with error text", () => {
335
+ const onChange = mock(() => {});
336
+ const {getByLabelText} = renderWithTheme(
337
+ <HeightField errorText="Required" onChange={onChange} value="70" />
338
+ );
339
+ expect(getByLabelText("ft input")).toBeTruthy();
340
+ });
341
+
342
+ it("fires focus on feet segment", () => {
343
+ const onChange = mock(() => {});
344
+ const {getByLabelText} = renderWithTheme(<HeightField onChange={onChange} value="70" />);
345
+ const feetInput = getByLabelText("ft input");
346
+ fireEvent(feetInput, "focus");
347
+ expect(feetInput).toBeTruthy();
348
+ });
349
+
350
+ it("fires focus on inches segment", () => {
351
+ const onChange = mock(() => {});
352
+ const {getByLabelText} = renderWithTheme(<HeightField onChange={onChange} value="70" />);
353
+ const inInput = getByLabelText("in input");
354
+ fireEvent(inInput, "focus");
355
+ expect(inInput).toBeTruthy();
356
+ });
357
+
358
+ it("handles text input change in inches segment", () => {
359
+ const onChange = mock(() => {});
360
+ const {getByLabelText} = renderWithTheme(<HeightField onChange={onChange} value="70" />);
361
+ const inInput = getByLabelText("in input");
362
+ fireEvent.changeText(inInput, "3");
363
+ expect(onChange).toHaveBeenCalled();
364
+ });
365
+
366
+ it("handles non-numeric input in HeightSegment", () => {
367
+ const onChange = mock(() => {});
368
+ const {getByLabelText} = renderWithTheme(<HeightField onChange={onChange} value="70" />);
369
+ const feetInput = getByLabelText("ft input");
370
+ fireEvent.changeText(feetInput, "abc");
371
+ expect(onChange).toHaveBeenCalled();
372
+ });
373
+
374
+ it("clamps to max value in HeightSegment handleChange", () => {
375
+ const onChange = mock(() => {});
376
+ const {getByLabelText} = renderWithTheme(<HeightField onChange={onChange} value="70" />);
377
+ const feetInput = getByLabelText("ft input");
378
+ fireEvent.changeText(feetInput, "99");
379
+ expect(feetInput).toBeTruthy();
380
+ });
381
+ });
package/src/MediaQuery.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import {Dimensions} from "react-native";
2
2
 
3
- export function mediaQuery(): "xs" | "sm" | "md" | "lg" {
3
+ export const mediaQuery = (): "xs" | "sm" | "md" | "lg" => {
4
4
  const width = Dimensions.get("window").width;
5
5
  if (width < 576) {
6
6
  return "xs";
@@ -11,9 +11,9 @@ export function mediaQuery(): "xs" | "sm" | "md" | "lg" {
11
11
  } else {
12
12
  return "lg";
13
13
  }
14
- }
14
+ };
15
15
 
16
- export function mediaQueryLargerThan(size: "xs" | "sm" | "md" | "lg"): boolean {
16
+ export const mediaQueryLargerThan = (size: "xs" | "sm" | "md" | "lg"): boolean => {
17
17
  const media = mediaQuery();
18
18
  if (size === "xs") {
19
19
  return true;
@@ -25,9 +25,9 @@ export function mediaQueryLargerThan(size: "xs" | "sm" | "md" | "lg"): boolean {
25
25
  return ["lg"].includes(media);
26
26
  }
27
27
  return false;
28
- }
28
+ };
29
29
 
30
- export function mediaQuerySmallerThan(size: "xs" | "sm" | "md" | "lg"): boolean {
30
+ export const mediaQuerySmallerThan = (size: "xs" | "sm" | "md" | "lg"): boolean => {
31
31
  const media = mediaQuery();
32
32
  if (size === "lg") {
33
33
  return true;
@@ -39,8 +39,8 @@ export function mediaQuerySmallerThan(size: "xs" | "sm" | "md" | "lg"): boolean
39
39
  return ["xs"].includes(media);
40
40
  }
41
41
  return false;
42
- }
42
+ };
43
43
 
44
- export function isMobileDevice(): boolean {
44
+ export const isMobileDevice = (): boolean => {
45
45
  return !mediaQueryLargerThan("sm");
46
- }
46
+ };
@@ -1,5 +1,5 @@
1
1
  import {describe, expect, it, mock} from "bun:test";
2
- import {fireEvent} from "@testing-library/react-native";
2
+ import {act, fireEvent} from "@testing-library/react-native";
3
3
  import {forwardRef, useImperativeHandle, useRef} from "react";
4
4
  import {Pressable, Text, View} from "react-native";
5
5
 
@@ -185,4 +185,23 @@ describe("MobileAddressAutocomplete", () => {
185
185
  expect(wrapper).toBeTruthy();
186
186
  expect(() => wrapper.props.onPress?.()).not.toThrow();
187
187
  });
188
+
189
+ it("fires handleAddressChange from the fallback TextField onChange", () => {
190
+ const handleAddressChange = mock(() => {});
191
+ const {TextField} = require("./TextField") as {
192
+ TextField: React.ComponentType<{onChange?: (v: string) => void}>;
193
+ };
194
+ const {UNSAFE_getByType} = renderWithTheme(
195
+ <MobileAddressAutocomplete
196
+ handleAddressChange={handleAddressChange}
197
+ handleAutoCompleteChange={() => {}}
198
+ inputValue=""
199
+ />
200
+ );
201
+ const textField = UNSAFE_getByType(TextField);
202
+ act(() => {
203
+ textField.props.onChange?.("789 Elm St");
204
+ });
205
+ expect(handleAddressChange).toHaveBeenCalledWith("789 Elm St");
206
+ });
188
207
  });