@applicaster/zapp-react-native-utils 14.0.0-rc.9 → 15.0.0-rc.2
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/actionsExecutor/ActionExecutorContext.tsx +60 -84
- package/actionsExecutor/ScreenActions.ts +164 -0
- package/actionsExecutor/StorageActions.ts +110 -0
- package/actionsExecutor/feedDecorator.ts +171 -0
- package/actionsExecutor/screenResolver.ts +11 -0
- package/analyticsUtils/AnalyticsEvents/helper.ts +81 -0
- package/analyticsUtils/AnalyticsEvents/sendHeaderClickEvent.ts +1 -1
- package/analyticsUtils/AnalyticsEvents/sendMenuClickEvent.ts +2 -1
- package/analyticsUtils/AnalyticsEvents/sendOnClickEvent.ts +14 -4
- package/analyticsUtils/__tests__/analyticsUtils.test.js +3 -0
- package/analyticsUtils/events.ts +8 -0
- package/analyticsUtils/index.tsx +3 -4
- package/analyticsUtils/manager.ts +1 -1
- package/analyticsUtils/playerAnalyticsTracker.ts +2 -1
- package/appUtils/HooksManager/Hook.ts +4 -4
- package/appUtils/HooksManager/index.ts +11 -1
- package/appUtils/accessibilityManager/const.ts +13 -0
- package/appUtils/accessibilityManager/hooks.ts +35 -1
- package/appUtils/accessibilityManager/index.ts +154 -30
- package/appUtils/accessibilityManager/utils.ts +24 -0
- package/appUtils/contextKeysManager/contextResolver.ts +42 -1
- package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +7 -0
- package/appUtils/focusManager/__tests__/focusManager.test.js +1 -1
- package/appUtils/focusManager/events.ts +2 -0
- package/appUtils/focusManager/index.ios.ts +10 -0
- package/appUtils/focusManager/index.ts +86 -11
- package/appUtils/focusManager/treeDataStructure/Tree/index.js +1 -1
- package/appUtils/focusManagerAux/utils/index.ts +94 -3
- package/appUtils/platform/platformUtils.ts +31 -1
- package/appUtils/playerManager/OverlayObserver/OverlaysObserver.ts +0 -15
- package/appUtils/playerManager/useChapterMarker.tsx +0 -1
- package/appUtils/playerManager/usePlayerControllerSetup.tsx +16 -0
- package/arrayUtils/__tests__/isEmptyArray.test.ts +63 -0
- package/arrayUtils/__tests__/isFilledArray.test.ts +1 -1
- package/arrayUtils/index.ts +8 -3
- package/audioPlayerUtils/__tests__/getArtworkImage.test.ts +144 -0
- package/audioPlayerUtils/__tests__/getBackgroundImage.test.ts +72 -0
- package/audioPlayerUtils/__tests__/getImageFromEntry.test.ts +110 -0
- package/audioPlayerUtils/assets/index.ts +2 -0
- package/audioPlayerUtils/index.ts +242 -0
- package/componentsUtils/__tests__/isTabsScreen.test.ts +38 -0
- package/componentsUtils/index.ts +4 -1
- package/conf/player/__tests__/selectors.test.ts +34 -0
- package/conf/player/selectors.ts +10 -0
- package/configurationUtils/__tests__/configurationUtils.test.js +0 -31
- package/configurationUtils/__tests__/getMediaItems.test.ts +65 -0
- package/configurationUtils/__tests__/imageSrcFromMediaItem.test.ts +34 -0
- package/configurationUtils/__tests__/manifestKeyParser.test.ts +546 -0
- package/configurationUtils/index.ts +64 -35
- package/configurationUtils/manifestKeyParser.ts +57 -32
- package/focusManager/FocusManager.ts +104 -20
- package/focusManager/Tree.ts +25 -21
- package/focusManager/__tests__/FocusManager.test.ts +50 -8
- package/focusManager/aux/index.ts +98 -0
- package/focusManager/utils.ts +12 -6
- package/index.d.ts +1 -10
- package/manifestUtils/_internals/getDefaultConfiguration.js +28 -0
- package/manifestUtils/{_internals.js → _internals/index.js} +2 -25
- package/manifestUtils/createConfig.js +4 -1
- package/manifestUtils/defaultManifestConfigurations/player.js +2764 -1539
- package/manifestUtils/index.js +4 -0
- package/manifestUtils/keys.js +12 -0
- package/manifestUtils/progressBar/__tests__/mobileProgressBar.test.js +0 -30
- package/manifestUtils/sharedConfiguration/screenPicker/stylesFields.js +6 -0
- package/navigationUtils/__tests__/mapContentTypesToRivers.test.ts +130 -0
- package/navigationUtils/index.ts +7 -5
- package/package.json +2 -3
- package/playerUtils/PlayerTTS/PlayerTTS.ts +359 -0
- package/playerUtils/PlayerTTS/index.ts +1 -0
- package/playerUtils/__tests__/configurationUtils.test.ts +1 -65
- package/playerUtils/__tests__/getPlayerActionButtons.test.ts +54 -0
- package/playerUtils/_internals/__tests__/utils.test.ts +71 -0
- package/playerUtils/_internals/index.ts +1 -0
- package/playerUtils/_internals/utils.ts +31 -0
- package/playerUtils/configurationUtils.ts +0 -44
- package/playerUtils/getPlayerActionButtons.ts +17 -0
- package/playerUtils/index.ts +53 -0
- package/playerUtils/usePlayerTTS.ts +21 -0
- package/playerUtils/useValidatePlayerConfig.tsx +22 -19
- package/reactHooks/autoscrolling/__tests__/useTrackedView.test.tsx +15 -14
- package/reactHooks/cell-click/__tests__/index.test.js +3 -0
- package/reactHooks/cell-click/index.ts +8 -1
- package/reactHooks/debugging/__tests__/index.test.js +0 -1
- package/reactHooks/feed/__tests__/useBatchLoading.test.tsx +47 -90
- package/reactHooks/feed/__tests__/useFeedLoader.test.tsx +71 -31
- package/reactHooks/feed/index.ts +2 -0
- package/reactHooks/feed/useBatchLoading.ts +17 -10
- package/reactHooks/feed/useFeedLoader.tsx +36 -34
- package/reactHooks/feed/useLoadPipesDataDispatch.ts +63 -0
- package/reactHooks/feed/usePipesCacheReset.ts +3 -3
- package/reactHooks/flatList/useSequentialRenderItem.tsx +3 -3
- package/reactHooks/layout/__tests__/index.test.tsx +3 -1
- package/reactHooks/layout/isTablet/index.ts +12 -5
- package/reactHooks/layout/useDimensions/__tests__/useDimensions.test.ts +34 -36
- package/reactHooks/layout/useDimensions/useDimensions.ts +2 -3
- package/reactHooks/layout/useLayoutVersion.ts +5 -5
- package/reactHooks/navigation/index.ts +7 -5
- package/reactHooks/navigation/useIsScreenActive.ts +9 -5
- package/reactHooks/navigation/useRoute.ts +7 -2
- package/reactHooks/navigation/useScreenStateStore.ts +8 -0
- package/reactHooks/resolvers/__tests__/useCellResolver.test.tsx +4 -0
- package/reactHooks/screen/useScreenContext.ts +1 -1
- package/reactHooks/state/__tests__/ZStoreProvider.test.tsx +2 -1
- package/reactHooks/state/index.ts +1 -1
- package/reactHooks/state/useHomeRiver.ts +4 -2
- package/reactHooks/state/useRivers.ts +7 -8
- package/riverComponetsMeasurementProvider/index.tsx +1 -1
- package/screenPickerUtils/index.ts +13 -0
- package/services/js2native.ts +1 -0
- package/storage/ScreenSingleValueProvider.ts +204 -0
- package/storage/ScreenStateMultiSelectProvider.ts +293 -0
- package/storage/StorageMultiSelectProvider.ts +192 -0
- package/storage/StorageSingleSelectProvider.ts +108 -0
- package/testUtils/index.tsx +7 -8
- package/time/BackgroundTimer.ts +6 -4
- package/utils/__tests__/endsWith.test.ts +30 -0
- package/utils/__tests__/find.test.ts +36 -0
- package/utils/__tests__/omit.test.ts +19 -0
- package/utils/__tests__/path.test.ts +33 -0
- package/utils/__tests__/pathOr.test.ts +37 -0
- package/utils/__tests__/startsWith.test.ts +30 -0
- package/utils/__tests__/take.test.ts +40 -0
- package/utils/endsWith.ts +9 -0
- package/utils/find.ts +3 -0
- package/utils/index.ts +33 -1
- package/utils/omit.ts +5 -0
- package/utils/path.ts +5 -0
- package/utils/pathOr.ts +5 -0
- package/utils/startsWith.ts +9 -0
- package/utils/take.ts +5 -0
- package/zappFrameworkUtils/HookCallback/callbackNavigationAction.ts +164 -0
- package/zappFrameworkUtils/HookCallback/hookCallbackManifestExtensions.config.js +60 -0
- package/zappFrameworkUtils/HookCallback/useCallbackActions.ts +22 -0
- package/zappFrameworkUtils/loginPluginUtils.ts +1 -1
- package/playerUtils/configurationGenerator.ts +0 -2572
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { get } from "@applicaster/zapp-react-native-utils/utils";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Selects the action buttons from the player configuration.
|
|
5
|
+
* @param {Object} pluginConf - player plugin config
|
|
6
|
+
* @returns {Array|null} An array of action buttons or null if not found.
|
|
7
|
+
*/
|
|
8
|
+
export const selectActionButtons = (pluginConf: any) => {
|
|
9
|
+
return get(pluginConf, "player_action_buttons", null);
|
|
10
|
+
};
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
import * as R from "ramda";
|
|
2
1
|
import {
|
|
3
2
|
populateConfigurationValues,
|
|
4
|
-
imageSrcFromMediaItem,
|
|
5
3
|
getBoolFromConfigValue,
|
|
6
4
|
remapUpdatedKeys,
|
|
7
5
|
} from "../";
|
|
8
|
-
import { entry } from "./testEntry";
|
|
9
6
|
|
|
10
7
|
describe("getBoolFromConfigValue", () => {
|
|
11
8
|
it('returns true if value is "true" string', () => {
|
|
@@ -57,34 +54,6 @@ describe("getBoolFromConfigValue", () => {
|
|
|
57
54
|
});
|
|
58
55
|
});
|
|
59
56
|
|
|
60
|
-
describe("imageSrcFromMediaItem", () => {
|
|
61
|
-
describe("returns the src value of first media_item", () => {
|
|
62
|
-
it("when the matching key is found and the src is not empty", () => {
|
|
63
|
-
const result = imageSrcFromMediaItem(entry, ["logo_thumbnail"]);
|
|
64
|
-
|
|
65
|
-
expect(result).toEqual(entry.media_group[1].media_item[0].src);
|
|
66
|
-
expect(result).not.toEqual("");
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
it("returns a media item with the 'image_base' key as a fallback", () => {
|
|
71
|
-
const result = imageSrcFromMediaItem(entry, ["does_not_exist"]);
|
|
72
|
-
const fallback = entry.media_group[0].media_item[0];
|
|
73
|
-
expect(result).toEqual(fallback.src);
|
|
74
|
-
expect(fallback.key).toBe("image_base");
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it("returns undefined if the key was found but the source was empty", () => {
|
|
78
|
-
const badEntry = R.set(
|
|
79
|
-
R.lensPath(["media_group", 0, "media_item", 0, "src"]),
|
|
80
|
-
"",
|
|
81
|
-
entry
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
expect(imageSrcFromMediaItem(badEntry, ["image_base"])).toBeUndefined();
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
57
|
describe("populateConfigurationValues", () => {
|
|
89
58
|
it("transforms and returns the valid values", () => {
|
|
90
59
|
const fields = [
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { getMediaItems } from "..";
|
|
2
|
+
import { entry as baseEntry } from "./testEntry";
|
|
3
|
+
|
|
4
|
+
describe("getMediaItems", () => {
|
|
5
|
+
it("returns both image and thumbnail media items", () => {
|
|
6
|
+
const items = getMediaItems(baseEntry);
|
|
7
|
+
expect(items).toHaveLength(2);
|
|
8
|
+
expect(items[0].key).toBe("image_base");
|
|
9
|
+
expect(items[1].key).toBe("logo_thumbnail");
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("returns only image media items if no thumbnail present", () => {
|
|
13
|
+
const entry = {
|
|
14
|
+
...baseEntry,
|
|
15
|
+
media_group: [
|
|
16
|
+
{
|
|
17
|
+
type: "image",
|
|
18
|
+
media_item: [
|
|
19
|
+
{ key: "image_base", src: "img.png" },
|
|
20
|
+
{ key: "other", src: "other.png" },
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const items = getMediaItems(entry);
|
|
27
|
+
expect(items).toHaveLength(2);
|
|
28
|
+
expect(items[0].key).toBe("image_base");
|
|
29
|
+
expect(items[1].key).toBe("other");
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("returns only thumbnail media items if no image present", () => {
|
|
33
|
+
const entry = {
|
|
34
|
+
...baseEntry,
|
|
35
|
+
media_group: [
|
|
36
|
+
{
|
|
37
|
+
type: "thumbnail",
|
|
38
|
+
media_item: [{ key: "thumb1", src: "thumb1.png" }],
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const items = getMediaItems(entry);
|
|
44
|
+
expect(items).toHaveLength(1);
|
|
45
|
+
expect(items[0].key).toBe("thumb1");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("returns undefined if no media_group present", () => {
|
|
49
|
+
const entry = { ...baseEntry };
|
|
50
|
+
delete entry.media_group;
|
|
51
|
+
expect(getMediaItems(entry)).toBeUndefined();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("returns undefined if media_group is present but has no image or thumbnail", () => {
|
|
55
|
+
const entry = {
|
|
56
|
+
...baseEntry,
|
|
57
|
+
media_group: [
|
|
58
|
+
{ type: "audio", media_item: [{ key: "audio1", src: "audio1.mp3" }] },
|
|
59
|
+
],
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const items = getMediaItems(entry);
|
|
63
|
+
expect(items).toBeUndefined();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as R from "ramda";
|
|
2
|
+
import { imageSrcFromMediaItem } from "../";
|
|
3
|
+
import { entry } from "./testEntry";
|
|
4
|
+
|
|
5
|
+
describe("imageSrcFromMediaItem", () => {
|
|
6
|
+
it("when the matching key is found and the src is not empty", () => {
|
|
7
|
+
const result = imageSrcFromMediaItem(entry as ZappEntry, [
|
|
8
|
+
"logo_thumbnail",
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
expect(result).toEqual(entry.media_group[1].media_item[0].src);
|
|
12
|
+
expect(result).not.toEqual("");
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("returns a media item with the 'image_base' key as a fallback", () => {
|
|
16
|
+
const result = imageSrcFromMediaItem(entry as ZappEntry, [
|
|
17
|
+
"does_not_exist",
|
|
18
|
+
]);
|
|
19
|
+
|
|
20
|
+
const fallback = entry.media_group[0].media_item[0];
|
|
21
|
+
expect(result).toEqual(fallback.src);
|
|
22
|
+
expect(fallback.key).toBe("image_base");
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("returns undefined if the key was found but the source was empty", () => {
|
|
26
|
+
const badEntry: ZappEntry = R.set(
|
|
27
|
+
R.lensPath(["media_group", 0, "media_item", 0, "src"]),
|
|
28
|
+
"",
|
|
29
|
+
entry
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
expect(imageSrcFromMediaItem(badEntry, ["image_base"])).toBeUndefined();
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,546 @@
|
|
|
1
|
+
import { getAllSpecificStyles } from "../manifestKeyParser";
|
|
2
|
+
|
|
3
|
+
jest.mock("@applicaster/zapp-react-native-utils/reactUtils", () => ({
|
|
4
|
+
platformSelect: jest.fn((platforms) => platforms.samsung_tv), // Default to samsung for tests
|
|
5
|
+
}));
|
|
6
|
+
|
|
7
|
+
jest.mock("@applicaster/zapp-react-native-utils/stringUtils", () => ({
|
|
8
|
+
toCamelCase: jest.fn((str: string) => {
|
|
9
|
+
// Simple camelCase implementation for testing
|
|
10
|
+
return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());
|
|
11
|
+
}),
|
|
12
|
+
}));
|
|
13
|
+
|
|
14
|
+
describe("getAllSpecificStyles", () => {
|
|
15
|
+
beforeEach(() => {
|
|
16
|
+
jest.clearAllMocks();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
describe("Basic functionality", () => {
|
|
20
|
+
it("should throw error if outStyles is not provided", () => {
|
|
21
|
+
expect(() => {
|
|
22
|
+
getAllSpecificStyles({
|
|
23
|
+
componentName: "button",
|
|
24
|
+
subComponentName: "",
|
|
25
|
+
configuration: {},
|
|
26
|
+
outStyles: null as any,
|
|
27
|
+
});
|
|
28
|
+
}).toThrow("outStyles is required");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("should throw error if componentName is not provided", () => {
|
|
32
|
+
expect(() => {
|
|
33
|
+
getAllSpecificStyles({
|
|
34
|
+
componentName: "",
|
|
35
|
+
subComponentName: "",
|
|
36
|
+
configuration: {},
|
|
37
|
+
outStyles: {},
|
|
38
|
+
});
|
|
39
|
+
}).toThrow("componentName is required");
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("should initialize default key if not present", () => {
|
|
43
|
+
const outStyles = {};
|
|
44
|
+
|
|
45
|
+
getAllSpecificStyles({
|
|
46
|
+
componentName: "button",
|
|
47
|
+
subComponentName: "",
|
|
48
|
+
configuration: {},
|
|
49
|
+
outStyles,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
expect(outStyles).toHaveProperty("default");
|
|
53
|
+
expect(outStyles["default"]).toEqual({});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("should handle empty configuration", () => {
|
|
57
|
+
const outStyles = { default: {} };
|
|
58
|
+
|
|
59
|
+
getAllSpecificStyles({
|
|
60
|
+
componentName: "button",
|
|
61
|
+
subComponentName: "",
|
|
62
|
+
configuration: {},
|
|
63
|
+
outStyles,
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
expect(outStyles).toEqual({ default: {} });
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
describe("Style name parsing", () => {
|
|
71
|
+
it("should parse basic style without state or platform", () => {
|
|
72
|
+
const outStyles = {};
|
|
73
|
+
|
|
74
|
+
const configuration = {
|
|
75
|
+
button_style_background_color: "#FF0000",
|
|
76
|
+
button_style_border_width: 2,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
getAllSpecificStyles({
|
|
80
|
+
componentName: "button",
|
|
81
|
+
subComponentName: "",
|
|
82
|
+
configuration,
|
|
83
|
+
outStyles,
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
expect(outStyles["default"]).toEqual({
|
|
87
|
+
backgroundColor: "#FF0000",
|
|
88
|
+
borderWidth: 2,
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("should handle subComponentName correctly", () => {
|
|
93
|
+
const outStyles = {};
|
|
94
|
+
|
|
95
|
+
const configuration = {
|
|
96
|
+
player_controls_style_button_background_color: "#FF0000",
|
|
97
|
+
player_controls_style_button_text_size: 16,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
getAllSpecificStyles({
|
|
101
|
+
componentName: "player_controls",
|
|
102
|
+
subComponentName: "button",
|
|
103
|
+
configuration,
|
|
104
|
+
outStyles,
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
expect(outStyles["default"]).toEqual({
|
|
108
|
+
backgroundColor: "#FF0000",
|
|
109
|
+
textSize: 16,
|
|
110
|
+
});
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it("should ignore keys that do not match the prefix", () => {
|
|
114
|
+
const outStyles = {};
|
|
115
|
+
|
|
116
|
+
const configuration = {
|
|
117
|
+
button_style_background_color: "#FF0000",
|
|
118
|
+
other_component_style_text_color: "#00FF00", // Should be ignored
|
|
119
|
+
random_key: "value", // Should be ignored
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
getAllSpecificStyles({
|
|
123
|
+
componentName: "button",
|
|
124
|
+
subComponentName: "",
|
|
125
|
+
configuration,
|
|
126
|
+
outStyles,
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
expect(outStyles["default"]).toEqual({
|
|
130
|
+
backgroundColor: "#FF0000",
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
describe("State handling", () => {
|
|
136
|
+
it("should handle pressed state", () => {
|
|
137
|
+
const outStyles = {};
|
|
138
|
+
|
|
139
|
+
const configuration = {
|
|
140
|
+
button_style_background_color: "#FF0000",
|
|
141
|
+
button_style_pressed_background_color: "#00FF00",
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
getAllSpecificStyles({
|
|
145
|
+
componentName: "button",
|
|
146
|
+
subComponentName: "",
|
|
147
|
+
configuration,
|
|
148
|
+
outStyles,
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
expect(outStyles["default"]).toEqual({
|
|
152
|
+
backgroundColor: "#FF0000",
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
expect(outStyles["pressed"]).toEqual({
|
|
156
|
+
backgroundColor: "#00FF00",
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("should handle focused state", () => {
|
|
161
|
+
const outStyles = {};
|
|
162
|
+
|
|
163
|
+
const configuration = {
|
|
164
|
+
button_style_focused_border_width: 3,
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
getAllSpecificStyles({
|
|
168
|
+
componentName: "button",
|
|
169
|
+
subComponentName: "",
|
|
170
|
+
configuration,
|
|
171
|
+
outStyles,
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
expect(outStyles["focused"]).toEqual({
|
|
175
|
+
borderWidth: 3,
|
|
176
|
+
});
|
|
177
|
+
});
|
|
178
|
+
|
|
179
|
+
it("should handle selected state", () => {
|
|
180
|
+
const outStyles = {};
|
|
181
|
+
|
|
182
|
+
const configuration = {
|
|
183
|
+
button_style_selected_opacity: 0.5,
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
getAllSpecificStyles({
|
|
187
|
+
componentName: "button",
|
|
188
|
+
subComponentName: "",
|
|
189
|
+
configuration,
|
|
190
|
+
outStyles,
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
expect(outStyles["selected"]).toEqual({
|
|
194
|
+
opacity: 0.5,
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("should handle focused_selected state", () => {
|
|
199
|
+
const outStyles = {};
|
|
200
|
+
|
|
201
|
+
const configuration = {
|
|
202
|
+
button_style_focused_selected_scale: 1.2,
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
getAllSpecificStyles({
|
|
206
|
+
componentName: "button",
|
|
207
|
+
subComponentName: "",
|
|
208
|
+
configuration,
|
|
209
|
+
outStyles,
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
expect(outStyles["focused_selected"]).toEqual({
|
|
213
|
+
scale: 1.2,
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it("should merge default styles into other states", () => {
|
|
218
|
+
const outStyles = {};
|
|
219
|
+
|
|
220
|
+
const configuration = {
|
|
221
|
+
button_style_background_color: "#FF0000",
|
|
222
|
+
button_style_border_width: 1,
|
|
223
|
+
button_style_opacity: 1,
|
|
224
|
+
button_style_pressed_background_color: "#00FF00",
|
|
225
|
+
button_style_focused_opacity: 0.8,
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
getAllSpecificStyles({
|
|
229
|
+
componentName: "button",
|
|
230
|
+
subComponentName: "",
|
|
231
|
+
configuration,
|
|
232
|
+
outStyles,
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
expect(outStyles["default"]).toEqual({
|
|
236
|
+
backgroundColor: "#FF0000",
|
|
237
|
+
borderWidth: 1,
|
|
238
|
+
opacity: 1,
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
// Pressed should have default styles merged with its specific override
|
|
242
|
+
expect(outStyles["pressed"]).toEqual({
|
|
243
|
+
backgroundColor: "#00FF00", // Override
|
|
244
|
+
borderWidth: 1, // From default
|
|
245
|
+
opacity: 1, // From default
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
// Focused should have default styles merged with its specific override
|
|
249
|
+
expect(outStyles["focused"]).toEqual({
|
|
250
|
+
backgroundColor: "#FF0000", // From default
|
|
251
|
+
borderWidth: 1, // From default
|
|
252
|
+
opacity: 0.8, // Override
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
it("should preserve existing state values when merging", () => {
|
|
257
|
+
const outStyles = {
|
|
258
|
+
pressed: { existingKey: "existingValue" },
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
const configuration = {
|
|
262
|
+
button_style_background_color: "#FF0000",
|
|
263
|
+
button_style_pressed_text_color: "#FFFFFF",
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
getAllSpecificStyles({
|
|
267
|
+
componentName: "button",
|
|
268
|
+
subComponentName: "",
|
|
269
|
+
configuration,
|
|
270
|
+
outStyles,
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
expect(outStyles["pressed"]).toEqual({
|
|
274
|
+
existingKey: "existingValue", // Should be preserved
|
|
275
|
+
backgroundColor: "#FF0000", // From default
|
|
276
|
+
textColor: "#FFFFFF", // New pressed style
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
});
|
|
280
|
+
|
|
281
|
+
describe("Platform handling", () => {
|
|
282
|
+
it("should include styles for current platform (samsung)", () => {
|
|
283
|
+
const outStyles = {};
|
|
284
|
+
|
|
285
|
+
const configuration = {
|
|
286
|
+
button_style_samsung_background_color: "#FF0000",
|
|
287
|
+
button_style_background_color: "#00FF00",
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
getAllSpecificStyles({
|
|
291
|
+
componentName: "button",
|
|
292
|
+
subComponentName: "",
|
|
293
|
+
configuration,
|
|
294
|
+
outStyles,
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
expect(outStyles["default"]).toEqual({
|
|
298
|
+
backgroundColor: "#FF0000", // Samsung-specific should be included
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it("should skip styles for other platforms", () => {
|
|
303
|
+
const outStyles = {};
|
|
304
|
+
|
|
305
|
+
const configuration = {
|
|
306
|
+
button_style_ios_background_color: "#FF0000",
|
|
307
|
+
button_style_android_text_color: "#00FF00",
|
|
308
|
+
button_style_tvos_border_width: 2,
|
|
309
|
+
button_style_lg_opacity: 0.5,
|
|
310
|
+
button_style_background_color: "#FFFFFF",
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
getAllSpecificStyles({
|
|
314
|
+
componentName: "button",
|
|
315
|
+
subComponentName: "",
|
|
316
|
+
configuration,
|
|
317
|
+
outStyles,
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
expect(outStyles["default"]).toEqual({
|
|
321
|
+
backgroundColor: "#FFFFFF", // Only non-platform specific
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
|
|
325
|
+
it("should handle platform in middle of style name", () => {
|
|
326
|
+
const outStyles = {};
|
|
327
|
+
|
|
328
|
+
const configuration = {
|
|
329
|
+
button_style_text_samsung_color: "#FF0000",
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
getAllSpecificStyles({
|
|
333
|
+
componentName: "button",
|
|
334
|
+
subComponentName: "text",
|
|
335
|
+
configuration,
|
|
336
|
+
outStyles,
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
expect(outStyles["default"]).toEqual({
|
|
340
|
+
color: "#FF0000",
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
|
|
344
|
+
it("should handle platform-specific styles with states", () => {
|
|
345
|
+
const outStyles = {};
|
|
346
|
+
|
|
347
|
+
const configuration = {
|
|
348
|
+
button_style_samsung_pressed_background_color: "#FF0000",
|
|
349
|
+
button_style_ios_pressed_background_color: "#00FF00", // Should be ignored
|
|
350
|
+
};
|
|
351
|
+
|
|
352
|
+
getAllSpecificStyles({
|
|
353
|
+
componentName: "button",
|
|
354
|
+
subComponentName: "",
|
|
355
|
+
configuration,
|
|
356
|
+
outStyles,
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
expect(outStyles["pressed"]).toEqual({
|
|
360
|
+
backgroundColor: "#FF0000", // Only samsung style
|
|
361
|
+
});
|
|
362
|
+
});
|
|
363
|
+
|
|
364
|
+
it("should work correctly when platform is Samsung", () => {
|
|
365
|
+
const outStyles = {};
|
|
366
|
+
|
|
367
|
+
const configuration = {
|
|
368
|
+
button_style_ios_background_color: "#FF0000",
|
|
369
|
+
button_style_samsung_background_color: "#00FF00",
|
|
370
|
+
button_style_background_color: "#FFFFFF",
|
|
371
|
+
};
|
|
372
|
+
|
|
373
|
+
getAllSpecificStyles({
|
|
374
|
+
componentName: "button",
|
|
375
|
+
subComponentName: "",
|
|
376
|
+
configuration,
|
|
377
|
+
outStyles,
|
|
378
|
+
});
|
|
379
|
+
|
|
380
|
+
expect(outStyles["default"]).toEqual({
|
|
381
|
+
backgroundColor: "#00FF00", // Samsung-specific should win
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
describe("Complex scenarios", () => {
|
|
387
|
+
it("should handle multiple states and platforms correctly", () => {
|
|
388
|
+
const outStyles = {};
|
|
389
|
+
|
|
390
|
+
const configuration = {
|
|
391
|
+
// Default styles
|
|
392
|
+
button_style_background_color: "#FFFFFF",
|
|
393
|
+
button_style_text_color: "#000000",
|
|
394
|
+
button_style_border_width: 1,
|
|
395
|
+
|
|
396
|
+
// Platform-specific default
|
|
397
|
+
button_style_samsung_padding: 10,
|
|
398
|
+
|
|
399
|
+
// State-specific
|
|
400
|
+
button_style_pressed_background_color: "#EEEEEE",
|
|
401
|
+
button_style_focused_scale: 1.1,
|
|
402
|
+
|
|
403
|
+
// Platform + state specific
|
|
404
|
+
button_style_samsung_pressed_opacity: 0.8,
|
|
405
|
+
button_style_ios_pressed_opacity: 0.6, // Should be ignored
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
getAllSpecificStyles({
|
|
409
|
+
componentName: "button",
|
|
410
|
+
subComponentName: "",
|
|
411
|
+
configuration,
|
|
412
|
+
outStyles,
|
|
413
|
+
});
|
|
414
|
+
|
|
415
|
+
expect(outStyles["default"]).toEqual({
|
|
416
|
+
backgroundColor: "#FFFFFF",
|
|
417
|
+
textColor: "#000000",
|
|
418
|
+
borderWidth: 1,
|
|
419
|
+
padding: 10,
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
expect(outStyles["pressed"]).toEqual({
|
|
423
|
+
backgroundColor: "#EEEEEE",
|
|
424
|
+
textColor: "#000000",
|
|
425
|
+
borderWidth: 1,
|
|
426
|
+
padding: 10,
|
|
427
|
+
opacity: 0.8,
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
expect(outStyles["focused"]).toEqual({
|
|
431
|
+
backgroundColor: "#FFFFFF",
|
|
432
|
+
textColor: "#000000",
|
|
433
|
+
borderWidth: 1,
|
|
434
|
+
padding: 10,
|
|
435
|
+
scale: 1.1,
|
|
436
|
+
});
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
it("should handle edge case keys correctly", () => {
|
|
440
|
+
const outStyles = {};
|
|
441
|
+
|
|
442
|
+
const configuration = {
|
|
443
|
+
button_style_: "shouldBeIgnored", // Empty style name
|
|
444
|
+
button_style_samsung_: "shouldBeIgnored", // Platform but no style
|
|
445
|
+
button_style__pressed: "shouldBeIgnored", // No style name before state
|
|
446
|
+
button_style_valid_key: "included",
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
getAllSpecificStyles({
|
|
450
|
+
componentName: "button",
|
|
451
|
+
subComponentName: "",
|
|
452
|
+
configuration,
|
|
453
|
+
outStyles,
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
expect(outStyles["default"]).toEqual({
|
|
457
|
+
validKey: "included",
|
|
458
|
+
});
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
it("should handle all state suffixes in priority order", () => {
|
|
462
|
+
const outStyles = {};
|
|
463
|
+
|
|
464
|
+
const configuration = {
|
|
465
|
+
// Test that focused_selected is recognized before focused
|
|
466
|
+
button_style_focused_selected_test: "focused_selected_value",
|
|
467
|
+
button_style_focused_another: "focused_value",
|
|
468
|
+
};
|
|
469
|
+
|
|
470
|
+
getAllSpecificStyles({
|
|
471
|
+
componentName: "button",
|
|
472
|
+
subComponentName: "",
|
|
473
|
+
configuration,
|
|
474
|
+
outStyles,
|
|
475
|
+
});
|
|
476
|
+
|
|
477
|
+
expect(outStyles["focused_selected"]).toEqual({
|
|
478
|
+
test: "focused_selected_value",
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
expect(outStyles["focused"]).toEqual({
|
|
482
|
+
another: "focused_value",
|
|
483
|
+
});
|
|
484
|
+
});
|
|
485
|
+
});
|
|
486
|
+
|
|
487
|
+
describe("Immutability", () => {
|
|
488
|
+
it("should not mutate configuration object", () => {
|
|
489
|
+
const configuration = Object.freeze({
|
|
490
|
+
button_style_background_color: "#FF0000",
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
const outStyles = {};
|
|
494
|
+
|
|
495
|
+
expect(() => {
|
|
496
|
+
getAllSpecificStyles({
|
|
497
|
+
componentName: "button",
|
|
498
|
+
subComponentName: "",
|
|
499
|
+
configuration,
|
|
500
|
+
outStyles,
|
|
501
|
+
});
|
|
502
|
+
}).not.toThrow();
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
it("platform pressed overrides generic pressed for same key", () => {
|
|
506
|
+
const outStyles = {};
|
|
507
|
+
|
|
508
|
+
const configuration = {
|
|
509
|
+
button_style_pressed_background_color: "#111111", // generic
|
|
510
|
+
button_style_samsung_pressed_background_color: "#222222", // platform
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
getAllSpecificStyles({
|
|
514
|
+
componentName: "button",
|
|
515
|
+
subComponentName: "",
|
|
516
|
+
configuration,
|
|
517
|
+
outStyles,
|
|
518
|
+
});
|
|
519
|
+
|
|
520
|
+
expect(outStyles["pressed"]["backgroundColor"]).toBe("#222222");
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
it("should handle frozen outStyles properties", () => {
|
|
524
|
+
const outStyles = {
|
|
525
|
+
default: Object.freeze({ existingProp: "value" }),
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
const configuration = {
|
|
529
|
+
button_style_background_color: "#FF0000",
|
|
530
|
+
};
|
|
531
|
+
|
|
532
|
+
getAllSpecificStyles({
|
|
533
|
+
componentName: "button",
|
|
534
|
+
subComponentName: "",
|
|
535
|
+
configuration,
|
|
536
|
+
outStyles,
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
// Should create new object instead of mutating frozen one
|
|
540
|
+
expect(outStyles["default"]).toEqual({
|
|
541
|
+
existingProp: "value",
|
|
542
|
+
backgroundColor: "#FF0000",
|
|
543
|
+
});
|
|
544
|
+
});
|
|
545
|
+
});
|
|
546
|
+
});
|