@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createCommitChecks, getCommitChecks, isSameGeometry, startCheckSession, SLOW_CHECK_MS } from './commitChecks.js'
|
|
1
|
+
import { createCommitChecks, getCommitChecks, isSameGeometry, startCheckSession, canFinishCheck, SLOW_CHECK_MS } from './commitChecks.js'
|
|
2
2
|
|
|
3
3
|
const square = { type: 'Feature', geometry: { type: 'Polygon', coordinates: [[[0, 0], [0, 1], [1, 1], [1, 0], [0, 0]]] } }
|
|
4
4
|
const context = { phase: 'change', mode: 'draw_polygon', vertexIndex: 3 }
|
|
@@ -20,13 +20,13 @@ describe('createCommitChecks', () => {
|
|
|
20
20
|
test('passes the event and a { signal, revision } second argument to the callback', () => {
|
|
21
21
|
const checks = createCommitChecks()
|
|
22
22
|
const onGeometryChange = jest.fn(() => true)
|
|
23
|
-
checks.run({ feature: square, context, onGeometryChange })
|
|
23
|
+
checks.run({ feature: square, context, consumerCheck: onGeometryChange })
|
|
24
24
|
expect(onGeometryChange).toHaveBeenCalledWith({ feature: square, ...context }, { signal: expect.any(AbortSignal), revision: 1 })
|
|
25
25
|
})
|
|
26
26
|
|
|
27
27
|
test('normalises a synchronous result', () => {
|
|
28
28
|
const checks = createCommitChecks()
|
|
29
|
-
checks.run({ feature: square, context,
|
|
29
|
+
checks.run({ feature: square, context, consumerCheck: () => ({ valid: false, reason: 'too big' }) })
|
|
30
30
|
expect(checks.state).toEqual(expect.objectContaining({ status: 'invalid', result: { valid: false, reason: 'too big', source: 'callback' } }))
|
|
31
31
|
})
|
|
32
32
|
|
|
@@ -36,7 +36,7 @@ describe('createCommitChecks', () => {
|
|
|
36
36
|
const onSettle = jest.fn()
|
|
37
37
|
checks.setOnSettle(onSettle)
|
|
38
38
|
let resolve
|
|
39
|
-
checks.run({ feature: square, context,
|
|
39
|
+
checks.run({ feature: square, context, consumerCheck: () => new Promise((_resolve) => { resolve = _resolve }) })
|
|
40
40
|
expect(checks.state).toEqual(expect.objectContaining({ status: 'pending', slow: false }))
|
|
41
41
|
|
|
42
42
|
jest.advanceTimersByTime(SLOW_CHECK_MS)
|
|
@@ -48,7 +48,7 @@ describe('createCommitChecks', () => {
|
|
|
48
48
|
expect(onSettle.mock.calls.map(([state]) => [state.status, state.slow])).toEqual([['pending', false], ['pending', true], ['invalid', false]])
|
|
49
49
|
|
|
50
50
|
// The next check settles straight away, so it doesn't follow a pending state
|
|
51
|
-
checks.run({ feature: square, context,
|
|
51
|
+
checks.run({ feature: square, context, consumerCheck: () => true })
|
|
52
52
|
expect(checks.state.afterPending).toBe(false)
|
|
53
53
|
jest.useRealTimers()
|
|
54
54
|
})
|
|
@@ -58,7 +58,7 @@ describe('createCommitChecks', () => {
|
|
|
58
58
|
const checks = createCommitChecks()
|
|
59
59
|
const onSettle = jest.fn()
|
|
60
60
|
checks.setOnSettle(onSettle)
|
|
61
|
-
checks.run({ feature: square, context,
|
|
61
|
+
checks.run({ feature: square, context, consumerCheck: () => Promise.resolve(true) })
|
|
62
62
|
await flush()
|
|
63
63
|
jest.advanceTimersByTime(SLOW_CHECK_MS)
|
|
64
64
|
expect(checks.state).toEqual(expect.objectContaining({ status: 'valid', afterPending: false }))
|
|
@@ -73,16 +73,25 @@ describe('createCommitChecks', () => {
|
|
|
73
73
|
expect(checks.state.result.source).toBe('rules')
|
|
74
74
|
|
|
75
75
|
jest.spyOn(console, 'warn').mockImplementation(() => {})
|
|
76
|
-
checks.run({ feature: square, context,
|
|
76
|
+
checks.run({ feature: square, context, consumerCheck: () => { throw new Error('503') } })
|
|
77
77
|
expect(checks.state).toEqual(expect.objectContaining({ status: 'error', result: { valid: false, reason: null, source: 'callback' } }))
|
|
78
78
|
console.warn.mockRestore()
|
|
79
79
|
})
|
|
80
80
|
|
|
81
|
+
test('logs a callback error with the phase, so it names the finishing check too', () => {
|
|
82
|
+
const checks = createCommitChecks()
|
|
83
|
+
jest.spyOn(console, 'warn').mockImplementation(() => {})
|
|
84
|
+
const error = new Error('503')
|
|
85
|
+
checks.run({ feature: square, context: { phase: 'edit-finish' }, consumerCheck: () => { throw error } })
|
|
86
|
+
expect(console.warn).toHaveBeenCalledWith('[interactive-map]', '[draw] geometry check failed (edit-finish)', error)
|
|
87
|
+
console.warn.mockRestore()
|
|
88
|
+
})
|
|
89
|
+
|
|
81
90
|
test('reset aborts the check in flight, drops its reply and returns to idle', async () => {
|
|
82
91
|
const checks = createCommitChecks()
|
|
83
92
|
let resolve
|
|
84
93
|
let signal
|
|
85
|
-
checks.run({ feature: square, context,
|
|
94
|
+
checks.run({ feature: square, context, consumerCheck: (_event, ctx) => { signal = ctx.signal; return new Promise((_resolve) => { resolve = _resolve }) } })
|
|
86
95
|
checks.reset()
|
|
87
96
|
expect(signal.aborted).toBe(true)
|
|
88
97
|
|
|
@@ -97,8 +106,8 @@ describe('createCommitChecks', () => {
|
|
|
97
106
|
const onGeometryChange = (_event, { signal }) => new Promise((_resolve, reject) => {
|
|
98
107
|
signal.addEventListener('abort', () => reject(new Error('aborted')))
|
|
99
108
|
})
|
|
100
|
-
checks.run({ feature: square, context, onGeometryChange })
|
|
101
|
-
checks.run({ feature: square, context,
|
|
109
|
+
checks.run({ feature: square, context, consumerCheck: onGeometryChange })
|
|
110
|
+
checks.run({ feature: square, context, consumerCheck: () => true })
|
|
102
111
|
await flush()
|
|
103
112
|
expect(checks.state.status).toBe('valid')
|
|
104
113
|
expect(warn).not.toHaveBeenCalled()
|
|
@@ -122,12 +131,59 @@ describe('createCommitChecks', () => {
|
|
|
122
131
|
expect(checks.reset()).toBe('c')
|
|
123
132
|
})
|
|
124
133
|
|
|
134
|
+
test('carries the last callback result into later states, ignoring the built-in rules', () => {
|
|
135
|
+
const checks = createCommitChecks()
|
|
136
|
+
const partDrawn = { type: 'Feature', geometry: { type: 'Polygon', coordinates: [[[0, 0], [1, 0], [0, 0]]] } }
|
|
137
|
+
checks.run({ feature: square, context, consumerCheck: () => false })
|
|
138
|
+
expect(checks.state.lastResultStatus).toBe('invalid')
|
|
139
|
+
|
|
140
|
+
checks.run({ feature: partDrawn, context, consumerCheck: () => true })
|
|
141
|
+
expect(checks.state).toEqual(expect.objectContaining({ status: 'invalid', lastResultStatus: 'invalid' }))
|
|
142
|
+
|
|
143
|
+
checks.run({ feature: square, context, consumerCheck: () => new Promise(() => {}) })
|
|
144
|
+
checks.run({ feature: square, context, consumerCheck: () => new Promise(() => {}) })
|
|
145
|
+
expect(checks.state).toEqual(expect.objectContaining({ status: 'pending', lastResultStatus: 'invalid' }))
|
|
146
|
+
|
|
147
|
+
checks.reset()
|
|
148
|
+
expect(checks.state.lastResultStatus).toBeNull()
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
test('counts a callback error as its last result', () => {
|
|
152
|
+
const checks = createCommitChecks()
|
|
153
|
+
jest.spyOn(console, 'warn').mockImplementation(() => {})
|
|
154
|
+
checks.run({ feature: square, context, consumerCheck: () => { throw new Error('503') } })
|
|
155
|
+
expect(checks.state.lastResultStatus).toBe('error')
|
|
156
|
+
console.warn.mockRestore()
|
|
157
|
+
})
|
|
158
|
+
|
|
125
159
|
test('works without an onSettle callback', () => {
|
|
126
160
|
const checks = createCommitChecks()
|
|
127
161
|
expect(() => checks.run({ feature: square, context })).not.toThrow()
|
|
128
162
|
})
|
|
129
163
|
})
|
|
130
164
|
|
|
165
|
+
describe('canFinishCheck', () => {
|
|
166
|
+
test('is true for a passing check, and false for a failed one or none', () => {
|
|
167
|
+
expect(canFinishCheck({ status: 'valid' })).toBe(true)
|
|
168
|
+
expect(canFinishCheck({ status: 'invalid' })).toBe(false)
|
|
169
|
+
expect(canFinishCheck({ status: 'error' })).toBe(false)
|
|
170
|
+
expect(canFinishCheck({ status: 'idle' })).toBe(false)
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
test('keeps the last callback result while a check is pending', () => {
|
|
174
|
+
expect(canFinishCheck({ status: 'pending', lastResultStatus: null })).toBe(true)
|
|
175
|
+
expect(canFinishCheck({ status: 'pending', lastResultStatus: 'valid' })).toBe(true)
|
|
176
|
+
expect(canFinishCheck({ status: 'pending', lastResultStatus: 'invalid' })).toBe(false)
|
|
177
|
+
expect(canFinishCheck({ status: 'pending', lastResultStatus: 'error' })).toBe(false)
|
|
178
|
+
})
|
|
179
|
+
|
|
180
|
+
test('is false while an existing feature’s edit-start check is pending', () => {
|
|
181
|
+
expect(canFinishCheck({ status: 'pending', lastResultStatus: null, context: { phase: 'edit-start' } })).toBe(false)
|
|
182
|
+
expect(canFinishCheck({ status: 'valid', lastResultStatus: 'valid', context: { phase: 'edit-start' } })).toBe(true)
|
|
183
|
+
expect(canFinishCheck({ status: 'pending', lastResultStatus: null, context: { phase: 'change' } })).toBe(true)
|
|
184
|
+
})
|
|
185
|
+
})
|
|
186
|
+
|
|
131
187
|
describe('getCommitChecks', () => {
|
|
132
188
|
test('keeps one controller per draw adapter', () => {
|
|
133
189
|
const drawA = {}
|
|
@@ -166,16 +222,20 @@ describe('startCheckSession', () => {
|
|
|
166
222
|
const draw = {}
|
|
167
223
|
const onGeometryChange = jest.fn()
|
|
168
224
|
const onGeometryPreview = jest.fn(() => true)
|
|
169
|
-
|
|
225
|
+
const onGeometryFinish = jest.fn()
|
|
226
|
+
startCheckSession(draw, { onGeometryChange, onGeometryPreview, onGeometryFinish }, { onGeometryChange: jest.fn(), onGeometryPreview: jest.fn(), onGeometryFinish: jest.fn() })
|
|
170
227
|
expect(draw._commitValidator).toBe(onGeometryChange)
|
|
171
228
|
expect(draw._previewValidator).toBe(onGeometryPreview)
|
|
229
|
+
expect(draw._finishValidator).toBe(onGeometryFinish)
|
|
172
230
|
})
|
|
173
231
|
|
|
174
232
|
test('falls back to the plugin-level callbacks', () => {
|
|
175
233
|
const draw = {}
|
|
176
234
|
const onGeometryChange = jest.fn()
|
|
177
|
-
|
|
235
|
+
const onGeometryFinish = jest.fn()
|
|
236
|
+
startCheckSession(draw, {}, { onGeometryChange, onGeometryFinish })
|
|
178
237
|
expect(draw._commitValidator).toBe(onGeometryChange)
|
|
238
|
+
expect(draw._finishValidator).toBe(onGeometryFinish)
|
|
179
239
|
expect(draw._previewValidator).toBeUndefined()
|
|
180
240
|
})
|
|
181
241
|
|
|
@@ -184,7 +244,7 @@ describe('startCheckSession', () => {
|
|
|
184
244
|
const draw = { get: jest.fn(() => shape), delete: jest.fn() }
|
|
185
245
|
const eventBus = { emit: jest.fn() }
|
|
186
246
|
const checks = getCommitChecks(draw)
|
|
187
|
-
checks.run({ feature: shape, context: { phase: 'change' },
|
|
247
|
+
checks.run({ feature: shape, context: { phase: 'change' }, consumerCheck: () => new Promise(() => {}) })
|
|
188
248
|
checks.hold('held')
|
|
189
249
|
expect(checks.heldId).toBe('held')
|
|
190
250
|
|
|
@@ -1,23 +1,30 @@
|
|
|
1
1
|
import { COMMIT_RULES, PLACE_RULES, PREVIEW_RULES, MIN_VERTICES } from './rules.js'
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Normalise a rule / callback result into `{ valid, reason, announcement?, recheckOnFinish? }`.
|
|
4
|
+
* Normalise a rule / callback result into `{ valid, reason, announcement?, recheckOnFinish?, reopen?, properties? }`.
|
|
5
5
|
*
|
|
6
6
|
* Supports three return shapes so a user `onGeometryPreview`/`onGeometryChange` callback can stay
|
|
7
7
|
* terse:
|
|
8
8
|
* - `true` / `undefined` → valid
|
|
9
9
|
* - `false` → invalid (no reason)
|
|
10
|
-
* - `{ valid, reason, announcement, recheckOnFinish }` → passed through
|
|
10
|
+
* - `{ valid, reason, announcement, recheckOnFinish, reopen, properties }` → passed through
|
|
11
11
|
*/
|
|
12
12
|
export const normaliseResult = (result) => {
|
|
13
13
|
if (result === undefined || result === true) { return { valid: true } }
|
|
14
14
|
if (result === false) { return { valid: false, reason: null } }
|
|
15
|
-
const { valid, reason, announcement, recheckOnFinish } = result
|
|
15
|
+
const { valid, reason, announcement, recheckOnFinish, reopen, properties } = result
|
|
16
|
+
const isValid = valid !== false
|
|
16
17
|
return {
|
|
17
|
-
valid:
|
|
18
|
+
valid: isValid,
|
|
18
19
|
reason,
|
|
19
20
|
...(announcement && { announcement }),
|
|
20
|
-
...(recheckOnFinish && { recheckOnFinish: true })
|
|
21
|
+
...(recheckOnFinish && { recheckOnFinish: true }),
|
|
22
|
+
// Only a passing result can ask to reopen: a failing new shape reopens anyway. Acted on
|
|
23
|
+
// only when a new shape is finished (see createFinishHandlers in events.js).
|
|
24
|
+
...(isValid && reopen && { reopen: true }),
|
|
25
|
+
// Only a passing result can add properties: an invalid shape isn't finished. Their shape
|
|
26
|
+
// is checked when they're merged (see mergeFeatureProperties), which warns if it's wrong.
|
|
27
|
+
...(isValid && properties != null && { properties })
|
|
21
28
|
}
|
|
22
29
|
}
|
|
23
30
|
|
|
@@ -211,6 +211,24 @@ describe('normaliseResult', () => {
|
|
|
211
211
|
.toEqual({ valid: true, reason: undefined, announcement: 'Area 2 hectares', recheckOnFinish: true })
|
|
212
212
|
expect(normaliseResult({ valid: false, reason: 'too big' })).not.toHaveProperty('announcement')
|
|
213
213
|
})
|
|
214
|
+
|
|
215
|
+
test('keeps properties on a passing result only', () => {
|
|
216
|
+
const properties = { drawRules: { checked: false } }
|
|
217
|
+
expect(normaliseResult({ valid: true, properties })).toEqual({ valid: true, reason: undefined, properties })
|
|
218
|
+
expect(normaliseResult({ properties })).toHaveProperty('properties', properties)
|
|
219
|
+
expect(normaliseResult({ valid: false, reason: 'overlap', properties })).not.toHaveProperty('properties')
|
|
220
|
+
expect(normaliseResult({ valid: true, properties: null })).not.toHaveProperty('properties')
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
test('keeps reopen on a passing result only', () => {
|
|
224
|
+
expect(normaliseResult({ valid: true, reopen: true })).toEqual({ valid: true, reason: undefined, reopen: true })
|
|
225
|
+
expect(normaliseResult({ valid: false, reason: 'overlap', reopen: true })).not.toHaveProperty('reopen')
|
|
226
|
+
expect(normaliseResult({ valid: true, reopen: false })).not.toHaveProperty('reopen')
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
test('passes properties of the wrong shape on, for mergeFeatureProperties to refuse with a warning', () => {
|
|
230
|
+
expect(normaliseResult({ valid: true, properties: ['a'] })).toHaveProperty('properties', ['a'])
|
|
231
|
+
})
|
|
214
232
|
})
|
|
215
233
|
|
|
216
234
|
describe('toPlacementBlocked', () => {
|
|
@@ -21,6 +21,7 @@ export const MapProvider = ({ options, children }) => {
|
|
|
21
21
|
const mapStyle = mapStyles.find(s => s.id === savedMapStyleId) || mapStyles[0]
|
|
22
22
|
const savedMapSize = localStorage.getItem(`${options.id}:mapSize`)
|
|
23
23
|
const mapSize = savedMapSize || options.mapSize
|
|
24
|
+
dispatch({ type: 'SET_MAP_STYLES', payload: mapStyles })
|
|
24
25
|
dispatch({ type: 'SET_MAP_STYLE', payload: mapStyle })
|
|
25
26
|
dispatch({ type: 'SET_MAP_SIZE', payload: mapSize })
|
|
26
27
|
}
|
|
@@ -13,12 +13,14 @@ jest.mock('./mapReducer.js', () => {
|
|
|
13
13
|
|
|
14
14
|
const setMapReady = jest.fn((state) => ({ ...state, isMapReady: true }))
|
|
15
15
|
const setMapStyle = jest.fn((state, payload) => ({ ...state, mapStyle: payload }))
|
|
16
|
+
const setMapStyles = jest.fn((state, payload) => ({ ...state, mapStyles: payload }))
|
|
16
17
|
const setMapSize = jest.fn((state, payload) => ({ ...state, mapSize: payload }))
|
|
17
18
|
const updateCrossHair = jest.fn((state, payload) => ({ ...state, crossHair: payload }))
|
|
18
19
|
|
|
19
20
|
const actionsMap = {
|
|
20
21
|
SET_MAP_READY: setMapReady,
|
|
21
22
|
SET_MAP_STYLE: setMapStyle,
|
|
23
|
+
SET_MAP_STYLES: setMapStyles,
|
|
22
24
|
SET_MAP_SIZE: setMapSize,
|
|
23
25
|
UPDATE_CROSS_HAIR: updateCrossHair
|
|
24
26
|
}
|
|
@@ -103,6 +105,29 @@ describe('MapProvider', () => {
|
|
|
103
105
|
})
|
|
104
106
|
})
|
|
105
107
|
|
|
108
|
+
test('keeps every announced map style, and selects the saved one', () => {
|
|
109
|
+
let contextValue
|
|
110
|
+
const Child = () => {
|
|
111
|
+
contextValue = React.useContext(MapContext)
|
|
112
|
+
return null
|
|
113
|
+
}
|
|
114
|
+
localStorage.setItem('map1:mapStyleId', 'dark')
|
|
115
|
+
|
|
116
|
+
render(
|
|
117
|
+
<MapProvider options={{ id: 'map1', mapSize: '100x100', eventBus: mockEventBus }}>
|
|
118
|
+
<Child />
|
|
119
|
+
</MapProvider>
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
const mapStyles = [{ id: 'outdoor' }, { id: 'dark' }]
|
|
123
|
+
act(() => {
|
|
124
|
+
capturedHandlers['map:initmapstyles'](mapStyles)
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
expect(contextValue.mapStyles).toBe(mapStyles)
|
|
128
|
+
expect(contextValue.mapStyle).toEqual({ id: 'dark' })
|
|
129
|
+
})
|
|
130
|
+
|
|
106
131
|
test('dispatches SET_MAP_READY when MAP_READY fires', () => {
|
|
107
132
|
let contextValue
|
|
108
133
|
const Child = () => {
|
|
@@ -17,6 +17,11 @@ const setMapStyle = (state, payload) => ({
|
|
|
17
17
|
mapStyle: payload
|
|
18
18
|
})
|
|
19
19
|
|
|
20
|
+
const setMapStyles = (state, payload) => ({
|
|
21
|
+
...state,
|
|
22
|
+
mapStyles: payload
|
|
23
|
+
})
|
|
24
|
+
|
|
20
25
|
const setMapSize = (state, payload) => {
|
|
21
26
|
return {
|
|
22
27
|
...state,
|
|
@@ -67,6 +72,7 @@ export const actionsMap = {
|
|
|
67
72
|
MAP_MOVE_END: mergePayload,
|
|
68
73
|
MAP_FIRST_IDLE: mergePayload,
|
|
69
74
|
SET_MAP_STYLE: setMapStyle,
|
|
75
|
+
SET_MAP_STYLES: setMapStyles,
|
|
70
76
|
SET_MAP_SIZE: setMapSize,
|
|
71
77
|
UPDATE_CROSS_HAIR: updateCrossHair,
|
|
72
78
|
UPSERT_LOCATION_MARKER: upsertMarker,
|
|
@@ -52,6 +52,13 @@ describe('actionsMap', () => {
|
|
|
52
52
|
expect(result.otherProp).toBe(state.otherProp)
|
|
53
53
|
})
|
|
54
54
|
|
|
55
|
+
test('SET_MAP_STYLES sets mapStyles', () => {
|
|
56
|
+
const mapStyles = [{ id: 'outdoor' }, { id: 'dark' }]
|
|
57
|
+
const result = actionsMap.SET_MAP_STYLES(state, mapStyles)
|
|
58
|
+
expect(result.mapStyles).toBe(mapStyles)
|
|
59
|
+
expect(result.otherProp).toBe(state.otherProp)
|
|
60
|
+
})
|
|
61
|
+
|
|
55
62
|
test('SET_MAP_SIZE sets mapSize', () => {
|
|
56
63
|
const newSize = { width: 200, height: 200 }
|
|
57
64
|
const result = actionsMap.SET_MAP_SIZE(state, newSize)
|
|
@@ -22,6 +22,8 @@ export const initialState = (config) => {
|
|
|
22
22
|
isMapReady: false,
|
|
23
23
|
mapProvider: null,
|
|
24
24
|
mapStyle: initialMapStyle,
|
|
25
|
+
// Every map style the user can switch to — set by a plugin that handles map styles
|
|
26
|
+
mapStyles: initialMapStyle ? [initialMapStyle] : [],
|
|
25
27
|
mapSize,
|
|
26
28
|
center,
|
|
27
29
|
zoom,
|
|
@@ -39,6 +39,7 @@ describe('mapReducer', () => {
|
|
|
39
39
|
expect(state).toMatchObject({
|
|
40
40
|
isMapReady: false,
|
|
41
41
|
mapStyle: { id: 'style1' },
|
|
42
|
+
mapStyles: [{ id: 'style1' }],
|
|
42
43
|
mapSize: '100x100',
|
|
43
44
|
center: [0, 0],
|
|
44
45
|
zoom: 5,
|
|
@@ -63,6 +64,7 @@ describe('mapReducer', () => {
|
|
|
63
64
|
const state = initialState(getConfig({ mapStyle: { id: 'custom' }, center: [10, 20], zoom: 12 }))
|
|
64
65
|
|
|
65
66
|
expect(state.mapStyle).toBeNull()
|
|
67
|
+
expect(state.mapStyles).toEqual([])
|
|
66
68
|
expect(state.center).toEqual([10, 20])
|
|
67
69
|
expect(state.zoom).toBe(12)
|
|
68
70
|
})
|