@@ -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,49 @@ 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+
81+ // tooltip in the document and maybe check if it's visible
82+ // action button is still active and can actionMenuTrigger the menu.
83+
4084describe ( 'ActionMenu' , ( ) => {
4185 behavesAsComponent ( {
4286 Component : ActionList ,
@@ -244,4 +288,83 @@ describe('ActionMenu', () => {
244288 const results = await axe ( container )
245289 expect ( results ) . toHaveNoViolations ( )
246290 } )
291+
292+ it ( 'should open menu on menu button click and it is wrapped with tooltip' , async ( ) => {
293+ const component = HTMLRender ( < ExampleWithTooltip /> )
294+ const button = component . getByRole ( 'button' )
295+
296+ const user = userEvent . setup ( )
297+ await user . click ( button )
298+
299+ expect ( component . getByRole ( 'menu' ) ) . toBeInTheDocument ( )
300+ } )
301+
302+ it ( 'should open menu on menu button click and it is wrapped with tooltip v2' , async ( ) => {
303+ const component = HTMLRender (
304+ ExampleWithTooltipV2 (
305+ < TooltipV2 text = "Additional context about the menu button" direction = "s" >
306+ < ActionMenu . Button > Toggle Menu</ ActionMenu . Button >
307+ </ TooltipV2 > ,
308+ ) ,
309+ )
310+ const button = component . getByRole ( 'button' )
311+
312+ const user = userEvent . setup ( )
313+ await user . click ( button )
314+
315+ expect ( component . getByRole ( 'menu' ) ) . toBeInTheDocument ( )
316+ } )
317+
318+ it ( 'should display tooltip when menu button is focused' , async ( ) => {
319+ const component = HTMLRender ( < ExampleWithTooltip /> )
320+ const button = component . getByRole ( 'button' )
321+ button . focus ( )
322+ expect ( component . getByRole ( 'tooltip' ) ) . toBeInTheDocument ( )
323+ } )
324+
325+ it ( 'should display tooltip v2 when menu button is focused' , async ( ) => {
326+ const component = HTMLRender (
327+ ExampleWithTooltipV2 (
328+ < TooltipV2 text = "Additional context about the menu button" direction = "s" >
329+ < ActionMenu . Button > Toggle Menu</ ActionMenu . Button >
330+ </ TooltipV2 > ,
331+ ) ,
332+ )
333+ const button = component . getByRole ( 'button' )
334+ button . focus ( )
335+ expect ( component . getByRole ( 'tooltip' ) ) . toBeInTheDocument ( )
336+ } )
337+
338+ it ( 'should open menu on menu anchor click and it is wrapped with tooltip v2' , async ( ) => {
339+ const component = HTMLRender (
340+ ExampleWithTooltipV2 (
341+ < ActionMenu . Anchor >
342+ < TooltipV2 text = "Additional context about the menu button" direction = "n" >
343+ < Button > Toggle Menu</ Button >
344+ </ TooltipV2 >
345+ </ ActionMenu . Anchor > ,
346+ ) ,
347+ )
348+ const button = component . getByRole ( 'button' )
349+
350+ const user = userEvent . setup ( )
351+ await user . click ( button )
352+
353+ expect ( component . getByRole ( 'menu' ) ) . toBeInTheDocument ( )
354+ } )
355+
356+ it ( 'should display tooltip v2 and menu anchor is focused' , async ( ) => {
357+ const component = HTMLRender (
358+ ExampleWithTooltipV2 (
359+ < ActionMenu . Anchor >
360+ < TooltipV2 text = "Additional context about the menu button" direction = "n" >
361+ < Button > Toggle Menu</ Button >
362+ </ TooltipV2 >
363+ </ ActionMenu . Anchor > ,
364+ ) ,
365+ )
366+ const button = component . getByRole ( 'button' )
367+ button . focus ( )
368+ expect ( component . getByRole ( 'tooltip' ) ) . toBeInTheDocument ( )
369+ } )
247370} )
0 commit comments