@@ -177,6 +177,15 @@ describe('TimePicker', () => {
177177 expect (
178178 container . querySelector ( '.cds--form-requirement' )
179179 ) . toHaveTextContent ( 'Invalid time' ) ;
180+ const invalidText = screen . getByText ( 'Invalid time' ) ;
181+ expect ( screen . getByRole ( 'textbox' ) ) . toHaveAttribute (
182+ 'aria-describedby' ,
183+ invalidText . id
184+ ) ;
185+ expect ( screen . getByRole ( 'textbox' ) ) . toHaveAttribute (
186+ 'aria-invalid' ,
187+ 'true'
188+ ) ;
180189 } ) ;
181190
182191 it ( 'should show warning state when warning is true' , ( ) => {
@@ -192,6 +201,12 @@ describe('TimePicker', () => {
192201 expect (
193202 container . querySelector ( '.cds--form-requirement' )
194203 ) . toHaveTextContent ( 'Warning message' ) ;
204+ const warningText = screen . getByText ( 'Warning message' ) ;
205+ expect ( screen . getByRole ( 'textbox' ) ) . toHaveAttribute (
206+ 'aria-describedby' ,
207+ warningText . id
208+ ) ;
209+ expect ( screen . getByRole ( 'textbox' ) ) . not . toHaveAttribute ( 'aria-invalid' ) ;
195210 } ) ;
196211
197212 it ( 'should not show invalid state when disabled' , ( ) => {
@@ -289,5 +304,51 @@ describe('TimePicker', () => {
289304 container . querySelector ( '.cds--time-picker__input-field-error' )
290305 ) . not . toBeInTheDocument ( ) ;
291306 } ) ;
307+
308+ it ( 'should preserve provided aria-describedby when not invalid or warning' , ( ) => {
309+ render ( < TimePicker id = "time-picker" aria-describedby = "custom-hint" /> ) ;
310+ expect ( screen . getByRole ( 'textbox' ) ) . toHaveAttribute (
311+ 'aria-describedby' ,
312+ 'custom-hint'
313+ ) ;
314+ } ) ;
315+
316+ it ( 'should merge invalid aria attributes with consumer-provided aria-describedby' , ( ) => {
317+ render (
318+ < TimePicker
319+ id = "time-picker"
320+ invalid
321+ invalidText = "Invalid time"
322+ aria-describedby = "custom-hint"
323+ aria-invalid = { false }
324+ />
325+ ) ;
326+ const invalidText = screen . getByText ( 'Invalid time' ) ;
327+ expect ( screen . getByRole ( 'textbox' ) ) . toHaveAttribute (
328+ 'aria-describedby' ,
329+ `${ invalidText . id } custom-hint`
330+ ) ;
331+ expect ( screen . getByRole ( 'textbox' ) ) . toHaveAttribute (
332+ 'aria-invalid' ,
333+ 'true'
334+ ) ;
335+ } ) ;
336+
337+ it ( 'should merge warning aria attributes with consumer-provided aria-describedby' , ( ) => {
338+ render (
339+ < TimePicker
340+ id = "time-picker"
341+ warning
342+ warningText = "Warning message"
343+ aria-describedby = "custom-hint"
344+ />
345+ ) ;
346+ const warningText = screen . getByText ( 'Warning message' ) ;
347+ expect ( screen . getByRole ( 'textbox' ) ) . toHaveAttribute (
348+ 'aria-describedby' ,
349+ `${ warningText . id } custom-hint`
350+ ) ;
351+ expect ( screen . getByRole ( 'textbox' ) ) . not . toHaveAttribute ( 'aria-invalid' ) ;
352+ } ) ;
292353 } ) ;
293354} ) ;
0 commit comments