@applicaster/zapp-react-native-utils 16.0.0-rc.12 → 16.0.0-rc.120
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/actionUtils/index.ts +3 -1
- package/actionsExecutor/ActionExecutor.ts +57 -12
- package/actionsExecutor/ActionExecutorContext.tsx +113 -314
- package/actionsExecutor/__tests__/ActionExecutor.test.ts +71 -0
- package/actionsExecutor/__tests__/feedDecorator.test.ts +61 -0
- package/actionsExecutor/actions/__tests__/dismissBottomSheet.test.ts +25 -0
- package/actionsExecutor/actions/__tests__/goBack.test.ts +62 -0
- package/actionsExecutor/actions/__tests__/goHome.test.ts +19 -0
- package/actionsExecutor/actions/__tests__/loadItemsFromSource.test.ts +88 -0
- package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +267 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +100 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +300 -0
- package/actionsExecutor/actions/__tests__/presentScreen.test.ts +127 -0
- package/actionsExecutor/actions/__tests__/showAlert.test.ts +49 -0
- package/actionsExecutor/actions/__tests__/showToast.test.ts +88 -0
- package/actionsExecutor/actions/appRestart.ts +24 -0
- package/actionsExecutor/actions/confirmDialog.ts +53 -0
- package/actionsExecutor/actions/dismissBottomSheet.ts +23 -0
- package/actionsExecutor/actions/goBack.ts +60 -0
- package/actionsExecutor/actions/goHome.ts +31 -0
- package/actionsExecutor/actions/index.ts +42 -0
- package/actionsExecutor/actions/localStorageRemove.ts +27 -0
- package/actionsExecutor/actions/localStorageSet.ts +28 -0
- package/actionsExecutor/actions/localStorageToggleFlag.ts +28 -0
- package/actionsExecutor/actions/navigateToScreen.ts +121 -0
- package/actionsExecutor/actions/openBottomSheet.ts +339 -0
- package/actionsExecutor/actions/presentScreen.ts +78 -0
- package/actionsExecutor/actions/refreshComponent.ts +85 -0
- package/actionsExecutor/actions/screenSetVariable.ts +35 -0
- package/actionsExecutor/actions/screenToggleFlag.ts +38 -0
- package/actionsExecutor/actions/sendCloudEvent.ts +93 -0
- package/actionsExecutor/actions/sessionStorageRemove.ts +19 -0
- package/actionsExecutor/actions/sessionStorageSet.ts +20 -0
- package/actionsExecutor/actions/sessionStorageToggleFlag.ts +15 -0
- package/actionsExecutor/actions/showAlert.ts +51 -0
- package/actionsExecutor/actions/showToast.ts +87 -0
- package/actionsExecutor/actions/switchLayout.ts +40 -0
- package/actionsExecutor/consts.ts +27 -0
- package/actionsExecutor/feedDecorator.ts +6 -6
- package/actionsExecutor/types.ts +59 -0
- package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -2
- package/analyticsUtils/PlayerAnalyticsManager.ts +12 -2
- package/analyticsUtils/__tests__/analyticsMapper.test.ts +35 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testACP_events.json +1 -1
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testBlockUnlistedParams_rules.json +1 -1
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEmptyRenameKeepsName_events.json +4 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEmptyRenameKeepsName_rules.json +6 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testEventRegex_events.json +3 -9
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testIgnoreOrdering_events.json +18 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testIgnoreOrdering_rules.json +16 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexEventNoFallback_events.json +4 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexEventNoFallback_rules.json +6 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexMultiGroupRename_events.json +4 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexMultiGroupRename_rules.json +6 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexNonNamedFullMatch_events.json +4 -0
- package/analyticsUtils/__tests__/fixtures/analytics_mapper_testRegexNonNamedFullMatch_rules.json +6 -0
- package/analyticsUtils/__tests__/fixtures/index.js +20 -0
- package/analyticsUtils/analyticsMapper.ts +4 -1
- package/analyticsUtils/playerAnalyticsTracker.ts +26 -3
- package/appUtils/HooksManager/index.ts +9 -0
- package/appUtils/contextKeysManager/__tests__/getKey/failure.test.ts +1 -1
- package/appUtils/contextKeysManager/__tests__/removeKey/failure.test.ts +1 -1
- package/appUtils/contextKeysManager/__tests__/setKey/failure/invalidKey.test.ts +4 -4
- package/appUtils/contextKeysManager/index.ts +1 -1
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +142 -59
- package/appUtils/playerManager/OverlayObserver/__tests__/getUpcomingQueue.test.ts +67 -0
- package/appUtils/playerManager/OverlayObserver/__tests__/liveContent.test.ts +205 -0
- package/appUtils/playerManager/OverlayObserver/__tests__/utils.test.ts +56 -0
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.android.tv.ts +4 -0
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ios.tv.ts +4 -0
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.ts +24 -0
- package/appUtils/playerManager/OverlayObserver/getUpcomingQueue.web.ts +4 -0
- package/appUtils/playerManager/OverlayObserver/utils.ts +51 -20
- package/appUtils/playerManager/__tests__/playerContent.test.ts +403 -0
- package/appUtils/playerManager/__tests__/playerFactory.test.ts +1 -1
- package/appUtils/playerManager/__tests__/playerNative.test.ts +114 -0
- package/appUtils/playerManager/__tests__/playerNativeCommand.test.ts +62 -0
- package/appUtils/playerManager/__tests__/playerToolbox.test.ts +97 -0
- package/appUtils/playerManager/__tests__/usePlayerContent.test.tsx +64 -0
- package/appUtils/playerManager/__tests__/usePlayerControllerSetup.test.tsx +62 -0
- package/appUtils/playerManager/{conts.ts → const.ts} +33 -0
- package/appUtils/playerManager/index.ts +8 -1
- package/appUtils/playerManager/player.ts +125 -3
- package/appUtils/playerManager/playerFactory.ts +1 -1
- package/appUtils/playerManager/playerNative.ts +28 -4
- package/appUtils/playerManager/playerNativeCommand.ts +3 -6
- package/appUtils/playerManager/playerToolbox.ts +157 -0
- package/appUtils/playerManager/usePlayerContent.tsx +43 -0
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +7 -1
- package/appUtils/playerManager/userLanguagePreference.ts +1 -1
- package/arrayUtils/__tests__/{anyThruthy.test.ts → anyTruthy.test.ts} +8 -0
- package/arrayUtils/__tests__/arrayUtils.test.ts +165 -108
- package/arrayUtils/__tests__/isEmptyArray.test.ts +11 -0
- package/arrayUtils/__tests__/isFilledArray.test.ts +12 -0
- package/arrayUtils/__tests__/isFirst.test.ts +17 -0
- package/arrayUtils/__tests__/isIndexInRange.test.ts +14 -0
- package/arrayUtils/__tests__/isLast.test.ts +31 -0
- package/arrayUtils/__tests__/makeListOf.test.ts +31 -0
- package/arrayUtils/__tests__/makeListOfIndexes.test.ts +20 -0
- package/arrayUtils/__tests__/reorderByIds.test.ts +63 -0
- package/arrayUtils/__tests__/sample.test.ts +61 -0
- package/arrayUtils/index.ts +119 -20
- package/bottomSheet/__tests__/scrollContext.test.tsx +35 -0
- package/bottomSheet/index.ts +17 -0
- package/cellUtils/__tests__/getButtonsEnabled.test.ts +28 -0
- package/cellUtils/__tests__/getCellNavigationEnabled.test.ts +36 -0
- package/cellUtils/__tests__/getIsCellNavigationEnabled.test.ts +35 -0
- package/cellUtils/__tests__/isCellNavigationEnabled.test.ts +21 -0
- package/cellUtils/index.ts +73 -8
- package/colorUtils/__tests__/isTransparentColor.test.ts +76 -0
- package/colorUtils/__tests__/isValidColor.test.ts +70 -0
- package/colorUtils/index.ts +50 -0
- package/configurationUtils/__tests__/manifestKeyParser.test.ts +21 -0
- package/configurationUtils/__tests__/modalBlocksParser.test.ts +392 -0
- package/configurationUtils/manifestKeyParser.ts +50 -10
- package/configurationUtils/modalBlocksParser.ts +252 -0
- package/entryActions/__tests__/buildEntryActions.test.ts +235 -0
- package/entryActions/aliasPresentation.ts +108 -0
- package/entryActions/buildEntryActions.ts +167 -0
- package/entryActions/index.ts +15 -0
- package/entryActions/types.ts +39 -0
- package/focusManager/FocusManager.ts +26 -0
- package/focusManager/__tests__/FocusManager.test.ts +9 -0
- package/localizationUtils/index.ts +12 -6
- package/logger/__tests__/xrayToolbox.test.ts +69 -0
- package/logger/xrayToolbox.ts +67 -0
- package/manifestUtils/__tests__/player.audioControls.test.js +158 -0
- package/manifestUtils/_internals/index.js +14 -3
- package/manifestUtils/defaultManifestConfigurations/generalContent.js +41 -0
- package/manifestUtils/defaultManifestConfigurations/player.js +357 -20
- package/manifestUtils/fieldUtils/__tests__/fieldUtils.test.js +84 -0
- package/manifestUtils/fieldUtils/index.js +125 -0
- package/manifestUtils/index.js +3 -0
- package/manifestUtils/keys.js +15 -1
- package/manifestUtils/mobileAction/button/index.js +16 -0
- package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +21 -0
- package/manifestUtils/mobileAction/container/index.js +3 -1
- package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +1 -1
- package/manifestUtils/mobileAction/groups/defaults.js +5 -2
- package/manifestUtils/modalBlocks.js +304 -0
- package/manifestUtils/platformIsTV.js +1 -0
- package/modalState/ContentViewModel.ts +113 -0
- package/modalState/EditableCollection.ts +17 -0
- package/modalState/EditableCollectionRegistry.ts +51 -0
- package/modalState/ModalOrchestrator.ts +212 -0
- package/modalState/RemoteEditableCollection.ts +235 -0
- package/modalState/__tests__/ContentViewModel.editable.test.ts +69 -0
- package/modalState/__tests__/ContentViewModel.test.ts +165 -0
- package/modalState/__tests__/EditableCollectionRegistry.test.ts +112 -0
- package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +63 -0
- package/modalState/__tests__/RemoteEditableCollection.test.ts +415 -0
- package/modalState/__tests__/index.test.ts +30 -1
- package/modalState/__tests__/useBottomSheetContent.test.ts +349 -0
- package/modalState/__tests__/useModalStoreState.test.ts +142 -0
- package/modalState/index.ts +35 -83
- package/modalState/store.ts +109 -0
- package/modalState/types.ts +162 -0
- package/modalState/useBottomSheetContent.ts +109 -0
- package/navigationUtils/xrayNavigator.ts +12 -0
- package/numberUtils/__tests__/isMinusZero.test.ts +20 -0
- package/numberUtils/__tests__/isZero.test.ts +27 -0
- package/numberUtils/__tests__/requireNumber.test.ts +50 -0
- package/numberUtils/__tests__/toNumber.test.ts +27 -0
- package/numberUtils/__tests__/toNumberWithDefault.test.ts +64 -0
- package/numberUtils/__tests__/toNumberWithDefaultZero.test.ts +48 -0
- package/numberUtils/index.ts +27 -8
- package/package.json +2 -2
- package/pipesUtils/__tests__/buildUrlWithQuery.test.ts +33 -0
- package/pipesUtils/__tests__/withPipesEndpoint.test.tsx +56 -0
- package/pipesUtils/index.ts +1 -0
- package/pipesUtils/withPipesEndpoint.tsx +54 -0
- package/playerUtils/__tests__/contentDataKeys.test.ts +297 -0
- package/playerUtils/__tests__/resolvePlayerActions.test.ts +138 -0
- package/playerUtils/__tests__/resolvePlayerTitleSubtitle.test.ts +180 -0
- package/playerUtils/contentDataKeys.ts +134 -0
- package/playerUtils/index.ts +37 -16
- package/playerUtils/isAudioItem.ts +26 -0
- package/playerUtils/resolvePlayerActions.ts +71 -0
- package/playerUtils/resolvePlayerTitleSubtitle.ts +76 -0
- package/pluginUtils/__tests__/pluginUtils.test.js +32 -0
- package/pluginUtils/index.ts +29 -0
- package/reactHooks/__tests__/getPluginConfiguration.test.ts +82 -0
- package/reactHooks/actions/index.ts +117 -2
- package/reactHooks/cell-click/__tests__/index.test.js +64 -0
- package/reactHooks/cell-click/index.ts +39 -24
- package/reactHooks/connection/index.tsx +8 -5
- package/reactHooks/feed/__mocks__/useMarkPipesDataStale.ts +4 -0
- package/reactHooks/feed/__tests__/useInflatedUrl.test.tsx +25 -0
- package/reactHooks/feed/__tests__/useMarkPipesDataStale.test.tsx +243 -0
- package/reactHooks/feed/index.ts +5 -1
- package/reactHooks/feed/useBatchLoading.ts +9 -1
- package/reactHooks/feed/useMarkPipesDataStale.ts +97 -0
- package/reactHooks/index.ts +2 -0
- package/reactHooks/layout/index.ts +1 -1
- package/reactHooks/navigation/__mocks__/index.ts +4 -0
- package/reactHooks/navigation/__tests__/index.test.tsx +176 -1
- package/reactHooks/navigation/__tests__/useIsScreenActive.test.ts +42 -0
- package/reactHooks/navigation/__tests__/usePresentScreen.test.ts +154 -0
- package/reactHooks/navigation/index.ts +3 -1
- package/reactHooks/navigation/useIsScreenActive.ts +29 -8
- package/reactHooks/navigation/usePresentScreen.ts +157 -0
- package/reactHooks/navigation/useRoute.ts +22 -5
- package/reactHooks/state/useComponentScreenState.ts +1 -1
- package/reactHooks/usePluginConfiguration.ts +88 -47
- package/reactHooks/utils/__tests__/index.test.js +22 -2
- package/reactHooks/utils/index.ts +13 -2
- package/riverComponetsMeasurementProvider/index.tsx +15 -9
- package/stringUtils/__tests__/stringUtils.test.js +42 -0
- package/stringUtils/index.ts +2 -2
- package/uiActionsRegistrator/__tests__/resolveActionIdentifiers.test.ts +93 -0
- package/uiActionsRegistrator/__tests__/subscribe.test.ts +133 -0
- package/uiActionsRegistrator/__tests__/usableActionItems.test.ts +52 -0
- package/uiActionsRegistrator/index.ts +25 -0
- package/uiActionsRegistrator/registry.ts +351 -0
- package/uiActionsRegistrator/resolveActionIdentifiers.ts +100 -0
- package/uiActionsRegistrator/usableActionItems.ts +66 -0
- package/zappFrameworkUtils/__tests__/localStorageHelper.test.ts +146 -0
- package/zappFrameworkUtils/localStorageHelper.ts +19 -15
- package/appUtils/playerManager/usePlayerTitleSummaryOverlay.tsx +0 -56
- package/playerUtils/__tests__/getPlayerActionButtons.test.ts +0 -54
- package/playerUtils/getPlayerActionButtons.ts +0 -17
- package/reactHooks/feed/__mocks__/usePipesCacheReset.ts +0 -1
- package/reactHooks/feed/usePipesCacheReset.ts +0 -44
- /package/reactHooks/actions/__tests__/{index.test.js → index.test.tsx} +0 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { registerXrayToolbox, XrayToolSpec } from "../../logger/xrayToolbox";
|
|
2
|
+
import type { PlayerManager } from "./index";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* X-Ray `player.*` toolbox: lets an agent read and drive the active player without screenshots.
|
|
6
|
+
* Registered by the PlayerManager singleton itself, so it exists wherever players do. Skipped
|
|
7
|
+
* when the installed X-Ray plugin has no React toolbox API.
|
|
8
|
+
*
|
|
9
|
+
* How the player is shown (video modal mode, mini player) is navigation state: see `nav.*`.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const toNumber = (value: unknown) =>
|
|
13
|
+
typeof value === "number" && Number.isFinite(value) ? value : null;
|
|
14
|
+
|
|
15
|
+
const clamp = (value: number, max: number) => Math.min(Math.max(value, 0), max);
|
|
16
|
+
|
|
17
|
+
/** The range a seek can reach: the DVR window on live, the content on VOD. */
|
|
18
|
+
const requireSeekable = (player: {
|
|
19
|
+
getSeekableDuration: () => number | undefined;
|
|
20
|
+
}) => {
|
|
21
|
+
const seekable = toNumber(player.getSeekableDuration());
|
|
22
|
+
|
|
23
|
+
if (!seekable) throw new Error("Seek is not supported");
|
|
24
|
+
|
|
25
|
+
return seekable;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const tools = (manager: PlayerManager): XrayToolSpec[] => {
|
|
29
|
+
const requirePlayer = () => {
|
|
30
|
+
const player = manager.getActivePlayer();
|
|
31
|
+
|
|
32
|
+
if (!player) throw new Error("No active player");
|
|
33
|
+
|
|
34
|
+
return player;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
return [
|
|
38
|
+
{
|
|
39
|
+
name: "state",
|
|
40
|
+
description:
|
|
41
|
+
"The active player: entry, position and duration in seconds, playing/buffering/ad/live/muted, " +
|
|
42
|
+
"role (Primary, Cell, Chromecast) and casting. active: false when nothing plays.",
|
|
43
|
+
handler: () => {
|
|
44
|
+
const player = manager.getActivePlayer();
|
|
45
|
+
|
|
46
|
+
if (!player) return { active: false, casting: manager.isCasting() };
|
|
47
|
+
|
|
48
|
+
const entry = player.getEntry();
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
active: true,
|
|
52
|
+
playerId: player.playerId,
|
|
53
|
+
entry: entry ? { id: entry.id, title: entry.title } : null,
|
|
54
|
+
position: toNumber(player.getPosition()),
|
|
55
|
+
duration: toNumber(player.getDuration()),
|
|
56
|
+
// isPlaying() only means "not paused", which is also true before the stream starts.
|
|
57
|
+
playing: !!player.isReadyToPlay() && player.isPlaying(),
|
|
58
|
+
buffering: !!player.isBuffering(),
|
|
59
|
+
readyToPlay: !!player.isReadyToPlay(),
|
|
60
|
+
ad: player.isAd(),
|
|
61
|
+
live: !!player.isLive(),
|
|
62
|
+
muted: !!player.getIsMuted(),
|
|
63
|
+
role: player.playerRole,
|
|
64
|
+
casting: manager.isCasting(),
|
|
65
|
+
};
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: "play",
|
|
70
|
+
description: "Resume the active player.",
|
|
71
|
+
handler: () => {
|
|
72
|
+
requirePlayer().play();
|
|
73
|
+
|
|
74
|
+
return "OK";
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: "pause",
|
|
79
|
+
description: "Pause the active player.",
|
|
80
|
+
handler: () => {
|
|
81
|
+
requirePlayer().pause();
|
|
82
|
+
|
|
83
|
+
return "OK";
|
|
84
|
+
},
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: "seek",
|
|
88
|
+
description:
|
|
89
|
+
"Seek to an absolute position, as the player's console command does: seconds from the start, " +
|
|
90
|
+
"or from the end when negative. Clamped to the seekable range. Where it lands can differ: " +
|
|
91
|
+
"server-side ads snap back to the break before the target; read player.state afterwards.",
|
|
92
|
+
parameters: [
|
|
93
|
+
{
|
|
94
|
+
name: "position",
|
|
95
|
+
type: "number",
|
|
96
|
+
description:
|
|
97
|
+
"Seconds from the start; negative values count back from the end.",
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
handler: ({ position }) => {
|
|
101
|
+
const player = requirePlayer();
|
|
102
|
+
const seconds = toNumber(position);
|
|
103
|
+
|
|
104
|
+
if (seconds === null) {
|
|
105
|
+
throw new Error("'position' must be a number of seconds");
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const seekable = requireSeekable(player);
|
|
109
|
+
|
|
110
|
+
const target =
|
|
111
|
+
seconds >= 0
|
|
112
|
+
? Math.min(seconds, seekable)
|
|
113
|
+
: clamp(seekable + seconds, seekable);
|
|
114
|
+
|
|
115
|
+
player.seekTo(target);
|
|
116
|
+
|
|
117
|
+
return { position: target };
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: "offset",
|
|
122
|
+
description:
|
|
123
|
+
"Seek relative to the current position, as the player's console command does: positive " +
|
|
124
|
+
"forward, negative back. Clamped to the seekable range.",
|
|
125
|
+
parameters: [
|
|
126
|
+
{
|
|
127
|
+
name: "seconds",
|
|
128
|
+
type: "number",
|
|
129
|
+
description: "Seconds to move: positive forward, negative back.",
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
handler: ({ seconds }) => {
|
|
133
|
+
const player = requirePlayer();
|
|
134
|
+
const delta = toNumber(seconds);
|
|
135
|
+
|
|
136
|
+
if (delta === null) throw new Error("'seconds' must be a number");
|
|
137
|
+
|
|
138
|
+
if (delta === 0) throw new Error("Ignored zero relative seek");
|
|
139
|
+
|
|
140
|
+
const seekable = requireSeekable(player);
|
|
141
|
+
const from = toNumber(player.getContentPosition()) ?? 0;
|
|
142
|
+
const target = clamp(from + delta, seekable);
|
|
143
|
+
|
|
144
|
+
player.seekTo(target);
|
|
145
|
+
|
|
146
|
+
return { from, position: target };
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
];
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
export const registerPlayerToolbox = (manager: PlayerManager) =>
|
|
153
|
+
registerXrayToolbox({
|
|
154
|
+
name: "player",
|
|
155
|
+
description: "Inspect and control the active player.",
|
|
156
|
+
tools: tools(manager),
|
|
157
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { Player, PlayerContent } from "./player";
|
|
3
|
+
import { usePlayer } from "./usePlayer";
|
|
4
|
+
|
|
5
|
+
const EMPTY_CONTENT: PlayerContent = {
|
|
6
|
+
title: null,
|
|
7
|
+
summary: null,
|
|
8
|
+
imageUrl: null,
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Subscribes to the player's resolved Title/Subtitle, the same way
|
|
13
|
+
* `usePlayerState` subscribes to playback state. Modeled on that hook
|
|
14
|
+
* deliberately: one React bridge pattern for everything the manager publishes.
|
|
15
|
+
*
|
|
16
|
+
* Passing no `playerId` uses the active player, which is the right default -
|
|
17
|
+
* only one player instance is live at a time. `usePlayer` additionally swaps
|
|
18
|
+
* to the casting receiver while casting, so this follows cast handover
|
|
19
|
+
* automatically.
|
|
20
|
+
*/
|
|
21
|
+
export const usePlayerContent = (playerId?: string): PlayerContent => {
|
|
22
|
+
const player: Player = usePlayer(playerId);
|
|
23
|
+
|
|
24
|
+
const [content, setContent] = React.useState<PlayerContent>(
|
|
25
|
+
() => player?.getContent() ?? EMPTY_CONTENT
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
React.useEffect(() => {
|
|
29
|
+
if (!player) {
|
|
30
|
+
setContent(EMPTY_CONTENT);
|
|
31
|
+
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const subscription = player
|
|
36
|
+
.getContentObservable()
|
|
37
|
+
.subscribe((next) => setContent(next));
|
|
38
|
+
|
|
39
|
+
return () => subscription.unsubscribe();
|
|
40
|
+
}, [player]);
|
|
41
|
+
|
|
42
|
+
return content;
|
|
43
|
+
};
|
|
@@ -3,11 +3,12 @@ import { useConfiguration } from "../../reactHooks/useConfiguration";
|
|
|
3
3
|
import { useEffect } from "react";
|
|
4
4
|
import { playerManager } from "./index";
|
|
5
5
|
import { useValidatePlayerConfig } from "../../playerUtils/useValidatePlayerConfig";
|
|
6
|
-
import { PlayerRole } from "./
|
|
6
|
+
import { PlayerRole } from "./const";
|
|
7
7
|
import { isAppleTV } from "@applicaster/zapp-react-native-ui-components/Helpers/Platform";
|
|
8
8
|
import { TVSeekController } from "../../reactHooks/player/TVSeekControlller/TVSeekController";
|
|
9
9
|
import { KeyInputHandler } from "../keyInputHandler/KeyInputHandler";
|
|
10
10
|
import { isTV } from "../../reactUtils";
|
|
11
|
+
import { PlayerAnalyticsManager } from "../../analyticsUtils/PlayerAnalyticsManager";
|
|
11
12
|
|
|
12
13
|
// TODO: Rename to ControllerType
|
|
13
14
|
export const usePlayerControllerSetup = ({
|
|
@@ -68,6 +69,11 @@ export const usePlayerControllerSetup = ({
|
|
|
68
69
|
return;
|
|
69
70
|
}
|
|
70
71
|
|
|
72
|
+
// The analytics manager attaches its listener when a player registers, so it
|
|
73
|
+
// must exist first; on web the Player wrapper that also creates it renders
|
|
74
|
+
// only after the lazily loaded engine chunk, i.e. after registration.
|
|
75
|
+
PlayerAnalyticsManager.getInstance();
|
|
76
|
+
|
|
71
77
|
playerManager.registerPlayer({
|
|
72
78
|
id: playerId,
|
|
73
79
|
playerController,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { localStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/LocalStorage";
|
|
2
2
|
import { sessionStorage } from "@applicaster/zapp-react-native-bridge/ZappStorage/SessionStorage";
|
|
3
3
|
import { createLogger, utilsLogger } from "../../logger";
|
|
4
|
-
import { userPreferencesNamespace } from "./
|
|
4
|
+
import { userPreferencesNamespace } from "./const";
|
|
5
5
|
|
|
6
6
|
export const preferredAudioLanguageStorageKey = "preferred_audio_language";
|
|
7
7
|
|
|
@@ -21,4 +21,12 @@ describe("anyTruthy", () => {
|
|
|
21
21
|
expect(anyTruthy([true])).toBe(true);
|
|
22
22
|
expect(anyTruthy([false])).toBe(false);
|
|
23
23
|
});
|
|
24
|
+
|
|
25
|
+
it("should return true when the first value is true", () => {
|
|
26
|
+
expect(anyTruthy([true, false, false])).toBe(true);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("should return true when only the last value is true", () => {
|
|
30
|
+
expect(anyTruthy([false, false, true])).toBe(true);
|
|
31
|
+
});
|
|
24
32
|
});
|
|
@@ -28,6 +28,30 @@ describe("shiftArray", () => {
|
|
|
28
28
|
expect(shiftArray(negativeOffset, array)).toMatchSnapshot();
|
|
29
29
|
expect(shiftArray(2 * negativeOffset, array)).toMatchSnapshot();
|
|
30
30
|
});
|
|
31
|
+
|
|
32
|
+
it("returns a new array and does not mutate the original", () => {
|
|
33
|
+
const original = ["a", "b", "c"];
|
|
34
|
+
const result = shiftArray(1, original);
|
|
35
|
+
|
|
36
|
+
expect(result).toEqual(["b", "c", "a"]);
|
|
37
|
+
expect(result).not.toBe(original);
|
|
38
|
+
expect(original).toEqual(["a", "b", "c"]);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("returns an empty array when shifting an empty array", () => {
|
|
42
|
+
expect(shiftArray(1, [])).toEqual([]);
|
|
43
|
+
expect(shiftArray(-1, [])).toEqual([]);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("returns the same order for a single-element array", () => {
|
|
47
|
+
expect(shiftArray(1, [1])).toEqual([1]);
|
|
48
|
+
expect(shiftArray(-1, [1])).toEqual([1]);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("handles an offset equal to the array length", () => {
|
|
52
|
+
expect(shiftArray(4, array)).toEqual(array);
|
|
53
|
+
expect(shiftArray(-4, array)).toEqual(array);
|
|
54
|
+
});
|
|
31
55
|
});
|
|
32
56
|
|
|
33
57
|
describe("removeItemFromList", () => {
|
|
@@ -58,6 +82,38 @@ describe("removeItemFromList", () => {
|
|
|
58
82
|
arrayOfObjects
|
|
59
83
|
);
|
|
60
84
|
});
|
|
85
|
+
|
|
86
|
+
it("returns the same reference when the item is not found", () => {
|
|
87
|
+
const list = [1, 2, 3];
|
|
88
|
+
|
|
89
|
+
expect(removeItemFromList(4, list)).toBe(list);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("returns a new array when the item is removed", () => {
|
|
93
|
+
const list = [1, 2, 3];
|
|
94
|
+
const result = removeItemFromList(2, list);
|
|
95
|
+
|
|
96
|
+
expect(result).toEqual([1, 3]);
|
|
97
|
+
expect(result).not.toBe(list);
|
|
98
|
+
expect(list).toEqual([1, 2, 3]);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it("removes only the first occurrence of a duplicate item", () => {
|
|
102
|
+
expect(removeItemFromList(2, [1, 2, 2, 3])).toEqual([1, 2, 3]);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("removes the first and last items", () => {
|
|
106
|
+
expect(removeItemFromList(1, [1, 2, 3])).toEqual([2, 3]);
|
|
107
|
+
expect(removeItemFromList(3, [1, 2, 3])).toEqual([1, 2]);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it("returns an empty list when removing from an empty list", () => {
|
|
111
|
+
expect(removeItemFromList(1, [])).toEqual([]);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("returns an empty list when removing the only item", () => {
|
|
115
|
+
expect(removeItemFromList(1, [1])).toEqual([]);
|
|
116
|
+
});
|
|
61
117
|
});
|
|
62
118
|
|
|
63
119
|
describe("mapPromises", () => {
|
|
@@ -84,145 +140,146 @@ describe("mapPromises", () => {
|
|
|
84
140
|
values.forEach((value) => {
|
|
85
141
|
expect(promiseFn).toHaveBeenNthCalledWith(value, value, value - 1);
|
|
86
142
|
});
|
|
87
|
-
});
|
|
88
143
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const arrayOfPrimitives = [1, 2, 3, 4];
|
|
92
|
-
expect(removeItemFromList(1, arrayOfPrimitives)).toEqual([2, 3, 4]);
|
|
144
|
+
expect.assertions(values.length + 1);
|
|
145
|
+
});
|
|
93
146
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
];
|
|
147
|
+
it("resolves to an empty array for an empty input", async () => {
|
|
148
|
+
await expect(mapPromises(promiseFn, [])).resolves.toEqual([]);
|
|
149
|
+
expect(promiseFn).not.toHaveBeenCalled();
|
|
150
|
+
});
|
|
99
151
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
});
|
|
152
|
+
it("rejects when any promise rejects", async () => {
|
|
153
|
+
const failingFn = jest.fn((num) =>
|
|
154
|
+
num === 2 ? Promise.reject(new Error("fail")) : Promise.resolve(num)
|
|
155
|
+
);
|
|
105
156
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
{ prop: "value2" },
|
|
110
|
-
{ prop: "value3" },
|
|
111
|
-
];
|
|
157
|
+
await expect(mapPromises(failingFn, [1, 2, 3])).rejects.toThrow("fail");
|
|
158
|
+
});
|
|
159
|
+
});
|
|
112
160
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
161
|
+
describe("reducePromises", () => {
|
|
162
|
+
const promiseFn = jest.fn((current, previous, index, cb) => {
|
|
163
|
+
return new Promise((resolve) => {
|
|
164
|
+
setTimeout(() => {
|
|
165
|
+
resolve(previous + current);
|
|
166
|
+
cb?.(index);
|
|
167
|
+
}, 1);
|
|
116
168
|
});
|
|
117
169
|
});
|
|
118
170
|
|
|
119
|
-
|
|
120
|
-
|
|
171
|
+
beforeEach(() => {
|
|
172
|
+
promiseFn.mockClear();
|
|
173
|
+
});
|
|
121
174
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
});
|
|
175
|
+
it("is a curried function; and returns the reduced promise values", async () => {
|
|
176
|
+
const promiseReducer = reducePromises(promiseFn);
|
|
125
177
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
178
|
+
const initialValue = 0;
|
|
179
|
+
const values = [1, 2, 3];
|
|
180
|
+
const sumOfValues = initialValue + values.reduce((a, b) => a + b, 0);
|
|
129
181
|
|
|
130
|
-
|
|
131
|
-
await expect(promiseMapper(values)).resolves.toEqual([2, 3, 4]);
|
|
132
|
-
});
|
|
182
|
+
expect(typeof promiseReducer).toBe("function");
|
|
133
183
|
|
|
134
|
-
|
|
135
|
-
|
|
184
|
+
await expect(promiseReducer(initialValue, values)).resolves.toEqual(
|
|
185
|
+
sumOfValues
|
|
186
|
+
);
|
|
187
|
+
});
|
|
136
188
|
|
|
137
|
-
|
|
138
|
-
|
|
189
|
+
it("calls promises one after the other", (done) => {
|
|
190
|
+
const values = [1, 2, 3];
|
|
191
|
+
const previousValues = [0, 1, 3];
|
|
192
|
+
|
|
193
|
+
reducePromises(
|
|
194
|
+
(current, previous, index) =>
|
|
195
|
+
promiseFn(current, previous, index, (index) => {
|
|
196
|
+
expect(promiseFn).toHaveBeenCalledTimes(index + 1);
|
|
197
|
+
|
|
198
|
+
expect(promiseFn).toHaveBeenNthCalledWith(
|
|
199
|
+
index + 1,
|
|
200
|
+
values[index],
|
|
201
|
+
previousValues[index],
|
|
202
|
+
index,
|
|
203
|
+
expect.any(Function)
|
|
204
|
+
);
|
|
205
|
+
|
|
206
|
+
if (index === 2) done();
|
|
207
|
+
}),
|
|
208
|
+
0,
|
|
209
|
+
values
|
|
210
|
+
);
|
|
139
211
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
});
|
|
212
|
+
expect.assertions(values.length * 2);
|
|
213
|
+
});
|
|
143
214
|
|
|
144
|
-
|
|
145
|
-
|
|
215
|
+
it("returns the initial value for an empty list", async () => {
|
|
216
|
+
await expect(reducePromises(promiseFn, 10, [])).resolves.toBe(10);
|
|
217
|
+
expect(promiseFn).not.toHaveBeenCalled();
|
|
146
218
|
});
|
|
147
219
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
setTimeout(() => {
|
|
152
|
-
resolve(previous + current);
|
|
153
|
-
cb?.(index);
|
|
154
|
-
}, 1);
|
|
155
|
-
});
|
|
156
|
-
});
|
|
220
|
+
it("reduces a single-element list", async () => {
|
|
221
|
+
await expect(reducePromises(promiseFn, 5, [2])).resolves.toBe(7);
|
|
222
|
+
});
|
|
157
223
|
|
|
158
|
-
|
|
159
|
-
|
|
224
|
+
it("rejects when a promise rejects", async () => {
|
|
225
|
+
const failingFn = jest.fn(async (current, previous) => {
|
|
226
|
+
if (current === 2) throw new Error("reduce fail");
|
|
227
|
+
|
|
228
|
+
return previous + current;
|
|
160
229
|
});
|
|
161
230
|
|
|
162
|
-
|
|
163
|
-
|
|
231
|
+
await expect(reducePromises(failingFn, 0, [1, 2, 3])).rejects.toThrow(
|
|
232
|
+
"reduce fail"
|
|
233
|
+
);
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
describe("mapAndSplit", () => {
|
|
238
|
+
it("maps over a list of values and split it in chunks", () => {
|
|
239
|
+
const values = new Array(20).fill(0).map((_, i) => i);
|
|
240
|
+
|
|
241
|
+
const alphabet = Array.from(Array(26)).map((_, i) =>
|
|
242
|
+
String.fromCharCode(i + 65)
|
|
243
|
+
);
|
|
164
244
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
const sumOfValues = initialValue + values.reduce((a, b) => a + b, 0);
|
|
245
|
+
const getLetterForInt = (num) => alphabet[num];
|
|
246
|
+
const chunkSize = 5;
|
|
168
247
|
|
|
169
|
-
|
|
248
|
+
const result = mapAndSplit<number, string>(
|
|
249
|
+
getLetterForInt,
|
|
250
|
+
chunkSize
|
|
251
|
+
)(values);
|
|
170
252
|
|
|
171
|
-
|
|
172
|
-
sumOfValues
|
|
173
|
-
);
|
|
174
|
-
});
|
|
253
|
+
expect(result.length).toBe(values.length / chunkSize);
|
|
175
254
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
reducePromises(
|
|
181
|
-
(current, previous, index) =>
|
|
182
|
-
promiseFn(current, previous, index, (index) => {
|
|
183
|
-
expect(promiseFn).toHaveBeenCalledTimes(index + 1);
|
|
184
|
-
|
|
185
|
-
expect(promiseFn).toHaveBeenNthCalledWith(
|
|
186
|
-
index + 1,
|
|
187
|
-
values[index],
|
|
188
|
-
previousValues[index],
|
|
189
|
-
index,
|
|
190
|
-
expect.any(Function)
|
|
191
|
-
);
|
|
192
|
-
|
|
193
|
-
if (index === 2) done();
|
|
194
|
-
}),
|
|
195
|
-
0,
|
|
196
|
-
values
|
|
197
|
-
);
|
|
198
|
-
|
|
199
|
-
expect.assertions(values.length * 2);
|
|
255
|
+
result.forEach((chunk, chunkIndex) => {
|
|
256
|
+
chunk.forEach((value, index) => {
|
|
257
|
+
expect(value).toBe(alphabet[chunkIndex * chunkSize + index]);
|
|
258
|
+
});
|
|
200
259
|
});
|
|
201
260
|
});
|
|
202
261
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
262
|
+
it("is a curried function", () => {
|
|
263
|
+
const mapper = (n: number) => n * 2;
|
|
264
|
+
const splitBy2 = mapAndSplit(mapper, 2);
|
|
206
265
|
|
|
207
|
-
|
|
208
|
-
String.fromCharCode(i + 65)
|
|
209
|
-
);
|
|
266
|
+
expect(typeof splitBy2).toBe("function");
|
|
210
267
|
|
|
211
|
-
|
|
212
|
-
|
|
268
|
+
expect(splitBy2([1, 2, 3, 4])).toEqual([
|
|
269
|
+
[2, 4],
|
|
270
|
+
[6, 8],
|
|
271
|
+
]);
|
|
272
|
+
});
|
|
213
273
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
)(values);
|
|
274
|
+
it("returns an empty list for an empty input", () => {
|
|
275
|
+
expect(mapAndSplit((n: number) => n, 2)([])).toEqual([]);
|
|
276
|
+
});
|
|
218
277
|
|
|
219
|
-
|
|
278
|
+
it("puts remaining items in a final smaller chunk", () => {
|
|
279
|
+
expect(mapAndSplit((n: number) => n, 2)([1, 2, 3])).toEqual([[1, 2], [3]]);
|
|
280
|
+
});
|
|
220
281
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
expect(value).toBe(alphabet[chunkIndex * chunkSize + index]);
|
|
224
|
-
});
|
|
225
|
-
});
|
|
226
|
-
});
|
|
282
|
+
it("returns a single chunk when chunk size exceeds the list length", () => {
|
|
283
|
+
expect(mapAndSplit((n: number) => n * 10, 10)([1, 2])).toEqual([[10, 20]]);
|
|
227
284
|
});
|
|
228
285
|
});
|
|
@@ -60,4 +60,15 @@ describe("isEmptyArray", () => {
|
|
|
60
60
|
|
|
61
61
|
expect(isEmptyArray(value)).toBe(false);
|
|
62
62
|
});
|
|
63
|
+
|
|
64
|
+
it("array with falsy values is not empty", () => {
|
|
65
|
+
expect(isEmptyArray([0])).toBe(false);
|
|
66
|
+
expect(isEmptyArray([false])).toBe(false);
|
|
67
|
+
expect(isEmptyArray([null])).toBe(false);
|
|
68
|
+
expect(isEmptyArray([undefined])).toBe(false);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("nested empty array is not empty", () => {
|
|
72
|
+
expect(isEmptyArray([[]])).toBe(false);
|
|
73
|
+
});
|
|
63
74
|
});
|
|
@@ -60,4 +60,16 @@ describe("isFilledArray", () => {
|
|
|
60
60
|
|
|
61
61
|
expect(isFilledArray(value)).toBe(false);
|
|
62
62
|
});
|
|
63
|
+
|
|
64
|
+
it("array with falsy values is filled", () => {
|
|
65
|
+
expect(isFilledArray([0])).toBe(true);
|
|
66
|
+
expect(isFilledArray([false])).toBe(true);
|
|
67
|
+
expect(isFilledArray([null])).toBe(true);
|
|
68
|
+
expect(isFilledArray([undefined])).toBe(true);
|
|
69
|
+
expect(isFilledArray([""])).toBe(true);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("nested empty array is filled", () => {
|
|
73
|
+
expect(isFilledArray([[]])).toBe(true);
|
|
74
|
+
});
|
|
63
75
|
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { isFirst } from "..";
|
|
2
|
+
|
|
3
|
+
describe("isFirst", () => {
|
|
4
|
+
it("returns true for index 0", () => {
|
|
5
|
+
expect(isFirst(0)).toBe(true);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it("returns false for positive indexes", () => {
|
|
9
|
+
expect(isFirst(1)).toBe(false);
|
|
10
|
+
expect(isFirst(10)).toBe(false);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("returns true for negative indexes", () => {
|
|
14
|
+
expect(isFirst(-1)).toBe(true);
|
|
15
|
+
expect(isFirst(-100)).toBe(true);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -56,4 +56,18 @@ describe("isIndexInRange", () => {
|
|
|
56
56
|
|
|
57
57
|
expect(isIndexInRange(index, length)).toBe(false);
|
|
58
58
|
});
|
|
59
|
+
|
|
60
|
+
it("single-element list", () => {
|
|
61
|
+
expect(isIndexInRange(0, 1)).toBe(true);
|
|
62
|
+
expect(isIndexInRange(1, 1)).toBe(false);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it("negative length is out of range", () => {
|
|
66
|
+
expect(isIndexInRange(0, -1)).toBe(false);
|
|
67
|
+
expect(isIndexInRange(0, -5)).toBe(false);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("middle index is in range", () => {
|
|
71
|
+
expect(isIndexInRange(1, 3)).toBe(true);
|
|
72
|
+
});
|
|
59
73
|
});
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { isLast } from "..";
|
|
2
|
+
|
|
3
|
+
describe("isLast", () => {
|
|
4
|
+
it("returns true for the last index", () => {
|
|
5
|
+
expect(isLast(2, 3)).toBe(true);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it("returns false for indexes before the last", () => {
|
|
9
|
+
expect(isLast(0, 3)).toBe(false);
|
|
10
|
+
expect(isLast(1, 3)).toBe(false);
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it("returns true for indexes at or past the last", () => {
|
|
14
|
+
expect(isLast(3, 3)).toBe(true);
|
|
15
|
+
expect(isLast(10, 3)).toBe(true);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("returns true for a single-element list", () => {
|
|
19
|
+
expect(isLast(0, 1)).toBe(true);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it("treats empty length as last for indexes >= -1", () => {
|
|
23
|
+
expect(isLast(0, 0)).toBe(true);
|
|
24
|
+
expect(isLast(-1, 0)).toBe(true);
|
|
25
|
+
expect(isLast(-2, 0)).toBe(false);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("returns false for negative indexes that are before length - 1", () => {
|
|
29
|
+
expect(isLast(-1, 3)).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
});
|