@@ -8,43 +8,61 @@ 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
- <input aria-owns="list-id" role="combobox" type="text">
14
+ <input type="text">
14
15
<ul role="listbox" id="list-id">
15
16
<li id="baymax" role="option">Baymax</li>
16
17
<li><del>BB-8</del></li>
17
18
<li id="hubot" role="option">Hubot</li>
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 )
32
+ assert . equal ( input . getAttribute ( 'role' ) , 'combobox' )
33
+ assert . equal ( input . getAttribute ( 'aria-expanded' ) , 'false' )
34
+ assert . equal ( input . getAttribute ( 'aria-controls' ) , 'list-id' )
35
+ assert . equal ( input . getAttribute ( 'aria-autocomplete' ) , 'list' )
36
+ assert . equal ( input . getAttribute ( 'aria-haspopup' ) , 'listbox' )
37
+
38
+ comboboxNav . start ( input )
39
+ assert . equal ( input . getAttribute ( 'aria-expanded' ) , 'true' )
31
40
32
41
press ( input , 'ArrowDown' )
33
42
assert . equal ( list . children [ 0 ] . getAttribute ( 'aria-selected' ) , 'true' )
34
43
comboboxNav . navigate ( input , list , 1 )
35
44
assert . equal ( list . children [ 2 ] . getAttribute ( 'aria-selected' ) , 'true' )
36
45
37
- comboboxNav . uninstall ( input , list )
38
-
46
+ comboboxNav . stop ( input )
39
47
press ( input , 'ArrowDown' )
40
48
assert . equal ( list . children [ 2 ] . getAttribute ( 'aria-selected' ) , 'true' )
49
+
50
+ comboboxNav . uninstall ( input )
51
+ assert . equal ( list . children [ 2 ] . getAttribute ( 'aria-selected' ) , 'false' )
52
+
53
+ assert ( ! input . hasAttribute ( 'role' ) )
54
+ assert ( ! input . hasAttribute ( 'aria-expanded' ) )
55
+ assert ( ! input . hasAttribute ( 'aria-controls' ) )
56
+ assert ( ! input . hasAttribute ( 'aria-autocomplete' ) )
57
+ assert ( ! input . hasAttribute ( 'aria-haspopup' ) )
41
58
} )
42
59
} )
43
60
44
61
describe ( 'with default setup' , function ( ) {
62
+ let input , list , options
45
63
beforeEach ( function ( ) {
46
64
document . body . innerHTML = `
47
- <input aria-owns="list-id" role="combobox" type="text">
65
+ <input type="text">
48
66
<ul role="listbox" id="list-id">
49
67
<li id="baymax" role="option">Baymax</li>
50
68
<li><del>BB-8</del></li>
@@ -55,17 +73,19 @@ describe('combobox-nav', function() {
55
73
<li><a href="#wall-e" role="option">Wall-E</a></li>
56
74
</ul>
57
75
`
58
- comboboxNav . install ( document . querySelector ( 'input' ) , document . querySelector ( 'ul' ) )
76
+ input = document . querySelector ( 'input' )
77
+ list = document . querySelector ( 'ul' )
78
+ options = document . querySelectorAll ( 'li' )
79
+ comboboxNav . install ( input , list )
80
+ comboboxNav . start ( input )
59
81
} )
60
82
61
83
afterEach ( function ( ) {
62
- comboboxNav . uninstall ( document . querySelector ( 'input' ) , document . querySelector ( 'ul' ) )
84
+ comboboxNav . uninstall ( document . querySelector ( 'input' ) )
63
85
document . body . innerHTML = ''
64
86
} )
65
87
66
88
it ( 'updates attributes on keyboard events' , function ( ) {
67
- const input = document . querySelector ( 'input' )
68
- const options = document . querySelectorAll ( 'li' )
69
89
const expectedTargets = [ ]
70
90
71
91
document . addEventListener ( 'combobox-commit' , function ( { target} ) {
@@ -107,7 +127,6 @@ describe('combobox-nav', function() {
107
127
} )
108
128
109
129
it ( 'fires commit events on click' , function ( ) {
110
- const options = document . querySelectorAll ( 'li' )
111
130
const expectedTargets = [ ]
112
131
113
132
document . addEventListener ( 'combobox-commit' , function ( { target} ) {
@@ -135,10 +154,6 @@ describe('combobox-nav', function() {
135
154
} )
136
155
137
156
it ( 'clears aria-activedescendant and sets aria-selected=false when cleared' , function ( ) {
138
- const input = document . querySelector ( 'input' )
139
- const list = document . querySelector ( 'ul' )
140
- const options = document . querySelectorAll ( 'li' )
141
-
142
157
press ( input , 'ArrowDown' )
143
158
assert . equal ( options [ 0 ] . getAttribute ( 'aria-selected' ) , 'true' )
144
159
assert . equal ( input . getAttribute ( 'aria-activedescendant' ) , 'baymax' )
@@ -150,12 +165,9 @@ describe('combobox-nav', function() {
150
165
} )
151
166
152
167
it ( 'scrolls when the selected item is not in view' , function ( ) {
153
- const input = document . querySelector ( 'input' )
154
- const list = document . querySelector ( 'ul' )
155
168
list . style . overflow = 'auto'
156
169
list . style . height = '18px'
157
170
list . style . position = 'relative'
158
- const options = document . querySelectorAll ( 'li' )
159
171
assert . equal ( list . scrollTop , 0 )
160
172
161
173
press ( input , 'ArrowDown' )
0 commit comments