@@ -238,16 +238,64 @@ module('layout', moduleConfig, () => {
238238 assert . strictEqual ( itemsCount , items . length , `items with the "${ RADIO_BUTTON_CLASS } " class were rendered` ) ;
239239 } ) ;
240240
241- test ( 'radioGroup should have role="alert" attribute on validation message' , function ( assert ) {
242- const $radioGroup = $ ( '#radioGroup' ) . dxRadioGroup ( {
241+ } ) ;
242+
243+ module ( 'accessibility' , moduleConfig , ( ) => {
244+ test ( 'validation message should not have role="alert"' , function ( assert ) {
245+ const $radioGroup = createRadioGroup ( {
243246 items : [ 1 , 2 , 3 ] ,
244247 isValid : false ,
245- validationError : 'Some error' ,
248+ validationError : { message : 'Some error' } ,
246249 validationMessageMode : 'always' ,
247250 } ) ;
248251 const $validationMessage = $radioGroup . find ( `.${ INVALID_MESSAGE_CONTENT } ` ) ;
249252
250- assert . strictEqual ( $validationMessage . attr ( 'role' ) , 'alert' ) ;
253+ assert . notStrictEqual ( $validationMessage . attr ( 'role' ) , 'alert' , 'validation message does not have role="alert"' ) ;
254+ } ) ;
255+
256+ test ( 'root element should not have aria-describedby when invalid' , function ( assert ) {
257+ const $radioGroup = createRadioGroup ( {
258+ items : [ 1 , 2 , 3 ] ,
259+ isValid : false ,
260+ validationError : { message : 'Some error' } ,
261+ validationMessageMode : 'always' ,
262+ } ) ;
263+
264+ assert . strictEqual ( $radioGroup . attr ( 'aria-describedby' ) , undefined , 'root element does not have aria-describedby' ) ;
265+ } ) ;
266+
267+ test ( 'each radio button should have aria-describedby referencing the validation message when invalid' , function ( assert ) {
268+ const $radioGroup = createRadioGroup ( {
269+ items : [ 1 , 2 , 3 ] ,
270+ isValid : false ,
271+ validationError : { message : 'Some error' } ,
272+ validationMessageMode : 'always' ,
273+ } ) ;
274+ const instance = getInstance ( $radioGroup ) ;
275+ const contentId = $radioGroup . find ( `.${ INVALID_MESSAGE_CONTENT } ` ) . attr ( 'id' ) ;
276+ const $buttons = $ ( instance . itemElements ( ) ) ;
277+
278+ assert . ok ( contentId , 'validation message content has an id' ) ;
279+ $buttons . each ( function ( ) {
280+ assert . strictEqual ( $ ( this ) . attr ( 'aria-describedby' ) , contentId , 'radio button references validation message' ) ;
281+ } ) ;
282+ } ) ;
283+
284+ test ( 'aria-describedby should be removed from radio buttons when validation state becomes valid' , function ( assert ) {
285+ const $radioGroup = createRadioGroup ( {
286+ items : [ 1 , 2 , 3 ] ,
287+ isValid : false ,
288+ validationError : { message : 'Some error' } ,
289+ validationMessageMode : 'always' ,
290+ } ) ;
291+ const instance = getInstance ( $radioGroup ) ;
292+
293+ instance . option ( 'isValid' , true ) ;
294+
295+ const $buttons = $ ( instance . itemElements ( ) ) ;
296+ $buttons . each ( function ( ) {
297+ assert . strictEqual ( $ ( this ) . attr ( 'aria-describedby' ) , undefined , 'aria-describedby is removed from radio button' ) ;
298+ } ) ;
251299 } ) ;
252300} ) ;
253301
0 commit comments