@applicaster/zapp-react-native-utils 12.0.0-alpha.4400210593 → 12.0.0-alpha.4510795609

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 (71) hide show
  1. package/analyticsUtils/AnalyticsEvents/index.ts +13 -0
  2. package/analyticsUtils/AnalyticsEvents/searchEvents.ts +21 -0
  3. package/analyticsUtils/AnalyticsEvents/sendShareEvent.ts +21 -0
  4. package/analyticsUtils/analyticsPlugins.ts +25 -0
  5. package/analyticsUtils/events.ts +12 -0
  6. package/analyticsUtils/index.tsx +12 -0
  7. package/appUtils/focusManager/__tests__/__snapshots__/focusManager.test.js.snap +2 -3
  8. package/appUtils/focusManager/__tests__/focusManager.test.js +4 -24
  9. package/appUtils/focusManager/__tests__/index.test.ts +2 -3
  10. package/appUtils/focusManager/index.ts +76 -56
  11. package/appUtils/focusManager/treeDataStructure/Utils/index.js +74 -43
  12. package/appUtils/focusManager/utils/index.ts +100 -0
  13. package/appUtils/focusManagerAux/index.ts +76 -0
  14. package/appUtils/focusManagerAux/utils/index.ts +100 -0
  15. package/appUtils/keyCodes/keys.web.js +8 -0
  16. package/appUtils/keyCodes/keysByPlatform.js +11 -1
  17. package/appUtils/platform/const.ts +25 -0
  18. package/appUtils/platform/index.ts +3 -0
  19. package/appUtils/platform/platformUtils.ts +223 -0
  20. package/appUtils/playerManager/index.ts +11 -5
  21. package/appUtils/playerManager/nativePlayerManager.ts +12 -0
  22. package/appUtils/playerManager/player.ts +1 -3
  23. package/appUtils/playerManager/playerNative.ts +10 -14
  24. package/appUtils/playerManager/usePlayerControllerSetup.tsx +6 -1
  25. package/arrayUtils/__tests__/isFilledArray.test.ts +63 -0
  26. package/arrayUtils/index.ts +5 -0
  27. package/booleanUtils/index.ts +4 -4
  28. package/cellUtils/__tests__/cellUtils.test.ts +9 -20
  29. package/cellUtils/index.ts +6 -12
  30. package/dateUtils/index.ts +11 -0
  31. package/headersUtils/index.ts +1 -0
  32. package/inflatedUrlUtils/index.ts +4 -4
  33. package/keyboardState/index.ts +0 -0
  34. package/localizationUtils/__tests__/localizationUtils.test.ts +72 -53
  35. package/localizationUtils/index.ts +13 -22
  36. package/manifestUtils/defaultManifestConfigurations/generalContent.js +6 -0
  37. package/manifestUtils/defaultManifestConfigurations/player.js +2 -1
  38. package/numberUtils/__tests__/isLikeNumber.test.ts +18 -0
  39. package/numberUtils/index.ts +9 -18
  40. package/package.json +2 -2
  41. package/playerUtils/configurationGenerator.ts +3 -1
  42. package/reactHooks/autoscrolling/__tests__/{useTrackedView.test.ts → useTrackedView.test.tsx} +16 -1
  43. package/reactHooks/cell-click/__tests__/index.test.js +10 -1
  44. package/reactHooks/cell-click/index.ts +12 -12
  45. package/reactHooks/feed/__tests__/useBuildPipesUrl.test.tsx +30 -70
  46. package/reactHooks/feed/__tests__/useFeedRefresh.test.tsx +6 -2
  47. package/reactHooks/feed/__tests__/useInflatedUrl.test.ts +18 -3
  48. package/reactHooks/feed/useBuildPipesUrl.ts +7 -10
  49. package/reactHooks/feed/useFeedRefresh.tsx +9 -7
  50. package/reactHooks/feed/useInflatedUrl.ts +44 -15
  51. package/reactHooks/layout/__tests__/{index.test.js → index.test.tsx} +43 -29
  52. package/reactHooks/layout/getDeviceInfo/index.ts +4 -2
  53. package/reactHooks/layout/types/index.ts +1 -0
  54. package/reactHooks/layout/useDimensions/useDimensions.ts +5 -2
  55. package/reactHooks/navigation/__mocks__/index.ts +13 -0
  56. package/reactHooks/navigation/__mocks__/useNavigation.ts +3 -0
  57. package/reactHooks/navigation/__tests__/index.test.tsx +11 -8
  58. package/reactHooks/navigation/index.ts +56 -67
  59. package/reactHooks/screen/__tests__/useCurrentScreenData.test.tsx +21 -23
  60. package/reactHooks/screen/index.ts +2 -0
  61. package/reactHooks/screen/useScreenBackgroundColor.ts +23 -0
  62. package/reactHooks/screen/useScreenContext.ts +3 -3
  63. package/reactUtils/index.ts +102 -0
  64. package/screenState/index.ts +0 -8
  65. package/stringUtils/index.ts +5 -0
  66. package/testUtils/getByTestId.ts +14 -0
  67. package/testUtils/index.tsx +24 -22
  68. package/types.ts +4 -0
  69. package/appUtils/focusManager/FocusableEvents.ts +0 -8
  70. package/appUtils/focusManager/treeDataStructure/Utils/__tests__/Utils_android.test.js +0 -1094
  71. package/appUtils/focusManager/treeDataStructure/Utils/index.android.js +0 -261
