@applicaster/zapp-react-native-ui-components 16.0.0-alpha.2024822855 → 16.0.0-alpha.2105365027

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (95) hide show
  1. package/Components/Cell/Cell.tsx +3 -6
  2. package/Components/Cell/TvOSCellComponent.tsx +0 -1
  3. package/Components/FocusableList/index.tsx +7 -0
  4. package/Components/GeneralContentScreen/GeneralContentScreen.tsx +7 -0
  5. package/Components/GeneralContentScreen/GeneralContentScreenHookAdapter.tsx +15 -0
  6. package/Components/GeneralContentScreen/hookAdapter/__tests__/skipExpression.test.ts +294 -0
  7. package/Components/GeneralContentScreen/hookAdapter/__tests__/validationHelper.test.ts +64 -0
  8. package/Components/GeneralContentScreen/hookAdapter/skipExpression.ts +252 -0
  9. package/Components/GeneralContentScreen/hookAdapter/validationHelper.ts +18 -0
  10. package/Components/LinkHandler/LinkHandler.tsx +2 -7
  11. package/Components/MasterCell/DefaultComponents/ActionButton.tsx +5 -1
  12. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/components/ActionButtonController.tsx +19 -4
  13. package/Components/MasterCell/DefaultComponents/ActionButtonsCore/components/__tests__/ActionButtonController.test.tsx +43 -1
  14. package/Components/MasterCell/DefaultComponents/Button.tsx +1 -0
  15. package/Components/MasterCell/DefaultComponents/LiveImage/executePreloadHooks.ts +2 -4
  16. package/Components/MasterCell/DefaultComponents/LiveImage/index.tsx +14 -6
  17. package/Components/MasterCell/DefaultComponents/Toggle.tsx +1 -8
  18. package/Components/MasterCell/DefaultComponents/__tests__/Toggle.test.tsx +10 -6
  19. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/ActionButton.tsx +1 -1
  20. package/Components/MasterCell/DefaultComponents/mobile/MobileActionButtons/__tests__/PressableView.test.tsx +4 -2
  21. package/Components/MasterCell/SharedUI/CollapsibleTextContainer/__tests__/factory.test.ts +32 -0
  22. package/Components/MasterCell/__tests__/masterCell.test.js +60 -0
  23. package/Components/MasterCell/index.tsx +60 -11
  24. package/Components/MasterCell/utils/__tests__/withoutFocusedState.test.js +20 -0
  25. package/Components/MasterCell/utils/index.ts +18 -0
  26. package/Components/ModalComponent/ActionsBottomSheet/ActionButton.tsx +56 -0
  27. package/Components/ModalComponent/ActionsBottomSheet/__tests__/openActionsBottomSheet.test.ts +38 -0
  28. package/Components/ModalComponent/ActionsBottomSheet/boundActionButton.tsx +24 -0
  29. package/Components/ModalComponent/ActionsBottomSheet/index.ts +9 -0
  30. package/Components/ModalComponent/ActionsBottomSheet/openActionsBottomSheet.ts +61 -0
  31. package/Components/ModalComponent/AudioPlayer/Components/Button.tsx +70 -73
  32. package/Components/ModalComponent/AudioPlayer/Components/Header.tsx +65 -56
  33. package/Components/ModalComponent/AudioPlayer/Components/Input.tsx +140 -65
  34. package/Components/ModalComponent/AudioPlayer/Components/Item.tsx +202 -48
  35. package/Components/ModalComponent/AudioPlayer/Components/NowPlayingHeaderSection.tsx +148 -32
  36. package/Components/ModalComponent/AudioPlayer/Components/__tests__/Item.test.tsx +164 -0
  37. package/Components/ModalComponent/AudioPlayer/Components/__tests__/NowPlayingHeaderSection.test.tsx +36 -0
  38. package/Components/ModalComponent/AudioPlayer/Components/index.ts +0 -2
  39. package/Components/ModalComponent/AudioPlayer/utils/__tests__/mergeStyles.test.ts +433 -0
  40. package/Components/ModalComponent/AudioPlayer/utils/mergeStyles.ts +389 -25
  41. package/Components/ModalComponent/BottomSheetModalContent.tsx +126 -77
  42. package/Components/ModalComponent/Header/CloseButton.tsx +12 -0
  43. package/Components/ModalComponent/Header/__tests__/CloseButton.test.tsx +72 -0
  44. package/Components/ModalComponent/SortableList.tsx +36 -22
  45. package/Components/ModalComponent/SortableList.web.tsx +2 -70
  46. package/Components/ModalComponent/TextInputContent.tsx +42 -7
  47. package/Components/ModalComponent/__tests__/BottomSheetModalContent.test.tsx +111 -6
  48. package/Components/ModalComponent/__tests__/SortableList.web.test.tsx +16 -0
  49. package/Components/ModalComponent/__tests__/TextInputContent.test.tsx +50 -1
  50. package/Components/ModalComponent/__tests__/showTextInput.test.ts +25 -0
  51. package/Components/ModalComponent/index.tsx +7 -9
  52. package/Components/ModalComponent/presets/__tests__/getCell.test.ts +24 -0
  53. package/Components/ModalComponent/presets/dynamicCollectionCell.tsx +1 -1
  54. package/Components/ModalComponent/presets/selectableCell.tsx +1 -1
  55. package/Components/ModalComponent/showTextInput.ts +13 -2
  56. package/Components/ModalComponent/utils.ts +6 -1
  57. package/Components/OfflineHandler/__tests__/index.test.tsx +109 -0
  58. package/Components/OfflineHandler/hooks.ts +0 -12
  59. package/Components/OfflineHandler/index.tsx +42 -4
  60. package/Components/PlayerContainer/PlayerContainer.tsx +8 -1
  61. package/Components/River/ComponentsMap/ComponentsMap.tsx +89 -60
  62. package/Components/River/River.tsx +4 -0
  63. package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +140 -75
  64. package/Components/River/__tests__/componentsMap.test.js +8 -3
  65. package/Components/River/__tests__/resultCallback.test.tsx +47 -0
  66. package/Components/Screen/__tests__/Screen.test.tsx +24 -0
  67. package/Components/Screen/__tests__/__snapshots__/Screen.test.tsx.snap +2 -0
  68. package/Components/Screen/index.tsx +5 -0
  69. package/Components/Screen/navigationHandler.ts +8 -8
  70. package/Components/ScreenRevealManager/ScreenRevealManager.ts +18 -2
  71. package/Components/ScreenRevealManager/__tests__/ScreenRevealManager.test.ts +36 -0
  72. package/Components/ScreenRevealManager/__tests__/withScreenRevealManager.test.tsx +56 -0
  73. package/Components/ScreenRevealManager/withScreenRevealManager.tsx +21 -4
  74. package/Components/Transitioner/AnimationManager.js +1 -1
  75. package/Components/Transitioner/Scene.tsx +4 -3
  76. package/Components/Transitioner/Transitioner.tsx +71 -33
  77. package/Components/Transitioner/__tests__/transitioner.test.js +372 -3
  78. package/Components/VideoLive/LiveImageManager.ts +8 -2
  79. package/Components/VideoLive/__tests__/LiveImageManager.test.ts +59 -0
  80. package/Components/VideoModal/PlayerWrapper.tsx +4 -1
  81. package/Components/VideoModal/__tests__/PlayerWrapper.test.tsx +1 -0
  82. package/Components/VideoModal/__tests__/playerWrapperStyle.test.ts +58 -0
  83. package/Components/VideoModal/__tests__/playerWrapperUtils.test.ts +16 -0
  84. package/Components/VideoModal/playerWrapperStyle.ts +21 -3
  85. package/Components/VideoModal/playerWrapperUtils.ts +7 -1
  86. package/Contexts/ModalNavigationContext/__tests__/index.test.tsx +15 -0
  87. package/Contexts/ModalNavigationContext/index.tsx +2 -2
  88. package/Decorators/ZappPipesDataConnector/__tests__/screenToolbox.test.ts +347 -0
  89. package/Decorators/ZappPipesDataConnector/__tests__/screenToolboxUnavailable.test.ts +53 -0
  90. package/Decorators/ZappPipesDataConnector/index.tsx +19 -4
  91. package/Decorators/ZappPipesDataConnector/screenToolbox.ts +384 -0
  92. package/Hooks/useEntryActionsExpander.ts +63 -0
  93. package/assets/empty-Info.png +0 -0
  94. package/package.json +5 -5
  95. package/Components/ModalComponent/AudioPlayer/Components/Action.tsx +0 -314
