@@ -25,6 +25,31 @@ describe('Progress', () => {
2525 expect ( screen . getByText ( '100%' ) ) . toBeInTheDocument ( )
2626 } )
2727
28+ it ( 'uses custom formatted text for visible and accessible value text' , ( ) => {
29+ render ( < Progress percent = { 75 } format = { ( value ) => `${ value } days` } /> )
30+
31+ const progress = screen . getByRole ( 'progressbar' , { name : 'Progress' } )
32+
33+ expect ( progress ) . toHaveAttribute ( 'aria-valuenow' , '75' )
34+ expect ( progress ) . toHaveAttribute ( 'aria-valuetext' , '75 days' )
35+ expect ( screen . getByText ( '75 days' ) ) . toBeInTheDocument ( )
36+ } )
37+
38+ it ( 'keeps explicit value text when custom formatted content is visual only' , ( ) => {
39+ render (
40+ < Progress
41+ percent = { 75 }
42+ format = { ( value ) => < span > { value } days</ span > }
43+ aria-valuetext = "75 days remaining"
44+ /> ,
45+ )
46+
47+ const progress = screen . getByRole ( 'progressbar' , { name : 'Progress' } )
48+
49+ expect ( progress ) . toHaveAttribute ( 'aria-valuetext' , '75 days remaining' )
50+ expect ( screen . getByText ( '75 days' ) ) . toBeInTheDocument ( )
51+ } )
52+
2853 it ( 'supports external labelling and custom value text' , ( ) => {
2954 render (
3055 < div >
@@ -44,4 +69,4 @@ describe('Progress', () => {
4469 expect ( progress ) . toHaveAttribute ( 'aria-valuetext' , '64 percent complete' )
4570 expect ( screen . queryByText ( '64%' ) ) . not . toBeInTheDocument ( )
4671 } )
47- } )
72+ } )
0 commit comments