@applicaster/zapp-react-native-ui-components 16.0.0-alpha.1042942411 → 16.0.0-alpha.1054344748

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 (112) hide show
  1. package/Components/AudioPlayer/tv/__tests__/audioPlayer.test.js +19 -0
  2. package/Components/AudioPlayer/tv/__tests__/index.test.tsx +120 -0
  3. package/Components/AudioPlayer/tv/index.tsx +5 -1
  4. package/Components/Cell/Cell.tsx +3 -6
  5. package/Components/Cell/TvOSCellComponent.tsx +0 -1
  6. package/Components/GeneralContentScreen/GeneralContentScreenHookAdapter.tsx +15 -0
  7. package/Components/GeneralContentScreen/hookAdapter/__tests__/skipExpression.test.ts +294 -0
  8. package/Components/GeneralContentScreen/hookAdapter/__tests__/validationHelper.test.ts +64 -0
  9. package/Components/GeneralContentScreen/hookAdapter/skipExpression.ts +252 -0
  10. package/Components/GeneralContentScreen/hookAdapter/validationHelper.ts +18 -0
  11. package/Components/LinkHandler/LinkHandler.tsx +2 -7
  12. package/Components/MasterCell/DefaultComponents/ActionButton.tsx +64 -28
  13. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/components/ActionButtonController.tsx +19 -4
  14. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/components/__tests__/ActionButtonController.test.tsx +43 -1
  15. package/Components/MasterCell/DefaultComponents/BorderContainerView/__tests__/index.test.tsx +46 -217
  16. package/Components/MasterCell/DefaultComponents/BorderContainerView/index.tsx +109 -46
  17. package/Components/MasterCell/DefaultComponents/Button.tsx +44 -50
  18. package/Components/MasterCell/DefaultComponents/CellBadge/index.tsx +14 -13
  19. package/Components/MasterCell/DefaultComponents/Image/hoc/utils/__tests__/withDimensions.test.ts +420 -125
  20. package/Components/MasterCell/DefaultComponents/Image/hoc/utils/index.ts +114 -19
  21. package/Components/MasterCell/DefaultComponents/Image/hoc/withDimensions.tsx +19 -8
  22. package/Components/MasterCell/DefaultComponents/LiveImage/executePreloadHooks.ts +2 -4
  23. package/Components/MasterCell/DefaultComponents/LiveImage/index.tsx +2 -3
  24. package/Components/MasterCell/DefaultComponents/SecondaryImage/Image.tsx +50 -46
  25. package/Components/MasterCell/DefaultComponents/SecondaryImage/__tests__/__snapshots__/Image.test.tsx.snap +39 -47
  26. package/Components/MasterCell/DefaultComponents/SecondaryImage/utils.ts +6 -19
  27. package/Components/MasterCell/DefaultComponents/Text/index.tsx +15 -45
  28. package/Components/MasterCell/DefaultComponents/Toggle.tsx +36 -14
  29. package/Components/MasterCell/DefaultComponents/__tests__/Toggle.test.tsx +167 -0
  30. package/Components/MasterCell/DefaultComponents/__tests__/text.test.tsx +67 -196
  31. package/Components/MasterCell/DefaultComponents/index.ts +0 -4
  32. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/PressableView.test.tsx +6 -4
  33. package/Components/MasterCell/SharedUI/CollapsibleTextContainer/__tests__/factory.test.ts +32 -0
  34. package/Components/MasterCell/SharedUI/CollapsibleTextContainer/index.ts +1 -2
  35. package/Components/MasterCell/elementMapper.tsx +0 -2
  36. package/Components/ModalComponent/ActionsBottomSheet/ActionButton.tsx +56 -0
  37. package/Components/ModalComponent/ActionsBottomSheet/__tests__/openActionsBottomSheet.test.ts +38 -0
  38. package/Components/ModalComponent/ActionsBottomSheet/boundActionButton.tsx +24 -0
  39. package/Components/ModalComponent/ActionsBottomSheet/index.ts +9 -0
  40. package/Components/ModalComponent/ActionsBottomSheet/openActionsBottomSheet.ts +61 -0
  41. package/Components/ModalComponent/AudioPlayer/Components/Button.tsx +87 -97
  42. package/Components/ModalComponent/AudioPlayer/Components/Header.tsx +87 -126
  43. package/Components/ModalComponent/AudioPlayer/Components/Input.tsx +140 -83
  44. package/Components/ModalComponent/AudioPlayer/Components/Item.tsx +252 -123
  45. package/Components/ModalComponent/AudioPlayer/Components/NowPlayingHeaderSection.tsx +205 -0
  46. package/Components/ModalComponent/AudioPlayer/Components/__tests__/Item.test.tsx +113 -0
  47. package/Components/ModalComponent/AudioPlayer/Components/__tests__/NowPlayingHeaderSection.test.tsx +36 -0
  48. package/Components/ModalComponent/AudioPlayer/Components/index.ts +3 -3
  49. package/Components/ModalComponent/AudioPlayer/utils/__tests__/mergeStyles.test.ts +356 -0
  50. package/Components/ModalComponent/AudioPlayer/utils/mergeStyles.ts +521 -0
  51. package/Components/ModalComponent/BottomSheetModalContent.tsx +498 -66
  52. package/Components/ModalComponent/Button/index.tsx +5 -3
  53. package/Components/ModalComponent/Header/CloseButton.tsx +12 -0
  54. package/Components/ModalComponent/Header/__tests__/CloseButton.test.tsx +72 -0
  55. package/Components/ModalComponent/Header/index.tsx +20 -7
  56. package/Components/ModalComponent/Header/utils.ts +1 -1
  57. package/Components/ModalComponent/ModalBlocksStyleContext.tsx +10 -0
  58. package/Components/ModalComponent/SortableList.tsx +156 -0
  59. package/Components/ModalComponent/SortableList.web.tsx +34 -0
  60. package/Components/ModalComponent/TextInputContent.tsx +135 -0
  61. package/Components/ModalComponent/__tests__/BottomSheetModalContent.test.tsx +343 -0
  62. package/Components/ModalComponent/__tests__/SortableList.web.test.tsx +16 -0
  63. package/Components/ModalComponent/__tests__/TextInputContent.test.tsx +169 -0
  64. package/Components/ModalComponent/__tests__/showTextInput.test.ts +95 -0
  65. package/Components/ModalComponent/index.tsx +18 -9
  66. package/Components/ModalComponent/presets/__tests__/getCell.test.ts +90 -0
  67. package/Components/ModalComponent/presets/dynamicCollectionCell.tsx +78 -0
  68. package/Components/ModalComponent/presets/index.ts +27 -0
  69. package/Components/ModalComponent/presets/selectableCell.tsx +28 -0
  70. package/Components/ModalComponent/presets/standardCell.tsx +41 -0
  71. package/Components/ModalComponent/presets/types.ts +35 -0
  72. package/Components/ModalComponent/showTextInput.ts +52 -0
  73. package/Components/ModalComponent/utils.ts +82 -21
  74. package/Components/OfflineHandler/__tests__/index.test.tsx +109 -0
  75. package/Components/OfflineHandler/hooks.ts +0 -12
  76. package/Components/OfflineHandler/index.tsx +42 -4
  77. package/Components/PlayerContainer/PlayerContainer.tsx +19 -8
  78. package/Components/PlayerContainer/ProgramInfo/index.tsx +3 -4
  79. package/Components/PlayerContainer/__tests__/PlayerContainer.test.tsx +66 -13
  80. package/Components/River/ComponentsMap/ComponentsMap.tsx +85 -59
  81. package/Components/River/River.tsx +4 -0
  82. package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +138 -75
  83. package/Components/River/__tests__/componentsMap.test.js +8 -3
  84. package/Components/River/__tests__/resultCallback.test.tsx +47 -0
  85. package/Components/Screen/__tests__/Screen.test.tsx +24 -0
  86. package/Components/Screen/__tests__/__snapshots__/Screen.test.tsx.snap +2 -0
  87. package/Components/Screen/index.tsx +5 -0
  88. package/Components/Screen/navigationHandler.ts +8 -8
  89. package/Components/ScreenRevealManager/ScreenRevealManager.ts +18 -2
  90. package/Components/ScreenRevealManager/__tests__/ScreenRevealManager.test.ts +36 -0
  91. package/Components/ScreenRevealManager/__tests__/withScreenRevealManager.test.tsx +56 -0
  92. package/Components/ScreenRevealManager/withScreenRevealManager.tsx +21 -4
  93. package/Components/Transitioner/AnimationManager.js +1 -1
  94. package/Components/Transitioner/Scene.tsx +4 -3
  95. package/Components/Transitioner/Transitioner.tsx +71 -33
  96. package/Components/Transitioner/__tests__/transitioner.test.js +372 -3
  97. package/Components/VideoLive/LiveImageManager.ts +9 -3
  98. package/Components/VideoLive/__tests__/LiveImageManager.test.ts +59 -0
  99. package/Contexts/ModalNavigationContext/__tests__/index.test.tsx +15 -0
  100. package/Contexts/ModalNavigationContext/index.tsx +2 -2
  101. package/Hooks/useEntryActionsExpander.ts +63 -0
  102. package/assets/empty-Info.png +0 -0
  103. package/package.json +6 -5
  104. package/Components/MasterCell/DefaultComponents/CellBadge/__tests__/__snapshots__/index.test.tsx.snap +0 -18
  105. package/Components/MasterCell/DefaultComponents/CellBadge/__tests__/index.test.tsx +0 -90
  106. package/Components/MasterCell/DefaultComponents/UIKitAdapters/Badge.tsx +0 -49
  107. package/Components/MasterCell/DefaultComponents/__tests__/ActionButton.test.tsx +0 -122
  108. package/Components/MasterCell/DefaultComponents/__tests__/Button.test.tsx +0 -186
  109. package/Components/MasterCell/DefaultComponents/__tests__/DynamicBadge.test.tsx +0 -156
  110. package/Components/MasterCell/DefaultComponents/__tests__/__snapshots__/ActionButton.test.tsx.snap +0 -60
  111. package/Components/ModalComponent/AudioPlayer/Components/Action.tsx +0 -332
  112. /package/Decorators/ZappPipesDataConnector/__tests__/{Hero.js → Hero.tsx} +0 -0
