@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.
- package/dist/esm/im-core.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.md +3 -1
- package/docs/assets/css/docusaurus.scss +7 -1
- package/docs/plugins/draw.md +326 -121
- package/package.json +1 -1
- package/plugins/datasets/dist/esm/im-datasets-plugin.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/initialise/DatasetsInit.jsx +6 -17
- package/plugins/datasets/src/initialise/DatasetsInit.test.jsx +3 -43
- 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/esm/index.js +1 -1
- package/plugins/draw/dist/esm/liveDrawChecks.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 +9 -6
- package/plugins/draw/src/DrawInit.test.jsx +15 -0
- package/plugins/draw/src/adapterEvents.js +82 -44
- package/plugins/draw/src/adapters/adapterContract.test.js +3 -3
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +18 -10
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +31 -22
- package/plugins/draw/src/adapters/maplibre/drawEvents.js +2 -1
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/clickHandlers.js +13 -12
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/clickHandlers.test.js +5 -5
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/undoHandlers.js +1 -1
- package/plugins/draw/src/adapters/maplibre/modes/drawMode/undoHandlers.test.js +2 -2
- package/plugins/draw/src/adapters/maplibre/modes/drawPointMode.js +6 -9
- package/plugins/draw/src/adapters/maplibre/modes/drawPointMode.test.js +4 -4
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.js +6 -9
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.test.js +1 -1
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode/undoHandlers.js +8 -14
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode/undoHandlers.test.js +37 -8
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode.js +11 -1
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/undoHandlers.js +14 -19
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/undoHandlers.test.js +41 -4
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode.js +12 -1
- package/plugins/draw/src/adapters/maplibre/utils/editModeEvents.js +3 -1
- package/plugins/draw/src/adapters/maplibre/utils/geometryValidation.js +9 -10
- package/plugins/draw/src/adapters/maplibre/utils/geometryValidation.test.js +5 -24
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +10 -7
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +12 -7
- package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.js +5 -0
- package/plugins/draw/src/adapters/openlayers/core/OLDrawManager.test.js +7 -3
- package/plugins/draw/src/adapters/openlayers/draw/DrawMode.js +11 -11
- package/plugins/draw/src/adapters/openlayers/draw/DrawMode.test.js +15 -15
- package/plugins/draw/src/adapters/openlayers/edit/EditMode.js +21 -28
- package/plugins/draw/src/adapters/openlayers/edit/EditMode.test.js +26 -5
- package/plugins/draw/src/adapters/openlayers/edit/selectionState.js +5 -6
- package/plugins/draw/src/adapters/openlayers/edit/selectionState.test.js +2 -12
- package/plugins/draw/src/adapters/openlayers/edit/undoOps.js +9 -0
- package/plugins/draw/src/adapters/openlayers/edit/undoOps.test.js +7 -0
- package/plugins/draw/src/adapters/openlayers/point/drawPointMode.js +6 -9
- package/plugins/draw/src/adapters/openlayers/point/drawPointMode.test.js +3 -3
- package/plugins/draw/src/adapters/openlayers/point/editPointMode.js +18 -9
- package/plugins/draw/src/adapters/openlayers/point/editPointMode.test.js +29 -4
- package/plugins/draw/src/adapters/openlayers/point/pointOps.js +3 -2
- package/plugins/draw/src/adapters/openlayers/point/pointOps.test.js +6 -0
- package/plugins/draw/src/adapters/openlayers/point/pointSelectionState.js +3 -4
- package/plugins/draw/src/adapters/openlayers/point/pointSelectionState.test.js +2 -12
- package/plugins/draw/src/api/createNewShape.js +4 -4
- package/plugins/draw/src/api/createNewShape.test.js +1 -1
- package/plugins/draw/src/api/editFeature.js +8 -11
- package/plugins/draw/src/api/editFeature.test.js +33 -22
- package/plugins/draw/src/api/newLine.test.js +3 -3
- package/plugins/draw/src/api/newPoint.js +4 -5
- package/plugins/draw/src/api/newPoint.test.js +11 -3
- package/plugins/draw/src/api/newPolygon.test.js +11 -3
- package/plugins/draw/src/api/recheckGeometry.js +32 -0
- package/plugins/draw/src/api/recheckGeometry.test.js +55 -0
- package/plugins/draw/src/api/setGeometry.js +33 -0
- package/plugins/draw/src/api/setGeometry.test.js +48 -0
- package/plugins/draw/src/api/split.js +26 -22
- package/plugins/draw/src/api/split.test.js +38 -18
- package/plugins/draw/src/events.js +269 -77
- package/plugins/draw/src/events.test.js +779 -34
- package/plugins/draw/src/hooks/useSpatialList.js +10 -11
- package/plugins/draw/src/hooks/useSpatialList.test.js +3 -3
- package/plugins/draw/src/manifest.js +30 -15
- package/plugins/draw/src/manifest.test.js +91 -9
- package/plugins/draw/src/reducer.js +31 -9
- package/plugins/draw/src/reducer.test.js +35 -3
- package/plugins/draw/src/utils/drawModes.js +27 -0
- package/plugins/draw/src/utils/drawModes.test.js +27 -0
- package/plugins/draw/src/utils/needsDrawTarget.js +1 -5
- package/plugins/draw/src/utils/needsDrawTarget.test.js +1 -11
- package/plugins/draw/src/utils/touchTarget.js +34 -26
- package/plugins/draw/src/utils/touchTarget.test.js +32 -20
- package/plugins/draw/src/validation/commitChecks.js +187 -0
- package/plugins/draw/src/validation/commitChecks.test.js +209 -0
- package/plugins/draw/src/validation/liveDrawChecks.js +11 -11
- package/plugins/draw/src/validation/liveDrawChecks.test.js +37 -37
- package/plugins/draw/src/validation/liveStroke.js +6 -6
- package/plugins/draw/src/validation/liveStroke.test.js +27 -27
- package/plugins/draw/src/validation/rules.js +16 -14
- package/plugins/draw/src/validation/rules.test.js +5 -5
- package/plugins/draw/src/validation/validateGeometry.js +58 -31
- package/plugins/draw/src/validation/validateGeometry.test.js +68 -44
- package/plugins/interact/dist/esm/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/umd/im-interact-plugin.js +1 -1
- package/plugins/interact/dist/umd/index.js +1 -1
- package/plugins/interact/src/hooks/useInteractionHandlers.js +3 -5
- package/plugins/interact/src/hooks/useInteractionHandlers.test.js +4 -3
- package/plugins/interact/src/hooks/useSpatialList.js +16 -17
- package/plugins/interact/src/hooks/useSpatialList.test.js +9 -9
- package/plugins/map-styles/dist/esm/im-map-styles-plugin.js +1 -1
- package/plugins/map-styles/dist/umd/im-map-styles-plugin.js +1 -1
- package/plugins/map-styles/src/MapStyles.jsx +2 -2
- package/providers/maplibre/dist/esm/index.js +1 -1
- package/providers/maplibre/dist/umd/index.js +1 -1
- package/providers/maplibre/src/index.js +11 -2
- package/providers/maplibre/src/index.test.js +23 -1
- package/providers/maplibre/src/utils/detectModuleWorker.js +8 -19
- package/providers/maplibre/src/utils/detectModuleWorker.test.js +19 -23
- package/providers/maplibre/src/utils/workerUrl.js +12 -0
- package/providers/maplibre/src/utils/workerUrl.test.js +14 -1
- package/src/App/components/MapButton/MapButton.jsx +6 -0
- package/src/App/components/MapButton/MapButton.test.jsx +10 -0
- package/src/App/components/Markers/Markers.jsx +3 -5
- package/src/App/components/Markers/Markers.test.jsx +9 -11
- package/src/App/components/Panel/Panel.jsx +2 -9
- package/src/App/hooks/useInterfaceAPI.js +16 -4
- package/src/App/hooks/useInterfaceAPI.test.js +66 -1
- package/src/App/renderer/mapButtons.js +2 -1
- package/src/App/renderer/mapButtons.test.js +9 -0
- package/src/App/store/MapProvider.jsx +3 -0
- package/src/App/store/MapProvider.test.jsx +24 -0
- package/src/config/mapSizeScales.js +3 -0
- package/src/types.js +4 -0
- package/src/utils/focusAfterPanelClose.js +9 -0
- 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
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
//
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
|
67
|
-
const
|
|
68
|
-
|
|
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.
|
|
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
|
-
|
|
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.
|
|
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
|
|
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
|
-
|
|
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.
|
|
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.
|
|
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.
|
|
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
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
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.
|
|
182
|
+
expect(draw.setCanFinish).not.toHaveBeenCalled()
|
|
174
183
|
expect(result).toEqual({ valid: true })
|
|
175
184
|
})
|
|
176
185
|
|
|
177
|
-
test('a committed vertex (phase:
|
|
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.
|
|
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
|
-
|
|
188
|
-
expect(
|
|
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.
|
|
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')
|