@applicaster/zapp-react-native-utils 16.0.0-rc.99 → 17.0.0-alpha.1102403272
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 +2 -2
- package/actionsExecutor/ActionExecutorContext.tsx +2 -2
- package/actionsExecutor/__tests__/StorageActions.test.ts +98 -0
- package/actionsExecutor/__tests__/feedDecorator.test.ts +30 -0
- package/actionsExecutor/__tests__/screenToggleFlag.test.ts +90 -0
- package/actionsExecutor/actions/__tests__/navigateToScreen.test.ts +186 -5
- package/actionsExecutor/actions/__tests__/openBottomSheet.customContent.test.ts +24 -0
- package/actionsExecutor/actions/__tests__/openBottomSheet.inlineItems.test.ts +72 -0
- package/actionsExecutor/actions/appRestart.ts +2 -2
- package/actionsExecutor/actions/confirmDialog.ts +2 -2
- package/actionsExecutor/actions/dismissBottomSheet.ts +2 -2
- package/actionsExecutor/actions/goBack.ts +2 -2
- package/actionsExecutor/actions/goHome.ts +2 -2
- package/actionsExecutor/actions/navigateToScreen.ts +46 -45
- package/actionsExecutor/actions/openBottomSheet.ts +4 -2
- package/actionsExecutor/actions/presentScreen.ts +2 -2
- package/actionsExecutor/actions/refreshComponent.ts +2 -2
- package/actionsExecutor/actions/screenToggleFlag.ts +1 -3
- package/actionsExecutor/actions/sendCloudEvent.ts +2 -2
- package/actionsExecutor/actions/showAlert.ts +2 -2
- package/actionsExecutor/actions/switchLayout.ts +2 -2
- package/actionsExecutor/feedDecorator.ts +8 -2
- package/actionsExecutor/types.ts +7 -0
- package/analyticsUtils/__tests__/playerAnalyticsSafeguard.test.ts +62 -0
- package/analyticsUtils/logger.ts +9 -4
- package/analyticsUtils/playerAnalyticsTracker.ts +1 -0
- package/appUtils/HooksManager/index.ts +10 -2
- 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 +1 -22
- 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 +0 -25
- 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/{success/saveItemAndReference.test.ts → success.test.ts} +2 -42
- package/appUtils/contextKeysManager/index.ts +30 -131
- 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 +1 -1
- package/appUtils/playerManager/__tests__/playerDiagnostics.test.ts +62 -0
- package/appUtils/playerManager/__tests__/playerNative.test.ts +76 -0
- package/appUtils/playerManager/__tests__/playerNativeCommand.test.ts +62 -0
- package/appUtils/playerManager/__tests__/playerToolbox.test.ts +281 -0
- package/appUtils/playerManager/__tests__/usePlayerControllerSetup.test.tsx +62 -0
- package/appUtils/playerManager/const.ts +13 -0
- package/appUtils/playerManager/index.ts +9 -2
- package/appUtils/playerManager/player.ts +28 -1
- package/appUtils/playerManager/playerNative.ts +23 -1
- package/appUtils/playerManager/playerNativeCommand.ts +3 -6
- package/appUtils/playerManager/playerToolbox.ts +196 -0
- package/appUtils/playerManager/usePlayNextOverlay.tsx +2 -2
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +6 -0
- package/appUtils/playerManager/userCellPlayerMutedPreference.ts +1 -1
- package/appUtils/playerManager/userLanguagePreference.ts +1 -1
- package/arrayUtils/__tests__/reorderByIds.test.ts +13 -0
- package/arrayUtils/index.ts +26 -43
- 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 +40 -0
- package/cellUtils/logger.ts +2 -2
- package/configurationUtils/__tests__/modalBlocksParser.test.ts +134 -0
- package/configurationUtils/modalBlocksParser.ts +38 -0
- package/debugging/DebugFeatues.tsx +2 -25
- package/debugging/DebugFeatures.ts +495 -0
- package/debugging/__tests__/DebugFeatures.test.ts +313 -0
- package/debugging/index.ts +3 -0
- package/domUtils/logger.ts +2 -2
- package/entryActions/aliasPresentation.ts +1 -0
- package/entryActions/buildEntryActions.ts +1 -1
- package/errorUtils/index.ts +2 -0
- package/focusManager/FocusManager.ts +43 -6
- package/focusManager/__tests__/FocusManager.test.ts +124 -3
- 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__/createConfig.test.js +17 -7
- package/manifestUtils/_internals/getDefaultConfiguration.js +9 -11
- package/manifestUtils/defaultManifestConfigurations/player.js +8 -0
- package/manifestUtils/keys.js +7 -2
- package/manifestUtils/mobileAction/container/__tests__/mobileActionButtonsContainer.test.js +21 -0
- package/manifestUtils/mobileAction/groups/__tests__/buildMobileActionButtonGroups.test.js +1 -1
- package/manifestUtils/mobileAction/groups/defaults.js +2 -1
- package/modalState/EditableCollectionRegistry.ts +1 -1
- package/modalState/ModalOrchestrator.ts +1 -0
- package/modalState/RemoteEditableCollection.ts +1 -1
- package/modalState/__tests__/ModalOrchestrator.phase3.test.ts +23 -0
- package/modalState/index.ts +2 -0
- package/modalState/types.ts +11 -0
- package/navigationUtils/index.ts +5 -2
- package/navigationUtils/xrayNavigator.ts +12 -0
- package/numberUtils/index.ts +2 -2
- package/package.json +3 -2
- package/playerUtils/PlayerTTS/PlayerTTS.ts +1 -1
- package/playerUtils/imaScriptDom.ts +1 -1
- package/playerUtils/useValidatePlayerConfig.tsx +1 -1
- 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 +29 -23
- package/reactHooks/cell-click/__tests__/index.test.js +67 -1
- package/reactHooks/cell-click/helpers.ts +3 -1
- package/reactHooks/cell-click/index.ts +10 -2
- package/reactHooks/connection/index.tsx +8 -5
- package/reactHooks/feed/__tests__/feedInvalidation.test.tsx +338 -0
- package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +8 -2
- package/reactHooks/feed/__tests__/useMarkPipesDataStale.test.tsx +243 -0
- 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 +68 -23
- package/reactHooks/hookModal/hooks/useHookModalScreenData.ts +5 -2
- package/reactHooks/logger.ts +5 -2
- package/reactHooks/navigation/usePresentScreen.ts +19 -6
- package/reactHooks/player/TVSeekControlller/TVSeekController.ts +2 -2
- package/reactHooks/resolvers/useComponentResolver.ts +10 -0
- package/reactHooks/screen/useScreenData.ts +2 -2
- package/reactHooks/usePluginConfiguration.ts +84 -46
- 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 +5 -5
- 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/stylesUtils/logger.ts +2 -2
- package/uiActionsRegistrator/__tests__/subscribe.test.ts +26 -0
- package/uiActionsRegistrator/registry.ts +17 -1
- package/uiActionsRegistrator/resolveActionIdentifiers.ts +6 -2
- package/uiActionsRegistrator/usableActionItems.ts +1 -1
- package/zappFrameworkUtils/HookCallback/callbackNavigationAction.ts +2 -1
- 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
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import { localStorage as NativeLocalStorageMock } from "../../../zapp-react-native-bridge/ZappStorage/__mocks__/android";
|
|
2
|
+
|
|
3
|
+
const STATE_KEY = "__applicasterDebugFeatures";
|
|
4
|
+
|
|
5
|
+
type LoadedModule = {
|
|
6
|
+
DebugFeaturesModule: typeof import("../DebugFeatures");
|
|
7
|
+
LegacyModule: typeof import("../DebugFeatues");
|
|
8
|
+
ReactNative: typeof import("react-native");
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const loadModules = (
|
|
12
|
+
nativeDebugBridge?: Record<string, jest.Mock>
|
|
13
|
+
): LoadedModule => {
|
|
14
|
+
delete (globalThis as any)[STATE_KEY];
|
|
15
|
+
NativeLocalStorageMock.__clear();
|
|
16
|
+
|
|
17
|
+
let DebugFeaturesModule: typeof import("../DebugFeatures");
|
|
18
|
+
let LegacyModule: typeof import("../DebugFeatues");
|
|
19
|
+
let ReactNative: typeof import("react-native");
|
|
20
|
+
|
|
21
|
+
jest.isolateModules(() => {
|
|
22
|
+
ReactNative = require("react-native");
|
|
23
|
+
ReactNative.NativeModules.LocalStorage = NativeLocalStorageMock;
|
|
24
|
+
|
|
25
|
+
if (nativeDebugBridge) {
|
|
26
|
+
ReactNative.NativeModules.DebugFeaturesBridge = nativeDebugBridge;
|
|
27
|
+
} else {
|
|
28
|
+
delete ReactNative.NativeModules.DebugFeaturesBridge;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
DebugFeaturesModule = require("../DebugFeatures");
|
|
32
|
+
LegacyModule = require("../DebugFeatues");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
return {
|
|
36
|
+
DebugFeaturesModule,
|
|
37
|
+
LegacyModule,
|
|
38
|
+
ReactNative,
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
describe("DebugFeatures", () => {
|
|
43
|
+
afterEach(() => {
|
|
44
|
+
delete (globalThis as any)[STATE_KEY];
|
|
45
|
+
const ReactNative = require("react-native");
|
|
46
|
+
delete ReactNative.NativeModules.DebugFeaturesBridge;
|
|
47
|
+
jest.restoreAllMocks();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe("when native DebugFeaturesBridge is available", () => {
|
|
51
|
+
it("delegates registration, reading, writing, and receives native change events", async () => {
|
|
52
|
+
const nativeBridge = {
|
|
53
|
+
registerFeatureFlag: jest.fn().mockResolvedValue(true),
|
|
54
|
+
getFeatures: jest.fn().mockResolvedValue([
|
|
55
|
+
{
|
|
56
|
+
id: "plugin.flag",
|
|
57
|
+
group: "Plugin",
|
|
58
|
+
description: "Test flag",
|
|
59
|
+
initialState: true,
|
|
60
|
+
enabled: true,
|
|
61
|
+
value: "true",
|
|
62
|
+
},
|
|
63
|
+
]),
|
|
64
|
+
isFeatureFlagEnabled: jest.fn().mockResolvedValue(true),
|
|
65
|
+
toggleFeatureFlag: jest.fn().mockResolvedValue(false),
|
|
66
|
+
getStringValue: jest.fn().mockResolvedValue("123"),
|
|
67
|
+
setStringValue: jest.fn().mockResolvedValue("abc"),
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
const { DebugFeaturesModule, ReactNative } = loadModules(nativeBridge);
|
|
71
|
+
const { default: DebugFeatures, subscribe } = DebugFeaturesModule;
|
|
72
|
+
const instance = DebugFeatures.getInstance();
|
|
73
|
+
|
|
74
|
+
await expect(
|
|
75
|
+
instance.registerFeatureFlag({
|
|
76
|
+
id: "plugin.flag",
|
|
77
|
+
group: "Plugin",
|
|
78
|
+
description: "Test flag",
|
|
79
|
+
initialState: true,
|
|
80
|
+
})
|
|
81
|
+
).resolves.toBe(true);
|
|
82
|
+
|
|
83
|
+
expect(nativeBridge.registerFeatureFlag).toHaveBeenCalledWith({
|
|
84
|
+
id: "plugin.flag",
|
|
85
|
+
group: "Plugin",
|
|
86
|
+
description: "Test flag",
|
|
87
|
+
initialState: true,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
await expect(instance.getFeatures()).resolves.toEqual([
|
|
91
|
+
{
|
|
92
|
+
id: "plugin.flag",
|
|
93
|
+
group: "Plugin",
|
|
94
|
+
description: "Test flag",
|
|
95
|
+
initialState: true,
|
|
96
|
+
enabled: true,
|
|
97
|
+
value: "true",
|
|
98
|
+
},
|
|
99
|
+
]);
|
|
100
|
+
|
|
101
|
+
await expect(instance.isFeatureFlagEnabled("plugin.flag")).resolves.toBe(
|
|
102
|
+
true
|
|
103
|
+
);
|
|
104
|
+
|
|
105
|
+
await expect(
|
|
106
|
+
instance.toggleFeatureFlag("plugin.flag", false)
|
|
107
|
+
).resolves.toBe(false);
|
|
108
|
+
|
|
109
|
+
await expect(instance.getStringValue("plugin.str")).resolves.toBe("123");
|
|
110
|
+
|
|
111
|
+
await expect(instance.setStringValue("plugin.str", "abc")).resolves.toBe(
|
|
112
|
+
"abc"
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
const globalEvents = [];
|
|
116
|
+
const keyEvents = [];
|
|
117
|
+
const unsubGlobal = subscribe((event) => globalEvents.push(event));
|
|
118
|
+
|
|
119
|
+
const unsubKey = subscribe(
|
|
120
|
+
(event) => keyEvents.push(event),
|
|
121
|
+
"plugin.flag"
|
|
122
|
+
);
|
|
123
|
+
|
|
124
|
+
ReactNative.DeviceEventEmitter.emit("DebugFeatures.changed", {
|
|
125
|
+
id: "plugin.flag",
|
|
126
|
+
value: "true",
|
|
127
|
+
enabled: true,
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
ReactNative.DeviceEventEmitter.emit("DebugFeatures.changed", {
|
|
131
|
+
id: "other.flag",
|
|
132
|
+
value: "hello",
|
|
133
|
+
enabled: false,
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
expect(globalEvents).toEqual([
|
|
137
|
+
{ id: "plugin.flag", value: "true", enabled: true },
|
|
138
|
+
{ id: "other.flag", value: "hello", enabled: false },
|
|
139
|
+
]);
|
|
140
|
+
|
|
141
|
+
expect(keyEvents).toEqual([
|
|
142
|
+
{ id: "plugin.flag", value: "true", enabled: true },
|
|
143
|
+
]);
|
|
144
|
+
|
|
145
|
+
unsubGlobal();
|
|
146
|
+
unsubKey();
|
|
147
|
+
|
|
148
|
+
ReactNative.DeviceEventEmitter.emit("DebugFeatures.changed", {
|
|
149
|
+
id: "plugin.flag",
|
|
150
|
+
value: "false",
|
|
151
|
+
enabled: false,
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
expect(globalEvents).toHaveLength(2);
|
|
155
|
+
expect(keyEvents).toHaveLength(1);
|
|
156
|
+
});
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
describe("when native DebugFeaturesBridge is missing", () => {
|
|
160
|
+
it("falls back to LocalStorage and in-JS registry and notifies subscribers", async () => {
|
|
161
|
+
const { DebugFeaturesModule, LegacyModule } = loadModules();
|
|
162
|
+
|
|
163
|
+
const {
|
|
164
|
+
default: DebugFeatures,
|
|
165
|
+
registerFeatureFlag,
|
|
166
|
+
getFeatures,
|
|
167
|
+
isFeatureFlagEnabled,
|
|
168
|
+
toggleFeatureFlag,
|
|
169
|
+
getStringValue,
|
|
170
|
+
setStringValue,
|
|
171
|
+
subscribe,
|
|
172
|
+
} = DebugFeaturesModule;
|
|
173
|
+
|
|
174
|
+
const globalListener = jest.fn();
|
|
175
|
+
const keyListener = jest.fn();
|
|
176
|
+
const unsubGlobal = subscribe(globalListener);
|
|
177
|
+
const unsubKey = subscribe(keyListener, "flag.initial_true");
|
|
178
|
+
|
|
179
|
+
await expect(
|
|
180
|
+
registerFeatureFlag({
|
|
181
|
+
id: "flag.initial_true",
|
|
182
|
+
group: "Debug",
|
|
183
|
+
description: "Starts enabled",
|
|
184
|
+
initialState: true,
|
|
185
|
+
})
|
|
186
|
+
).resolves.toBe(true);
|
|
187
|
+
|
|
188
|
+
await expect(
|
|
189
|
+
registerFeatureFlag({
|
|
190
|
+
id: "flag.default_off",
|
|
191
|
+
group: "Debug",
|
|
192
|
+
description: "Starts disabled",
|
|
193
|
+
})
|
|
194
|
+
).resolves.toBe(false);
|
|
195
|
+
|
|
196
|
+
expect(globalListener).toHaveBeenCalledWith({
|
|
197
|
+
id: "flag.initial_true",
|
|
198
|
+
value: "true",
|
|
199
|
+
enabled: true,
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
expect(keyListener).toHaveBeenCalledWith({
|
|
203
|
+
id: "flag.initial_true",
|
|
204
|
+
value: "true",
|
|
205
|
+
enabled: true,
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
// Re-registering initialState: true does not overwrite an explicit false
|
|
209
|
+
await expect(toggleFeatureFlag("flag.initial_true", false)).resolves.toBe(
|
|
210
|
+
false
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
await expect(
|
|
214
|
+
registerFeatureFlag({
|
|
215
|
+
id: "flag.initial_true",
|
|
216
|
+
group: "Debug",
|
|
217
|
+
description: "Starts enabled",
|
|
218
|
+
initialState: true,
|
|
219
|
+
})
|
|
220
|
+
).resolves.toBe(false);
|
|
221
|
+
|
|
222
|
+
await expect(isFeatureFlagEnabled("flag.initial_true")).resolves.toBe(
|
|
223
|
+
false
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
await expect(
|
|
227
|
+
LegacyModule.default
|
|
228
|
+
.getInstance()
|
|
229
|
+
.isFeatureFlagEnabled("flag.initial_true")
|
|
230
|
+
).resolves.toBe(false);
|
|
231
|
+
|
|
232
|
+
await expect(
|
|
233
|
+
DebugFeatures.getInstance().isFeatureFlagEnabled("flag.default_off")
|
|
234
|
+
).resolves.toBe(false);
|
|
235
|
+
|
|
236
|
+
await expect(setStringValue("flag.str", "123")).resolves.toBe("123");
|
|
237
|
+
await expect(getStringValue("flag.str")).resolves.toBe("123");
|
|
238
|
+
await expect(setStringValue("flag.str", "")).resolves.toBeNull();
|
|
239
|
+
await expect(getStringValue("flag.str")).resolves.toBeNull();
|
|
240
|
+
|
|
241
|
+
await expect(getFeatures()).resolves.toEqual([
|
|
242
|
+
{
|
|
243
|
+
id: "flag.default_off",
|
|
244
|
+
group: "Debug",
|
|
245
|
+
description: "Starts disabled",
|
|
246
|
+
initialState: false,
|
|
247
|
+
enabled: false,
|
|
248
|
+
value: null,
|
|
249
|
+
},
|
|
250
|
+
{
|
|
251
|
+
id: "flag.initial_true",
|
|
252
|
+
group: "Debug",
|
|
253
|
+
description: "Starts enabled",
|
|
254
|
+
initialState: true,
|
|
255
|
+
enabled: false,
|
|
256
|
+
value: "false",
|
|
257
|
+
},
|
|
258
|
+
]);
|
|
259
|
+
|
|
260
|
+
expect(globalListener).toHaveBeenLastCalledWith({
|
|
261
|
+
id: "flag.str",
|
|
262
|
+
value: null,
|
|
263
|
+
enabled: false,
|
|
264
|
+
});
|
|
265
|
+
|
|
266
|
+
unsubGlobal();
|
|
267
|
+
unsubKey();
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it("logs an error via X-Ray logger when native module is present but a method is missing", async () => {
|
|
271
|
+
const logErrorMock = jest.fn();
|
|
272
|
+
|
|
273
|
+
jest.doMock("../../logger", () => ({
|
|
274
|
+
...jest.requireActual("../../logger"),
|
|
275
|
+
createLogger: () => ({
|
|
276
|
+
log_verbose: jest.fn(),
|
|
277
|
+
log_debug: jest.fn(),
|
|
278
|
+
log_info: jest.fn(),
|
|
279
|
+
log_warning: jest.fn(),
|
|
280
|
+
log_error: logErrorMock,
|
|
281
|
+
}),
|
|
282
|
+
}));
|
|
283
|
+
|
|
284
|
+
const partialBridge = {
|
|
285
|
+
registerFeatureFlag: jest.fn().mockResolvedValue(true),
|
|
286
|
+
};
|
|
287
|
+
|
|
288
|
+
const { DebugFeaturesModule } = loadModules(partialBridge);
|
|
289
|
+
|
|
290
|
+
const { registerFeatureFlag, isFeatureFlagEnabled, getStringValue } =
|
|
291
|
+
DebugFeaturesModule;
|
|
292
|
+
|
|
293
|
+
try {
|
|
294
|
+
await expect(
|
|
295
|
+
registerFeatureFlag({ id: "flag.partial", initialState: true })
|
|
296
|
+
).resolves.toBe(true);
|
|
297
|
+
|
|
298
|
+
await expect(isFeatureFlagEnabled("flag.partial")).resolves.toBe(false);
|
|
299
|
+
await expect(getStringValue("flag.partial")).resolves.toBeNull();
|
|
300
|
+
|
|
301
|
+
expect(logErrorMock).toHaveBeenCalledWith(
|
|
302
|
+
"DebugFeaturesBridge.isFeatureFlagEnabled is missing on native module"
|
|
303
|
+
);
|
|
304
|
+
|
|
305
|
+
expect(logErrorMock).toHaveBeenCalledWith(
|
|
306
|
+
"DebugFeaturesBridge.getStringValue is missing on native module"
|
|
307
|
+
);
|
|
308
|
+
} finally {
|
|
309
|
+
jest.dontMock("../../logger");
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
});
|
|
313
|
+
});
|
package/domUtils/logger.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { subsystemLogger } from "../logger";
|
|
2
2
|
|
|
3
|
-
export const domUtilsLogger =
|
|
3
|
+
export const domUtilsLogger = subsystemLogger("core/dom", "DomUtils");
|
package/errorUtils/index.ts
CHANGED
|
@@ -14,6 +14,8 @@ export const getParsedResponse = (err): XRayEventData => {
|
|
|
14
14
|
|
|
15
15
|
const xRayData: XRayEventData = {
|
|
16
16
|
data: {
|
|
17
|
+
// What X-Ray diagnostics read is top level in `data`: the error's context carries it.
|
|
18
|
+
diagnostic: context?.diagnostic,
|
|
17
19
|
context,
|
|
18
20
|
name,
|
|
19
21
|
params,
|
|
@@ -222,14 +222,47 @@ class FocusManager {
|
|
|
222
222
|
return () => this.unregisterFocusable(focusableId);
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
-
unregisterFocusable(
|
|
225
|
+
unregisterFocusable(component: string | FocusManager.TouchableReactRef) {
|
|
226
|
+
const focusableId = isString(component)
|
|
227
|
+
? component
|
|
228
|
+
: getFocusableId(component);
|
|
229
|
+
|
|
226
230
|
const node = this.tree.find(focusableId);
|
|
231
|
+
const parentNode = this.tree.findParent(focusableId);
|
|
232
|
+
|
|
233
|
+
const removesFocusedSubtree =
|
|
234
|
+
this._focusedId === focusableId ||
|
|
235
|
+
!!(this._focusedId && node?.findNode(this._focusedId));
|
|
227
236
|
|
|
228
237
|
this.focusableComponents = this.focusableComponents.filter(
|
|
229
|
-
(c) => c !== node?.component
|
|
238
|
+
(c) => c !== node?.component && getFocusableId(c) !== focusableId
|
|
230
239
|
);
|
|
231
240
|
|
|
232
241
|
this.tree.remove(focusableId);
|
|
242
|
+
|
|
243
|
+
if (removesFocusedSubtree) {
|
|
244
|
+
this._focusedId = null;
|
|
245
|
+
this.retainFocus(parentNode);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Recover before parent-first unmounts discard the focused child's ancestry.
|
|
250
|
+
// Land on a mounted ancestor so key handlers keep a target.
|
|
251
|
+
private retainFocus(node: TreeNode | null) {
|
|
252
|
+
let current = node;
|
|
253
|
+
|
|
254
|
+
while (current) {
|
|
255
|
+
const ref = FocusManager.findFocusable(current.id);
|
|
256
|
+
|
|
257
|
+
if (ref?.current?.props?.id) {
|
|
258
|
+
this.setFocusLocal(ref);
|
|
259
|
+
ref.current.onFocus?.(ref.current, {}, undefined);
|
|
260
|
+
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
current = current.parentId ? this.tree.find(current.parentId) : null;
|
|
265
|
+
}
|
|
233
266
|
}
|
|
234
267
|
|
|
235
268
|
private setNextFocus(
|
|
@@ -418,13 +451,17 @@ class FocusManager {
|
|
|
418
451
|
}
|
|
419
452
|
|
|
420
453
|
private hasFocus = (node) => {
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
454
|
+
const propsId = node?.component?.current?.props?.id;
|
|
455
|
+
|
|
456
|
+
// A focused cell keeps its buttons as children. Count that cell, not only leaves.
|
|
457
|
+
if (
|
|
458
|
+
this.isFocused(propsId) ||
|
|
459
|
+
(node?.id !== propsId && this.isFocused(node?.id))
|
|
460
|
+
) {
|
|
424
461
|
return true;
|
|
425
462
|
}
|
|
426
463
|
|
|
427
|
-
return false;
|
|
464
|
+
return node.children?.some((child) => this.hasFocus(child)) ?? false;
|
|
428
465
|
};
|
|
429
466
|
|
|
430
467
|
isAnyDescendantFocused(id: string) {
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { focusManager } from "../FocusManager";
|
|
2
|
+
import { Touchable } from "@applicaster/zapp-react-native-ui-components/Components/Focusable/Touchable";
|
|
3
|
+
import { Tree } from "../Tree";
|
|
4
|
+
import { TreeNode } from "../TreeNode";
|
|
2
5
|
|
|
3
6
|
const isFocusableCell = true;
|
|
4
7
|
const parentFocusableId = "parentFocusableId";
|
|
@@ -120,11 +123,11 @@ describe("FocusManager", () => {
|
|
|
120
123
|
/* check state of focus */
|
|
121
124
|
expect(focusManager.isAnyDescendantFocused("group")).toBe(false);
|
|
122
125
|
|
|
123
|
-
/* set focus on 2nd child */
|
|
126
|
+
/* set focus on 2nd child, which itself has children */
|
|
124
127
|
focusManager.setFocus(child2.current.props.id);
|
|
125
128
|
|
|
126
|
-
/*
|
|
127
|
-
expect(focusManager.isAnyDescendantFocused("group")).toBe(
|
|
129
|
+
/* the focused node is the child, not one of its leaves */
|
|
130
|
+
expect(focusManager.isAnyDescendantFocused("group")).toBe(true);
|
|
128
131
|
});
|
|
129
132
|
|
|
130
133
|
it("focusManager isFocusableChildOf should be defined", () => {
|
|
@@ -231,6 +234,15 @@ describe("FocusManager", () => {
|
|
|
231
234
|
).toBeFalsy();
|
|
232
235
|
});
|
|
233
236
|
|
|
237
|
+
it("moves focus to the mounted parent when the focused element unregisters", () => {
|
|
238
|
+
focusManager.setFocus("child1");
|
|
239
|
+
|
|
240
|
+
focusManager.unregisterFocusable("child1");
|
|
241
|
+
|
|
242
|
+
expect(focusManager.focusedId).toBe("group");
|
|
243
|
+
expect(focusManager.focused).toBe(group.current);
|
|
244
|
+
});
|
|
245
|
+
|
|
234
246
|
it("focusManager registerFocusable should be defined", () => {
|
|
235
247
|
expect(focusManager.registerFocusable).toBeDefined();
|
|
236
248
|
});
|
|
@@ -257,3 +269,112 @@ describe("FocusManager", () => {
|
|
|
257
269
|
expect(focusManager.focusedId).toBe("child2");
|
|
258
270
|
});
|
|
259
271
|
});
|
|
272
|
+
|
|
273
|
+
describe("FocusManager subtree replacement", () => {
|
|
274
|
+
const createFocusable = (id: string) => ({
|
|
275
|
+
current: new Touchable({ id, children: null, onFocus: jest.fn() }),
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
let root: FocusManager.TouchableReactRef;
|
|
279
|
+
let rail: FocusManager.TouchableReactRef;
|
|
280
|
+
let cell: FocusManager.TouchableReactRef;
|
|
281
|
+
let sibling: FocusManager.TouchableReactRef;
|
|
282
|
+
|
|
283
|
+
const register = (
|
|
284
|
+
touchableRef: FocusManager.TouchableReactRef,
|
|
285
|
+
parentFocusableRef: FocusManager.TouchableReactRef
|
|
286
|
+
) =>
|
|
287
|
+
focusManager.registerFocusable({
|
|
288
|
+
touchableRef,
|
|
289
|
+
parentFocusableRef,
|
|
290
|
+
isFocusableCell: true,
|
|
291
|
+
parentFocusableId: "",
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
beforeEach(() => {
|
|
295
|
+
root = createFocusable("replacement-root");
|
|
296
|
+
rail = createFocusable("replacement-rail");
|
|
297
|
+
cell = createFocusable("replacement-cell");
|
|
298
|
+
sibling = createFocusable("replacement-sibling");
|
|
299
|
+
register(root, { current: null });
|
|
300
|
+
register(rail, root);
|
|
301
|
+
register(cell, rail);
|
|
302
|
+
register(sibling, root);
|
|
303
|
+
focusManager.setFocus("replacement-cell");
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
afterEach(() => {
|
|
307
|
+
[
|
|
308
|
+
"replacement-cell",
|
|
309
|
+
"replacement-rail",
|
|
310
|
+
"replacement-sibling",
|
|
311
|
+
"replacement-root",
|
|
312
|
+
].forEach((id) => focusManager.unregisterFocusable(id));
|
|
313
|
+
|
|
314
|
+
focusManager.resetFocus();
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it("retains focus before a parent-first unmount removes the focused descendant's ancestry", () => {
|
|
318
|
+
focusManager.unregisterFocusable("replacement-rail");
|
|
319
|
+
|
|
320
|
+
expect(focusManager.focusedId).toBe("replacement-root");
|
|
321
|
+
expect(focusManager.focused).toBe(root.current);
|
|
322
|
+
|
|
323
|
+
focusManager.unregisterFocusable("replacement-cell");
|
|
324
|
+
|
|
325
|
+
expect(focusManager.focused).toBe(root.current);
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
it("removes descendant registrations even after their parent removed the tree nodes", () => {
|
|
329
|
+
focusManager.unregisterFocusable("replacement-rail");
|
|
330
|
+
focusManager.unregisterFocusable("replacement-cell");
|
|
331
|
+
|
|
332
|
+
expect(focusManager.focusableComponents).not.toContain(cell);
|
|
333
|
+
expect(focusManager.focusableComponents).not.toContain(rail);
|
|
334
|
+
|
|
335
|
+
const replacementRail = createFocusable("replacement-rail");
|
|
336
|
+
const replacementCell = createFocusable("replacement-cell");
|
|
337
|
+
register(replacementRail, root);
|
|
338
|
+
register(replacementCell, replacementRail);
|
|
339
|
+
focusManager.setFocus("replacement-cell");
|
|
340
|
+
|
|
341
|
+
expect(focusManager.focused).toBe(replacementCell.current);
|
|
342
|
+
expect(focusManager.isFocusableChildOf(replacementCell, root)).toBe(true);
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
it("does not move focus when an unrelated subtree unregisters", () => {
|
|
346
|
+
focusManager.setFocus("replacement-sibling");
|
|
347
|
+
focusManager.unregisterFocusable("replacement-rail");
|
|
348
|
+
focusManager.unregisterFocusable("replacement-cell");
|
|
349
|
+
|
|
350
|
+
expect(focusManager.focused).toBe(sibling.current);
|
|
351
|
+
});
|
|
352
|
+
|
|
353
|
+
it("resolves a placeholder ancestor through its mounted registration", () => {
|
|
354
|
+
const findParent = jest
|
|
355
|
+
.spyOn(Tree.prototype, "findParent")
|
|
356
|
+
.mockReturnValueOnce(new TreeNode(null, "replacement-root", "", false));
|
|
357
|
+
|
|
358
|
+
focusManager.unregisterFocusable("replacement-rail");
|
|
359
|
+
findParent.mockRestore();
|
|
360
|
+
|
|
361
|
+
expect(focusManager.focused).toBe(root.current);
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
it("retains focus through child-first cleanup", () => {
|
|
365
|
+
focusManager.unregisterFocusable("replacement-cell");
|
|
366
|
+
expect(focusManager.focused).toBe(rail.current);
|
|
367
|
+
|
|
368
|
+
focusManager.unregisterFocusable("replacement-rail");
|
|
369
|
+
expect(focusManager.focused).toBe(root.current);
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
it("clears focus when the entire root containing the focused cell unregisters", () => {
|
|
373
|
+
focusManager.unregisterFocusable("replacement-root");
|
|
374
|
+
focusManager.unregisterFocusable("replacement-rail");
|
|
375
|
+
focusManager.unregisterFocusable("replacement-cell");
|
|
376
|
+
|
|
377
|
+
expect(focusManager.focusedId).toBeNull();
|
|
378
|
+
expect(focusManager.focused).toBeNull();
|
|
379
|
+
});
|
|
380
|
+
});
|