@@ -173,7 +173,7 @@ test("returns the aria owners for a given element", function() {
173173 var actual = axs . utils . getIdReferrers ( "aria-owns" , owned ) ;
174174 equal ( expected . length , ownerCount ) ; // sanity check the test itself
175175 equal ( actual . length , ownerCount ) ;
176- var allFound = Array . prototype . every . call ( expected , function ( element ) {
176+ var allFound = Array . prototype . every . call ( expected , function ( element ) {
177177 return ( Array . prototype . indexOf . call ( actual , element ) >= 0 ) ;
178178 } ) ;
179179 equal ( allFound , true ) ;
@@ -193,7 +193,7 @@ test("returns the elements this element labels", function() {
193193 var actual = axs . utils . getIdReferrers ( "aria-labelledby" , label ) ;
194194 equal ( expected . length , labelledCount ) ; // sanity check the test itself
195195 equal ( actual . length , labelledCount ) ;
196- var allFound = Array . prototype . every . call ( expected , function ( element ) {
196+ var allFound = Array . prototype . every . call ( expected , function ( element ) {
197197 return ( Array . prototype . indexOf . call ( actual , element ) >= 0 ) ;
198198 } ) ;
199199 equal ( allFound , true ) ;
@@ -246,9 +246,11 @@ module("getRoles", {
246246test ( "getRoles on element with valid role." , function ( ) {
247247 for ( var role in axs . constants . ARIA_ROLES ) {
248248 if ( axs . constants . ARIA_ROLES . hasOwnProperty ( role ) && ! axs . constants . ARIA_ROLES [ role ] . abstract ) {
249+ var appliedRole = { name : role , valid : true , details : axs . constants . ARIA_ROLES [ role ] } ;
249250 var expected = {
250251 valid : true ,
251- roles : [ { name : role , valid : true , details : axs . constants . ARIA_ROLES [ role ] } ]
252+ applied : appliedRole ,
253+ roles : [ appliedRole ]
252254 } ;
253255 var element = document . createElement ( 'div' ) ;
254256 element . setAttribute ( 'role' , role ) ;
@@ -275,9 +277,11 @@ test("getRoles on element with empty role.", function() {
275277} ) ;
276278
277279test ( "getRoles on element with implicit role and options.implicit." , function ( ) {
280+ var appliedRole = { name : 'checkbox' , valid : true , details : axs . constants . ARIA_ROLES [ 'checkbox' ] } ;
278281 var expected = {
279282 valid : true ,
280- roles : [ { name : 'checkbox' , valid : true , details : axs . constants . ARIA_ROLES [ 'checkbox' ] } ]
283+ applied : appliedRole ,
284+ roles : [ appliedRole ]
281285 } ;
282286 var element = document . createElement ( 'input' ) ;
283287 element . setAttribute ( 'type' , 'checkbox' ) ;
@@ -307,3 +311,50 @@ test("getRoles on element with abstract role.", function() {
307311 }
308312 }
309313} ) ;
314+ ( function ( ) {
315+ /**
316+ * Creates a 'role detail' object which can be used for comparison in the assertions below.
317+ * @param {!string } role A potential ARIA role.
318+ * @return The 'role detail' object.
319+ */
320+ function createExpectedRoleObject ( role ) {
321+ var valid = ( axs . constants . ARIA_ROLES . hasOwnProperty ( role ) && ! axs . constants . ARIA_ROLES [ role ] . abstract ) ;
322+ var result = { name : role , valid : valid } ;
323+ if ( valid ) {
324+ result . details = axs . constants . ARIA_ROLES [ role ] ;
325+ }
326+ return result ;
327+ }
328+
329+ /**
330+ * Helper for multiple role tests.
331+ * @param {!Array<string> } roles Strings to set in the 'role' attribute of the element under test.
332+ * @param {!number } validIdx The index of the expected applied (valid) ARIA role in the array above
333+ * or a negative number if there are no valid roles.
334+ * @return {Function } A test function for qunit.
335+ */
336+ function multipleRoleTestHelper ( roles , validIdx ) {
337+ return function ( ) {
338+ var expectedRoles = roles . map ( createExpectedRoleObject ) ;
339+ var expected = {
340+ roles : expectedRoles
341+ } ;
342+ if ( validIdx >= 0 ) {
343+ expected . valid = true ;
344+ expected . applied = expectedRoles [ validIdx ] ;
345+ }
346+ else {
347+ expected . valid = false ;
348+ }
349+ var element = document . createElement ( 'div' ) ;
350+ element . setAttribute ( 'role' , roles . join ( ' ' ) ) ;
351+ var actual = axs . utils . getRoles ( element ) ;
352+ deepEqual ( actual , expected ) ;
353+ } ;
354+ }
355+
356+ test ( "getRoles on element with multiple valid roles." , multipleRoleTestHelper ( [ 'checkbox' , 'button' , 'radio' ] , 0 ) ) ;
357+ test ( "getRoles on element with invalid and valid roles." , multipleRoleTestHelper ( [ 'foo' , 'button' , 'bar' ] , 1 ) ) ;
358+ test ( "getRoles on element with multiple invalid roles." , multipleRoleTestHelper ( [ 'foo' , 'fubar' , 'bar' ] , - 1 ) ) ;
359+
360+ } ( ) ) ;
0 commit comments