@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.
- package/dist/ActionSheet.js +15 -27
- package/dist/ActionSheet.js.map +1 -1
- package/dist/MarkdownView.js +20 -7
- package/dist/MarkdownView.js.map +1 -1
- package/dist/useConsentHistory.d.ts +6 -1
- package/dist/useConsentHistory.js +2 -1
- package/dist/useConsentHistory.js.map +1 -1
- package/package.json +1 -1
- package/src/ActionSheet.test.tsx +554 -0
- package/src/ActionSheet.tsx +24 -37
- package/src/Banner.test.tsx +36 -1
- package/src/DataTable.test.tsx +176 -1
- package/src/DateTimeField.test.tsx +716 -2
- package/src/HeightActionSheet.test.tsx +1 -1
- package/src/HeightField.test.tsx +35 -0
- package/src/HeightFieldDesktop.test.tsx +19 -0
- package/src/MarkdownView.test.tsx +28 -0
- package/src/MarkdownView.tsx +69 -7
- package/src/MobileAddressAutoComplete.test.tsx +6 -2
- package/src/PickerSelect.test.tsx +243 -0
- package/src/SplitPage.test.tsx +299 -43
- package/src/TapToEdit.test.tsx +13 -0
- package/src/ToastNotifications.test.tsx +674 -0
- package/src/Tooltip.test.tsx +707 -1
- package/src/WebAddressAutocomplete.test.tsx +99 -0
- package/src/WebDropdownMenu.test.tsx +28 -2
- package/src/__snapshots__/Banner.test.tsx.snap +125 -0
- package/src/__snapshots__/DataTable.test.tsx.snap +366 -0
- package/src/__snapshots__/MarkdownView.test.tsx.snap +284 -74
- package/src/__snapshots__/SplitPage.test.tsx.snap +698 -46
- package/src/bunSetup.ts +0 -4
- package/src/login/LoginScreen.test.tsx +12 -0
- package/src/useConsentHistory.test.ts +20 -13
- package/src/useConsentHistory.ts +7 -2
package/src/DataTable.test.tsx
CHANGED
|
@@ -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
|
|
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
|
});
|