@terreno/ui 57.6.1 → 57.8.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 (77) hide show
  1. package/dist/Avatar.js +2 -2
  2. package/dist/Avatar.js.map +1 -1
  3. package/dist/Button.js +2 -2
  4. package/dist/Button.js.map +1 -1
  5. package/dist/Common.d.ts +93 -5
  6. package/dist/Common.d.ts.map +1 -1
  7. package/dist/Common.js.map +1 -1
  8. package/dist/DateTimeActionSheet.js +2 -2
  9. package/dist/DateTimeActionSheet.js.map +1 -1
  10. package/dist/DateTimeField.js +3 -3
  11. package/dist/DateTimeField.js.map +1 -1
  12. package/dist/DropdownPanel.d.ts +24 -0
  13. package/dist/DropdownPanel.d.ts.map +1 -0
  14. package/dist/DropdownPanel.js +186 -0
  15. package/dist/DropdownPanel.js.map +1 -0
  16. package/dist/HeightField.js +2 -2
  17. package/dist/HeightField.js.map +1 -1
  18. package/dist/IconButton.d.ts.map +1 -1
  19. package/dist/IconButton.js +9 -6
  20. package/dist/IconButton.js.map +1 -1
  21. package/dist/MediaQuery.d.ts +10 -0
  22. package/dist/MediaQuery.d.ts.map +1 -1
  23. package/dist/MediaQuery.js +13 -1
  24. package/dist/MediaQuery.js.map +1 -1
  25. package/dist/MultiselectField.js +2 -2
  26. package/dist/MultiselectField.js.map +1 -1
  27. package/dist/RadioField.js +2 -2
  28. package/dist/RadioField.js.map +1 -1
  29. package/dist/SplitPage.d.ts +1 -1
  30. package/dist/SplitPage.d.ts.map +1 -1
  31. package/dist/SplitPage.js +126 -21
  32. package/dist/SplitPage.js.map +1 -1
  33. package/dist/UnifiedAddressAutoComplete.js +2 -2
  34. package/dist/UnifiedAddressAutoComplete.js.map +1 -1
  35. package/dist/dataTableFilters.js +3 -3
  36. package/dist/dataTableFilters.js.map +1 -1
  37. package/dist/dropdownPanelLayout.d.ts +59 -0
  38. package/dist/dropdownPanelLayout.d.ts.map +1 -0
  39. package/dist/dropdownPanelLayout.js +57 -0
  40. package/dist/dropdownPanelLayout.js.map +1 -0
  41. package/dist/fieldElements/FieldTitle.js +2 -2
  42. package/dist/fieldElements/FieldTitle.js.map +1 -1
  43. package/dist/index.d.ts +2 -1
  44. package/dist/index.d.ts.map +1 -1
  45. package/dist/index.js +2 -1
  46. package/dist/index.js.map +1 -1
  47. package/package.json +1 -1
  48. package/src/Avatar.tsx +2 -2
  49. package/src/Button.test.tsx +7 -7
  50. package/src/Button.tsx +2 -2
  51. package/src/Common.ts +93 -5
  52. package/src/DateTimeActionSheet.tsx +4 -4
  53. package/src/DateTimeField.test.tsx +5 -4
  54. package/src/DateTimeField.tsx +3 -3
  55. package/src/{Filter.test.tsx → DropdownPanel.test.tsx} +141 -43
  56. package/src/{Filter.tsx → DropdownPanel.tsx} +145 -74
  57. package/src/HeightField.tsx +2 -2
  58. package/src/IconButton.test.tsx +63 -0
  59. package/src/IconButton.tsx +10 -5
  60. package/src/MediaQuery.ts +14 -1
  61. package/src/MultiselectField.tsx +2 -2
  62. package/src/RadioField.tsx +2 -2
  63. package/src/SplitPage.test.tsx +449 -11
  64. package/src/SplitPage.tsx +255 -21
  65. package/src/UnifiedAddressAutoComplete.test.tsx +4 -4
  66. package/src/UnifiedAddressAutoComplete.tsx +2 -2
  67. package/src/__snapshots__/{Filter.test.tsx.snap → DropdownPanel.test.tsx.snap} +6 -2
  68. package/src/bunSetup.ts +8 -1
  69. package/src/dataTableFilters.tsx +5 -5
  70. package/src/dropdownPanelLayout.test.ts +140 -0
  71. package/src/dropdownPanelLayout.ts +131 -0
  72. package/src/fieldElements/FieldTitle.tsx +2 -2
  73. package/src/index.tsx +2 -1
  74. package/dist/Filter.d.ts +0 -14
  75. package/dist/Filter.d.ts.map +0 -1
  76. package/dist/Filter.js +0 -145
  77. package/dist/Filter.js.map +0 -1
