@@ -3,7 +3,8 @@ import {Tooltip, TooltipProps} from '../Tooltip'
33import { checkStoriesForAxeViolations } from '../../../utils/testing'
44import { render as HTMLRender } from '@testing-library/react'
55import theme from '../../../theme'
6- import { Button , ActionMenu , ActionList , ThemeProvider , SSRProvider , BaseStyles } from '../../../'
6+ import { Button , IconButton , ActionMenu , ActionList , ThemeProvider , SSRProvider , BaseStyles } from '../../../'
7+ import { XIcon } from '@primer/octicons-react'
78
89const TooltipComponent = ( props : Omit < TooltipProps , 'text' > & { text ?: string } ) => (
910 < Tooltip text = "Tooltip text" { ...props } >
@@ -91,4 +92,22 @@ describe('Tooltip', () => {
9192 expect ( menuButton ) . toHaveAttribute ( 'aria-describedby' , tooltip . id )
9293 expect ( menuButton ) . toHaveAttribute ( 'aria-haspopup' , 'true' )
9394 } )
95+ it ( 'should use the custom tooltip id (if present) to label the trigger element' , ( ) => {
96+ const { getByRole} = HTMLRender (
97+ < Tooltip id = "custom-tooltip-id" text = "Close feedback form" direction = "nw" type = "label" >
98+ < IconButton aria-labelledby = "custom-tooltip-id" icon = { XIcon } variant = "invisible" onClick = { ( ) => { } } />
99+ </ Tooltip > ,
100+ )
101+ const triggerEL = getByRole ( 'button' )
102+ expect ( triggerEL ) . toHaveAttribute ( 'aria-labelledby' , 'custom-tooltip-id' )
103+ } )
104+ it ( 'should use the custom tooltip id (if present) to described the trigger element' , ( ) => {
105+ const { getByRole} = HTMLRender (
106+ < Tooltip text = "This operation cannot be reverted" id = "custom-tooltip-id" >
107+ < Button > Delete</ Button >
108+ </ Tooltip > ,
109+ )
110+ const triggerEL = getByRole ( 'button' )
111+ expect ( triggerEL ) . toHaveAttribute ( 'aria-describedby' , 'custom-tooltip-id' )
112+ } )
94113} )
0 commit comments