@applicaster/zapp-react-native-ui-components 15.0.0-alpha.1690332913 → 15.0.0-alpha.1693300296

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 (118) hide show
  1. package/Components/Cell/Cell.tsx +6 -0
  2. package/Components/GeneralContentScreen/GeneralContentScreen.tsx +39 -28
  3. package/Components/GeneralContentScreen/__tests__/GeneralContentScreen.test.tsx +104 -0
  4. package/Components/GeneralContentScreen/utils/__tests__/getScreenDataSource.test.ts +19 -0
  5. package/Components/GeneralContentScreen/utils/__tests__/useCurationAPI.test.js +1 -1
  6. package/Components/GeneralContentScreen/utils/getScreenDataSource.ts +9 -0
  7. package/Components/GeneralContentScreen/utils/useCurationAPI.ts +7 -7
  8. package/Components/HandlePlayable/HandlePlayable.tsx +16 -29
  9. package/Components/HandlePlayable/utils.ts +31 -0
  10. package/Components/HookRenderer/HookRenderer.tsx +40 -10
  11. package/Components/HookRenderer/__tests__/HookRenderer.test.tsx +60 -0
  12. package/Components/Layout/TV/NavBarContainer.tsx +1 -10
  13. package/Components/Layout/TV/__tests__/__snapshots__/NavBarContainer.test.tsx.snap +7 -12
  14. package/Components/Layout/TV/__tests__/__snapshots__/ScreenContainer.test.tsx.snap +7 -12
  15. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/model.test.ts +80 -0
  16. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/placement.test.ts +187 -0
  17. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/selectors.test.ts +45 -0
  18. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/__tests__/style.test.ts +49 -0
  19. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/model.ts +47 -0
  20. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/placement.ts +170 -0
  21. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/selectors.ts +26 -0
  22. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/style.ts +29 -0
  23. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/types.ts +37 -0
  24. package/Components/MasterCell/DefaultComponents/Button.tsx +0 -15
  25. package/Components/MasterCell/DefaultComponents/LiveImage/__tests__/prepareEntry.test.ts +352 -0
  26. package/Components/MasterCell/DefaultComponents/LiveImage/executePreloadHooks.ts +136 -0
  27. package/Components/MasterCell/DefaultComponents/LiveImage/index.tsx +33 -16
  28. package/Components/MasterCell/DefaultComponents/PressableView.tsx +196 -0
  29. package/Components/MasterCell/DefaultComponents/SecondaryImage/Image.tsx +40 -39
  30. package/Components/MasterCell/DefaultComponents/SecondaryImage/__tests__/Image.test.tsx +95 -0
  31. package/Components/MasterCell/DefaultComponents/SecondaryImage/__tests__/__snapshots__/Image.test.tsx.snap +86 -0
  32. package/Components/MasterCell/DefaultComponents/SecondaryImage/__tests__/index.test.ts +141 -0
  33. package/Components/MasterCell/DefaultComponents/SecondaryImage/hooks/__tests__/useGetImageDimensions.test.ts +7 -6
  34. package/Components/MasterCell/DefaultComponents/SecondaryImage/index.ts +1 -1
  35. package/Components/MasterCell/DefaultComponents/Text/index.tsx +2 -6
  36. package/Components/MasterCell/DefaultComponents/index.ts +2 -0
  37. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Asset.ts +46 -0
  38. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Button.ts +126 -0
  39. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/ButtonContainerView.ts +23 -0
  40. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/Spacer.ts +16 -0
  41. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/TextLabel.ts +67 -0
  42. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/TextLabelsContainer.ts +32 -0
  43. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/PressableView.test.tsx +191 -0
  44. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/builders.test.ts +140 -0
  45. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/index.test.ts +222 -0
  46. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/helpers.ts +105 -0
  47. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/index.ts +104 -0
  48. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/__tests__/insertButtons.test.ts +118 -0
  49. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/utils/index.ts +73 -0
  50. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/__tests__/index.test.ts +86 -0
  51. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/index.ts +35 -48
  52. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/__tests__/getPluginIdentifier.test.ts +115 -29
  53. package/Components/MasterCell/DefaultComponents/tv/TvActionButtons/utils/index.ts +39 -144
  54. package/Components/MasterCell/elementMapper.tsx +1 -0
  55. package/Components/MasterCell/hoc/__tests__/withAsyncRender.test.tsx +219 -0
  56. package/Components/MasterCell/hoc/withAsyncRender.tsx +9 -7
  57. package/Components/OfflineHandler/NotificationView/NotificationView.lg.tsx +17 -9
  58. package/Components/OfflineHandler/NotificationView/NotificationView.samsung.tsx +16 -8
  59. package/Components/OfflineHandler/NotificationView/utils.ts +34 -0
  60. package/Components/PlayerContainer/PlayerContainer.tsx +1 -18
  61. package/Components/PreloaderWrapper/__tests__/index.test.tsx +26 -0
  62. package/Components/PreloaderWrapper/index.tsx +15 -0
  63. package/Components/River/ComponentsMap/ComponentsMap.tsx +16 -0
  64. package/Components/River/ComponentsMap/hooks/__tests__/useLoadingState.test.ts +1 -1
  65. package/Components/River/RefreshControl.tsx +36 -13
  66. package/Components/River/RiverItem.tsx +26 -20
  67. package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +2 -0
  68. package/Components/River/__tests__/componentsMap.test.js +38 -0
  69. package/Components/Screen/__tests__/Screen.test.tsx +1 -0
  70. package/Components/Screen/hooks.ts +73 -3
  71. package/Components/Screen/index.tsx +7 -1
  72. package/Components/Screen/orientationHandler.ts +7 -10
  73. package/Components/ScreenFeedLoader/ScreenFeedLoader.tsx +46 -0
  74. package/Components/ScreenFeedLoader/__tests__/ScreenFeedLoader.test.tsx +94 -0
  75. package/Components/ScreenFeedLoader/index.ts +1 -0
  76. package/Components/ScreenResolver/__tests__/screenResolver.test.js +24 -0
  77. package/Components/ScreenResolver/hooks/index.ts +3 -0
  78. package/Components/ScreenResolver/hooks/useGetComponent.ts +15 -0
  79. package/Components/ScreenResolver/hooks/useScreenComponentResolver.tsx +90 -0
  80. package/Components/ScreenResolver/index.tsx +15 -117
  81. package/Components/ScreenResolver/utils/__tests__/getScreenTypeProps.test.ts +45 -0
  82. package/Components/ScreenResolver/utils/getScreenTypeProps.ts +43 -0
  83. package/Components/ScreenResolver/utils/index.ts +1 -0
  84. package/Components/ScreenResolver/withDefaultScreenContext.tsx +16 -0
  85. package/Components/ScreenResolverFeedProvider/ScreenResolverFeedProvider.tsx +25 -0
  86. package/Components/ScreenResolverFeedProvider/__tests__/ScreenResolverFeedProvider.test.tsx +44 -0
  87. package/Components/ScreenResolverFeedProvider/index.ts +1 -0
  88. package/Components/Tabs/TabContent.tsx +7 -4
  89. package/Components/Transitioner/Scene.tsx +9 -15
  90. package/Components/VideoLive/LiveImageManager.ts +199 -54
  91. package/Components/VideoLive/PlayerLiveImageComponent.tsx +31 -33
  92. package/Components/VideoLive/__tests__/PlayerLiveImageComponent.test.tsx +2 -17
  93. package/Components/VideoModal/hooks/__tests__/useDelayedPlayerDetails.test.ts +15 -7
  94. package/Components/Viewport/ViewportAware/__tests__/viewportAware.test.js +0 -2
  95. package/Components/Viewport/ViewportAware/index.tsx +16 -7
  96. package/Components/Viewport/ViewportEvents/__tests__/viewportEvents.test.js +1 -1
  97. package/Components/ZappUIComponent/index.tsx +12 -6
  98. package/Components/default-cell-renderer/viewTrees/mobile/index.ts +0 -3
  99. package/Components/index.js +1 -1
  100. package/Contexts/ScreenContext/__tests__/index.test.tsx +57 -0
  101. package/Contexts/ScreenContext/index.tsx +71 -19
  102. package/Contexts/ScreenTrackedViewPositionsContext/__tests__/index.test.tsx +1 -1
  103. package/Contexts/ZappHookModalContext/index.tsx +37 -61
  104. package/Contexts/ZappPipesContext/ZappPipesContextFactory.tsx +18 -7
  105. package/Contexts/index.ts +0 -2
  106. package/Decorators/ZappPipesDataConnector/ResolverSelector.tsx +25 -7
  107. package/Decorators/ZappPipesDataConnector/__tests__/ResolverSelector.test.tsx +212 -5
  108. package/Decorators/ZappPipesDataConnector/__tests__/UrlFeedResolver.test.tsx +39 -21
  109. package/Decorators/ZappPipesDataConnector/resolvers/UrlFeedResolver.tsx +18 -7
  110. package/events/index.ts +3 -0
  111. package/events/scrollEndReached.ts +15 -0
  112. package/package.json +5 -5
  113. package/Components/MasterCell/DefaultComponents/Text/utils/__tests__/withAdjustedLineHeight.test.ts +0 -46
  114. package/Components/MasterCell/DefaultComponents/Text/utils/index.ts +0 -21
  115. package/Components/PlayerContainer/ErrorDisplay/ErrorDisplay.tsx +0 -57
  116. package/Components/PlayerContainer/ErrorDisplay/index.ts +0 -9
  117. package/Components/PlayerContainer/useRestrictMobilePlayback.tsx +0 -101
  118. /package/Components/HookRenderer/{index.tsx → index.ts} +0 -0