@@ -1,21 +1,58 @@
1
- import {afterAll, afterEach, beforeEach, describe, expect, it, mock} from "bun:test";
2
- import {act} from "@testing-library/react-native";
3
- import {View} from "react-native";
1
+ import {afterAll, afterEach, beforeEach, describe, expect, it, mock, spyOn} from "bun:test";
2
+ import {act, fireEvent} from "@testing-library/react-native";
3
+ import {forwardRef, type ReactNode, type Ref, useImperativeHandle} from "react";
4
+ import {type ScaledSize, StyleSheet, useWindowDimensions, View} from "react-native";
4
5
  import type {ReactTestInstance} from "react-test-renderer";
5
6
 
6
7
  import {SplitPage} from "./SplitPage";
7
8
  import {renderWithTheme} from "./test-utils";
8
9
 
9
- // Mock react-native-swiper-flatlist
10
+ interface PagerScrollOptions {
11
+ animated?: boolean;
12
+ index: number;
13
+ }
14
+
15
+ const swiperScrollToIndex = mock((_options?: PagerScrollOptions) => {});
16
+
17
+ // Mock react-native-swiper-flatlist. The host tree stays a View with testID "swiper-flatlist"
18
+ // so existing snapshots keep matching. The ref exposes scrollToIndex for the opt-in pager tests.
10
19
  mock.module("react-native-swiper-flatlist", () => ({
11
- SwiperFlatList: ({children}: {children: React.ReactNode}) => (
12
- <View testID="swiper-flatlist">{children}</View>
20
+ SwiperFlatList: forwardRef(
21
+ (
22
+ {children}: {children?: ReactNode},
23
+ ref: Ref<{scrollToIndex: (options: PagerScrollOptions) => void}>
24
+ ) => {
25
+ useImperativeHandle(ref, () => ({scrollToIndex: swiperScrollToIndex}));
26
+ return <View testID="swiper-flatlist">{children}</View>;
27
+ }
13
28
  ),
14
29
  }));
15
30
 
31
+ type WindowDimensionsImpl = () => ScaledSize;
32
+ type MockableUseWindowDimensions = WindowDimensionsImpl & {
33
+ mockImplementation?: (impl: WindowDimensionsImpl) => void;
34
+ };
35
+
36
+ const setWindowWidth = (width: number): (() => void) => {
37
+ const useWindowDimensionsMock = useWindowDimensions as MockableUseWindowDimensions;
38
+ if (typeof useWindowDimensionsMock.mockImplementation !== "function") {
39
+ return (): void => {};
40
+ }
41
+ useWindowDimensionsMock.mockImplementation(
42
+ (): ScaledSize => ({fontScale: 1, height: 812, scale: 2, width})
43
+ );
44
+ return (): void => {
45
+ useWindowDimensionsMock.mockImplementation?.(
46
+ (): ScaledSize => ({fontScale: 1, height: 812, scale: 2, width: 375})
47
+ );
48
+ };
49
+ };
50
+
51
+ const styleWidth = (style: unknown): unknown => StyleSheet.flatten(style)?.width;
52
+
16
53
  const setDesktop = () => {
17
54
  mock.module("./MediaQuery", () => ({
18
- isMobileDevice: () => false,
55
+ isNarrowViewport: () => false,
19
56
  mediaQuery: () => "lg" as const,
20
57
  mediaQueryLargerThan: () => true,
21
58
  mediaQuerySmallerThan: () => false,
@@ -24,19 +61,20 @@ const setDesktop = () => {
24
61
 
25
62
  const setMobile = () => {
26
63
  mock.module("./MediaQuery", () => ({
27
- isMobileDevice: () => true,
64
+ isNarrowViewport: () => true,
28
65
  mediaQuery: () => "xs" as const,
29
66
  mediaQueryLargerThan: () => false,
30
- mediaQuerySmallerThan: () => true,
67
+ mediaQuerySmallerThan: () => false,
31
68
  }));
32
69
  };
33
70
 
34
71
  // Restore MediaQuery to bunSetup defaults after all tests to prevent cross-file pollution.
35
- // bunSetup mocks: isMobileDevice → false, mediaQueryLargerThan → false.
72
+ // bunSetup mocks: isNarrowViewport → false, mediaQueryLargerThan → false, mediaQuerySmallerThan → false.
36
73
  const restoreDefault = () => {
37
74
  mock.module("./MediaQuery", () => ({
38
- isMobileDevice: mock(() => false),
75
+ isNarrowViewport: mock(() => false),
39
76
  mediaQueryLargerThan: mock(() => false),
77
+ mediaQuerySmallerThan: mock(() => false),
40
78
  }));
41
79
  };
42
80
 
@@ -44,6 +82,41 @@ afterAll(() => {
44
82
  restoreDefault();
45
83
  });
46
84
 
85
+ const findAncestor = (
86
+ node: ReactTestInstance,
87
+ predicate: (candidate: ReactTestInstance) => boolean
88
+ ): ReactTestInstance | undefined => {
89
+ let current = node.parent;
90
+ while (current) {
91
+ if (predicate(current)) {
92
+ return current;
93
+ }
94
+ current = current.parent;
95
+ }
96
+ return undefined;
97
+ };
98
+
99
+ const getIconButtonByTestId = (root: ReactTestInstance, testID: string): ReactTestInstance => {
100
+ const iconButton = root.findAll(
101
+ (node: ReactTestInstance) =>
102
+ node.props?.testID === testID && typeof node.props?.onClick === "function"
103
+ )[0];
104
+ if (!iconButton) {
105
+ throw new Error(`Unable to find IconButton with testID: ${testID}`);
106
+ }
107
+ return iconButton;
108
+ };
109
+
110
+ const queryIconButtonByTestId = (
111
+ root: ReactTestInstance,
112
+ testID: string
113
+ ): ReactTestInstance | undefined => {
114
+ return root.findAll(
115
+ (node: ReactTestInstance) =>
116
+ node.props?.testID === testID && typeof node.props?.onClick === "function"
117
+ )[0];
118
+ };
119
+
47
120
  describe("SplitPage", () => {
48
121
  const defaultProps = {
49
122
  listViewData: [
@@ -581,4 +654,369 @@ describe("SplitPage", () => {
581
654
  expect(root).toBeTruthy();
582
655
  });
583
656
  });
657
+
658
+ describe("opt-in layouts", () => {
659
+ const twoChildren = (
660
+ <SplitPage {...defaultProps}>
661
+ <View testID="child-1" />
662
+ <View testID="child-2" />
663
+ </SplitPage>
664
+ );
665
+
666
+ const selectFirst = async (
667
+ getAllByLabelText: (label: string) => ReactTestInstance[]
668
+ ): Promise<void> => {
669
+ const boxes = getAllByLabelText("Select");
670
+ await act(async () => {
671
+ fireEvent.press(boxes[0]);
672
+ });
673
+ };
674
+
675
+ const layoutWidth = (node: ReactTestInstance, width: number): void => {
676
+ node.props.onLayout({
677
+ nativeEvent: {layout: {height: 400, width, x: 0, y: 0}},
678
+ });
679
+ };
680
+
681
+ it("shrinks at narrowBelowWidth and keeps the desktop layout above that width", async () => {
682
+ setDesktop();
683
+ const restoreNarrow = setWindowWidth(500);
684
+ const shrunk = renderWithTheme(
685
+ <SplitPage {...defaultProps} narrowBelowWidth={500}>
686
+ <View testID="child-1" />
687
+ <View testID="child-2" />
688
+ </SplitPage>
689
+ );
690
+ expect(shrunk.queryByTestId("child-1")).toBeNull();
691
+ expect(shrunk.queryByTestId("swiper-flatlist")).toBeNull();
692
+ await selectFirst(shrunk.getAllByLabelText);
693
+ expect(shrunk.getByTestId("swiper-flatlist")).toBeTruthy();
694
+ restoreNarrow();
695
+
696
+ setMobile();
697
+ const restoreWide = setWindowWidth(501);
698
+ const sideBySide = renderWithTheme(
699
+ <SplitPage {...defaultProps} narrowBelowWidth={500}>
700
+ <View testID="child-1" />
701
+ <View testID="child-2" />
702
+ </SplitPage>
703
+ );
704
+ expect(sideBySide.getByTestId("child-1")).toBeTruthy();
705
+ expect(sideBySide.queryByTestId("swiper-flatlist")).toBeNull();
706
+ restoreWide();
707
+ });
708
+
709
+ it("keeps the desktop flex row and the narrow dotted swiper without the new props", async () => {
710
+ setDesktop();
711
+ const desktop = renderWithTheme(twoChildren);
712
+ expect(desktop.queryByTestId("split-page-desktop-children-scroll")).toBeNull();
713
+ const rowChild = findAncestor(
714
+ desktop.getByTestId("child-1"),
715
+ (candidate) => styleWidth(candidate.props.style) === "60%"
716
+ );
717
+ expect(rowChild).toBeDefined();
718
+ expect(StyleSheet.flatten(rowChild?.props.style)?.flex).toBe(1);
719
+
720
+ setMobile();
721
+ const mobile = renderWithTheme(twoChildren);
722
+ expect(mobile.queryByTestId("swiper-flatlist")).toBeNull();
723
+ await selectFirst(mobile.getAllByLabelText);
724
+ expect(mobile.getByTestId("swiper-flatlist")).toBeTruthy();
725
+ expect(mobile.queryByTestId("split-page-mobile-children")).toBeNull();
726
+ const paginated = mobile.UNSAFE_root.findAll(
727
+ (node: ReactTestInstance) => node.props?.showPagination === true
728
+ );
729
+ expect(paginated.length).toBeGreaterThan(0);
730
+ });
731
+
732
+ it("sizes desktop children from the minimum width until the row is measured", async () => {
733
+ setDesktop();
734
+ const {getByTestId} = renderWithTheme(
735
+ <SplitPage {...defaultProps} desktopChildrenMinWidth={200}>
736
+ <View testID="child-1" />
737
+ <View testID="child-2" />
738
+ </SplitPage>
739
+ );
740
+ const scroll = getByTestId("split-page-desktop-children-scroll");
741
+ expect(styleWidth(getByTestId("split-page-desktop-child-0").props.style)).toBe(200);
742
+ expect(styleWidth(getByTestId("split-page-desktop-child-1").props.style)).toBe(200);
743
+
744
+ await act(async () => {
745
+ layoutWidth(scroll, 1000);
746
+ });
747
+ expect(styleWidth(getByTestId("split-page-desktop-child-0").props.style)).toBe(500);
748
+ expect(styleWidth(getByTestId("split-page-desktop-child-1").props.style)).toBe(500);
749
+
750
+ await act(async () => {
751
+ layoutWidth(scroll, 300);
752
+ });
753
+ expect(styleWidth(getByTestId("split-page-desktop-child-0").props.style)).toBe(200);
754
+ expect(styleWidth(getByTestId("split-page-desktop-child-1").props.style)).toBe(200);
755
+ expect(scroll.props.contentContainerStyle.width).toBe(400);
756
+ });
757
+
758
+ it("keeps the segmented control when desktopChildrenMinWidth is set with three children", () => {
759
+ setDesktop();
760
+ const warnSpy = spyOn(console, "warn").mockImplementation(() => {});
761
+ const {queryByTestId, UNSAFE_root} = renderWithTheme(
762
+ <SplitPage
763
+ {...defaultProps}
764
+ desktopChildrenMinWidth={200}
765
+ tabs={["Tab 1", "Tab 2", "Tab 3"]}
766
+ >
767
+ <View testID="child-1" />
768
+ <View testID="child-2" />
769
+ <View testID="child-3" />
770
+ </SplitPage>
771
+ );
772
+ const segmented = UNSAFE_root.findAll(
773
+ (node: ReactTestInstance) => node.props?.items && node.props?.onChange
774
+ );
775
+ expect(segmented.length).toBeGreaterThan(0);
776
+ expect(queryByTestId("split-page-desktop-children-scroll")).toBeNull();
777
+ expect(warnSpy).toHaveBeenCalledWith(
778
+ "desktopChildrenMinWidth applies only when SplitPage has two or fewer children."
779
+ );
780
+ warnSpy.mockRestore();
781
+ });
782
+
783
+ it("renders the labeled narrow pager with a next control on the first child", async () => {
784
+ setMobile();
785
+ const {getAllByLabelText, getByTestId, UNSAFE_root} = renderWithTheme(
786
+ <SplitPage {...defaultProps} narrowViewportChildLabels={["Summary", "Notes"]}>
787
+ <View testID="child-1" />
788
+ <View testID="child-2" />
789
+ </SplitPage>
790
+ );
791
+ await selectFirst(getAllByLabelText);
792
+ expect(getByTestId("split-page-mobile-children")).toBeTruthy();
793
+ expect(getIconButtonByTestId(UNSAFE_root, "split-page-column-next")).toBeTruthy();
794
+ expect(queryIconButtonByTestId(UNSAFE_root, "split-page-column-previous")).toBeUndefined();
795
+ expect(queryIconButtonByTestId(UNSAFE_root, "split-page-back-to-list")).toBeUndefined();
796
+ const paginated = UNSAFE_root.findAll(
797
+ (node: ReactTestInstance) => node.props?.showPagination === true
798
+ );
799
+ expect(paginated).toHaveLength(0);
800
+ const labeled = UNSAFE_root.findAll(
801
+ (node: ReactTestInstance) => typeof node.props?.getItemLayout === "function"
802
+ );
803
+ expect(labeled.length).toBeGreaterThan(0);
804
+ expect(labeled[0].props.showPagination).toBeUndefined();
805
+ });
806
+
807
+ it("scrolls to the next child without an unanimated snap from the index change", async () => {
808
+ setMobile();
809
+ const {getAllByLabelText, UNSAFE_root} = renderWithTheme(
810
+ <SplitPage {...defaultProps} narrowViewportChildLabels={["Summary", "Notes"]}>
811
+ <View testID="child-1" />
812
+ <View testID="child-2" />
813
+ </SplitPage>
814
+ );
815
+ await selectFirst(getAllByLabelText);
816
+ swiperScrollToIndex.mockClear();
817
+ await act(async () => {
818
+ getIconButtonByTestId(UNSAFE_root, "split-page-column-next").props.onClick();
819
+ });
820
+ expect(swiperScrollToIndex).toHaveBeenCalledWith({animated: true, index: 1});
821
+ expect(swiperScrollToIndex.mock.calls.some((call) => call[0]?.animated === false)).toBe(
822
+ false
823
+ );
824
+ });
825
+
826
+ it("shows only previous on the last of two children", async () => {
827
+ setMobile();
828
+ const two = renderWithTheme(
829
+ <SplitPage {...defaultProps} narrowViewportChildLabels={["Summary", "Notes"]}>
830
+ <View testID="child-1" />
831
+ <View testID="child-2" />
832
+ </SplitPage>
833
+ );
834
+ await selectFirst(two.getAllByLabelText);
835
+ await act(async () => {
836
+ getIconButtonByTestId(two.UNSAFE_root, "split-page-column-next").props.onClick();
837
+ });
838
+ expect(getIconButtonByTestId(two.UNSAFE_root, "split-page-column-previous")).toBeTruthy();
839
+ expect(queryIconButtonByTestId(two.UNSAFE_root, "split-page-column-next")).toBeUndefined();
840
+ });
841
+
842
+ it("shows both directions on a middle child and walks previous back to the first", async () => {
843
+ setMobile();
844
+ const three = renderWithTheme(
845
+ <SplitPage
846
+ {...defaultProps}
847
+ narrowViewportChildLabels={["Summary", "Notes", "History"]}
848
+ tabs={["Summary", "Notes", "History"]}
849
+ >
850
+ <View testID="child-1" />
851
+ <View testID="child-2" />
852
+ <View testID="child-3" />
853
+ </SplitPage>
854
+ );
855
+ await selectFirst(three.getAllByLabelText);
856
+ await act(async () => {
857
+ getIconButtonByTestId(three.UNSAFE_root, "split-page-column-next").props.onClick();
858
+ });
859
+ expect(getIconButtonByTestId(three.UNSAFE_root, "split-page-column-previous")).toBeTruthy();
860
+ expect(getIconButtonByTestId(three.UNSAFE_root, "split-page-column-next")).toBeTruthy();
861
+ await act(async () => {
862
+ getIconButtonByTestId(three.UNSAFE_root, "split-page-column-next").props.onClick();
863
+ });
864
+ expect(queryIconButtonByTestId(three.UNSAFE_root, "split-page-column-next")).toBeUndefined();
865
+ swiperScrollToIndex.mockClear();
866
+ await act(async () => {
867
+ getIconButtonByTestId(three.UNSAFE_root, "split-page-column-previous").props.onClick();
868
+ });
869
+ await act(async () => {
870
+ getIconButtonByTestId(three.UNSAFE_root, "split-page-column-previous").props.onClick();
871
+ });
872
+ expect(swiperScrollToIndex).toHaveBeenCalledWith({animated: true, index: 1});
873
+ expect(swiperScrollToIndex).toHaveBeenCalledWith({animated: true, index: 0});
874
+ expect(
875
+ queryIconButtonByTestId(three.UNSAFE_root, "split-page-column-previous")
876
+ ).toBeUndefined();
877
+ expect(getIconButtonByTestId(three.UNSAFE_root, "split-page-column-next")).toBeTruthy();
878
+ });
879
+
880
+ it("returns to the list when the labeled back button is pressed", async () => {
881
+ setMobile();
882
+ const onSelectionChange = mock(async () => {});
883
+ const {getAllByLabelText, UNSAFE_root} = renderWithTheme(
884
+ <SplitPage
885
+ {...defaultProps}
886
+ narrowViewportChildLabels={["Summary", "Notes"]}
887
+ narrowViewportListButtonLabel="Back to list"
888
+ onSelectionChange={onSelectionChange}
889
+ >
890
+ <View testID="child-1" />
891
+ <View testID="child-2" />
892
+ </SplitPage>
893
+ );
894
+ await selectFirst(getAllByLabelText);
895
+ await act(async () => {
896
+ getIconButtonByTestId(UNSAFE_root, "split-page-back-to-list").props.onClick();
897
+ });
898
+ expect(onSelectionChange).toHaveBeenCalledWith(undefined);
899
+ });
900
+
901
+ it("shows the labeled pager when narrowViewportSelectionActive is set without a list selection", () => {
902
+ setMobile();
903
+ const {getByTestId, queryByLabelText} = renderWithTheme(
904
+ <SplitPage
905
+ {...defaultProps}
906
+ narrowViewportChildLabels={["Summary", "Notes"]}
907
+ narrowViewportSelectionActive
908
+ >
909
+ <View testID="child-1" />
910
+ <View testID="child-2" />
911
+ </SplitPage>
912
+ );
913
+ expect(getByTestId("split-page-mobile-children")).toBeTruthy();
914
+ expect(queryByLabelText("Select")).toBeNull();
915
+ });
916
+
917
+ it("resets the narrow pager to the first child when narrowViewportSelectionKey changes", async () => {
918
+ setMobile();
919
+ const view = renderWithTheme(
920
+ <SplitPage
921
+ {...defaultProps}
922
+ narrowViewportChildLabels={["Summary", "Notes"]}
923
+ narrowViewportSelectionActive
924
+ narrowViewportSelectionKey="record-a"
925
+ >
926
+ <View testID="child-1" />
927
+ <View testID="child-2" />
928
+ </SplitPage>
929
+ );
930
+ await act(async () => {
931
+ getIconButtonByTestId(view.UNSAFE_root, "split-page-column-next").props.onClick();
932
+ });
933
+ expect(getIconButtonByTestId(view.UNSAFE_root, "split-page-column-previous")).toBeTruthy();
934
+ swiperScrollToIndex.mockClear();
935
+ await act(async () => {
936
+ view.rerender(
937
+ <SplitPage
938
+ {...defaultProps}
939
+ narrowViewportChildLabels={["Summary", "Notes"]}
940
+ narrowViewportSelectionActive
941
+ narrowViewportSelectionKey="record-b"
942
+ >
943
+ <View testID="child-1" />
944
+ <View testID="child-2" />
945
+ </SplitPage>
946
+ );
947
+ });
948
+ expect(swiperScrollToIndex).toHaveBeenCalledWith({animated: false, index: 0});
949
+ expect(
950
+ queryIconButtonByTestId(view.UNSAFE_root, "split-page-column-previous")
951
+ ).toBeUndefined();
952
+ expect(getIconButtonByTestId(view.UNSAFE_root, "split-page-column-next")).toBeTruthy();
953
+ });
954
+
955
+ it("realigns the current child when the page width changes", async () => {
956
+ setMobile();
957
+ const restoreWidth = setWindowWidth(375);
958
+ const view = renderWithTheme(
959
+ <SplitPage
960
+ {...defaultProps}
961
+ narrowViewportChildLabels={["Summary", "Notes"]}
962
+ narrowViewportSelectionActive
963
+ narrowViewportSelectionKey="record-a"
964
+ >
965
+ <View testID="child-1" />
966
+ <View testID="child-2" />
967
+ </SplitPage>
968
+ );
969
+ await act(async () => {
970
+ getIconButtonByTestId(view.UNSAFE_root, "split-page-column-next").props.onClick();
971
+ });
972
+ swiperScrollToIndex.mockClear();
973
+ await act(async () => {
974
+ layoutWidth(view.getByTestId("split-page-mobile-children"), 280);
975
+ });
976
+ expect(swiperScrollToIndex).toHaveBeenCalledWith({animated: false, index: 1});
977
+ expect(getIconButtonByTestId(view.UNSAFE_root, "split-page-column-previous")).toBeTruthy();
978
+ expect(queryIconButtonByTestId(view.UNSAFE_root, "split-page-column-next")).toBeUndefined();
979
+
980
+ swiperScrollToIndex.mockClear();
981
+ setWindowWidth(420);
982
+ await act(async () => {
983
+ view.rerender(
984
+ <SplitPage
985
+ {...defaultProps}
986
+ narrowViewportChildLabels={["Summary", "Notes"]}
987
+ narrowViewportSelectionActive
988
+ narrowViewportSelectionKey="record-a"
989
+ >
990
+ <View testID="child-1" />
991
+ <View testID="child-2" />
992
+ </SplitPage>
993
+ );
994
+ });
995
+ expect(swiperScrollToIndex).toHaveBeenCalledWith({animated: false, index: 1});
996
+ expect(swiperScrollToIndex.mock.calls.some((call) => call[0]?.index === 0)).toBe(false);
997
+ expect(getIconButtonByTestId(view.UNSAFE_root, "split-page-column-previous")).toBeTruthy();
998
+ restoreWidth();
999
+ });
1000
+
1001
+ it("falls back to the dotted swiper when narrowViewportChildLabels does not match the children", async () => {
1002
+ setMobile();
1003
+ const warnSpy = spyOn(console, "warn").mockImplementation(() => {});
1004
+ const {getAllByLabelText, queryByTestId, UNSAFE_root} = renderWithTheme(
1005
+ <SplitPage {...defaultProps} narrowViewportChildLabels={["Summary"]}>
1006
+ <View testID="child-1" />
1007
+ <View testID="child-2" />
1008
+ </SplitPage>
1009
+ );
1010
+ await selectFirst(getAllByLabelText);
1011
+ expect(warnSpy).toHaveBeenCalledWith(
1012
+ "narrowViewportChildLabels must have one entry per child. Falling back to the default narrow pager."
1013
+ );
1014
+ expect(queryByTestId("split-page-mobile-children")).toBeNull();
1015
+ const paginated = UNSAFE_root.findAll(
1016
+ (node: ReactTestInstance) => node.props?.showPagination === true
1017
+ );
1018
+ expect(paginated.length).toBeGreaterThan(0);
1019
+ warnSpy.mockRestore();
1020
+ });
1021
+ });
584
1022
  });