@@ -1,6 +1,8 @@
1
1
  const { LiveImageManager } = require("../LiveImageManager");
2
2
 
3
3
  describe("LiveImageManager", () => {
4
+ const flushPromises = () => new Promise(setImmediate);
5
+
4
6
  it("should subscribe to LiveImageManager events", () => {
5
7
  const sampleListener = {
6
8
  id: "1",
@@ -78,4 +80,61 @@ describe("LiveImageManager", () => {
78
80
  expect(mockOnEnd1).toHaveBeenCalledWith(eventBody);
79
81
  expect(mockOnEnd2).toHaveBeenCalledWith(eventBody);
80
82
  });
83
+
84
+ it("should start a prepared live image when the mounted player loads", async () => {
85
+ const manager = new LiveImageManager();
86
+
87
+ const item = {
88
+ playerId: "live-image",
89
+ tag: "Live image",
90
+ player: {
91
+ playerId: "live-image",
92
+ playerState: { isReadyToPlay: false },
93
+ getEntry: jest.fn(),
94
+ play: jest.fn(),
95
+ },
96
+ getPlayer: jest.fn(),
97
+ prepareForPlayback: jest.fn().mockResolvedValue(true),
98
+ setMode: jest.fn(),
99
+ };
100
+
101
+ manager.playLiveImage(item);
102
+ await flushPromises();
103
+
104
+ expect(item.setMode).toHaveBeenCalledWith("video");
105
+ expect(item.player.play).not.toHaveBeenCalled();
106
+
107
+ manager.onLiveImageVideoLoaded(item);
108
+
109
+ expect(item.player.play).toHaveBeenCalledTimes(1);
110
+ });
111
+
112
+ it("should not start a live image that was paused before the player loaded", async () => {
113
+ const manager = new LiveImageManager();
114
+
115
+ const item = {
116
+ playerId: "live-image",
117
+ tag: "Live image",
118
+ player: {
119
+ playerId: "live-image",
120
+ playerState: { isReadyToPlay: false },
121
+ getEntry: jest.fn(),
122
+ play: jest.fn(),
123
+ pause: jest.fn(),
124
+ onPlayerClose: jest.fn(),
125
+ },
126
+ getPlayer: jest.fn(),
127
+ prepareForPlayback: jest.fn().mockResolvedValue(true),
128
+ setMode: jest.fn(),
129
+ };
130
+
131
+ manager.playLiveImage(item);
132
+ await flushPromises();
133
+ manager.pauseLiveImage(item);
134
+ manager.onLiveImageVideoLoaded(item);
135
+
136
+ expect(item.player.pause).toHaveBeenCalledTimes(1);
137
+ expect(item.player.play).not.toHaveBeenCalled();
138
+ expect(item.setMode).toHaveBeenLastCalledWith("image");
139
+ });
81
140
  });
@@ -0,0 +1,15 @@
1
+ import React from "react";
2
+ import { render } from "@testing-library/react-native";
3
+ import { withModalNavigationContextProvider } from "../";
4
+
5
+ describe("withModalNavigationContextProvider", () => {
6
+ it("does not re-render the wrapped component when props are unchanged", () => {
7
+ const Component = jest.fn(() => null);
8
+ const WrappedComponent = withModalNavigationContextProvider(Component);
9
+ const { rerender } = render(<WrappedComponent title="Modal" />);
10
+
11
+ rerender(<WrappedComponent title="Modal" />);
12
+
13
+ expect(Component).toHaveBeenCalledTimes(1);
14
+ });
15
+ });
@@ -6,11 +6,11 @@ export function useModalNavigationContext() {
6
6
  }
7
7
 
8
8
  export function withModalNavigationContextProvider(Component) {
9
- return function WrappedWithModalNavigationContextProvider(props) {
9
+ return React.memo(function WrappedWithModalNavigationContextProvider(props) {
10
10
  return (
11
11
  <ModalNavigationContext.Provider value={true}>
12
12
  <Component {...props} />
13
13
  </ModalNavigationContext.Provider>
14
14
  );
15
- };
15
+ });
16
16
  }
@@ -0,0 +1,63 @@
1
+ import * as React from "react";
2
+
3
+ import { ActionExecutorContext } from "@applicaster/zapp-react-native-utils/actionsExecutor/ActionExecutorContext";
4
+ import {
5
+ buildEntryActions,
6
+ EntryActionDeps,
7
+ } from "@applicaster/zapp-react-native-utils/entryActions";
8
+ import { useRoute } from "@applicaster/zapp-react-native-utils/reactHooks/navigation";
9
+ import { useScreenStateStore } from "@applicaster/zapp-react-native-utils/reactHooks/navigation/useScreenStateStore";
10
+ import {
11
+ useCurrentScreenData,
12
+ useScreenContext,
13
+ } from "@applicaster/zapp-react-native-utils/reactHooks/screen";
14
+ import { RegisteredAction } from "@applicaster/zapp-react-native-utils/uiActionsRegistrator";
15
+
16
+ /**
17
+ * Expands `entry.extensions.entry_action` into invokable actions, against the
18
+ * screen this hook is called from.
19
+ *
20
+ * Entry actions are data on the entry, not an installed capability, so there is
21
+ * nothing to look up by identifier: the surface showing the entry expands them.
22
+ * That also decides which screen they execute against — the one whose tree this
23
+ * hook runs in, rather than whichever screen happened to be current when a
24
+ * global provider was registered.
25
+ *
26
+ * Pass the result to `resolveActionIdentifiers` / `resolvePlayerActions` as
27
+ * `expandEntryActions`.
28
+ */
29
+ export function useEntryActionsExpander(): (
30
+ entry: ZappEntry | ZappFeed
31
+ ) => RegisteredAction[] {
32
+ const { pathname } = useRoute();
33
+
34
+ const screenContext = useScreenContext();
35
+ const screenData = useCurrentScreenData();
36
+ const screenState = screenContext?.options;
37
+ const screenStateStore = useScreenStateStore();
38
+ const actionExecutor = React.useContext(ActionExecutorContext);
39
+
40
+ // Read through a ref so the returned expander keeps a stable identity: it
41
+ // feeds `useMemo` dependency lists on surfaces that re-resolve their actions
42
+ // on every registry change.
43
+ const depsRef = React.useRef<EntryActionDeps>();
44
+
45
+ depsRef.current = {
46
+ actionExecutor,
47
+ actionContext: {
48
+ screenData,
49
+ screenState,
50
+ screenRoute: pathname,
51
+ screenStateStore,
52
+ // From the screen context, the way `useCellClick` builds the same bag.
53
+ // The ZappPipes entry context is a route-keyed map, so reading `.data`
54
+ // off it was always undefined.
55
+ screenEntry: screenContext?.entry,
56
+ },
57
+ };
58
+
59
+ return React.useCallback(
60
+ (entry: ZappEntry | ZappFeed) => buildEntryActions(entry, depsRef.current),
61
+ []
62
+ );
63
+ }
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-ui-components",
3
- "version": "16.0.0-alpha.1042942411",
3
+ "version": "16.0.0-alpha.1054344748",
4
4
  "description": "Applicaster Zapp React Native ui components for the Quick Brick App",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
@@ -28,12 +28,13 @@
28
28
  },
29
29
  "homepage": "https://github.com/applicaster/quickbrick#readme",
30
30
  "dependencies": {
31
- "@applicaster/applicaster-types": "16.0.0-alpha.1042942411",
32
- "@applicaster/zapp-react-native-bridge": "16.0.0-alpha.1042942411",
33
- "@applicaster/zapp-react-native-redux": "16.0.0-alpha.1042942411",
34
- "@applicaster/zapp-react-native-utils": "16.0.0-alpha.1042942411",
31
+ "@applicaster/applicaster-types": "16.0.0-alpha.1054344748",
32
+ "@applicaster/zapp-react-native-bridge": "16.0.0-alpha.1054344748",
33
+ "@applicaster/zapp-react-native-redux": "16.0.0-alpha.1054344748",
34
+ "@applicaster/zapp-react-native-utils": "16.0.0-alpha.1054344748",
35
35
  "fast-json-stable-stringify": "^2.1.0",
36
36
  "promise": "^8.3.0",
37
+ "react-native-sortables": "1.7.1",
37
38
  "url": "^0.11.0",
38
39
  "uuid": "^3.3.2"
39
40
  },
@@ -1,18 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`CellBadge matches the rendered CellBadge snapshot after config inflation 1`] = `
4
- <View
5
- style={
6
- {
7
- "bottom": 0,
8
- "flex": 1,
9
- "left": 0,
10
- "marginBottom": 5,
11
- "marginLeft": 6,
12
- "marginRight": 4,
13
- "marginTop": 3,
14
- "position": "absolute",
15
- }
16
- }
17
- />
18
- `;
@@ -1,90 +0,0 @@
1
- import { View } from "react-native";
2
- import { render } from "@testing-library/react-native";
3
- import { configInflater } from "../../../dataAdapter";
4
- import { elementMapper } from "../../../elementMapper";
5
- import { CellBadge } from "..";
6
- import { UIKitBadge } from "../../UIKitAdapters/Badge";
7
-
8
- const createValue = (overrides: Record<string, unknown> = {}) => {
9
- const values = {
10
- cell_badge_switch: true,
11
- cell_badge_position: "bottom_left",
12
- cell_badge_width: 42,
13
- cell_badge_height: 24,
14
- cell_badge_margin_top: 3,
15
- cell_badge_margin_right: 4,
16
- cell_badge_margin_bottom: 5,
17
- cell_badge_margin_left: 6,
18
- cell_badge_default: "default.png",
19
- cell_badge_selected: "selected.png",
20
- cell_badge_focused: "focused.png",
21
- cell_badge_focused_selected: "focused-selected.png",
22
- ...overrides,
23
- };
24
-
25
- return (key: string) => values[key];
26
- };
27
-
28
- describe("CellBadge", () => {
29
- it("returns explicit CellBadge props and image config", () => {
30
- const result = CellBadge({
31
- value: createValue(),
32
- state: "focused_selected",
33
- });
34
-
35
- expect(result).toMatchObject({
36
- type: "UIKitBadge",
37
- style: {
38
- flex: 1,
39
- },
40
- additionalProps: {
41
- position: "bottom_left",
42
- width: 42,
43
- height: 24,
44
- margins: {
45
- marginTop: 3,
46
- marginRight: 4,
47
- marginBottom: 5,
48
- marginLeft: 6,
49
- },
50
- },
51
- elements: [
52
- {
53
- type: "Image",
54
- style: {
55
- width: 42,
56
- height: 24,
57
- },
58
- additionalProps: {
59
- resizeMode: "cover",
60
- },
61
- },
62
- ],
63
- });
64
-
65
- expect(result.elements[0].data[0].func()).toBe("focused-selected.png");
66
- });
67
-
68
- it("matches the rendered CellBadge snapshot after config inflation", () => {
69
- const inflatedConfig = configInflater(
70
- {},
71
- CellBadge({
72
- value: createValue(),
73
- state: "focused_selected",
74
- })
75
- );
76
-
77
- const wrapper = render(
78
- elementMapper({
79
- View,
80
- UIKitBadge,
81
- Image: View,
82
- })({
83
- ...inflatedConfig,
84
- key: "cell-badge",
85
- })
86
- );
87
-
88
- expect(wrapper.toJSON()).toMatchSnapshot();
89
- });
90
- });
@@ -1,49 +0,0 @@
1
- import React from "react";
2
- import {
3
- Badge,
4
- BadgeProps,
5
- } from "@applicaster/uikit/lib/components/uikit/badge";
6
- import { ViewStyle } from "react-native";
7
-
8
- export const UIKitBadge = ({
9
- children,
10
- style,
11
- position,
12
- width,
13
- height,
14
- margins,
15
- onPress,
16
- testID,
17
- accessibilityLabel,
18
- accessibilityHint,
19
- }: {
20
- children?: React.ReactNode;
21
- style?: BadgeProps["style"];
22
- position?: BadgeProps["position"];
23
- width?: BadgeProps["width"];
24
- height?: BadgeProps["height"];
25
- margins?: Pick<
26
- ViewStyle,
27
- "marginTop" | "marginRight" | "marginBottom" | "marginLeft"
28
- >;
29
- onPress?: BadgeProps["onPress"];
30
- testID?: BadgeProps["testID"];
31
- accessibilityLabel?: BadgeProps["accessibilityLabel"];
32
- accessibilityHint?: BadgeProps["accessibilityHint"];
33
- }) => (
34
- <Badge
35
- onPress={onPress}
36
- testID={testID}
37
- accessibilityLabel={accessibilityLabel}
38
- accessibilityHint={accessibilityHint}
39
- position={position}
40
- width={width}
41
- height={height}
42
- style={{
43
- ...style,
44
- ...margins,
45
- }}
46
- >
47
- {children}
48
- </Badge>
49
- );
@@ -1,122 +0,0 @@
1
- import React from "react";
2
- import { TouchableOpacity } from "react-native";
3
- import { render } from "@testing-library/react-native";
4
-
5
- import { ActionButton } from "../ActionButton";
6
-
7
- const mockUseActions = jest.fn();
8
-
9
- jest.mock("@applicaster/zapp-react-native-utils/reactHooks/actions", () => ({
10
- useActions: (...args) => mockUseActions(...args),
11
- }));
12
-
13
- jest.mock("@applicaster/zapp-react-native-utils/theme", () => ({
14
- useTheme: jest.fn(() => ({
15
- use_downscaling_images: false,
16
- })),
17
- }));
18
-
19
- describe("MasterCell ActionButton", () => {
20
- beforeEach(() => {
21
- jest.clearAllMocks();
22
-
23
- mockUseActions.mockReturnValue({
24
- initialEntryState: () => ({
25
- asset: "active.png",
26
- }),
27
- invokeAction: jest.fn(),
28
- addListener: jest.fn(),
29
- isActionAvailable: jest.fn(() => true),
30
- });
31
- });
32
-
33
- it("renders using UIKit ActionButton and passes Image AssetComponent for image assets", () => {
34
- const item = {
35
- id: "entry-id",
36
- };
37
-
38
- const wrapper = render(
39
- <ActionButton
40
- item={item as any}
41
- action={{ identifier: "bookmark" }}
42
- asset={{
43
- type: "Image",
44
- src: {
45
- active: "active.png",
46
- inactive: "inactive.png",
47
- },
48
- style: {
49
- width: 32,
50
- height: 32,
51
- },
52
- props: {
53
- testID: "action-button-image",
54
- },
55
- }}
56
- style={{
57
- width: 32,
58
- height: 32,
59
- }}
60
- testID="action-button"
61
- accessibilityLabel="action-button-label"
62
- />
63
- );
64
-
65
- const button = wrapper.getByTestId("action-button");
66
- const image = wrapper.getByTestId("action-button-image");
67
-
68
- expect(button.props.accessibilityLabel).toBe("action-button-label");
69
-
70
- expect(image.props.source).toEqual({ uri: "inactive.png" });
71
- });
72
-
73
- it('matches the rendered "action-button" snapshot', () => {
74
- const wrapper = render(
75
- <ActionButton
76
- item={{ id: "entry-id" } as any}
77
- action={{ identifier: "bookmark" }}
78
- asset={{
79
- type: "Image",
80
- src: {
81
- active: "active.png",
82
- inactive: "inactive.png",
83
- },
84
- style: {
85
- width: 32,
86
- height: 32,
87
- },
88
- props: {
89
- testID: "action-button-image",
90
- },
91
- }}
92
- style={{
93
- width: 32,
94
- height: 32,
95
- }}
96
- testID="action-button"
97
- accessibilityLabel="action-button-label"
98
- />
99
- );
100
-
101
- expect(wrapper.UNSAFE_getByType(TouchableOpacity).props).toMatchObject({
102
- activeOpacity: 1,
103
- id: "action-button-entry-id",
104
- testID: "action-button",
105
- accessibilityLabel: "action-button-label",
106
- accessible: true,
107
- accessibilityHint: undefined,
108
- style: { width: 32, height: 32 },
109
- });
110
-
111
- expect(
112
- wrapper.UNSAFE_getByType(TouchableOpacity).props.children.props
113
- ).toMatchObject({
114
- fadeDuration: 0,
115
- style: { width: 32, height: 32 },
116
- uri: "inactive.png",
117
- testID: "action-button-image",
118
- });
119
-
120
- expect(wrapper.toJSON()).toMatchSnapshot();
121
- });
122
- });
@@ -1,186 +0,0 @@
1
- import React from "react";
2
- import { TouchableOpacity } from "react-native";
3
- import { render } from "@testing-library/react-native";
4
-
5
- import { Button } from "../Button";
6
- import { masterCellLogger } from "../../logger";
7
-
8
- const mockUseActions = jest.fn();
9
-
10
- const baseProps = {
11
- item: { id: "entry-id" } as any,
12
- action: { identifier: "bookmark", type: "plugin" },
13
- asset: {
14
- type: "Image" as const,
15
- src: {
16
- active: "active.png",
17
- inactive: "inactive.png",
18
- },
19
- style: {
20
- width: 24,
21
- height: 24,
22
- },
23
- props: {
24
- testID: "button-image",
25
- },
26
- },
27
- style: {
28
- width: 40,
29
- height: 40,
30
- },
31
- testID: "button",
32
- accessibilityLabel: "button-label",
33
- };
34
-
35
- jest.mock("@applicaster/zapp-react-native-utils/reactHooks/actions", () => ({
36
- useActions: (...args) => mockUseActions(...args),
37
- }));
38
-
39
- jest.mock("@applicaster/zapp-react-native-utils/theme", () => ({
40
- useTheme: jest.fn(() => ({
41
- use_downscaling_images: false,
42
- })),
43
- }));
44
-
45
- jest.mock("../../logger", () => ({
46
- masterCellLogger: {
47
- warning: jest.fn(),
48
- error: jest.fn(),
49
- },
50
- }));
51
-
52
- describe("MasterCell Button", () => {
53
- beforeEach(() => {
54
- jest.clearAllMocks();
55
- });
56
-
57
- it("renders the UIKit button with the inactive asset when the item is not selected", () => {
58
- mockUseActions.mockReturnValue({
59
- state: [],
60
- });
61
-
62
- const wrapper = render(<Button {...baseProps} />);
63
- const button = wrapper.getByTestId("button");
64
- const image = wrapper.getByTestId("button-image");
65
-
66
- expect(button.props).toMatchObject({
67
- testID: "button",
68
- accessibilityLabel: "button-label",
69
- style: { width: 40, height: 40 },
70
- });
71
-
72
- expect(wrapper.UNSAFE_getByType(TouchableOpacity).props.id).toBe(
73
- "entry-id"
74
- );
75
-
76
- expect(image.props.source).toEqual({ uri: "inactive.png" });
77
-
78
- expect(image.props.style).toMatchObject({
79
- width: 24,
80
- height: 24,
81
- });
82
- });
83
-
84
- it("renders the active asset when the legacy action context marks the item as selected", () => {
85
- mockUseActions.mockReturnValue({
86
- state: [],
87
- masterCell: {
88
- isSelected: jest.fn(() => true),
89
- },
90
- });
91
-
92
- const wrapper = render(<Button {...baseProps} />);
93
-
94
- expect(wrapper.getByTestId("button-image").props.source).toEqual({
95
- uri: "active.png",
96
- });
97
- });
98
-
99
- it("defaults ButtonAsset to the Image component when asset.type is missing", () => {
100
- mockUseActions.mockReturnValue({
101
- state: [],
102
- });
103
-
104
- const wrapper = render(
105
- <Button
106
- {...baseProps}
107
- asset={{
108
- ...baseProps.asset,
109
- type: undefined as any,
110
- }}
111
- />
112
- );
113
-
114
- expect(wrapper.getByTestId("button-image").props.source).toEqual({
115
- uri: "inactive.png",
116
- });
117
- });
118
-
119
- it("forwards asset.props to the ButtonAsset component", () => {
120
- mockUseActions.mockReturnValue({
121
- state: [],
122
- });
123
-
124
- const wrapper = render(
125
- <Button
126
- {...baseProps}
127
- asset={{
128
- ...baseProps.asset,
129
- props: {
130
- testID: "button-image",
131
- resizeMode: "contain",
132
- nativeID: "button-asset",
133
- },
134
- }}
135
- />
136
- );
137
-
138
- expect(wrapper.getByTestId("button-image").props).toMatchObject({
139
- testID: "button-image",
140
- resizeMode: "contain",
141
- nativeID: "button-asset",
142
- });
143
- });
144
-
145
- it("renders the ActionButton when the action context uses the new API", () => {
146
- const addListener = jest.fn(() => jest.fn());
147
-
148
- mockUseActions.mockReturnValue({
149
- initialEntryState: jest.fn(() => ({
150
- asset: "active.png",
151
- })),
152
- invokeAction: jest.fn(),
153
- addListener,
154
- isActionAvailable: jest.fn(() => true),
155
- });
156
-
157
- const wrapper = render(<Button {...baseProps} />);
158
- const button = wrapper.getByTestId("button");
159
- const image = wrapper.getByTestId("button-image");
160
-
161
- expect(button.props.accessibilityLabel).toBe("button-label");
162
- expect(image.props.source).toEqual({ uri: "inactive.png" });
163
- expect(addListener).toHaveBeenCalledWith("entry-id", expect.any(Function));
164
-
165
- expect(wrapper.UNSAFE_getByType(TouchableOpacity).props.id).toBe(
166
- "action-button-entry-id"
167
- );
168
- });
169
-
170
- it("returns null and logs a warning when the action plugin is missing", () => {
171
- mockUseActions.mockReturnValue(undefined);
172
-
173
- const wrapper = render(
174
- <Button
175
- {...baseProps}
176
- action={{ identifier: "missing-plugin", type: "plugin" }}
177
- />
178
- );
179
-
180
- expect(wrapper.toJSON()).toBeNull();
181
-
182
- expect(masterCellLogger.warning).toHaveBeenCalledWith(
183
- "You're missing an action plugin(missing-plugin) required by your button. \n Button can't be displayed"
184
- );
185
- });
186
- });