@@ -29,9 +29,11 @@ const glyphPaths = fs
2929const generatedFilesDirectory = path . resolve ( __dirname , './generated' ) ;
3030const baseNameToGeneratedFilePath : Record < string , string > = { } ;
3131
32- fs . readdirSync ( generatedFilesDirectory ) . forEach ( filePath => {
33- baseNameToGeneratedFilePath [ getBaseName ( filePath ) ] = filePath ;
34- } ) ;
32+ fs . readdirSync ( generatedFilesDirectory )
33+ . filter ( filePath => / .* \. t s x $ / . test ( filePath ) )
34+ . forEach ( filePath => {
35+ baseNameToGeneratedFilePath [ getBaseName ( filePath ) ] = filePath ;
36+ } ) ;
3537
3638const MyTestSVGRGlyph : SVGR . Component = props => (
3739 < svg data-testid = "my-glyph" { ...props } > </ svg >
@@ -276,7 +278,7 @@ describe('Generated glyphs', () => {
276278 } ) ;
277279
278280 describe ( 'accessible props handled correctly' , ( ) => {
279- test ( 'when no prop is supplied, aria-label is genereated ' , ( ) => {
281+ test ( 'when no prop is supplied, aria-label is generated ' , ( ) => {
280282 render ( < EditIcon /> ) ;
281283 const editIcon = screen . getByRole ( 'img' ) ;
282284 expect ( editIcon . getAttribute ( 'aria-label' ) ) . toBe ( 'Edit Icon' ) ;
@@ -295,11 +297,32 @@ describe('Generated glyphs', () => {
295297 expect ( editIcon . getAttribute ( 'aria-labelledby' ) ) . toBe ( 'Test label' ) ;
296298 } ) ;
297299
298- test ( 'when title is supplied it overrides default label ' , ( ) => {
300+ test ( 'when title is supplied it renders a title element and aria-labelledby ' , ( ) => {
299301 render ( < EditIcon title = "Test title" /> ) ;
300302 const editIcon = screen . getByRole ( 'img' ) ;
301303 expect ( editIcon . getAttribute ( 'aria-label' ) ) . toBe ( null ) ;
302- expect ( editIcon . getAttribute ( 'title' ) ) . toBe ( 'Test title' ) ;
304+ // Should have aria-labelledby instead of title attribute
305+ const ariaLabelledBy = editIcon . getAttribute ( 'aria-labelledby' ) ;
306+ expect ( ariaLabelledBy ) . not . toBe ( null ) ;
307+ // Should find a title element with matching ID containing the text
308+ const titleElement = editIcon . querySelector ( 'title' ) ;
309+ expect ( titleElement ) . not . toBe ( null ) ;
310+ expect ( titleElement ?. textContent ) . toBe ( 'Test title' ) ;
311+ expect ( titleElement ?. id ) . toBe ( ariaLabelledBy ) ;
312+ } ) ;
313+
314+ test ( 'when both title and aria-labelledby are supplied they are combined' , ( ) => {
315+ render ( < EditIcon title = "Test title" aria-labelledby = "external-label" /> ) ;
316+ const editIcon = screen . getByRole ( 'img' ) ;
317+ expect ( editIcon . getAttribute ( 'aria-label' ) ) . toBe ( null ) ;
318+ const ariaLabelledBy = editIcon . getAttribute ( 'aria-labelledby' ) ;
319+ // Should contain both the title ID and the external label
320+ expect ( ariaLabelledBy ) . toContain ( 'external-label' ) ;
321+ const titleElement = editIcon . querySelector ( 'title' ) ;
322+ expect ( titleElement ) . not . toBe ( null ) ;
323+ expect ( titleElement ?. textContent ) . toBe ( 'Test title' ) ;
324+ // The aria-labelledby should reference both
325+ expect ( ariaLabelledBy ) . toBe ( `${ titleElement ?. id } external-label` ) ;
303326 } ) ;
304327
305328 test ( 'when role="presentation", aria-hidden is true' , ( ) => {
0 commit comments