@defra/interactive-map 0.0.56-alpha → 0.0.58-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 (138) hide show
  1. package/dist/esm/im-core.js +1 -1
  2. package/dist/umd/im-core.js +1 -1
  3. package/dist/umd/index.js +1 -1
  4. package/docs/api/button-definition.md +11 -0
  5. package/docs/api/context.md +2 -0
  6. package/docs/api.md +3 -1
  7. package/docs/assets/css/docusaurus.scss +7 -1
  8. package/docs/plugins/draw.md +326 -121
  9. package/package.json +1 -1
  10. package/plugins/datasets/dist/esm/im-datasets-plugin.js +1 -1
  11. package/plugins/datasets/dist/umd/im-datasets-plugin.js +1 -1
  12. package/plugins/datasets/dist/umd/index.js +1 -1
  13. package/plugins/datasets/src/initialise/DatasetsInit.jsx +6 -17
  14. package/plugins/datasets/src/initialise/DatasetsInit.test.jsx +3 -43
  15. package/plugins/draw/dist/esm/im-draw-ml-adapter.js +1 -1
  16. package/plugins/draw/dist/esm/im-draw-ol-adapter.js +1 -1
  17. package/plugins/draw/dist/esm/im-draw-plugin.js +1 -1
  18. package/plugins/draw/dist/esm/index.js +1 -1
  19. package/plugins/draw/dist/esm/liveDrawChecks.js +1 -1
  20. package/plugins/draw/dist/umd/im-draw-ml-adapter.js +1 -1
  21. package/plugins/draw/dist/umd/im-draw-ol-adapter.js +1 -1
  22. package/plugins/draw/dist/umd/im-draw-plugin.js +1 -1
  23. package/plugins/draw/dist/umd/index.js +1 -1
  24. package/plugins/draw/src/DrawInit.jsx +9 -6
  25. package/plugins/draw/src/DrawInit.test.jsx +15 -0
  26. package/plugins/draw/src/adapterEvents.js +82 -44
  27. package/plugins/draw/src/adapters/adapterContract.test.js +3 -3
  28. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +18 -10
  29. package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +31 -22
  30. package/plugins/draw/src/adapters/maplibre/drawEvents.js +2 -1
  31. package/plugins/draw/src/adapters/maplibre/modes/drawMode/clickHandlers.js +13 -12
  32. package/plugins/draw/src/adapters/maplibre/modes/drawMode/clickHandlers.test.js +5 -5
  33. package/plugins/draw/src/adapters/maplibre/modes/drawMode/undoHandlers.js +1 -1
  34. package/plugins/draw/src/adapters/maplibre/modes/drawMode/undoHandlers.test.js +2 -2
  35. package/plugins/draw/src/adapters/maplibre/modes/drawPointMode.js +6 -9
  36. package/plugins/draw/src/adapters/maplibre/modes/drawPointMode.test.js +4 -4
  37. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.js +6 -9
  38. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.test.js +1 -1
  39. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/undoHandlers.js +8 -14
  40. package/plugins/draw/src/adapters/maplibre/modes/editPointMode/undoHandlers.test.js +37 -8
  41. package/plugins/draw/src/adapters/maplibre/modes/editPointMode.js +11 -1
  42. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/undoHandlers.js +14 -19
  43. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/undoHandlers.test.js +41 -4
  44. package/plugins/draw/src/adapters/maplibre/modes/editVertexMode.js +12 -1
  45. package/plugins/draw/src/adapters/maplibre/utils/editModeEvents.js +3 -1
  46. package/plugins/draw/src/adapters/maplibre/utils/geometryValidation.js +9 -10
  47. package/plugins/draw/src/adapters/maplibre/utils/geometryValidation.test.js +5 -24
  48. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +10 -7
  49. package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +12 -7
  50. package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.js +5 -0
  51. package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.test.js +7 -3
  52. package/plugins/draw/src/adapters/openlayers/draw/DrawMode.js +11 -11
  53. package/plugins/draw/src/adapters/openlayers/draw/DrawMode.test.js +15 -15
  54. package/plugins/draw/src/adapters/openlayers/edit/EditMode.js +21 -28
  55. package/plugins/draw/src/adapters/openlayers/edit/EditMode.test.js +26 -5
  56. package/plugins/draw/src/adapters/openlayers/edit/selectionState.js +5 -6
  57. package/plugins/draw/src/adapters/openlayers/edit/selectionState.test.js +2 -12
  58. package/plugins/draw/src/adapters/openlayers/edit/undoOps.js +9 -0
  59. package/plugins/draw/src/adapters/openlayers/edit/undoOps.test.js +7 -0
  60. package/plugins/draw/src/adapters/openlayers/point/drawPointMode.js +6 -9
  61. package/plugins/draw/src/adapters/openlayers/point/drawPointMode.test.js +3 -3
  62. package/plugins/draw/src/adapters/openlayers/point/editPointMode.js +18 -9
  63. package/plugins/draw/src/adapters/openlayers/point/editPointMode.test.js +29 -4
  64. package/plugins/draw/src/adapters/openlayers/point/pointOps.js +3 -2
  65. package/plugins/draw/src/adapters/openlayers/point/pointOps.test.js +6 -0
  66. package/plugins/draw/src/adapters/openlayers/point/pointSelectionState.js +3 -4
  67. package/plugins/draw/src/adapters/openlayers/point/pointSelectionState.test.js +2 -12
  68. package/plugins/draw/src/api/createNewShape.js +4 -4
  69. package/plugins/draw/src/api/createNewShape.test.js +1 -1
  70. package/plugins/draw/src/api/editFeature.js +8 -11
  71. package/plugins/draw/src/api/editFeature.test.js +33 -22
  72. package/plugins/draw/src/api/newLine.test.js +3 -3
  73. package/plugins/draw/src/api/newPoint.js +4 -5
  74. package/plugins/draw/src/api/newPoint.test.js +11 -3
  75. package/plugins/draw/src/api/newPolygon.test.js +11 -3
  76. package/plugins/draw/src/api/recheckGeometry.js +32 -0
  77. package/plugins/draw/src/api/recheckGeometry.test.js +55 -0
  78. package/plugins/draw/src/api/setGeometry.js +33 -0
  79. package/plugins/draw/src/api/setGeometry.test.js +48 -0
  80. package/plugins/draw/src/api/split.js +26 -22
  81. package/plugins/draw/src/api/split.test.js +38 -18
  82. package/plugins/draw/src/events.js +269 -77
  83. package/plugins/draw/src/events.test.js +779 -34
  84. package/plugins/draw/src/hooks/useSpatialList.js +10 -11
  85. package/plugins/draw/src/hooks/useSpatialList.test.js +3 -3
  86. package/plugins/draw/src/manifest.js +30 -15
  87. package/plugins/draw/src/manifest.test.js +91 -9
  88. package/plugins/draw/src/reducer.js +31 -9
  89. package/plugins/draw/src/reducer.test.js +35 -3
  90. package/plugins/draw/src/utils/drawModes.js +27 -0
  91. package/plugins/draw/src/utils/drawModes.test.js +27 -0
  92. package/plugins/draw/src/utils/needsDrawTarget.js +1 -5
  93. package/plugins/draw/src/utils/needsDrawTarget.test.js +1 -11
  94. package/plugins/draw/src/utils/touchTarget.js +34 -26
  95. package/plugins/draw/src/utils/touchTarget.test.js +32 -20
  96. package/plugins/draw/src/validation/commitChecks.js +187 -0
  97. package/plugins/draw/src/validation/commitChecks.test.js +209 -0
  98. package/plugins/draw/src/validation/liveDrawChecks.js +11 -11
  99. package/plugins/draw/src/validation/liveDrawChecks.test.js +37 -37
  100. package/plugins/draw/src/validation/liveStroke.js +6 -6
  101. package/plugins/draw/src/validation/liveStroke.test.js +27 -27
  102. package/plugins/draw/src/validation/rules.js +16 -14
  103. package/plugins/draw/src/validation/rules.test.js +5 -5
  104. package/plugins/draw/src/validation/validateGeometry.js +58 -31
  105. package/plugins/draw/src/validation/validateGeometry.test.js +68 -44
  106. package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
  107. package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
  108. package/plugins/interact/dist/umd/index.js +1 -1
  109. package/plugins/interact/src/hooks/useInteractionHandlers.js +3 -5
  110. package/plugins/interact/src/hooks/useInteractionHandlers.test.js +4 -3
  111. package/plugins/interact/src/hooks/useSpatialList.js +16 -17
  112. package/plugins/interact/src/hooks/useSpatialList.test.js +9 -9
  113. package/plugins/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
  114. package/plugins/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
  115. package/plugins/map-styles/src/MapStyles.jsx +2 -2
  116. package/providers/maplibre/dist/esm/index.js +1 -1
  117. package/providers/maplibre/dist/umd/index.js +1 -1
  118. package/providers/maplibre/src/index.js +11 -2
  119. package/providers/maplibre/src/index.test.js +23 -1
  120. package/providers/maplibre/src/utils/detectModuleWorker.js +8 -19
  121. package/providers/maplibre/src/utils/detectModuleWorker.test.js +19 -23
  122. package/providers/maplibre/src/utils/workerUrl.js +12 -0
  123. package/providers/maplibre/src/utils/workerUrl.test.js +14 -1
  124. package/src/App/components/MapButton/MapButton.jsx +6 -0
  125. package/src/App/components/MapButton/MapButton.test.jsx +10 -0
  126. package/src/App/components/Markers/Markers.jsx +3 -5
  127. package/src/App/components/Markers/Markers.test.jsx +9 -11
  128. package/src/App/components/Panel/Panel.jsx +2 -9
  129. package/src/App/hooks/useInterfaceAPI.js +16 -4
  130. package/src/App/hooks/useInterfaceAPI.test.js +66 -1
  131. package/src/App/renderer/mapButtons.js +2 -1
  132. package/src/App/renderer/mapButtons.test.js +9 -0
  133. package/src/App/store/MapProvider.jsx +3 -0
  134. package/src/App/store/MapProvider.test.jsx +24 -0
  135. package/src/config/mapSizeScales.js +3 -0
  136. package/src/types.js +4 -0
  137. package/src/utils/focusAfterPanelClose.js +9 -0
  138. package/src/utils/focusAfterPanelClose.test.js +40 -0
