@@ -2,10 +2,11 @@ import {render as HTMLRender, fireEvent} from '@testing-library/react'
22import { axe } from 'jest-axe'
33import React , { useCallback , useRef , useState } from 'react'
44
5- import { ActionMenu } from '../deprecated/ActionMenu'
5+ import { ActionMenu } from '../ActionMenu'
6+ import { ActionList } from '../ActionList'
67import BaseStyles from '../BaseStyles'
78import Box from '../Box'
8- import Button from '../deprecated/Button /Button'
9+ import { Button } from '../Button'
910import { ConfirmationDialog , useConfirm } from '../Dialog/ConfirmationDialog'
1011import theme from '../theme'
1112import { ThemeProvider } from '../ThemeProvider'
@@ -62,10 +63,14 @@ const ShorthandHookFromActionMenu = () => {
6263 < SSRProvider >
6364 < BaseStyles >
6465 < Box display = "flex" flexDirection = "column" alignItems = "flex-start" >
65- < ActionMenu
66- renderAnchor = { props => < Button { ...props } > { text } </ Button > }
67- items = { [ { text : 'Show dialog' , onAction : onButtonClick } ] }
68- />
66+ < ActionMenu >
67+ < ActionMenu . Button > { text } </ ActionMenu . Button >
68+ < ActionMenu . Overlay >
69+ < ActionList >
70+ < ActionList . Item onSelect = { onButtonClick } > Show dialog</ ActionList . Item >
71+ </ ActionList >
72+ </ ActionMenu . Overlay >
73+ </ ActionMenu >
6974 </ Box >
7075 </ BaseStyles >
7176 </ SSRProvider >
@@ -95,36 +100,36 @@ describe('ConfirmationDialog', () => {
95100 } )
96101
97102 it ( 'focuses the primary action when opened and the confirmButtonType is not set' , async ( ) => {
98- const { getByText} = HTMLRender ( < Basic /> )
103+ const { getByText, getByRole } = HTMLRender ( < Basic /> )
99104 fireEvent . click ( getByText ( 'Show dialog' ) )
100- expect ( getByText ( ' Primary') ) . toEqual ( document . activeElement )
105+ expect ( getByRole ( 'button' , { name : ' Primary'} ) ) . toEqual ( document . activeElement )
101106 expect ( getByText ( 'Secondary' ) ) . not . toEqual ( document . activeElement )
102107 } )
103108
104109 it ( 'focuses the primary action when opened and the confirmButtonType is not danger' , async ( ) => {
105- const { getByText} = HTMLRender ( < Basic confirmButtonType = "primary" /> )
110+ const { getByText, getByRole } = HTMLRender ( < Basic confirmButtonType = "primary" /> )
106111 fireEvent . click ( getByText ( 'Show dialog' ) )
107- expect ( getByText ( ' Primary') ) . toEqual ( document . activeElement )
112+ expect ( getByRole ( 'button' , { name : ' Primary'} ) ) . toEqual ( document . activeElement )
108113 expect ( getByText ( 'Secondary' ) ) . not . toEqual ( document . activeElement )
109114 } )
110115
111116 it ( 'focuses the secondary action when opened and the confirmButtonType is danger' , async ( ) => {
112- const { getByText} = HTMLRender ( < Basic confirmButtonType = "danger" /> )
117+ const { getByText, getByRole } = HTMLRender ( < Basic confirmButtonType = "danger" /> )
113118 fireEvent . click ( getByText ( 'Show dialog' ) )
114- expect ( getByText ( ' Primary') ) . not . toEqual ( document . activeElement )
115- expect ( getByText ( ' Secondary') ) . toEqual ( document . activeElement )
119+ expect ( getByRole ( 'button' , { name : ' Primary'} ) ) . not . toEqual ( document . activeElement )
120+ expect ( getByRole ( 'button' , { name : ' Secondary'} ) ) . toEqual ( document . activeElement )
116121 } )
117122
118123 it ( 'supports nested `focusTrap`s' , async ( ) => {
119124 const spy = jest . spyOn ( console , 'error' ) . mockImplementationOnce ( ( ) => { } )
120125
121- const { getByText} = HTMLRender ( < ShorthandHookFromActionMenu /> )
126+ const { getByText, getByRole } = HTMLRender ( < ShorthandHookFromActionMenu /> )
122127
123128 fireEvent . click ( getByText ( 'Show menu' ) )
124129 fireEvent . click ( getByText ( 'Show dialog' ) )
125130
126- expect ( getByText ( ' Primary') ) . toEqual ( document . activeElement )
127- expect ( getByText ( ' Secondary') ) . not . toEqual ( document . activeElement )
131+ expect ( getByRole ( 'button' , { name : ' Primary'} ) ) . toEqual ( document . activeElement )
132+ expect ( getByRole ( 'button' , { name : ' Secondary'} ) ) . not . toEqual ( document . activeElement )
128133
129134 // REACT_VERSION_LATEST should be treated as a constant for the test
130135 // environment
0 commit comments