@defra/interactive-map 0.0.57-alpha → 0.0.59-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/docs/assets/css/docusaurus.scss +7 -1
- package/docs/plugins/draw.md +317 -186
- package/package.json +1 -1
- 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/adapterEvents.js +15 -9
- package/plugins/draw/src/adapters/adapterContract.test.js +1 -0
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.js +15 -3
- package/plugins/draw/src/adapters/maplibre/MaplibreDrawAdapter.test.js +27 -0
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.js +8 -19
- package/plugins/draw/src/adapters/maplibre/modes/editPointMode/pointerHandlers.test.js +20 -0
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/pointerHandlers.js +6 -17
- package/plugins/draw/src/adapters/maplibre/modes/editVertexMode/pointerHandlers.test.js +19 -0
- package/plugins/draw/src/adapters/maplibre/utils/editModeEvents.js +29 -1
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.js +13 -3
- package/plugins/draw/src/adapters/openlayers/OLDrawAdapter.test.js +28 -0
- package/plugins/draw/src/api/addFeature.js +9 -6
- package/plugins/draw/src/api/addFeature.test.js +37 -10
- package/plugins/draw/src/api/createNewShape.js +2 -2
- package/plugins/draw/src/api/editFeature.js +1 -1
- package/plugins/draw/src/api/newPoint.js +2 -2
- package/plugins/draw/src/api/newPoint.test.js +8 -0
- package/plugins/draw/src/api/newPolygon.test.js +8 -0
- package/plugins/draw/src/api/recheckGeometry.js +1 -1
- package/plugins/draw/src/api/recheckGeometry.test.js +2 -2
- package/plugins/draw/src/api/setProperties.js +39 -0
- package/plugins/draw/src/api/setProperties.test.js +74 -0
- package/plugins/draw/src/api/setStyle.js +16 -19
- package/plugins/draw/src/api/setStyle.test.js +17 -2
- package/plugins/draw/src/api/split.js +10 -4
- package/plugins/draw/src/api/split.test.js +30 -2
- package/plugins/draw/src/events.js +110 -64
- package/plugins/draw/src/events.test.js +494 -4
- package/plugins/draw/src/manifest.js +6 -4
- package/plugins/draw/src/manifest.test.js +20 -26
- package/plugins/draw/src/reducer.js +7 -0
- package/plugins/draw/src/reducer.test.js +11 -0
- package/plugins/draw/src/utils/flattenStyleProperties.js +54 -2
- package/plugins/draw/src/utils/flattenStyleProperties.test.js +74 -1
- package/plugins/draw/src/utils/isPlainObject.js +14 -0
- package/plugins/draw/src/utils/isPlainObject.test.js +24 -0
- package/plugins/draw/src/utils/mergeFeatureProperties.js +45 -0
- package/plugins/draw/src/utils/mergeFeatureProperties.test.js +48 -0
- package/plugins/draw/src/utils/stripInternalProperties.js +3 -2
- package/plugins/draw/src/validation/commitChecks.js +32 -12
- package/plugins/draw/src/validation/commitChecks.test.js +73 -13
- package/plugins/draw/src/validation/validateGeometry.js +12 -5
- package/plugins/draw/src/validation/validateGeometry.test.js +18 -0
- package/src/App/store/MapProvider.jsx +1 -0
- package/src/App/store/MapProvider.test.jsx +25 -0
- package/src/App/store/mapActionsMap.js +6 -0
- package/src/App/store/mapActionsMap.test.js +7 -0
- package/src/App/store/mapReducer.js +2 -0
- package/src/App/store/mapReducer.test.js +2 -0
|
@@ -84,6 +84,14 @@ describe('newPolygon', () => {
|
|
|
84
84
|
expect(draw.changeMode.mock.calls[0][1]).not.toHaveProperty('onGeometryChange')
|
|
85
85
|
})
|
|
86
86
|
|
|
87
|
+
test('stores a per-call onGeometryFinish without leaking it into mode options', () => {
|
|
88
|
+
const { context, draw } = makeContext()
|
|
89
|
+
const onGeometryFinish = jest.fn()
|
|
90
|
+
newPolygon(context, 'f1', { onGeometryFinish })
|
|
91
|
+
expect(draw._finishValidator).toBe(onGeometryFinish)
|
|
92
|
+
expect(draw.changeMode.mock.calls[0][1]).not.toHaveProperty('onGeometryFinish')
|
|
93
|
+
})
|
|
94
|
+
|
|
87
95
|
test('falls back to the plugin-level onGeometryChange validator', () => {
|
|
88
96
|
const pluginOnGeometryChange = jest.fn()
|
|
89
97
|
const { context, draw } = makeContext({ pluginConfig: { onGeometryChange: pluginOnGeometryChange } })
|
|
@@ -27,6 +27,6 @@ export const recheckGeometry = ({ mapProvider }, detail) => {
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
const context = { phase: 'recheck', mode, ...(detail !== undefined && { detail }) }
|
|
30
|
-
checks.run({ feature, context,
|
|
30
|
+
checks.run({ feature, context, consumerCheck: draw._commitValidator })
|
|
31
31
|
return true
|
|
32
32
|
}
|
|
@@ -12,7 +12,7 @@ describe('recheckGeometry', () => {
|
|
|
12
12
|
.mockReturnValueOnce({ valid: false, reason: 'near a parcel' })
|
|
13
13
|
.mockReturnValueOnce(true)
|
|
14
14
|
const checks = getCommitChecks(draw)
|
|
15
|
-
checks.run({ feature: square, context: { phase: 'change', mode: 'edit_vertex' },
|
|
15
|
+
checks.run({ feature: square, context: { phase: 'change', mode: 'edit_vertex' }, consumerCheck: draw._commitValidator })
|
|
16
16
|
expect(checks.state.status).toBe('invalid')
|
|
17
17
|
|
|
18
18
|
expect(recheckGeometry({ mapProvider: { draw } })).toBe(true)
|
|
@@ -26,7 +26,7 @@ describe('recheckGeometry', () => {
|
|
|
26
26
|
test('passes a detail through to onGeometryChange', () => {
|
|
27
27
|
const draw = makeDraw()
|
|
28
28
|
draw._commitValidator = jest.fn(() => true)
|
|
29
|
-
getCommitChecks(draw).run({ feature: square, context: { phase: 'change', mode: 'edit_vertex' },
|
|
29
|
+
getCommitChecks(draw).run({ feature: square, context: { phase: 'change', mode: 'edit_vertex' }, consumerCheck: draw._commitValidator })
|
|
30
30
|
recheckGeometry({ mapProvider: { draw } }, { refresh: false })
|
|
31
31
|
expect(draw._commitValidator).toHaveBeenLastCalledWith(
|
|
32
32
|
{ feature: square, phase: 'recheck', mode: 'edit_vertex', detail: { refresh: false } },
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { mergeFeatureProperties } from '../utils/mergeFeatureProperties.js'
|
|
2
|
+
import { mapStyleIds } from '../utils/flattenStyleProperties.js'
|
|
3
|
+
import { isEditMode } from '../utils/drawModes.js'
|
|
4
|
+
import { logger } from '../../../../src/services/logger.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Merge data properties into an existing feature. See mergeFeatureProperties for the rules:
|
|
8
|
+
* a shallow merge, undefined left out, null kept, internal and style properties refused.
|
|
9
|
+
*
|
|
10
|
+
* @param {object} context - plugin context
|
|
11
|
+
* @param {string} featureId
|
|
12
|
+
* @param {object} properties
|
|
13
|
+
* @returns {boolean} false if the feature doesn't exist
|
|
14
|
+
*/
|
|
15
|
+
export const setProperties = ({ pluginState, mapState, mapProvider, services }, featureId, properties = {}) => {
|
|
16
|
+
const { draw } = mapProvider
|
|
17
|
+
const { eventBus } = services
|
|
18
|
+
|
|
19
|
+
if (!draw) {
|
|
20
|
+
return false
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (!draw.get(featureId)) {
|
|
24
|
+
logger.warn('setProperties: no feature found for id', featureId)
|
|
25
|
+
return false
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const applied = mergeFeatureProperties(draw, featureId, properties, { caller: 'setProperties', styleIds: mapStyleIds(mapState) })
|
|
29
|
+
|
|
30
|
+
// Cancelling an edit puts back the feature as it was when the edit started, so that copy
|
|
31
|
+
// gets the properties too — they aren't part of the edit.
|
|
32
|
+
const { feature: editStart, dispatch } = pluginState
|
|
33
|
+
if (isEditMode(draw.getMode()) && editStart?.id === featureId) {
|
|
34
|
+
dispatch({ type: 'SET_FEATURE', payload: { feature: { ...editStart, properties: { ...editStart.properties, ...applied } } } })
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
eventBus.emit('draw:propertieschange', { featureId, properties: applied })
|
|
38
|
+
return true
|
|
39
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { setProperties } from './setProperties.js'
|
|
2
|
+
import { logger } from '../../../../src/services/logger.js'
|
|
3
|
+
|
|
4
|
+
jest.mock('../../../../src/services/logger.js', () => ({
|
|
5
|
+
logger: { warn: jest.fn(), error: jest.fn() }
|
|
6
|
+
}))
|
|
7
|
+
|
|
8
|
+
const setup = ({ draw, mode = 'disabled', feature = null } = {}) => {
|
|
9
|
+
const eventBus = { emit: jest.fn() }
|
|
10
|
+
const dispatch = jest.fn()
|
|
11
|
+
if (draw) { draw.getMode = jest.fn(() => mode) }
|
|
12
|
+
return {
|
|
13
|
+
context: { pluginState: { feature, dispatch }, mapState: { mapStyles: [{ id: 'outdoor' }, { id: 'dark' }] }, mapProvider: { draw }, services: { eventBus } },
|
|
14
|
+
eventBus,
|
|
15
|
+
dispatch
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const makeDraw = () => ({ get: jest.fn((id) => ({ id, properties: {} })), setProperties: jest.fn() })
|
|
20
|
+
|
|
21
|
+
beforeEach(() => jest.clearAllMocks())
|
|
22
|
+
|
|
23
|
+
describe('setProperties', () => {
|
|
24
|
+
test('does nothing when there is no draw instance', () => {
|
|
25
|
+
const { context, eventBus } = setup()
|
|
26
|
+
expect(setProperties(context, 'a', { name: 'x' })).toBe(false)
|
|
27
|
+
expect(eventBus.emit).not.toHaveBeenCalled()
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
test('warns and does nothing for an id with no existing feature', () => {
|
|
31
|
+
const draw = makeDraw()
|
|
32
|
+
draw.get.mockReturnValue(undefined)
|
|
33
|
+
const { context, eventBus } = setup({ draw })
|
|
34
|
+
expect(setProperties(context, 'missing', { name: 'x' })).toBe(false)
|
|
35
|
+
expect(draw.setProperties).not.toHaveBeenCalled()
|
|
36
|
+
expect(eventBus.emit).not.toHaveBeenCalled()
|
|
37
|
+
expect(logger.warn).toHaveBeenCalledWith('setProperties: no feature found for id', 'missing')
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('merges the properties and reports what was applied', () => {
|
|
41
|
+
const draw = makeDraw()
|
|
42
|
+
const { context, eventBus, dispatch } = setup({ draw })
|
|
43
|
+
expect(setProperties(context, 'a', { name: 'North field', fillType: 'arable', stroke: 'red', strokeDark: 'tan' })).toBe(true)
|
|
44
|
+
expect(draw.setProperties).toHaveBeenCalledWith('a', { name: 'North field', fillType: 'arable' })
|
|
45
|
+
expect(eventBus.emit).toHaveBeenCalledWith('draw:propertieschange', { featureId: 'a', properties: { name: 'North field', fillType: 'arable' } })
|
|
46
|
+
expect(dispatch).not.toHaveBeenCalled()
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
test('defaults properties to {}', () => {
|
|
50
|
+
const draw = makeDraw()
|
|
51
|
+
const { context, eventBus } = setup({ draw })
|
|
52
|
+
expect(setProperties(context, 'a')).toBe(true)
|
|
53
|
+
expect(eventBus.emit).toHaveBeenCalledWith('draw:propertieschange', { featureId: 'a', properties: {} })
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
// Otherwise Cancel would put back the edit-start copy without them
|
|
57
|
+
test('also updates the edit-start copy of the feature being edited', () => {
|
|
58
|
+
const draw = makeDraw()
|
|
59
|
+
const editStart = { id: 'a', geometry: {}, properties: { landUse: 'arable', sortKey: 2 } }
|
|
60
|
+
const { context, dispatch } = setup({ draw, mode: 'edit_vertex', feature: editStart })
|
|
61
|
+
setProperties(context, 'a', { name: 'North field' })
|
|
62
|
+
expect(dispatch).toHaveBeenCalledWith({
|
|
63
|
+
type: 'SET_FEATURE',
|
|
64
|
+
payload: { feature: { id: 'a', geometry: {}, properties: { landUse: 'arable', sortKey: 2, name: 'North field' } } }
|
|
65
|
+
})
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test('leaves the edit-start copy alone when a different feature is changed', () => {
|
|
69
|
+
const draw = makeDraw()
|
|
70
|
+
const { context, dispatch } = setup({ draw, mode: 'edit_vertex', feature: { id: 'b', properties: {} } })
|
|
71
|
+
setProperties(context, 'a', { name: 'x' })
|
|
72
|
+
expect(dispatch).not.toHaveBeenCalled()
|
|
73
|
+
})
|
|
74
|
+
})
|
|
@@ -1,23 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { toStyleChanges, definedOnly, mapStyleIds } from '../utils/flattenStyleProperties.js'
|
|
2
2
|
import { logger } from '../../../../src/services/logger.js'
|
|
3
3
|
|
|
4
4
|
const STYLE_KEYS = new Set(['stroke', 'fill', 'strokeWidth'])
|
|
5
5
|
|
|
6
|
-
// A
|
|
7
|
-
//
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const definedOnly = (properties) => {
|
|
11
|
-
const result = {}
|
|
12
|
-
for (const [key, value] of Object.entries(properties)) {
|
|
13
|
-
if (value !== undefined) {
|
|
14
|
-
result[key] = value
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
return result
|
|
18
|
-
}
|
|
6
|
+
// A removed key is reported as null, so a page that merges the payload into its saved copy
|
|
7
|
+
// of the feature clears it too
|
|
8
|
+
const toPayload = (changes) =>
|
|
9
|
+
Object.fromEntries(Object.entries(changes).map(([key, value]) => [key, value === undefined ? null : value]))
|
|
19
10
|
|
|
20
|
-
export const setStyle = ({ mapProvider, services }, featureId, styleChanges = {}) => {
|
|
11
|
+
export const setStyle = ({ mapState, mapProvider, services }, featureId, styleChanges = {}) => {
|
|
21
12
|
const { draw } = mapProvider
|
|
22
13
|
const { eventBus } = services
|
|
23
14
|
|
|
@@ -25,7 +16,8 @@ export const setStyle = ({ mapProvider, services }, featureId, styleChanges = {}
|
|
|
25
16
|
return false
|
|
26
17
|
}
|
|
27
18
|
|
|
28
|
-
|
|
19
|
+
const feature = draw.get(featureId)
|
|
20
|
+
if (!feature) {
|
|
29
21
|
logger.warn('setStyle: no feature found for id', featureId)
|
|
30
22
|
return false
|
|
31
23
|
}
|
|
@@ -35,9 +27,14 @@ export const setStyle = ({ mapProvider, services }, featureId, styleChanges = {}
|
|
|
35
27
|
for (const [key, value] of Object.entries(styleChanges)) {
|
|
36
28
|
(STYLE_KEYS.has(key) ? styleProps : symbolProps)[key] = value
|
|
37
29
|
}
|
|
38
|
-
|
|
30
|
+
// A partial patch: style keys left out stay as they are. Setting one replaces all of its
|
|
31
|
+
// per-style values, which reach the adapter as undefined, meaning remove.
|
|
32
|
+
const changes = {
|
|
33
|
+
...toStyleChanges(feature.properties, styleProps, mapStyleIds(mapState)),
|
|
34
|
+
...definedOnly(symbolProps)
|
|
35
|
+
}
|
|
39
36
|
|
|
40
|
-
draw.setStyle(featureId,
|
|
41
|
-
eventBus.emit('draw:stylechange', { featureId, properties })
|
|
37
|
+
draw.setStyle(featureId, changes)
|
|
38
|
+
eventBus.emit('draw:stylechange', { featureId, properties: toPayload(changes) })
|
|
42
39
|
return true
|
|
43
40
|
}
|
|
@@ -5,9 +5,9 @@ jest.mock('../../../../src/services/logger.js', () => ({
|
|
|
5
5
|
logger: { warn: jest.fn(), error: jest.fn() }
|
|
6
6
|
}))
|
|
7
7
|
|
|
8
|
-
const setup = (draw) => {
|
|
8
|
+
const setup = (draw, mapStyles = []) => {
|
|
9
9
|
const eventBus = { emit: jest.fn() }
|
|
10
|
-
return { context: { mapProvider: { draw }, services: { eventBus } }, eventBus }
|
|
10
|
+
return { context: { mapState: { mapStyles }, mapProvider: { draw }, services: { eventBus } }, eventBus }
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
beforeEach(() => jest.clearAllMocks())
|
|
@@ -66,6 +66,21 @@ describe('setStyle', () => {
|
|
|
66
66
|
expect(draw.setStyle).toHaveBeenCalledWith('a', { stroke: 'red', symbol: 'pin' })
|
|
67
67
|
})
|
|
68
68
|
|
|
69
|
+
// Otherwise the renderers would keep reading the old strokeOutdoor over the new stroke
|
|
70
|
+
test('setting a style prop removes its values for each map style, and the event reports them as null', () => {
|
|
71
|
+
const draw = {
|
|
72
|
+
get: jest.fn(() => ({ id: 'a', properties: { stroke: 'brown', strokeOutdoor: 'brown', strokeDark: 'tan', fillType: 'arable' } })),
|
|
73
|
+
setStyle: jest.fn()
|
|
74
|
+
}
|
|
75
|
+
const { context, eventBus } = setup(draw, [{ id: 'outdoor' }, { id: 'dark' }])
|
|
76
|
+
setStyle(context, 'a', { stroke: 'red' })
|
|
77
|
+
expect(draw.setStyle).toHaveBeenCalledWith('a', { strokeOutdoor: undefined, strokeDark: undefined, stroke: 'red' })
|
|
78
|
+
expect(eventBus.emit).toHaveBeenCalledWith('draw:stylechange', {
|
|
79
|
+
featureId: 'a',
|
|
80
|
+
properties: { strokeOutdoor: null, strokeDark: null, stroke: 'red' }
|
|
81
|
+
})
|
|
82
|
+
})
|
|
83
|
+
|
|
69
84
|
test('defaults styleChanges to {} and still resolves cleanly', () => {
|
|
70
85
|
const draw = { get: jest.fn(() => ({ id: 'a' })), setStyle: jest.fn() }
|
|
71
86
|
const { context } = setup(draw)
|
|
@@ -32,10 +32,13 @@ const applySplitCommit = ({ draw, dispatch, polygonFeature, feature }) => {
|
|
|
32
32
|
|
|
33
33
|
const toResult = (isValid) => (isValid ? { valid: true } : { valid: false, reason: INVALID_REASON })
|
|
34
34
|
|
|
35
|
-
// Installed as draw._previewValidator. '
|
|
36
|
-
// until its last vertex, so
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
// Installed as draw._previewValidator. 'preview' only colours the line and 'place' is a
|
|
36
|
+
// no-op — a split isn't complete until its last vertex, so an invalid verdict would
|
|
37
|
+
// disable the Add point button and block placement.
|
|
38
|
+
const createSplitPreviewValidator = ({ draw, polygonFeature }) => ({ feature, phase }) => {
|
|
39
|
+
if (phase === 'preview') { applySplitPreview({ draw, polygonFeature, feature }) }
|
|
40
|
+
return { valid: true }
|
|
41
|
+
}
|
|
39
42
|
|
|
40
43
|
// Installed as draw._commitValidator. 'create' is a no-op — checking it would
|
|
41
44
|
// hijack an early finish into edit mode.
|
|
@@ -63,8 +66,10 @@ export const split = ({ appState, appConfig, pluginState, mapState, mapProvider,
|
|
|
63
66
|
// Swap in split's own rules; restored in stopListening.
|
|
64
67
|
const previousPreviewValidator = draw._previewValidator
|
|
65
68
|
const previousValidator = draw._commitValidator
|
|
69
|
+
const previousFinishValidator = draw._finishValidator
|
|
66
70
|
draw._previewValidator = createSplitPreviewValidator({ draw, polygonFeature })
|
|
67
71
|
draw._commitValidator = createSplitCommitValidator({ draw, dispatch, polygonFeature })
|
|
72
|
+
draw._finishValidator = null
|
|
68
73
|
getCommitChecks(draw).reset()
|
|
69
74
|
|
|
70
75
|
// Always include the draw outline layer so the split line snaps to it
|
|
@@ -86,6 +91,7 @@ export const split = ({ appState, appConfig, pluginState, mapState, mapProvider,
|
|
|
86
91
|
const stopListening = () => {
|
|
87
92
|
draw._previewValidator = previousPreviewValidator
|
|
88
93
|
draw._commitValidator = previousValidator
|
|
94
|
+
draw._finishValidator = previousFinishValidator
|
|
89
95
|
draw.off(ADAPTER_EVENTS.CREATE, onSplitCreate)
|
|
90
96
|
draw.off(ADAPTER_EVENTS.CANCEL, onSplitCancel)
|
|
91
97
|
}
|
|
@@ -79,12 +79,16 @@ describe('split', () => {
|
|
|
79
79
|
const featureCollection = { type: 'FeatureCollection' }
|
|
80
80
|
const previousValidator = jest.fn()
|
|
81
81
|
const previousPreviewValidator = jest.fn()
|
|
82
|
+
const previousFinishValidator = jest.fn()
|
|
82
83
|
draw._commitValidator = previousValidator
|
|
83
84
|
draw._previewValidator = previousPreviewValidator
|
|
85
|
+
draw._finishValidator = previousFinishValidator
|
|
84
86
|
draw.get.mockReturnValue(polygonFeature)
|
|
85
87
|
splitPolygon.mockReturnValue(featureCollection)
|
|
86
88
|
|
|
87
89
|
split(context, 'poly')
|
|
90
|
+
// The split line is never passed to the consumer's onGeometryFinish
|
|
91
|
+
expect(draw._finishValidator).toBeNull()
|
|
88
92
|
const onCreate = handlerFor(draw, 'create')
|
|
89
93
|
const geojson = { id: 'line' }
|
|
90
94
|
onCreate(geojson)
|
|
@@ -96,6 +100,7 @@ describe('split', () => {
|
|
|
96
100
|
expect(eventBus.emit).toHaveBeenCalledWith('draw:split', { originalFeatureId: 'poly', featureCollection })
|
|
97
101
|
expect(draw._commitValidator).toBe(previousValidator)
|
|
98
102
|
expect(draw._previewValidator).toBe(previousPreviewValidator)
|
|
103
|
+
expect(draw._finishValidator).toBe(previousFinishValidator)
|
|
99
104
|
// The splitter line only ever existed to compute the split — it must not
|
|
100
105
|
// linger in the draw store afterwards.
|
|
101
106
|
expect(draw.delete).toHaveBeenCalledWith('_splitter')
|
|
@@ -194,6 +199,18 @@ describe('split', () => {
|
|
|
194
199
|
expect(result).toEqual({ valid: false, reason: expect.any(String) })
|
|
195
200
|
})
|
|
196
201
|
|
|
202
|
+
test('a committed vertex that completes the split returns a passing verdict', () => {
|
|
203
|
+
const { context, dispatch, draw } = makeContext()
|
|
204
|
+
splitPolygon.mockReturnValue({ type: 'FeatureCollection' })
|
|
205
|
+
split(context, 'poly')
|
|
206
|
+
|
|
207
|
+
const result = draw._commitValidator({ feature: lineFeature([[0, 0], [1, 1]]), phase: 'change', mode: 'draw_line', vertexIndex: 1 })
|
|
208
|
+
|
|
209
|
+
expect(draw.setDrawingPreviewProperty).toHaveBeenCalledWith('splitter', 'valid')
|
|
210
|
+
expect(dispatch).toHaveBeenCalledWith({ type: 'SET_ACTION', payload: { name: 'split', isValid: true } })
|
|
211
|
+
expect(result).toEqual({ valid: true })
|
|
212
|
+
})
|
|
213
|
+
|
|
197
214
|
test('the commit validator ignores the live preview phase', () => {
|
|
198
215
|
const { context, draw } = makeContext()
|
|
199
216
|
split(context, 'poly')
|
|
@@ -204,7 +221,7 @@ describe('split', () => {
|
|
|
204
221
|
expect(splitPolygon).not.toHaveBeenCalled()
|
|
205
222
|
})
|
|
206
223
|
|
|
207
|
-
test('a line with fewer than two coordinates is
|
|
224
|
+
test('a line with fewer than two coordinates is coloured invalid without calling splitPolygon', () => {
|
|
208
225
|
const { context, draw } = makeContext()
|
|
209
226
|
split(context, 'poly')
|
|
210
227
|
|
|
@@ -213,7 +230,18 @@ describe('split', () => {
|
|
|
213
230
|
|
|
214
231
|
expect(splitPolygon).not.toHaveBeenCalled()
|
|
215
232
|
expect(draw.setDrawingPreviewProperty).toHaveBeenCalledWith('splitter', 'invalid')
|
|
216
|
-
expect(result).toEqual({ valid:
|
|
233
|
+
expect(result).toEqual({ valid: true })
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
test('the live preview of an incomplete split colours it invalid but never vetoes, so Add point stays enabled', () => {
|
|
237
|
+
const { context, draw } = makeContext()
|
|
238
|
+
splitPolygon.mockReturnValue(null)
|
|
239
|
+
split(context, 'poly')
|
|
240
|
+
|
|
241
|
+
const result = draw._previewValidator({ feature: lineFeature([[0, 0], [1, 1]]), phase: 'preview', mode: 'draw_line', numVertices: 1 })
|
|
242
|
+
|
|
243
|
+
expect(draw.setDrawingPreviewProperty).toHaveBeenCalledWith('splitter', 'invalid')
|
|
244
|
+
expect(result).toEqual({ valid: true })
|
|
217
245
|
})
|
|
218
246
|
})
|
|
219
247
|
})
|