@@ -1,5 +1,6 @@
1
1
  import { splitPolygon } from '../utils/spatial.js'
2
- import { ADAPTER_EVENTS } from '../adapterEvents.js'
2
+ import { ADAPTER_EVENTS, CHANGE_PHASE } from '../adapterEvents.js'
3
+ import { getCommitChecks } from '../validation/commitChecks.js'
3
4
 
4
5
  const INVALID_REASON = 'Line does not split the shape into two parts'
5
6
  const MIN_LINE_VERTICES = 2
@@ -21,29 +22,25 @@ const applySplitPreview = ({ draw, polygonFeature, feature }) => {
21
22
  return isValid
22
23
  }
23
24
 
24
- // Colours the preview and gates Done/the finish gesture for a committed vertex.
25
+ // Colours the preview for a committed vertex and records whether the split is valid.
26
+ // Its returned verdict gates Done and the finish gesture (events.js).
25
27
  const applySplitCommit = ({ draw, dispatch, polygonFeature, feature }) => {
26
28
  const isValid = applySplitPreview({ draw, polygonFeature, feature })
27
29
  dispatch({ type: 'SET_ACTION', payload: { name: 'split', isValid } })
28
- dispatch({ type: 'SET_GEOMETRY_VALID', payload: isValid })
29
- draw.setGeometryValid(isValid)
30
30
  return isValid
31
31
  }
