@@ -98,33 +98,33 @@ describe('ConfirmationDialog', () => {
98
98
} )
99
99
100
100
it ( 'focuses the primary action when opened and the confirmButtonType is not set' , async ( ) => {
101
- const { getByText} = HTMLRender ( < Basic /> )
101
+ const { getByText, getByRole } = HTMLRender ( < Basic /> )
102
102
fireEvent . click ( getByText ( 'Show dialog' ) )
103
- expect ( getByText ( ' Primary') ) . toEqual ( document . activeElement )
104
- expect ( getByText ( ' Secondary') ) . not . toEqual ( document . activeElement )
103
+ expect ( getByRole ( 'button' , { name : ' Primary'} ) ) . toHaveFocus ( )
104
+ expect ( getByRole ( 'button' , { name : ' Secondary'} ) ) . not . toHaveFocus ( )
105
105
} )
106
106
107
107
it ( 'focuses the primary action when opened and the confirmButtonType is not danger' , async ( ) => {
108
- const { getByText} = HTMLRender ( < Basic confirmButtonType = "primary" /> )
108
+ const { getByText, getByRole } = HTMLRender ( < Basic confirmButtonType = "primary" /> )
109
109
fireEvent . click ( getByText ( 'Show dialog' ) )
110
- expect ( getByText ( ' Primary') ) . toEqual ( document . activeElement )
111
- expect ( getByText ( ' Secondary') ) . not . toEqual ( document . activeElement )
110
+ expect ( getByRole ( 'button' , { name : ' Primary'} ) ) . toHaveFocus ( )
111
+ expect ( getByRole ( 'button' , { name : ' Secondary'} ) ) . not . toHaveFocus ( )
112
112
} )
113
113
114
114
it ( 'focuses the secondary action when opened and the confirmButtonType is danger' , async ( ) => {
115
- const { getByText} = HTMLRender ( < Basic confirmButtonType = "danger" /> )
115
+ const { getByText, getByRole } = HTMLRender ( < Basic confirmButtonType = "danger" /> )
116
116
fireEvent . click ( getByText ( 'Show dialog' ) )
117
- expect ( getByText ( ' Primary') ) . not . toEqual ( document . activeElement )
118
- expect ( getByText ( ' Secondary') ) . toEqual ( document . activeElement )
117
+ expect ( getByRole ( 'button' , { name : ' Primary'} ) ) . not . toHaveFocus ( )
118
+ expect ( getByRole ( 'button' , { name : ' Secondary'} ) ) . toHaveFocus ( )
119
119
} )
120
120
121
121
it ( 'supports nested `focusTrap`s' , async ( ) => {
122
- const { getByText} = HTMLRender ( < ShorthandHookFromActionMenu /> )
122
+ const { getByText, getByRole } = HTMLRender ( < ShorthandHookFromActionMenu /> )
123
123
124
124
fireEvent . click ( getByText ( 'Show menu' ) )
125
125
fireEvent . click ( getByText ( 'Show dialog' ) )
126
126
127
- expect ( getByText ( ' Primary') ) . toEqual ( document . activeElement )
128
- expect ( getByText ( ' Secondary') ) . not . toEqual ( document . activeElement )
127
+ expect ( getByRole ( 'button' , { name : ' Primary'} ) ) . toHaveFocus ( )
128
+ expect ( getByRole ( 'button' , { name : ' Secondary'} ) ) . not . toHaveFocus ( )
129
129
} )
130
130
} )
0 commit comments