@enact/spotlight 3.4.9-experimental-3 → 3.4.9-experimental-7

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 (68) hide show
  1. package/{build/Accelerator → Accelerator}/Accelerator.d.ts +0 -0
  2. package/Accelerator/Accelerator.js +149 -156
  3. package/CHANGELOG.md +22 -0
  4. package/{build/Pause → Pause}/Pause.d.ts +0 -0
  5. package/Pause/Pause.js +102 -80
  6. package/Pause/tests/Pause-specs.js +65 -97
  7. package/SpotlightContainerDecorator/SpotlightContainer.js +175 -140
  8. package/{build/SpotlightContainerDecorator → SpotlightContainerDecorator}/SpotlightContainerDecorator.d.ts +0 -0
  9. package/SpotlightContainerDecorator/SpotlightContainerDecorator.js +222 -176
  10. package/SpotlightContainerDecorator/tests/Element.prototype.closest.js +44 -40
  11. package/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +221 -210
  12. package/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +150 -243
  13. package/SpotlightContainerDecorator/useSpotlightContainer.js +47 -28
  14. package/{build/SpotlightRootDecorator → SpotlightRootDecorator}/SpotlightRootDecorator.d.ts +0 -0
  15. package/SpotlightRootDecorator/SpotlightRootDecorator.js +206 -111
  16. package/{build/Spottable → Spottable}/Spottable.d.ts +0 -0
  17. package/Spottable/Spottable.js +448 -410
  18. package/Spottable/tests/Spottable-specs.js +90 -117
  19. package/package.json +3 -2
  20. package/src/container.js +718 -653
  21. package/src/navigate.js +406 -491
  22. package/src/pointer.js +86 -78
  23. package/{build/src → src}/spotlight.d.ts +0 -0
  24. package/src/spotlight.js +846 -885
  25. package/src/target.js +448 -474
  26. package/src/tests/container-specs.js +643 -1251
  27. package/src/tests/navigate-specs.js +77 -134
  28. package/src/tests/pointer-specs.js +126 -182
  29. package/src/tests/spotlight-specs.js +103 -133
  30. package/src/tests/target-specs.js +597 -960
  31. package/src/tests/utils.js +89 -67
  32. package/src/utils.js +155 -158
  33. package/build/Accelerator/Accelerator.js +0 -162
  34. package/build/Accelerator/package.json +0 -3
  35. package/build/CHANGELOG.md +0 -838
  36. package/build/Pause/Pause.js +0 -164
  37. package/build/Pause/package.json +0 -3
  38. package/build/Pause/tests/Pause-specs.js +0 -65
  39. package/build/README.md +0 -61
  40. package/build/SpotlightContainerDecorator/SpotlightContainer.js +0 -176
  41. package/build/SpotlightContainerDecorator/SpotlightContainerDecorator.js +0 -282
  42. package/build/SpotlightContainerDecorator/package.json +0 -3
  43. package/build/SpotlightContainerDecorator/tests/Element.prototype.closest.js +0 -45
  44. package/build/SpotlightContainerDecorator/tests/SpotlightContainerDecorator-specs.js +0 -221
  45. package/build/SpotlightContainerDecorator/tests/useSpotlightContainer-specs.js +0 -160
  46. package/build/SpotlightContainerDecorator/useSpotlightContainer.js +0 -133
  47. package/build/SpotlightRootDecorator/SpotlightRootDecorator.js +0 -189
  48. package/build/SpotlightRootDecorator/package.json +0 -3
  49. package/build/Spottable/Spottable.js +0 -491
  50. package/build/Spottable/package.json +0 -3
  51. package/build/Spottable/tests/Spottable-specs.js +0 -90
  52. package/build/package-lock.json +0 -229
  53. package/build/package.json +0 -28
  54. package/build/src/container.js +0 -1201
  55. package/build/src/navigate.js +0 -419
  56. package/build/src/pointer.js +0 -183
  57. package/build/src/spotlight.js +0 -896
  58. package/build/src/target.js +0 -507
  59. package/build/src/tests/container-specs.js +0 -653
  60. package/build/src/tests/navigate-specs.js +0 -87
  61. package/build/src/tests/pointer-specs.js +0 -130
  62. package/build/src/tests/spotlight-specs.js +0 -112
  63. package/build/src/tests/target-specs.js +0 -614
  64. package/build/src/tests/utils.js +0 -104
  65. package/build/src/utils.js +0 -180
  66. package/build/styles/debug.less +0 -97
  67. package/build/styles/mixins.less +0 -63
  68. package/docs/index.md +0 -364
@@ -1,1261 +1,653 @@
1
- import {
2
- addContainer,
3
- configureContainer,
4
- configureDefaults,
5
- containerAttribute,
6
- getAllContainerIds,
7
- getContainerConfig,
8
- getContainerDefaultElement,
9
- getContainerFocusTarget,
10
- getContainerLastFocusedElement,
11
- getContainerNavigableElements,
12
- getContainersForNode,
13
- getDefaultContainer,
14
- getLastContainer,
15
- getNavigableContainersForNode,
16
- getSpottableDescendants,
17
- isContainer,
18
- isNavigable,
19
- unmountContainer,
20
- removeContainer,
21
- removeAllContainers,
22
- rootContainerId,
23
- setContainerLastFocusedElement,
24
- setLastContainer,
25
- setLastContainerFromTarget
26
- } from '../container';
1
+ "use strict";
27
2
 
28
- import {
29
- container,
30
- join,
31
- node,
32
- someContainers,
33
- someNodes,
34
- someSpottables,
35
- someSpottablesAndContainers,
36
- spottable,
37
- testScenario
38
- } from './utils';
3
+ var _container17 = require("../container");
39
4
 
40
- const nonSpottable = () => node({className: 'other'});
5
+ var _utils = require("./utils");
41
6
 
42
- const scenarios = {
43
- onlySpottables: someSpottables(5),
44
- onlyContainers: someContainers(5),
45
- spottableAndContainers: someSpottablesAndContainers(5),
46
- nonSpottableSiblings: join(
47
- someSpottables(5),
48
- someNodes(nonSpottable, 5)
49
- ),
50
- nestedContainers: container(container(container())),
51
- disabledContainers: join(
52
- someSpottables(5),
53
- someContainers(5),
54
- node({[containerAttribute]: 'disabled-container', 'data-spotlight-container-disabled': true})
55
- ),
56
- nestedContainersWithSpottables: join(
57
- someSpottables(5),
58
- container({children: someSpottables(5)})
59
- ),
60
- siblingContainers: join(
61
- container({[containerAttribute]: 'first', children: someSpottables(5)}),
62
- container({[containerAttribute]: 'second', children: someSpottables(5)})
63
- ),
64
- mixedOrder: join(
65
- container({[containerAttribute]: 'first', name: 'c1'}),
66
- spottable({name: 's1'}),
67
- container({[containerAttribute]: 'second', name: 'c2'}),
68
- spottable({name: 's2'})
69
- ),
70
- complexTree: join(
71
- spottable(nonSpottable()),
72
- container({[containerAttribute]: 'first-container', children: join(
73
- someSpottables(2),
74
- container({[containerAttribute]: 'second-container', children: join(
75
- spottable({id: 'secondContainerFirstSpottable'}),
76
- someSpottables(2),
77
- container({
78
- [containerAttribute]: 'third-container',
79
- 'data-spotlight-container-disabled': true,
80
- children: join(
81
- someSpottables(4),
82
- node({id: 'child-of-third'})
83
- )
84
- })
85
- )})
86
- )})
87
- ),
88
- spottablesInDisabledContainer: container({
89
- [containerAttribute]: 'container',
90
- 'data-spotlight-container-disabled': true,
91
- children: someSpottables(5)
92
- }),
93
- spottablesInNestedDisabledContainer: container({
94
- [containerAttribute]: 'container',
95
- 'data-spotlight-container-disabled': true,
96
- children: container({
97
- [containerAttribute]: 'child',
98
- children: someSpottables(5)
99
- })
100
- }),
101
- containerWithDefaultAndLastFocused: container({
102
- [containerAttribute]: 'container',
103
- children: join(
104
- spottable({id: 'firstSpottable'}),
105
- someSpottables(5),
106
- node({id: 'spottableDefault', className: 'spottable spottable-default'}),
107
- spottable({id: 'lastFocused'})
108
- )
109
- }),
110
- nestedContainersWithDefaultAndLastFocused: container({
111
- [containerAttribute]: 'container',
112
- children: join(
113
- spottable({id: 'firstSpottable'}),
114
- someSpottables(5),
115
- container({
116
- [containerAttribute]: 'child',
117
- id: 'spottableDefault',
118
- className: 'spottable-default',
119
- children: join(
120
- spottable({id: 'firstChildSpottable'}),
121
- someSpottables(5),
122
- spottable({id: 'lastChildFocused'})
123
- )
124
- }),
125
- spottable({id: 'lastFocused'})
126
- )
127
- }),
128
- emptySubcontainer: container({
129
- [containerAttribute]: 'container',
130
- children: join(
131
- container({
132
- [containerAttribute]: 'subcontainer'
133
- }),
134
- spottable({id: 'afterSubcontainer'})
135
- )
136
- }),
137
- owned: join(
138
- spottable({id: 's1'}),
139
- node({id: 'n1'}),
140
- container({
141
- [containerAttribute]: 'container',
142
- 'aria-owns': 's1 n1',
143
- children: spottable({id: 's2'})
144
- })
145
- )
146
- };
7
+ var _node, _container, _container2, _container3, _container4, _container5, _container6, _container7, _container8, _container9, _container10, _container11, _container12, _container13, _container15, _container16;
147
8
 
148
- const setupContainers = () => {
149
- configureDefaults({
150
- selector: '.spottable'
151
- });
152
- configureContainer(rootContainerId);
153
- setLastContainer(rootContainerId);
154
- };
9
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
155
10
 
