@applicaster/quick-brick-player 16.0.0-rc.6 → 16.0.0-rc.61

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 (26) hide show
  1. package/package.json +6 -6
  2. package/src/Player/AudioLayer/AudioDescription.tsx +46 -11
  3. package/src/Player/AudioLayer/AudioPlayerWrapper.tsx +38 -48
  4. package/src/Player/AudioLayer/Layout/Controls/__tests__/utils.test.ts +66 -0
  5. package/src/Player/AudioLayer/Layout/Controls/index.tsx +34 -14
  6. package/src/Player/AudioLayer/Layout/Controls/utils.ts +26 -0
  7. package/src/Player/AudioLayer/Layout/DockedControls/index.tsx +1 -13
  8. package/src/Player/AudioLayer/Layout/MobileLayout.tsx +0 -4
  9. package/src/Player/AudioLayer/Layout/TabletLandscapeLayout.tsx +0 -4
  10. package/src/Player/AudioLayer/Layout/TabletPortraitLayout.tsx +0 -4
  11. package/src/Player/AudioLayer/SleepTimerManager.ts +5 -1
  12. package/src/Player/AudioLayer/SpeedManager.ts +4 -0
  13. package/src/Player/AudioLayer/__tests__/AudioDescription.test.tsx +147 -0
  14. package/src/Player/AudioLayer/__tests__/AudioPlayerWrapper.test.tsx +130 -0
  15. package/src/Player/AudioLayer/__tests__/SleepTimerManager.test.ts +78 -0
  16. package/src/Player/AudioLayer/__tests__/SpeedManager.test.ts +57 -0
  17. package/src/Player/AudioLayer/__tests__/playerActions.test.ts +351 -0
  18. package/src/Player/AudioLayer/__tests__/usePlaylistNavigation.test.ts +387 -0
  19. package/src/Player/AudioLayer/components/SleepTimerModalHeader/SleepTimerModalHeader.tsx +9 -8
  20. package/src/Player/AudioLayer/components/SleepTimerModalHeader/__tests__/SleepTimerModalHeader.test.tsx +53 -0
  21. package/src/Player/AudioLayer/playerActions.ts +280 -0
  22. package/src/Player/AudioLayer/usePlaylistNavigation.ts +134 -0
  23. package/src/Player/AudioLayer/useSleepTimerModal.ts +20 -57
  24. package/src/Player/__tests__/getNativeProps.test.ts +115 -0
  25. package/src/Player/__tests__/toNativeMetadata.test.ts +77 -0
  26. package/src/Player/index.tsx +72 -27
