@applicaster/zapp-react-native-utils 14.0.0-alpha.5621117258 → 14.0.0-alpha.5974411329

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