156
- const teardownContainers = () => {
157
- // clean up any containers we create for safe tests
158
- removeAllContainers();
11
+ var nonSpottable = function nonSpottable() {
12
+ return (0, _utils.node)({
13
+ className: 'other'
14
+ });
159
15
  };
160
16
 
161
- describe('container', () => {
162
- describe('#getSpottableDescendants', () => {
163
- beforeEach(setupContainers);
164
- afterEach(teardownContainers);
165
-
166
- test('should find spottables', testScenario(
167
- scenarios.onlySpottables,
168
- () => {
169
- const expected = 5;
170
- const actual = getSpottableDescendants(rootContainerId).length;
171
-
172
- expect(actual).toBe(expected);
173
- }
174
- ));
175
-
176
- test('should find containers', testScenario(
177
- scenarios.onlyContainers,
178
- () => {
179
- const expected = 5;
180
- const actual = getSpottableDescendants(rootContainerId).length;
181
-
182
- expect(actual).toBe(expected);
183
- }
184
- ));
185
-
186
- test('should find spottables and containers', testScenario(
187
- scenarios.spottableAndContainers,
188
- () => {
189
- const expected = 10;
190
- const actual = getSpottableDescendants(rootContainerId).length;
191
-
192
- expect(actual).toBe(expected);
193
- }
194
- ));
195
-
196
- test('should only find spottables with non-spottable siblings', testScenario(
197
- scenarios.nonSpottableSiblings,
198
- () => {
199
- const expected = 5;
200
- const actual = getSpottableDescendants(rootContainerId).length;
201
-
202
- expect(actual).toBe(expected);
203
- }
204
- ));
205
-
206
- test('should only find top-level containers', testScenario(
207
- scenarios.nestedContainers,
208
- () => {
209
- const expected = 1;
210
- const actual = getSpottableDescendants(rootContainerId).length;
211
-
212
- expect(actual).toBe(expected);
213
- }
214
- ));
215
-
216
- test('should only find top-level containers and spottables', testScenario(
217
- scenarios.nestedContainersWithSpottables,
218
- () => {
219
- const expected = 6;
220
- const actual = getSpottableDescendants(rootContainerId).length;
221
-
222
- expect(actual).toBe(expected);
223
- }
224
- ));
225
-
226
- test('should not find spottables in sibling containers', testScenario(
227
- scenarios.siblingContainers,
228
- () => {
229
- configureContainer('first');
230
-
231
- const expected = 5;
232
- const actual = getSpottableDescendants('first').length;
233
-
234
- expect(actual).toBe(expected);
235
- }
236
- ));
237
-
238
- test('should not find spottables in descendant containers', testScenario(
239
- scenarios.complexTree,
240
- () => {
241
- configureContainer('first-container');
242
-
243
- const expected = 3;
244
- const actual = getSpottableDescendants('first-container').length;
245
-
246
- expect(actual).toBe(expected);
247
- }
248
- ));
249
-
250
- test('should not find containers that are disabled', testScenario(
251
- scenarios.complexTree,
252
- () => {
253
- configureContainer('first-container');
254
- configureContainer('second-container');
255
-
256
- const expected = 3;
257
- const actual = getSpottableDescendants('second-container').length;
258
-
259
- expect(actual).toBe(expected);
260
- }
261
- ));
262
-
263
- test('should not any spottables within a disabled container', testScenario(
264
- scenarios.spottablesInDisabledContainer,
265
- () => {
266
- configureContainer('container');
267
-
268
- const expected = 0;
269
- const actual = getSpottableDescendants('container').length;
270
-
271
- expect(actual).toBe(expected);
272
- }
273
- ));
274
-
275
- test(
276
- 'should not any spottables within a disabled ancestor container',
277
- testScenario(
278
- scenarios.spottablesInNestedDisabledContainer,
279
- () => {
280
- configureContainer('container');
281
- configureContainer('child');
282
-
283
- const expected = 0;
284
- const actual = getSpottableDescendants('child').length;
285
-
286
- expect(actual).toBe(expected);
287
- }
288
- )
289
- );
290
-
291
- test('should return spottables and containers in source order', testScenario(
292
- scenarios.mixedOrder,
293
- () => {
294
- const expected = ['c1', 's1', 'c2', 's2'];
295
- const actual = getSpottableDescendants(rootContainerId).map(n => n.getAttribute('name'));
296
-
297
- expect(actual).toEqual(expected);
298
- }
299
- ));
300
-
301
- test('should include owned nodes', testScenario(
302
- scenarios.owned,
303
- () => {
304
- configureContainer('container');
305
-
306
- // owned nodes follow internal nodes
307
- const expected = ['s2', 's1'];
308
- const actual = getSpottableDescendants('container').map(n => n.getAttribute('id'));
309
-
310
- expect(actual).toEqual(expected);
311
- }
312
- ));
313
- });
314
-
315
- describe('#getContainersForNode', () => {
316
- test(
317
- 'should return the rootContainerId when no other containers exist',
318
- testScenario(
319
- scenarios.onlySpottables,
320
- (root) => {
321
- const expected = [rootContainerId];
322
- const actual = getContainersForNode(root.lastChild);
323
-
324
- expect(actual).toEqual(expected);
325
- }
326
- )
327
- );
328
-
329
- test('should return all ancestor container ids', testScenario(
330
- scenarios.complexTree,
331
- (root) => {
332
- const childOfThird = root.querySelector('#child-of-third');
333
- const expected = [
334
- rootContainerId,
335
- 'first-container',
336
- 'second-container',
337
- 'third-container'
338
- ];
339
- const actual = getContainersForNode(childOfThird);
340
-
341
- expect(actual).toEqual(expected);
342
- }
343
- ));
344
-
345
- test('should return immediate container id as last in list', testScenario(
346
- scenarios.complexTree,
347
- (root) => {
348
- const childOfThird = root.querySelector('#child-of-third');
349
- const expected = 'third-container';
350
- const actual = getContainersForNode(childOfThird).pop();
351
-
352
- expect(actual).toEqual(expected);
353
- }
354
- ));
355
- });
356
-
357
- describe('#isContainer', () => {
358
- beforeEach(() => {
359
- configureContainer('test-container');
360
- });
361
-
362
- afterEach(() => {
363
- removeContainer('test-container');
364
- });
365
-
366
- test('should return true for nodes that have the container attribute', () => {
367
- const div = document.createElement('div');
368
- div.setAttribute('data-spotlight-container', 'my-container');
369
-
370
- const expected = true;
371
- const actual = isContainer(div);
372
-
373
- expect(actual).toBe(expected);
374
- });
375
-
376
- test(
377
- 'should return false for nodes that do not have the container attribute',
378
- () => {
379
- const div = document.createElement('div');
380
-
381
- const expected = false;
382
- const actual = isContainer(div);
383
-
384
- expect(actual).toBe(expected);
385
- }
386
- );
387
-
388
- test('should return true for a configured container id', () => {
389
- const expected = true;
390
- const actual = isContainer('test-container');
391
-
392
- expect(actual).toBe(expected);
393
- });
394
-
395
- test('should return false for a unconfigured container id', () => {
396
- const expected = false;
397
- const actual = isContainer('unconfigured-container');
398
-
399
- expect(actual).toBe(expected);
400
- });
401
- });
402
-
403
- describe('#getContainerFocusTarget', () => {
404
- beforeEach(setupContainers);
405
- afterEach(teardownContainers);
406
-
407
- test(
408
- 'should return the last focused element when enterTo is "last-focused"',
409
- testScenario(
410
- scenarios.containerWithDefaultAndLastFocused,
411
- (root) => {
412
- configureContainer('container', {
413
- enterTo: 'last-focused',
414
- defaultElement: '.spottable-default'
415
- });
416
-
417
- setContainerLastFocusedElement(root.querySelector('#lastFocused'), ['container']);
418
-
419
- const expected = 'lastFocused';
420
- const actual = getContainerFocusTarget('container').id;
421
-
422
- expect(actual).toBe(expected);
423
- }
424
- )
425
- );
426
-
427
- test(
428
- 'should return the default spottable element when enterTo is "last-focused" but no element has been focused',
429
- testScenario(
430
- scenarios.containerWithDefaultAndLastFocused,
431
- () => {
432
- configureContainer('container', {
433
- enterTo: 'last-focused',
434
- defaultElement: '.spottable-default'
435
- });
436
-
437
- const expected = 'spottableDefault';
438
- const actual = getContainerFocusTarget('container').id;
439
-
440
- expect(actual).toBe(expected);
441
- }
442
- )
443
- );
444
-
445
- test(
446
- 'should return the first spottable element when enterTo is "last-focused" and defaultElement is not configured',
447
- testScenario(
448
- scenarios.containerWithDefaultAndLastFocused,
449
- () => {
450
- configureContainer('container', {
451
- enterTo: 'last-focused'
452
- });
453
-
454
- const expected = 'firstSpottable';
455
- const actual = getContainerFocusTarget('container').id;
456
-
457
- expect(actual).toBe(expected);
458
- }
459
- )
460
- );
461
-
462
- test(
463
- 'should return the first spottable element when enterTo is "last-focused" and defaultElement is not found',
464
- testScenario(
465
- scenarios.containerWithDefaultAndLastFocused,
466
- () => {
467
- configureContainer('container', {
468
- enterTo: 'last-focused',
469
- // configured, but not found
470
- defaultElement: '[data-default-spottable]'
471
- });
472
-
473
- const expected = 'firstSpottable';
474
- const actual = getContainerFocusTarget('container').id;
475
-
476
- expect(actual).toBe(expected);
477
- }
478
- )
479
- );
480
-
481
- test(
482
- 'should return the default spottable element when enterTo is "default-element"',
483
- testScenario(
484
- scenarios.containerWithDefaultAndLastFocused,
485
- () => {
486
- configureContainer('container', {
487
- enterTo: 'default-element',
488
- defaultElement: '.spottable-default'
489
- });
490
-
491
- const expected = 'spottableDefault';
492
- const actual = getContainerFocusTarget('container').id;
493
-
494
- expect(actual).toBe(expected);
495
- }
496
- )
497
- );
498
-
499
- test(
500
- 'should return the default spottable element when enterTo is "default-element" and defaultElement contains an array of selectors',
501
- testScenario(
502
- scenarios.containerWithDefaultAndLastFocused,
503
- () => {
504
- configureContainer('container', {
505
- enterTo: 'default-element',
506
- defaultElement: ['.does-not-exist', '.spottable-default']
507
- });
508
-
509
- const expected = 'spottableDefault';
510
- const actual = getContainerFocusTarget('container').id;
511
-
512
- expect(actual).toBe(expected);
513
- }
514
- )
515
- );
516
-
517
- // FIXME: This is testing a previously supported feature (setting a node as defaultElement)
518
- // which was never documented and should be removed in a future release.
519
- test(
520
- 'should return the default spottable element when enterTo is "default-element" and defaultElement contains an array of selectors wiht a node reference',
521
- testScenario(
522
- scenarios.containerWithDefaultAndLastFocused,
523
- (root) => {
524
- configureContainer('container', {
525
- enterTo: 'default-element',
526
- defaultElement: [root.querySelector('#lastFocused'), '.spottable-default']
527
- });
528
-
529
- const expected = 'lastFocused';
530
- const actual = getContainerFocusTarget('container').id;
531
-
532
- expect(actual).toBe(expected);
533
- }
534
- )
535
- );
536
-
537
- test(
538
- 'should return the first spottable element when enterTo is "default-element" but defaultElement is not configured',
539
- testScenario(
540
- scenarios.containerWithDefaultAndLastFocused,
541
- () => {
542
- configureContainer('container', {
543
- enterTo: 'default-element'
544
- });
545
-
546
- const expected = 'firstSpottable';
547
- const actual = getContainerFocusTarget('container').id;
548
-
549
- expect(actual).toBe(expected);
550
- }
551
- )
552
- );
553
-
554
- test(
555
- 'should return the first spottable element when enterTo is "default-element" but defaultElement is not found',
556
- testScenario(
557
- scenarios.containerWithDefaultAndLastFocused,
558
- () => {
559
- configureContainer('container', {
560
- enterTo: 'default-element',
561
- defaultElement: '[data-default-spottable]'
562
- });
563
-
564
- const expected = 'firstSpottable';
565
- const actual = getContainerFocusTarget('container').id;
566
-
567
- expect(actual).toBe(expected);
568
- }
569
- )
570
- );
571
-
572
- test(
573
- 'should return the default element when enterTo is "default-element" and defaultElement is within a subcontainer',
574
- testScenario(
575
- scenarios.complexTree,
576
- () => {
577
- configureContainer('first-container', {
578
- enterTo: 'default-element',
579
- defaultElement: `[${containerAttribute}='second-container'] > .spottable`
580
- });
581
- configureContainer('second-container');
582
-
583
- const expected = 'second-container';
584
- const actual = getContainerFocusTarget('first-container').parentNode.dataset.spotlightId;
585
-
586
- expect(actual).toBe(expected);
587
- }
588
- )
589
- );
590
-
591
- test(
592
- 'should return the first spottable element when enterTo is "default-element" and defaultElement is within a disabled subcontainer',
593
- testScenario(
594
- scenarios.complexTree,
595
- () => {
596
- configureContainer('second-container', {
597
- enterTo: 'default-element',
598
- defaultElement: `[${containerAttribute}='third-container'] > .spottable`
599
- });
600
- configureContainer('third-container');
601
-
602
- const expected = 'secondContainerFirstSpottable';
603
- const actual = getContainerFocusTarget('second-container').id;
604
-
605
- expect(actual).toBe(expected);
606
- }
607
- )
608
- );
609
-
610
- test(
611
- 'should return the first spottable element when enterTo is not configured',
612
- testScenario(
613
- scenarios.containerWithDefaultAndLastFocused,
614
- () => {
615
- configureContainer('container');
616
-
617
- const expected = 'firstSpottable';
618
- const actual = getContainerFocusTarget('container').id;
619
-
620
- expect(actual).toBe(expected);
621
- }
622
- )
623
- );
624
-
625
- test(
626
- 'should return the default element when enterTo is not configured and defaultElement is configured',
627
- testScenario(
628
- scenarios.containerWithDefaultAndLastFocused,
629
- () => {
630
- configureContainer('container', {
631
- defaultElement: '.spottable-default'
632
- });
633
-
634
- const expected = 'spottableDefault';
635
- const actual = getContainerFocusTarget('container').id;
636
-
637
- expect(actual).toBe(expected);
638
- }
639
- )
640
- );
641
-
642
- test('should cascade search into child containers with', testScenario(
643
- scenarios.nestedContainersWithDefaultAndLastFocused,
644
- (root) => {
645
- configureContainer('container', {
646
- defaultElement: '.spottable-default'
647
- });
648
-
649
- configureContainer('child', {
650
- enterTo: 'last-focused',
651
- defaultElement: '.spottable-default'
652
- });
653
-
654
- setContainerLastFocusedElement(root.querySelector('#lastChildFocused'), [rootContainerId, 'container', 'child']);
655
-
656
- const expected = 'lastChildFocused';
657
- const actual = getContainerFocusTarget('container').id;
658
-
659
- expect(actual).toBe(expected);
660
- }
661
- ));
662
-
663
- test(
664
- 'should cascade search into child containers when multiple containers have enterTo configured',
665
- testScenario(
666
- scenarios.nestedContainersWithDefaultAndLastFocused,
667
- (root) => {
668
- configureContainer('container', {
669
- enterTo: 'last-focused',
670
- defaultElement: '.spottable-default'
671
- });
672
-
673
- configureContainer('child', {
674
- enterTo: 'last-focused',
675
- defaultElement: '.spottable-default'
676
- });
677
-
678
- setContainerLastFocusedElement(root.querySelector('#lastChildFocused'), [rootContainerId, 'container', 'child']);
679
-
680
- const expected = 'lastChildFocused';
681
- const actual = getContainerFocusTarget('container').id;
682
-
683
- expect(actual).toBe(expected);
684
- }
685
- )
686
- );
687
-
688
- test('should skip empty subcontainers', testScenario(
689
- scenarios.emptySubcontainer,
690
- () => {
691
- configureContainer('container');
692
- configureContainer('subcontainer');
693
-
694
- const expected = 'afterSubcontainer';
695
- const actual = getContainerFocusTarget('container').id;
696
-
697
- expect(actual).toBe(expected);
698
- }
699
- ));
700
-
701
- test('should return null for an unconfigured container', testScenario(
702
- scenarios.complexTree,
703
- () => {
704
- const expected = null;
705
- const actual = getContainerFocusTarget('first-container');
706
-
707
- expect(actual).toBe(expected);
708
- }
709
- ));
710
- });
711
-
712
- describe('#isNavigable', () => {
713
- beforeEach(setupContainers);
714
- afterEach(teardownContainers);
715
-
716
- test('should return false a null node', () => {
717
- const expected = false;
718
- const actual = isNavigable(null, rootContainerId);
719
-
720
- expect(actual).toBe(expected);
721
- });
722
-
723
- test(
724
- 'should return true for any node when not verifying selector and without a navigableFilter',
725
- testScenario(
726
- scenarios.nonSpottableSiblings,
727
- (root) => {
728
- const expected = true;
729
- const actual = isNavigable(root.querySelector('.other'), rootContainerId);
730
-
731
- expect(actual).toBe(expected);
732
- }
733
- )
734
- );
735
-
736
- test(
737
- 'should return true for spottable children when verifying selector',
738
- testScenario(
739
- scenarios.onlySpottables,
740
- (root) => {
741
- const expected = true;
742
- const actual = isNavigable(root.querySelector('.spottable'), rootContainerId, true);
743
-
744
- expect(actual).toBe(expected);
745
- }
746
- )
747
- );
748
-
749
- test('should return true for containers', testScenario(
750
- scenarios.onlyContainers,
751
- (root) => {
752
- const expected = true;
753
- const actual = isNavigable(root.querySelector(`[${containerAttribute}]`), rootContainerId, true);
754
-
755
- expect(actual).toBe(expected);
756
- }
757
- ));
758
-
759
- test('should filter the node with navigableFilter', testScenario(
760
- scenarios.spottableAndContainers,
761
- (root) => {
762
- configureContainer(rootContainerId, {
763
- // test filter which makes containers non-navigable
764
- navigableFilter: n => !isContainer(n)
765
- });
766
-
767
- const expected = false;
768
- const actual = isNavigable(root.querySelector(`[${containerAttribute}]`), rootContainerId, true);
769
-
770
- expect(actual).toBe(expected);
771
- }
772
- ));
773
- });
774
-
775
- describe('#setContainerLastFocusedElement', () => {
776
- beforeEach(setupContainers);
777
- afterEach(teardownContainers);
778
-
779
- test('should update lastFocusedElement for a single container', testScenario(
780
- scenarios.onlySpottables,
781
- (root) => {
782
- const item = root.querySelectorAll('.spottable').item(3);
783
-
784
- setContainerLastFocusedElement(
785
- item,
786
- getContainersForNode(item)
787
- );
788
-
789
- const expected = item;
790
- const actual = getContainerConfig(rootContainerId).lastFocusedElement;
791
-
792
- expect(actual).toBe(expected);
793
- }
794
- ));
795
-
796
- test(
797
- 'should update lastFocusedElement to the node\'s container id when element is within a container with enterTo configured',
798
- testScenario(
799
- scenarios.complexTree,
800
- (root) => {
801
- const item = root
802
- .querySelectorAll(`[${containerAttribute}='first-container'] .spottable`)
803
- .item(0);
804
- configureContainer('first-container', {
805
- enterTo: 'last-focused'
806
- });
807
-
808
- setContainerLastFocusedElement(
809
- item,
810
- getContainersForNode(item)
811
- );
812
-
813
- const expected = 'first-container';
814
- const actual = getContainerConfig(rootContainerId).lastFocusedElement;
815
-
816
- expect(actual).toBe(expected);
817
- }
818
- )
819
- );
820
-
821
- test(
822
- 'should ignore sub-containers that does not have enterTo configured',
823
- testScenario(
824
- scenarios.complexTree,
825
- (root) => {
826
- const item = root
827
- .querySelectorAll(`[${containerAttribute}='second-container'] .spottable`)
828
- .item(0);
829
-
830
- setContainerLastFocusedElement(
831
- item,
832
- getContainersForNode(item)
833
- );
834
-
835
- const expected = item;
836
- const actual = getContainerConfig(rootContainerId).lastFocusedElement;
837
-
838
- expect(actual).toBe(expected);
839
- }
840
- )
841
- );
842
-
843
- test(
844
- 'should update lastFocusedElement to the first sub-container that has enterTo configured',
845
- testScenario(
846
- scenarios.complexTree,
847
- (root) => {
848
- const item = root
849
- .querySelectorAll(`[${containerAttribute}='second-container'] .spottable`)
850
- .item(0);
851
- configureContainer('second-container', {
852
- enterTo: 'last-focused'
853
- });
854
-
855
- setContainerLastFocusedElement(
856
- item,
857
- getContainersForNode(item)
858
- );
859
-
860
- const expected = 'second-container';
861
- const actual = getContainerConfig(rootContainerId).lastFocusedElement;
862
-
863
- expect(actual).toBe(expected);
864
- }
865
- )
866
- );
867
- });
868
-
869
- describe('#unmountContainer', () => {
870
- beforeEach(setupContainers);
871
- afterEach(teardownContainers);
872
-
873
- test(
874
- 'should return element when last focused is not within a subcontainer with enterTo',
875
- testScenario(
876
- scenarios.onlySpottables,
877
- (root) => {
878
- const index = 3;
879
- const item = root.querySelectorAll('.spottable').item(index);
880
- setContainerLastFocusedElement(
881
- item,
882
- getContainersForNode(item)
883
- );
884
-
885
- unmountContainer(rootContainerId);
886
-
887
- const expected = true;
888
- const actual = getContainerConfig(rootContainerId).lastFocusedKey.element;
889
-
890
- expect(actual).toBe(expected);
891
- }
892
- )
893
- );
894
-
895
- test(
896
- 'should return container when last focused is within a subcontainer with enterTo',
897
- testScenario(
898
- scenarios.complexTree,
899
- (root) => {
900
- const item = root
901
- .querySelectorAll(`[${containerAttribute}="first-container"] .spottable`)
902
- .item(1);
903
- configureContainer('first-container', {
904
- enterTo: 'last-focused'
905
- });
906
- setContainerLastFocusedElement(
907
- item,
908
- getContainersForNode(item)
909
- );
910
-
911
- unmountContainer(rootContainerId);
912
-
913
- const expected = true;
914
- const actual = getContainerConfig(rootContainerId).lastFocusedKey.container;
915
-
916
- expect(actual).toBe(expected);
917
- }
918
- )
919
- );
920
-
921
- test(
922
- 'should save the index of the node when lastFocusedPersist is undefined',
923
- testScenario(
924
- scenarios.onlySpottables,
925
- (root) => {
926
- const index = 3;
927
- const item = root.querySelectorAll('.spottable').item(index);
928
- setContainerLastFocusedElement(
929
- item,
930
- getContainersForNode(item)
931
- );
932
-
933
- unmountContainer(rootContainerId);
934
-
935
- const expected = index;
936
- const actual = getContainerConfig(rootContainerId).lastFocusedKey.key;
937
-
938
- expect(actual).toBe(expected);
939
- }
940
- )
941
- );
942
-
943
- test(
944
- 'should save a custom key for container-configured lastFocusedPersist',
945
- testScenario(
946
- scenarios.onlySpottables,
947
- (root) => {
948
- const index = 3;
949
- const item = root.querySelectorAll('.spottable').item(3);
950
- configureContainer(rootContainerId, {
951
- lastFocusedPersist: (n, all) => ({
952
- element: true,
953
- key: `item-${all.indexOf(n)}`
954
- })
955
- });
956
- setContainerLastFocusedElement(
957
- item,
958
- getContainersForNode(item)
959
- );
960
-
961
- unmountContainer(rootContainerId);
962
-
963
- const expected = `item-${index}`;
964
- const actual = getContainerConfig(rootContainerId).lastFocusedKey.key;
965
-
966
- expect(actual).toBe(expected);
967
- }
968
- )
969
- );
970
-
971
- test(
972
- 'should save the container id as the key when a container with enterTo configured had the last focused item',
973
- testScenario(
974
- scenarios.complexTree,
975
- (root) => {
976
- const item = root
977
- .querySelectorAll(`[${containerAttribute}="first-container"] .spottable`)
978
- .item(1);
979
- configureContainer('first-container', {
980
- enterTo: 'last-focused'
981
- });
982
- setContainerLastFocusedElement(
983
- item,
984
- getContainersForNode(item)
985
- );
986
-
987
- unmountContainer(rootContainerId);
988
-
989
- const expected = 'first-container';
990
- const actual = getContainerConfig(rootContainerId).lastFocusedKey.key;
991
-
992
- expect(actual).toBe(expected);
993
- }
994
- )
995
- );
996
-
997
- test(
998
- 'should save the index as the key when last focused item is only within containers without enterTo configured',
999
- testScenario(
1000
- scenarios.complexTree,
1001
- (root) => {
1002
- const item = root
1003
- .querySelectorAll(`[${containerAttribute}="second-container"] .spottable`)
1004
- .item(1);
1005
- setContainerLastFocusedElement(
1006
- item,
1007
- getContainersForNode(item)
1008
- );
1009
-
1010
- unmountContainer(rootContainerId);
1011
-
1012
- const expected = 4;
1013
- const actual = getContainerConfig(rootContainerId).lastFocusedKey.key;
1014
-
1015
- expect(actual).toBe(expected);
1016
- }
1017
- )
1018
- );
1019
-
1020
- test('should mark the container inactive', testScenario(
1021
- scenarios.complexTree,
1022
- () => {
1023
- addContainer('first-container');
1024
- unmountContainer('first-container');
1025
-
1026
- const expected = false;
1027
- const actual = getContainerConfig('first-container').active;
1028
-
1029
- expect(actual).toBe(expected);
1030
- }
1031
- ));
1032
- });
1033
-
1034
- describe('#setLastContainerFromTarget', () => {
1035
- beforeEach(setupContainers);
1036
- afterEach(teardownContainers);
1037
-
1038
- test(
1039
- 'should be nearest restrict="self-only" container to current if target is not within it',
1040
- testScenario(
1041
- scenarios.complexTree,
1042
- (root) => {
1043
- configureContainer('first-container', {
1044
- restrict: 'self-only'
1045
- });
1046
- const current = root.querySelector('[data-spotlight-id="first-container"] .spottable');
1047
- const target = root.querySelector('.spottable');
1048
-
1049
- setLastContainerFromTarget(current, target);
1050
-
1051
- const expected = 'first-container';
1052
- const actual = getLastContainer();
1053
-
1054
- expect(actual).toBe(expected);
1055
- }
1056
- )
1057
- );
1058
-
1059
- test(
1060
- 'should be use nearest container to target if within current container',
1061
- testScenario(
1062
- scenarios.complexTree,
1063
- (root) => {
1064
- configureContainer('first-container', {
1065
- restrict: 'none'
1066
- });
1067
- configureContainer('second-container', {
1068
- restrict: 'none'
1069
- });
1070
- const current = root.querySelector('[data-spotlight-id="first-container"] .spottable');
1071
- const target = root.querySelector('[data-spotlight-id="second-container"] .spottable');
1072
-
1073
- setLastContainerFromTarget(current, target);
1074
-
1075
- const expected = 'second-container';
1076
- const actual = getLastContainer();
1077
-
1078
- expect(actual).toBe(expected);
1079
- }
1080
- )
1081
- );
1082
-
1083
- test(
1084
- 'should target container if it is restrict="self-only" and contains current container',
1085
- testScenario(
1086
- scenarios.complexTree,
1087
- (root) => {
1088
- configureContainer('first-container', {
1089
- restrict: 'self-only'
1090
- });
1091
- configureContainer('second-container', {
1092
- restrict: 'none'
1093
- });
1094
- const current = root.querySelector('[data-spotlight-id="second-container"] .spottable');
1095
- const target = root.querySelector('[data-spotlight-id="first-container"]');
1096
-
1097
- setLastContainerFromTarget(current, target);
1098
-
1099
- const expected = 'first-container';
1100
- const actual = getLastContainer();
1101
-
1102
- expect(actual).toBe(expected);
1103
- }
1104
- )
1105
- );
1106
- });
1107
-
1108
- describe('#getDefaultContainer', () => {
1109
- beforeEach(setupContainers);
1110
- afterEach(teardownContainers);
1111
-
1112
- test('should return an empty string when container is inactive', testScenario(
1113
- scenarios.complexTree,
1114
- () => {
1115
- unmountContainer(rootContainerId);
1116
-
1117
- const expected = '';
1118
- const actual = getDefaultContainer();
1119
-
1120
- expect(actual).toBe(expected);
1121
- }
1122
- ));
1123
- });
1124
-
1125
- describe('#getLastContainer', () => {
1126
- beforeEach(setupContainers);
1127
- afterEach(teardownContainers);
1128
-
1129
- test('should return an empty string when container is inactive', testScenario(
1130
- scenarios.complexTree,
1131
- () => {
1132
- addContainer('first-container');
1133
- setLastContainer('first-container');
1134
- unmountContainer('first-container');
1135
-
1136
- const expected = '';
1137
- const actual = getLastContainer();
1138
-
1139
- expect(actual).toBe(expected);
1140
- }
1141
- ));
1142
- });
1143
-
1144
- describe('#getAllContainerIds', () => {
1145
- beforeEach(setupContainers);
1146
- afterEach(teardownContainers);
1147
-
1148
- test('should not include inacive containers', testScenario(
1149
- scenarios.onlyContainers,
1150
- (root) => {
1151
- const {containerId} = root.querySelector('[data-spotlight-id]').dataset;
1152
-
1153
- addContainer(containerId);
1154
- unmountContainer(containerId);
1155
-
1156
- const expected = -1;
1157
- const actual = getAllContainerIds().indexOf(containerId);
1158
-
1159
- expect(actual).toBe(expected);
1160
- }
1161
- ));
1162
- });
1163
-
1164
- describe('#getContainerLastFocusedElement', () => {
1165
- beforeEach(setupContainers);
1166
- afterEach(teardownContainers);
1167
-
1168
- test('should return null for an invalid container', testScenario(
1169
- scenarios.onlySpottables,
1170
- () => {
1171
- const expected = null;
1172
- const actual = getContainerLastFocusedElement('does-not-exist');
1173
-
1174
- expect(actual).toBe(expected);
1175
- }
1176
- ));
1177
- });
1178
-
1179
- describe('#getContainerDefaultElement', () => {
1180
- beforeEach(setupContainers);
1181
- afterEach(teardownContainers);
1182
-
1183
- test('should return null for an invalid container', testScenario(
1184
- scenarios.onlySpottables,
1185
- () => {
1186
- const expected = null;
1187
- const actual = getContainerDefaultElement('does-not-exist');
1188
-
1189
- expect(actual).toBe(expected);
1190
- }
1191
- ));
1192
- });
1193
-
1194
- describe('#getNavigableContainersForNode', () => {
1195
- beforeEach(setupContainers);
1196
- afterEach(teardownContainers);
1197
-
1198
- test(
1199
- 'should include all containers when none are restrict="self-only"',
1200
- testScenario(
1201
- scenarios.complexTree,
1202
- (root) => {
1203
- const expected = [rootContainerId, 'first-container', 'second-container'];
1204
- const actual = getNavigableContainersForNode(root.querySelector('#secondContainerFirstSpottable'));
1205
-
1206
- expect(actual).toEqual(expected);
1207
- }
1208
- )
1209
- );
1210
-
1211
- test(
1212
- 'should include all containers within the first restrict="self-only" container (inclusive)',
1213
- testScenario(
1214
- scenarios.complexTree,
1215
- (root) => {
1216
- configureContainer('first-container', {restrict: 'self-only'});
1217
-
1218
- const expected = ['first-container', 'second-container'];
1219
- const actual = getNavigableContainersForNode(root.querySelector('#secondContainerFirstSpottable'));
1220
-
1221
- expect(actual).toEqual(expected);
1222
- }
1223
- )
1224
- );
1225
- });
1226
-
1227
- describe('#getContainerNavigableElements', () => {
1228
- beforeEach(setupContainers);
1229
- afterEach(teardownContainers);
1230
-
1231
- test(
1232
- 'should return an empty array for an unconfigured container',
1233
- testScenario(
1234
- scenarios.complexTree,
1235
- () => {
1236
- const expected = [];
1237
- const actual = getContainerNavigableElements('first-container');
1238
-
1239
- expect(actual).toEqual(expected);
1240
- }
1241
- )
1242
- );
17
+ var scenarios = {
18
+ onlySpottables: (0, _utils.someSpottables)(5),
19
+ onlyContainers: (0, _utils.someContainers)(5),
20
+ spottableAndContainers: (0, _utils.someSpottablesAndContainers)(5),
21
+ nonSpottableSiblings: (0, _utils.join)((0, _utils.someSpottables)(5), (0, _utils.someNodes)(nonSpottable, 5)),
22
+ nestedContainers: (0, _utils.container)((0, _utils.container)((0, _utils.container)())),
23
+ disabledContainers: (0, _utils.join)((0, _utils.someSpottables)(5), (0, _utils.someContainers)(5), (0, _utils.node)((_node = {}, _defineProperty(_node, _container17.containerAttribute, 'disabled-container'), _defineProperty(_node, 'data-spotlight-container-disabled', true), _node))),
24
+ nestedContainersWithSpottables: (0, _utils.join)((0, _utils.someSpottables)(5), (0, _utils.container)({
25
+ children: (0, _utils.someSpottables)(5)
26
+ })),
27
+ siblingContainers: (0, _utils.join)((0, _utils.container)((_container = {}, _defineProperty(_container, _container17.containerAttribute, 'first'), _defineProperty(_container, "children", (0, _utils.someSpottables)(5)), _container)), (0, _utils.container)((_container2 = {}, _defineProperty(_container2, _container17.containerAttribute, 'second'), _defineProperty(_container2, "children", (0, _utils.someSpottables)(5)), _container2))),
28
+ mixedOrder: (0, _utils.join)((0, _utils.container)((_container3 = {}, _defineProperty(_container3, _container17.containerAttribute, 'first'), _defineProperty(_container3, "name", 'c1'), _container3)), (0, _utils.spottable)({
29
+ name: 's1'
30
+ }), (0, _utils.container)((_container4 = {}, _defineProperty(_container4, _container17.containerAttribute, 'second'), _defineProperty(_container4, "name", 'c2'), _container4)), (0, _utils.spottable)({
31
+ name: 's2'
32
+ })),
33
+ complexTree: (0, _utils.join)((0, _utils.spottable)(nonSpottable()), (0, _utils.container)((_container7 = {}, _defineProperty(_container7, _container17.containerAttribute, 'first-container'), _defineProperty(_container7, "children", (0, _utils.join)((0, _utils.someSpottables)(2), (0, _utils.container)((_container6 = {}, _defineProperty(_container6, _container17.containerAttribute, 'second-container'), _defineProperty(_container6, "children", (0, _utils.join)((0, _utils.spottable)({
34
+ id: 'secondContainerFirstSpottable'
35
+ }), (0, _utils.someSpottables)(2), (0, _utils.container)((_container5 = {}, _defineProperty(_container5, _container17.containerAttribute, 'third-container'), _defineProperty(_container5, 'data-spotlight-container-disabled', true), _defineProperty(_container5, "children", (0, _utils.join)((0, _utils.someSpottables)(4), (0, _utils.node)({
36
+ id: 'child-of-third'
37
+ }))), _container5)))), _container6)))), _container7))),
38
+ spottablesInDisabledContainer: (0, _utils.container)((_container8 = {}, _defineProperty(_container8, _container17.containerAttribute, 'container'), _defineProperty(_container8, 'data-spotlight-container-disabled', true), _defineProperty(_container8, "children", (0, _utils.someSpottables)(5)), _container8)),
39
+ spottablesInNestedDisabledContainer: (0, _utils.container)((_container10 = {}, _defineProperty(_container10, _container17.containerAttribute, 'container'), _defineProperty(_container10, 'data-spotlight-container-disabled', true), _defineProperty(_container10, "children", (0, _utils.container)((_container9 = {}, _defineProperty(_container9, _container17.containerAttribute, 'child'), _defineProperty(_container9, "children", (0, _utils.someSpottables)(5)), _container9))), _container10)),
40
+ containerWithDefaultAndLastFocused: (0, _utils.container)((_container11 = {}, _defineProperty(_container11, _container17.containerAttribute, 'container'), _defineProperty(_container11, "children", (0, _utils.join)((0, _utils.spottable)({
41
+ id: 'firstSpottable'
42
+ }), (0, _utils.someSpottables)(5), (0, _utils.node)({
43
+ id: 'spottableDefault',
44
+ className: 'spottable spottable-default'
45
+ }), (0, _utils.spottable)({
46
+ id: 'lastFocused'
47
+ }))), _container11)),
48
+ nestedContainersWithDefaultAndLastFocused: (0, _utils.container)((_container13 = {}, _defineProperty(_container13, _container17.containerAttribute, 'container'), _defineProperty(_container13, "children", (0, _utils.join)((0, _utils.spottable)({
49
+ id: 'firstSpottable'
50
+ }), (0, _utils.someSpottables)(5), (0, _utils.container)((_container12 = {}, _defineProperty(_container12, _container17.containerAttribute, 'child'), _defineProperty(_container12, "id", 'spottableDefault'), _defineProperty(_container12, "className", 'spottable-default'), _defineProperty(_container12, "children", (0, _utils.join)((0, _utils.spottable)({
51
+ id: 'firstChildSpottable'
52
+ }), (0, _utils.someSpottables)(5), (0, _utils.spottable)({
53
+ id: 'lastChildFocused'
54
+ }))), _container12)), (0, _utils.spottable)({
55
+ id: 'lastFocused'
56
+ }))), _container13)),
57
+ emptySubcontainer: (0, _utils.container)((_container15 = {}, _defineProperty(_container15, _container17.containerAttribute, 'container'), _defineProperty(_container15, "children", (0, _utils.join)((0, _utils.container)(_defineProperty({}, _container17.containerAttribute, 'subcontainer')), (0, _utils.spottable)({
58
+ id: 'afterSubcontainer'
59
+ }))), _container15)),
60
+ owned: (0, _utils.join)((0, _utils.spottable)({
61
+ id: 's1'
62
+ }), (0, _utils.node)({
63
+ id: 'n1'
64
+ }), (0, _utils.container)((_container16 = {}, _defineProperty(_container16, _container17.containerAttribute, 'container'), _defineProperty(_container16, 'aria-owns', 's1 n1'), _defineProperty(_container16, "children", (0, _utils.spottable)({
65
+ id: 's2'
66
+ })), _container16)))
67
+ };
1243
68
 
1244
- test(
1245
- 'should return an empty array for an unmounted, configured container',
1246
- testScenario(
1247
- scenarios.onlySpottables,
1248
- () => {
1249
- configureContainer('first-container', {
1250
- overflow: true
1251
- });
69
+ var setupContainers = function setupContainers() {
70
+ (0, _container17.configureDefaults)({
71
+ selector: '.spottable'
72
+ });
73
+ (0, _container17.configureContainer)(_container17.rootContainerId);
74
+ (0, _container17.setLastContainer)(_container17.rootContainerId);
75
+ };
1252
76
 
1253
- const expected = [];
1254
- const actual = getContainerNavigableElements('first-container');
77
+ var teardownContainers = function teardownContainers() {
78
+ // clean up any containers we create for safe tests
79
+ (0, _container17.removeAllContainers)();
80
+ };
1255
81
 
1256
- expect(actual).toEqual(expected);
1257
- }
1258
- )
1259
- );
1260
- });
1261
- });
82
+ describe('container', function () {
83
+ describe('#getSpottableDescendants', function () {
84
+ beforeEach(setupContainers);
85
+ afterEach(teardownContainers);
86
+ test('should find spottables', (0, _utils.testScenario)(scenarios.onlySpottables, function () {
87
+ var expected = 5;
88
+ var actual = (0, _container17.getSpottableDescendants)(_container17.rootContainerId).length;
89
+ expect(actual).toBe(expected);
90
+ }));
91
+ test('should find containers', (0, _utils.testScenario)(scenarios.onlyContainers, function () {
92
+ var expected = 5;
93
+ var actual = (0, _container17.getSpottableDescendants)(_container17.rootContainerId).length;
94
+ expect(actual).toBe(expected);
95
+ }));
96
+ test('should find spottables and containers', (0, _utils.testScenario)(scenarios.spottableAndContainers, function () {
97
+ var expected = 10;
98
+ var actual = (0, _container17.getSpottableDescendants)(_container17.rootContainerId).length;
99
+ expect(actual).toBe(expected);
100
+ }));
101
+ test('should only find spottables with non-spottable siblings', (0, _utils.testScenario)(scenarios.nonSpottableSiblings, function () {
102
+ var expected = 5;
103
+ var actual = (0, _container17.getSpottableDescendants)(_container17.rootContainerId).length;
104
+ expect(actual).toBe(expected);
105
+ }));
106
+ test('should only find top-level containers', (0, _utils.testScenario)(scenarios.nestedContainers, function () {
107
+ var expected = 1;
108
+ var actual = (0, _container17.getSpottableDescendants)(_container17.rootContainerId).length;
109
+ expect(actual).toBe(expected);
110
+ }));
111
+ test('should only find top-level containers and spottables', (0, _utils.testScenario)(scenarios.nestedContainersWithSpottables, function () {
112
+ var expected = 6;
113
+ var actual = (0, _container17.getSpottableDescendants)(_container17.rootContainerId).length;
114
+ expect(actual).toBe(expected);
115
+ }));
116
+ test('should not find spottables in sibling containers', (0, _utils.testScenario)(scenarios.siblingContainers, function () {
117
+ (0, _container17.configureContainer)('first');
118
+ var expected = 5;
119
+ var actual = (0, _container17.getSpottableDescendants)('first').length;
120
+ expect(actual).toBe(expected);
121
+ }));
122
+ test('should not find spottables in descendant containers', (0, _utils.testScenario)(scenarios.complexTree, function () {
123
+ (0, _container17.configureContainer)('first-container');
124
+ var expected = 3;
125
+ var actual = (0, _container17.getSpottableDescendants)('first-container').length;
126
+ expect(actual).toBe(expected);
127
+ }));
128
+ test('should not find containers that are disabled', (0, _utils.testScenario)(scenarios.complexTree, function () {
129
+ (0, _container17.configureContainer)('first-container');
130
+ (0, _container17.configureContainer)('second-container');
131
+ var expected = 3;
132
+ var actual = (0, _container17.getSpottableDescendants)('second-container').length;
133
+ expect(actual).toBe(expected);
134
+ }));
135
+ test('should not any spottables within a disabled container', (0, _utils.testScenario)(scenarios.spottablesInDisabledContainer, function () {
136
+ (0, _container17.configureContainer)('container');
137
+ var expected = 0;
138
+ var actual = (0, _container17.getSpottableDescendants)('container').length;
139
+ expect(actual).toBe(expected);
140
+ }));
141
+ test('should not any spottables within a disabled ancestor container', (0, _utils.testScenario)(scenarios.spottablesInNestedDisabledContainer, function () {
142
+ (0, _container17.configureContainer)('container');
143
+ (0, _container17.configureContainer)('child');
144
+ var expected = 0;
145
+ var actual = (0, _container17.getSpottableDescendants)('child').length;
146
+ expect(actual).toBe(expected);
147
+ }));
148
+ test('should return spottables and containers in source order', (0, _utils.testScenario)(scenarios.mixedOrder, function () {
149
+ var expected = ['c1', 's1', 'c2', 's2'];
150
+ var actual = (0, _container17.getSpottableDescendants)(_container17.rootContainerId).map(function (n) {
151
+ return n.getAttribute('name');
152
+ });
153
+ expect(actual).toEqual(expected);
154
+ }));
155
+ test('should include owned nodes', (0, _utils.testScenario)(scenarios.owned, function () {
156
+ (0, _container17.configureContainer)('container'); // owned nodes follow internal nodes
157
+
158
+ var expected = ['s2', 's1'];
159
+ var actual = (0, _container17.getSpottableDescendants)('container').map(function (n) {
160
+ return n.getAttribute('id');
161
+ });
162
+ expect(actual).toEqual(expected);
163
+ }));
164
+ });
165
+ describe('#getContainersForNode', function () {
166
+ test('should return the rootContainerId when no other containers exist', (0, _utils.testScenario)(scenarios.onlySpottables, function (root) {
167
+ var expected = [_container17.rootContainerId];
168
+ var actual = (0, _container17.getContainersForNode)(root.lastChild);
169
+ expect(actual).toEqual(expected);
170
+ }));
171
+ test('should return all ancestor container ids', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
172
+ var childOfThird = root.querySelector('#child-of-third');
173
+ var expected = [_container17.rootContainerId, 'first-container', 'second-container', 'third-container'];
174
+ var actual = (0, _container17.getContainersForNode)(childOfThird);
175
+ expect(actual).toEqual(expected);
176
+ }));
177
+ test('should return immediate container id as last in list', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
178
+ var childOfThird = root.querySelector('#child-of-third');
179
+ var expected = 'third-container';
180
+ var actual = (0, _container17.getContainersForNode)(childOfThird).pop();
181
+ expect(actual).toEqual(expected);
182
+ }));
183
+ });
184
+ describe('#isContainer', function () {
185
+ beforeEach(function () {
186
+ (0, _container17.configureContainer)('test-container');
187
+ });
188
+ afterEach(function () {
189
+ (0, _container17.removeContainer)('test-container');
190
+ });
191
+ test('should return true for nodes that have the container attribute', function () {
192
+ var div = document.createElement('div');
193
+ div.setAttribute('data-spotlight-container', 'my-container');
194
+ var expected = true;
195
+ var actual = (0, _container17.isContainer)(div);
196
+ expect(actual).toBe(expected);
197
+ });
198
+ test('should return false for nodes that do not have the container attribute', function () {
199
+ var div = document.createElement('div');
200
+ var expected = false;
201
+ var actual = (0, _container17.isContainer)(div);
202
+ expect(actual).toBe(expected);
203
+ });
204
+ test('should return true for a configured container id', function () {
205
+ var expected = true;
206
+ var actual = (0, _container17.isContainer)('test-container');
207
+ expect(actual).toBe(expected);
208
+ });
209
+ test('should return false for a unconfigured container id', function () {
210
+ var expected = false;
211
+ var actual = (0, _container17.isContainer)('unconfigured-container');
212
+ expect(actual).toBe(expected);
213
+ });
214
+ });
215
+ describe('#getContainerFocusTarget', function () {
216
+ beforeEach(setupContainers);
217
+ afterEach(teardownContainers);
218
+ test('should return the last focused element when enterTo is "last-focused"', (0, _utils.testScenario)(scenarios.containerWithDefaultAndLastFocused, function (root) {
219
+ (0, _container17.configureContainer)('container', {
220
+ enterTo: 'last-focused',
221
+ defaultElement: '.spottable-default'
222
+ });
223
+ (0, _container17.setContainerLastFocusedElement)(root.querySelector('#lastFocused'), ['container']);
224
+ var expected = 'lastFocused';
225
+ var actual = (0, _container17.getContainerFocusTarget)('container').id;
226
+ expect(actual).toBe(expected);
227
+ }));
228
+ test('should return the default spottable element when enterTo is "last-focused" but no element has been focused', (0, _utils.testScenario)(scenarios.containerWithDefaultAndLastFocused, function () {
229
+ (0, _container17.configureContainer)('container', {
230
+ enterTo: 'last-focused',
231
+ defaultElement: '.spottable-default'
232
+ });
233
+ var expected = 'spottableDefault';
234
+ var actual = (0, _container17.getContainerFocusTarget)('container').id;
235
+ expect(actual).toBe(expected);
236
+ }));
237
+ test('should return the first spottable element when enterTo is "last-focused" and defaultElement is not configured', (0, _utils.testScenario)(scenarios.containerWithDefaultAndLastFocused, function () {
238
+ (0, _container17.configureContainer)('container', {
239
+ enterTo: 'last-focused'
240
+ });
241
+ var expected = 'firstSpottable';
242
+ var actual = (0, _container17.getContainerFocusTarget)('container').id;
243
+ expect(actual).toBe(expected);
244
+ }));
245
+ test('should return the first spottable element when enterTo is "last-focused" and defaultElement is not found', (0, _utils.testScenario)(scenarios.containerWithDefaultAndLastFocused, function () {
246
+ (0, _container17.configureContainer)('container', {
247
+ enterTo: 'last-focused',
248
+ // configured, but not found
249
+ defaultElement: '[data-default-spottable]'
250
+ });
251
+ var expected = 'firstSpottable';
252
+ var actual = (0, _container17.getContainerFocusTarget)('container').id;
253
+ expect(actual).toBe(expected);
254
+ }));
255
+ test('should return the default spottable element when enterTo is "default-element"', (0, _utils.testScenario)(scenarios.containerWithDefaultAndLastFocused, function () {
256
+ (0, _container17.configureContainer)('container', {
257
+ enterTo: 'default-element',
258
+ defaultElement: '.spottable-default'
259
+ });
260
+ var expected = 'spottableDefault';
261
+ var actual = (0, _container17.getContainerFocusTarget)('container').id;
262
+ expect(actual).toBe(expected);
263
+ }));
264
+ test('should return the default spottable element when enterTo is "default-element" and defaultElement contains an array of selectors', (0, _utils.testScenario)(scenarios.containerWithDefaultAndLastFocused, function () {
265
+ (0, _container17.configureContainer)('container', {
266
+ enterTo: 'default-element',
267
+ defaultElement: ['.does-not-exist', '.spottable-default']
268
+ });
269
+ var expected = 'spottableDefault';
270
+ var actual = (0, _container17.getContainerFocusTarget)('container').id;
271
+ expect(actual).toBe(expected);
272
+ })); // FIXME: This is testing a previously supported feature (setting a node as defaultElement)
273
+ // which was never documented and should be removed in a future release.
274
+
275
+ test('should return the default spottable element when enterTo is "default-element" and defaultElement contains an array of selectors wiht a node reference', (0, _utils.testScenario)(scenarios.containerWithDefaultAndLastFocused, function (root) {
276
+ (0, _container17.configureContainer)('container', {
277
+ enterTo: 'default-element',
278
+ defaultElement: [root.querySelector('#lastFocused'), '.spottable-default']
279
+ });
280
+ var expected = 'lastFocused';
281
+ var actual = (0, _container17.getContainerFocusTarget)('container').id;
282
+ expect(actual).toBe(expected);
283
+ }));
284
+ test('should return the first spottable element when enterTo is "default-element" but defaultElement is not configured', (0, _utils.testScenario)(scenarios.containerWithDefaultAndLastFocused, function () {
285
+ (0, _container17.configureContainer)('container', {
286
+ enterTo: 'default-element'
287
+ });
288
+ var expected = 'firstSpottable';
289
+ var actual = (0, _container17.getContainerFocusTarget)('container').id;
290
+ expect(actual).toBe(expected);
291
+ }));
292
+ test('should return the first spottable element when enterTo is "default-element" but defaultElement is not found', (0, _utils.testScenario)(scenarios.containerWithDefaultAndLastFocused, function () {
293
+ (0, _container17.configureContainer)('container', {
294
+ enterTo: 'default-element',
295
+ defaultElement: '[data-default-spottable]'
296
+ });
297
+ var expected = 'firstSpottable';
298
+ var actual = (0, _container17.getContainerFocusTarget)('container').id;
299
+ expect(actual).toBe(expected);
300
+ }));
301
+ test('should return the default element when enterTo is "default-element" and defaultElement is within a subcontainer', (0, _utils.testScenario)(scenarios.complexTree, function () {
302
+ (0, _container17.configureContainer)('first-container', {
303
+ enterTo: 'default-element',
304
+ defaultElement: "[".concat(_container17.containerAttribute, "='second-container'] > .spottable")
305
+ });
306
+ (0, _container17.configureContainer)('second-container');
307
+ var expected = 'second-container';
308
+ var actual = (0, _container17.getContainerFocusTarget)('first-container').parentNode.dataset.spotlightId;
309
+ expect(actual).toBe(expected);
310
+ }));
311
+ test('should return the first spottable element when enterTo is "default-element" and defaultElement is within a disabled subcontainer', (0, _utils.testScenario)(scenarios.complexTree, function () {
312
+ (0, _container17.configureContainer)('second-container', {
313
+ enterTo: 'default-element',
314
+ defaultElement: "[".concat(_container17.containerAttribute, "='third-container'] > .spottable")
315
+ });
316
+ (0, _container17.configureContainer)('third-container');
317
+ var expected = 'secondContainerFirstSpottable';
318
+ var actual = (0, _container17.getContainerFocusTarget)('second-container').id;
319
+ expect(actual).toBe(expected);
320
+ }));
321
+ test('should return the first spottable element when enterTo is not configured', (0, _utils.testScenario)(scenarios.containerWithDefaultAndLastFocused, function () {
322
+ (0, _container17.configureContainer)('container');
323
+ var expected = 'firstSpottable';
324
+ var actual = (0, _container17.getContainerFocusTarget)('container').id;
325
+ expect(actual).toBe(expected);
326
+ }));
327
+ test('should return the default element when enterTo is not configured and defaultElement is configured', (0, _utils.testScenario)(scenarios.containerWithDefaultAndLastFocused, function () {
328
+ (0, _container17.configureContainer)('container', {
329
+ defaultElement: '.spottable-default'
330
+ });
331
+ var expected = 'spottableDefault';
332
+ var actual = (0, _container17.getContainerFocusTarget)('container').id;
333
+ expect(actual).toBe(expected);
334
+ }));
335
+ test('should cascade search into child containers with', (0, _utils.testScenario)(scenarios.nestedContainersWithDefaultAndLastFocused, function (root) {
336
+ (0, _container17.configureContainer)('container', {
337
+ defaultElement: '.spottable-default'
338
+ });
339
+ (0, _container17.configureContainer)('child', {
340
+ enterTo: 'last-focused',
341
+ defaultElement: '.spottable-default'
342
+ });
343
+ (0, _container17.setContainerLastFocusedElement)(root.querySelector('#lastChildFocused'), [_container17.rootContainerId, 'container', 'child']);
344
+ var expected = 'lastChildFocused';
345
+ var actual = (0, _container17.getContainerFocusTarget)('container').id;
346
+ expect(actual).toBe(expected);
347
+ }));
348
+ test('should cascade search into child containers when multiple containers have enterTo configured', (0, _utils.testScenario)(scenarios.nestedContainersWithDefaultAndLastFocused, function (root) {
349
+ (0, _container17.configureContainer)('container', {
350
+ enterTo: 'last-focused',
351
+ defaultElement: '.spottable-default'
352
+ });
353
+ (0, _container17.configureContainer)('child', {
354
+ enterTo: 'last-focused',
355
+ defaultElement: '.spottable-default'
356
+ });
357
+ (0, _container17.setContainerLastFocusedElement)(root.querySelector('#lastChildFocused'), [_container17.rootContainerId, 'container', 'child']);
358
+ var expected = 'lastChildFocused';
359
+ var actual = (0, _container17.getContainerFocusTarget)('container').id;
360
+ expect(actual).toBe(expected);
361
+ }));
362
+ test('should skip empty subcontainers', (0, _utils.testScenario)(scenarios.emptySubcontainer, function () {
363
+ (0, _container17.configureContainer)('container');
364
+ (0, _container17.configureContainer)('subcontainer');
365
+ var expected = 'afterSubcontainer';
366
+ var actual = (0, _container17.getContainerFocusTarget)('container').id;
367
+ expect(actual).toBe(expected);
368
+ }));
369
+ test('should return null for an unconfigured container', (0, _utils.testScenario)(scenarios.complexTree, function () {
370
+ var expected = null;
371
+ var actual = (0, _container17.getContainerFocusTarget)('first-container');
372
+ expect(actual).toBe(expected);
373
+ }));
374
+ });
375
+ describe('#isNavigable', function () {
376
+ beforeEach(setupContainers);
377
+ afterEach(teardownContainers);
378
+ test('should return false a null node', function () {
379
+ var expected = false;
380
+ var actual = (0, _container17.isNavigable)(null, _container17.rootContainerId);
381
+ expect(actual).toBe(expected);
382
+ });
383
+ test('should return true for any node when not verifying selector and without a navigableFilter', (0, _utils.testScenario)(scenarios.nonSpottableSiblings, function (root) {
384
+ var expected = true;
385
+ var actual = (0, _container17.isNavigable)(root.querySelector('.other'), _container17.rootContainerId);
386
+ expect(actual).toBe(expected);
387
+ }));
388
+ test('should return true for spottable children when verifying selector', (0, _utils.testScenario)(scenarios.onlySpottables, function (root) {
389
+ var expected = true;
390
+ var actual = (0, _container17.isNavigable)(root.querySelector('.spottable'), _container17.rootContainerId, true);
391
+ expect(actual).toBe(expected);
392
+ }));
393
+ test('should return true for containers', (0, _utils.testScenario)(scenarios.onlyContainers, function (root) {
394
+ var expected = true;
395
+ var actual = (0, _container17.isNavigable)(root.querySelector("[".concat(_container17.containerAttribute, "]")), _container17.rootContainerId, true);
396
+ expect(actual).toBe(expected);
397
+ }));
398
+ test('should filter the node with navigableFilter', (0, _utils.testScenario)(scenarios.spottableAndContainers, function (root) {
399
+ (0, _container17.configureContainer)(_container17.rootContainerId, {
400
+ // test filter which makes containers non-navigable
401
+ navigableFilter: function navigableFilter(n) {
402
+ return !(0, _container17.isContainer)(n);
403
+ }
404
+ });
405
+ var expected = false;
406
+ var actual = (0, _container17.isNavigable)(root.querySelector("[".concat(_container17.containerAttribute, "]")), _container17.rootContainerId, true);
407
+ expect(actual).toBe(expected);
408
+ }));
409
+ });
410
+ describe('#setContainerLastFocusedElement', function () {
411
+ beforeEach(setupContainers);
412
+ afterEach(teardownContainers);
413
+ test('should update lastFocusedElement for a single container', (0, _utils.testScenario)(scenarios.onlySpottables, function (root) {
414
+ var item = root.querySelectorAll('.spottable').item(3);
415
+ (0, _container17.setContainerLastFocusedElement)(item, (0, _container17.getContainersForNode)(item));
416
+ var expected = item;
417
+ var actual = (0, _container17.getContainerConfig)(_container17.rootContainerId).lastFocusedElement;
418
+ expect(actual).toBe(expected);
419
+ }));
420
+ test('should update lastFocusedElement to the node\'s container id when element is within a container with enterTo configured', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
421
+ var item = root.querySelectorAll("[".concat(_container17.containerAttribute, "='first-container'] .spottable")).item(0);
422
+ (0, _container17.configureContainer)('first-container', {
423
+ enterTo: 'last-focused'
424
+ });
425
+ (0, _container17.setContainerLastFocusedElement)(item, (0, _container17.getContainersForNode)(item));
426
+ var expected = 'first-container';
427
+ var actual = (0, _container17.getContainerConfig)(_container17.rootContainerId).lastFocusedElement;
428
+ expect(actual).toBe(expected);
429
+ }));
430
+ test('should ignore sub-containers that does not have enterTo configured', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
431
+ var item = root.querySelectorAll("[".concat(_container17.containerAttribute, "='second-container'] .spottable")).item(0);
432
+ (0, _container17.setContainerLastFocusedElement)(item, (0, _container17.getContainersForNode)(item));
433
+ var expected = item;
434
+ var actual = (0, _container17.getContainerConfig)(_container17.rootContainerId).lastFocusedElement;
435
+ expect(actual).toBe(expected);
436
+ }));
437
+ test('should update lastFocusedElement to the first sub-container that has enterTo configured', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
438
+ var item = root.querySelectorAll("[".concat(_container17.containerAttribute, "='second-container'] .spottable")).item(0);
439
+ (0, _container17.configureContainer)('second-container', {
440
+ enterTo: 'last-focused'
441
+ });
442
+ (0, _container17.setContainerLastFocusedElement)(item, (0, _container17.getContainersForNode)(item));
443
+ var expected = 'second-container';
444
+ var actual = (0, _container17.getContainerConfig)(_container17.rootContainerId).lastFocusedElement;
445
+ expect(actual).toBe(expected);
446
+ }));
447
+ });
448
+ describe('#unmountContainer', function () {
449
+ beforeEach(setupContainers);
450
+ afterEach(teardownContainers);
451
+ test('should return element when last focused is not within a subcontainer with enterTo', (0, _utils.testScenario)(scenarios.onlySpottables, function (root) {
452
+ var index = 3;
453
+ var item = root.querySelectorAll('.spottable').item(index);
454
+ (0, _container17.setContainerLastFocusedElement)(item, (0, _container17.getContainersForNode)(item));
455
+ (0, _container17.unmountContainer)(_container17.rootContainerId);
456
+ var expected = true;
457
+ var actual = (0, _container17.getContainerConfig)(_container17.rootContainerId).lastFocusedKey.element;
458
+ expect(actual).toBe(expected);
459
+ }));
460
+ test('should return container when last focused is within a subcontainer with enterTo', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
461
+ var item = root.querySelectorAll("[".concat(_container17.containerAttribute, "=\"first-container\"] .spottable")).item(1);
462
+ (0, _container17.configureContainer)('first-container', {
463
+ enterTo: 'last-focused'
464
+ });
465
+ (0, _container17.setContainerLastFocusedElement)(item, (0, _container17.getContainersForNode)(item));
466
+ (0, _container17.unmountContainer)(_container17.rootContainerId);
467
+ var expected = true;
468
+ var actual = (0, _container17.getContainerConfig)(_container17.rootContainerId).lastFocusedKey.container;
469
+ expect(actual).toBe(expected);
470
+ }));
471
+ test('should save the index of the node when lastFocusedPersist is undefined', (0, _utils.testScenario)(scenarios.onlySpottables, function (root) {
472
+ var index = 3;
473
+ var item = root.querySelectorAll('.spottable').item(index);
474
+ (0, _container17.setContainerLastFocusedElement)(item, (0, _container17.getContainersForNode)(item));
475
+ (0, _container17.unmountContainer)(_container17.rootContainerId);
476
+ var expected = index;
477
+ var actual = (0, _container17.getContainerConfig)(_container17.rootContainerId).lastFocusedKey.key;
478
+ expect(actual).toBe(expected);
479
+ }));
480
+ test('should save a custom key for container-configured lastFocusedPersist', (0, _utils.testScenario)(scenarios.onlySpottables, function (root) {
481
+ var index = 3;
482
+ var item = root.querySelectorAll('.spottable').item(3);
483
+ (0, _container17.configureContainer)(_container17.rootContainerId, {
484
+ lastFocusedPersist: function lastFocusedPersist(n, all) {
485
+ return {
486
+ element: true,
487
+ key: "item-".concat(all.indexOf(n))
488
+ };
489
+ }
490
+ });
491
+ (0, _container17.setContainerLastFocusedElement)(item, (0, _container17.getContainersForNode)(item));
492
+ (0, _container17.unmountContainer)(_container17.rootContainerId);
493
+ var expected = "item-".concat(index);
494
+ var actual = (0, _container17.getContainerConfig)(_container17.rootContainerId).lastFocusedKey.key;
495
+ expect(actual).toBe(expected);
496
+ }));
497
+ test('should save the container id as the key when a container with enterTo configured had the last focused item', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
498
+ var item = root.querySelectorAll("[".concat(_container17.containerAttribute, "=\"first-container\"] .spottable")).item(1);
499
+ (0, _container17.configureContainer)('first-container', {
500
+ enterTo: 'last-focused'
501
+ });
502
+ (0, _container17.setContainerLastFocusedElement)(item, (0, _container17.getContainersForNode)(item));
503
+ (0, _container17.unmountContainer)(_container17.rootContainerId);
504
+ var expected = 'first-container';
505
+ var actual = (0, _container17.getContainerConfig)(_container17.rootContainerId).lastFocusedKey.key;
506
+ expect(actual).toBe(expected);
507
+ }));
508
+ test('should save the index as the key when last focused item is only within containers without enterTo configured', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
509
+ var item = root.querySelectorAll("[".concat(_container17.containerAttribute, "=\"second-container\"] .spottable")).item(1);
510
+ (0, _container17.setContainerLastFocusedElement)(item, (0, _container17.getContainersForNode)(item));
511
+ (0, _container17.unmountContainer)(_container17.rootContainerId);
512
+ var expected = 4;
513
+ var actual = (0, _container17.getContainerConfig)(_container17.rootContainerId).lastFocusedKey.key;
514
+ expect(actual).toBe(expected);
515
+ }));
516
+ test('should mark the container inactive', (0, _utils.testScenario)(scenarios.complexTree, function () {
517
+ (0, _container17.addContainer)('first-container');
518
+ (0, _container17.unmountContainer)('first-container');
519
+ var expected = false;
520
+ var actual = (0, _container17.getContainerConfig)('first-container').active;
521
+ expect(actual).toBe(expected);
522
+ }));
523
+ });
524
+ describe('#setLastContainerFromTarget', function () {
525
+ beforeEach(setupContainers);
526
+ afterEach(teardownContainers);
527
+ test('should be nearest restrict="self-only" container to current if target is not within it', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
528
+ (0, _container17.configureContainer)('first-container', {
529
+ restrict: 'self-only'
530
+ });
531
+ var current = root.querySelector('[data-spotlight-id="first-container"] .spottable');
532
+ var target = root.querySelector('.spottable');
533
+ (0, _container17.setLastContainerFromTarget)(current, target);
534
+ var expected = 'first-container';
535
+ var actual = (0, _container17.getLastContainer)();
536
+ expect(actual).toBe(expected);
537
+ }));
538
+ test('should be use nearest container to target if within current container', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
539
+ (0, _container17.configureContainer)('first-container', {
540
+ restrict: 'none'
541
+ });
542
+ (0, _container17.configureContainer)('second-container', {
543
+ restrict: 'none'
544
+ });
545
+ var current = root.querySelector('[data-spotlight-id="first-container"] .spottable');
546
+ var target = root.querySelector('[data-spotlight-id="second-container"] .spottable');
547
+ (0, _container17.setLastContainerFromTarget)(current, target);
548
+ var expected = 'second-container';
549
+ var actual = (0, _container17.getLastContainer)();
550
+ expect(actual).toBe(expected);
551
+ }));
552
+ test('should target container if it is restrict="self-only" and contains current container', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
553
+ (0, _container17.configureContainer)('first-container', {
554
+ restrict: 'self-only'
555
+ });
556
+ (0, _container17.configureContainer)('second-container', {
557
+ restrict: 'none'
558
+ });
559
+ var current = root.querySelector('[data-spotlight-id="second-container"] .spottable');
560
+ var target = root.querySelector('[data-spotlight-id="first-container"]');
561
+ (0, _container17.setLastContainerFromTarget)(current, target);
562
+ var expected = 'first-container';
563
+ var actual = (0, _container17.getLastContainer)();
564
+ expect(actual).toBe(expected);
565
+ }));
566
+ });
567
+ describe('#getDefaultContainer', function () {
568
+ beforeEach(setupContainers);
569
+ afterEach(teardownContainers);
570
+ test('should return an empty string when container is inactive', (0, _utils.testScenario)(scenarios.complexTree, function () {
571
+ (0, _container17.unmountContainer)(_container17.rootContainerId);
572
+ var expected = '';
573
+ var actual = (0, _container17.getDefaultContainer)();
574
+ expect(actual).toBe(expected);
575
+ }));
576
+ });
577
+ describe('#getLastContainer', function () {
578
+ beforeEach(setupContainers);
579
+ afterEach(teardownContainers);
580
+ test('should return an empty string when container is inactive', (0, _utils.testScenario)(scenarios.complexTree, function () {
581
+ (0, _container17.addContainer)('first-container');
582
+ (0, _container17.setLastContainer)('first-container');
583
+ (0, _container17.unmountContainer)('first-container');
584
+ var expected = '';
585
+ var actual = (0, _container17.getLastContainer)();
586
+ expect(actual).toBe(expected);
587
+ }));
588
+ });
589
+ describe('#getAllContainerIds', function () {
590
+ beforeEach(setupContainers);
591
+ afterEach(teardownContainers);
592
+ test('should not include inacive containers', (0, _utils.testScenario)(scenarios.onlyContainers, function (root) {
593
+ var containerId = root.querySelector('[data-spotlight-id]').dataset.containerId;
594
+ (0, _container17.addContainer)(containerId);
595
+ (0, _container17.unmountContainer)(containerId);
596
+ var expected = -1;
597
+ var actual = (0, _container17.getAllContainerIds)().indexOf(containerId);
598
+ expect(actual).toBe(expected);
599
+ }));
600
+ });
601
+ describe('#getContainerLastFocusedElement', function () {
602
+ beforeEach(setupContainers);
603
+ afterEach(teardownContainers);
604
+ test('should return null for an invalid container', (0, _utils.testScenario)(scenarios.onlySpottables, function () {
605
+ var expected = null;
606
+ var actual = (0, _container17.getContainerLastFocusedElement)('does-not-exist');
607
+ expect(actual).toBe(expected);
608
+ }));
609
+ });
610
+ describe('#getContainerDefaultElement', function () {
611
+ beforeEach(setupContainers);
612
+ afterEach(teardownContainers);
613
+ test('should return null for an invalid container', (0, _utils.testScenario)(scenarios.onlySpottables, function () {
614
+ var expected = null;
615
+ var actual = (0, _container17.getContainerDefaultElement)('does-not-exist');
616
+ expect(actual).toBe(expected);
617
+ }));
618
+ });
619
+ describe('#getNavigableContainersForNode', function () {
620
+ beforeEach(setupContainers);
621
+ afterEach(teardownContainers);
622
+ test('should include all containers when none are restrict="self-only"', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
623
+ var expected = [_container17.rootContainerId, 'first-container', 'second-container'];
624
+ var actual = (0, _container17.getNavigableContainersForNode)(root.querySelector('#secondContainerFirstSpottable'));
625
+ expect(actual).toEqual(expected);
626
+ }));
627
+ test('should include all containers within the first restrict="self-only" container (inclusive)', (0, _utils.testScenario)(scenarios.complexTree, function (root) {
628
+ (0, _container17.configureContainer)('first-container', {
629
+ restrict: 'self-only'
630
+ });
631
+ var expected = ['first-container', 'second-container'];
632
+ var actual = (0, _container17.getNavigableContainersForNode)(root.querySelector('#secondContainerFirstSpottable'));
633
+ expect(actual).toEqual(expected);
634
+ }));
635
+ });
636
+ describe('#getContainerNavigableElements', function () {
637
+ beforeEach(setupContainers);
638
+ afterEach(teardownContainers);
639
+ test('should return an empty array for an unconfigured container', (0, _utils.testScenario)(scenarios.complexTree, function () {
640
+ var expected = [];
641
+ var actual = (0, _container17.getContainerNavigableElements)('first-container');
642
+ expect(actual).toEqual(expected);
643
+ }));
644
+ test('should return an empty array for an unmounted, configured container', (0, _utils.testScenario)(scenarios.onlySpottables, function () {
645
+ (0, _container17.configureContainer)('first-container', {
646
+ overflow: true
647
+ });
648
+ var expected = [];
649
+ var actual = (0, _container17.getContainerNavigableElements)('first-container');
650
+ expect(actual).toEqual(expected);
651
+ }));
652
+ });
653
+ });