@@ -0,0 +1,147 @@
1
+ import React from "react";
2
+ import { StyleSheet } from "react-native";
3
+ import { render } from "@testing-library/react-native";
4
+
5
+ import { AudioDescription } from "../AudioDescription";
6
+
7
+ // `title`/`summary` come from the player manager's content channel rather than
8
+ // from props or context, so the hook is mocked here. Read lazily inside the
9
+ // factory: `jest.mock` is hoisted above the `let`, so capturing eagerly would
10
+ // freeze it at `undefined`.
11
+ let mockContent: {
12
+ title: Option<string | number>;
13
+ summary: Option<string | number>;
14
+ } = { title: "A Title", summary: "A Summary" };
15
+
16
+ jest.mock(
17
+ "@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayerContent",
18
+ () => ({ usePlayerContent: () => mockContent })
19
+ );
20
+
21
+ beforeEach(() => {
22
+ mockContent = { title: "A Title", summary: "A Summary" };
23
+ });
24
+
25
+ const layoutState = { inline: false, docked: false, isModal: true };
26
+
27
+ const valueFrom =
28
+ (config: Record<string, unknown>): GetValue =>
29
+ (key: string) =>
30
+ (config[key] ?? null) as never;
31
+
32
+ const renderDescription = (
33
+ config: Record<string, unknown>,
34
+ state = layoutState
35
+ ) =>
36
+ render(
37
+ <AudioDescription
38
+ layoutState={state}
39
+ value={valueFrom(config)}
40
+ maxWidth={400}
41
+ />
42
+ );
43
+
44
+ // The wrapper's style prop is an array, so flatten before reading height.
45
+ const wrapperHeight = (tree) =>
46
+ StyleSheet.flatten(tree.toJSON().props.style).height;
47
+
48
+ describe("AudioDescription", () => {
49
+ it("renders both texts when both toggles are on", () => {
50
+ const { queryByText } = renderDescription({ title: true, subtitle: true });
51
+
52
+ expect(queryByText("A Title")).toBeTruthy();
53
+ expect(queryByText("A Summary")).toBeTruthy();
54
+ });
55
+
56
+ it("hides the title when the title toggle is off", () => {
57
+ const { queryByText } = renderDescription({ title: false, subtitle: true });
58
+
59
+ expect(queryByText("A Title")).toBeNull();
60
+ expect(queryByText("A Summary")).toBeTruthy();
61
+ });
62
+
63
+ it("hides the summary when the subtitle toggle is off", () => {
64
+ const { queryByText } = renderDescription({ title: true, subtitle: false });
65
+
66
+ expect(queryByText("A Title")).toBeTruthy();
67
+ expect(queryByText("A Summary")).toBeNull();
68
+ });
69
+
70
+ it("renders neither text when both toggles are off", () => {
71
+ const { queryByText } = renderDescription({
72
+ title: false,
73
+ subtitle: false,
74
+ });
75
+
76
+ expect(queryByText("A Title")).toBeNull();
77
+ expect(queryByText("A Summary")).toBeNull();
78
+ });
79
+
80
+ it("reserves no height when both toggles are off", () => {
81
+ const tree = renderDescription({ title: false, subtitle: false });
82
+
83
+ expect(wrapperHeight(tree)).toBe(0);
84
+ });
85
+
86
+ it("reserves less height when the title is hidden than when it is shown", () => {
87
+ const withTitle = renderDescription({ title: true, subtitle: true });
88
+ const withoutTitle = renderDescription({ title: false, subtitle: true });
89
+
90
+ expect(wrapperHeight(withoutTitle)).toBeLessThan(wrapperHeight(withTitle));
91
+ });
92
+
93
+ it("reserves less height when the subtitle is hidden than when it is shown", () => {
94
+ const withSubtitle = renderDescription({ title: true, subtitle: true });
95
+ const withoutSubtitle = renderDescription({ title: true, subtitle: false });
96
+
97
+ expect(wrapperHeight(withoutSubtitle)).toBeLessThan(
98
+ wrapperHeight(withSubtitle)
99
+ );
100
+ });
101
+
102
+ it("reads the docked toggle keys when docked", () => {
103
+ const { queryByText } = renderDescription(
104
+ { docked_player_title: true, docked_player_subtitle: false },
105
+ { ...layoutState, docked: true }
106
+ );
107
+
108
+ expect(queryByText("A Title")).toBeTruthy();
109
+ expect(queryByText("A Summary")).toBeNull();
110
+ });
111
+
112
+ /**
113
+ * Live audio resolves its text asynchronously: the channel feed is polled
114
+ * after playback starts, so the first render has no programme title yet. The
115
+ * row must hold its place across that transition instead of collapsing and
116
+ * expanding a second later.
117
+ */
118
+ describe("layout stability while the text is still missing", () => {
119
+ it("reserves the same height with and without text", () => {
120
+ const withText = renderDescription({ title: true, subtitle: true });
121
+
122
+ mockContent = { title: null, summary: null };
123
+
124
+ const withoutText = renderDescription({ title: true, subtitle: true });
125
+
126
+ expect(wrapperHeight(withoutText)).toBe(wrapperHeight(withText));
127
+ });
128
+
129
+ it("still renders both rows when the text has not arrived", () => {
130
+ mockContent = { title: null, summary: null };
131
+
132
+ const tree = renderDescription({ title: true, subtitle: true });
133
+
134
+ expect(wrapperHeight(tree)).toBeGreaterThan(0);
135
+ });
136
+
137
+ it("reserves height for the summary even when only the summary is missing", () => {
138
+ const withSummary = renderDescription({ title: true, subtitle: true });
139
+
140
+ mockContent = { title: "A Title", summary: null };
141
+
142
+ const withoutSummary = renderDescription({ title: true, subtitle: true });
143
+
144
+ expect(wrapperHeight(withoutSummary)).toBe(wrapperHeight(withSummary));
145
+ });
146
+ });
147
+ });
@@ -0,0 +1,130 @@
1
+ import React from "react";
2
+ import { render } from "@testing-library/react-native";
3
+
4
+ /**
5
+ * Covers AudioPlayerWrapper's remaining Title/Subtitle responsibility, which is
6
+ * only lifecycle: keep the manager's live-content polling running while this
7
+ * player is mounted. It carries neither the text (consumers read it from the
8
+ * player manager via `usePlayerContent`) nor any decision about the polling -
9
+ * whether the content is live, where the channel's programme feed lives and
10
+ * how often to poll are all `OverlaysObserver`'s.
11
+ *
12
+ * The rest of the chain is covered where each link lives:
13
+ * - is-live / feed url / interval OverlayObserver/__tests__/liveContent.test.ts
14
+ * - polling -> `observer.liveEntry` OverlayObserver/__tests__/liveContent.test.ts
15
+ * - liveEntry -> published content playerManager/__tests__/playerContent.test.ts
16
+ * - published content -> rendered text AudioLayer/__tests__/AudioDescription.test.tsx
17
+ */
18
+
19
+ const mockStartLiveContentUpdates = jest.fn();
20
+ const mockStopLiveContentUpdates = jest.fn();
21
+
22
+ const mockPlayer = {
23
+ getOverlayObservable: () => ({
24
+ startLiveContentUpdates: mockStartLiveContentUpdates,
25
+ stopLiveContentUpdates: mockStopLiveContentUpdates,
26
+ }),
27
+ addListener: jest.fn(() => jest.fn()),
28
+ play: jest.fn(),
29
+ pause: jest.fn(),
30
+ rewind: jest.fn(),
31
+ forward: jest.fn(),
32
+ };
33
+
34
+ let mockIsLive = false;
35
+
36
+ jest.mock(
37
+ "@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayer",
38
+ () => ({ usePlayer: () => mockPlayer })
39
+ );
40
+
41
+ jest.mock(
42
+ "@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayerState",
43
+ () => ({
44
+ usePlayerState: () => ({
45
+ isLive: mockIsLive,
46
+ seekableDuration: 0,
47
+ isReadyToPlay: false,
48
+ isBuffering: false,
49
+ isPaused: false,
50
+ }),
51
+ })
52
+ );
53
+
54
+ jest.mock("@applicaster/zapp-react-native-utils/appUtils", () => ({
55
+ playerManager: {
56
+ close: jest.fn(),
57
+ isCasting: jest.fn(() => false),
58
+ },
59
+ }));
60
+
61
+ jest.mock("@applicaster/zapp-react-native-utils/reactHooks", () => ({
62
+ useNavigation: jest.fn(() => ({ maximiseVideoModal: jest.fn() })),
63
+ }));
64
+
65
+ jest.mock("@applicaster/zapp-react-native-utils/modalState", () => ({
66
+ useModalStoreState: jest.fn(() => ({ visible: false })),
67
+ dismissModal: jest.fn(),
68
+ openBottomSheetModal: jest.fn(),
69
+ }));
70
+
71
+ jest.mock("../Layout", () => ({
72
+ __esModule: true,
73
+ default: () => null,
74
+ }));
75
+
76
+ import { AudioPlayerWrapper } from "../AudioPlayerWrapper";
77
+
78
+ const LIVE_ENTRY = {
79
+ id: "entry-1",
80
+ title: "Channel Title",
81
+ summary: "Channel Summary",
82
+ extensions: {
83
+ live: { channel_src: "https://feed.test/subClass/audio" },
84
+ },
85
+ } as any;
86
+
87
+ const baseProps = {
88
+ configuration: { audio_live_player_update_interval: 30 },
89
+ style: { width: 100, height: 100 } as any,
90
+ entry: LIVE_ENTRY,
91
+ layoutState: { inline: false, docked: false, isModal: false, pip: false },
92
+ playNextData: null,
93
+ children: null,
94
+ };
95
+
96
+ describe("AudioPlayerWrapper live content polling", () => {
97
+ beforeEach(() => {
98
+ jest.clearAllMocks();
99
+ mockIsLive = true;
100
+ });
101
+
102
+ it("asks the observer to keep live content fresh while mounted", () => {
103
+ render(<AudioPlayerWrapper {...baseProps} />);
104
+
105
+ expect(mockStartLiveContentUpdates).toHaveBeenCalled();
106
+ });
107
+
108
+ it("stops polling on unmount", () => {
109
+ const { unmount } = render(<AudioPlayerWrapper {...baseProps} />);
110
+
111
+ unmount();
112
+
113
+ expect(mockStopLiveContentUpdates).toHaveBeenCalled();
114
+ });
115
+
116
+ it("re-evaluates when the player reports the content is live", () => {
117
+ // `isLive` is unknown until the player loads, so the effect has to run
118
+ // again once it settles - the observer decides what to do with it.
119
+ mockIsLive = false;
120
+
121
+ const { rerender } = render(<AudioPlayerWrapper {...baseProps} />);
122
+
123
+ mockStartLiveContentUpdates.mockClear();
124
+ mockIsLive = true;
125
+
126
+ rerender(<AudioPlayerWrapper {...baseProps} />);
127
+
128
+ expect(mockStartLiveContentUpdates).toHaveBeenCalled();
129
+ });
130
+ });
@@ -0,0 +1,78 @@
1
+ import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
2
+ import { SLEEP_TIMER_OFF, SleepTimerController } from "../SleepTimerManager";
3
+
4
+ jest.mock(
5
+ "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage",
6
+ () => ({
7
+ localStorage: {
8
+ getItem: jest.fn(),
9
+ setItem: jest.fn(),
10
+ removeItem: jest.fn(),
11
+ },
12
+ })
13
+ );
14
+
15
+ describe("SleepTimerController", () => {
16
+ const player = {
17
+ startSleepTimer: jest.fn(),
18
+ cancelSleepTimer: jest.fn(),
19
+ };
20
+
21
+ let sleepController: SleepTimerController;
22
+
23
+ beforeEach(() => {
24
+ jest.clearAllMocks();
25
+ (localStorage.setItem as jest.Mock).mockResolvedValue(undefined);
26
+ (localStorage.removeItem as jest.Mock).mockResolvedValue(undefined);
27
+ (localStorage.getItem as jest.Mock).mockResolvedValue(undefined);
28
+ sleepController = new SleepTimerController(player as any);
29
+ });
30
+
31
+ it("starts from the off state", () => {
32
+ expect(sleepController.currentState.timer).toEqual(SLEEP_TIMER_OFF);
33
+ });
34
+
35
+ it("starts a sleep timer on the constructed player", async () => {
36
+ await sleepController.setSleepTimer({
37
+ label: "15 minutes",
38
+ value: 15,
39
+ });
40
+
41
+ expect(player.cancelSleepTimer).toHaveBeenCalled();
42
+ expect(player.startSleepTimer).toHaveBeenCalled();
43
+ expect(sleepController.currentState.timer.value).toBe(15);
44
+ });
45
+
46
+ it("loadSleep restores an unexpired timer", async () => {
47
+ const futureSleepDate = Date.now() + 60 * 1000;
48
+
49
+ (localStorage.getItem as jest.Mock).mockResolvedValue({
50
+ label: "15 minutes",
51
+ value: 15,
52
+ futureSleepDate,
53
+ });
54
+
55
+ player.startSleepTimer.mockClear();
56
+
57
+ await sleepController.loadSleep();
58
+
59
+ expect(player.startSleepTimer).toHaveBeenCalledWith(futureSleepDate);
60
+ expect(sleepController.currentState.timer.value).toBe(15);
61
+ });
62
+
63
+ it("loadSleep drops an expired timer without starting a native timer", async () => {
64
+ (localStorage.getItem as jest.Mock).mockResolvedValue({
65
+ label: "15 minutes",
66
+ value: 15,
67
+ futureSleepDate: Date.now() - 1000,
68
+ });
69
+
70
+ player.startSleepTimer.mockClear();
71
+
72
+ await sleepController.loadSleep();
73
+
74
+ expect(player.startSleepTimer).not.toHaveBeenCalled();
75
+ expect(localStorage.removeItem).toHaveBeenCalled();
76
+ expect(sleepController.currentState.timer).toEqual(SLEEP_TIMER_OFF);
77
+ });
78
+ });
@@ -0,0 +1,57 @@
1
+ import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
2
+ import { DEFAULT_SPEED, SpeedController } from "../SpeedManager";
3
+
4
+ jest.mock(
5
+ "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage",
6
+ () => ({
7
+ localStorage: {
8
+ getItem: jest.fn(),
9
+ setItem: jest.fn(),
10
+ removeItem: jest.fn(),
11
+ },
12
+ })
13
+ );
14
+
15
+ describe("SpeedController", () => {
16
+ const player = { setPlaybackRate: jest.fn() };
17
+ let speedController: SpeedController;
18
+
19
+ beforeEach(() => {
20
+ jest.clearAllMocks();
21
+ (localStorage.setItem as jest.Mock).mockResolvedValue(undefined);
22
+ (localStorage.getItem as jest.Mock).mockResolvedValue(undefined);
23
+ speedController = new SpeedController(player as any);
24
+ });
25
+
26
+ it("requires a player in the constructor", () => {
27
+ expect(speedController.currentSpeed).toEqual(DEFAULT_SPEED);
28
+ });
29
+
30
+ it("applies playback speed on the constructed player", async () => {
31
+ await speedController.setPlaybackSpeed({
32
+ asset: "speed_1_5",
33
+ value: 1.5,
34
+ });
35
+
36
+ expect(player.setPlaybackRate).toHaveBeenCalledWith(1.5);
37
+
38
+ expect(speedController.currentSpeed).toEqual({
39
+ asset: "speed_1_5",
40
+ value: 1.5,
41
+ });
42
+ });
43
+
44
+ it("loadSpeed restores a stored rate onto the player", async () => {
45
+ (localStorage.getItem as jest.Mock).mockResolvedValue({
46
+ asset: "speed_1_5",
47
+ value: 1.5,
48
+ });
49
+
50
+ player.setPlaybackRate.mockClear();
51
+
52
+ await speedController.loadSpeed();
53
+
54
+ expect(player.setPlaybackRate).toHaveBeenCalledWith(1.5);
55
+ expect(speedController.currentSpeed.value).toBe(1.5);
56
+ });
57
+ });