Skip to content

Commit 6f438b6

Browse files
authored
Merge branch 'master' into spring7
2 parents 8129f4a + 603e57b commit 6f438b6

2 files changed

Lines changed: 85 additions & 6 deletions

File tree

web/client/plugins/Itinerary/epics/__tests__/itinerary-test.js

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import {
4545
import { CONTROL_NAME, ITINERARY_ROUTE_LAYER } from '../../constants';
4646
import { ADD_LAYER } from '../../../../actions/layers';
4747
import { REMOVE_ADDITIONAL_LAYER, REMOVE_ALL_ADDITIONAL_LAYERS, UPDATE_ADDITIONAL_LAYER } from '../../../../actions/additionallayers';
48-
import { CHANGE_MOUSE_POINTER, ZOOM_TO_EXTENT } from '../../../../actions/map';
48+
import { CHANGE_MOUSE_POINTER, CLICK_ON_MAP, ZOOM_TO_EXTENT } from '../../../../actions/map';
4949
import { CHANGE_MAPINFO_STATE, PURGE_MAPINFO_RESULTS } from '../../../../actions/mapInfo';
5050
import { SHOW_NOTIFICATION } from '../../../../actions/notifications';
5151

@@ -328,16 +328,25 @@ describe('Itinerary Epics', () => {
328328

329329
it('should handle map click and update location', (done) => {
330330
const action = { type: SELECT_LOCATION_FROM_MAP, index: 1 };
331+
const point = { latlng: { lat: 44.4949, lng: 11.3426 } };
332+
const clickAction = { type: CLICK_ON_MAP, point };
331333

332334
const state = {
333335
itinerary: {
334336
locations: [[2.3522, 48.8566], [4.8320, 45.7578]]
335337
}
336338
};
337339

338-
testEpic(itinerarySelectLocationFromMapEpic, 1, action, (actions) => {
340+
testEpic(itinerarySelectLocationFromMapEpic, 4, [action, clickAction], (actions) => {
339341
expect(actions[0].type).toBe(CHANGE_MOUSE_POINTER);
340342
expect(actions[0].pointer).toBe('pointer');
343+
expect(actions[1].type).toBe(CHANGE_MOUSE_POINTER);
344+
expect(actions[1].pointer).toBe('auto');
345+
expect(actions[2].type).toBe(UPDATE_LOCATIONS);
346+
expect(actions[2].locations).toEqual([[2.3522, 48.8566], [11.3426, 44.4949]]);
347+
expect(actions[3].type).toBe(UPDATE_ADDITIONAL_LAYER);
348+
expect(actions[3].id).toBe(ITINERARY_ROUTE_LAYER + `_waypoint_marker_${1}`);
349+
expect(actions[3].owner).toBe(CONTROL_NAME + '_waypoint_marker');
341350
}, state, done);
342351
});
343352

@@ -355,6 +364,56 @@ describe('Itinerary Epics', () => {
355364
expect(actions[0].pointer).toBe('pointer');
356365
}, state, done);
357366
});
367+
368+
it('should cancel location selection when index is empty', (done) => {
369+
const action = { type: SELECT_LOCATION_FROM_MAP, index: null };
370+
371+
testEpic(addTimeoutEpic(itinerarySelectLocationFromMapEpic, 10), 2, action, (actions) => {
372+
expect(actions[0].type).toBe(CHANGE_MOUSE_POINTER);
373+
expect(actions[0].pointer).toBe('auto');
374+
expect(actions[1].type).toBe(TEST_TIMEOUT);
375+
expect(actions.some(({ type }) => type === UPDATE_LOCATIONS)).toBe(false);
376+
expect(actions.some(({ type }) => type === UPDATE_ADDITIONAL_LAYER)).toBe(false);
377+
}, {}, done);
378+
});
379+
380+
it('should cancel pending location selection on itinerary reset', (done) => {
381+
const point = { latlng: { lat: 44.4949, lng: 11.3426 } };
382+
const actions = [
383+
{ type: SELECT_LOCATION_FROM_MAP, index: 0 },
384+
{ type: RESET_ITINERARY },
385+
{ type: CLICK_ON_MAP, point }
386+
];
387+
388+
testEpic(addTimeoutEpic(itinerarySelectLocationFromMapEpic, 10), 3, actions, (emittedActions) => {
389+
expect(emittedActions[0].type).toBe(CHANGE_MOUSE_POINTER);
390+
expect(emittedActions[0].pointer).toBe('pointer');
391+
expect(emittedActions[1].type).toBe(CHANGE_MOUSE_POINTER);
392+
expect(emittedActions[1].pointer).toBe('auto');
393+
expect(emittedActions[2].type).toBe(TEST_TIMEOUT);
394+
expect(emittedActions.some(({ type }) => type === UPDATE_LOCATIONS)).toBe(false);
395+
expect(emittedActions.some(({ type }) => type === UPDATE_ADDITIONAL_LAYER)).toBe(false);
396+
}, {}, done);
397+
});
398+
399+
it('should cancel pending location selection when itinerary closes', (done) => {
400+
const point = { latlng: { lat: 44.4949, lng: 11.3426 } };
401+
const actions = [
402+
{ type: SELECT_LOCATION_FROM_MAP, index: 0 },
403+
{ type: SET_CONTROL_PROPERTY, control: CONTROL_NAME, value: false },
404+
{ type: CLICK_ON_MAP, point }
405+
];
406+
407+
testEpic(addTimeoutEpic(itinerarySelectLocationFromMapEpic, 10), 3, actions, (emittedActions) => {
408+
expect(emittedActions[0].type).toBe(CHANGE_MOUSE_POINTER);
409+
expect(emittedActions[0].pointer).toBe('pointer');
410+
expect(emittedActions[1].type).toBe(CHANGE_MOUSE_POINTER);
411+
expect(emittedActions[1].pointer).toBe('auto');
412+
expect(emittedActions[2].type).toBe(TEST_TIMEOUT);
413+
expect(emittedActions.some(({ type }) => type === UPDATE_LOCATIONS)).toBe(false);
414+
expect(emittedActions.some(({ type }) => type === UPDATE_ADDITIONAL_LAYER)).toBe(false);
415+
}, {}, done);
416+
});
358417
});
359418

360419
describe('onItineraryRunEpic', () => {

web/client/plugins/Itinerary/epics/itinerary.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ import { info, error as errorNotification } from '../../../actions/notifications
4343
import { createMarkerSvgDataUrl } from '../../../utils/StyleUtils';
4444

4545
const OFFSET = DEFAULT_PANEL_WIDTH;
46+
const isCancelLocationSelectionAction = ({type, control, value}) =>
47+
type === RESET_ITINERARY
48+
|| (type === SET_CONTROL_PROPERTY && control === CONTROL_NAME && !value)
49+
|| (type === TOGGLE_CONTROL && control === CONTROL_NAME);
4650

4751
/**
4852
* Handles itinerary map layout updates
@@ -188,10 +192,26 @@ export const onOpenItineraryEpic = (action$, {getState}) =>
188192
*/
189193
export const itinerarySelectLocationFromMapEpic = (action$, { getState }) =>
190194
action$.ofType(SELECT_LOCATION_FROM_MAP)
191-
.switchMap(({ index }) =>
192-
action$.ofType(CLICK_ON_MAP)
195+
.switchMap(({ index }) => {
196+
if (isNil(index) || index === '') {
197+
return Observable.of(changeMousePointer('auto'));
198+
}
199+
const cancelSelection$ = action$
200+
.ofType(RESET_ITINERARY, SET_CONTROL_PROPERTY, TOGGLE_CONTROL)
201+
.filter(isCancelLocationSelectionAction)
202+
.take(1)
203+
.map(() => ({ cancel: true }));
204+
return Observable.merge(
205+
action$.ofType(CLICK_ON_MAP)
206+
.take(1)
207+
.map(({ point }) => ({ point })),
208+
cancelSelection$
209+
)
193210
.take(1)
194211
.switchMap(({ point }) => {
212+
if (!point?.latlng) {
213+
return Observable.of(changeMousePointer('auto'));
214+
}
195215
const { latlng } = point;
196216
const state = getState();
197217
const locations = locationsSelector(state);
@@ -202,8 +222,8 @@ export const itinerarySelectLocationFromMapEpic = (action$, { getState }) =>
202222
updateLocations(newLocations),
203223
addMarkerFeature(latlng, index)
204224
);
205-
}).startWith(changeMousePointer('pointer'))
206-
);
225+
}).startWith(changeMousePointer('pointer'));
226+
});
207227

208228
/**
209229
* Handles itinerary run

0 commit comments

Comments
 (0)