@@ -134,7 +134,7 @@ export class CellComponent extends React.Component<Props, State> {
134
134
  }
135
135
  }
136
136
 
137
- onFocus(focusable, mouse) {
137
+ onFocus(focusable) {
138
138
  const {
139
139
  item: { id, title },
140
140
  shouldScrollVertically,
@@ -145,10 +145,7 @@ export class CellComponent extends React.Component<Props, State> {
145
145
  if (isFocusable) {
146
146
  this.setState({ cellFocused: true });
147
147
 
148
- if (
149
- shouldUpdate &&
150
- shouldScrollVertically?.(mouse, focusable, id, title)
151
- ) {
148
+ if (shouldUpdate && shouldScrollVertically?.(focusable, id, title)) {
152
149
  this.scrollVertically(focusable);
153
150
  }
154
151
  }
@@ -262,7 +259,7 @@ export class CellComponent extends React.Component<Props, State> {
262
259
  const handleFocus = (focusable, mouse) => {
263
260
  const focusFn = onFocus || noop;
264
261
  focusFn(focusable, mouse);
265
- this.onFocus(focusable, mouse);
262
+ this.onFocus(focusable);
266
263
  };
267
264
 
268
265
  if (this.state.hasFocusableInside) {
@@ -228,7 +228,6 @@ class TvOSCell extends React.Component<Props, State> {
228
228
  mainOffsetUpdater?.(
229
229
  { tag: this.target },
230
230
  totalOffset,
231
- null,
232
231
  groupId,
233
232
  id,
234
233
  component.id,
@@ -1,5 +1,6 @@
1
1
  import * as R from "ramda";
2
2
  import * as React from "react";
3
+ import { countRender } from "@applicaster/zapp-react-native-utils/perfTracker";
3
4
  import {
4
5
  FlatList,
5
6
  FlatListProps,
@@ -101,6 +102,12 @@ function FocusableListComponent<ItemT>(props: Props<ItemT>, ref) {
101
102
  onScrollToIndexFailed = noop,
102
103
  } = props;
103
104
 
105
+ countRender(`FocusableList:${props.id || "anonymous"}`, {
106
+ id: props.id,
107
+ horizontal: !!horizontal,
108
+ dataCount: data ? data.length : 0,
109
+ });
110
+
104
111
  useCheckItemIdsForUnique({ componentId: props.id, items: data });
105
112
 
106
113
  const { focused, nextFocusUp, nextFocusRight, nextFocusDown, nextFocusLeft } =
@@ -1,4 +1,5 @@
1
1
  import React, { useEffect } from "react";
2
+ import { countRender } from "@applicaster/zapp-react-native-utils/perfTracker";
2
3
  import { ComponentsMap } from "../River/ComponentsMap";
3
4
  import { CellTapContext } from "@applicaster/zapp-react-native-ui-components/Contexts/CellTapContext";
4
5
  import { useActions } from "@applicaster/zapp-react-native-utils/reactHooks/actions";
@@ -107,6 +108,12 @@ export const GeneralContentScreen = ({
107
108
 
108
109
  const isReady = useRiverActionProviderReady();
109
110
 
111
+ countRender("GeneralContentScreen", {
112
+ screenId,
113
+ isReady,
114
+ componentsCount: (components || uiComponents)?.length,
115
+ });
116
+
110
117
  const contextValue = React.useMemo(
111
118
  () => whenMatchingType(Function, cellTapAction) || onCellTapAction,
112
119
  [typeof cellTapAction === "function" ? cellTapAction : onCellTapAction]
@@ -11,6 +11,20 @@ type HookComponentProps = HookPluginProps & {
11
11
  function GeneralContentScreenHookComponent(props: HookComponentProps) {
12
12
  const { hookPlugin, focused, parentFocus } = props;
13
13
 
14
+ const componentsMapExtraPropsMemo = React.useMemo(
15
+ () => ({
16
+ safeArea: {
17
+ edges: {
18
+ top: "additive",
19
+ bottom: "additive",
20
+ left: "off",
21
+ right: "off",
22
+ },
23
+ },
24
+ }),
25
+ []
26
+ );
27
+
14
28
  if (!hookPlugin?.screen_id) {
15
29
  log_error(
16
30
  "GeneralContentScreenHookAdapter: This component should only be used as a hook, but no hookPlugin was provided."
@@ -26,6 +40,7 @@ function GeneralContentScreenHookComponent(props: HookComponentProps) {
26
40
  isScreenWrappedInContainer={false}
27
41
  focused={focused}
28
42
  parentFocus={parentFocus}
43
+ componentsMapExtraProps={componentsMapExtraPropsMemo}
29
44
  />
30
45
  </HookContentFocusGroup>
31
46
  );
@@ -0,0 +1,294 @@
1
+ import {
2
+ looksLikeSkipExpression,
3
+ parseSkipExpression,
4
+ evaluateSkipExpression,
5
+ } from "../skipExpression";
6
+
7
+ jest.mock("../logger", () => ({
8
+ log_debug: jest.fn(),
9
+ log_error: jest.fn(),
10
+ log_info: jest.fn(),
11
+ }));
12
+
13
+ const TOKEN = "quick-brick-login-flow.access_token";
14
+ const PROFILE = "user_account.profile";
15
+
16
+ /**
17
+ * Stands in for `getKeyToSkipHook`: resolves a "namespace.key" store, so the
18
+ * expression evaluator is exercised against real lookups rather than mocks.
19
+ */
20
+ const storage = (store: Record<string, unknown>) =>
21
+ jest.fn((key: string, namespace?: string) =>
22
+ Promise.resolve(store[`${namespace}.${key}`])
23
+ );
24
+
25
+ const evaluate = (expression: unknown, store: Record<string, unknown> = {}) =>
26
+ evaluateSkipExpression(parseSkipExpression(expression), storage(store));
27
+
28
+ describe("looksLikeSkipExpression", () => {
29
+ it("recognises a JSON object, whatever its content", () => {
30
+ expect(looksLikeSkipExpression('{"exists":"ns.key"}')).toBe(true);
31
+ expect(looksLikeSkipExpression(' {"exists":"ns.key"} ')).toBe(true);
32
+ expect(looksLikeSkipExpression({ exists: "ns.key" })).toBe(true);
33
+ });
34
+
35
+ it("recognises a malformed expression, so it is never read as a key list", () => {
36
+ expect(looksLikeSkipExpression('{"any":')).toBe(true);
37
+ });
38
+
39
+ it("rejects a legacy comma-separated key list", () => {
40
+ expect(looksLikeSkipExpression("ns1.key1, ns2.key2")).toBe(false);
41
+ });
42
+
43
+ it("rejects empty and missing input", () => {
44
+ expect(looksLikeSkipExpression("")).toBe(false);
45
+ expect(looksLikeSkipExpression(" ")).toBe(false);
46
+ expect(looksLikeSkipExpression(undefined)).toBe(false);
47
+ });
48
+ });
49
+
50
+ describe("parseSkipExpression", () => {
51
+ it("parses a JSON string into an expression object", () => {
52
+ expect(parseSkipExpression('{"exists":"ns.key"}')).toEqual({
53
+ exists: "ns.key",
54
+ });
55
+ });
56
+
57
+ it("ignores leading and trailing whitespace around the JSON", () => {
58
+ expect(parseSkipExpression(' {"exists":"ns.key"} ')).toEqual({
59
+ exists: "ns.key",
60
+ });
61
+ });
62
+
63
+ it("accepts an expression that is already an object", () => {
64
+ expect(parseSkipExpression({ exists: "ns.key" })).toEqual({
65
+ exists: "ns.key",
66
+ });
67
+ });
68
+
69
+ it("returns null for a legacy comma-separated key list", () => {
70
+ expect(parseSkipExpression("ns1.key1, ns2.key2")).toBeNull();
71
+ });
72
+
73
+ it("returns null for a malformed JSON object", () => {
74
+ expect(parseSkipExpression('{"exists":')).toBeNull();
75
+ });
76
+
77
+ it("returns null for empty and missing input", () => {
78
+ expect(parseSkipExpression("")).toBeNull();
79
+ expect(parseSkipExpression(undefined)).toBeNull();
80
+ expect(parseSkipExpression(null)).toBeNull();
81
+ });
82
+
83
+ it("returns null for a JSON array, which is not a valid expression", () => {
84
+ expect(parseSkipExpression('["ns.key"]')).toBeNull();
85
+ });
86
+ });
87
+
88
+ describe("evaluateSkipExpression", () => {
89
+ it("returns false when there is no expression", async () => {
90
+ await expect(evaluateSkipExpression(null, storage({}))).resolves.toBe(
91
+ false
92
+ );
93
+ });
94
+
95
+ describe("exists", () => {
96
+ it("is true when the key holds a value", async () => {
97
+ await expect(
98
+ evaluate({ exists: "ns.key" }, { "ns.key": "value" })
99
+ ).resolves.toBe(true);
100
+ });
101
+
102
+ it("is false when the key is absent", async () => {
103
+ await expect(evaluate({ exists: "ns.key" })).resolves.toBe(false);
104
+ });
105
+
106
+ it("is false when the key holds an empty string", async () => {
107
+ await expect(
108
+ evaluate({ exists: "ns.key" }, { "ns.key": "" })
109
+ ).resolves.toBe(false);
110
+ });
111
+
112
+ it("splits the namespace on the last dot, like the legacy format", async () => {
113
+ const readKey = storage({ "com.applicaster.feature.someKey": "value" });
114
+
115
+ await evaluateSkipExpression(
116
+ { exists: "com.applicaster.feature.someKey" },
117
+ readKey
118
+ );
119
+
120
+ expect(readKey).toHaveBeenCalledWith(
121
+ "someKey",
122
+ "com.applicaster.feature"
123
+ );
124
+ });
125
+
126
+ it("treats a bare string operand as a shorthand for exists", async () => {
127
+ await expect(
128
+ evaluateSkipExpression("ns.key", storage({ "ns.key": "value" }))
129
+ ).resolves.toBe(true);
130
+ });
131
+ });
132
+
133
+ describe("missing", () => {
134
+ it("is true when the key is absent", async () => {
135
+ await expect(evaluate({ missing: "ns.key" })).resolves.toBe(true);
136
+ });
137
+
138
+ it("is false when the key holds a value", async () => {
139
+ await expect(
140
+ evaluate({ missing: "ns.key" }, { "ns.key": "value" })
141
+ ).resolves.toBe(false);
142
+ });
143
+ });
144
+
145
+ describe("equals", () => {
146
+ it("is true when the stored value matches", async () => {
147
+ await expect(
148
+ evaluate(
149
+ { equals: { key: "ns.key", value: "kids" } },
150
+ { "ns.key": "kids" }
151
+ )
152
+ ).resolves.toBe(true);
153
+ });
154
+
155
+ it("is false when the stored value differs", async () => {
156
+ await expect(
157
+ evaluate(
158
+ { equals: { key: "ns.key", value: "kids" } },
159
+ { "ns.key": "adults" }
160
+ )
161
+ ).resolves.toBe(false);
162
+ });
163
+
164
+ it("compares a non-string stored value by its string form", async () => {
165
+ await expect(
166
+ evaluate({ equals: { key: "ns.key", value: "42" } }, { "ns.key": 42 })
167
+ ).resolves.toBe(true);
168
+ });
169
+ });
170
+
171
+ describe("all", () => {
172
+ it("is true only when every operand is true", async () => {
173
+ await expect(
174
+ evaluate({ all: ["ns.a", "ns.b"] }, { "ns.a": "1", "ns.b": "2" })
175
+ ).resolves.toBe(true);
176
+ });
177
+
178
+ it("is false when one operand is false", async () => {
179
+ await expect(
180
+ evaluate({ all: ["ns.a", "ns.b"] }, { "ns.a": "1" })
181
+ ).resolves.toBe(false);
182
+ });
183
+
184
+ it("stops reading storage after the first false operand", async () => {
185
+ const readKey = storage({ "ns.b": "2" });
186
+
187
+ await evaluateSkipExpression({ all: ["ns.a", "ns.b"] }, readKey);
188
+
189
+ expect(readKey).toHaveBeenCalledTimes(1);
190
+ });
191
+
192
+ it("is false for an empty operand list", async () => {
193
+ await expect(evaluate({ all: [] })).resolves.toBe(false);
194
+ });
195
+ });
196
+
197
+ describe("any", () => {
198
+ it("is true when one operand is true", async () => {
199
+ await expect(
200
+ evaluate({ any: ["ns.a", "ns.b"] }, { "ns.b": "2" })
201
+ ).resolves.toBe(true);
202
+ });
203
+
204
+ it("is false when every operand is false", async () => {
205
+ await expect(evaluate({ any: ["ns.a", "ns.b"] })).resolves.toBe(false);
206
+ });
207
+
208
+ it("stops reading storage after the first true operand", async () => {
209
+ const readKey = storage({ "ns.a": "1", "ns.b": "2" });
210
+
211
+ await evaluateSkipExpression({ any: ["ns.a", "ns.b"] }, readKey);
212
+
213
+ expect(readKey).toHaveBeenCalledTimes(1);
214
+ });
215
+
216
+ it("is false for an empty operand list", async () => {
217
+ await expect(evaluate({ any: [] })).resolves.toBe(false);
218
+ });
219
+ });
220
+
221
+ describe("not", () => {
222
+ it("inverts a true operand", async () => {
223
+ await expect(
224
+ evaluate({ not: "ns.key" }, { "ns.key": "value" })
225
+ ).resolves.toBe(false);
226
+ });
227
+
228
+ it("inverts a false operand", async () => {
229
+ await expect(evaluate({ not: "ns.key" })).resolves.toBe(true);
230
+ });
231
+ });
232
+
233
+ describe("malformed expressions fail open", () => {
234
+ it("is false for an unknown operator", async () => {
235
+ await expect(evaluate({ matches: "ns.key" })).resolves.toBe(false);
236
+ });
237
+
238
+ it("is false for an operator carrying the wrong operand type", async () => {
239
+ await expect(evaluate({ exists: 42 })).resolves.toBe(false);
240
+ await expect(evaluate({ all: "ns.key" })).resolves.toBe(false);
241
+ });
242
+
243
+ it("is false for an operand list holding a malformed node", async () => {
244
+ await expect(
245
+ evaluate({ all: ["ns.a", { matches: "ns.b" }] }, { "ns.a": "1" })
246
+ ).resolves.toBe(false);
247
+ });
248
+
249
+ it("is false when a storage read throws", async () => {
250
+ const readKey = jest.fn(() => Promise.reject(new Error("storage error")));
251
+
252
+ await expect(
253
+ evaluateSkipExpression({ exists: "ns.key" }, readKey)
254
+ ).resolves.toBe(false);
255
+ });
256
+
257
+ it("keeps evaluating the other operands when one storage read throws", async () => {
258
+ const readKey = jest.fn((key: string) =>
259
+ key === "a"
260
+ ? Promise.reject(new Error("storage error"))
261
+ : Promise.resolve("value")
262
+ );
263
+
264
+ await expect(
265
+ evaluateSkipExpression({ any: ["ns.a", "ns.b"] }, readKey)
266
+ ).resolves.toBe(true);
267
+ });
268
+ });
269
+
270
+ describe("profile selector scenario", () => {
271
+ const skipProfileSelector = {
272
+ any: [{ missing: TOKEN }, { exists: PROFILE }],
273
+ };
274
+
275
+ it("shows the hook to a logged-in user who has not picked a profile yet", async () => {
276
+ await expect(
277
+ evaluate(skipProfileSelector, { [TOKEN]: "a-token" })
278
+ ).resolves.toBe(false);
279
+ });
280
+
281
+ it("skips the hook for a logged-out user", async () => {
282
+ await expect(evaluate(skipProfileSelector)).resolves.toBe(true);
283
+ });
284
+
285
+ it("skips the hook once a profile has been picked", async () => {
286
+ await expect(
287
+ evaluate(skipProfileSelector, {
288
+ [TOKEN]: "a-token",
289
+ [PROFILE]: "profile-id",
290
+ })
291
+ ).resolves.toBe(true);
292
+ });
293
+ });
294
+ });
@@ -122,3 +122,67 @@ describe("shouldSkipHook", () => {
122
122
  await expect(shouldSkipHook("ns1.key1, ns2.key2")).resolves.toBe(true);
123
123
  });
124
124
  });
125
+
126
+ describe("shouldSkipHook with a packed expression", () => {
127
+ const SKIP_UNLESS_LOGGED_IN_WITHOUT_PROFILE = JSON.stringify({
128
+ any: [
129
+ { missing: "quick-brick-login-flow.access_token" },
130
+ { exists: "user_account.profile" },
131
+ ],
132
+ });
133
+
134
+ const storedKeys = (store: Record<string, string>) => {
135
+ mockSessionGetItem.mockImplementation((key, namespace) =>
136
+ Promise.resolve(store[`${namespace}.${key}`] ?? null)
137
+ );
138
+
139
+ mockLocalGetItem.mockResolvedValue(null);
140
+ };
141
+
142
+ beforeEach(() => {
143
+ jest.clearAllMocks();
144
+ storedKeys({});
145
+ });
146
+
147
+ it("does not skip for a logged-in user who has not picked a profile yet", async () => {
148
+ storedKeys({ "quick-brick-login-flow.access_token": "a-token" });
149
+
150
+ await expect(
151
+ shouldSkipHook(SKIP_UNLESS_LOGGED_IN_WITHOUT_PROFILE)
152
+ ).resolves.toBe(false);
153
+ });
154
+
155
+ it("skips for a logged-out user", async () => {
156
+ await expect(
157
+ shouldSkipHook(SKIP_UNLESS_LOGGED_IN_WITHOUT_PROFILE)
158
+ ).resolves.toBe(true);
159
+ });
160
+
161
+ it("skips once a profile has been picked", async () => {
162
+ storedKeys({
163
+ "quick-brick-login-flow.access_token": "a-token",
164
+ "user_account.profile": "profile-id",
165
+ });
166
+
167
+ await expect(
168
+ shouldSkipHook(SKIP_UNLESS_LOGGED_IN_WITHOUT_PROFILE)
169
+ ).resolves.toBe(true);
170
+ });
171
+
172
+ it("falls back to local storage for a key the session does not hold", async () => {
173
+ mockLocalGetItem.mockResolvedValue("a-token");
174
+
175
+ await expect(
176
+ shouldSkipHook(JSON.stringify({ exists: "ns.key" }))
177
+ ).resolves.toBe(true);
178
+
179
+ expect(mockSessionGetItem).toHaveBeenCalledWith("key", "ns");
180
+ expect(mockLocalGetItem).toHaveBeenCalledWith("key", "ns");
181
+ });
182
+
183
+ it("returns false for a malformed expression instead of reading storage", async () => {
184
+ await expect(shouldSkipHook('{"any":')).resolves.toBe(false);
185
+ expect(mockSessionGetItem).not.toHaveBeenCalled();
186
+ expect(mockLocalGetItem).not.toHaveBeenCalled();
187
+ });
188
+ });