32
32
 
33
- // Installed as draw._geometryValidator. 'place' and 'create' are no-ops — a split
34
- // isn't complete until its last vertex, so checking those would block placement
35
- // and hijack an early finish into edit mode.
36
- const createSplitValidator = ({ draw, dispatch, polygonFeature }) => ({ feature, phase }) => {
37
- let isValid
38
- if (phase === 'preview') {
39
- isValid = applySplitPreview({ draw, polygonFeature, feature })
40
- } else if (phase?.startsWith('commit-')) {
41
- isValid = applySplitCommit({ draw, dispatch, polygonFeature, feature })
42
- } else {
43
- return { valid: true }
44
- }
45
- return isValid ? { valid: true } : { valid: false, reason: INVALID_REASON }
46
- }
33
+ const toResult = (isValid) => (isValid ? { valid: true } : { valid: false, reason: INVALID_REASON })
34
+
35
+ // Installed as draw._previewValidator. 'place' is a no-op — a split isn't complete
36
+ // until its last vertex, so checking it would block placement.
37
+ const createSplitPreviewValidator = ({ draw, polygonFeature }) => ({ feature, phase }) =>
38
+ phase === 'preview' ? toResult(applySplitPreview({ draw, polygonFeature, feature })) : { valid: true }
39
+
40
+ // Installed as draw._commitValidator. 'create' is a no-op — checking it would
41
+ // hijack an early finish into edit mode.
42
+ const createSplitCommitValidator = ({ draw, dispatch, polygonFeature }) => ({ feature, phase }) =>
43
+ phase === CHANGE_PHASE ? toResult(applySplitCommit({ draw, dispatch, polygonFeature, feature })) : { valid: true }
47
44
 
