@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.
Files changed (125) hide show
  1. package/assets/templates/add-polygons.njk +2 -2
  2. package/assets/templates/add-symbols.njk +2 -2
  3. package/dist/css/index.css +1 -1
  4. package/dist/esm/im-core.js +1 -1
  5. package/dist/esm/im-shell.js +1 -1
  6. package/dist/umd/im-core.js +1 -1
  7. package/dist/umd/index.js +1 -1
  8. package/docs/api/button-definition.md +11 -0
  9. package/docs/api/context.md +2 -0
  10. package/docs/api/panel-definition.md +30 -0
  11. package/docs/api/symbol-config.md +12 -0
  12. package/docs/api.md +21 -2
  13. package/docs/assets/images/slot-map.svg +3 -3
  14. package/docs/plugins/datasets.md +11 -1
  15. package/docs/plugins/draw.md +26 -0
  16. package/package.json +1 -1
  17. package/plugins/datasets/dist/esm/index.js +1 -1
  18. package/plugins/datasets/dist/esm/layerAdapter.js +1 -1
  19. package/plugins/datasets/dist/umd/im-datasets-ml-adapter.js +1 -1
  20. package/plugins/datasets/dist/umd/im-datasets-ol-adapter.js +1 -1
  21. package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
  22. package/plugins/datasets/dist/umd/index.js +1 -1
  23. package/plugins/datasets/src/index.js +0 -1
  24. package/plugins/datasets/src/index.test.js +2 -8
  25. package/plugins/datasets/src/registry/dataset.test.js +9 -0
  26. package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
  27. package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
  28. package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
  29. package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
  30. package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
  31. package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
  32. package/plugins/draw/dist/umd/index.js +1 -1
  33. package/plugins/draw/src/DrawInit.jsx +3 -0
  34. package/plugins/draw/src/DrawInit.test.jsx +16 -0
  35. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +19 -3
  36. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +27 -0
  37. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +10 -2
  38. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +14 -0
  39. package/plugins/draw/src/defaults.js +4 -0
  40. package/plugins/draw/src/hooks/useSnapMinZoom.js +29 -0
  41. package/plugins/draw/src/hooks/useSnapMinZoom.test.js +82 -0
  42. package/plugins/draw/src/manifest.js +4 -1
  43. package/plugins/draw/src/manifest.test.js +15 -2
  44. package/plugins/draw/src/utils/snapMinZoom.js +8 -0
  45. package/plugins/draw/src/utils/snapMinZoom.test.js +22 -0
  46. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  47. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  48. package/plugins/map-key/dist/esm/im-map-key-plugin.js +1 -1
  49. package/plugins/map-key/dist/umd/im-map-key-plugin.js +1 -1
  50. package/plugins/map-key/src/manifest.js +1 -1
  51. package/plugins/search/dist/css/index.css +1 -1
  52. package/plugins/search/src/components/Form/Form.module.scss +1 -0
  53. package/providers/esri/dist/esm/im-esri-provider.js +1 -1
  54. package/providers/esri/src/esriProvider.js +10 -21
  55. package/providers/esri/src/utils/coords.js +37 -7
  56. package/providers/esri/src/utils/coords.test.js +22 -1
  57. package/providers/esri/src/utils/spatial.js +1 -47
  58. package/providers/maplibre/dist/esm/im-maplibre-provider.js +1 -1
  59. package/providers/maplibre/dist/umd/im-maplibre-provider.js +1 -1
  60. package/providers/maplibre/src/maplibreProvider.js +5 -14
  61. package/providers/maplibre/src/maplibreProvider.test.js +143 -146
  62. package/providers/maplibre/src/utils/spatial.js +0 -40
  63. package/providers/maplibre/src/utils/spatial.test.js +0 -35
  64. package/providers/openlayers/dist/esm/im-openlayers-provider.js +1 -1
  65. package/providers/openlayers/dist/umd/im-openlayers-provider.js +1 -1
  66. package/providers/openlayers/src/openlayersProvider.js +5 -14
  67. package/providers/openlayers/src/openlayersProvider.test.js +12 -10
  68. package/providers/openlayers/src/utils/spatial.js +0 -39
  69. package/providers/openlayers/src/utils/spatial.test.js +1 -26
  70. package/src/App/components/Hints/Hints.jsx +9 -21
  71. package/src/App/components/Hints/Hints.test.jsx +20 -33
  72. package/src/App/components/MapButton/MapButton.jsx +20 -2
  73. package/src/App/components/MapButton/MapButton.module.scss +15 -1
  74. package/src/App/components/MapButton/MapButton.test.jsx +21 -3
  75. package/src/App/components/Panel/Panel.jsx +16 -1
  76. package/src/App/components/Panel/Panel.test.jsx +44 -0
  77. package/src/App/components/Tooltip/Tooltip.jsx +29 -11
  78. package/src/App/components/Tooltip/Tooltip.test.jsx +45 -3
  79. package/src/App/components/Viewport/MapController.jsx +2 -0
  80. package/src/App/components/Viewport/MapController.test.jsx +3 -0
  81. package/src/App/hooks/useCrossHairAPI.js +27 -28
  82. package/src/App/hooks/useCrossHairAPI.test.js +64 -7
  83. package/src/App/hooks/useLayoutMeasurements.js +175 -131
  84. package/src/App/hooks/useLayoutMeasurements.test.js +227 -122
  85. package/src/App/hooks/useMapProviderOverrides.js +114 -35
  86. package/src/App/hooks/useMapProviderOverrides.test.js +188 -5
  87. package/src/App/hooks/useModalPanelBehaviour.js +18 -32
  88. package/src/App/hooks/useModalPanelBehaviour.test.js +45 -33
  89. package/src/App/hooks/useUserMoveTracking.js +65 -0
  90. package/src/App/hooks/useUserMoveTracking.test.js +99 -0
  91. package/src/App/hooks/useVisibleGeometry.js +35 -45
  92. package/src/App/hooks/useVisibleGeometry.test.js +149 -121
  93. package/src/App/layout/Layout.jsx +4 -4
  94. package/src/App/layout/layout.module.scss +124 -61
  95. package/src/App/renderer/mapButtons.js +1 -0
  96. package/src/App/renderer/mapButtons.test.js +8 -0
  97. package/src/App/store/AppProvider.jsx +3 -0
  98. package/src/App/store/appDispatchMiddleware.js +18 -10
  99. package/src/App/store/appDispatchMiddleware.test.js +42 -4
  100. package/src/App/store/mapActionsMap.js +2 -1
  101. package/src/App/store/mapActionsMap.test.js +6 -0
  102. package/src/App/store/mapReducer.js +2 -0
  103. package/src/App/store/mapReducer.test.js +1 -0
  104. package/src/InteractiveMap/InteractiveMap.js +3 -2
  105. package/src/InteractiveMap/InteractiveMap.test.js +2 -2
  106. package/src/config/events.js +1 -1
  107. package/src/config/mapPanelSlots.js +8 -0
  108. package/src/config/symbolConfig.js +1 -1
  109. package/src/scss/settings/_colors.scss +4 -0
  110. package/src/services/symbolRegistry.js +1 -1
  111. package/src/services/symbolRegistry.test.js +19 -0
  112. package/src/types.js +33 -8
  113. package/src/utils/getFitMove.js +73 -0
  114. package/src/utils/getFitMove.test.js +114 -0
  115. package/src/utils/getSafeZoneInset.js +122 -77
  116. package/src/utils/getSafeZoneInset.test.js +241 -54
  117. package/src/utils/getValueForStyle.js +10 -5
  118. package/src/utils/getValueForStyle.test.js +13 -2
  119. package/src/utils/renderedBoxes.js +25 -0
  120. package/src/utils/renderedBoxes.test.js +61 -0
  121. package/src/utils/screenBox.js +70 -0
  122. package/src/utils/screenBox.test.js +69 -0
  123. package/src/utils/symbolUtils.js +9 -9
  124. package/src/utils/symbolUtils.test.js +21 -0
  125. 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 content='Test tooltip' {...props}>
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 content='Test 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 content='Test 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
- const assignCrossHairAPI = (crossHair, el, mapProvider, dispatch, updatePosition) => {
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
- // Fully hidden — display:none, not just faded — rather than staying in the accessibility
36
- // tree while invisible. An earlier version kept it ax-tree-present here so Voice Control
37
- // could re-summon it by name, but that made "Show Names" put a "Target" label over
38
- // nothing whenever it was genuinely hidden, which is more confusing than helpful. Voice
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 (crossHair.isMapControlsOpen) {
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
- // A plain property on the shared crossHair object, not dispatched state — every owner
114
- // (draw's per-adapter modes, interact's useCrossHairVisibility) already holds this same
115
- // object, so mutating it here is all that's needed for hide()'s own guard above to see the
116
- // current value live, however long ago it was last set. This alone never shows or hides
117
- // anything by itself — it only ever blocks a hide() call already in flight — so it's safe to
118
- // run unconditionally even when no plugin that cares about it is loaded at all.
119
- //
120
- // Deliberately NOT a useEffect: this component's own effects and interact's/draw's own
121
- // updateCrossHair effects both react to the same expandedButtons change, and React gives no
122
- // ordering guarantee between two different components' effects — if the consumer's effect
123
- // (which decides to call hide()) ran before this one updated the flag, hide()'s guard would
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
- it('hide() is a no-op while isMapControlsOpen is set', () => {
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
- it('keeps crossHair.isMapControlsOpen synced with expandedButtons, set synchronously during render (not a useEffect) so it is never stale relative to another component\'s own effect reacting to the same change', () => {
112
- useApp.mockReturnValue({ safeZoneInset: { left: 10, top: 20 }, expandedButtons: new Set(['mapControls']) })
113
- setup()
114
- expect(mockCrossHair.isMapControlsOpen).toBe(true)
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', () => {