@applicaster/zapp-react-native-utils 16.0.0-rc.13 → 16.0.0-rc.131
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 +59 -14
- package/actionsExecutor/ActionExecutorContext.tsx +115 -316
- package/actionsExecutor/__tests__/ActionExecutor.test.ts +71 -0
- package/actionsExecutor/__tests__/StorageActions.test.ts +98 -0
- package/actionsExecutor/__tests__/feedDecorator.test.ts +91 -0
- package/actionsExecutor/__tests__/screenToggleFlag.test.ts +90 -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 +314 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +100 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +372 -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 +127 -0
- package/actionsExecutor/actions/openBottomSheet.ts +340 -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 +36 -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 +14 -8
- package/actionsExecutor/types.ts +66 -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/__tests__/playerAnalyticsSafeguard.test.ts +62 -0
- package/analyticsUtils/analyticsMapper.ts +4 -1
- package/analyticsUtils/logger.ts +9 -4
- package/analyticsUtils/playerAnalyticsTracker.ts +27 -3
- package/appUtils/HooksManager/index.ts +9 -0
- package/appUtils/HooksManager/logger.ts +5 -2
- package/appUtils/accessibilityManager/logger.ts +2 -4
- package/appUtils/accessibilityManager/utils.ts +1 -1
- package/appUtils/contextKeysManager/__tests__/getKey/failure.test.ts +2 -23
- package/appUtils/contextKeysManager/__tests__/getKey/success/fullSearch.test.ts +1 -25
- package/appUtils/contextKeysManager/__tests__/getKey/success/searchInSecure.test.ts +1 -7
- package/appUtils/contextKeysManager/__tests__/removeKey/failure.test.ts +1 -26
- package/appUtils/contextKeysManager/__tests__/removeKey/success.test.ts +0 -6
- package/appUtils/contextKeysManager/__tests__/setKey/failure/failedToSaveInStorage.test.ts +0 -40
- package/appUtils/contextKeysManager/__tests__/setKey/failure/invalidKey.test.ts +4 -4
- package/appUtils/contextKeysManager/__tests__/setKey/{success/saveItemAndReference.test.ts → success.test.ts} +2 -42
- package/appUtils/contextKeysManager/index.ts +31 -132
- package/appUtils/focusManager/__tests__/focusManager.test.js +33 -0
- package/appUtils/focusManager/__tests__/focusToolbox.test.ts +357 -0
- package/appUtils/focusManager/focusToolbox.ts +223 -0
- package/appUtils/focusManager/index.ios.ts +7 -1
- package/appUtils/focusManager/index.ts +3 -3
- package/appUtils/focusManager/logger.ts +2 -2
- package/appUtils/focusManagerAux/index.ts +2 -2
- package/appUtils/orientationHelper.ts +2 -2
- package/appUtils/platform/platformUtils.ts +6 -22
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +143 -60
- 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__/playerDiagnostics.test.ts +62 -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 +281 -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 +10 -3
- package/appUtils/playerManager/player.ts +141 -4
- package/appUtils/playerManager/playerFactory.ts +1 -1
- package/appUtils/playerManager/playerNative.ts +29 -5
- package/appUtils/playerManager/playerNativeCommand.ts +3 -6
- package/appUtils/playerManager/playerToolbox.ts +196 -0
- package/appUtils/playerManager/usePlayNextOverlay.tsx +2 -2
- package/appUtils/playerManager/usePlayerContent.tsx +43 -0
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +7 -1
- package/appUtils/playerManager/userCellPlayerMutedPreference.ts +1 -1
- package/appUtils/playerManager/userLanguagePreference.ts +2 -2
- 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/cellUtils/logger.ts +2 -2
- 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 +403 -0
- package/configurationUtils/manifestKeyParser.ts +50 -10
- package/configurationUtils/modalBlocksParser.ts +252 -0
- package/domUtils/logger.ts +2 -2
- package/entryActions/__tests__/buildEntryActions.test.ts +235 -0
- package/entryActions/aliasPresentation.ts +109 -0
- package/entryActions/buildEntryActions.ts +167 -0
- package/entryActions/index.ts +15 -0
- package/entryActions/types.ts +39 -0
- package/focusManager/FocusManager.ts +35 -2
- package/focusManager/__tests__/FocusManager.test.ts +121 -0
- package/focusManager/focusToolbox.ts +208 -0
- package/focusManager/index.ts +7 -0
- package/focusManager/logger.ts +2 -6
- package/headersUtils/index.ts +2 -2
- package/localizationUtils/index.ts +12 -6
- package/logger/__tests__/subsystems.test.ts +148 -0
- package/logger/__tests__/xrayToolbox.test.ts +69 -0
- package/logger/index.ts +48 -9
- package/logger/subsystems.ts +112 -0
- package/logger/xrayToolbox.ts +69 -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 +16 -2
- 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 +213 -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 +86 -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 +37 -83
- package/modalState/store.ts +109 -0
- package/modalState/types.ts +173 -0
- package/modalState/useBottomSheetContent.ts +109 -0
- package/navigationUtils/index.ts +5 -2
- 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 +29 -10
- package/package.json +3 -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/PlayerTTS/PlayerTTS.ts +1 -1
- 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/imaScriptDom.ts +1 -1
- 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/playerUtils/useValidatePlayerConfig.tsx +1 -1
- package/pluginUtils/__tests__/pluginUtils.test.js +32 -0
- package/pluginUtils/index.ts +29 -0
- package/pluginUtils/logger.ts +2 -2
- package/quickBrickAssets/__tests__/index.test.ts +18 -0
- package/quickBrickAssets/index.ts +35 -0
- package/reactHooks/__tests__/getPluginConfiguration.test.ts +82 -0
- package/reactHooks/actions/index.ts +124 -3
- package/reactHooks/cell-click/__tests__/index.test.js +131 -1
- package/reactHooks/cell-click/index.ts +48 -25
- package/reactHooks/connection/index.tsx +8 -5
- package/reactHooks/feed/__mocks__/useMarkPipesDataStale.ts +4 -0
- package/reactHooks/feed/__tests__/feedInvalidation.test.tsx +338 -0
- package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +8 -2
- 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/useBuildPipesUrl.ts +5 -2
- package/reactHooks/feed/useFeedLoader.tsx +30 -3
- package/reactHooks/feed/useLoadPipesDataDispatch.ts +12 -11
- package/reactHooks/feed/useMarkPipesDataStale.ts +97 -0
- package/reactHooks/hookModal/hooks/useHookModalScreenData.ts +5 -2
- package/reactHooks/index.ts +2 -0
- package/reactHooks/layout/index.ts +1 -1
- package/reactHooks/logger.ts +5 -2
- 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/player/TVSeekControlller/TVSeekController.ts +2 -2
- package/reactHooks/screen/useScreenData.ts +2 -2
- 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/reactHooks/videoModal/hooks/useChangeOrientation.ts +2 -7
- package/reactHooks/videoModal/hooks/useVideoModalScreenData.tsx +1 -1
- package/reactUtils/__tests__/deviceTargetGuards.test.js +73 -0
- package/reactUtils/createContext/helpers.ts +2 -2
- package/reactUtils/index.ts +28 -0
- package/reactUtils/logger.ts +2 -2
- package/riverComponetsMeasurementProvider/index.tsx +17 -13
- package/storage/ScreenSingleValueProvider.ts +1 -1
- package/storage/ScreenStateMultiSelectProvider.ts +1 -1
- package/storage/StorageMultiSelectProvider.ts +1 -1
- package/storage/StorageSingleSelectProvider.ts +1 -1
- package/stringUtils/__tests__/stringUtils.test.js +42 -0
- package/stringUtils/index.ts +2 -2
- package/stylesUtils/logger.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/HookCallback/callbackNavigationAction.ts +2 -1
- package/zappFrameworkUtils/__tests__/localStorageHelper.test.ts +146 -0
- package/zappFrameworkUtils/localStorageHelper.ts +19 -15
- package/zappFrameworkUtils/loginPluginUtils.ts +2 -1
- package/zappFrameworkUtils/presentPluginOneTime.ts +2 -1
- package/appUtils/contextKeysManager/__tests__/getKey/success/byReference.test.ts +0 -56
- package/appUtils/contextKeysManager/__tests__/getKeyByReference/failure.test.ts +0 -265
- package/appUtils/contextKeysManager/__tests__/getKeyByReference/success.test.ts +0 -303
- package/appUtils/contextKeysManager/__tests__/removeReferenceForKey/failure.test.ts +0 -82
- package/appUtils/contextKeysManager/__tests__/removeReferenceForKey/success.test.ts +0 -41
- package/appUtils/contextKeysManager/__tests__/setKey/success/saveItemButNotReference.test.ts +0 -208
- package/appUtils/contextKeysManager/__tests__/setReferenceForKey/failure.test.ts +0 -93
- package/appUtils/contextKeysManager/__tests__/setReferenceForKey/success.test.ts +0 -45
- 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,372 @@
|
|
|
1
|
+
import { openBottomSheetAction } from "../openBottomSheet";
|
|
2
|
+
import { actionExecutor, ActionResult } from "../../ActionExecutor";
|
|
3
|
+
import { modalOrchestrator } from "../../../modalState/ModalOrchestrator";
|
|
4
|
+
|
|
5
|
+
jest.mock("@applicaster/zapp-pipes-v2-client", () => ({
|
|
6
|
+
PipesClientResponseHelper: jest.fn(() => ({ error: null })),
|
|
7
|
+
RequestBuilder: jest.fn(() => ({
|
|
8
|
+
setEntryContext: jest.fn().mockReturnThis(),
|
|
9
|
+
setScreenContext: jest.fn().mockReturnThis(),
|
|
10
|
+
setUrl: jest.fn().mockReturnThis(),
|
|
11
|
+
buildAxiosRequest: jest.fn().mockResolvedValue(undefined),
|
|
12
|
+
call: jest.fn().mockResolvedValue({
|
|
13
|
+
response: {
|
|
14
|
+
entry: [],
|
|
15
|
+
extensions: { dynamic_collection_options: { operations: "add" } },
|
|
16
|
+
},
|
|
17
|
+
}),
|
|
18
|
+
})),
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
jest.mock("../../../modalState/store", () => ({
|
|
22
|
+
openBottomSheetModal: jest.fn(),
|
|
23
|
+
}));
|
|
24
|
+
|
|
25
|
+
jest.mock("../../../modalState/ModalOrchestrator", () => ({
|
|
26
|
+
modalOrchestrator: {
|
|
27
|
+
open: jest.fn(),
|
|
28
|
+
replace: jest.fn(),
|
|
29
|
+
stackSize: 0,
|
|
30
|
+
},
|
|
31
|
+
isPresentSubMenuAction: jest.requireActual("../../../modalState/types")
|
|
32
|
+
.isPresentSubMenuAction,
|
|
33
|
+
}));
|
|
34
|
+
|
|
35
|
+
describe("openBottomSheetAction inline items", () => {
|
|
36
|
+
beforeEach(() => {
|
|
37
|
+
jest.clearAllMocks();
|
|
38
|
+
(modalOrchestrator as any).stackSize = 0;
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
const speedSheetAction = {
|
|
42
|
+
type: "openBottomSheet",
|
|
43
|
+
options: {
|
|
44
|
+
header: { title: "Playback Speed" },
|
|
45
|
+
content: {
|
|
46
|
+
role: "collection_selector",
|
|
47
|
+
behavior: {
|
|
48
|
+
selectMode: "single",
|
|
49
|
+
currentSelection: ["1"],
|
|
50
|
+
},
|
|
51
|
+
items: [
|
|
52
|
+
{
|
|
53
|
+
id: "0.8",
|
|
54
|
+
title: "0.8x",
|
|
55
|
+
extensions: {
|
|
56
|
+
tap_actions: {
|
|
57
|
+
actions: [
|
|
58
|
+
{ type: "setPlaybackSpeed", options: { value: 0.8 } },
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: "1",
|
|
65
|
+
title: "1x",
|
|
66
|
+
extensions: {
|
|
67
|
+
tap_actions: {
|
|
68
|
+
actions: [{ type: "setPlaybackSpeed", options: { value: 1 } }],
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
},
|
|
72
|
+
],
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
} as any;
|
|
76
|
+
|
|
77
|
+
it("opens orchestrator with inline items and marks current selection", async () => {
|
|
78
|
+
const result = await openBottomSheetAction(speedSheetAction);
|
|
79
|
+
|
|
80
|
+
expect(result).toBe(ActionResult.Success);
|
|
81
|
+
expect(modalOrchestrator.open).toHaveBeenCalledTimes(1);
|
|
82
|
+
expect(modalOrchestrator.replace).not.toHaveBeenCalled();
|
|
83
|
+
|
|
84
|
+
const [menu] = (modalOrchestrator.open as jest.Mock).mock.calls[0];
|
|
85
|
+
|
|
86
|
+
expect(menu.content.items[0].isSelected).toBe(false);
|
|
87
|
+
|
|
88
|
+
expect(menu.content.items[1]).toMatchObject({
|
|
89
|
+
id: "1",
|
|
90
|
+
title: "1x",
|
|
91
|
+
isSelected: true,
|
|
92
|
+
action: { type: "setPlaybackSpeed", options: { value: 1 } },
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("opens an empty inline collection when dynamic collection options are present", async () => {
|
|
97
|
+
const result = await openBottomSheetAction({
|
|
98
|
+
type: "openBottomSheet",
|
|
99
|
+
options: {
|
|
100
|
+
header: { title: "Queue" },
|
|
101
|
+
content: {
|
|
102
|
+
items: [],
|
|
103
|
+
emptyMessage: "Queued items will be added here",
|
|
104
|
+
dynamicCollection: {
|
|
105
|
+
operations: ["remove"],
|
|
106
|
+
provider: "@{provider/queue}",
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
} as any);
|
|
111
|
+
|
|
112
|
+
expect(result).toBe(ActionResult.Success);
|
|
113
|
+
|
|
114
|
+
const [menu] = (modalOrchestrator.open as jest.Mock).mock.calls[0];
|
|
115
|
+
|
|
116
|
+
expect(menu.content.items).toEqual([]);
|
|
117
|
+
expect(menu.content.emptyMessage).toBe("Queued items will be added here");
|
|
118
|
+
|
|
119
|
+
expect(menu.content.dynamicCollection).toMatchObject({
|
|
120
|
+
operations: ["remove"],
|
|
121
|
+
provider: "@{provider/queue}",
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it("accepts empty inline items when dynamic_collection_options live on extensions", async () => {
|
|
126
|
+
const result = await openBottomSheetAction({
|
|
127
|
+
type: "openBottomSheet",
|
|
128
|
+
options: {
|
|
129
|
+
content: {
|
|
130
|
+
items: [],
|
|
131
|
+
extensions: {
|
|
132
|
+
dynamic_collection_options: {
|
|
133
|
+
operations: "remove,reorder",
|
|
134
|
+
provider: "@{provider/offline}",
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
} as any);
|
|
140
|
+
|
|
141
|
+
expect(result).toBe(ActionResult.Success);
|
|
142
|
+
|
|
143
|
+
const [menu] = (modalOrchestrator.open as jest.Mock).mock.calls[0];
|
|
144
|
+
|
|
145
|
+
expect(menu.content.items).toEqual([]);
|
|
146
|
+
|
|
147
|
+
expect(menu.content.dynamicCollection).toMatchObject({
|
|
148
|
+
operations: ["remove", "reorder"],
|
|
149
|
+
provider: "@{provider/offline}",
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("returns an error for an empty items array with no source", async () => {
|
|
154
|
+
const result = await openBottomSheetAction({
|
|
155
|
+
type: "openBottomSheet",
|
|
156
|
+
options: {
|
|
157
|
+
content: { items: [] },
|
|
158
|
+
},
|
|
159
|
+
} as any);
|
|
160
|
+
|
|
161
|
+
expect(result).toBe(ActionResult.Error);
|
|
162
|
+
expect(modalOrchestrator.open).not.toHaveBeenCalled();
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("forwards content.emptyMessage onto the menu", async () => {
|
|
166
|
+
const result = await openBottomSheetAction({
|
|
167
|
+
type: "openBottomSheet",
|
|
168
|
+
options: {
|
|
169
|
+
header: { title: "Queue" },
|
|
170
|
+
content: {
|
|
171
|
+
items: [{ id: "t1", title: "Track 1" }],
|
|
172
|
+
emptyMessage: "Queued items will be added here",
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
} as any);
|
|
176
|
+
|
|
177
|
+
expect(result).toBe(ActionResult.Success);
|
|
178
|
+
|
|
179
|
+
const [menu] = (modalOrchestrator.open as jest.Mock).mock.calls[0];
|
|
180
|
+
|
|
181
|
+
expect(menu.content.emptyMessage).toBe("Queued items will be added here");
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("forwards content.operationButtons onto the menu", async () => {
|
|
185
|
+
const result = await openBottomSheetAction({
|
|
186
|
+
type: "openBottomSheet",
|
|
187
|
+
options: {
|
|
188
|
+
header: { title: "Playlists" },
|
|
189
|
+
content: {
|
|
190
|
+
items: [{ id: "p1", title: "Playlist 1" }],
|
|
191
|
+
operationButtons: {
|
|
192
|
+
add: {
|
|
193
|
+
title: "Create New Playlist",
|
|
194
|
+
iconURL: "https://example.com/add.png",
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
} as any);
|
|
200
|
+
|
|
201
|
+
expect(result).toBe(ActionResult.Success);
|
|
202
|
+
|
|
203
|
+
const [menu] = (modalOrchestrator.open as jest.Mock).mock.calls[0];
|
|
204
|
+
|
|
205
|
+
expect(menu.content.operationButtons).toEqual({
|
|
206
|
+
add: {
|
|
207
|
+
title: "Create New Playlist",
|
|
208
|
+
iconURL: "https://example.com/add.png",
|
|
209
|
+
},
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it("preserves Add presentation when loading itemsUrl content", async () => {
|
|
214
|
+
const result = await openBottomSheetAction({
|
|
215
|
+
type: "openBottomSheet",
|
|
216
|
+
options: {
|
|
217
|
+
content: {
|
|
218
|
+
itemsUrl: "https://example.com/collections",
|
|
219
|
+
operationButtons: {
|
|
220
|
+
add: {
|
|
221
|
+
title: "Create Collection",
|
|
222
|
+
iconURL: "file:///bundled-add.png",
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
expect(result).toBe(ActionResult.Success);
|
|
230
|
+
const [menu] = (modalOrchestrator.open as jest.Mock).mock.calls[0];
|
|
231
|
+
|
|
232
|
+
expect(menu.content).toMatchObject({
|
|
233
|
+
operationButtons: {
|
|
234
|
+
add: { title: "Create Collection", iconURL: "file:///bundled-add.png" },
|
|
235
|
+
},
|
|
236
|
+
dynamicCollection: { operations: ["add"] },
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
it("pushes a new sheet by default even when another sheet is already open", async () => {
|
|
241
|
+
(modalOrchestrator as any).stackSize = 1;
|
|
242
|
+
|
|
243
|
+
await openBottomSheetAction(speedSheetAction);
|
|
244
|
+
|
|
245
|
+
expect(modalOrchestrator.open).toHaveBeenCalledTimes(1);
|
|
246
|
+
expect(modalOrchestrator.replace).not.toHaveBeenCalled();
|
|
247
|
+
});
|
|
248
|
+
|
|
249
|
+
it("replaces the current sheet when options.replace is true", async () => {
|
|
250
|
+
(modalOrchestrator as any).stackSize = 1;
|
|
251
|
+
|
|
252
|
+
await openBottomSheetAction({
|
|
253
|
+
...speedSheetAction,
|
|
254
|
+
options: { ...speedSheetAction.options, replace: true },
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
expect(modalOrchestrator.replace).toHaveBeenCalledTimes(1);
|
|
258
|
+
expect(modalOrchestrator.open).not.toHaveBeenCalled();
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
it("executes all actions in tap_actions when onItemPress is called", async () => {
|
|
262
|
+
const multiActionSheet = {
|
|
263
|
+
type: "openBottomSheet",
|
|
264
|
+
options: {
|
|
265
|
+
header: { title: "Target Playlists" },
|
|
266
|
+
content: {
|
|
267
|
+
role: "collection_selector",
|
|
268
|
+
behavior: { selectMode: "none", currentSelection: [] },
|
|
269
|
+
items: [
|
|
270
|
+
{
|
|
271
|
+
id: "playlist-1",
|
|
272
|
+
title: "My Playlist",
|
|
273
|
+
extensions: {
|
|
274
|
+
tap_actions: {
|
|
275
|
+
actions: [
|
|
276
|
+
{
|
|
277
|
+
type: "sendCloudEvent",
|
|
278
|
+
options: { subject: "add_collection_to_collection" },
|
|
279
|
+
},
|
|
280
|
+
{
|
|
281
|
+
type: "showToast",
|
|
282
|
+
options: { message: "Added to playlist" },
|
|
283
|
+
},
|
|
284
|
+
{ type: "dismissBottomSheet", options: {} },
|
|
285
|
+
],
|
|
286
|
+
},
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
],
|
|
290
|
+
},
|
|
291
|
+
},
|
|
292
|
+
} as any;
|
|
293
|
+
|
|
294
|
+
await openBottomSheetAction(multiActionSheet);
|
|
295
|
+
|
|
296
|
+
const [menu, onItemPress] = (modalOrchestrator.open as jest.Mock).mock
|
|
297
|
+
.calls[0];
|
|
298
|
+
|
|
299
|
+
expect(menu.content.items[0].actions).toHaveLength(3);
|
|
300
|
+
|
|
301
|
+
const handleActionsSpy = jest
|
|
302
|
+
.spyOn(actionExecutor, "handleActions")
|
|
303
|
+
.mockResolvedValue(ActionResult.Success);
|
|
304
|
+
|
|
305
|
+
await onItemPress(menu.content.items[0]);
|
|
306
|
+
|
|
307
|
+
expect(handleActionsSpy).toHaveBeenCalledWith(
|
|
308
|
+
[
|
|
309
|
+
{
|
|
310
|
+
type: "sendCloudEvent",
|
|
311
|
+
options: { subject: "add_collection_to_collection" },
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
type: "showToast",
|
|
315
|
+
options: { message: "Added to playlist" },
|
|
316
|
+
},
|
|
317
|
+
{ type: "dismissBottomSheet", options: {} },
|
|
318
|
+
],
|
|
319
|
+
expect.objectContaining({
|
|
320
|
+
entry: menu.content.items[0],
|
|
321
|
+
})
|
|
322
|
+
);
|
|
323
|
+
|
|
324
|
+
handleActionsSpy.mockRestore();
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
it("executes preceding actions and excludes presentSubMenu from actionExecutor", async () => {
|
|
328
|
+
const subMenuSheet = {
|
|
329
|
+
type: "openBottomSheet",
|
|
330
|
+
options: {
|
|
331
|
+
header: { title: "Menu" },
|
|
332
|
+
content: {
|
|
333
|
+
items: [
|
|
334
|
+
{
|
|
335
|
+
id: "item-with-submenu",
|
|
336
|
+
title: "More Options",
|
|
337
|
+
extensions: {
|
|
338
|
+
tap_actions: {
|
|
339
|
+
actions: [
|
|
340
|
+
{ type: "sendAnalytics", options: { event: "click_more" } },
|
|
341
|
+
{
|
|
342
|
+
type: "presentSubMenu",
|
|
343
|
+
menu: { content: { title: "Sub Options", items: [] } },
|
|
344
|
+
},
|
|
345
|
+
],
|
|
346
|
+
},
|
|
347
|
+
},
|
|
348
|
+
},
|
|
349
|
+
],
|
|
350
|
+
},
|
|
351
|
+
},
|
|
352
|
+
} as any;
|
|
353
|
+
|
|
354
|
+
await openBottomSheetAction(subMenuSheet);
|
|
355
|
+
|
|
356
|
+
const [menu, onItemPress] = (modalOrchestrator.open as jest.Mock).mock
|
|
357
|
+
.calls[0];
|
|
358
|
+
|
|
359
|
+
const handleActionsSpy = jest
|
|
360
|
+
.spyOn(actionExecutor, "handleActions")
|
|
361
|
+
.mockResolvedValue(ActionResult.Success);
|
|
362
|
+
|
|
363
|
+
await onItemPress(menu.content.items[0]);
|
|
364
|
+
|
|
365
|
+
expect(handleActionsSpy).toHaveBeenCalledWith(
|
|
366
|
+
[{ type: "sendAnalytics", options: { event: "click_more" } }],
|
|
367
|
+
expect.objectContaining({ entry: menu.content.items[0] })
|
|
368
|
+
);
|
|
369
|
+
|
|
370
|
+
handleActionsSpy.mockRestore();
|
|
371
|
+
});
|
|
372
|
+
});
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { createPresentScreenAction } from "../presentScreen";
|
|
2
|
+
import { ActionResult } from "../../ActionExecutor";
|
|
3
|
+
|
|
4
|
+
const contextEntry = { id: "context-entry" } as any;
|
|
5
|
+
|
|
6
|
+
const succeeded = { success: true, cancelled: false };
|
|
7
|
+
|
|
8
|
+
const cancelled = { success: false, cancelled: true };
|
|
9
|
+
|
|
10
|
+
describe("presentScreenAction", () => {
|
|
11
|
+
let presentScreen: jest.Mock;
|
|
12
|
+
let presentScreenAction: ReturnType<typeof createPresentScreenAction>;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
presentScreen = jest.fn().mockResolvedValue(succeeded);
|
|
16
|
+
presentScreenAction = createPresentScreenAction(presentScreen);
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("presents the screen named by typeMapping", async () => {
|
|
20
|
+
await presentScreenAction({
|
|
21
|
+
type: "presentScreen",
|
|
22
|
+
options: { typeMapping: "parent_lock" },
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
expect(presentScreen).toHaveBeenCalledWith({
|
|
26
|
+
typeMapping: "parent_lock",
|
|
27
|
+
entry: undefined,
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("fails without presenting anything when typeMapping is missing", async () => {
|
|
32
|
+
const result = await presentScreenAction({
|
|
33
|
+
type: "presentScreen",
|
|
34
|
+
options: {},
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
expect(result).toBe(ActionResult.Error);
|
|
38
|
+
expect(presentScreen).not.toHaveBeenCalled();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("resolves the '@{entry/}' token to the entry from the execution context", async () => {
|
|
42
|
+
await presentScreenAction(
|
|
43
|
+
{
|
|
44
|
+
type: "presentScreen",
|
|
45
|
+
options: { typeMapping: "parent_lock", entry: "@{entry/}" },
|
|
46
|
+
},
|
|
47
|
+
{ entry: contextEntry }
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
expect(presentScreen).toHaveBeenCalledWith({
|
|
51
|
+
typeMapping: "parent_lock",
|
|
52
|
+
entry: contextEntry,
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("presents an entry supplied inline in the options", async () => {
|
|
57
|
+
const inlineEntry = { id: "inline-entry" } as any;
|
|
58
|
+
|
|
59
|
+
await presentScreenAction({
|
|
60
|
+
type: "presentScreen",
|
|
61
|
+
options: { typeMapping: "parent_lock", entry: inlineEntry },
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
expect(presentScreen).toHaveBeenCalledWith({
|
|
65
|
+
typeMapping: "parent_lock",
|
|
66
|
+
entry: inlineEntry,
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("fails without presenting anything when the entry option is not an object", async () => {
|
|
71
|
+
const result = await presentScreenAction({
|
|
72
|
+
type: "presentScreen",
|
|
73
|
+
options: { typeMapping: "parent_lock", entry: "not-an-entry" as any },
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
expect(result).toBe(ActionResult.Error);
|
|
77
|
+
expect(presentScreen).not.toHaveBeenCalled();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("succeeds when the presented screen reports success", async () => {
|
|
81
|
+
presentScreen.mockResolvedValue(succeeded);
|
|
82
|
+
|
|
83
|
+
const result = await presentScreenAction({
|
|
84
|
+
type: "presentScreen",
|
|
85
|
+
options: { typeMapping: "parent_lock" },
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
expect(result).toBe(ActionResult.Success);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("cancels the action chain when the presented screen is cancelled", async () => {
|
|
92
|
+
presentScreen.mockResolvedValue(cancelled);
|
|
93
|
+
|
|
94
|
+
const result = await presentScreenAction({
|
|
95
|
+
type: "presentScreen",
|
|
96
|
+
options: { typeMapping: "parent_lock" },
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
expect(result).toBe(ActionResult.Cancel);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("cancels the action chain when the presented screen reports failure", async () => {
|
|
103
|
+
presentScreen.mockResolvedValue({ success: false, cancelled: false });
|
|
104
|
+
|
|
105
|
+
const result = await presentScreenAction({
|
|
106
|
+
type: "presentScreen",
|
|
107
|
+
options: { typeMapping: "parent_lock" },
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
expect(result).toBe(ActionResult.Cancel);
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("errors when the screen could not be presented at all", async () => {
|
|
114
|
+
presentScreen.mockResolvedValue({
|
|
115
|
+
success: false,
|
|
116
|
+
cancelled: false,
|
|
117
|
+
error: "can not resolve screen type mapping: parent_lock",
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
const result = await presentScreenAction({
|
|
121
|
+
type: "presentScreen",
|
|
122
|
+
options: { typeMapping: "parent_lock" },
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
expect(result).toBe(ActionResult.Error);
|
|
126
|
+
});
|
|
127
|
+
});
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { showAlertAction } from "../showAlert";
|
|
2
|
+
import { ActionResult } from "../../ActionExecutor";
|
|
3
|
+
import { showAlertDialog } from "../../../alertUtils";
|
|
4
|
+
|
|
5
|
+
jest.mock("../../../alertUtils", () => ({
|
|
6
|
+
showAlertDialog: jest.fn(),
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
const dialog = showAlertDialog as jest.Mock;
|
|
10
|
+
|
|
11
|
+
const dismiss = () => dialog.mock.calls[0][0].completion();
|
|
12
|
+
|
|
13
|
+
describe("showAlert", () => {
|
|
14
|
+
beforeEach(() => dialog.mockReset());
|
|
15
|
+
|
|
16
|
+
it("shows the notice and resolves once it is dismissed", async () => {
|
|
17
|
+
const result = showAlertAction({
|
|
18
|
+
type: "showAlert",
|
|
19
|
+
options: { title: "Locked", message: "Ask the account owner." },
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
expect(dialog).toHaveBeenCalledWith(
|
|
23
|
+
expect.objectContaining({
|
|
24
|
+
title: "Locked",
|
|
25
|
+
message: "Ask the account owner.",
|
|
26
|
+
okButtonText: "OK",
|
|
27
|
+
})
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
dismiss();
|
|
31
|
+
|
|
32
|
+
// Dismissing a notice is not a cancellation: the chain carries on.
|
|
33
|
+
await expect(result).resolves.toBe(ActionResult.Success);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("takes the dismiss label from the action", async () => {
|
|
37
|
+
const result = showAlertAction({
|
|
38
|
+
type: "showAlert",
|
|
39
|
+
options: { title: "Locked", okButtonText: "Got it" },
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
expect(dialog).toHaveBeenCalledWith(
|
|
43
|
+
expect.objectContaining({ okButtonText: "Got it" })
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
dismiss();
|
|
47
|
+
await result;
|
|
48
|
+
});
|
|
49
|
+
});
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { showToastAction } from "../showToast";
|
|
2
|
+
import { postEvent } from "../../../reactHooks/useSubscriberFor";
|
|
3
|
+
import { ActionResult } from "../../ActionExecutor";
|
|
4
|
+
|
|
5
|
+
jest.mock("../../../reactHooks/useSubscriberFor", () => ({
|
|
6
|
+
postEvent: jest.fn(),
|
|
7
|
+
}));
|
|
8
|
+
|
|
9
|
+
describe("showToastAction", () => {
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
jest.clearAllMocks();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("calls postEvent with confirmation source, default timeout, and returns Success", async () => {
|
|
15
|
+
const action = {
|
|
16
|
+
type: "showToast",
|
|
17
|
+
options: {
|
|
18
|
+
id: "toast-1",
|
|
19
|
+
message: "Added to queue",
|
|
20
|
+
extraMessage: "Extra info",
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const result = await showToastAction(action);
|
|
25
|
+
|
|
26
|
+
expect(postEvent).toHaveBeenCalledTimes(1);
|
|
27
|
+
|
|
28
|
+
expect(postEvent).toHaveBeenCalledWith("showToast", [
|
|
29
|
+
{
|
|
30
|
+
id: "toast-1",
|
|
31
|
+
message: "Added to queue",
|
|
32
|
+
extraMessage: "Extra info",
|
|
33
|
+
style: undefined,
|
|
34
|
+
timeout: 5000,
|
|
35
|
+
source: "confirmation",
|
|
36
|
+
},
|
|
37
|
+
]);
|
|
38
|
+
|
|
39
|
+
expect(result).toBe(ActionResult.Success);
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("preserves an explicit timeout and style override", async () => {
|
|
43
|
+
const action = {
|
|
44
|
+
type: "showToast",
|
|
45
|
+
options: {
|
|
46
|
+
message: "Playlist created",
|
|
47
|
+
timeout: 3000,
|
|
48
|
+
style: { backgroundColor: "#00FF00" },
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
await showToastAction(action);
|
|
53
|
+
|
|
54
|
+
expect(postEvent).toHaveBeenCalledWith("showToast", [
|
|
55
|
+
{
|
|
56
|
+
id: undefined,
|
|
57
|
+
message: "Playlist created",
|
|
58
|
+
extraMessage: undefined,
|
|
59
|
+
style: { backgroundColor: "#00FF00" },
|
|
60
|
+
timeout: 3000,
|
|
61
|
+
source: "confirmation",
|
|
62
|
+
},
|
|
63
|
+
]);
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("handles missing or empty options without throwing", async () => {
|
|
67
|
+
const action = {
|
|
68
|
+
type: "showToast",
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const result = await showToastAction(action);
|
|
72
|
+
|
|
73
|
+
expect(postEvent).toHaveBeenCalledTimes(1);
|
|
74
|
+
|
|
75
|
+
expect(postEvent).toHaveBeenCalledWith("showToast", [
|
|
76
|
+
{
|
|
77
|
+
id: undefined,
|
|
78
|
+
message: undefined,
|
|
79
|
+
extraMessage: undefined,
|
|
80
|
+
style: undefined,
|
|
81
|
+
timeout: 5000,
|
|
82
|
+
source: "confirmation",
|
|
83
|
+
},
|
|
84
|
+
]);
|
|
85
|
+
|
|
86
|
+
expect(result).toBe(ActionResult.Success);
|
|
87
|
+
});
|
|
88
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/// <reference types="@applicaster/applicaster-types" />
|
|
2
|
+
import * as QuickBrickManager from "@applicaster/zapp-react-native-bridge/QuickBrick";
|
|
3
|
+
import { QUICK_BRICK_EVENTS } from "@applicaster/zapp-react-native-bridge/QuickBrick";
|
|
4
|
+
import { ActionResult } from "../ActionExecutor";
|
|
5
|
+
import { ActionHandler } from "../types";
|
|
6
|
+
import { createLogger } from "../../logger";
|
|
7
|
+
|
|
8
|
+
const { log_info } = createLogger({
|
|
9
|
+
subsystem: "core/actions",
|
|
10
|
+
category: "ActionExecutor",
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Restarts the application by triggering a force reload event.
|
|
15
|
+
* This action does not require any options or context.
|
|
16
|
+
*/
|
|
17
|
+
export const appRestartAction: ActionHandler =
|
|
18
|
+
async (): Promise<ActionResult> => {
|
|
19
|
+
log_info(`handleAction: ${QUICK_BRICK_EVENTS.FORCE_APP_RELOAD} event`);
|
|
20
|
+
|
|
21
|
+
QuickBrickManager.sendQuickBrickEvent(QUICK_BRICK_EVENTS.FORCE_APP_RELOAD);
|
|
22
|
+
|
|
23
|
+
return ActionResult.Success;
|
|
24
|
+
};
|