@@ -217,6 +217,55 @@ module.exports = {
217217 done ( ) ;
218218 } ) ;
219219 } ,
220+ "test: should set aria labels for currently selected item" : function ( done ) {
221+ var editor = initEditor ( "" ) ;
222+ var newLineCharacter = editor . session . doc . getNewLineCharacter ( ) ;
223+ editor . completers = [
224+ {
225+ getCompletions : function ( editor , session , pos , prefix , callback ) {
226+ var completions = Array ( 10 ) . fill ( null ) . map ( function ( i , n ) { return { caption : String ( n ) , value : String ( n ) } ; } ) ;
227+ callback ( null , completions ) ;
228+ } ,
229+ triggerCharacters : [ "." , newLineCharacter ]
230+ }
231+ ] ;
232+ sendKey ( 'Return' ) ;
233+ var popup = editor . completer . popup ;
234+ check ( function ( ) {
235+ assert . equal ( popup . data . length , 10 ) ;
236+ assert . ok ( checkAria ( '<d id="suggest-aria-id:0" role="option" aria-roledescription="item" aria-label="0" aria-setsize="10" aria-posinset="1" aria-describedby="doc-tooltip" aria-selected="true"><s >0</s><s > </s></d><d ><s >1</s><s > </s></d><d ><s >2</s><s > </s></d><d ><s >3</s><s > </s></d><d ><s >4</s><s > </s></d><d ><s >5</s><s > </s></d><d ><s >6</s><s > </s></d><d ><s >7</s><s > </s></d><d ><s >8</s><s > </s></d>' ) ) ;
237+ sendKey ( 'Down' ) ;
238+ check ( function ( ) {
239+ assert . ok ( checkAria ( '<d role="option" aria-roledescription="item" aria-label="0" aria-setsize="10" aria-describedby="doc-tooltip"><s >0</s><s > </s></d><d id="suggest-aria-id:1" role="option" aria-roledescription="item" aria-label="1" aria-setsize="10" aria-posinset="2" aria-describedby="doc-tooltip" aria-selected="true"><s >1</s><s > </s></d><d ><s >2</s><s > </s></d><d ><s >3</s><s > </s></d><d ><s >4</s><s > </s></d><d ><s >5</s><s > </s></d><d ><s >6</s><s > </s></d><d ><s >7</s><s > </s></d><d ><s >8</s><s > </s></d>' ) ) ;
240+ sendKey ( 'Down' ) ;
241+ check ( function ( ) {
242+ assert . ok ( checkAria ( '<d role="option" aria-roledescription="item" aria-label="0" aria-setsize="10" aria-describedby="doc-tooltip"><s >0</s><s > </s></d><d role="option" aria-roledescription="item" aria-label="1" aria-setsize="10" aria-describedby="doc-tooltip"><s >1</s><s > </s></d><d id="suggest-aria-id:2" role="option" aria-roledescription="item" aria-label="2" aria-setsize="10" aria-posinset="3" aria-describedby="doc-tooltip" aria-selected="true"><s >2</s><s > </s></d><d ><s >3</s><s > </s></d><d ><s >4</s><s > </s></d><d ><s >5</s><s > </s></d><d ><s >6</s><s > </s></d><d ><s >7</s><s > </s></d><d ><s >8</s><s > </s></d>' ) ) ;
243+ sendKey ( 'Down' ) ;
244+ check ( function ( ) {
245+ sendKey ( 'Down' ) ;
246+ assert . ok ( checkAria ( '<d role="option" aria-roledescription="item" aria-label="0" aria-setsize="10" aria-describedby="doc-tooltip"><s >0</s><s > </s></d><d role="option" aria-roledescription="item" aria-label="1" aria-setsize="10" aria-describedby="doc-tooltip"><s >1</s><s > </s></d><d role="option" aria-roledescription="item" aria-label="2" aria-setsize="10" aria-describedby="doc-tooltip"><s >2</s><s > </s></d><d id="suggest-aria-id:3" role="option" aria-roledescription="item" aria-label="3" aria-setsize="10" aria-posinset="4" aria-describedby="doc-tooltip" aria-selected="true"><s >3</s><s > </s></d><d ><s >4</s><s > </s></d><d ><s >5</s><s > </s></d><d ><s >6</s><s > </s></d><d ><s >7</s><s > </s></d><d ><s >8</s><s > </s></d>' ) ) ;
247+ check ( function ( ) {
248+ assert . ok ( checkAria ( '<d role="option" aria-roledescription="item" aria-label="0" aria-setsize="10" aria-describedby="doc-tooltip"><s >0</s><s > </s></d><d role="option" aria-roledescription="item" aria-label="1" aria-setsize="10" aria-describedby="doc-tooltip"><s >1</s><s > </s></d><d role="option" aria-roledescription="item" aria-label="2" aria-setsize="10" aria-describedby="doc-tooltip"><s >2</s><s > </s></d><d role="option" aria-roledescription="item" aria-label="3" aria-setsize="10" aria-describedby="doc-tooltip"><s >3</s><s > </s></d><d id="suggest-aria-id:4" role="option" aria-roledescription="item" aria-label="4" aria-setsize="10" aria-posinset="5" aria-describedby="doc-tooltip" aria-selected="true"><s >4</s><s > </s></d><d ><s >5</s><s > </s></d><d ><s >6</s><s > </s></d><d ><s >7</s><s > </s></d><d ><s >8</s><s > </s></d>' ) ) ;
249+ done ( ) ;
250+ } ) ;
251+ } ) ;
252+ } ) ;
253+ } ) ;
254+ } ) ;
255+ function check ( callback ) {
256+ popup = editor . completer . popup ;
257+ popup . renderer . on ( "afterRender" , function wait ( ) {
258+ popup . renderer . off ( "afterRender" , wait ) ;
259+ callback ( ) ;
260+ } ) ;
261+ }
262+ function checkAria ( expected ) {
263+ var popup = editor . completer . popup ;
264+ var innerHTML = popup . renderer . $textLayer . element . innerHTML
265+ . replace ( / \s * s t y l e = " [ ^ " ] + " | c l a s s = " [ ^ " ] + " | ( d ) i v | ( s ) p a n / g, "$1$2" ) ;
266+ return innerHTML === expected ;
267+ }
268+ } ,
220269 "test: different completers tooltips" : function ( done ) {
221270 var editor = initEditor ( "" ) ;
222271 var firstDoc = "<b>First</b>" ;
0 commit comments