@@ -8,6 +8,7 @@ function click(element) {
88
99describe ( 'combobox-nav' , function ( ) {
1010 describe ( 'with API' , function ( ) {
11+ let input , list
1112 beforeEach ( function ( ) {
1213 document . body . innerHTML = `
1314 <input type="text">
@@ -18,34 +19,45 @@ describe('combobox-nav', function() {
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 )
31-
3232 assert . equal ( input . getAttribute ( 'role' ) , 'combobox' )
3333 assert . equal ( input . getAttribute ( 'aria-expanded' ) , 'false' )
3434 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' )
3539
3640 press ( input , 'ArrowDown' )
3741 assert . equal ( list . children [ 0 ] . getAttribute ( 'aria-selected' ) , 'true' )
3842 comboboxNav . navigate ( input , list , 1 )
3943 assert . equal ( list . children [ 2 ] . getAttribute ( 'aria-selected' ) , 'true' )
4044
41- comboboxNav . uninstall ( input , list )
42-
45+ comboboxNav . stop ( input )
4346 press ( input , 'ArrowDown' )
4447 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' ) )
4556 } )
4657 } )
4758
4859 describe ( 'with default setup' , function ( ) {
60+ let input , list , options
4961 beforeEach ( function ( ) {
5062 document . body . innerHTML = `
5163 <input type="text">
@@ -59,17 +71,19 @@ describe('combobox-nav', function() {
5971 <li><a href="#wall-e" role="option">Wall-E</a></li>
6072 </ul>
6173 `
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 )
6379 } )
6480
6581 afterEach ( function ( ) {
66- comboboxNav . uninstall ( document . querySelector ( 'input' ) , document . querySelector ( 'ul' ) )
82+ comboboxNav . uninstall ( document . querySelector ( 'input' ) )
6783 document . body . innerHTML = ''
6884 } )
6985
7086 it ( 'updates attributes on keyboard events' , function ( ) {
71- const input = document . querySelector ( 'input' )
72- const options = document . querySelectorAll ( 'li' )
7387 const expectedTargets = [ ]
7488
7589 document . addEventListener ( 'combobox-commit' , function ( { target} ) {
@@ -111,7 +125,6 @@ describe('combobox-nav', function() {
111125 } )
112126
113127 it ( 'fires commit events on click' , function ( ) {
114- const options = document . querySelectorAll ( 'li' )
115128 const expectedTargets = [ ]
116129
117130 document . addEventListener ( 'combobox-commit' , function ( { target} ) {
@@ -139,10 +152,6 @@ describe('combobox-nav', function() {
139152 } )
140153
141154 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-
146155 press ( input , 'ArrowDown' )
147156 assert . equal ( options [ 0 ] . getAttribute ( 'aria-selected' ) , 'true' )
148157 assert . equal ( input . getAttribute ( 'aria-activedescendant' ) , 'baymax' )
@@ -154,12 +163,9 @@ describe('combobox-nav', function() {
154163 } )
155164
156165 it ( 'scrolls when the selected item is not in view' , function ( ) {
157- const input = document . querySelector ( 'input' )
158- const list = document . querySelector ( 'ul' )
159166 list . style . overflow = 'auto'
160167 list . style . height = '18px'
161168 list . style . position = 'relative'
162- const options = document . querySelectorAll ( 'li' )
163169 assert . equal ( list . scrollTop , 0 )
164170
165171 press ( input , 'ArrowDown' )
0 commit comments