@applicaster/zapp-react-native-ui-components 16.0.0-alpha.7845362739 → 16.0.0-alpha.8101951023
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/Components/AudioPlayer/tv/__tests__/audioPlayer.test.js +19 -0
- package/Components/AudioPlayer/tv/__tests__/index.test.tsx +120 -0
- package/Components/AudioPlayer/tv/index.tsx +5 -1
- package/Components/Cell/Cell.tsx +3 -6
- package/Components/Cell/TvOSCellComponent.tsx +0 -1
- package/Components/GeneralContentScreen/GeneralContentScreenHookAdapter.tsx +15 -0
- package/Components/GeneralContentScreen/hookAdapter/__tests__/skipExpression.test.ts +294 -0
- package/Components/GeneralContentScreen/hookAdapter/__tests__/validationHelper.test.ts +64 -0
- package/Components/GeneralContentScreen/hookAdapter/skipExpression.ts +252 -0
- package/Components/GeneralContentScreen/hookAdapter/validationHelper.ts +18 -0
- package/Components/LinkHandler/LinkHandler.tsx +2 -7
- package/Components/MasterCell/DefaultComponents/ActionButton.tsx +5 -1
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/components/ActionButtonController.tsx +19 -4
- package/Components/MasterCell/DefaultComponents/ActionButtonsCore/components/__tests__/ActionButtonController.test.tsx +43 -1
- package/Components/MasterCell/DefaultComponents/Button.tsx +1 -0
- package/Components/MasterCell/DefaultComponents/LiveImage/executePreloadHooks.ts +2 -4
- package/Components/MasterCell/DefaultComponents/LiveImage/index.tsx +2 -3
- package/Components/MasterCell/DefaultComponents/Toggle.tsx +36 -14
- package/Components/MasterCell/DefaultComponents/__tests__/Toggle.test.tsx +167 -0
- package/Components/MasterCell/SharedUI/CollapsibleTextContainer/__tests__/factory.test.ts +32 -0
- package/Components/MasterCell/SharedUI/CollapsibleTextContainer/index.ts +1 -2
- package/Components/ModalComponent/ActionsBottomSheet/ActionButton.tsx +56 -0
- package/Components/ModalComponent/ActionsBottomSheet/__tests__/openActionsBottomSheet.test.ts +38 -0
- package/Components/ModalComponent/ActionsBottomSheet/boundActionButton.tsx +24 -0
- package/Components/ModalComponent/ActionsBottomSheet/index.ts +9 -0
- package/Components/ModalComponent/ActionsBottomSheet/openActionsBottomSheet.ts +61 -0
- package/Components/ModalComponent/AudioPlayer/Components/Button.tsx +87 -97
- package/Components/ModalComponent/AudioPlayer/Components/Header.tsx +87 -126
- package/Components/ModalComponent/AudioPlayer/Components/Input.tsx +1 -44
- package/Components/ModalComponent/AudioPlayer/Components/Item.tsx +252 -123
- package/Components/ModalComponent/AudioPlayer/Components/NowPlayingHeaderSection.tsx +84 -0
- package/Components/ModalComponent/AudioPlayer/Components/__tests__/Item.test.tsx +113 -0
- package/Components/ModalComponent/AudioPlayer/Components/index.ts +3 -3
- package/Components/ModalComponent/AudioPlayer/utils/__tests__/mergeStyles.test.ts +356 -0
- package/Components/ModalComponent/AudioPlayer/utils/mergeStyles.ts +521 -0
- package/Components/ModalComponent/BottomSheetModalContent.tsx +488 -66
- package/Components/ModalComponent/Button/index.tsx +5 -3
- package/Components/ModalComponent/Header/CloseButton.tsx +12 -0
- package/Components/ModalComponent/Header/__tests__/CloseButton.test.tsx +72 -0
- package/Components/ModalComponent/Header/index.tsx +20 -7
- package/Components/ModalComponent/Header/utils.ts +1 -1
- package/Components/ModalComponent/ModalBlocksStyleContext.tsx +10 -0
- package/Components/ModalComponent/SortableList.tsx +157 -0
- package/Components/ModalComponent/SortableList.web.tsx +34 -0
- package/Components/ModalComponent/TextInputContent.tsx +112 -0
- package/Components/ModalComponent/__tests__/BottomSheetModalContent.test.tsx +270 -0
- package/Components/ModalComponent/__tests__/SortableList.web.test.tsx +16 -0
- package/Components/ModalComponent/__tests__/TextInputContent.test.tsx +156 -0
- package/Components/ModalComponent/__tests__/showTextInput.test.ts +95 -0
- package/Components/ModalComponent/index.tsx +18 -9
- package/Components/ModalComponent/presets/__tests__/getCell.test.ts +90 -0
- package/Components/ModalComponent/presets/dynamicCollectionCell.tsx +78 -0
- package/Components/ModalComponent/presets/index.ts +27 -0
- package/Components/ModalComponent/presets/selectableCell.tsx +28 -0
- package/Components/ModalComponent/presets/standardCell.tsx +41 -0
- package/Components/ModalComponent/presets/types.ts +35 -0
- package/Components/ModalComponent/showTextInput.ts +43 -0
- package/Components/ModalComponent/utils.ts +82 -21
- package/Components/OfflineHandler/hooks.ts +0 -12
- package/Components/PlayerContainer/PlayerContainer.tsx +11 -7
- package/Components/PlayerContainer/ProgramInfo/index.tsx +3 -4
- package/Components/PlayerContainer/__tests__/PlayerContainer.test.tsx +66 -13
- package/Components/River/ComponentsMap/ComponentsMap.tsx +85 -59
- package/Components/River/River.tsx +4 -0
- package/Components/River/__tests__/__snapshots__/componentsMap.test.js.snap +138 -75
- package/Components/River/__tests__/componentsMap.test.js +8 -3
- package/Components/River/__tests__/resultCallback.test.tsx +47 -0
- package/Components/Screen/__tests__/Screen.test.tsx +24 -0
- package/Components/Screen/__tests__/__snapshots__/Screen.test.tsx.snap +2 -0
- package/Components/Screen/index.tsx +5 -0
- package/Components/Screen/navigationHandler.ts +8 -8
- package/Components/ScreenRevealManager/ScreenRevealManager.ts +18 -2
- package/Components/ScreenRevealManager/__tests__/ScreenRevealManager.test.ts +36 -0
- package/Components/ScreenRevealManager/__tests__/withScreenRevealManager.test.tsx +56 -0
- package/Components/ScreenRevealManager/withScreenRevealManager.tsx +21 -4
- package/Components/VideoLive/LiveImageManager.ts +1 -1
- package/Contexts/ModalNavigationContext/__tests__/index.test.tsx +15 -0
- package/Contexts/ModalNavigationContext/index.tsx +2 -2
- package/Hooks/useEntryActionsExpander.ts +63 -0
- package/package.json +6 -5
- package/Components/ModalComponent/AudioPlayer/Components/Action.tsx +0 -332
- /package/Decorators/ZappPipesDataConnector/__tests__/{Hero.js → Hero.tsx} +0 -0
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { render } from "@testing-library/react-native";
|
|
3
3
|
|
|
4
|
+
let mockContent = { title: null, summary: null };
|
|
5
|
+
|
|
6
|
+
// Read lazily inside the factory: `jest.mock` is hoisted above the `let` above,
|
|
7
|
+
// so capturing the value eagerly would freeze it at `undefined`.
|
|
8
|
+
jest.mock(
|
|
9
|
+
"@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayerContent",
|
|
10
|
+
() => ({ usePlayerContent: () => mockContent })
|
|
11
|
+
);
|
|
12
|
+
|
|
4
13
|
import { AudioPlayerTV } from "..";
|
|
5
14
|
|
|
6
15
|
jest.mock("@applicaster/zapp-react-native-utils/audioPlayerUtils", () => ({
|
|
@@ -51,7 +60,17 @@ const audioPlayerProps = {
|
|
|
51
60
|
|
|
52
61
|
describe("<AudioPlayerTV />", () => {
|
|
53
62
|
it("renders correctly", () => {
|
|
63
|
+
// AudioPlayerTV no longer resolves its own title/summary from
|
|
64
|
+
// audio_item - it reads them from the player manager's content channel.
|
|
65
|
+
// Publishing the same values `audio_item.title`/`.summary` used to resolve
|
|
66
|
+
// to keeps this snapshot byte-for-byte identical to before that change.
|
|
67
|
+
mockContent = {
|
|
68
|
+
title: audioPlayerProps.audio_item.title,
|
|
69
|
+
summary: audioPlayerProps.audio_item.summary,
|
|
70
|
+
};
|
|
71
|
+
|
|
54
72
|
const { toJSON } = render(<AudioPlayerTV {...audioPlayerProps} />);
|
|
73
|
+
|
|
55
74
|
expect(toJSON()).toMatchSnapshot();
|
|
56
75
|
});
|
|
57
76
|
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { render } from "@testing-library/react-native";
|
|
3
|
+
|
|
4
|
+
import { AudioPlayerTV } from "..";
|
|
5
|
+
|
|
6
|
+
jest.mock("@applicaster/zapp-react-native-utils/audioPlayerUtils", () => ({
|
|
7
|
+
useArtworkImage: jest.fn(() => "artwork_url"),
|
|
8
|
+
}));
|
|
9
|
+
|
|
10
|
+
let mockContent: {
|
|
11
|
+
title: Option<string | number>;
|
|
12
|
+
summary: Option<string | number>;
|
|
13
|
+
} = { title: null, summary: null };
|
|
14
|
+
|
|
15
|
+
// Read lazily inside the factory: `jest.mock` is hoisted above the `let`
|
|
16
|
+
// above, so capturing the value eagerly would freeze it at `undefined`.
|
|
17
|
+
jest.mock(
|
|
18
|
+
"@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayerContent",
|
|
19
|
+
() => ({ usePlayerContent: () => mockContent })
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
const baseAudioItem = {
|
|
23
|
+
title: "tittle",
|
|
24
|
+
summary: "Summary",
|
|
25
|
+
content: {
|
|
26
|
+
src: "https://example.com",
|
|
27
|
+
},
|
|
28
|
+
media_group: [
|
|
29
|
+
{
|
|
30
|
+
type: "audio",
|
|
31
|
+
media_item: [
|
|
32
|
+
{
|
|
33
|
+
type: "audio",
|
|
34
|
+
src: "https://example.com",
|
|
35
|
+
key: "base_code",
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
],
|
|
40
|
+
extensions: {
|
|
41
|
+
audio_player_artwork_aspect_ratio: "1:1",
|
|
42
|
+
audio_player_background_image: "https://example.com",
|
|
43
|
+
audio_player_background_color: "black",
|
|
44
|
+
audio_player_channel_icon: "https://example.com",
|
|
45
|
+
audio_player_title_color: "white",
|
|
46
|
+
audio_player_summary_color: "white",
|
|
47
|
+
audio_player_rtl: true,
|
|
48
|
+
start_time: "10:10",
|
|
49
|
+
end_time: "11:11",
|
|
50
|
+
episode_name: "Episode Custom Title",
|
|
51
|
+
episode_summary: "Episode Custom Summary",
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const basePluginConfiguration = {
|
|
56
|
+
audio_player_background_color: "black",
|
|
57
|
+
audio_player_title_color: "white",
|
|
58
|
+
audio_player_summary_color: "white",
|
|
59
|
+
audio_player_rtl: true,
|
|
60
|
+
audio_player_background_image: "https://example.com",
|
|
61
|
+
audio_player_artwork_aspect_ratio: "1:1",
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
function renderAudioPlayer(
|
|
65
|
+
plugin_configuration,
|
|
66
|
+
content: {
|
|
67
|
+
title?: Option<string | number>;
|
|
68
|
+
summary?: Option<string | number>;
|
|
69
|
+
} = {}
|
|
70
|
+
) {
|
|
71
|
+
mockContent = {
|
|
72
|
+
title: content.title ?? null,
|
|
73
|
+
summary: content.summary ?? null,
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
return render(
|
|
77
|
+
<AudioPlayerTV
|
|
78
|
+
audio_item={baseAudioItem}
|
|
79
|
+
plugin_configuration={plugin_configuration}
|
|
80
|
+
style={{}}
|
|
81
|
+
/>
|
|
82
|
+
);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
describe("<AudioPlayerTV /> player content", () => {
|
|
86
|
+
it("renders the title and summary published by the player manager", () => {
|
|
87
|
+
const { getByText } = renderAudioPlayer(basePluginConfiguration, {
|
|
88
|
+
title: "Episode Custom Title",
|
|
89
|
+
summary: "Episode Custom Summary",
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
expect(getByText("Episode Custom Title")).toBeTruthy();
|
|
93
|
+
expect(getByText("Episode Custom Summary")).toBeTruthy();
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("renders nothing for title/summary when the player published neither", () => {
|
|
97
|
+
const { queryByText } = renderAudioPlayer(basePluginConfiguration);
|
|
98
|
+
|
|
99
|
+
expect(queryByText("tittle")).toBeNull();
|
|
100
|
+
expect(queryByText("Summary")).toBeNull();
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it("renders blank rather than crashing when no player is active", () => {
|
|
104
|
+
// `usePlayerContent` returns `{ title: null, summary: null }` when there is
|
|
105
|
+
// no player. A regression here means AudioPlayerTV crashes instead of
|
|
106
|
+
// rendering blank.
|
|
107
|
+
mockContent = { title: null, summary: null };
|
|
108
|
+
|
|
109
|
+
const { queryByText } = render(
|
|
110
|
+
<AudioPlayerTV
|
|
111
|
+
audio_item={baseAudioItem}
|
|
112
|
+
plugin_configuration={basePluginConfiguration}
|
|
113
|
+
style={{}}
|
|
114
|
+
/>
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
expect(queryByText("tittle")).toBeNull();
|
|
118
|
+
expect(queryByText("Summary")).toBeNull();
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -3,6 +3,8 @@ import React, { useCallback, useMemo } from "react";
|
|
|
3
3
|
import { platformSelect } from "@applicaster/zapp-react-native-utils/reactUtils";
|
|
4
4
|
import { useArtworkImage } from "@applicaster/zapp-react-native-utils/audioPlayerUtils";
|
|
5
5
|
|
|
6
|
+
import { usePlayerContent } from "@applicaster/zapp-react-native-utils/appUtils/playerManager/usePlayerContent";
|
|
7
|
+
|
|
6
8
|
import { AudioPlayerTVLayout } from "./Layout";
|
|
7
9
|
|
|
8
10
|
import { Channel } from "./Channel";
|
|
@@ -15,10 +17,12 @@ import { Props } from "../types";
|
|
|
15
17
|
|
|
16
18
|
export function AudioPlayerTV(props: Props) {
|
|
17
19
|
const { audio_item, plugin_configuration, style = {} } = props;
|
|
18
|
-
const { extensions
|
|
20
|
+
const { extensions } = audio_item;
|
|
19
21
|
|
|
20
22
|
const artwork = useArtworkImage(audio_item);
|
|
21
23
|
|
|
24
|
+
const { title, summary } = usePlayerContent();
|
|
25
|
+
|
|
22
26
|
const getProp = useCallback(
|
|
23
27
|
getPropertyFromEntryOrConfig({
|
|
24
28
|
entry: audio_item,
|
package/Components/Cell/Cell.tsx
CHANGED
|
@@ -134,7 +134,7 @@ export class CellComponent extends React.Component<Props, State> {
|
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
|
|
137
|
-
onFocus(focusable
|
|
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
|
|
262
|
+
this.onFocus(focusable);
|
|
266
263
|
};
|
|
267
264
|
|
|
268
265
|
if (this.state.hasFocusableInside) {
|
|
@@ -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
|
+
});
|