@defra/interactive-map 0.0.59-alpha → 0.0.61-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/assets/templates/add-polygons.njk +2 -2
- package/assets/templates/add-symbols.njk +2 -2
- package/dist/css/index.css +1 -1
- package/dist/esm/im-core.js +1 -1
- package/dist/esm/im-shell.js +1 -1
- package/dist/umd/im-core.js +1 -1
- package/dist/umd/index.js +1 -1
- package/docs/api/button-definition.md +11 -0
- package/docs/api/context.md +2 -0
- package/docs/api/panel-definition.md +30 -0
- package/docs/api/symbol-config.md +12 -0
- package/docs/api.md +21 -2
- package/docs/assets/images/slot-map.svg +3 -3
- package/docs/plugins/datasets.md +11 -1
- package/docs/plugins/draw.md +26 -0
- package/package.json +1 -1
- package/plugins/datasets/dist/esm/index.js +1 -1
- package/plugins/datasets/dist/esm/layerAdapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
- package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
- package/plugins/datasets/dist/umd/index.js +1 -1
- package/plugins/datasets/src/index.js +0 -1
- package/plugins/datasets/src/index.test.js +2 -8
- package/plugins/datasets/src/registry/dataset.test.js +9 -0
- package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
- package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
- package/plugins/draw/dist/umd/index.js +1 -1
- package/plugins/draw/src/DrawInit.jsx +3 -0
- package/plugins/draw/src/DrawInit.test.jsx +16 -0
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +19 -3
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +27 -0
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +10 -2
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +14 -0
- package/plugins/draw/src/defaults.js +4 -0
- package/plugins/draw/src/hooks/useSnapMinZoom.js +29 -0
- package/plugins/draw/src/hooks/useSnapMinZoom.test.js +82 -0
- package/plugins/draw/src/manifest.js +4 -1
- package/plugins/draw/src/manifest.test.js +15 -2
- package/plugins/draw/src/utils/snapMinZoom.js +8 -0
- package/plugins/draw/src/utils/snapMinZoom.test.js +22 -0
- package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
- package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
- package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -1
- package/plugins/map-key/src/manifest.js +1 -1
- package/plugins/search/dist/css/index.css +1 -1
- package/plugins/search/src/components/Form/Form.module.scss +1 -0
- package/providers/esri/dist/esm/im-esri-provider.js +1 -1
- package/providers/esri/src/esriProvider.js +10 -21
- package/providers/esri/src/utils/coords.js +37 -7
- package/providers/esri/src/utils/coords.test.js +22 -1
- package/providers/esri/src/utils/spatial.js +1 -47
- package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
- package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
- package/providers/maplibre/src/maplibreProvider.js +5 -14
- package/providers/maplibre/src/maplibreProvider.test.js +143 -146
- package/providers/maplibre/src/utils/spatial.js +0 -40
- package/providers/maplibre/src/utils/spatial.test.js +0 -35
- package/providers/openlayers/dist/esm/im-openlayers-provider.js +1 -1
- package/providers/openlayers/dist/umd/im-openlayers-provider.js +1 -1
- package/providers/openlayers/src/openlayersProvider.js +5 -14
- package/providers/openlayers/src/openlayersProvider.test.js +12 -10
- package/providers/openlayers/src/utils/spatial.js +0 -39
- package/providers/openlayers/src/utils/spatial.test.js +1 -26
- package/src/App/components/Hints/Hints.jsx +9 -21
- package/src/App/components/Hints/Hints.test.jsx +20 -33
- package/src/App/components/MapButton/MapButton.jsx +20 -2
- package/src/App/components/MapButton/MapButton.module.scss +15 -1
- package/src/App/components/MapButton/MapButton.test.jsx +21 -3
- package/src/App/components/Panel/Panel.jsx +16 -1
- package/src/App/components/Panel/Panel.test.jsx +44 -0
- package/src/App/components/Tooltip/Tooltip.jsx +29 -11
- package/src/App/components/Tooltip/Tooltip.test.jsx +45 -3
- package/src/App/components/Viewport/MapController.jsx +2 -0
- package/src/App/components/Viewport/MapController.test.jsx +3 -0
- package/src/App/hooks/useCrossHairAPI.js +27 -28
- package/src/App/hooks/useCrossHairAPI.test.js +64 -7
- package/src/App/hooks/useLayoutMeasurements.js +175 -131
- package/src/App/hooks/useLayoutMeasurements.test.js +227 -122
- package/src/App/hooks/useMapProviderOverrides.js +114 -35
- package/src/App/hooks/useMapProviderOverrides.test.js +188 -5
- package/src/App/hooks/useModalPanelBehaviour.js +18 -32
- package/src/App/hooks/useModalPanelBehaviour.test.js +45 -33
- package/src/App/hooks/useUserMoveTracking.js +65 -0
- package/src/App/hooks/useUserMoveTracking.test.js +99 -0
- package/src/App/hooks/useVisibleGeometry.js +35 -45
- package/src/App/hooks/useVisibleGeometry.test.js +149 -121
- package/src/App/layout/Layout.jsx +4 -4
- package/src/App/layout/layout.module.scss +124 -61
- package/src/App/renderer/mapButtons.js +1 -0
- package/src/App/renderer/mapButtons.test.js +8 -0
- package/src/App/store/AppProvider.jsx +3 -0
- package/src/App/store/appDispatchMiddleware.js +18 -10
- package/src/App/store/appDispatchMiddleware.test.js +42 -4
- package/src/App/store/mapActionsMap.js +2 -1
- package/src/App/store/mapActionsMap.test.js +6 -0
- package/src/App/store/mapReducer.js +2 -0
- package/src/App/store/mapReducer.test.js +1 -0
- package/src/InteractiveMap/InteractiveMap.js +3 -2
- package/src/InteractiveMap/InteractiveMap.test.js +2 -2
- package/src/config/events.js +1 -1
- package/src/config/mapPanelSlots.js +8 -0
- package/src/config/symbolConfig.js +1 -1
- package/src/scss/settings/_colors.scss +4 -0
- package/src/services/symbolRegistry.js +1 -1
- package/src/services/symbolRegistry.test.js +19 -0
- package/src/types.js +33 -8
- package/src/utils/getFitMove.js +73 -0
- package/src/utils/getFitMove.test.js +114 -0
- package/src/utils/getSafeZoneInset.js +122 -77
- package/src/utils/getSafeZoneInset.test.js +241 -54
- package/src/utils/getValueForStyle.js +10 -5
- package/src/utils/getValueForStyle.test.js +13 -2
- package/src/utils/renderedBoxes.js +25 -0
- package/src/utils/renderedBoxes.test.js +61 -0
- package/src/utils/screenBox.js +70 -0
- package/src/utils/screenBox.test.js +69 -0
- package/src/utils/symbolUtils.js +9 -9
- package/src/utils/symbolUtils.test.js +21 -0
- package/providers/esri/src/utils/spatial.test.js +0 -58
|
@@ -18,7 +18,7 @@ describe('Tooltip', () => {
|
|
|
18
18
|
getTooltipPosition.mockReturnValue('bottom')
|
|
19
19
|
|
|
20
20
|
const { container, unmount } = render(
|
|
21
|
-
<Tooltip
|
|
21
|
+
<Tooltip label='Test tooltip' {...props}>
|
|
22
22
|
<Child />
|
|
23
23
|
</Tooltip>
|
|
24
24
|
)
|
|
@@ -36,6 +36,48 @@ describe('Tooltip', () => {
|
|
|
36
36
|
afterEach(cleanup)
|
|
37
37
|
|
|
38
38
|
// --- Standard Tooltip tests ---
|
|
39
|
+
it('names the trigger with the label', () => {
|
|
40
|
+
const { button, tooltip } = renderTooltip()
|
|
41
|
+
expect(tooltip).toHaveTextContent('Test tooltip')
|
|
42
|
+
expect(button).toHaveAccessibleName('Test tooltip')
|
|
43
|
+
expect(button).not.toHaveAttribute('aria-describedby')
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('describes the trigger with the description, without naming it', () => {
|
|
47
|
+
const { button, tooltip } = renderTooltip({ label: undefined, description: 'More detail' })
|
|
48
|
+
expect(tooltip).toHaveTextContent('More detail')
|
|
49
|
+
expect(button).toHaveAccessibleName('Test button')
|
|
50
|
+
expect(button).toHaveAccessibleDescription('More detail')
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('shows the label and description together, reading each only once', () => {
|
|
54
|
+
const { button, tooltip } = renderTooltip({ description: 'More detail' })
|
|
55
|
+
expect(tooltip).toHaveTextContent('Test tooltip: More detail')
|
|
56
|
+
expect(button).toHaveAccessibleName('Test tooltip')
|
|
57
|
+
expect(button).toHaveAccessibleDescription('More detail')
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('keeps the trigger\'s own handlers', () => {
|
|
61
|
+
const handlers = {
|
|
62
|
+
onMouseEnter: jest.fn(),
|
|
63
|
+
onMouseLeave: jest.fn(),
|
|
64
|
+
onMouseDown: jest.fn(),
|
|
65
|
+
onKeyDown: jest.fn(),
|
|
66
|
+
onFocus: jest.fn(),
|
|
67
|
+
onBlur: jest.fn()
|
|
68
|
+
}
|
|
69
|
+
useApp.mockReturnValue({ interfaceType: 'keyboard' })
|
|
70
|
+
const { container } = render(<Tooltip label='Test tooltip'><Button {...handlers} /></Tooltip>)
|
|
71
|
+
const button = container.querySelector('button')
|
|
72
|
+
fireEvent.mouseEnter(button)
|
|
73
|
+
fireEvent.mouseLeave(button)
|
|
74
|
+
fireEvent.mouseDown(button)
|
|
75
|
+
fireEvent.keyDown(button, { key: 'ArrowDown' })
|
|
76
|
+
fireEvent.focus(button)
|
|
77
|
+
fireEvent.blur(button)
|
|
78
|
+
Object.values(handlers).forEach(handler => expect(handler).toHaveBeenCalledTimes(1))
|
|
79
|
+
})
|
|
80
|
+
|
|
39
81
|
it('renders with correct initial state', () => {
|
|
40
82
|
const { tooltip } = renderTooltip()
|
|
41
83
|
expect(tooltip).toHaveClass('im-c-tooltip--hidden')
|
|
@@ -111,7 +153,7 @@ describe('Tooltip', () => {
|
|
|
111
153
|
const fnRef = jest.fn()
|
|
112
154
|
|
|
113
155
|
render(
|
|
114
|
-
<Tooltip
|
|
156
|
+
<Tooltip label='Test tooltip'>
|
|
115
157
|
<ChildWithFunctionRef ref={fnRef} />
|
|
116
158
|
</Tooltip>
|
|
117
159
|
)
|
|
@@ -131,7 +173,7 @@ describe('Tooltip', () => {
|
|
|
131
173
|
const objRef = { current: null }
|
|
132
174
|
|
|
133
175
|
render(
|
|
134
|
-
<Tooltip
|
|
176
|
+
<Tooltip label='Test tooltip'>
|
|
135
177
|
<ChildWithObjectRef ref={objRef} />
|
|
136
178
|
</Tooltip>
|
|
137
179
|
)
|
|
@@ -3,6 +3,7 @@ import { useConfig } from '../../store/configContext'
|
|
|
3
3
|
import { useApp } from '../../store/appContext'
|
|
4
4
|
import { useMap } from '../../store/mapContext'
|
|
5
5
|
import { useMapStateSync } from '../../hooks/useMapStateSync'
|
|
6
|
+
import { useUserMoveTracking } from '../../hooks/useUserMoveTracking'
|
|
6
7
|
import { useMapURLSync } from '../../hooks/useMapURLSync'
|
|
7
8
|
import { useMapAnnouncements } from '../../hooks/useMapAnnouncements'
|
|
8
9
|
import { useMapProviderOverrides } from '../../hooks/useMapProviderOverrides'
|
|
@@ -53,6 +54,7 @@ export const MapController = ({ mapContainerRef }) => {
|
|
|
53
54
|
|
|
54
55
|
// Sync React state, handle URL persistence and announce to screen reader
|
|
55
56
|
useMapStateSync()
|
|
57
|
+
useUserMoveTracking()
|
|
56
58
|
useMapURLSync()
|
|
57
59
|
useMapAnnouncements()
|
|
58
60
|
|
|
@@ -5,6 +5,7 @@ import { useConfig } from '../../store/configContext'
|
|
|
5
5
|
import { useApp } from '../../store/appContext'
|
|
6
6
|
import { useMap } from '../../store/mapContext'
|
|
7
7
|
import { useMapStateSync } from '../../hooks/useMapStateSync'
|
|
8
|
+
import { useUserMoveTracking } from '../../hooks/useUserMoveTracking'
|
|
8
9
|
import { useMapURLSync } from '../../hooks/useMapURLSync'
|
|
9
10
|
import { useMapAnnouncements } from '../../hooks/useMapAnnouncements'
|
|
10
11
|
import { useMapProviderOverrides } from '../../hooks/useMapProviderOverrides'
|
|
@@ -15,6 +16,7 @@ jest.mock('../../store/configContext', () => ({ useConfig: jest.fn() }))
|
|
|
15
16
|
jest.mock('../../store/appContext', () => ({ useApp: jest.fn() }))
|
|
16
17
|
jest.mock('../../store/mapContext', () => ({ useMap: jest.fn() }))
|
|
17
18
|
jest.mock('../../hooks/useMapStateSync', () => ({ useMapStateSync: jest.fn() }))
|
|
19
|
+
jest.mock('../../hooks/useUserMoveTracking', () => ({ useUserMoveTracking: jest.fn() }))
|
|
18
20
|
jest.mock('../../hooks/useMapURLSync', () => ({ useMapURLSync: jest.fn() }))
|
|
19
21
|
jest.mock('../../hooks/useMapAnnouncements', () => ({ useMapAnnouncements: jest.fn() }))
|
|
20
22
|
jest.mock('../../hooks/useMapProviderOverrides', () => ({ useMapProviderOverrides: jest.fn() }))
|
|
@@ -91,6 +93,7 @@ describe('MapController', () => {
|
|
|
91
93
|
it('calls all map-related hooks', () => {
|
|
92
94
|
render(<MapController mapContainerRef={containerRef} />)
|
|
93
95
|
expect(useMapStateSync).toHaveBeenCalled()
|
|
96
|
+
expect(useUserMoveTracking).toHaveBeenCalled()
|
|
94
97
|
expect(useMapURLSync).toHaveBeenCalled()
|
|
95
98
|
expect(useMapAnnouncements).toHaveBeenCalled()
|
|
96
99
|
expect(useMapProviderOverrides).toHaveBeenCalled()
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useCallback, useEffect } from 'react'
|
|
1
|
+
import { useCallback, useEffect, useRef } from 'react'
|
|
2
2
|
import { useConfig } from '../store/configContext.js'
|
|
3
3
|
import { useApp } from '../store/appContext.js'
|
|
4
4
|
import { useMap } from '../store/mapContext.js'
|
|
@@ -6,15 +6,19 @@ import { useService } from '../store/serviceContext.js'
|
|
|
6
6
|
import { scaleFactor } from '../../config/appConfig.js'
|
|
7
7
|
import { EVENTS as events } from '../../config/events.js'
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
// crossHairHideHeldByMapControls is shared by every copy of the crossHair object, because each
|
|
10
|
+
// UPDATE_CROSS_HAIR replaces the object and a plugin can still call an older copy
|
|
11
|
+
const assignCrossHairAPI = (crossHair, el, mapProvider, dispatch, updatePosition, crossHairHideHeldByMapControls) => {
|
|
10
12
|
crossHair.pinToMap = (coords, state) => {
|
|
11
13
|
const { x, y } = mapProvider.mapToScreen(coords)
|
|
14
|
+
crossHairHideHeldByMapControls.isHideWaiting = false
|
|
12
15
|
crossHair.coords = coords
|
|
13
16
|
dispatch({ type: 'UPDATE_CROSS_HAIR', payload: { isPinnedToMap: true, isVisible: true, coords, state } })
|
|
14
17
|
updatePosition(el, x, y)
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
crossHair.fixAtCenter = () => {
|
|
21
|
+
crossHairHideHeldByMapControls.isHideWaiting = false
|
|
18
22
|
el.style.left = '50%'
|
|
19
23
|
el.style.top = '50%'
|
|
20
24
|
el.style.transform = 'translate(0,0)'
|
|
@@ -28,23 +32,21 @@ const assignCrossHairAPI = (crossHair, el, mapProvider, dispatch, updatePosition
|
|
|
28
32
|
}
|
|
29
33
|
|
|
30
34
|
crossHair.show = () => {
|
|
35
|
+
crossHairHideHeldByMapControls.isHideWaiting = false
|
|
31
36
|
el.style.display = 'block'
|
|
32
37
|
dispatch({ type: 'UPDATE_CROSS_HAIR', payload: { isVisible: true } })
|
|
33
38
|
}
|
|
34
39
|
|
|
35
|
-
//
|
|
36
|
-
//
|
|
37
|
-
//
|
|
38
|
-
//
|
|
39
|
-
// Control's real route back is opening MapControls (a normal, always-visible, always-named
|
|
40
|
-
// button) — see isMapControlsOpen below — so the crosshair itself doesn't need to stay
|
|
41
|
-
// discoverable while it's not actually there. Blocked outright while MapControls is open:
|
|
42
|
-
// that panel is a deliberate, explicit "I can't drag/pinch this map" signal from the user,
|
|
43
|
-
// which should win over whatever mouse-vs-touch/keyboard inference would otherwise decide.
|
|
40
|
+
// Hides the crosshair completely, so screen readers and Voice Control don't find a "Target"
|
|
41
|
+
// that isn't there. While the map controls are open the crosshair stays visible, because the
|
|
42
|
+
// user has asked for it. A hide asked for then is held back until the controls close, unless
|
|
43
|
+
// something shows the crosshair again first.
|
|
44
44
|
crossHair.hide = () => {
|
|
45
|
-
if (
|
|
45
|
+
if (crossHairHideHeldByMapControls.isMapControlsOpen) {
|
|
46
|
+
crossHairHideHeldByMapControls.isHideWaiting = true
|
|
46
47
|
return
|
|
47
48
|
}
|
|
49
|
+
crossHairHideHeldByMapControls.isHideWaiting = false
|
|
48
50
|
el.style.display = 'none'
|
|
49
51
|
dispatch({ type: 'UPDATE_CROSS_HAIR', payload: { isVisible: false } })
|
|
50
52
|
}
|
|
@@ -70,6 +72,7 @@ export const useCrossHair = () => {
|
|
|
70
72
|
const { safeZoneInset, expandedButtons } = useApp()
|
|
71
73
|
const { eventBus } = useService()
|
|
72
74
|
const { crossHair, dispatch, mapSize } = useMap()
|
|
75
|
+
const crossHairHideHeldByMapControlsRef = useRef({ isMapControlsOpen: false, isHideWaiting: false })
|
|
73
76
|
|
|
74
77
|
const updatePosition = (el, x, y) => {
|
|
75
78
|
if (!safeZoneInset) {
|
|
@@ -87,7 +90,7 @@ export const useCrossHair = () => {
|
|
|
87
90
|
return undefined
|
|
88
91
|
}
|
|
89
92
|
|
|
90
|
-
assignCrossHairAPI(crossHair, el, mapProvider, dispatch, updatePosition)
|
|
93
|
+
assignCrossHairAPI(crossHair, el, mapProvider, dispatch, updatePosition, crossHairHideHeldByMapControlsRef.current)
|
|
91
94
|
|
|
92
95
|
const handleRender = () => {
|
|
93
96
|
if (crossHair.coords && crossHair.isPinnedToMap) {
|
|
@@ -110,21 +113,17 @@ export const useCrossHair = () => {
|
|
|
110
113
|
}
|
|
111
114
|
}, [mapSize])
|
|
112
115
|
|
|
113
|
-
//
|
|
114
|
-
//
|
|
115
|
-
//
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
// read the stale value and incorrectly block itself. Setting it directly in the render body
|
|
125
|
-
// (matches DrawInit.jsx's shouldShowCrosshairRef convention) guarantees it's current before
|
|
126
|
-
// ANY component's effects run, since React finishes rendering the whole tree first.
|
|
127
|
-
crossHair.isMapControlsOpen = expandedButtons?.has('mapControls')
|
|
116
|
+
// Tells hide() whether the map controls are open. It's set while rendering so it's up to date
|
|
117
|
+
// as soon as possible, but a plugin can still call hide() before this component re-renders. So
|
|
118
|
+
// when the controls close, carry out any hide that was held back.
|
|
119
|
+
const isMapControlsOpen = !!expandedButtons?.has('mapControls')
|
|
120
|
+
crossHairHideHeldByMapControlsRef.current.isMapControlsOpen = isMapControlsOpen
|
|
121
|
+
|
|
122
|
+
useEffect(() => {
|
|
123
|
+
if (!isMapControlsOpen && crossHairHideHeldByMapControlsRef.current.isHideWaiting) {
|
|
124
|
+
crossHair.hide()
|
|
125
|
+
}
|
|
126
|
+
}, [isMapControlsOpen])
|
|
128
127
|
|
|
129
128
|
return {
|
|
130
129
|
crossHair,
|
|
@@ -98,20 +98,77 @@ describe('useCrossHair', () => {
|
|
|
98
98
|
expect(mockElement.style.display).toBe('none')
|
|
99
99
|
})
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
const withMapControls = (isOpen) => useApp.mockReturnValue({
|
|
102
|
+
safeZoneInset: { left: 10, top: 20 },
|
|
103
|
+
expandedButtons: new Set(isOpen ? ['mapControls'] : [])
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
it('holds back hide() while the map controls are open', () => {
|
|
107
|
+
withMapControls(true)
|
|
102
108
|
setup()
|
|
103
109
|
act(() => mockCrossHair.show())
|
|
104
|
-
mockCrossHair.isMapControlsOpen = true
|
|
105
|
-
|
|
106
110
|
act(() => mockCrossHair.hide())
|
|
107
111
|
expect(mockElement.style.display).toBe('block')
|
|
108
112
|
expect(mockDispatch).not.toHaveBeenCalledWith({ type: 'UPDATE_CROSS_HAIR', payload: { isVisible: false } })
|
|
109
113
|
})
|
|
110
114
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
+
// UPDATE_CROSS_HAIR replaces the crossHair object, and a plugin can still call an older copy
|
|
116
|
+
// (draw's effect cleanup does)
|
|
117
|
+
const replaceCrossHair = (hook) => {
|
|
118
|
+
const olderCopy = mockCrossHair
|
|
119
|
+
mockCrossHair = { ...mockCrossHair }
|
|
120
|
+
useMap.mockReturnValue({ crossHair: mockCrossHair, dispatch: mockDispatch, mapSize: 'medium' })
|
|
121
|
+
hook.rerender()
|
|
122
|
+
act(() => hook.result.current.crossHairRef(mockElement))
|
|
123
|
+
return olderCopy
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
it('hides when an older copy calls hide() after the map controls close', () => {
|
|
127
|
+
withMapControls(true)
|
|
128
|
+
const hook = setup()
|
|
129
|
+
act(() => mockCrossHair.show())
|
|
130
|
+
const olderCopy = replaceCrossHair(hook)
|
|
131
|
+
withMapControls(false)
|
|
132
|
+
hook.rerender()
|
|
133
|
+
act(() => olderCopy.hide())
|
|
134
|
+
expect(mockElement.style.display).toBe('none')
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
it('carries out a hide() held back on an older copy once the map controls close', () => {
|
|
138
|
+
withMapControls(true)
|
|
139
|
+
const hook = setup()
|
|
140
|
+
act(() => mockCrossHair.show())
|
|
141
|
+
const olderCopy = replaceCrossHair(hook)
|
|
142
|
+
act(() => olderCopy.hide())
|
|
143
|
+
expect(mockElement.style.display).toBe('block')
|
|
144
|
+
withMapControls(false)
|
|
145
|
+
hook.rerender()
|
|
146
|
+
expect(mockElement.style.display).toBe('none')
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
// A plugin's updateCrossHair effect can run before this hook re-renders, so its hide() is
|
|
150
|
+
// held back as the map controls close.
|
|
151
|
+
const closeMapControlsAfterBlockedHide = ({ showInBetween } = {}) => {
|
|
152
|
+
withMapControls(true)
|
|
153
|
+
const hook = setup()
|
|
154
|
+
act(() => mockCrossHair.show())
|
|
155
|
+
act(() => mockCrossHair.hide())
|
|
156
|
+
if (showInBetween) {
|
|
157
|
+
act(() => mockCrossHair.fixAtCenter())
|
|
158
|
+
}
|
|
159
|
+
withMapControls(false)
|
|
160
|
+
hook.rerender()
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
it('carries out a hide() blocked by MapControls once it closes', () => {
|
|
164
|
+
closeMapControlsAfterBlockedHide()
|
|
165
|
+
expect(mockElement.style.display).toBe('none')
|
|
166
|
+
expect(mockDispatch).toHaveBeenLastCalledWith({ type: 'UPDATE_CROSS_HAIR', payload: { isVisible: false } })
|
|
167
|
+
})
|
|
168
|
+
|
|
169
|
+
it('drops a blocked hide() when the crosshair is shown again before MapControls closes', () => {
|
|
170
|
+
closeMapControlsAfterBlockedHide({ showInBetween: true })
|
|
171
|
+
expect(mockElement.style.display).toBe('block')
|
|
115
172
|
})
|
|
116
173
|
|
|
117
174
|
it('setStyle updates state', () => {
|