@@ -103,7 +103,7 @@ export const SecondaryImage = ({ value, currentPosition, state }: Props) => {
103
103
  data: [
104
104
  {
105
105
  func: "image_src_from_media_item",
106
- args: [imageKey],
106
+ args: [imageKey, false],
107
107
  propName: "uri",
108
108
  },
109
109
  ],
@@ -7,7 +7,6 @@ import {
7
7
  } from "@applicaster/zapp-react-native-utils/cellUtils";
8
8
 
9
9
  import { useTextLabel, withFocusedStyles } from "./hooks";
10
- import { withScaledLineHeight } from "./utils";
11
10
  import { toNumber } from "@applicaster/zapp-react-native-utils/numberUtils";
12
11
  import { MeasurementPortalContext } from "../../../MeasurmentsPortal";
13
12
  import { isNilOrEmpty } from "@applicaster/zapp-react-native-utils/reactUtils/helpers";
@@ -70,12 +69,9 @@ const _Text = ({
70
69
 
71
70
  return (
72
71
  <Text
73
- style={[
74
- withScaledLineHeight(withFocusedStyles({ style, otherProps })),
75
- { height },
76
- ]}
77
- allowFontScaling={false}
72
+ style={[withFocusedStyles({ style, otherProps }), { height }]}
78
73
  {...withoutLabel(otherProps)}
74
+ allowFontScaling={false}
79
75
  >
80
76
  {textLabel}
81
77
  </Text>
@@ -16,12 +16,14 @@ import { CellBadge } from "./CellBadge";
16
16
  import { TvActionButtons } from "./tv/TvActionButtons";
17
17
  import { ButtonContainerView } from "./tv/ButtonContainerView";
18
18
  import { ImageBorderContainer } from "./ImageBorderContainer";
19
+ import { PressableView } from "./PressableView";
19
20
 
20
21
  export const defaultComponents = {
21
22
  View,
22
23
  CollapsibleTextContainer,
23
24
  Text,
24
25
  Button,
26
+ PressableView,
25
27
  Image,
26
28
  PureImage,
27
29
  ButtonContainerView,
@@ -0,0 +1,46 @@
1
+ import { toNumberWithDefaultZero } from "@applicaster/zapp-react-native-utils/numberUtils";
2
+
3
+ type Props = {
4
+ prefix: string;
5
+ value: Function;
6
+ actionIdentifier: string;
7
+ testID?: string;
8
+ };
9
+
10
+ export const Asset = ({ prefix, value, actionIdentifier, testID }: Props) => {
11
+ if (!value(`${prefix}_asset_enabled`)) {
12
+ return null;
13
+ }
14
+
15
+ return {
16
+ type: "Image",
17
+ style: {
18
+ width: toNumberWithDefaultZero(value(`${prefix}_asset_width`)),
19
+ height: toNumberWithDefaultZero(value(`${prefix}_asset_height`)),
20
+ marginTop: toNumberWithDefaultZero(value(`${prefix}_asset_margin_top`)),
21
+ marginRight: toNumberWithDefaultZero(
22
+ value(`${prefix}_asset_margin_right`)
23
+ ),
24
+ marginBottom: toNumberWithDefaultZero(
25
+ value(`${prefix}_asset_margin_bottom`)
26
+ ),
27
+ marginLeft: toNumberWithDefaultZero(value(`${prefix}_asset_margin_left`)),
28
+ backgroundColor: "transparent",
29
+ },
30
+ data: [
31
+ {
32
+ func: (entry) => entry,
33
+ args: [],
34
+ propName: "entry",
35
+ },
36
+ ],
37
+ additionalProps: {
38
+ source: {
39
+ context: actionIdentifier,
40
+ },
41
+ state: "inactive",
42
+ mobileActionRole: "asset",
43
+ testID: testID ? `${testID}-asset` : undefined,
44
+ },
45
+ };
46
+ };
@@ -0,0 +1,126 @@
1
+ import {
2
+ toNumberWithDefault,
3
+ toNumberWithDefaultZero,
4
+ } from "@applicaster/zapp-react-native-utils/numberUtils";
5
+ import { compact } from "@applicaster/zapp-react-native-utils/cellUtils";
6
+
7
+ import { Asset } from "./Asset";
8
+ import { Spacer } from "./Spacer";
9
+ import { TextLabelsContainer } from "./TextLabelsContainer";
10
+ import { getContentDirection, getContentsAlignment } from "./helpers";
11
+
12
+ const displayModeStyle = ({ value, prefix }) => {
13
+ const mode = value(`${prefix}_display_mode`) || "dynamic";
14
+
15
+ if (mode === "fixed") {
16
+ return {
17
+ width: toNumberWithDefault(140, value(`${prefix}_width`)),
18
+ };
19
+ }
20
+
21
+ if (mode === "fill") {
22
+ return {
23
+ flex: 1,
24
+ };
25
+ }
26
+
27
+ return {};
28
+ };
29
+
30
+ type Props = {
31
+ index: number;
32
+ value: Function;
33
+ stylePrefix: string;
34
+ specificPrefix: string;
35
+ spacingStyle: Record<string, unknown>;
36
+ };
37
+
38
+ export const Button = ({
39
+ index,
40
+ value,
41
+ stylePrefix,
42
+ specificPrefix,
43
+ spacingStyle,
44
+ }: Props) => {
45
+ if (!value(`${specificPrefix}_button_enabled`)) {
46
+ return null;
47
+ }
48
+
49
+ const testID = `mobile_action_button_${index + 1}`;
50
+ const actionIdentifier = value(`${specificPrefix}_assign_action`);
51
+ const assetAlignment = value(`${stylePrefix}_asset_alignment`) || "left";
52
+
53
+ const contentsAlignment =
54
+ value(`${stylePrefix}_contents_alignment`) || "center";
55
+
56
+ return {
57
+ type: "PressableView",
58
+ style: {
59
+ flexDirection: getContentDirection(assetAlignment),
60
+ alignItems: "center",
61
+ justifyContent: getContentsAlignment(contentsAlignment),
62
+
63
+ marginTop: toNumberWithDefaultZero(value(`${stylePrefix}_margin_top`)),
64
+ marginRight: toNumberWithDefaultZero(
65
+ value(`${stylePrefix}_margin_right`)
66
+ ),
67
+ marginBottom: toNumberWithDefaultZero(
68
+ value(`${stylePrefix}_margin_bottom`)
69
+ ),
70
+ marginLeft: toNumberWithDefaultZero(value(`${stylePrefix}_margin_left`)),
71
+
72
+ paddingTop: toNumberWithDefaultZero(value(`${stylePrefix}_padding_top`)),
73
+ paddingRight: toNumberWithDefaultZero(
74
+ value(`${stylePrefix}_padding_right`)
75
+ ),
76
+ paddingBottom: toNumberWithDefaultZero(
77
+ value(`${stylePrefix}_padding_bottom`)
78
+ ),
79
+ paddingLeft: toNumberWithDefaultZero(
80
+ value(`${stylePrefix}_padding_left`)
81
+ ),
82
+
83
+ borderWidth: toNumberWithDefaultZero(value(`${stylePrefix}_border_size`)),
84
+ borderRadius: toNumberWithDefaultZero(
85
+ value(`${stylePrefix}_corner_radius`)
86
+ ),
87
+ borderColor: value(`${stylePrefix}_border_color`),
88
+ backgroundColor: value(`${stylePrefix}_background_color`),
89
+
90
+ ...displayModeStyle({ value, prefix: stylePrefix }),
91
+ ...spacingStyle,
92
+ },
93
+ additionalProps: {
94
+ action: {
95
+ identifier: actionIdentifier,
96
+ },
97
+ focusedStyles: {
98
+ backgroundColor: value(`${stylePrefix}_focused_background_color`),
99
+ borderColor: value(`${stylePrefix}_focused_border_color`),
100
+ },
101
+ testID,
102
+ },
103
+ elements: compact([
104
+ Asset({
105
+ prefix: stylePrefix,
106
+ value,
107
+ actionIdentifier,
108
+ testID,
109
+ }),
110
+ Spacer(),
111
+ TextLabelsContainer({
112
+ prefix: stylePrefix,
113
+ value,
114
+ actionIdentifier,
115
+ testID,
116
+ }),
117
+ ]),
118
+ data: [
119
+ {
120
+ func: (x) => x,
121
+ args: [],
122
+ propName: "item",
123
+ },
124
+ ],
125
+ };
126
+ };
@@ -0,0 +1,23 @@
1
+ type Props = {
2
+ style: Record<string, unknown>;
3
+ contentStyle: Record<string, unknown>;
4
+ elements: Array<Record<string, unknown>>;
5
+ };
6
+
7
+ export const ButtonContainerView = ({
8
+ style,
9
+ contentStyle,
10
+ elements,
11
+ }: Props) => {
12
+ return {
13
+ type: "View",
14
+ style,
15
+ elements: [
16
+ {
17
+ type: "View",
18
+ style: contentStyle,
19
+ elements,
20
+ },
21
+ ],
22
+ };
23
+ };
@@ -0,0 +1,16 @@
1
+ type Props = {
2
+ enabled?: boolean;
3
+ };
4
+
5
+ export const Spacer = ({ enabled = false }: Props = {}) => {
6
+ if (!enabled) {
7
+ return null;
8
+ }
9
+
10
+ return {
11
+ type: "View",
12
+ style: {
13
+ flex: 1,
14
+ },
15
+ };
16
+ };
@@ -0,0 +1,67 @@
1
+ import { Platform } from "react-native";
2
+
3
+ import { toNumberWithDefaultZero } from "@applicaster/zapp-react-native-utils/numberUtils";
4
+
5
+ type Props = {
6
+ prefix: string;
7
+ value: Function;
8
+ actionIdentifier: string;
9
+ testID?: string;
10
+ };
11
+
12
+ export const TextLabel = ({
13
+ prefix,
14
+ value,
15
+ actionIdentifier,
16
+ testID,
17
+ }: Props) => {
18
+ if (!value(`${prefix}_label_enabled`)) {
19
+ return null;
20
+ }
21
+
22
+ return {
23
+ type: "Text",
24
+ style: {
25
+ color: value(`${prefix}_font_color`),
26
+ fontSize: toNumberWithDefaultZero(value(`${prefix}_font_size`)),
27
+ lineHeight: toNumberWithDefaultZero(value(`${prefix}_line_height`)),
28
+ marginTop: toNumberWithDefaultZero(value(`${prefix}_margin_top`)),
29
+ marginRight: toNumberWithDefaultZero(value(`${prefix}_margin_right`)),
30
+ marginBottom: toNumberWithDefaultZero(value(`${prefix}_margin_bottom`)),
31
+ marginLeft: toNumberWithDefaultZero(value(`${prefix}_margin_left`)),
32
+ fontFamily:
33
+ Platform.OS === "ios"
34
+ ? value(`${prefix}_ios_font_family`)
35
+ : value(`${prefix}_android_font_family`),
36
+ letterSpacing: toNumberWithDefaultZero(
37
+ Platform.OS === "ios"
38
+ ? value(`${prefix}_ios_letter_spacing`)
39
+ : value(`${prefix}_android_letter_spacing`)
40
+ ),
41
+ },
42
+ data: [
43
+ {
44
+ func: (entry) => entry,
45
+ args: [],
46
+ propName: "entry",
47
+ },
48
+ ],
49
+ additionalProps: {
50
+ label: {
51
+ context: actionIdentifier,
52
+ name: "label_1",
53
+ },
54
+ normalStyles: {
55
+ color: value(`${prefix}_font_color`),
56
+ },
57
+ focusedStyles: {
58
+ color: value(`${prefix}_focused_font_color`),
59
+ },
60
+ state: "default",
61
+ mobileActionRole: "label",
62
+ transformText: value(`${prefix}_text_transform`) || "default",
63
+ numberOfLines: value(`${prefix}_number_of_lines`),
64
+ testID: testID ? `${testID}-label` : undefined,
65
+ },
66
+ };
67
+ };
@@ -0,0 +1,32 @@
1
+ import { compact } from "@applicaster/zapp-react-native-utils/cellUtils";
2
+
3
+ import { TextLabel } from "./TextLabel";
4
+
5
+ type Props = {
6
+ prefix: string;
7
+ value: Function;
8
+ actionIdentifier: string;
9
+ testID?: string;
10
+ };
11
+
12
+ export const TextLabelsContainer = ({
13
+ prefix,
14
+ value,
15
+ actionIdentifier,
16
+ testID,
17
+ }: Props) => {
18
+ return {
19
+ type: "View",
20
+ additionalProps: {
21
+ mobileActionRole: "label_container",
22
+ },
23
+ elements: compact([
24
+ TextLabel({
25
+ prefix,
26
+ value,
27
+ actionIdentifier,
28
+ testID,
29
+ }),
30
+ ]),
31
+ };
32
+ };
@@ -0,0 +1,191 @@
1
+ import React from "react";
2
+ import { render, fireEvent } from "@testing-library/react-native";
3
+ import { useActions } from "@applicaster/zapp-react-native-utils/reactHooks/actions";
4
+
5
+ import { elementMapper } from "../../../../elementMapper";
6
+ import { defaultComponents } from "../../../index";
7
+
8
+ jest.mock("@applicaster/zapp-react-native-utils/reactHooks/actions", () => ({
9
+ useActions: jest.fn(),
10
+ }));
11
+
12
+ jest.mock("@applicaster/zapp-react-native-utils/theme", () => ({
13
+ useTheme: () => ({}),
14
+ }));
15
+
16
+ jest.mock("@applicaster/zapp-react-native-utils/localizationUtils", () => ({
17
+ useIsRTL: jest.fn(() => false),
18
+ }));
19
+
20
+ jest.mock(
21
+ "@applicaster/zapp-react-native-utils/reactHooks/navigation/useNavigation",
22
+ () => ({
23
+ useNavigation: jest.fn(() => ({
24
+ currentRoute: "home",
25
+ videoModalState: {
26
+ visible: false,
27
+ },
28
+ })),
29
+ })
30
+ );
31
+
32
+ jest.mock(
33
+ "@applicaster/zapp-react-native-utils/reactHooks/navigation/usePathname",
34
+ () => ({
35
+ usePathname: jest.fn(() => "home"),
36
+ })
37
+ );
38
+
39
+ jest.mock(
40
+ "@applicaster/zapp-react-native-utils/appUtils/accessibilityManager/hooks",
41
+ () => ({
42
+ useAccessibilityManager: jest.fn(() => ({
43
+ addHeading: jest.fn(),
44
+ })),
45
+ })
46
+ );
47
+
48
+ const mockUseActions = useActions as jest.Mock;
49
+
50
+ const item = {
51
+ id: "entry-1",
52
+ } as ZappEntry;
53
+
54
+ const buildActionContext = (entryState = {}) => ({
55
+ initialEntryState: jest.fn(() => ({
56
+ asset: {
57
+ inactive: "https://example.com/image-inactive.png",
58
+ active: "https://example.com/image-active.png",
59
+ },
60
+ label: {
61
+ label_1: "Play",
62
+ },
63
+ ...entryState,
64
+ })),
65
+ invokeAction: jest.fn(),
66
+ addListener: jest.fn(() => jest.fn()),
67
+ isActionAvailable: jest.fn(() => true),
68
+ });
69
+
70
+ const baseNode = {
71
+ type: "PressableView",
72
+ style: {
73
+ backgroundColor: "rgba(1,1,1,1)",
74
+ borderColor: "rgba(2,2,2,1)",
75
+ borderWidth: 1,
76
+ },
77
+ props: {
78
+ item,
79
+ action: {
80
+ identifier: "navigation_action",
81
+ },
82
+ focusedStyles: {
83
+ backgroundColor: "rgba(3,3,3,1)",
84
+ borderColor: "rgba(4,4,4,1)",
85
+ },
86
+ testID: "mobile-action-button",
87
+ },
88
+ elements: [
89
+ {
90
+ type: "Image",
91
+ style: {
92
+ width: 24,
93
+ height: 24,
94
+ },
95
+ props: {
96
+ testID: "mobile-action-button-asset",
97
+ source: {
98
+ context: "navigation_action",
99
+ },
100
+ mobileActionRole: "asset",
101
+ },
102
+ },
103
+ {
104
+ type: "View",
105
+ style: {
106
+ flexDirection: "column",
107
+ },
108
+ props: {
109
+ mobileActionRole: "label_container",
110
+ },
111
+ elements: [
112
+ {
113
+ type: "Text",
114
+ style: {
115
+ fontSize: 15,
116
+ },
117
+ props: {
118
+ testID: "mobile-action-button-label",
119
+ label: {
120
+ context: "navigation_action",
121
+ name: "label_1",
122
+ },
123
+ focusedStyles: {
124
+ color: "rgba(20,20,20,1)",
125
+ },
126
+ normalStyles: {
127
+ color: "rgba(10,10,10,1)",
128
+ },
129
+ mobileActionRole: "label",
130
+ transformText: "default",
131
+ },
132
+ },
133
+ ],
134
+ },
135
+ ],
136
+ };
137
+
138
+ describe("PressableView", () => {
139
+ beforeEach(() => {
140
+ jest.clearAllMocks();
141
+ });
142
+
143
+ const renderNode = (node = baseNode) =>
144
+ render(
145
+ <React.Fragment>
146
+ {elementMapper(defaultComponents)(node as never)}
147
+ </React.Fragment>
148
+ );
149
+
150
+ it("renders nested image and text children through elementMapper", () => {
151
+ mockUseActions.mockReturnValue(buildActionContext());
152
+
153
+ const { getByText, getByTestId } = renderNode();
154
+
155
+ expect(getByTestId("mobile-action-button")).toBeTruthy();
156
+ expect(getByTestId("mobile-action-button-asset")).toBeTruthy();
157
+ expect(getByText("Play")).toBeTruthy();
158
+ });
159
+
160
+ it("applies focused styles when action entry state is active", () => {
161
+ mockUseActions.mockReturnValue(buildActionContext({ active: true }));
162
+
163
+ const { getByTestId, getByText } = renderNode();
164
+
165
+ expect(
166
+ getByTestId("mobile-action-button").props.style.backgroundColor
167
+ ).toBe("rgba(3,3,3,1)");
168
+
169
+ expect(getByText("Play").props.style).toEqual(
170
+ expect.arrayContaining([
171
+ expect.objectContaining({ color: "rgba(20,20,20,1)" }),
172
+ ])
173
+ );
174
+ });
175
+
176
+ it("invokes action on press", () => {
177
+ const actionContext = buildActionContext();
178
+ mockUseActions.mockReturnValue(actionContext);
179
+
180
+ const { getByTestId } = renderNode();
181
+
182
+ fireEvent.press(getByTestId("mobile-action-button"));
183
+
184
+ expect(actionContext.invokeAction).toHaveBeenCalledWith(
185
+ item,
186
+ expect.objectContaining({
187
+ updateState: expect.any(Function),
188
+ })
189
+ );
190
+ });
191
+ });
@@ -0,0 +1,140 @@
1
+ import { Asset } from "../Asset";
2
+ import { Button } from "../Button";
3
+ import { ButtonContainerView } from "../ButtonContainerView";
4
+ import { Spacer } from "../Spacer";
5
+ import { TextLabel } from "../TextLabel";
6
+ import { TextLabelsContainer } from "../TextLabelsContainer";
7
+
8
+ describe("mobile action button builders", () => {
9
+ const configuration = {
10
+ mobile_buttons_container_align: "left",
11
+ mobile_buttons_container_margin_top: 0,
12
+ mobile_buttons_container_margin_right: 12,
13
+ mobile_buttons_container_margin_bottom: 0,
14
+ mobile_buttons_container_margin_left: 6,
15
+ mobile_buttons_container_stacking: "horizontal",
16
+ mobile_button_1_button_enabled: true,
17
+ mobile_button_1_assign_action: "navigation_action",
18
+ mobile_button_1_display_mode: "dynamic",
19
+ mobile_button_1_contents_alignment: "center",
20
+ mobile_button_1_background_color: "rgba(1,1,1,1)",
21
+ mobile_button_1_border_color: "rgba(0,0,0,0)",
22
+ mobile_button_1_border_size: 0,
23
+ mobile_button_1_corner_radius: 8,
24
+ mobile_button_1_padding_top: 10,
25
+ mobile_button_1_padding_right: 10,
26
+ mobile_button_1_padding_bottom: 10,
27
+ mobile_button_1_padding_left: 10,
28
+ mobile_button_1_asset_enabled: true,
29
+ mobile_button_1_action_asset_flavour: "flavour_1",
30
+ mobile_button_1_asset_alignment: "left",
31
+ mobile_button_1_asset_width: 24,
32
+ mobile_button_1_asset_height: 24,
33
+ mobile_button_1_asset_margin_top: 1,
34
+ mobile_button_1_asset_margin_right: 2,
35
+ mobile_button_1_asset_margin_bottom: 3,
36
+ mobile_button_1_asset_margin_left: 4,
37
+ mobile_button_1_label_enabled: true,
38
+ mobile_button_1_font_color: "rgba(255,255,255,1)",
39
+ mobile_button_1_focused_font_color: "rgba(255,0,0,1)",
40
+ mobile_button_1_ios_font_family: "Ubuntu-Bold",
41
+ mobile_button_1_android_font_family: "Ubuntu-Bold",
42
+ mobile_button_1_font_size: 15,
43
+ mobile_button_1_line_height: 24,
44
+ mobile_button_1_ios_letter_spacing: -0.2,
45
+ mobile_button_1_android_letter_spacing: -0.2,
46
+ mobile_button_1_text_transform: "default",
47
+ };
48
+
49
+ const value = (key) => configuration[key];
50
+
51
+ it("builds the container node with content style in additionalProps", () => {
52
+ const result = ButtonContainerView({
53
+ style: { position: "absolute" },
54
+ contentStyle: {
55
+ flexDirection: "row",
56
+ },
57
+ elements: [{ type: "PressableView" }],
58
+ });
59
+
60
+ expect(result).toEqual({
61
+ type: "View",
62
+ style: { position: "absolute" },
63
+ elements: [
64
+ {
65
+ type: "View",
66
+ style: {
67
+ flexDirection: "row",
68
+ },
69
+ elements: [{ type: "PressableView" }],
70
+ },
71
+ ],
72
+ });
73
+ });
74
+
75
+ it("builds the button node with asset and text label children", () => {
76
+ const result = Button({
77
+ index: 0,
78
+ value,
79
+ stylePrefix: "mobile_button_1",
80
+ specificPrefix: "mobile_button_1",
81
+ spacingStyle: { marginRight: 8 },
82
+ });
83
+
84
+ expect(result.type).toBe("PressableView");
85
+ expect(result.additionalProps.action.identifier).toBe("navigation_action");
86
+
87
+ expect(result.elements).toEqual(
88
+ expect.arrayContaining([
89
+ expect.objectContaining({ type: "Image" }),
90
+ expect.objectContaining({ type: "View" }),
91
+ ])
92
+ );
93
+ });
94
+
95
+ it("builds the asset, label container, label and spacer nodes", () => {
96
+ expect(
97
+ Asset({
98
+ prefix: "mobile_button_1",
99
+ value,
100
+ actionIdentifier: "navigation_action",
101
+ })
102
+ ).toEqual(
103
+ expect.objectContaining({
104
+ type: "Image",
105
+ })
106
+ );
107
+
108
+ expect(
109
+ TextLabelsContainer({
110
+ prefix: "mobile_button_1",
111
+ value,
112
+ actionIdentifier: "navigation_action",
113
+ })
114
+ ).toEqual(
115
+ expect.objectContaining({
116
+ type: "View",
117
+ elements: [expect.objectContaining({ type: "Text" })],
118
+ })
119
+ );
120
+
121
+ expect(
122
+ TextLabel({
123
+ prefix: "mobile_button_1",
124
+ value,
125
+ actionIdentifier: "navigation_action",
126
+ })
127
+ ).toEqual(
128
+ expect.objectContaining({
129
+ type: "Text",
130
+ })
131
+ );
132
+
133
+ expect(Spacer({ enabled: true })).toEqual({
134
+ type: "View",
135
+ style: {
136
+ flex: 1,
137
+ },
138
+ });
139
+ });
140
+ });