@@ -1,1094 +0,0 @@
1
- import {
2
- findFocusableNode,
3
- getLastFocusedItems,
4
- getPreferableItems,
5
- getPriorityItems,
6
- getSelectedItems,
7
- hasPriorityInDirection,
8
- } from "../../Utils/index.android";
9
- import { FocusDirection } from "../../../../directionHelper";
10
- import { Tree } from "../../Tree";
11
-
12
- const directionMocks = {
13
- right: { axis: "x", isHorizontal: true, isVertical: false, value: "right" },
14
- left: { axis: "x", isHorizontal: true, isVertical: false, value: "left" },
15
- up: { axis: "x", isHorizontal: false, isVertical: true, value: "up" },
16
- down: { axis: "x", isHorizontal: false, isVertical: true, value: "down" },
17
- };
18
-
19
- const screenMock1 = {
20
- root: {
21
- id: "root",
22
- children: [
23
- {
24
- id: "menu",
25
- parent: {
26
- id: "root",
27
- },
28
- children: [
29
- {
30
- id: "1dfa32eb-c1b6-4056-b566-ae001978d9eb",
31
- parent: {
32
- id: "menu",
33
- },
34
- component: {
35
- props: {
36
- id: "1dfa32eb-c1b6-4056-b566-ae001978d9eb",
37
- groupId: "menu",
38
- preferredFocus: false,
39
- },
40
- selected: false,
41
- getRect: jest.fn(() => ({
42
- top: 60,
43
- left: 678,
44
- right: 931,
45
- bottom: 90,
46
- width: 253,
47
- height: 30,
48
- x: 0,
49
- y: 0,
50
- })),
51
- },
52
- },
53
- {
54
- id: "a892edf2-ceb6-425f-8fdb-3e58b38b233e",
55
- parent: {
56
- id: "menu",
57
- },
58
- component: {
59
- props: {
60
- id: "a892edf2-ceb6-425f-8fdb-3e58b38b233e",
61
- groupId: "menu",
62
- preferredFocus: true,
63
- },
64
- selected: true,
65
- getRect: jest.fn(() => ({
66
- top: 60,
67
- left: 931,
68
- right: 1130,
69
- bottom: 90,
70
- width: 199,
71
- height: 30,
72
- x: 0,
73
- y: 0,
74
- })),
75
- },
76
- },
77
- ],
78
- component: {
79
- props: {
80
- id: "menu",
81
- preferredFocus: true,
82
- },
83
- getRect: jest.fn(() => ({
84
- top: 0,
85
- left: 0,
86
- right: 1920,
87
- bottom: 100,
88
- width: 1920,
89
- height: 100,
90
- x: 0,
91
- y: 0,
92
- })),
93
- },
94
- },
95
- {
96
- id: "ScreenPicker",
97
- parent: {
98
- id: "root",
99
- },
100
- children: [
101
- {
102
- id: "ScreenPicker.ScreenSelector",
103
- parent: {
104
- id: "ScreenPicker",
105
- },
106
- children: [
107
- {
108
- id: 14948,
109
- parent: {
110
- id: "ScreenPicker.ScreenSelector",
111
- },
112
- component: {
113
- props: {
114
- id: 14948,
115
- groupId: "ScreenPicker.ScreenSelector",
116
- preferredFocus: true,
117
- },
118
- selected: false,
119
- getRect: jest.fn(() => ({
120
- top: 131,
121
- left: 112,
122
- right: 412,
123
- bottom: 188,
124
- width: 300,
125
- height: 57,
126
- x: 0,
127
- y: 0,
128
- })),
129
- },
130
- },
131
- {
132
- id: 14949,
133
- parent: {
134
- id: "ScreenPicker.ScreenSelector",
135
- },
136
- component: {
137
- props: {
138
- id: 14949,
139
- groupId: "ScreenPicker.ScreenSelector",
140
- preferredFocus: false,
141
- },
142
- selected: false,
143
- getRect: jest.fn(() => ({
144
- top: 188,
145
- left: 112,
146
- right: 412,
147
- bottom: 245,
148
- width: 300,
149
- height: 57,
150
- x: 0,
151
- y: 0,
152
- })),
153
- },
154
- },
155
-
156
- {
157
- id: 14950,
158
- parent: {
159
- id: "ScreenPicker.ScreenSelector",
160
- },
161
- component: {
162
- props: {
163
- id: 14950,
164
- groupId: "ScreenPicker.ScreenSelector",
165
- preferredFocus: false,
166
- },
167
- selected: true,
168
- getRect: jest.fn(() => ({
169
- top: 245,
170
- left: 112,
171
- right: 412,
172
- bottom: 302,
173
- width: 300,
174
- height: 57,
175
- x: 0,
176
- y: 0,
177
- })),
178
- },
179
- },
180
-
181
- {
182
- id: 16270,
183
- parent: {
184
- id: "ScreenPicker.ScreenSelector",
185
- },
186
- component: {
187
- props: {
188
- id: 16270,
189
- groupId: "ScreenPicker.ScreenSelector",
190
- preferredFocus: false,
191
- },
192
- selected: false,
193
- getRect: jest.fn(() => ({
194
- top: 302,
195
- left: 112,
196
- right: 412,
197
- bottom: 359,
198
- width: 300,
199
- height: 57,
200
- x: 0,
201
- y: 0,
202
- })),
203
- },
204
- },
205
- ],
206
- component: {
207
- props: {
208
- id: "ScreenPicker.ScreenSelector",
209
- groupId: "ScreenPicker",
210
- preferredFocus: true,
211
- },
212
- getRect: jest.fn(() => ({
213
- top: 101,
214
- left: 112,
215
- right: 412,
216
- bottom: 2186,
217
- width: 300,
218
- height: 2085,
219
- x: 0,
220
- y: 0,
221
- })),
222
- },
223
- },
224
-
225
- {
226
- id: "ScreenPicker.ScreenContainer",
227
- parent: {
228
- id: "ScreenPicker",
229
- },
230
- children: [
231
- {
232
- id: "Grid",
233
- parent: {
234
- id: "ScreenPicker.ScreenContainer",
235
- },
236
- children: [
237
- {
238
- id: "Grid+5bc7813a8c1abc222700000e",
239
- parent: {
240
- id: "Grid",
241
- },
242
- component: {
243
- props: {
244
- id: "Grid+5bc7813a8c1abc222700000e",
245
- groupId: "Grid",
246
- preferredFocus: true,
247
- },
248
- getRect: jest.fn(() => ({
249
- top: 758,
250
- left: 526,
251
- right: 955,
252
- bottom: 1245,
253
- width: 429,
254
- height: 487,
255
- x: 0,
256
- y: 0,
257
- })),
258
- },
259
- },
260
-
261
- {
262
- id: "Grid+5af0a05a841c4b344c00002a",
263
- parent: {
264
- id: "Grid",
265
- },
266
- component: {
267
- props: {
268
- id: "Grid+5af0a05a841c4b344c00002a",
269
- groupId: "Grid",
270
- preferredFocus: false,
271
- },
272
- getRect: jest.fn(() => ({
273
- top: 758,
274
- left: 955,
275
- right: 1384,
276
- bottom: 1245,
277
- width: 429,
278
- height: 487,
279
- x: 0,
280
- y: 0,
281
- })),
282
- },
283
- },
284
-
285
- {
286
- id: "Grid+5ae9f107dbc8585711000011",
287
- parent: {
288
- id: "Grid",
289
- },
290
- component: {
291
- props: {
292
- id: "Grid+5ae9f107dbc8585711000011",
293
- groupId: "Grid",
294
- preferredFocus: false,
295
- },
296
- getRect: jest.fn(() => ({
297
- top: 758,
298
- left: 1384,
299
- right: 1813,
300
- bottom: 1245,
301
- width: 429,
302
- height: 487,
303
- x: 0,
304
- y: 0,
305
- })),
306
- },
307
- },
308
-
309
- {
310
- id: "Grid+5ad6451a841c4b3168000017",
311
- parent: {
312
- id: "Grid",
313
- },
314
- component: {
315
- props: {
316
- id: "Grid+5ad6451a841c4b3168000017",
317
- groupId: "Grid",
318
- preferredFocus: false,
319
- },
320
- getRect: jest.fn(() => ({
321
- top: 1245,
322
- left: 526,
323
- right: 955,
324
- bottom: 1732,
325
- width: 429,
326
- height: 487,
327
- x: 0,
328
- y: 0,
329
- })),
330
- },
331
- },
332
-
333
- {
334
- id: "Grid+5ad50977dbc8580f24000002",
335
- parent: {
336
- id: "Grid",
337
- },
338
- component: {
339
- props: {
340
- id: "Grid+5ad50977dbc8580f24000002",
341
- groupId: "Grid",
342
- preferredFocus: false,
343
- },
344
- getRect: jest.fn(() => ({
345
- top: 1245,
346
- left: 955,
347
- right: 1384,
348
- bottom: 1732,
349
- width: 429,
350
- height: 487,
351
- x: 0,
352
- y: 0,
353
- })),
354
- },
355
- },
356
-
357
- {
358
- id: "Grid+5abbb261841c4b026d00001b",
359
- parent: {
360
- id: "Grid",
361
- },
362
- component: {
363
- props: {
364
- id: "Grid+5abbb261841c4b026d00001b",
365
- groupId: "Grid",
366
- preferredFocus: false,
367
- },
368
- getRect: jest.fn(() => ({
369
- top: 1245,
370
- left: 1384,
371
- right: 1813,
372
- bottom: 1732,
373
- width: 429,
374
- height: 487,
375
- x: 0,
376
- y: 0,
377
- })),
378
- },
379
- },
380
-
381
- {
382
- id: "Grid+5a553591148bb0623f00000b",
383
- parent: {
384
- id: "Grid",
385
- },
386
- component: {
387
- props: {
388
- id: "Grid+5a553591148bb0623f00000b",
389
- groupId: "Grid",
390
- preferredFocus: false,
391
- },
392
- getRect: jest.fn(() => ({
393
- top: 1732,
394
- left: 526,
395
- right: 955,
396
- bottom: 2219,
397
- width: 429,
398
- height: 487,
399
- x: 0,
400
- y: 0,
401
- })),
402
- },
403
- },
404
-
405
- {
406
- id: "Grid+5a284cb8148bb006e3000002",
407
- parent: {
408
- id: "Grid",
409
- },
410
- component: {
411
- props: {
412
- id: "Grid+5a284cb8148bb006e3000002",
413
- groupId: "Grid",
414
- preferredFocus: false,
415
- },
416
- getRect: jest.fn(() => ({
417
- top: 1732,
418
- left: 955,
419
- right: 1384,
420
- bottom: 2219,
421
- width: 429,
422
- height: 487,
423
- x: 0,
424
- y: 0,
425
- })),
426
- },
427
- },
428
-
429
- {
430
- id: "Grid+59dd327b2d1ca033d3000027",
431
- parent: {
432
- id: "Grid",
433
- },
434
- component: {
435
- props: {
436
- id: "Grid+59dd327b2d1ca033d3000027",
437
- groupId: "Grid",
438
- preferredFocus: false,
439
- },
440
- getRect: jest.fn(() => ({
441
- top: 1732,
442
- left: 1384,
443
- right: 1813,
444
- bottom: 2219,
445
- width: 429,
446
- height: 487,
447
- x: 0,
448
- y: 0,
449
- })),
450
- },
451
- },
452
- {
453
- id: "Grid+594d8085fd2e611a7600002a",
454
- parent: {
455
- id: "Grid",
456
- },
457
- component: {
458
- props: {
459
- id: "Grid+594d8085fd2e611a7600002a",
460
- groupId: "Grid",
461
- preferredFocus: false,
462
- },
463
- getRect: jest.fn(() => ({
464
- top: 2219,
465
- left: 526,
466
- right: 955,
467
- bottom: 2706,
468
- width: 429,
469
- height: 487,
470
- x: 0,
471
- y: 0,
472
- })),
473
- },
474
- },
475
- {
476
- id: "Grid+594ad354fd2e61585c000019",
477
- parent: {
478
- id: "Grid",
479
- },
480
- component: {
481
- props: {
482
- id: "Grid+594ad354fd2e61585c000019",
483
- groupId: "Grid",
484
- preferredFocus: false,
485
- },
486
- getRect: jest.fn(() => ({
487
- top: 2219,
488
- left: 955,
489
- right: 1384,
490
- bottom: 2706,
491
- width: 429,
492
- height: 487,
493
- x: 0,
494
- y: 0,
495
- })),
496
- },
497
- },
498
- {
499
- id: "Grid+59405d44b57ac32c80000014",
500
- parent: {
501
- id: "Grid",
502
- },
503
- component: {
504
- props: {
505
- id: "Grid+59405d44b57ac32c80000014",
506
- groupId: "Grid",
507
- preferredFocus: false,
508
- },
509
- getRect: jest.fn(() => ({
510
- top: 2219,
511
- left: 1384,
512
- right: 1813,
513
- bottom: 2706,
514
- width: 429,
515
- height: 487,
516
- x: 0,
517
- y: 0,
518
- })),
519
- },
520
- },
521
- ],
522
- component: {
523
- props: {
524
- id: "Grid",
525
- groupId: "ScreenPicker.ScreenContainer",
526
- preferredFocus: true,
527
- },
528
- getRect: jest.fn(() => ({
529
- top: 661,
530
- left: 412,
531
- right: 1912,
532
- bottom: 2706,
533
- width: 1500,
534
- height: 2045,
535
- x: 0,
536
- y: 0,
537
- })),
538
- },
539
- },
540
- {
541
- id: "Hero",
542
- parent: {
543
- id: "ScreenPicker.ScreenContainer",
544
- },
545
- children: [
546
- {
547
- id: "Hero+5ad6451a841c4b3168000017",
548
- parent: {
549
- id: "Hero",
550
- },
551
- component: {
552
- props: {
553
- id: "Hero+5ad6451a841c4b3168000017",
554
- groupId: "Hero",
555
- preferredFocus: false,
556
- },
557
- getRect: jest.fn(() => ({
558
- top: 180,
559
- left: -596,
560
- right: 558,
561
- bottom: 661,
562
- width: 1154,
563
- height: 481,
564
- x: 0,
565
- y: 0,
566
- })),
567
- },
568
- },
569
-
570
- {
571
- id: "Hero+5bc7813a8c1abc222700000e",
572
- parent: {
573
- id: "Hero",
574
- },
575
- component: {
576
- props: {
577
- id: "Hero+5bc7813a8c1abc222700000e",
578
- groupId: "Hero",
579
- preferredFocus: false,
580
- },
581
- getRect: jest.fn(() => ({
582
- top: 180,
583
- left: 558,
584
- right: 1712,
585
- bottom: 661,
586
- width: 1154,
587
- height: 481,
588
- x: 0,
589
- y: 0,
590
- })),
591
- },
592
- },
593
- {
594
- id: "Hero+5af0a05a841c4b344c00002a",
595
- parent: {
596
- id: "Hero",
597
- },
598
- component: {
599
- props: {
600
- id: "Hero+5af0a05a841c4b344c00002a",
601
- groupId: "Hero",
602
- preferredFocus: true,
603
- },
604
- getRect: jest.fn(() => ({
605
- top: 180,
606
- left: 1712,
607
- right: 2866,
608
- bottom: 661,
609
- width: 1154,
610
- height: 481,
611
- x: 0,
612
- y: 0,
613
- })),
614
- },
615
- },
616
-
617
- {
618
- id: "Hero+5ae9f107dbc8585711000011",
619
- parent: {
620
- id: "Hero",
621
- },
622
- component: {
623
- props: {
624
- id: "Hero+5ae9f107dbc8585711000011",
625
- groupId: "Hero",
626
- preferredFocus: false,
627
- },
628
- getRect: jest.fn(() => ({
629
- top: 180,
630
- left: 2866,
631
- right: 4020,
632
- bottom: 661,
633
- width: 1154,
634
- height: 481,
635
- x: 0,
636
- y: 0,
637
- })),
638
- },
639
- },
640
- ],
641
- component: {
642
- props: {
643
- id: "Hero",
644
- groupId: "ScreenPicker.ScreenContainer",
645
- preferredFocus: true,
646
- },
647
- getRect: jest.fn(() => ({
648
- top: 131,
649
- left: 412,
650
- right: 1912,
651
- bottom: 661,
652
- width: 1500,
653
- height: 530,
654
- x: 0,
655
- y: 0,
656
- })),
657
- },
658
- },
659
- ],
660
- component: {
661
- props: {
662
- id: "ScreenPicker.ScreenContainer",
663
- groupId: "ScreenPicker",
664
- preferredFocus: false,
665
- },
666
- getRect: jest.fn(() => ({
667
- top: 101,
668
- left: 412,
669
- right: 1912,
670
- bottom: 2186,
671
- width: 1500,
672
- height: 2085,
673
- x: 0,
674
- y: 0,
675
- })),
676
- },
677
- },
678
- ],
679
- component: {
680
- props: {
681
- id: "ScreenPicker",
682
- preferredFocus: true,
683
- },
684
- getRect: jest.fn(() => ({
685
- top: 100,
686
- left: 0,
687
- right: 1920,
688
- bottom: 2186,
689
- width: 1920,
690
- height: 2086,
691
- x: 0,
692
- y: 0,
693
- })),
694
- },
695
- },
696
- ],
697
- },
698
- };
699
-
700
- const priorityMock = [
701
- {
702
- id: "child1",
703
- parent: { id: "parent1", lastFocusedItem: "child5" },
704
- component: {
705
- props: { id: "child1", preferredFocus: false, selected: false },
706
- },
707
- },
708
- {
709
- id: "child2",
710
- parent: { id: "parent1", lastFocusedItem: "child5" },
711
- component: {
712
- props: { id: "child2", preferredFocus: true, selected: false },
713
- },
714
- },
715
- {
716
- id: "child3",
717
- parent: { id: "parent1", lastFocusedItem: "child5" },
718
- component: {
719
- props: { id: "child3", preferredFocus: false, selected: false },
720
- },
721
- },
722
- {
723
- id: "child4",
724
- parent: { id: "parent1", lastFocusedItem: "child5" },
725
- component: {
726
- props: { id: "child4", preferredFocus: false, selected: true },
727
- },
728
- },
729
- {
730
- id: "child5",
731
- parent: { id: "parent1", lastFocusedItem: "child5" },
732
- component: {
733
- props: { id: "child5", preferredFocus: false, selected: false },
734
- },
735
- },
736
- ];
737
-
738
- const priorityMock2 = [
739
- {
740
- id: "child1",
741
- parent: { id: "parent1", lastFocusedItem: "child5" },
742
- component: {
743
- props: { id: "child1", preferredFocus: false, selected: false },
744
- },
745
- },
746
- {
747
- id: "child2",
748
- parent: { id: "parent1", lastFocusedItem: "child5" },
749
- component: {
750
- props: { id: "child2", preferredFocus: true, selected: false },
751
- },
752
- },
753
- {
754
- id: "child3",
755
- parent: { id: "parent1", lastFocusedItem: "child5" },
756
- component: {
757
- props: { id: "child3", preferredFocus: false, selected: false },
758
- },
759
- },
760
- {
761
- id: "child4",
762
- parent: { id: "parent1", lastFocusedItem: "child5" },
763
- component: {
764
- props: { id: "child4", preferredFocus: false, selected: false },
765
- },
766
- },
767
- {
768
- id: "child5",
769
- parent: { id: "parent1", lastFocusedItem: "child5" },
770
- component: {
771
- props: { id: "child5", preferredFocus: false, selected: false },
772
- },
773
- },
774
- ];
775
-
776
- const priorityMock3 = [
777
- {
778
- id: "child1",
779
- parent: { id: "parent1", lastFocusedItem: null },
780
- component: {
781
- props: { id: "child1", preferredFocus: false, selected: false },
782
- },
783
- },
784
- {
785
- id: "child2",
786
- parent: { id: "parent1", lastFocusedItem: null },
787
- component: {
788
- props: { id: "child2", preferredFocus: true, selected: false },
789
- },
790
- },
791
- {
792
- id: "child3",
793
- parent: { id: "parent1", lastFocusedItem: null },
794
- component: {
795
- props: { id: "child3", preferredFocus: false, selected: false },
796
- },
797
- },
798
- {
799
- id: "child4",
800
- parent: { id: "parent1", lastFocusedItem: null },
801
- component: {
802
- props: { id: "child4", preferredFocus: false, selected: false },
803
- },
804
- },
805
- {
806
- id: "child5",
807
- parent: { id: "parent1", lastFocusedItem: null },
808
- component: {
809
- props: { id: "child5", preferredFocus: false, selected: false },
810
- },
811
- },
812
- ];
813
-
814
- const priorityMock4 = [
815
- {
816
- id: "child1",
817
- parent: { id: "parent1", lastFocusedItem: null },
818
- component: {
819
- props: { id: "child1", preferredFocus: false, selected: false },
820
- },
821
- },
822
- {
823
- id: "child2",
824
- parent: { id: "parent1", lastFocusedItem: null },
825
- component: {
826
- props: { id: "child2", preferredFocus: false, selected: false },
827
- },
828
- },
829
- {
830
- id: "child3",
831
- parent: { id: "parent1", lastFocusedItem: null },
832
- component: {
833
- props: { id: "child3", preferredFocus: false, selected: false },
834
- },
835
- },
836
- {
837
- id: "child4",
838
- parent: { id: "parent1", lastFocusedItem: null },
839
- component: {
840
- props: { id: "child4", preferredFocus: false, selected: false },
841
- },
842
- },
843
- {
844
- id: "child5",
845
- parent: { id: "parent1", lastFocusedItem: null },
846
- component: {
847
- props: { id: "child5", preferredFocus: false, selected: false },
848
- },
849
- },
850
- ];
851
-
852
- function prepareMock(node) {
853
- if (node.children) {
854
- node.children.forEach((child) => {
855
- child.parent = node;
856
- prepareMock(child);
857
- });
858
- }
859
- }
860
-
861
- function treeLoaded() {}
862
-
863
- describe("findFocusableNode", () => {
864
- const mockScreen = screenMock1;
865
- prepareMock(mockScreen.root);
866
- const tree = new Tree(treeLoaded);
867
- tree.root = mockScreen.root;
868
- const selectedHero = tree.findInTree("Hero+5bc7813a8c1abc222700000e");
869
- const expectedOnRight = tree.findInTree("Hero+5af0a05a841c4b344c00002a");
870
-
871
- it("return expectedOnRight component when moving right direction", async () => {
872
- const foundNode = await findFocusableNode(
873
- directionMocks.right,
874
- selectedHero
875
- );
876
-
877
- expect(foundNode).toEqual(expectedOnRight);
878
- });
879
-
880
- // TODO this should change with new functionality of screen picker selector on left.
881
- const expectedOnLeft = tree.findInTree("Hero+5ad6451a841c4b3168000017");
882
-
883
- it("return expectedOnLeft component when moving left direction", async () => {
884
- const foundNode = await findFocusableNode(
885
- directionMocks.left,
886
- selectedHero
887
- );
888
-
889
- expect(foundNode).toEqual(expectedOnLeft);
890
- });
891
-
892
- it("return preferred menu id a892edf2-ceb6-425f-8fdb-3e58b38b233e component when moving up direction", async () => {
893
- const foundNode = await findFocusableNode(directionMocks.up, selectedHero);
894
- expect(foundNode.id).toEqual("a892edf2-ceb6-425f-8fdb-3e58b38b233e");
895
- });
896
-
897
- it("return preferred grid id Grid+5bc7813a8c1abc222700000e component when moving down direction", async () => {
898
- const foundNode = await findFocusableNode(
899
- directionMocks.down,
900
- selectedHero
901
- );
902
-
903
- expect(foundNode.id).toEqual("Grid+5bc7813a8c1abc222700000e");
904
- });
905
- });
906
-
907
- describe("getSelectedItems", () => {
908
- it("return size 1 of array and child4 for first item.id if parent currently selected item is child4", () => {
909
- const selectedItems = getSelectedItems(priorityMock);
910
- expect(selectedItems.length).toEqual(1);
911
- expect(selectedItems[0].id).toEqual("child4");
912
- });
913
- });
914
-
915
- describe("getLastFocusedItems", () => {
916
- it("return size 1 of array and child5 for first item.id if parent last focused item is child5", () => {
917
- const lastFocusedItems = getLastFocusedItems(priorityMock);
918
- expect(lastFocusedItems.length).toEqual(1);
919
- expect(lastFocusedItems[0].id).toEqual("child5");
920
- });
921
- });
922
-
923
- describe("getPreferableItems", () => {
924
- it("return size 1 of array and child2 for first item.id for preferable item", () => {
925
- const preferableItems = getPreferableItems(priorityMock);
926
- expect(preferableItems.length).toEqual(1);
927
- expect(preferableItems[0].id).toEqual("child2");
928
- });
929
- });
930
-
931
- describe("getPriorityItems", () => {
932
- it("return size 1 of array and child4 for first item.id for currently selected item.", () => {
933
- const priorityItems = getPriorityItems(priorityMock);
934
- expect(priorityItems.length).toEqual(1);
935
- expect(priorityItems[0].id).toEqual("child4");
936
- });
937
-
938
- it(`return size 1 of array and child5 for first item.id
939
- if there is no currently selected item is child4`, () => {
940
- const priorityItems = getPriorityItems(priorityMock2);
941
- expect(priorityItems.length).toEqual(1);
942
- expect(priorityItems[0].id).toEqual("child5");
943
- });
944
-
945
- it(`return size 1 of array and child2 for first item.id
946
- if there is no last focused or currently selected item.`, () => {
947
- const priorityItems = getPriorityItems(priorityMock3);
948
- expect(priorityItems.length).toEqual(1);
949
- expect(priorityItems[0].id).toEqual("child2");
950
- });
951
-
952
- it(`return size 1 of array and child1 for first item.id
953
- if there is no last focused, preferable or currently selected item.`, () => {
954
- const priorityItems = getPriorityItems(priorityMock4);
955
- expect(priorityItems.length).toEqual(1);
956
- expect(priorityItems[0].id).toEqual("child1");
957
- });
958
- });
959
-
960
- const componentMock1 = {
961
- id: "componentMock",
962
- parent: { id: "parent1", lastFocusedItem: null },
963
- component: {
964
- props: {
965
- id: "componentMock",
966
- prioritiseFocusOn: FocusDirection.UP | FocusDirection.LEFT,
967
- preferredFocus: false,
968
- selected: false,
969
- },
970
- },
971
- };
972
-
973
- const componentMock2 = {
974
- id: "componentMock",
975
- parent: { id: "parent1", lastFocusedItem: null },
976
- component: {
977
- props: {
978
- id: "componentMock",
979
- prioritiseFocusOn:
980
- FocusDirection.UP |
981
- FocusDirection.LEFT |
982
- FocusDirection.DOWN |
983
- FocusDirection.RIGHT,
984
- preferredFocus: false,
985
- selected: false,
986
- },
987
- },
988
- };
989
-
990
- const componentMock3 = {
991
- id: "componentMock",
992
- parent: { id: "parent1", lastFocusedItem: null },
993
- component: {
994
- props: {
995
- id: "componentMock",
996
- preferredFocus: false,
997
- selected: false,
998
- },
999
- },
1000
- };
1001
-
1002
- describe("hasPriorityInDirection", () => {
1003
- it(`return true for up and left directions and return false for right and bottom,
1004
- when input prioritiseFocusOn is .TOP or .LEFT`, () => {
1005
- const hasPriorityInUpDirection = hasPriorityInDirection(
1006
- directionMocks.up,
1007
- componentMock1.component
1008
- );
1009
-
1010
- expect(hasPriorityInUpDirection).toEqual(true);
1011
-
1012
- const hasPriorityInDownDirection = hasPriorityInDirection(
1013
- directionMocks.down,
1014
- componentMock1.component
1015
- );
1016
-
1017
- expect(hasPriorityInDownDirection).toEqual(false);
1018
-
1019
- const hasPriorityInLeftDirection = hasPriorityInDirection(
1020
- directionMocks.left,
1021
- componentMock1.component
1022
- );
1023
-
1024
- expect(hasPriorityInLeftDirection).toEqual(true);
1025
-
1026
- const hasPriorityInRightDirection = hasPriorityInDirection(
1027
- directionMocks.right,
1028
- componentMock1.component
1029
- );
1030
-
1031
- expect(hasPriorityInRightDirection).toEqual(false);
1032
- });
1033
-
1034
- it(`return true for in any direction, when input
1035
- prioritiseFocusOn is .TOP or .LEFT or .BOTTOM or .RIGHT`, () => {
1036
- const hasPriorityInUpDirection = hasPriorityInDirection(
1037
- directionMocks.up,
1038
- componentMock2.component
1039
- );
1040
-
1041
- expect(hasPriorityInUpDirection).toEqual(true);
1042
-
1043
- const hasPriorityInDownDirection = hasPriorityInDirection(
1044
- directionMocks.down,
1045
- componentMock2.component
1046
- );
1047
-
1048
- expect(hasPriorityInDownDirection).toEqual(true);
1049
-
1050
- const hasPriorityInLeftDirection = hasPriorityInDirection(
1051
- directionMocks.left,
1052
- componentMock2.component
1053
- );
1054
-
1055
- expect(hasPriorityInLeftDirection).toEqual(true);
1056
-
1057
- const hasPriorityInRightDirection = hasPriorityInDirection(
1058
- directionMocks.right,
1059
- componentMock2.component
1060
- );
1061
-
1062
- expect(hasPriorityInRightDirection).toEqual(true);
1063
- });
1064
-
1065
- it("return false for in any direction, when input prioritiseFocusOn is not defined", () => {
1066
- const hasPriorityInUpDirection = hasPriorityInDirection(
1067
- directionMocks.up,
1068
- componentMock3.component
1069
- );
1070
-
1071
- expect(hasPriorityInUpDirection).toEqual(false);
1072
-
1073
- const hasPriorityInDownDirection = hasPriorityInDirection(
1074
- directionMocks.down,
1075
- componentMock3.component
1076
- );
1077
-
1078
- expect(hasPriorityInDownDirection).toEqual(false);
1079
-
1080
- const hasPriorityInLeftDirection = hasPriorityInDirection(
1081
- directionMocks.left,
1082
- componentMock3.component
1083
- );
1084
-
1085
- expect(hasPriorityInLeftDirection).toEqual(false);
1086
-
1087
- const hasPriorityInRightDirection = hasPriorityInDirection(
1088
- directionMocks.right,
1089
- componentMock3.component
1090
- );
1091
-
1092
- expect(hasPriorityInRightDirection).toEqual(false);
1093
- });
1094
- });