@@ -102,9 +102,8 @@ test('renders Header with event handlers', async () => {
102102 } )
103103 const menu = screen . getByLabelText ( 'Menu' )
104104 const logo = screen . getByLabelText ( 'Logo' )
105- const account = screen . getByLabelText ( / O p e n a c c o u n t m e n u / i)
105+ const account = screen . getByLabelText ( / M y A c c o u n t / i)
106106 const cart = screen . getByLabelText ( / M y c a r t , n u m b e r o f i t e m s : 2 / )
107-
108107 await act ( async ( ) => {
109108 fireEvent . click ( menu )
110109 } )
@@ -121,13 +120,7 @@ test('renders Header with event handlers', async () => {
121120 expect ( onMyCartClick ) . toHaveBeenCalledTimes ( 1 )
122121
123122 await act ( async ( ) => {
124- fireEvent . mouseEnter ( account )
125- } )
126- // The onClick handler is on the AccountIcon inside the button,
127- // so we need to find and click that
128- const accountIcon = account . querySelector ( 'svg[aria-label="account"]' )
129- await act ( async ( ) => {
130- fireEvent . click ( accountIcon )
123+ fireEvent . click ( account )
131124 } )
132125 expect ( onMyAccountClick ) . toHaveBeenCalledTimes ( 1 )
133126} )
@@ -174,34 +167,18 @@ test('renders cart badge when basket is loaded', async () => {
174167test ( 'route to account page when an authenticated users click on account icon' , async ( ) => {
175168 const history = createMemoryHistory ( )
176169 history . push = jest . fn ( )
177- renderWithProviders ( < MockedComponent history = { history } /> )
170+ const { user } = renderWithProviders ( < MockedComponent history = { history } /> )
178171
179172 await waitFor ( ( ) => {
180173 // Look for account button
181- const accountTrigger = screen . getByLabelText ( / O p e n a c c o u n t m e n u / )
174+ const accountTrigger = screen . getByLabelText ( / M y a c c o u n t / )
182175 expect ( accountTrigger ) . toBeInTheDocument ( )
183176 } )
184177
185- const accountButton = screen . getByLabelText ( / O p e n a c c o u n t m e n u / )
186-
187- await act ( async ( ) => {
188- // Use mouseEnter to open the popover, then click on the AccountIcon inside
189- fireEvent . mouseEnter ( accountButton )
190- } )
191-
192- // The onClick handler is on the AccountIcon inside the button,
193- // so we need to find and click that
194- const accountIcon = accountButton . querySelector ( 'svg[aria-label="account"]' )
195- await act ( async ( ) => {
196- fireEvent . click ( accountIcon )
197- } )
198- await waitFor ( ( ) => {
199- expect ( history . push ) . toHaveBeenCalledWith ( createPathWithDefaults ( '/account' ) )
200- } )
178+ const accountButton = screen . getByLabelText ( / M y a c c o u n t / )
201179
202- // Test keyDown on the AccountIcon
203180 await act ( async ( ) => {
204- fireEvent . keyDown ( accountIcon , { key : 'Enter' , code : 'Enter' } )
181+ await user . click ( accountButton )
205182 } )
206183 await waitFor ( ( ) => {
207184 expect ( history . push ) . toHaveBeenCalledWith ( createPathWithDefaults ( '/account' ) )
@@ -228,41 +205,3 @@ test('route to wishlist page when an authenticated users click on wishlist icon'
228205 expect ( history . push ) . toHaveBeenCalledWith ( createPathWithDefaults ( '/account/wishlist' ) )
229206 } )
230207} )
231-
232- test ( 'shows dropdown menu when an authenticated users hover on the account icon' , async ( ) => {
233- global . server . use (
234- rest . post ( '*/customers/action/login' , ( req , res , ctx ) => {
235- return res ( ctx . delay ( 0 ) , ctx . status ( 200 ) , ctx . json ( mockedRegisteredCustomer ) )
236- } )
237- )
238- const history = createMemoryHistory ( )
239- history . push = jest . fn ( )
240-
241- await act ( async ( ) => {
242- renderWithProviders ( < MockedComponent history = { history } /> )
243- } )
244-
245- await waitFor ( ( ) => {
246- // Look for account button
247- const accountTrigger = screen . getByLabelText ( / O p e n a c c o u n t m e n u / i)
248- expect ( accountTrigger ) . toBeInTheDocument ( )
249- } )
250-
251- const accountButton = screen . getByLabelText ( / O p e n a c c o u n t m e n u / i)
252-
253- // Use mouseEnter to open the popover/dropdown
254- await act ( async ( ) => {
255- fireEvent . mouseEnter ( accountButton )
256- } )
257-
258- // Now check that the dropdown menu items are visible
259- await waitFor ( ( ) => {
260- expect ( screen . getByText ( / a c c o u n t d e t a i l s / i) ) . toBeInTheDocument ( )
261- expect ( screen . getByText ( / a d d r e s s e s / i) ) . toBeInTheDocument ( )
262- expect ( screen . getByText ( / w i s h l i s t / i) ) . toBeInTheDocument ( )
263- expect ( screen . getByText ( / o r d e r h i s t o r y / i) ) . toBeInTheDocument ( )
264- const logOutIcon = screen . getByLabelText ( 'signout' )
265- expect ( logOutIcon ) . toBeInTheDocument ( )
266- expect ( logOutIcon ) . toHaveAttribute ( 'aria-hidden' , 'true' )
267- } )
268- } )
0 commit comments