@@ -8,43 +8,61 @@ function click(element) {
88
99describe ( 'combobox-nav' , function ( ) {
1010 describe ( 'with API' , function ( ) {
11+ let input , list
1112 beforeEach ( function ( ) {
1213 document . body . innerHTML = `
13- <input aria-owns="list-id" role="combobox" type="text">
14+ <input type="text">
1415 <ul role="listbox" id="list-id">
1516 <li id="baymax" role="option">Baymax</li>
1617 <li><del>BB-8</del></li>
1718 <li id="hubot" role="option">Hubot</li>
1819 <li id="r2-d2" role="option">R2-D2</li>
1920 </ul>
2021 `
22+ input = document . querySelector ( 'input' )
23+ list = document . querySelector ( 'ul' )
2124 } )
2225
2326 afterEach ( function ( ) {
2427 document . body . innerHTML = ''
2528 } )
2629
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 ( ) {
3031 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' )
3140
3241 press ( input , 'ArrowDown' )
3342 assert . equal ( list . children [ 0 ] . getAttribute ( 'aria-selected' ) , 'true' )
3443 comboboxNav . navigate ( input , list , 1 )
3544 assert . equal ( list . children [ 2 ] . getAttribute ( 'aria-selected' ) , 'true' )
3645
37- comboboxNav . uninstall ( input , list )
38-
46+ comboboxNav . stop ( input )
3947 press ( input , 'ArrowDown' )
4048 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' ) )
4158 } )
4259 } )
4360
4461 describe ( 'with default setup' , function ( ) {
62+ let input , list , options
4563 beforeEach ( function ( ) {
4664 document . body . innerHTML = `
47- <input aria-owns="list-id" role="combobox" type="text">
65+ <input type="text">
4866 <ul role="listbox" id="list-id">
4967 <li id="baymax" role="option">Baymax</li>
5068 <li><del>BB-8</del></li>
@@ -55,17 +73,19 @@ describe('combobox-nav', function() {
5573 <li><a href="#wall-e" role="option">Wall-E</a></li>
5674 </ul>
5775 `
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 )
5981 } )
6082
6183 afterEach ( function ( ) {
62- comboboxNav . uninstall ( document . querySelector ( 'input' ) , document . querySelector ( 'ul' ) )
84+ comboboxNav . uninstall ( document . querySelector ( 'input' ) )
6385 document . body . innerHTML = ''
6486 } )
6587
6688 it ( 'updates attributes on keyboard events' , function ( ) {
67- const input = document . querySelector ( 'input' )
68- const options = document . querySelectorAll ( 'li' )
6989 const expectedTargets = [ ]
7090
7191 document . addEventListener ( 'combobox-commit' , function ( { target} ) {
@@ -107,7 +127,6 @@ describe('combobox-nav', function() {
107127 } )
108128
109129 it ( 'fires commit events on click' , function ( ) {
110- const options = document . querySelectorAll ( 'li' )
111130 const expectedTargets = [ ]
112131
113132 document . addEventListener ( 'combobox-commit' , function ( { target} ) {
@@ -135,10 +154,6 @@ describe('combobox-nav', function() {
135154 } )
136155
137156 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-
142157 press ( input , 'ArrowDown' )
143158 assert . equal ( options [ 0 ] . getAttribute ( 'aria-selected' ) , 'true' )
144159 assert . equal ( input . getAttribute ( 'aria-activedescendant' ) , 'baymax' )
@@ -150,12 +165,9 @@ describe('combobox-nav', function() {
150165 } )
151166
152167 it ( 'scrolls when the selected item is not in view' , function ( ) {
153- const input = document . querySelector ( 'input' )
154- const list = document . querySelector ( 'ul' )
155168 list . style . overflow = 'auto'
156169 list . style . height = '18px'
157170 list . style . position = 'relative'
158- const options = document . querySelectorAll ( 'li' )
159171 assert . equal ( list . scrollTop , 0 )
160172
161173 press ( input , 'ArrowDown' )
0 commit comments