@terreno/ui 0.14.1 → 0.15.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.
Files changed (70) hide show
  1. package/dist/ActionSheet.js +15 -27
  2. package/dist/ActionSheet.js.map +1 -1
  3. package/dist/Badge.js +1 -0
  4. package/dist/Badge.js.map +1 -1
  5. package/dist/Banner.d.ts +8 -0
  6. package/dist/Banner.js +2 -2
  7. package/dist/Banner.js.map +1 -1
  8. package/dist/MarkdownView.js +20 -7
  9. package/dist/MarkdownView.js.map +1 -1
  10. package/dist/PickerSelect.js +6 -2
  11. package/dist/PickerSelect.js.map +1 -1
  12. package/dist/Signature.d.ts +8 -1
  13. package/dist/Signature.js +93 -18
  14. package/dist/Signature.js.map +1 -1
  15. package/dist/Signature.native.d.ts +15 -0
  16. package/dist/Signature.native.js +116 -21
  17. package/dist/Signature.native.js.map +1 -1
  18. package/dist/TapToEdit.js +1 -1
  19. package/dist/TapToEdit.js.map +1 -1
  20. package/dist/index.d.ts +1 -1
  21. package/dist/index.js +1 -1
  22. package/dist/index.js.map +1 -1
  23. package/dist/useConsentHistory.d.ts +6 -1
  24. package/dist/useConsentHistory.js +2 -1
  25. package/dist/useConsentHistory.js.map +1 -1
  26. package/package.json +2 -4
  27. package/src/ActionSheet.test.tsx +554 -0
  28. package/src/ActionSheet.tsx +24 -37
  29. package/src/Badge.test.tsx +7 -0
  30. package/src/Badge.tsx +1 -0
  31. package/src/Banner.test.tsx +58 -3
  32. package/src/Banner.tsx +3 -3
  33. package/src/DataTable.test.tsx +176 -1
  34. package/src/DateTimeField.test.tsx +942 -2
  35. package/src/Field.test.tsx +23 -0
  36. package/src/HeightActionSheet.test.tsx +1 -1
  37. package/src/HeightField.test.tsx +35 -0
  38. package/src/HeightFieldDesktop.test.tsx +19 -0
  39. package/src/MarkdownView.test.tsx +28 -0
  40. package/src/MarkdownView.tsx +69 -7
  41. package/src/MobileAddressAutoComplete.test.tsx +6 -2
  42. package/src/PickerSelect.test.tsx +265 -0
  43. package/src/PickerSelect.tsx +24 -8
  44. package/src/Signature.native.tsx +147 -30
  45. package/src/Signature.test.tsx +2 -49
  46. package/src/Signature.tsx +128 -22
  47. package/src/SignatureField.test.tsx +0 -9
  48. package/src/SplitPage.test.tsx +299 -43
  49. package/src/TapToEdit.test.tsx +46 -0
  50. package/src/TapToEdit.tsx +1 -1
  51. package/src/ToastNotifications.test.tsx +748 -1
  52. package/src/Tooltip.test.tsx +707 -1
  53. package/src/WebAddressAutocomplete.test.tsx +99 -0
  54. package/src/WebDropdownMenu.test.tsx +28 -2
  55. package/src/__snapshots__/Banner.test.tsx.snap +125 -0
  56. package/src/__snapshots__/CustomSelectField.test.tsx.snap +5 -4
  57. package/src/__snapshots__/DataTable.test.tsx.snap +366 -0
  58. package/src/__snapshots__/Field.test.tsx.snap +377 -0
  59. package/src/__snapshots__/MarkdownView.test.tsx.snap +284 -74
  60. package/src/__snapshots__/PickerSelect.test.tsx.snap +5 -4
  61. package/src/__snapshots__/SegmentedControl.test.tsx.snap +9 -0
  62. package/src/__snapshots__/SelectField.test.tsx.snap +5 -4
  63. package/src/__snapshots__/Signature.test.tsx.snap +13 -3
  64. package/src/__snapshots__/SignatureField.test.tsx.snap +10 -3
  65. package/src/__snapshots__/SplitPage.test.tsx.snap +698 -46
  66. package/src/bunSetup.ts +0 -19
  67. package/src/index.tsx +1 -1
  68. package/src/login/LoginScreen.test.tsx +12 -0
  69. package/src/useConsentHistory.test.ts +20 -13
  70. package/src/useConsentHistory.ts +7 -2
