@@ -3,7 +3,8 @@ import userEvent from '@testing-library/user-event'
33import  { axe ,  toHaveNoViolations }  from  'jest-axe' 
44import  React  from  'react' 
55import  theme  from  '../theme' 
6- import  { ActionMenu ,  ActionList ,  BaseStyles ,  ThemeProvider ,  SSRProvider }  from  '..' 
6+ import  { ActionMenu ,  ActionList ,  BaseStyles ,  ThemeProvider ,  SSRProvider ,  Tooltip ,  Button }  from  '..' 
7+ import  { Tooltip  as  TooltipV2 }  from  '../drafts/Tooltip/Tooltip' 
78import  { behavesAsComponent ,  checkExports }  from  '../utils/testing' 
89import  { SingleSelect }  from  '../ActionMenu/ActionMenu.features.stories' 
910import  { MixedSelection }  from  '../ActionMenu/ActionMenu.examples.stories' 
@@ -37,6 +38,46 @@ function Example(): JSX.Element {
3738  ) 
3839} 
3940
41+ function  ExampleWithTooltip ( ) : JSX . Element  { 
42+   return  ( 
43+     < ThemeProvider  theme = { theme } > 
44+       < SSRProvider > 
45+         < BaseStyles > 
46+           < Tooltip  aria-label = "Additional context about the menu button"  direction = "s" > 
47+             < ActionMenu > 
48+               < ActionMenu . Button > Toggle Menu</ ActionMenu . Button > 
49+               < ActionMenu . Overlay > 
50+                 < ActionList > 
51+                   < ActionList . Item > New file</ ActionList . Item > 
52+                 </ ActionList > 
53+               </ ActionMenu . Overlay > 
54+             </ ActionMenu > 
55+           </ Tooltip > 
56+         </ BaseStyles > 
57+       </ SSRProvider > 
58+     </ ThemeProvider > 
59+   ) 
60+ } 
61+ 
62+ function  ExampleWithTooltipV2 ( actionMenuTrigger : React . ReactElement ) : JSX . Element  { 
63+   return  ( 
64+     < ThemeProvider  theme = { theme } > 
65+       < SSRProvider > 
66+         < BaseStyles > 
67+           < ActionMenu > 
68+             { actionMenuTrigger } 
69+             < ActionMenu . Overlay > 
70+               < ActionList > 
71+                 < ActionList . Item > New file</ ActionList . Item > 
72+               </ ActionList > 
73+             </ ActionMenu . Overlay > 
74+           </ ActionMenu > 
75+         </ BaseStyles > 
76+       </ SSRProvider > 
77+     </ ThemeProvider > 
78+   ) 
79+ } 
80+ 
4081describe ( 'ActionMenu' ,  ( )  =>  { 
4182  behavesAsComponent ( { 
4283    Component : ActionList , 
@@ -244,4 +285,83 @@ describe('ActionMenu', () => {
244285    const  results  =  await  axe ( container ) 
245286    expect ( results ) . toHaveNoViolations ( ) 
246287  } ) 
288+ 
289+   it ( 'should open menu on menu button click and it is wrapped with tooltip' ,  async  ( )  =>  { 
290+     const  component  =  HTMLRender ( < ExampleWithTooltip  /> ) 
291+     const  button  =  component . getByRole ( 'button' ) 
292+ 
293+     const  user  =  userEvent . setup ( ) 
294+     await  user . click ( button ) 
295+ 
296+     expect ( component . getByRole ( 'menu' ) ) . toBeInTheDocument ( ) 
297+   } ) 
298+ 
299+   it ( 'should open menu on menu button click and it is wrapped with tooltip v2' ,  async  ( )  =>  { 
300+     const  component  =  HTMLRender ( 
301+       ExampleWithTooltipV2 ( 
302+         < TooltipV2  text = "Additional context about the menu button"  direction = "s" > 
303+           < ActionMenu . Button > Toggle Menu</ ActionMenu . Button > 
304+         </ TooltipV2 > , 
305+       ) , 
306+     ) 
307+     const  button  =  component . getByRole ( 'button' ) 
308+ 
309+     const  user  =  userEvent . setup ( ) 
310+     await  user . click ( button ) 
311+ 
312+     expect ( component . getByRole ( 'menu' ) ) . toBeInTheDocument ( ) 
313+   } ) 
314+ 
315+   it ( 'should display tooltip when menu button is focused' ,  async  ( )  =>  { 
316+     const  component  =  HTMLRender ( < ExampleWithTooltip  /> ) 
317+     const  button  =  component . getByRole ( 'button' ) 
318+     button . focus ( ) 
319+     expect ( component . getByRole ( 'tooltip' ) ) . toBeInTheDocument ( ) 
320+   } ) 
321+ 
322+   it ( 'should display tooltip v2 when menu button is focused' ,  async  ( )  =>  { 
323+     const  component  =  HTMLRender ( 
324+       ExampleWithTooltipV2 ( 
325+         < TooltipV2  text = "Additional context about the menu button"  direction = "s" > 
326+           < ActionMenu . Button > Toggle Menu</ ActionMenu . Button > 
327+         </ TooltipV2 > , 
328+       ) , 
329+     ) 
330+     const  button  =  component . getByRole ( 'button' ) 
331+     button . focus ( ) 
332+     expect ( component . getByRole ( 'tooltip' ) ) . toBeInTheDocument ( ) 
333+   } ) 
334+ 
335+   it ( 'should open menu on menu anchor click and it is wrapped with tooltip v2' ,  async  ( )  =>  { 
336+     const  component  =  HTMLRender ( 
337+       ExampleWithTooltipV2 ( 
338+         < ActionMenu . Anchor > 
339+           < TooltipV2  text = "Additional context about the menu button"  direction = "n" > 
340+             < Button > Toggle Menu</ Button > 
341+           </ TooltipV2 > 
342+         </ ActionMenu . Anchor > , 
343+       ) , 
344+     ) 
345+     const  button  =  component . getByRole ( 'button' ) 
346+ 
347+     const  user  =  userEvent . setup ( ) 
348+     await  user . click ( button ) 
349+ 
350+     expect ( component . getByRole ( 'menu' ) ) . toBeInTheDocument ( ) 
351+   } ) 
352+ 
353+   it ( 'should display tooltip v2 and menu anchor is focused' ,  async  ( )  =>  { 
354+     const  component  =  HTMLRender ( 
355+       ExampleWithTooltipV2 ( 
356+         < ActionMenu . Anchor > 
357+           < TooltipV2  text = "Additional context about the menu button"  direction = "n" > 
358+             < Button > Toggle Menu</ Button > 
359+           </ TooltipV2 > 
360+         </ ActionMenu . Anchor > , 
361+       ) , 
362+     ) 
363+     const  button  =  component . getByRole ( 'button' ) 
364+     button . focus ( ) 
365+     expect ( component . getByRole ( 'tooltip' ) ) . toBeInTheDocument ( ) 
366+   } ) 
247367} ) 
0 commit comments