48
45
  /**
49
46
  * Start drawing a split line for a polygon.
@@ -63,9 +60,14 @@ export const split = ({ appState, appConfig, pluginState, mapState, mapProvider,
63
60
 
64
61
  const polygonFeature = draw.get(featureId)
65
62
 
66
- // Swap in split's own rule; restored in stopListening.
67
- const previousValidator = draw._geometryValidator
68
- draw._geometryValidator = createSplitValidator({ draw, dispatch, polygonFeature })
63
+ // Swap in split's own rules; restored in stopListening.
64
+ const previousPreviewValidator = draw._previewValidator
65
+ const previousValidator = draw._commitValidator
66
+ const previousFinishValidator = draw._finishValidator
67
+ draw._previewValidator = createSplitPreviewValidator({ draw, polygonFeature })
68
+ draw._commitValidator = createSplitCommitValidator({ draw, dispatch, polygonFeature })
69
+ draw._finishValidator = null
70
+ getCommitChecks(draw).reset()
69
71
 
70
72
  // Always include the draw outline layer so the split line snaps to it
71
73
  const snapLayers = ['stroke-inactive.cold', ...(options.snapLayers || [])]
@@ -84,7 +86,9 @@ export const split = ({ appState, appConfig, pluginState, mapState, mapProvider,
84
86
 
85
87
  // Unregister everything scoped to this session.
86
88
  const stopListening = () => {
87
- draw._geometryValidator = previousValidator
89
+ draw._previewValidator = previousPreviewValidator
90
+ draw._commitValidator = previousValidator
91
+ draw._finishValidator = previousFinishValidator
88
92
  draw.off(ADAPTER_EVENTS.CREATE, onSplitCreate)
89
93
  draw.off(ADAPTER_EVENTS.CANCEL, onSplitCancel)
90
94
  }
@@ -13,7 +13,7 @@ const makeContext = (overrides = {}) => {
13
13
  on: jest.fn(),
14
14
  off: jest.fn(),
15
15
  isSnapEnabled: jest.fn(() => true),
16
- setGeometryValid: jest.fn(),
16
+ setCanFinish: jest.fn(),
17
17
  setDrawingPreviewProperty: jest.fn(),
18
18
  delete: jest.fn()
19
19
  }
@@ -47,7 +47,8 @@ describe('split', () => {
47
47
 
48
48
  split(context, 'poly')
49
49
 
50
- expect(typeof draw._geometryValidator).toBe('function')
50
+ expect(typeof draw._previewValidator).toBe('function')
51
+ expect(typeof draw._commitValidator).toBe('function')
51
52
  expect(draw.setSnapLayers).toHaveBeenCalledWith(['stroke-inactive.cold'])
52
53
  expect(dispatch).toHaveBeenCalledWith({ type: 'SET_HAS_SNAP_LAYERS', payload: true })
53
54
  expect(draw.changeMode).toHaveBeenCalledWith('draw_line', expect.objectContaining({
@@ -72,16 +73,22 @@ describe('split', () => {
72
73
  expect(draw.setSnapLayers).toHaveBeenCalledWith(['stroke-inactive.cold', 'extra'])
73
74
  })
74
75
 
75
- test('finalising the line computes a valid split, emits the result, and restores the previous validator', () => {
76
+ test('finalising the line computes a valid split, emits the result, and restores the previous validators', () => {
76
77
  const { context, dispatch, draw, eventBus } = makeContext()
77
78
  const polygonFeature = { id: 'poly' }
78
79
  const featureCollection = { type: 'FeatureCollection' }
79
80
  const previousValidator = jest.fn()
80
- draw._geometryValidator = previousValidator
81
+ const previousPreviewValidator = jest.fn()
82
+ const previousFinishValidator = jest.fn()
83
+ draw._commitValidator = previousValidator
84
+ draw._previewValidator = previousPreviewValidator
85
+ draw._finishValidator = previousFinishValidator
81
86
  draw.get.mockReturnValue(polygonFeature)
82
87
  splitPolygon.mockReturnValue(featureCollection)
83
88
 
84
89
  split(context, 'poly')
90
+ // The split line is never passed to the consumer's onGeometryFinish
91
+ expect(draw._finishValidator).toBeNull()
85
92
  const onCreate = handlerFor(draw, 'create')
86
93
  const geojson = { id: 'line' }
87
94
  onCreate(geojson)
@@ -91,7 +98,9 @@ describe('split', () => {
91
98
  expect(splitPolygon).toHaveBeenCalledWith(polygonFeature, geojson)
92
99
  expect(dispatch).toHaveBeenCalledWith({ type: 'SET_ACTION', payload: { name: 'split', isValid: true } })
93
100
  expect(eventBus.emit).toHaveBeenCalledWith('draw:split', { originalFeatureId: 'poly', featureCollection })
94
- expect(draw._geometryValidator).toBe(previousValidator)
101
+ expect(draw._commitValidator).toBe(previousValidator)
102
+ expect(draw._previewValidator).toBe(previousPreviewValidator)
103
+ expect(draw._finishValidator).toBe(previousFinishValidator)
95
104
  // The splitter line only ever existed to compute the split — it must not
96
105
  // linger in the draw store afterwards.
97
106
  expect(draw.delete).toHaveBeenCalledWith('_splitter')
@@ -100,7 +109,7 @@ describe('split', () => {
100
109
  test('cancelling the splitter line stops listening and restores the previous validator', () => {
101
110
  const { context, draw } = makeContext()
102
111
  const previousValidator = jest.fn()
103
- draw._geometryValidator = previousValidator
112
+ draw._commitValidator = previousValidator
104
113
 
105
114
  split(context, 'poly')
106
115
  const onCancel = handlerFor(draw, 'cancel')
@@ -109,7 +118,7 @@ describe('split', () => {
109
118
  expect(draw.off).toHaveBeenCalledWith('create', expect.any(Function))
110
119
  expect(draw.off).toHaveBeenCalledWith('cancel', onCancel)
111
120
  expect(splitPolygon).not.toHaveBeenCalled()
112
- expect(draw._geometryValidator).toBe(previousValidator)
121
+ expect(draw._commitValidator).toBe(previousValidator)
113
122
  })
114
123
 
115
124
  test('finalising the line computes an invalid split and does not emit', () => {
@@ -124,13 +133,13 @@ describe('split', () => {
124
133
  expect(draw.delete).toHaveBeenCalledWith('_splitter')
125
134
  })
126
135
 
127
- describe('the installed draw._geometryValidator', () => {
136
+ describe('the installed validators', () => {
128
137
  test('never blocks a hard placement veto (phase: place)', () => {
129
138
  const { context, dispatch, draw } = makeContext()
130
139
  split(context, 'poly')
131
140
  dispatch.mockClear()
132
141
 
133
- const result = draw._geometryValidator({ feature: lineFeature([[0, 0], [1, 1]]), phase: 'place', mode: 'draw_line', vertexIndex: 1 })
142
+ const result = draw._previewValidator({ feature: lineFeature([[0, 0], [1, 1]]), phase: 'place', mode: 'draw_line', vertexIndex: 1 })
134
143
 
135
144
  expect(result).toEqual({ valid: true })
136
145
  expect(splitPolygon).not.toHaveBeenCalled()
@@ -143,7 +152,7 @@ describe('split', () => {
143
152
  split(context, 'poly')
144
153
  dispatch.mockClear()
145
154
 
146
- const result = draw._geometryValidator({ feature: lineFeature([[0, 0], [1, 1]]), phase: 'create', mode: 'draw_line' })
155
+ const result = draw._commitValidator({ feature: lineFeature([[0, 0], [1, 1]]), phase: 'create', mode: 'draw_line' })
147
156
 
148
157
  expect(result).toEqual({ valid: true })
149
158
  expect(splitPolygon).not.toHaveBeenCalled()
@@ -162,39 +171,50 @@ describe('split', () => {
162
171
  // gates the built-in rules by numVertices, not a caller's own rule, so this
163
172
  // must still reach the validator (numVertices: 1, below MIN_VERTICES.LineString).
164
173
  const feature = lineFeature([[0, 0], [1, 1]])
165
- const result = draw._geometryValidator({ feature, phase: 'preview', mode: 'draw_line', numVertices: 1 })
174
+ const result = draw._previewValidator({ feature, phase: 'preview', mode: 'draw_line', numVertices: 1 })
166
175
 
167
176
  expect(splitPolygon).toHaveBeenCalledWith(polygonFeature, { id: '_splitter', geometry: feature.geometry })
168
177
  expect(draw.setDrawingPreviewProperty).toHaveBeenCalledWith('splitter', 'valid')
169
- // Committed Done-gating (pluginState.geometryValid / map._drawGeometryValid) must only
178
+ // Committed Done-gating (pluginState.geometryValid / map._drawCanFinish) must only
170
179
  // change on an actual commit — otherwise a live "what if you added a point here" check
171
180
  // could flicker a just-committed valid split back to disabled.
172
181
  expect(dispatch).not.toHaveBeenCalled()
173
- expect(draw.setGeometryValid).not.toHaveBeenCalled()
182
+ expect(draw.setCanFinish).not.toHaveBeenCalled()
174
183
  expect(result).toEqual({ valid: true })
175
184
  })
176
185
 
177
- test('a committed vertex (phase: commit-add) updates both the visual colour and Done-gating', () => {
186
+ test('a committed vertex (phase: change) updates the visual colour and returns the verdict that gates Done', () => {
178
187
  const { context, dispatch, draw } = makeContext()
179
188
  splitPolygon.mockReturnValue(null)
180
189
  split(context, 'poly')
181
190
 
182
191
  const feature = lineFeature([[0, 0], [1, 1]])
183
- const result = draw._geometryValidator({ feature, phase: 'commit-add', mode: 'draw_line', vertexIndex: 1 })
192
+ const result = draw._commitValidator({ feature, phase: 'change', mode: 'draw_line', vertexIndex: 1 })
184
193
 
185
194
  expect(draw.setDrawingPreviewProperty).toHaveBeenCalledWith('splitter', 'invalid')
186
195
  expect(dispatch).toHaveBeenCalledWith({ type: 'SET_ACTION', payload: { name: 'split', isValid: false } })
187
- expect(dispatch).toHaveBeenCalledWith({ type: 'SET_GEOMETRY_VALID', payload: false })
188
- expect(draw.setGeometryValid).toHaveBeenCalledWith(false)
196
+ // The Done gate is applied by events.js from the returned verdict, not written here
197
+ expect(dispatch).not.toHaveBeenCalledWith(expect.objectContaining({ type: 'SET_VALIDATION_STATUS' }))
198
+ expect(draw.setCanFinish).not.toHaveBeenCalled()
189
199
  expect(result).toEqual({ valid: false, reason: expect.any(String) })
190
200
  })
191
201
 
202
+ test('the commit validator ignores the live preview phase', () => {
203
+ const { context, draw } = makeContext()
204
+ split(context, 'poly')
205
+
206
+ const result = draw._commitValidator({ feature: lineFeature([[0, 0], [1, 1]]), phase: 'preview', mode: 'draw_line' })
207
+
208
+ expect(result).toEqual({ valid: true })
209
+ expect(splitPolygon).not.toHaveBeenCalled()
210
+ })
211
+
192
212
  test('a line with fewer than two coordinates is treated as invalid without calling splitPolygon', () => {
193
213
  const { context, draw } = makeContext()
194
214
  split(context, 'poly')
195
215
 
196
216
  const feature = lineFeature([[0, 0]])
197
- const result = draw._geometryValidator({ feature, phase: 'preview', mode: 'draw_line', numVertices: 0 })
217
+ const result = draw._previewValidator({ feature, phase: 'preview', mode: 'draw_line', numVertices: 0 })
198
218
 
199
219
  expect(splitPolygon).not.toHaveBeenCalled()
200
220
  expect(draw.setDrawingPreviewProperty).toHaveBeenCalledWith('splitter', 'invalid')