@@ -1,12 +1,17 @@
1
- import {describe, expect, it, mock} from "bun:test";
2
- import {act, fireEvent, waitFor} from "@testing-library/react-native";
1
+ import {beforeEach, describe, expect, it, mock} from "bun:test";
2
+ import {act, fireEvent, render, waitFor} from "@testing-library/react-native";
3
3
  import React from "react";
4
4
 
5
- import {Banner} from "./Banner";
5
+ import {Banner, BannerButton, hideBanner} from "./Banner";
6
+ import {ThemeContext} from "./Theme";
6
7
  import {renderWithTheme} from "./test-utils";
7
8
  import {Unifier} from "./Unifier";
8
9
 
9
10
  describe("Banner", () => {
11
+ beforeEach(() => {
12
+ Unifier.storage.getItem = mock(() => Promise.resolve(null));
13
+ Unifier.storage.setItem = mock(() => Promise.resolve());
14
+ });
10
15
  it("renders correctly with default props", () => {
11
16
  const {toJSON} = renderWithTheme(<Banner id="test-banner" text="Test message" />);
12
17
  expect(toJSON()).toMatchSnapshot();
@@ -239,4 +244,54 @@ describe("Banner", () => {
239
244
 
240
245
  expect(handleClick).toHaveBeenCalled();
241
246
  });
247
+
248
+ it("hideBanner persists the banner id to storage", async () => {
249
+ const setItemMock = Unifier.storage.setItem as ReturnType<typeof mock>;
250
+ setItemMock.mockClear();
251
+
252
+ await hideBanner("my-banner");
253
+ expect(setItemMock).toHaveBeenCalledWith("@TerrenoUI:my-banner", "true");
254
+ });
255
+
256
+ it("renders with button loading state", () => {
257
+ const handleClick = mock(() => Promise.resolve());
258
+ const {toJSON} = renderWithTheme(
259
+ <Banner
260
+ buttonOnClick={handleClick}
261
+ buttonText="Loading"
262
+ id="test-banner"
263
+ loading
264
+ text="Banner loading"
265
+ />
266
+ );
267
+ expect(toJSON()).toMatchSnapshot();
268
+ });
269
+
270
+ it("renders banner with dismissible=true and no id (non-persistent dismiss)", async () => {
271
+ const {getByLabelText, queryByText} = renderWithTheme(
272
+ <Banner dismissible text="Non persistent" />
273
+ );
274
+ expect(queryByText("Non persistent")).toBeTruthy();
275
+ await act(async () => {
276
+ fireEvent.press(getByLabelText("Dismiss"));
277
+ });
278
+ await waitFor(() => {
279
+ expect(queryByText("Non persistent")).toBeNull();
280
+ });
281
+ });
282
+
283
+ it("BannerButton returns null when theme is not available", () => {
284
+ const nullThemeContext = {
285
+ resetTheme: () => {},
286
+ setPrimitives: () => {},
287
+ setTheme: () => {},
288
+ theme: null,
289
+ };
290
+ const {toJSON} = render(
291
+ <ThemeContext.Provider value={nullThemeContext as never}>
292
+ <BannerButton buttonOnClick={() => {}} buttonText="Test" />
293
+ </ThemeContext.Provider>
294
+ );
295
+ expect(toJSON()).toBeNull();
296
+ });
242
297
  });
package/src/Banner.tsx CHANGED
@@ -17,7 +17,7 @@ type BannerButtonProps = {
17
17
  loading?: boolean;
18
18
  };
19
19
 
20
- const BannerButton = ({
20
+ export const BannerButton = ({
21
21
  loading: propsLoading,
22
22
  buttonText,
23
23
  buttonIconName,
@@ -178,14 +178,14 @@ export const Banner = (props: BannerProps): React.ReactElement | null => {
178
178
  <View style={{paddingLeft: 16, paddingRight: 10}}>
179
179
  <BannerButton
180
180
  buttonIconName={buttonIconName}
181
- buttonOnClick={buttonOnClick ?? (() => {})}
181
+ buttonOnClick={buttonOnClick!}
182
182
  buttonText={buttonText}
183
183
  />
184
184
  </View>
185
185
  )}
186
186
  {Boolean(buttonText && !buttonIconName && buttonOnClick) && (
187
187
  <View style={{paddingLeft: 16, paddingRight: 10}}>
188
- <BannerButton buttonOnClick={buttonOnClick ?? (() => {})} buttonText={buttonText} />
188
+ <BannerButton buttonOnClick={buttonOnClick!} buttonText={buttonText} />
189
189
  </View>
190
190
  )}
191
191
  </View>
@@ -2,6 +2,7 @@
2
2
  import {describe, expect, it, mock} from "bun:test";
3
3
  import {act} from "@testing-library/react-native";
4
4
 
5
+ import type {DataTableCustomComponentMap, DataTableProps} from "./Common";
5
6
  import {DataTable} from "./DataTable";
6
7
  import {Text} from "./Text";
7
8
  import {renderWithTheme} from "./test-utils";
@@ -115,7 +116,7 @@ describe("DataTable", () => {
115
116
  <DataTable
116
117
  columns={sampleColumns}
117
118
  data={sampleData}
118
- moreContentComponent={MoreContent as any}
119
+ moreContentComponent={MoreContent as unknown as DataTableProps["moreContentComponent"]}
119
120
  />
120
121
  );
121
122
  expect(toJSON()).toMatchSnapshot();
@@ -348,4 +349,178 @@ describe("DataTable", () => {
348
349
  });
349
350
  }
350
351
  });
352
+
353
+ it("renders with customColumnComponentMap", () => {
354
+ const CustomCell = ({cellData}: {cellData: {value: unknown}; column: unknown}) => (
355
+ <Text>Custom: {String(cellData.value)}</Text>
356
+ );
357
+ const customColumns = [
358
+ {columnType: "custom", title: "Custom Col", width: 150},
359
+ {columnType: "text", title: "Name", width: 100},
360
+ ];
361
+ const customData = [[{value: "A"}, {value: "Bob"}]];
362
+ const {getByText} = renderWithTheme(
363
+ <DataTable
364
+ columns={customColumns}
365
+ customColumnComponentMap={{custom: CustomCell} as DataTableCustomComponentMap}
366
+ data={customData}
367
+ />
368
+ );
369
+ expect(getByText("Custom: A")).toBeTruthy();
370
+ });
371
+
372
+ it("handleSort cycles through asc, desc, and clear", () => {
373
+ const sortableColumns = [
374
+ {columnType: "text", sortable: true, title: "Name", width: 150},
375
+ {columnType: "text", sortable: false, title: "Age", width: 100},
376
+ ];
377
+ const setSortColumn = mock((_val: unknown) => {});
378
+ const {UNSAFE_getAllByType} = renderWithTheme(
379
+ <DataTable
380
+ columns={sortableColumns}
381
+ data={[[{value: "Alice"}, {value: "28"}]]}
382
+ setSortColumn={setSortColumn}
383
+ />
384
+ );
385
+
386
+ const {Pressable: PressableComp} = require("react-native");
387
+ const pressables = UNSAFE_getAllByType(PressableComp);
388
+ const sortButton = pressables.find((p: {props: {hitSlop?: number}}) => p.props.hitSlop === 16);
389
+ expect(sortButton).toBeTruthy();
390
+
391
+ // First press: asc
392
+ act(() => {
393
+ sortButton!.props.onPress();
394
+ });
395
+ expect(setSortColumn).toHaveBeenCalledWith({column: 0, direction: "asc"});
396
+ });
397
+
398
+ it("handleSort from asc to desc", () => {
399
+ const sortableColumns = [{columnType: "text", sortable: true, title: "Name", width: 150}];
400
+ const setSortColumn = mock((_val: unknown) => {});
401
+ const {UNSAFE_getAllByType} = renderWithTheme(
402
+ <DataTable
403
+ columns={sortableColumns}
404
+ data={[[{value: "Alice"}]]}
405
+ setSortColumn={setSortColumn}
406
+ sortColumn={{column: 0, direction: "asc"}}
407
+ />
408
+ );
409
+
410
+ const {Pressable: PressableComp} = require("react-native");
411
+ const pressables = UNSAFE_getAllByType(PressableComp);
412
+ const sortButton = pressables.find((p: {props: {hitSlop?: number}}) => p.props.hitSlop === 16);
413
+
414
+ act(() => {
415
+ sortButton!.props.onPress();
416
+ });
417
+ expect(setSortColumn).toHaveBeenCalledWith({column: 0, direction: "desc"});
418
+ });
419
+
420
+ it("handleSort from desc clears sort", () => {
421
+ const sortableColumns = [{columnType: "text", sortable: true, title: "Name", width: 150}];
422
+ const setSortColumn = mock((_val: unknown) => {});
423
+ const {UNSAFE_getAllByType} = renderWithTheme(
424
+ <DataTable
425
+ columns={sortableColumns}
426
+ data={[[{value: "Alice"}]]}
427
+ setSortColumn={setSortColumn}
428
+ sortColumn={{column: 0, direction: "desc"}}
429
+ />
430
+ );
431
+
432
+ const {Pressable: PressableComp} = require("react-native");
433
+ const pressables = UNSAFE_getAllByType(PressableComp);
434
+ const sortButton = pressables.find((p: {props: {hitSlop?: number}}) => p.props.hitSlop === 16);
435
+
436
+ act(() => {
437
+ sortButton!.props.onPress();
438
+ });
439
+ expect(setSortColumn).toHaveBeenCalledWith(undefined);
440
+ });
441
+
442
+ it("handleSort does nothing for non-sortable column", () => {
443
+ const columns = [{columnType: "text", sortable: false, title: "Name", width: 150}];
444
+ const setSortColumn = mock((_val: unknown) => {});
445
+ const {toJSON} = renderWithTheme(
446
+ <DataTable columns={columns} data={[[{value: "Alice"}]]} setSortColumn={setSortColumn} />
447
+ );
448
+ expect(toJSON()).toBeTruthy();
449
+ });
450
+
451
+ it("handleScroll syncs header and body scroll positions", () => {
452
+ const {UNSAFE_getAllByType} = renderWithTheme(
453
+ <DataTable columns={sampleColumns} data={sampleData} pinnedColumns={1} />
454
+ );
455
+
456
+ const {ScrollView: ScrollViewComp} = require("react-native");
457
+ const scrollViews = UNSAFE_getAllByType(ScrollViewComp);
458
+ const horizontalScrollViews = scrollViews.filter(
459
+ (sv: {props: {horizontal?: boolean}}) => sv.props.horizontal
460
+ );
461
+
462
+ if (horizontalScrollViews.length >= 2) {
463
+ // Trigger scroll on the body scroll view
464
+ act(() => {
465
+ horizontalScrollViews[1].props.onScroll({
466
+ nativeEvent: {contentOffset: {x: 50, y: 0}},
467
+ });
468
+ });
469
+
470
+ // Trigger scroll on the header scroll view
471
+ act(() => {
472
+ horizontalScrollViews[0].props.onScroll({
473
+ nativeEvent: {contentOffset: {x: 100, y: 0}},
474
+ });
475
+ });
476
+ }
477
+ });
478
+
479
+ it("renders with cell highlight color", () => {
480
+ const highlightData = [[{highlight: "primary", value: "Highlighted"}]];
481
+ const highlightColumns = [{columnType: "text", title: "Col", width: 150}];
482
+ const {toJSON} = renderWithTheme(<DataTable columns={highlightColumns} data={highlightData} />);
483
+ expect(toJSON()).toBeTruthy();
484
+ });
485
+
486
+ it("opens and closes more content modal", () => {
487
+ const MoreContent = ({rowIndex}: {rowIndex: number}) => <Text>Row {rowIndex} details</Text>;
488
+ const {UNSAFE_getAllByType} = renderWithTheme(
489
+ <DataTable
490
+ columns={sampleColumns}
491
+ data={sampleData}
492
+ moreContentComponent={MoreContent as unknown as DataTableProps["moreContentComponent"]}
493
+ />
494
+ );
495
+
496
+ const {Pressable: PressableComp} = require("react-native");
497
+ const pressables = UNSAFE_getAllByType(PressableComp);
498
+ // Find the "Open modal" button (MoreButtonCell)
499
+ const moreButton = pressables.find(
500
+ (p: {props: {accessibilityLabel?: string}}) => p.props.accessibilityLabel === "Open modal"
501
+ );
502
+
503
+ if (moreButton) {
504
+ act(() => {
505
+ moreButton.props.onPress();
506
+ });
507
+ }
508
+ });
509
+
510
+ it("handleSort with no setSortColumn is a no-op", () => {
511
+ const sortableColumns = [{columnType: "text", sortable: true, title: "Name", width: 150}];
512
+ const {UNSAFE_getAllByType} = renderWithTheme(
513
+ <DataTable columns={sortableColumns} data={[[{value: "Alice"}]]} />
514
+ );
515
+
516
+ const {Pressable: PressableComp} = require("react-native");
517
+ const pressables = UNSAFE_getAllByType(PressableComp);
518
+ const sortButton = pressables.find((p: {props: {hitSlop?: number}}) => p.props.hitSlop === 16);
519
+
520
+ if (sortButton) {
521
+ act(() => {
522
+ sortButton.props.onPress();
523
+ });
524
+ }
525
+ });
351
526
  });