1
1
// SPDX-License-Identifier: MPL-2.0
2
2
// Copyright (C) 2020 - 2022 Gemeente Amsterdam
3
- import { render , screen } from '@testing-library/react'
3
+ import { render , screen , waitFor } from '@testing-library/react'
4
4
import userEvent from '@testing-library/user-event'
5
5
import * as reactRedux from 'react-redux'
6
- import * as reactRouterDom from 'react-router-dom'
7
6
8
7
import configuration from 'shared/services/configuration/configuration'
9
8
import { formatAddress } from 'shared/services/format-address'
@@ -12,6 +11,7 @@ import { AssetSelectProvider } from 'signals/incident/components/form/MapSelecto
12
11
import type { SummaryProps } from 'signals/incident/components/form/MapSelectors/Asset/types'
13
12
import type { Item } from 'signals/incident/components/form/MapSelectors/types'
14
13
import { showMap } from 'signals/incident/containers/IncidentContainer/actions'
14
+ import { history } from 'test/utils'
15
15
import { withAppContext } from 'test/utils'
16
16
import type { Address } from 'types/address'
17
17
@@ -58,22 +58,12 @@ export const summaryProps: SummaryProps = {
58
58
coordinates : { lat : 0 , lng : 0 } ,
59
59
}
60
60
61
- let mockLocation = {
62
- pathname : '/incident/vulaan' ,
63
- referrer : '/' ,
64
- search : '' ,
65
- state : { } ,
66
- hash : '' ,
67
- }
68
-
69
61
export const withContext = (
70
62
Component : JSX . Element ,
71
63
context = assetSelectContextValue
72
64
) =>
73
65
withAppContext (
74
- < reactRouterDom . MemoryRouter initialEntries = { [ mockLocation ] } >
75
- < AssetSelectProvider value = { context } > { Component } </ AssetSelectProvider >
76
- </ reactRouterDom . MemoryRouter >
66
+ < AssetSelectProvider value = { context } > { Component } </ AssetSelectProvider >
77
67
)
78
68
79
69
const dispatch = jest . fn ( )
@@ -204,14 +194,13 @@ describe('signals/incident/components/form/AssetSelect/Summary', () => {
204
194
expect ( screen . getByTestId ( 'map-edit-button' ) ) . toBeInTheDocument ( )
205
195
} )
206
196
207
- it ( "does not render the mapEditButton at 'incident/summary'" , ( ) => {
208
- mockLocation = {
209
- ...mockLocation ,
210
- pathname : '/incident/summary' ,
211
- }
197
+ it ( "does not render the mapEditButton at 'incident/summary'" , async ( ) => {
198
+ history . push ( '/incident/summary' )
212
199
213
200
render ( withContext ( < Summary { ...summaryProps } /> ) )
214
201
215
- expect ( screen . queryByTestId ( 'map-edit-button' ) ) . not . toBeInTheDocument ( )
202
+ await waitFor ( ( ) => {
203
+ expect ( screen . queryByTestId ( 'map-edit-button' ) ) . not . toBeInTheDocument ( )
204
+ } )
216
205
} )
217
206
} )
0 commit comments