@applicaster/zapp-react-native-ui-components 16.0.0-rc.59 → 16.0.0-rc.60

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.
@@ -1,6 +1,15 @@
1
1
  import React from "react";
2
2
  import { render } from "@testing-library/react-native";
3
3
 
4
+ let mockContent = { title: null, summary: null };
5
+
6
+ // Read lazily inside the factory: `jest.mock` is hoisted above the `let` above,
7
+ // so capturing the value eagerly would freeze it at `undefined`.
8
+ jest.mock(
9
+ "@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayerContent",
10
+ () => ({ usePlayerContent: () => mockContent })
11
+ );
12
+
4
13
  import { AudioPlayerTV } from "..";
5
14
 
6
15
  jest.mock("@applicaster/zapp-react-native-utils/audioPlayerUtils", () => ({
@@ -51,7 +60,17 @@ const audioPlayerProps = {
51
60
 
52
61
  describe("<AudioPlayerTV />", () => {
53
62
  it("renders correctly", () => {
63
+ // AudioPlayerTV no longer resolves its own title/summary from
64
+ // audio_item - it reads them from the player manager's content channel.
65
+ // Publishing the same values `audio_item.title`/`.summary` used to resolve
66
+ // to keeps this snapshot byte-for-byte identical to before that change.
67
+ mockContent = {
68
+ title: audioPlayerProps.audio_item.title,
69
+ summary: audioPlayerProps.audio_item.summary,
70
+ };
71
+
54
72
  const { toJSON } = render(<AudioPlayerTV {...audioPlayerProps} />);
73
+
55
74
  expect(toJSON()).toMatchSnapshot();
56
75
  });
57
76
  });
@@ -0,0 +1,120 @@
1
+ import React from "react";
2
+ import { render } from "@testing-library/react-native";
3
+
4
+ import { AudioPlayerTV } from "..";
5
+
6
+ jest.mock("@applicaster/zapp-react-native-utils/audioPlayerUtils", () => ({
7
+ useArtworkImage: jest.fn(() => "artwork_url"),
8
+ }));
9
+
10
+ let mockContent: {
11
+ title: Option<string | number>;
12
+ summary: Option<string | number>;
13
+ } = { title: null, summary: null };
14
+
15
+ // Read lazily inside the factory: `jest.mock` is hoisted above the `let`
16
+ // above, so capturing the value eagerly would freeze it at `undefined`.
17
+ jest.mock(
18
+ "@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayerContent",
19
+ () => ({ usePlayerContent: () => mockContent })
20
+ );
21
+
22
+ const baseAudioItem = {
23
+ title: "tittle",
24
+ summary: "Summary",
25
+ content: {
26
+ src: "https://example.com",
27
+ },
28
+ media_group: [
29
+ {
30
+ type: "audio",
31
+ media_item: [
32
+ {
33
+ type: "audio",
34
+ src: "https://example.com",
35
+ key: "base_code",
36
+ },
37
+ ],
38
+ },
39
+ ],
40
+ extensions: {
41
+ audio_player_artwork_aspect_ratio: "1:1",
42
+ audio_player_background_image: "https://example.com",
43
+ audio_player_background_color: "black",
44
+ audio_player_channel_icon: "https://example.com",
45
+ audio_player_title_color: "white",
46
+ audio_player_summary_color: "white",
47
+ audio_player_rtl: true,
48
+ start_time: "10:10",
49
+ end_time: "11:11",
50
+ episode_name: "Episode Custom Title",
51
+ episode_summary: "Episode Custom Summary",
52
+ },
53
+ };
54
+
55
+ const basePluginConfiguration = {
56
+ audio_player_background_color: "black",
57
+ audio_player_title_color: "white",
58
+ audio_player_summary_color: "white",
59
+ audio_player_rtl: true,
60
+ audio_player_background_image: "https://example.com",
61
+ audio_player_artwork_aspect_ratio: "1:1",
62
+ };
63
+
64
+ function renderAudioPlayer(
65
+ plugin_configuration,
66
+ content: {
67
+ title?: Option<string | number>;
68
+ summary?: Option<string | number>;
69
+ } = {}
70
+ ) {
71
+ mockContent = {
72
+ title: content.title ?? null,
73
+ summary: content.summary ?? null,
74
+ };
75
+
76
+ return render(
77
+ <AudioPlayerTV
78
+ audio_item={baseAudioItem}
79
+ plugin_configuration={plugin_configuration}
80
+ style={{}}
81
+ />
82
+ );
83
+ }
84
+
85
+ describe("<AudioPlayerTV /> player content", () => {
86
+ it("renders the title and summary published by the player manager", () => {
87
+ const { getByText } = renderAudioPlayer(basePluginConfiguration, {
88
+ title: "Episode Custom Title",
89
+ summary: "Episode Custom Summary",
90
+ });
91
+
92
+ expect(getByText("Episode Custom Title")).toBeTruthy();
93
+ expect(getByText("Episode Custom Summary")).toBeTruthy();
94
+ });
95
+
96
+ it("renders nothing for title/summary when the player published neither", () => {
97
+ const { queryByText } = renderAudioPlayer(basePluginConfiguration);
98
+
99
+ expect(queryByText("tittle")).toBeNull();
100
+ expect(queryByText("Summary")).toBeNull();
101
+ });
102
+
103
+ it("renders blank rather than crashing when no player is active", () => {
104
+ // `usePlayerContent` returns `{ title: null, summary: null }` when there is
105
+ // no player. A regression here means AudioPlayerTV crashes instead of
106
+ // rendering blank.
107
+ mockContent = { title: null, summary: null };
108
+
109
+ const { queryByText } = render(
110
+ <AudioPlayerTV
111
+ audio_item={baseAudioItem}
112
+ plugin_configuration={basePluginConfiguration}
113
+ style={{}}
114
+ />
115
+ );
116
+
117
+ expect(queryByText("tittle")).toBeNull();
118
+ expect(queryByText("Summary")).toBeNull();
119
+ });
120
+ });
@@ -3,6 +3,8 @@ import React, { useCallback, useMemo } from "react";
3
3
  import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
4
4
  import { useArtworkImage } from "@applicaster/zapp-react-native-utils/audioPlayerUtils";
5
5
 
6
+ import { usePlayerContent } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayerContent";
7
+
6
8
  import { AudioPlayerTVLayout } from "./Layout";
7
9
 
8
10
  import { Channel } from "./Channel";
@@ -15,10 +17,12 @@ import { Props } from "../types";
15
17
 
16
18
  export function AudioPlayerTV(props: Props) {
17
19
  const { audio_item, plugin_configuration, style = {} } = props;
18
- const { extensions, title, summary } = audio_item;
20
+ const { extensions } = audio_item;
19
21
 
20
22
  const artwork = useArtworkImage(audio_item);
21
23
 
24
+ const { title, summary } = usePlayerContent();
25
+
22
26
  const getProp = useCallback(
23
27
  getPropertyFromEntryOrConfig({
24
28
  entry: audio_item,
@@ -190,12 +190,10 @@ const renderApplePlayer = ({
190
190
  return null;
191
191
  }
192
192
 
193
- const { title, summary } = item || {};
194
-
193
+ // Title/Subtitle are not resolved here: `ProgramInfo` reads them from the
194
+ // player manager's content channel via `usePlayerContent`.
195
195
  return (
196
196
  <ProgramInfo
197
- title={title}
198
- subtitle={summary}
199
197
  plugin_configuration={pluginConfiguration}
200
198
  videoStyle={videoStyle}
201
199
  />
@@ -7,12 +7,11 @@ import * as React from "react";
7
7
  import { Text, TextStyle, View, ViewStyle } from "react-native";
8
8
  import { QBImage as Image } from "@applicaster/zapp-react-native-ui-components/Components/Image";
9
9
 
10
+ import { usePlayerContent } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayerContent";
10
11
  import * as programStyles from "./styles";
11
12
 
12
13
  type Props = {
13
14
  logo?: string;
14
- title: string;
15
- subtitle: string;
16
15
  isAudioContent: boolean;
17
16
  styles: {};
18
17
  plugin_configuration: {
@@ -28,13 +27,13 @@ const defaultColor = "#EFEFEF";
28
27
 
29
28
  function ProgramInfoComponent({
30
29
  logo,
31
- title = "",
32
- subtitle = "",
33
30
  isAudioContent,
34
31
  styles,
35
32
  plugin_configuration = {},
36
33
  videoStyle = {},
37
34
  }: Props) {
35
+ const { title = "", summary: subtitle = "" } = usePlayerContent();
36
+
38
37
  const platformKey = styleKeys.style_namespace;
39
38
 
40
39
  const colorTitle =
@@ -17,17 +17,37 @@ jest.mock(
17
17
  );
18
18
 
19
19
  jest.mock("@applicaster/zapp-react-native-utils/reactUtils", () => ({
20
+ // Defaults to `false` for the hardware-back-handling tests below, which
21
+ // key off `isTV`. The ProgramInfo/content-context describe block below
22
+ // overrides this per test (`isTV()` is also what PlayerContainer's
23
+ // `playerContentValue` uses to pick TV vs mobile data keys, decoupled
24
+ // from `isTvOSPlatform` below).
20
25
  isTV: jest.fn(() => false),
21
26
  isAndroidTVPlatform: jest.fn(() => false),
22
- isTvOSPlatform: jest.fn(() => false),
27
+ // `isTvOSPlatform` backs a module-level constant in PlayerContainer.tsx that
28
+ // is read once at import time, so it must already be `true` here in order
29
+ // to exercise `renderApplePlayer`'s tvOS-only ProgramInfo branch in this
30
+ // test file. It does not affect the hardware-back-handling tests below,
31
+ // which key off `isTV` instead.
32
+ isTvOSPlatform: jest.fn(() => true),
23
33
  isApplePlatform: jest.fn(() => true),
24
34
  platformSelect: jest.fn(({ native }) => native),
25
35
  }));
26
36
 
27
- jest.mock("@applicaster/zapp-react-native-utils/playerUtils", () => ({
28
- isAudioItem: jest.fn(() => false),
29
- isInlineTV: jest.fn(() => false),
30
- }));
37
+ jest.mock("@applicaster/zapp-react-native-utils/playerUtils", () => {
38
+ // Keep the real data-key resolver (createConfigValueGetter,
39
+ // resolvePlayerContentText, VIDEO_PLAYER_CONTENT_DATA_KEYS) so the tvOS
40
+ // ProgramInfo data-key tests exercise actual resolution logic, not a stub.
41
+ const actual = jest.requireActual(
42
+ "@applicaster/zapp-react-native-utils/playerUtils"
43
+ );
44
+
45
+ return {
46
+ ...actual,
47
+ isAudioItem: jest.fn(() => false),
48
+ isInlineTV: jest.fn(() => false),
49
+ };
50
+ });
31
51
 
32
52
  jest.mock(
33
53
  "@applicaster/zapp-react-native-tvos-ui-components/Components/TVEventHandlerComponent",
@@ -76,6 +96,11 @@ jest.mock("@applicaster/zapp-react-native-bridge/QuickBrick", () => ({
76
96
  sendQuickBrickEvent: jest.fn(),
77
97
  }));
78
98
 
99
+ // Stubbed so PlayerContainer can render without ProgramInfo's own
100
+ // redux/style plumbing. It no longer needs to capture Title/Subtitle: those
101
+ // come from the player manager's content channel, and the key-set selection
102
+ // they depend on is covered directly in
103
+ // `playerManager/__tests__/playerContent.test.ts`.
79
104
  jest.mock("../ProgramInfo", () => ({
80
105
  ProgramInfo: () => null,
81
106
  }));
@@ -143,14 +168,33 @@ jest.mock(
143
168
  jest.mock("../PlayerContainerContext", () => {
144
169
  const ReactActual = require("react");
145
170
 
171
+ const PlayerContainerContext = ReactActual.createContext({
172
+ isLanguageOverlayVisible: false,
173
+ bottomFocusableId: "bottom",
174
+ showComponentsContainer: false,
175
+ refs: null,
176
+ });
177
+
146
178
  return {
147
- PlayerContainerContext: ReactActual.createContext({
148
- isLanguageOverlayVisible: false,
149
- bottomFocusableId: "bottom",
150
- showComponentsContainer: false,
151
- refs: null,
152
- }),
153
- PlayerContainerContextProvider: ({ children }) => children,
179
+ PlayerContainerContext,
180
+ // Mirrors just enough of the real provider for these tests: renders an
181
+ // actual `PlayerContainerContext.Provider` so the real
182
+ // `PlayerContainerContext.Consumer` inside PlayerContainer.tsx sees the
183
+ // container fields a real provider would give it, instead of a bare
184
+ // `({ children }) => children` passthrough.
185
+ PlayerContainerContextProvider: ({ children }: any) =>
186
+ ReactActual.createElement(
187
+ PlayerContainerContext.Provider,
188
+ {
189
+ value: {
190
+ isLanguageOverlayVisible: false,
191
+ bottomFocusableId: "bottom",
192
+ showComponentsContainer: false,
193
+ refs: null,
194
+ },
195
+ },
196
+ children
197
+ ),
154
198
  };
155
199
  });
156
200
 
@@ -201,7 +245,14 @@ const { __player: mockPlayer } = jest.requireMock(
201
245
  "@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayer"
202
246
  );
203
247
 
204
- const Player = React.forwardRef(() => null);
248
+ const { isTV: mockIsTV } = jest.requireMock(
249
+ "@applicaster/zapp-react-native-utils/reactUtils"
250
+ );
251
+
252
+ // Renders children so that `renderApplePlayer`'s returned <ProgramInfo>
253
+ // element (passed as this component's `children` prop) actually mounts —
254
+ // otherwise React never invokes the ProgramInfo function component at all.
255
+ const Player = React.forwardRef((props: any, _ref) => props.children ?? null);
205
256
 
206
257
  const item = {
207
258
  id: "entry-1",
@@ -235,6 +286,7 @@ const pressHardwareBack = () => {
235
286
  describe("PlayerContainer hardware back handling", () => {
236
287
  beforeEach(() => {
237
288
  jest.clearAllMocks();
289
+ mockIsTV.mockReturnValue(false);
238
290
  mockBackHandlerRef.current = null;
239
291
  mockPlayer.getPluginConfiguration.mockReturnValue({});
240
292
  mockPlayer.isPaused.mockReturnValue(false);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@applicaster/zapp-react-native-ui-components",
3
- "version": "16.0.0-rc.59",
3
+ "version": "16.0.0-rc.60",
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,10 +28,10 @@
28
28
  },
29
29
  "homepage": "https://github.com/applicaster/quickbrick#readme",
30
30
  "dependencies": {
31
- "@applicaster/applicaster-types": "16.0.0-rc.59",
32
- "@applicaster/zapp-react-native-bridge": "16.0.0-rc.59",
33
- "@applicaster/zapp-react-native-redux": "16.0.0-rc.59",
34
- "@applicaster/zapp-react-native-utils": "16.0.0-rc.59",
31
+ "@applicaster/applicaster-types": "16.0.0-rc.60",
32
+ "@applicaster/zapp-react-native-bridge": "16.0.0-rc.60",
33
+ "@applicaster/zapp-react-native-redux": "16.0.0-rc.60",
34
+ "@applicaster/zapp-react-native-utils": "16.0.0-rc.60",
35
35
  "fast-json-stable-stringify": "^2.1.0",
36
36
  "promise": "^8.3.0",
37
37
  "react-native-sortables": "1.7.1",