@@ -8,6 +8,7 @@ function click(element) {
8
8
9
9
describe ( 'combobox-nav' , function ( ) {
10
10
describe ( 'with API' , function ( ) {
11
+ let input , list
11
12
beforeEach ( function ( ) {
12
13
document . body . innerHTML = `
13
14
<input type="text">
@@ -18,34 +19,45 @@ describe('combobox-nav', function() {
18
19
<li id="r2-d2" role="option">R2-D2</li>
19
20
</ul>
20
21
`
22
+ input = document . querySelector ( 'input' )
23
+ list = document . querySelector ( 'ul' )
21
24
} )
22
25
23
26
afterEach ( function ( ) {
24
27
document . body . innerHTML = ''
25
28
} )
26
29
27
- it ( 'installs, navigates, and uninstalls' , function ( ) {
28
- const input = document . querySelector ( 'input' )
29
- const list = document . querySelector ( 'ul' )
30
+ it ( 'installs, starts, navigates, stops, and uninstalls' , function ( ) {
30
31
comboboxNav . install ( input , list )
31
-
32
32
assert . equal ( input . getAttribute ( 'role' ) , 'combobox' )
33
33
assert . equal ( input . getAttribute ( 'aria-expanded' ) , 'false' )
34
34
assert . equal ( input . getAttribute ( 'aria-controls' ) , 'list-id' )
35
+ assert . equal ( input . getAttribute ( 'aria-autocomplete' ) , 'list' )
36
+
37
+ comboboxNav . start ( input )
38
+ assert . equal ( input . getAttribute ( 'aria-expanded' ) , 'true' )
35
39
36
40
press ( input , 'ArrowDown' )
37
41
assert . equal ( list . children [ 0 ] . getAttribute ( 'aria-selected' ) , 'true' )
38
42
comboboxNav . navigate ( input , list , 1 )
39
43
assert . equal ( list . children [ 2 ] . getAttribute ( 'aria-selected' ) , 'true' )
40
44
41
- comboboxNav . uninstall ( input , list )
42
-
45
+ comboboxNav . stop ( input )
43
46
press ( input , 'ArrowDown' )
44
47
assert . equal ( list . children [ 2 ] . getAttribute ( 'aria-selected' ) , 'true' )
48
+
49
+ comboboxNav . uninstall ( input )
50
+ assert . equal ( list . children [ 2 ] . getAttribute ( 'aria-selected' ) , 'false' )
51
+
52
+ assert ( ! input . hasAttribute ( 'role' ) )
53
+ assert ( ! input . hasAttribute ( 'aria-expanded' ) )
54
+ assert ( ! input . hasAttribute ( 'aria-controls' ) )
55
+ assert ( ! input . hasAttribute ( 'aria-autocomplete' ) )
45
56
} )
46
57
} )
47
58
48
59
describe ( 'with default setup' , function ( ) {
60
+ let input , list , options
49
61
beforeEach ( function ( ) {
50
62
document . body . innerHTML = `
51
63
<input type="text">
@@ -59,17 +71,19 @@ describe('combobox-nav', function() {
59
71
<li><a href="#wall-e" role="option">Wall-E</a></li>
60
72
</ul>
61
73
`
62
- comboboxNav . install ( document . querySelector ( 'input' ) , document . querySelector ( 'ul' ) )
74
+ input = document . querySelector ( 'input' )
75
+ list = document . querySelector ( 'ul' )
76
+ options = document . querySelectorAll ( 'li' )
77
+ comboboxNav . install ( input , list )
78
+ comboboxNav . start ( input )
63
79
} )
64
80
65
81
afterEach ( function ( ) {
66
- comboboxNav . uninstall ( document . querySelector ( 'input' ) , document . querySelector ( 'ul' ) )
82
+ comboboxNav . uninstall ( document . querySelector ( 'input' ) )
67
83
document . body . innerHTML = ''
68
84
} )
69
85
70
86
it ( 'updates attributes on keyboard events' , function ( ) {
71
- const input = document . querySelector ( 'input' )
72
- const options = document . querySelectorAll ( 'li' )
73
87
const expectedTargets = [ ]
74
88
75
89
document . addEventListener ( 'combobox-commit' , function ( { target} ) {
@@ -111,7 +125,6 @@ describe('combobox-nav', function() {
111
125
} )
112
126
113
127
it ( 'fires commit events on click' , function ( ) {
114
- const options = document . querySelectorAll ( 'li' )
115
128
const expectedTargets = [ ]
116
129
117
130
document . addEventListener ( 'combobox-commit' , function ( { target} ) {
@@ -139,10 +152,6 @@ describe('combobox-nav', function() {
139
152
} )
140
153
141
154
it ( 'clears aria-activedescendant and sets aria-selected=false when cleared' , function ( ) {
142
- const input = document . querySelector ( 'input' )
143
- const list = document . querySelector ( 'ul' )
144
- const options = document . querySelectorAll ( 'li' )
145
-
146
155
press ( input , 'ArrowDown' )
147
156
assert . equal ( options [ 0 ] . getAttribute ( 'aria-selected' ) , 'true' )
148
157
assert . equal ( input . getAttribute ( 'aria-activedescendant' ) , 'baymax' )
@@ -154,12 +163,9 @@ describe('combobox-nav', function() {
154
163
} )
155
164
156
165
it ( 'scrolls when the selected item is not in view' , function ( ) {
157
- const input = document . querySelector ( 'input' )
158
- const list = document . querySelector ( 'ul' )
159
166
list . style . overflow = 'auto'
160
167
list . style . height = '18px'
161
168
list . style . position = 'relative'
162
- const options = document . querySelectorAll ( 'li' )
163
169
assert . equal ( list . scrollTop , 0 )
164
170
165
171
press ( input , 'ArrowDown' )
0 commit comments