@applicaster/zapp-react-native-utils 15.1.7 → 15.1.9-alpha.3547421944
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.
- package/actionsExecutor/__tests__/feedDecorator.test.ts +61 -0
- package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +133 -0
- package/actionsExecutor/actions/navigateToScreen.ts +18 -4
- package/actionsExecutor/feedDecorator.ts +6 -6
- package/appUtils/HooksManager/index.ts +9 -0
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +127 -46
- package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
- package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
- package/appUtils/playerManager/__tests__/usePlayerContent.test.tsx +64 -0
- package/appUtils/playerManager/player.ts +114 -2
- package/appUtils/playerManager/usePlayerContent.tsx +43 -0
- package/cellUtils/index.ts +30 -3
- package/manifestUtils/defaultManifestConfigurations/player.js +166 -0
- package/package.json +2 -2
- package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
- package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
- package/playerUtils/contentDataKeys.ts +134 -0
- package/playerUtils/index.ts +20 -15
- package/playerUtils/isAudioItem.ts +26 -0
- package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
- package/reactHooks/cell-click/index.ts +2 -11
- package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { OverlaysObserver } from "../OverlaysObserver";
|
|
2
|
+
import { loadFeedEntry } from "../utils";
|
|
3
|
+
|
|
4
|
+
jest.mock("../utils", () => ({
|
|
5
|
+
...jest.requireActual("../utils"),
|
|
6
|
+
loadFeedEntry: jest.fn(),
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
const FEED_ENTRY = { title: "Programme One" } as unknown as ZappEntry;
|
|
10
|
+
|
|
11
|
+
const CHANNEL_ENTRY = {
|
|
12
|
+
title: "Channel",
|
|
13
|
+
extensions: { live: { channel_src: "https://feed.test/subClass/audio" } },
|
|
14
|
+
} as unknown as ZappEntry;
|
|
15
|
+
|
|
16
|
+
const makePlayer = ({
|
|
17
|
+
isLive = true,
|
|
18
|
+
entry = CHANNEL_ENTRY,
|
|
19
|
+
configuration = { audio_live_player_update_interval: 30 },
|
|
20
|
+
}: {
|
|
21
|
+
isLive?: boolean;
|
|
22
|
+
entry?: ZappEntry;
|
|
23
|
+
configuration?: Record<string, any>;
|
|
24
|
+
} = {}) => ({
|
|
25
|
+
isLive: () => isLive,
|
|
26
|
+
getEntry: () => entry,
|
|
27
|
+
getPluginConfiguration: () => configuration,
|
|
28
|
+
publishContent: jest.fn(),
|
|
29
|
+
addListener: jest.fn(() => () => {}),
|
|
30
|
+
removeListener: jest.fn(),
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
describe("OverlaysObserver live content", () => {
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
jest.useFakeTimers();
|
|
36
|
+
(loadFeedEntry as jest.Mock).mockReset();
|
|
37
|
+
(loadFeedEntry as jest.Mock).mockResolvedValue(FEED_ENTRY);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
afterEach(() => {
|
|
41
|
+
jest.useRealTimers();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("stores the loaded programme and asks the player to republish", async () => {
|
|
45
|
+
const player = makePlayer();
|
|
46
|
+
const observer = new OverlaysObserver({ player } as any);
|
|
47
|
+
|
|
48
|
+
observer.startLiveContentUpdates();
|
|
49
|
+
|
|
50
|
+
await Promise.resolve();
|
|
51
|
+
await Promise.resolve();
|
|
52
|
+
|
|
53
|
+
expect(observer.liveEntry).toBe(FEED_ENTRY);
|
|
54
|
+
expect(player.publishContent).toHaveBeenCalled();
|
|
55
|
+
|
|
56
|
+
observer.stopLiveContentUpdates();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("clears the stored programme on clearLiveEntry", async () => {
|
|
60
|
+
const player = makePlayer();
|
|
61
|
+
const observer = new OverlaysObserver({ player } as any);
|
|
62
|
+
|
|
63
|
+
observer.startLiveContentUpdates();
|
|
64
|
+
|
|
65
|
+
await Promise.resolve();
|
|
66
|
+
await Promise.resolve();
|
|
67
|
+
|
|
68
|
+
observer.clearLiveEntry();
|
|
69
|
+
|
|
70
|
+
expect(observer.liveEntry).toBeNull();
|
|
71
|
+
|
|
72
|
+
observer.stopLiveContentUpdates();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("reloads on the configured interval", async () => {
|
|
76
|
+
const player = makePlayer();
|
|
77
|
+
const observer = new OverlaysObserver({ player } as any);
|
|
78
|
+
|
|
79
|
+
observer.startLiveContentUpdates();
|
|
80
|
+
|
|
81
|
+
await Promise.resolve();
|
|
82
|
+
|
|
83
|
+
(loadFeedEntry as jest.Mock).mockClear();
|
|
84
|
+
|
|
85
|
+
jest.advanceTimersByTime(30_000);
|
|
86
|
+
|
|
87
|
+
expect(loadFeedEntry).toHaveBeenCalledTimes(1);
|
|
88
|
+
|
|
89
|
+
observer.stopLiveContentUpdates();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("stops polling after stopLiveContentUpdates", async () => {
|
|
93
|
+
const player = makePlayer();
|
|
94
|
+
const observer = new OverlaysObserver({ player } as any);
|
|
95
|
+
|
|
96
|
+
observer.startLiveContentUpdates();
|
|
97
|
+
|
|
98
|
+
await Promise.resolve();
|
|
99
|
+
|
|
100
|
+
observer.stopLiveContentUpdates();
|
|
101
|
+
|
|
102
|
+
(loadFeedEntry as jest.Mock).mockClear();
|
|
103
|
+
|
|
104
|
+
jest.advanceTimersByTime(90_000);
|
|
105
|
+
|
|
106
|
+
expect(loadFeedEntry).not.toHaveBeenCalled();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it("keeps the previous content when a poll fails", async () => {
|
|
110
|
+
const player = makePlayer();
|
|
111
|
+
const observer = new OverlaysObserver({ player } as any);
|
|
112
|
+
|
|
113
|
+
(loadFeedEntry as jest.Mock).mockRejectedValue(new Error("network"));
|
|
114
|
+
|
|
115
|
+
observer.startLiveContentUpdates();
|
|
116
|
+
|
|
117
|
+
await Promise.resolve();
|
|
118
|
+
await Promise.resolve();
|
|
119
|
+
|
|
120
|
+
expect(observer.liveEntry).toBeNull();
|
|
121
|
+
expect(player.publishContent).not.toHaveBeenCalled();
|
|
122
|
+
|
|
123
|
+
observer.stopLiveContentUpdates();
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("drops a response that arrives after polling was stopped", async () => {
|
|
127
|
+
const player = makePlayer();
|
|
128
|
+
const observer = new OverlaysObserver({ player } as any);
|
|
129
|
+
|
|
130
|
+
let resolveLoad: (entry: ZappEntry) => void;
|
|
131
|
+
|
|
132
|
+
(loadFeedEntry as jest.Mock).mockReturnValue(
|
|
133
|
+
new Promise<ZappEntry>((resolve) => {
|
|
134
|
+
resolveLoad = resolve;
|
|
135
|
+
})
|
|
136
|
+
);
|
|
137
|
+
|
|
138
|
+
observer.startLiveContentUpdates();
|
|
139
|
+
observer.stopLiveContentUpdates();
|
|
140
|
+
|
|
141
|
+
// The request was already in flight when polling stopped: clearing the
|
|
142
|
+
// interval cannot cancel it, so its result must be ignored rather than
|
|
143
|
+
// published over whatever is playing now.
|
|
144
|
+
resolveLoad(FEED_ENTRY);
|
|
145
|
+
|
|
146
|
+
await Promise.resolve();
|
|
147
|
+
await Promise.resolve();
|
|
148
|
+
|
|
149
|
+
expect(observer.liveEntry).toBeNull();
|
|
150
|
+
expect(player.publishContent).not.toHaveBeenCalled();
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("does not start polling when the entry carries no live channel feed", () => {
|
|
154
|
+
const player = makePlayer({ entry: { title: "No Feed" } as ZappEntry });
|
|
155
|
+
const observer = new OverlaysObserver({ player } as any);
|
|
156
|
+
|
|
157
|
+
observer.startLiveContentUpdates();
|
|
158
|
+
|
|
159
|
+
expect(loadFeedEntry).not.toHaveBeenCalled();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it("does not start polling for on-demand content", () => {
|
|
163
|
+
const player = makePlayer({ isLive: false });
|
|
164
|
+
const observer = new OverlaysObserver({ player } as any);
|
|
165
|
+
|
|
166
|
+
observer.startLiveContentUpdates();
|
|
167
|
+
|
|
168
|
+
expect(loadFeedEntry).not.toHaveBeenCalled();
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it("rewrites the channel url to reach the programme feed", () => {
|
|
172
|
+
const player = makePlayer();
|
|
173
|
+
const observer = new OverlaysObserver({ player } as any);
|
|
174
|
+
|
|
175
|
+
observer.startLiveContentUpdates();
|
|
176
|
+
|
|
177
|
+
expect(loadFeedEntry).toHaveBeenCalledWith(
|
|
178
|
+
"https://feed.test/livePage/audio",
|
|
179
|
+
expect.anything()
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
observer.stopLiveContentUpdates();
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("falls back to the manifest default interval when none is configured", async () => {
|
|
186
|
+
// An unset value would make `intervalSeconds * 1000` NaN, and setInterval
|
|
187
|
+
// treats NaN as 0 - a tight loop hammering the feed.
|
|
188
|
+
const player = makePlayer({ configuration: {} });
|
|
189
|
+
const observer = new OverlaysObserver({ player } as any);
|
|
190
|
+
|
|
191
|
+
observer.startLiveContentUpdates();
|
|
192
|
+
|
|
193
|
+
await Promise.resolve();
|
|
194
|
+
|
|
195
|
+
(loadFeedEntry as jest.Mock).mockClear();
|
|
196
|
+
|
|
197
|
+
jest.advanceTimersByTime(59_000);
|
|
198
|
+
expect(loadFeedEntry).not.toHaveBeenCalled();
|
|
199
|
+
|
|
200
|
+
jest.advanceTimersByTime(1_000);
|
|
201
|
+
expect(loadFeedEntry).toHaveBeenCalledTimes(1);
|
|
202
|
+
|
|
203
|
+
observer.stopLiveContentUpdates();
|
|
204
|
+
});
|
|
205
|
+
});
|
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
import { Player } from "../player";
|
|
2
|
+
import { isTV } from "../../../reactUtils";
|
|
3
|
+
|
|
4
|
+
jest.mock("../../../reactUtils", () => ({
|
|
5
|
+
...jest.requireActual("../../../reactUtils"),
|
|
6
|
+
isTV: jest.fn(() => false),
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
const mockIsTV = isTV as jest.Mock;
|
|
10
|
+
|
|
11
|
+
const ENTRY = {
|
|
12
|
+
title: "Entry Title",
|
|
13
|
+
summary: "Entry Summary",
|
|
14
|
+
extensions: { programme: "Programme Title" },
|
|
15
|
+
} as unknown as ZappEntry;
|
|
16
|
+
|
|
17
|
+
const LIVE_ENTRY = {
|
|
18
|
+
title: "Live Title",
|
|
19
|
+
summary: "Live Summary",
|
|
20
|
+
} as unknown as ZappEntry;
|
|
21
|
+
|
|
22
|
+
const makePlayer = (configuration: Record<string, any> | null = null) => {
|
|
23
|
+
const player = new Player({ playerId: "test-player" });
|
|
24
|
+
|
|
25
|
+
player.getPluginConfiguration = () => configuration;
|
|
26
|
+
|
|
27
|
+
return player;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
describe("Player content channel", () => {
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
mockIsTV.mockReturnValue(false);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("resolves the entry fields when nothing is configured", () => {
|
|
36
|
+
const player = makePlayer();
|
|
37
|
+
|
|
38
|
+
player.entry = ENTRY;
|
|
39
|
+
|
|
40
|
+
expect(player.getContent()).toEqual({
|
|
41
|
+
title: "Entry Title",
|
|
42
|
+
summary: "Entry Summary",
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("resolves a configured custom data key", () => {
|
|
47
|
+
const player = makePlayer({
|
|
48
|
+
title_data_key_source: "other",
|
|
49
|
+
title_custom_data_key: "extensions.programme",
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
player.entry = ENTRY;
|
|
53
|
+
|
|
54
|
+
expect(player.getContent().title).toBe("Programme Title");
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it("falls back to the entry field when the configured key is unresolvable", () => {
|
|
58
|
+
const player = makePlayer({
|
|
59
|
+
title_data_key_source: "other",
|
|
60
|
+
title_custom_data_key: "extensions.nope",
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
player.entry = ENTRY;
|
|
64
|
+
|
|
65
|
+
expect(player.getContent().title).toBe("Entry Title");
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it("emits the resolved content to subscribers when the entry changes", () => {
|
|
69
|
+
const player = makePlayer();
|
|
70
|
+
const received: any[] = [];
|
|
71
|
+
|
|
72
|
+
player
|
|
73
|
+
.getContentObservable()
|
|
74
|
+
.subscribe((content) => received.push(content));
|
|
75
|
+
|
|
76
|
+
player.entry = ENTRY;
|
|
77
|
+
|
|
78
|
+
expect(received[received.length - 1]).toEqual({
|
|
79
|
+
title: "Entry Title",
|
|
80
|
+
summary: "Entry Summary",
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("seeds subscribers with resolved content, never the raw entry", () => {
|
|
85
|
+
const player = makePlayer({
|
|
86
|
+
title_data_key_source: "other",
|
|
87
|
+
title_custom_data_key: "extensions.programme",
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
player.entry = ENTRY;
|
|
91
|
+
|
|
92
|
+
const received: any[] = [];
|
|
93
|
+
|
|
94
|
+
player
|
|
95
|
+
.getContentObservable()
|
|
96
|
+
.subscribe((content) => received.push(content));
|
|
97
|
+
|
|
98
|
+
expect(received[0].title).toBe("Programme Title");
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
// The live entry lives on `OverlaysObserver`, not on the player, so these
|
|
102
|
+
// stub the observer rather than constructing a real one (whose constructor
|
|
103
|
+
// pulls in chapter markers, play-next and the plugin store). What is under
|
|
104
|
+
// test here is only how `getContent` and the `entry` setter treat it; the
|
|
105
|
+
// observer's own side - loading the feed and storing the result - is
|
|
106
|
+
// covered in `OverlayObserver/__tests__/liveContent.test.ts`.
|
|
107
|
+
const withLiveEntry = (player: Player, liveEntry: ZappEntry | null) => {
|
|
108
|
+
(player as any).overlaysObserver = {
|
|
109
|
+
liveEntry,
|
|
110
|
+
clearLiveEntry() {
|
|
111
|
+
this.liveEntry = null;
|
|
112
|
+
},
|
|
113
|
+
};
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
it("prefers the observer's live entry over the player entry", () => {
|
|
117
|
+
const player = makePlayer();
|
|
118
|
+
|
|
119
|
+
player.entry = ENTRY;
|
|
120
|
+
withLiveEntry(player, LIVE_ENTRY);
|
|
121
|
+
|
|
122
|
+
expect(player.getContent()).toEqual({
|
|
123
|
+
title: "Live Title",
|
|
124
|
+
summary: "Live Summary",
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("clears the live entry when a new entry is set", () => {
|
|
129
|
+
const player = makePlayer();
|
|
130
|
+
|
|
131
|
+
player.entry = ENTRY;
|
|
132
|
+
withLiveEntry(player, LIVE_ENTRY);
|
|
133
|
+
player.entry = ENTRY;
|
|
134
|
+
|
|
135
|
+
expect(player.getContent().title).toBe("Entry Title");
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
it("falls through to the player entry when there is no observer at all", () => {
|
|
139
|
+
const player = makePlayer();
|
|
140
|
+
|
|
141
|
+
player.entry = ENTRY;
|
|
142
|
+
|
|
143
|
+
expect((player as any).overlaysObserver).toBeFalsy();
|
|
144
|
+
expect(player.getContent().title).toBe("Entry Title");
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it("resolves the cover image from the entry's media group", () => {
|
|
148
|
+
const player = makePlayer();
|
|
149
|
+
|
|
150
|
+
player.entry = {
|
|
151
|
+
title: "Entry Title",
|
|
152
|
+
media_group: [
|
|
153
|
+
{
|
|
154
|
+
type: "image",
|
|
155
|
+
media_item: [
|
|
156
|
+
{ key: "image_other", src: "https://img.test/other.jpg" },
|
|
157
|
+
{ key: "image_base", src: "https://img.test/base.jpg" },
|
|
158
|
+
],
|
|
159
|
+
},
|
|
160
|
+
],
|
|
161
|
+
} as unknown as ZappEntry;
|
|
162
|
+
|
|
163
|
+
expect(player.getContent().imageUrl).toBe("https://img.test/base.jpg");
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("falls back to the first media item when there is no image_base", () => {
|
|
167
|
+
const player = makePlayer();
|
|
168
|
+
|
|
169
|
+
player.entry = {
|
|
170
|
+
title: "Entry Title",
|
|
171
|
+
media_group: [
|
|
172
|
+
{
|
|
173
|
+
type: "image",
|
|
174
|
+
media_item: [
|
|
175
|
+
{ key: "image_other", src: "https://img.test/other.jpg" },
|
|
176
|
+
],
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
} as unknown as ZappEntry;
|
|
180
|
+
|
|
181
|
+
expect(player.getContent().imageUrl).toBe("https://img.test/other.jpg");
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("has no image when the entry carries no media group", () => {
|
|
185
|
+
const player = makePlayer();
|
|
186
|
+
|
|
187
|
+
player.entry = ENTRY;
|
|
188
|
+
|
|
189
|
+
expect(player.getContent().imageUrl).toBeUndefined();
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
it("takes the cover image from the live entry, not the channel", () => {
|
|
193
|
+
// The programme's own artwork has to travel with its title - otherwise the
|
|
194
|
+
// lock screen would keep showing the channel's cover all day.
|
|
195
|
+
const player = makePlayer();
|
|
196
|
+
|
|
197
|
+
player.entry = {
|
|
198
|
+
title: "Channel",
|
|
199
|
+
media_group: [
|
|
200
|
+
{
|
|
201
|
+
type: "image",
|
|
202
|
+
media_item: [
|
|
203
|
+
{ key: "image_base", src: "https://img.test/channel.jpg" },
|
|
204
|
+
],
|
|
205
|
+
},
|
|
206
|
+
],
|
|
207
|
+
} as unknown as ZappEntry;
|
|
208
|
+
|
|
209
|
+
withLiveEntry(player, {
|
|
210
|
+
title: "Programme",
|
|
211
|
+
media_group: [
|
|
212
|
+
{
|
|
213
|
+
type: "image",
|
|
214
|
+
media_item: [
|
|
215
|
+
{ key: "image_base", src: "https://img.test/programme.jpg" },
|
|
216
|
+
],
|
|
217
|
+
},
|
|
218
|
+
],
|
|
219
|
+
} as unknown as ZappEntry);
|
|
220
|
+
|
|
221
|
+
expect(player.getContent().imageUrl).toBe("https://img.test/programme.jpg");
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
it("publishes the observer's live entry to subscribers", () => {
|
|
225
|
+
const player = makePlayer();
|
|
226
|
+
const received: any[] = [];
|
|
227
|
+
|
|
228
|
+
player.entry = ENTRY;
|
|
229
|
+
|
|
230
|
+
player
|
|
231
|
+
.getContentObservable()
|
|
232
|
+
.subscribe((content) => received.push(content));
|
|
233
|
+
|
|
234
|
+
withLiveEntry(player, LIVE_ENTRY);
|
|
235
|
+
player.publishContent();
|
|
236
|
+
|
|
237
|
+
expect(received[received.length - 1].title).toBe("Live Title");
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it("does not resolve while no subscriber exists", () => {
|
|
241
|
+
const player = makePlayer();
|
|
242
|
+
const getConfiguration = jest.fn(() => null);
|
|
243
|
+
|
|
244
|
+
player.getPluginConfiguration = getConfiguration;
|
|
245
|
+
player.entry = ENTRY;
|
|
246
|
+
|
|
247
|
+
expect(getConfiguration).not.toHaveBeenCalled();
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Which Studio key set backs the resolution is decided inside `getContent()`
|
|
253
|
+
* (via `getPlayerContentDataKeys`). Getting it wrong would make one platform
|
|
254
|
+
* or content type read another's Studio configuration, so each combination is
|
|
255
|
+
* pinned here - including the negative cases that prove the sets never cross.
|
|
256
|
+
*
|
|
257
|
+
* These moved here from `PlayerContainer.test.tsx` when the resolution moved
|
|
258
|
+
* out of the React tree and into the player; the assertions are unchanged.
|
|
259
|
+
*/
|
|
260
|
+
describe("Player content channel: key-set selection", () => {
|
|
261
|
+
const VIDEO_ENTRY = {
|
|
262
|
+
id: "video-entry",
|
|
263
|
+
title: "Entry Title",
|
|
264
|
+
summary: "Entry Summary",
|
|
265
|
+
content: { src: "https://example.com/video.m3u8" },
|
|
266
|
+
extensions: { customTitleKey: "Custom Title From Extensions" },
|
|
267
|
+
} as unknown as ZappEntry;
|
|
268
|
+
|
|
269
|
+
const AUDIO_ENTRY = {
|
|
270
|
+
id: "audio-entry",
|
|
271
|
+
title: "Entry Title",
|
|
272
|
+
summary: "Entry Summary",
|
|
273
|
+
content: { type: "audio", src: "https://example.com/audio.m3u8" },
|
|
274
|
+
extensions: { customTitleKey: "Custom Audio Title From Extensions" },
|
|
275
|
+
} as unknown as ZappEntry;
|
|
276
|
+
|
|
277
|
+
const contentFor = (
|
|
278
|
+
entry: ZappEntry,
|
|
279
|
+
configuration: Record<string, any> | null
|
|
280
|
+
) => {
|
|
281
|
+
const player = makePlayer(configuration);
|
|
282
|
+
|
|
283
|
+
player.entry = entry;
|
|
284
|
+
|
|
285
|
+
return player.getContent();
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
describe("TV video", () => {
|
|
289
|
+
beforeEach(() => mockIsTV.mockReturnValue(true));
|
|
290
|
+
|
|
291
|
+
it("resolves the TV video override to the configured extensions key", () => {
|
|
292
|
+
const content = contentFor(VIDEO_ENTRY, {
|
|
293
|
+
video_player_title_data_key_source: "other",
|
|
294
|
+
video_player_title_custom_data_key: "extensions.customTitleKey",
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
expect(content.title).toBe("Custom Title From Extensions");
|
|
298
|
+
// summary was not overridden, so it keeps falling back to entry.summary.
|
|
299
|
+
expect(content.summary).toBe("Entry Summary");
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it("falls back to the entry title when the configured key does not resolve", () => {
|
|
303
|
+
const content = contentFor(VIDEO_ENTRY, {
|
|
304
|
+
video_player_title_data_key_source: "other",
|
|
305
|
+
video_player_title_custom_data_key: "extensions.doesNotExist",
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
expect(content.title).toBe("Entry Title");
|
|
309
|
+
});
|
|
310
|
+
|
|
311
|
+
it("ignores mobile configuration", () => {
|
|
312
|
+
const content = contentFor(VIDEO_ENTRY, {
|
|
313
|
+
title_data_key_source: "other",
|
|
314
|
+
title_custom_data_key: "extensions.customTitleKey",
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
expect(content.title).toBe("Entry Title");
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
it("reads the TV video key set, not the mobile one, when both are configured", () => {
|
|
321
|
+
const content = contentFor(VIDEO_ENTRY, {
|
|
322
|
+
video_player_title_data_key_source: "other",
|
|
323
|
+
video_player_title_custom_data_key: "extensions.customTitleKey",
|
|
324
|
+
// A mobile key is also configured, to prove the TV branch ignores it.
|
|
325
|
+
title_data_key_source: "other",
|
|
326
|
+
title_custom_data_key: "extensions.doesNotExist",
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
expect(content.title).toBe("Custom Title From Extensions");
|
|
330
|
+
});
|
|
331
|
+
|
|
332
|
+
it("passes the entry fields through when nothing is configured", () => {
|
|
333
|
+
const content = contentFor(VIDEO_ENTRY, {});
|
|
334
|
+
|
|
335
|
+
expect(content.title).toBe("Entry Title");
|
|
336
|
+
expect(content.summary).toBe("Entry Summary");
|
|
337
|
+
});
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
describe("TV audio", () => {
|
|
341
|
+
beforeEach(() => mockIsTV.mockReturnValue(true));
|
|
342
|
+
|
|
343
|
+
it("reads the TV audio key set, not the TV video one", () => {
|
|
344
|
+
const content = contentFor(AUDIO_ENTRY, {
|
|
345
|
+
audio_player_title_data_key_source: "other",
|
|
346
|
+
audio_player_title_custom_data_key: "extensions.customTitleKey",
|
|
347
|
+
// Configuring the TV *video* key too, to prove TV audio content reads
|
|
348
|
+
// its own key family instead.
|
|
349
|
+
video_player_title_data_key_source: "other",
|
|
350
|
+
video_player_title_custom_data_key: "extensions.doesNotExist",
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
expect(content.title).toBe("Custom Audio Title From Extensions");
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
it("falls back to the entry fields when nothing is configured", () => {
|
|
357
|
+
const content = contentFor(AUDIO_ENTRY, {});
|
|
358
|
+
|
|
359
|
+
expect(content.title).toBe("Entry Title");
|
|
360
|
+
expect(content.summary).toBe("Entry Summary");
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
describe("mobile", () => {
|
|
365
|
+
beforeEach(() => mockIsTV.mockReturnValue(false));
|
|
366
|
+
|
|
367
|
+
it("resolves the default (mobile) key set", () => {
|
|
368
|
+
const content = contentFor(VIDEO_ENTRY, {
|
|
369
|
+
title_data_key_source: "other",
|
|
370
|
+
title_custom_data_key: "extensions.customTitleKey",
|
|
371
|
+
});
|
|
372
|
+
|
|
373
|
+
expect(content.title).toBe("Custom Title From Extensions");
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
it("ignores TV video configuration", () => {
|
|
377
|
+
const content = contentFor(VIDEO_ENTRY, {
|
|
378
|
+
video_player_title_data_key_source: "other",
|
|
379
|
+
video_player_title_custom_data_key: "extensions.customTitleKey",
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
expect(content.title).toBe("Entry Title");
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
it("shares one key set between video and audio", () => {
|
|
386
|
+
const content = contentFor(AUDIO_ENTRY, {
|
|
387
|
+
title_data_key_source: "other",
|
|
388
|
+
title_custom_data_key: "extensions.customTitleKey",
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
expect(content.title).toBe("Custom Audio Title From Extensions");
|
|
392
|
+
});
|
|
393
|
+
|
|
394
|
+
it("ignores TV audio configuration for mobile audio", () => {
|
|
395
|
+
const content = contentFor(AUDIO_ENTRY, {
|
|
396
|
+
audio_player_title_data_key_source: "other",
|
|
397
|
+
audio_player_title_custom_data_key: "extensions.customTitleKey",
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
expect(content.title).toBe("Entry Title");
|
|
401
|
+
});
|
|
402
|
+
});
|
|
403
|
+
});
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { renderHook, act } from "@testing-library/react-native";
|
|
2
|
+
import { BehaviorSubject } from "rxjs";
|
|
3
|
+
|
|
4
|
+
import { usePlayerContent } from "../usePlayerContent";
|
|
5
|
+
|
|
6
|
+
const mockPlayer: any = {
|
|
7
|
+
subject: null as BehaviorSubject<any> | null,
|
|
8
|
+
getContent: jest.fn(),
|
|
9
|
+
getContentObservable: jest.fn(),
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
jest.mock("../usePlayer", () => ({
|
|
13
|
+
usePlayer: () => mockPlayer,
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
describe("usePlayerContent", () => {
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
mockPlayer.subject = new BehaviorSubject({
|
|
19
|
+
title: "First Title",
|
|
20
|
+
summary: "First Summary",
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
mockPlayer.getContent = jest.fn(() => mockPlayer.subject.getValue());
|
|
24
|
+
|
|
25
|
+
mockPlayer.getContentObservable = jest.fn(() =>
|
|
26
|
+
mockPlayer.subject.asObservable()
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("returns the player's current content", () => {
|
|
31
|
+
const { result } = renderHook(() => usePlayerContent());
|
|
32
|
+
|
|
33
|
+
expect(result.current).toEqual({
|
|
34
|
+
title: "First Title",
|
|
35
|
+
summary: "First Summary",
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("re-renders when the player publishes new content", () => {
|
|
40
|
+
const { result } = renderHook(() => usePlayerContent());
|
|
41
|
+
|
|
42
|
+
act(() => {
|
|
43
|
+
mockPlayer.subject.next({
|
|
44
|
+
title: "Second Title",
|
|
45
|
+
summary: "Second Summary",
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
expect(result.current).toEqual({
|
|
50
|
+
title: "Second Title",
|
|
51
|
+
summary: "Second Summary",
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("unsubscribes on unmount", () => {
|
|
56
|
+
const { unmount } = renderHook(() => usePlayerContent());
|
|
57
|
+
|
|
58
|
+
expect(mockPlayer.subject.observed).toBe(true);
|
|
59
|
+
|
|
60
|
+
unmount();
|
|
61
|
+
|
|
62
|
+
expect(mockPlayer.subject.observed).toBe(false);
|
|
63
|
+
});
|
|
64
|
+
});
|