@@ -45,7 +45,7 @@ import {
4545import { CONTROL_NAME , ITINERARY_ROUTE_LAYER } from '../../constants' ;
4646import { ADD_LAYER } from '../../../../actions/layers' ;
4747import { 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' ;
4949import { CHANGE_MAPINFO_STATE , PURGE_MAPINFO_RESULTS } from '../../../../actions/mapInfo' ;
5050import { 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' , ( ) => {
0 commit comments