-
Notifications
You must be signed in to change notification settings - Fork 9
/
OnDeviceComponent.spec.ts
2655 lines (2311 loc) · 77.6 KB
/
OnDeviceComponent.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* eslint-disable @typescript-eslint/no-non-null-assertion */
const chai = require('chai');
const assertArrays = require('chai-arrays');
chai.use(assertArrays);
const expect = chai.expect;
import * as assert from 'assert';
import { utils } from './utils';
import type * as ODC from './types/OnDeviceComponent';
import { ecp, odc, device } from '.';
// Used to unwrap promise return types to get the true value
type Unwrap<T> = T extends Promise<infer U> ? U : T extends (...args: any) => Promise<infer U> ? U : T extends (...args: any) => infer U ? U : T;
describe('OnDeviceComponent', function () {
before(async () => {
await device.deploy({
rootDir: '../testProject',
preventMultipleDeployments: true
});
});
describe('getAllCount', function () {
it('should have the correct fields and return a known node subtype', async () => {
const { totalNodes, nodeCountByType } = await odc.getAllCount();
expect(totalNodes).to.be.greaterThan(0);
expect(nodeCountByType['MainScene']).to.equal(1);
for (const nodeSubtype in nodeCountByType) {
expect(nodeCountByType[nodeSubtype]).to.be.greaterThan(0);
}
});
});
describe('getRootsCount', function () {
it('should have the correct fields and return a known node subtype', async () => {
const { totalNodes, nodeCountByType } = await odc.getRootsCount();
expect(totalNodes).to.be.greaterThan(0);
expect(nodeCountByType['MainScene']).to.equal(1);
for (const nodeSubtype in nodeCountByType) {
expect(nodeCountByType[nodeSubtype]).to.be.greaterThan(0);
}
});
});
describe('storeNodeReferences', function () {
let storeResult: Unwrap<typeof odc.storeNodeReferences>;
before(async () => {
storeResult = await odc.storeNodeReferences();
});
it('should have the correct fields for flatTree', () => {
expect(storeResult.flatTree).to.be.an('array');
for (const tree of storeResult.flatTree) {
expect(tree.subtype).to.be.a.string;
expect(tree.id).to.be.a.string;
if (tree.id !== 'animation') {
expect(tree.visible).to.be.a('boolean');
expect(tree.opacity).to.be.a('number');
expect(tree.translation).to.be.an('array');
}
expect(tree.id).to.be.string;
expect(tree.ref).to.be.a('number');
expect(tree.parentRef).to.be.a('number');
}
});
it('should have the correct fields for rootTree', () => {
expect(storeResult.rootTree).to.be.an('array');
const tree = storeResult.rootTree[0];
expect(tree.subtype).to.be.a.string;
expect(tree.id).to.be.a.string;
expect(tree.visible).to.be.a('boolean');
expect(tree.opacity).to.be.a('number');
expect(tree.translation).to.be.an('array');
expect(tree.ref).to.be.a('number');
expect(tree.parentRef).to.be.a('number');
expect(tree.children).to.be.an('array');
});
it('each tree should have a children array field', () => {
expect(storeResult.rootTree).to.be.array();
for (const tree of storeResult.flatTree) {
expect(tree.children).to.be.array();
}
});
it('should not include node count info by default', () => {
expect(storeResult.totalNodes).to.not.be.ok;
expect(storeResult.nodeCountByType).to.not.be.ok;
});
it('should include correct keyPaths for both findNode and index based key paths', () => {
expect(storeResult.rootTree[0].children[5].keyPath).to.equal('#pagesContainerGroup');
expect(storeResult.rootTree[0].children[5].children[0].keyPath).to.equal('#pagesContainerGroup.0');
});
describe('includeNodeCountInfo', function () {
before(async () => {
storeResult = await odc.storeNodeReferences({
includeNodeCountInfo: true
});
});
it('should include node count info if requested', () => {
expect(storeResult.totalNodes).to.be.greaterThan(0);
expect(Object.keys(storeResult.nodeCountByType!).length).to.be.greaterThan(0);
});
it('should not run array grid child finding code unless explicitly requested', () => {
for (const nodeTree of storeResult.flatTree) {
expect(nodeTree.subtype).to.not.equal('RowListItem');
}
});
});
describe('includeArrayGridChildren', function () {
before(async () => {
storeResult = await odc.storeNodeReferences({
includeArrayGridChildren: true
});
});
it('should include ArrayGrid children and keyPaths if requested', () => {
let arrayGridChildrenCount = 0;
for (const nodeTree of storeResult.flatTree) {
if (nodeTree.parentRef === -1) {
continue;
}
if (nodeTree.subtype === 'RowListItem') {
arrayGridChildrenCount++;
} else if (nodeTree.subtype === 'RowListItemComponent') {
expect(nodeTree.keyPath.endsWith(`items.${nodeTree.position}`)).to.be.true;
} else if (nodeTree.subtype === 'RowListRowTitleComponent') {
expect(nodeTree.keyPath.endsWith(`title`)).to.be.true;
}
}
expect(arrayGridChildrenCount).to.be.greaterThan(0);
});
it('should be able to pull ArrayGrid children for an itemComponent even if it did not have a parent and did not have enough items to have an itemComponent in the same row that had a parent as long as we have a rowTitleComponent', () => {
let rowListWithCustomTitleComponentNodeTree: ODC.TreeNode | undefined = undefined;
for (const nodeTree of storeResult.flatTree) {
if (nodeTree.id === 'rowListWithCustomTitleComponent') {
rowListWithCustomTitleComponentNodeTree = nodeTree;
}
}
expect(rowListWithCustomTitleComponentNodeTree).to.be.ok;
const markupGrid = rowListWithCustomTitleComponentNodeTree?.children[0].children[1];
expect(markupGrid?.subtype).to.equal('MarkupGrid');
expect(markupGrid?.children.length).to.equal(1);
expect(markupGrid?.children[0].subtype).to.equal('RowListItemComponent');
});
});
describe('includeBoundingRectInfo', function () {
before(async () => {
storeResult = await odc.storeNodeReferences({
includeBoundingRectInfo: true
});
});
it('should include boundingRect info if requested and node extends from group', () => {
for (const nodeTree of storeResult.flatTree) {
if (nodeTree.id === 'animation') {
expect(nodeTree.sceneRect).to.be.undefined;
} else {
expect(nodeTree.sceneRect).to.not.be.undefined;
}
}
});
});
});
describe('getNodesInfo', function () {
let storeResult: Unwrap<typeof odc.storeNodeReferences>;
before(async () => {
storeResult = await odc.storeNodeReferences();
});
it('should get only the requested number of nodes with the right return types', async () => {
const requests = {} as {
[key: string]: ODC.GetValueArgs
};
for (const index in storeResult.flatTree) {
if (index === '12') break;
requests[index] = {
base: 'nodeRef',
keyPath: index
};
}
const { results } = await odc.getNodesInfo({
requests: requests
});
expect(Object.keys(results).length).to.equal(Object.keys(requests).length);
for (const key in results) {
const node = results[key];
expect(node).to.be.ok;
expect(node.fields.id.value).to.equal(storeResult.flatTree[key].id);
expect(node.subtype).to.equal(storeResult.flatTree[key].subtype);
}
});
it('should include fields in the response', async () => {
const { results } = await odc.getNodesInfo({
requests: {
firstItem: {
base: 'nodeRef',
keyPath: '0'
}
}
});
const node = results.firstItem;
expect(node.subtype).to.equal('MainScene');
expect(node.fields.visible.fieldType).to.equal('boolean');
expect(node.fields.visible.type).to.equal('roBoolean');
expect(node.fields.visible.value).to.be.true;
});
it('should include children array with each child node subtype', async () => {
const { results } = await odc.getNodesInfo({
requests: {
firstItem: {
base: 'nodeRef',
keyPath: '0'
}
}
});
const node = results.firstItem;
const expectedSubtypes = [
'Poster',
'Poster',
'Rectangle',
'Animation',
'Group',
'Group'
];
for (const child of node.children) {
expect(child.subtype).to.equal(expectedSubtypes.shift());
}
});
it('should fail if we try to access a non-node keyPath', async () => {
try {
await odc.getNodesInfo({
requests: {
firstItem: {
base: 'global',
keyPath: 'booleanValue'
}
}
});
} catch (e) {
// failed as expected
return;
}
assert.fail('Should have thrown an exception getting boolean value');
});
});
describe('deleteNodeReferences', function () {
it('should successfully delete the node references for the default key', async () => {
await odc.storeNodeReferences();
await odc.deleteNodeReferences();
try {
await odc.getNodesInfo({
requests: {
firstItem: {
base: 'nodeRef',
keyPath: '0'
}
}
});
} catch (e) {
// failed as expected
return;
}
assert.fail('Should have thrown an exception on the getNodesInfo if the references were removed');
});
});
describe('getNodesWithProperties', function () {
before(async () => {
await odc.storeNodeReferences({ includeArrayGridChildren: true });
});
it('should be able to work with a single field with no operator specified and return the correct response', async () => {
const fieldValue = true;
const fieldName = 'myCustomBooleanField';
await setAndVerifyValue({
keyPath: `pagesContainer.0.${fieldName}`,
value: fieldValue
});
const { nodes, nodeRefs } = await odc.getNodesWithProperties({
properties: [{
field: fieldName,
value: fieldValue
}]
});
expect(nodes.length).to.equal(1);
expect(nodeRefs.length).to.equal(1);
const node = nodes[0];
expect(node.subtype).to.equal('LandingPage');
expect(node[fieldName]).to.equal(fieldValue);
});
it('should be able to work with a multiple fields with operator specified and return the correct node response', async () => {
const fieldValue = utils.addRandomPostfix('myCustomStringFieldValue');
const fieldName = 'myCustomStringField';
await setAndVerifyValue({
keyPath: `pagesContainer.0.${fieldName}`,
value: fieldValue + 'ExtraToTestInWorksCorrect'
});
const { nodes } = await odc.getNodesWithProperties({
properties: [{
fields: ['renderTracking', fieldName],
operator: 'in',
value: fieldValue
}]
});
expect(nodes.length).to.equal(1);
const node = nodes[0];
expect(node.subtype).to.equal('LandingPage');
expect(node[fieldName]).to.contain(fieldValue);
});
it('If only one property matches then the node should not be returned', async () => {
const fieldValue = utils.addRandomPostfix('myCustomStringFieldValue');
const fieldName = 'myCustomStringField';
const { nodes } = await odc.getNodesWithProperties({
properties: [{
field: 'visible',
value: false
},
{
fields: ['renderTracking', fieldName],
operator: 'in',
value: fieldValue
}]
});
expect(nodes.length).to.equal(0);
});
it('If wrong value type for operator we should throw an error', async () => {
try {
const fieldName = 'myCustomStringField';
const result = await odc.getNodesWithProperties({
properties: [{
field: fieldName,
operator: '>=',
value: ''
}]
});
} catch (e) {
// failed as expected
return;
}
assert.fail('Should have thrown an exception');
});
it('should be able to run all the same advanced functionality as we can on a keyPath in getValue if we set a keyPath', async () => {
// Only return nodes whose width is 42
const { nodes } = await odc.getNodesWithProperties({
properties: [{
keyPath: 'boundingRect().width',
operator: '=',
value: 42
}]
});
expect(nodes.length).to.equal(1);
const node = nodes[0];
expect(node.subtype).to.equal('Poster');
expect(node.id).to.equal('poster');
});
});
describe('findNodesAtLocation', function () {
let nodeTreeResponse;
before(async () => {
nodeTreeResponse = await odc.storeNodeReferences({
includeArrayGridChildren: true,
includeBoundingRectInfo: true
});
});
it('should sort the matching nodes with the center closest to specified location first', async () => {
const { matches } = await odc.findNodesAtLocation({
x: 100,
y: 100,
nodeTreeResponse: nodeTreeResponse
});
expect(matches[0].id).to.equal('rect2');
});
it('should not match nodes that are not visible', async () => {
const { matches } = await odc.findNodesAtLocation({
x: 100,
y: 100,
nodeTreeResponse: nodeTreeResponse
});
for (const match of matches) {
expect(match.id).to.not.equal('invisibleRect');
}
});
it('Should return proper ArrayGrid child for a MarkupGrid', async () => {
const { matches } = await odc.findNodesAtLocation({
x: 700,
y: 150,
nodeTreeResponse: nodeTreeResponse
});
expect(matches[0].keyPath).to.equal('#pagesContainerGroup.0.#markupGrid.1.#rect');
});
it('Should return proper ArrayGrid child for a RowList', async () => {
const { matches } = await odc.findNodesAtLocation({
x: 500,
y: 600,
nodeTreeResponse: nodeTreeResponse
});
expect(matches[0].keyPath).to.equal('#pagesContainerGroup.0.#rowListWithoutCustomTitleComponent.1.items.1.#rect');
});
});
describe('responsivenessTesting', function () {
it('should fail to get data if we have not started responsiveness testing yet', async () => {
try {
await odc.getResponsivenessTestingData();
} catch (e) {
// failed as expected
return;
}
assert.fail('Should have thrown an exception');
});
it('should use our passed in params if provided', async () => {
const periodTickCount = 10;
const tickDuration = 1;
const periodsTrackCount = 2;
await odc.startResponsivenessTesting({
periodTickCount: periodTickCount,
tickDuration: tickDuration,
periodsTrackCount: periodsTrackCount
});
const response = await odc.getResponsivenessTestingData();
await odc.stopResponsivenessTesting();
expect(response.periodTickCount).to.equal(periodTickCount);
expect(response.tickDuration).to.equal(tickDuration);
expect(response.periodsTrackCount).to.equal(periodsTrackCount);
});
it('should return an empty array response if we have not finished a period yet but still give total counts', async () => {
const periodTickCount = 5000;
const tickDuration = 1;
await odc.startResponsivenessTesting({
periodTickCount: periodTickCount,
tickDuration: tickDuration
});
await utils.sleep(50);
const { periods, testingTotals } = await odc.getResponsivenessTestingData();
await odc.stopResponsivenessTesting();
expect(periods).to.be.an('array');
expect(periods.length).to.equal(0);
expect(testingTotals.duration).to.be.a('number');
expect(testingTotals.tickCount).to.be.a('number');
expect(testingTotals.percent).to.be.a('number');
});
it('should return a proper response if enough time has passed for periods to be set', async () => {
const periodTickCount = 5;
const tickDuration = 1;
const periodsTrackCount = 2;
await odc.startResponsivenessTesting({
periodTickCount: periodTickCount,
tickDuration: tickDuration,
periodsTrackCount: periodsTrackCount
});
await utils.sleep(50);
const { periods, testingTotals } = await odc.getResponsivenessTestingData();
await odc.stopResponsivenessTesting();
expect(periods).to.be.an('array');
expect(periods.length).to.equal(periodsTrackCount);
expect(periods[0].percent).to.be.a('number');
expect(testingTotals.duration).to.be.a('number');
expect(testingTotals.tickCount).to.be.a('number');
expect(testingTotals.percent).to.be.a('number');
});
});
describe('disableScreenSaver', function () {
it('should work disabling', async () => {
await odc.disableScreenSaver({ disableScreensaver: true });
});
it('should work reenabling', async () => {
await odc.disableScreenSaver({ disableScreensaver: false });
});
});
describe('getValue', function () {
it('found should be true if key path was found and has timeTaken as a number', async () => {
const { found, timeTaken } = await odc.getValue({ base: 'scene', keyPath: '' });
expect(found).to.be.true;
expect(timeTaken).to.be.a('number');
});
it('should still work if keyPath was not provided', async () => {
const { value } = await odc.getValue({ base: 'scene' });
expect(value.subtype).to.equal('MainScene');
});
it('should default to having scene as base', async () => {
const { value } = await odc.getValue({});
expect(value.subtype).to.equal('MainScene');
});
it('found should be false if key path was not found', async () => {
const { found } = await odc.getValue({ keyPath: 'invalid' });
expect(found).to.be.false;
});
it('should work with getChild', async () => {
const { value } = await odc.getValue({ keyPath: '1' });
expect(value.id).to.eq('poster');
});
it('should work with negative getChild', async () => {
const { value } = await odc.getValue({ keyPath: '-1' });
expect(value.id).to.eq('pagesContainerGroup');
});
it('should work with findnode', async () => {
const { value } = await odc.getValue({ keyPath: '#subchild3' });
expect(value.id).to.eq('subchild3');
});
it('should not find a child if it is not beneath the parent node', async () => {
const { value } = await odc.getValue({ keyPath: '#subchild3.#testTarget' });
expect(value?.id).to.be.undefined;
});
it('should work with findNode.getChild', async () => {
const { value } = await odc.getValue({ keyPath: '#testTarget.0' });
expect(value.id).to.eq('child1');
});
it('should work with findNode.getChild.getChild', async () => {
const { value } = await odc.getValue({ keyPath: '#testTarget.1.1' });
expect(value.id).to.eq('subchild2');
});
it('should work with findNode.getChild.findNode', async () => {
const { value } = await odc.getValue({ keyPath: '#testTarget.1.#subchild1' });
expect(value.id).to.eq('subchild1');
});
it('should be able to get a value on a valid field', async () => {
const { value } = await odc.getValue({ base: 'global', keyPath: 'AuthManager.isLoggedIn' });
expect(value).to.be.false;
});
it('should work with array values', async () => {
const { value } = await odc.getValue({ base: 'global', keyPath: 'arrayValue.0.name' });
expect(value).to.equal('firstItem');
});
it('should work with negative array values', async () => {
const { value } = await odc.getValue({ base: 'global', keyPath: 'arrayValue.-1.name' });
expect(value).to.equal('lastItem');
});
it('should not include children by default', async () => {
const { value } = await odc.getValue({});
expect(value.children).to.be.undefined;
});
it('should not include children if maxChildDepth set to zero', async () => {
const { value } = await odc.getValue({ responseMaxChildDepth: 0 });
expect(value.children).to.be.undefined;
});
it('should include children to specified depth', async () => {
const { value } = await odc.getValue({ responseMaxChildDepth: 2 });
expect(value.children).to.not.be.empty;
for (const child of value.children) {
for (const subchild of child.children) {
// We only requested 2 so make sure it only returned two levels
expect(subchild.children).to.be.undefined;
}
}
});
it('should work with nodeRef base', async () => {
const storeResult = await odc.storeNodeReferences();
const key = 10;
const storeNode = storeResult.flatTree[key];
const { value } = await odc.getValue({ base: 'nodeRef', keyPath: `${key}` });
expect(value.id).to.equal(storeNode.id);
expect(value.subtype).to.equal(storeNode.subtype);
});
it('should be able to retrieve a RowList item component', async () => {
const { value } = await odc.getValue({
keyPath: '#pagesContainerGroup.0.#rowListWithCustomTitleComponent.1.items.2'
});
expect(value.subtype).to.equal('RowListItemComponent');
});
it('should be able to retrieve a RowList item component\'s children', async () => {
const { value } = await odc.getValue({
keyPath: '#pagesContainerGroup.0.#rowListWithCustomTitleComponent.1.items.2.#rect'
});
expect(value.id).to.equal('rect');
});
it('should be able to retrieve a RowList title component', async () => {
const { value } = await odc.getValue({
keyPath: '#pagesContainerGroup.0.#rowListWithCustomTitleComponent.1.title'
});
expect(value.subtype).to.equal('RowListRowTitleComponent');
});
it('should be able to retrieve a MarkupGrid item component', async () => {
const { value } = await odc.getValue({
keyPath: '#pagesContainerGroup.0.#markupGrid.1'
});
expect(value.itemContent.id).to.equal('item 1');
});
describe('Brightscript interface function calls', function () {
describe('getParent()', () => {
it('should work on node item', async () => {
const { value } = await odc.getValue({ keyPath: '#poster.getParent()' });
expect(value.subtype).to.equal('MainScene');
});
it('should gracefully fallback if called on nonsupported type', async () => {
const { found } = await odc.getValue({ keyPath: 'intValue.getParent()' });
expect(found).to.false;
});
});
describe('count()', () => {
it('should work on array item', async () => {
const { value } = await odc.getValue({ base: 'global', keyPath: 'arrayValue.count()' });
expect(value).to.equal(3);
});
it('should work on AA item', async () => {
const { value } = await odc.getValue({ base: 'global', keyPath: 'arrayValue.0.count()' });
expect(value).to.equal(1);
});
it('should work on node item', async () => {
const { value } = await odc.getValue({ base: 'global', keyPath: 'AuthManager.count()' });
expect(value).to.equal(6);
});
it('should gracefully fallback if called on nonsupported type', async () => {
const { found } = await odc.getValue({ base: 'global', keyPath: 'intValue.count()' });
expect(found).to.false;
});
});
describe('keys()', () => {
it('should work on AA item', async () => {
const { value } = await odc.getValue({ base: 'global', keyPath: 'arrayValue.0.keys()' });
expect(value).to.be.instanceof(Array);
expect(value[0]).to.equal('name');
});
it('should work on node item', async () => {
const { value } = await odc.getValue({ base: 'global', keyPath: 'AuthManager.keys()' });
expect(value).to.be.instanceof(Array);
expect(value[0]).to.equal('change');
});
it('should gracefully fallback if called on nonsupported type', async () => {
const { found } = await odc.getValue({ base: 'global', keyPath: 'intValue.keys()' });
expect(found).to.false;
});
});
describe('len()', () => {
it('should work on string item', async () => {
const { value } = await odc.getValue({ base: 'global', keyPath: 'stringValue.len()' });
expect(value).to.equal(11);
});
it('should gracefully fallback if called on nonsupported type', async () => {
const { found } = await odc.getValue({ base: 'global', keyPath: 'intValue.len()' });
expect(found).to.false;
});
});
describe('getChildCount()', () => {
it('should work on node item', async () => {
const { value } = await odc.getValue({ keyPath: '#pagesContainerGroup.getChildCount()' });
expect(value).to.equal(1);
});
it('should gracefully fallback if called on nonsupported type', async () => {
const { found } = await odc.getValue({ base: 'global', keyPath: 'intValue.getChildCount()' });
expect(found).to.false;
});
});
describe('threadinfo()', () => {
it('should work on node item', async () => {
const { value } = await odc.getValue({ keyPath: 'threadinfo()' });
const currentThread = value.currentThread;
expect(currentThread.name).to.equal('MainScene');
expect(currentThread.type).to.equal('Render');
});
it('should gracefully fallback if called on nonsupported type', async () => {
const { found } = await odc.getValue({ base: 'global', keyPath: 'intValue.threadinfo()' });
expect(found).to.false;
});
});
describe('getFieldTypes()', () => {
it('should work on node item', async () => {
const { value } = await odc.getValue({ keyPath: 'getFieldTypes()' });
const expectedValues = {
allowBackgroundTask: 'boolean',
backExitsScene: 'boolean',
backgroundColor: 'color',
backgroundUri: 'uri',
change: 'std::type_index',
childRenderOrder: 'std::type_index',
clippingRect: 'rect2d',
currentDesignResolution: 'std::type_index',
dialog: 'std::type_index',
enableRenderTracking: 'boolean',
focusable: 'boolean',
focusedChild: 'std::type_index',
id: 'string',
inheritParentOpacity: 'boolean',
inheritParentTransform: 'boolean',
limitBackgroundToUIResolution: 'boolean',
muteAudioGuide: 'boolean',
opacity: 'float',
pagesContainer: 'node',
palette: 'std::type_index',
renderPass: 'integer',
renderTracking: 'std::type_index',
rotation: 'float',
scale: 'vector2d',
scaleRotateCenter: 'vector2d',
translation: 'vector2d',
visible: 'boolean'
};
expect(Object.keys(value).length).to.equal(Object.keys(expectedValues).length);
for (const key in expectedValues) {
expect(value[key]).to.equal(expectedValues[key]);
}
});
it('should gracefully fallback if called on nonsupported type', async () => {
const { found } = await odc.getValue({ base: 'global', keyPath: 'intValue.getFieldTypes()' });
expect(found).to.false;
});
});
describe('subtype()', () => {
it('should work on node item', async () => {
const { value } = await odc.getValue({ keyPath: '#rowListWithCustomTitleComponent.subtype()' });
expect(value).to.equal('RowList');
});
it('should gracefully fallback if called on nonsupported type', async () => {
const { found } = await odc.getValue({ base: 'global', keyPath: 'intValue.subtype()' });
expect(found).to.false;
});
});
describe('boundingRect()', () => {
it('should work on node item', async () => {
const { value } = await odc.getValue({ keyPath: '#rowListWithCustomTitleComponent.boundingRect()' });
expect(value.height).to.equal(430);
expect(value.width).to.equal(1950);
expect(value.x).to.equal(135);
expect(value.y).to.equal(685);
});
it('should gracefully fallback if called on nonsupported type', async () => {
const { found } = await odc.getValue({ base: 'global', keyPath: 'intValue.boundingRect()' });
expect(found).to.false;
});
});
describe('localBoundingRect()', () => {
it('should work on node item', async () => {
const { value } = await odc.getValue({ keyPath: '#rowListWithCustomTitleComponent.localBoundingRect()' });
expect(value.height).to.equal(430);
expect(value.width).to.equal(1950);
expect(value.x).to.equal(-15);
expect(value.y).to.equal(-15);
});
it('should gracefully fallback if called on nonsupported type', async () => {
const { found } = await odc.getValue({ base: 'global', keyPath: 'intValue.localBoundingRect()' });
expect(found).to.false;
});
});
describe('sceneBoundingRect()', () => {
it('should work on node item', async () => {
const { value } = await odc.getValue({ keyPath: '#rowListWithCustomTitleComponent.sceneBoundingRect()' });
expect(value.height).to.equal(430);
expect(value.width).to.equal(1950);
expect(value.x).to.equal(135);
expect(value.y).to.equal(685);
});
it('should gracefully fallback if called on nonsupported type', async () => {
const { found } = await odc.getValue({ base: 'global', keyPath: 'intValue.sceneBoundingRect()' });
expect(found).to.false;
});
});
describe('sceneSubBoundingRect()', () => {
it('should work on node item', async () => {
const { value } = await odc.getValue({ keyPath: '#rowListWithCustomTitleComponent.sceneSubBoundingRect(item1_1)' });
expect(value.height).to.equal(150);
expect(value.width).to.equal(300);
expect(value.x).to.equal(480);
expect(value.y).to.equal(936);
});
it('should gracefully fallback if called on nonsupported type', async () => {
const { found } = await odc.getValue({ base: 'global', keyPath: 'intValue.sceneSubBoundingRect(item0_1)()' });
expect(found).to.false;
});
});
});
});
describe('getValues', function () {
it('should work with multiple values and should return the timeTaken value', async () => {
const { results, timeTaken } = await odc.getValues({
requests: {
subchild1: { keyPath: '#testTarget.1.#subchild1' },
subchild2: { keyPath: '#testTarget.1.1' }
}
});
expect(results.subchild1.value.id).to.eq('subchild1');
expect(results.subchild2.value.id).to.eq('subchild2');
expect(timeTaken).to.be.a('number');
});
});
describe('getFocusedNode', function () {
it('should return currently focused node', async () => {
await odc.focusNode({
keyPath: '#pagesContainerGroup.#loginButton'
});
const { node } = await odc.getFocusedNode();
expect(node).to.be.ok;
expect(node!.id).to.equal('loginButton');
});
it('should not return the node if includeNode is false', async () => {
await odc.focusNode({
keyPath: '#pagesContainerGroup.#loginButton',
});
const { node } = await odc.getFocusedNode({ includeNode: false });
expect(node).to.be.not.be.ok;
});
it('should not include children by default', async () => {
const { node } = await odc.getFocusedNode();
expect(node).to.be.ok;
expect(node!.children).to.be.undefined;
});
it('should not include children if maxChildDepth is set to zero', async () => {
const { node } = await odc.getFocusedNode({ responseMaxChildDepth: 0 });
expect(node).to.be.ok;
expect(node!.children).to.be.undefined;
});
it('should include children to specified depth', async () => {
const { node } = await odc.getFocusedNode({ responseMaxChildDepth: 1 });
expect(node).to.be.ok;
expect(node?.children).to.not.be.empty;
for (const child of node?.children ?? []) {
// We only requested 1 so make sure it only returned a single level
expect(child.children).to.be.undefined;
}
});
it('should not include ref field by default', async () => {
const { ref } = await odc.getFocusedNode();
expect(ref).to.not.be.ok;
});
it('should fail if invalid key supplied or we did not store first', async () => {
try {
await odc.getFocusedNode({ nodeRefKey: 'na', includeRef: true });
} catch (e) {
// failed as expected
return;
}
assert.fail('Should have thrown an exception');
});
it('should return correct ref if requested', async () => {
const storeResult = await odc.storeNodeReferences();
const { node, ref } = await odc.getFocusedNode({ includeRef: true });
expect(ref).to.be.ok;
expect(node).to.be.ok;
expect(storeResult.flatTree[ref!].subtype).to.equal(node!.subtype);
expect(storeResult.flatTree[ref!].id).to.equal(node!.id);
});
it('should return focused arrayGrid child if requested', async () => {
const storeResult = await odc.storeNodeReferences({ includeArrayGridChildren: true });
await odc.focusNode({
keyPath: '#rowListWithCustomTitleComponent'
});
const { node, ref } = await odc.getFocusedNode({
includeRef: true,
returnFocusedArrayGridChild: true
});
expect(ref).to.be.ok;
expect(node).to.be.ok;
expect(storeResult.flatTree[ref!].subtype).to.equal(node!.subtype);
expect(node!.itemContent.id).to.equal('row 0 item 0');
// Reset back to login button for focus
await odc.focusNode({
keyPath: '#pagesContainerGroup.#loginButton'
});
});
it('should include correct keyPath field', async () => {
const expectedKeyPath = '#pagesContainerGroup.0.#loginButton';
await odc.focusNode({ keyPath: expectedKeyPath });
const { keyPath } = await odc.getFocusedNode();
expect(keyPath).to.equal(expectedKeyPath);
});
});
describe('hasFocus', function () {
it('should return true when current node has focus', async () => {
const args: ODC.FocusNodeArgs = { keyPath: '#pagesContainerGroup.#loginButton' };
await odc.focusNode(args);
const hasFocus = await odc.hasFocus(args);
expect(hasFocus).to.be.true;
});
it('should return false when current node does not have focus', async () => {
expect(await odc.hasFocus({ keyPath: '#child1' })).to.be.false;
});
});
describe('isInFocusChain', function () {
it('should return true when current node is in focus chain', async () => {
const args: ODC.FocusNodeArgs = { keyPath: '#pagesContainerGroup.#loginButton' };
await odc.focusNode(args);
const isInFocusChain = await odc.isInFocusChain(args);
expect(isInFocusChain).to.be.true;
});
it('should return false when current node is not in focus chain', async () => {
expect(await odc.isInFocusChain({ keyPath: '#child1' })).to.be.false;
});
});
describe('focusNode', function () {
it('should successfully set focus on the requested node', async () => {
const args: ODC.FocusNodeArgs = { keyPath: '#pagesContainerGroup' };
await odc.focusNode(args);
const hasFocus = await odc.hasFocus(args);
expect(hasFocus).to.be.true;
});
it('should return an error when keypath does not point to a node', async () => {
try {
await odc.focusNode({ keyPath: 'stringValue' });
} catch (e) {
// failed as expected
return;