1+ import { VideoMapDrawControl } from '../../../src/mapboxgl/control/VideoMapDrawControl' ;
2+
3+ function createDrawStub ( ) {
4+ return {
5+ activate : jasmine . createSpy ( 'activate' ) ,
6+ changeMode : jasmine . createSpy ( 'changeMode' ) ,
7+ setStyles : jasmine . createSpy ( 'setStyles' ) ,
8+ getStyles : jasmine . createSpy ( 'getStyles' ) . and . returnValue ( { point : { } } ) ,
9+ getUiMode : jasmine . createSpy ( 'getUiMode' ) . and . returnValue ( 'simple_select' ) ,
10+ getSelectedIds : jasmine . createSpy ( 'getSelectedIds' ) . and . returnValue ( [ ] ) ,
11+ getMode : jasmine . createSpy ( 'getMode' ) . and . returnValue ( null ) ,
12+ delete : jasmine . createSpy ( 'delete' ) ,
13+ cancel : jasmine . createSpy ( 'cancel' )
14+ } ;
15+ }
16+
17+ function createVideoMapStub ( draw ) {
18+ return {
19+ on : jasmine . createSpy ( 'on' ) ,
20+ off : jasmine . createSpy ( 'off' ) ,
21+ _getDraw : jasmine . createSpy ( '_getDraw' ) . and . returnValue ( draw )
22+ } ;
23+ }
24+
25+ describe ( 'VideoMapDrawControl branches' , ( ) => {
26+ it ( 'binds, switches and unbinds VideoMap event listeners' , ( ) => {
27+ const firstDraw = createDrawStub ( ) ;
28+ const nextDraw = createDrawStub ( ) ;
29+ const firstVideoMap = createVideoMapStub ( firstDraw ) ;
30+ const nextVideoMap = createVideoMapStub ( nextDraw ) ;
31+ const control = new VideoMapDrawControl ( ) ;
32+ control . onAdd ( { } ) ;
33+
34+ control . setVideoMap ( firstVideoMap ) ;
35+ expect ( firstVideoMap . on . calls . count ( ) ) . toBe ( 5 ) ;
36+ expect ( firstDraw . activate ) . toHaveBeenCalled ( ) ;
37+ control . setVideoMap ( nextVideoMap ) ;
38+ expect ( firstVideoMap . off . calls . count ( ) ) . toBe ( 5 ) ;
39+ expect ( nextVideoMap . on . calls . count ( ) ) . toBe ( 5 ) ;
40+ expect ( nextDraw . activate ) . toHaveBeenCalled ( ) ;
41+
42+ control . onRemove ( ) ;
43+ expect ( nextVideoMap . off . calls . count ( ) ) . toBe ( 5 ) ;
44+ expect ( nextDraw . changeMode ) . toHaveBeenCalledWith ( 'simple_select' ) ;
45+ } ) ;
46+
47+ it ( 'forwards styles and returns null styles without a VideoMap' , ( ) => {
48+ const control = new VideoMapDrawControl ( ) ;
49+ control . setStyles ( { point : { 'circle-color' : '#f00' } } ) ;
50+ expect ( control . getStyles ( ) ) . toBeNull ( ) ;
51+
52+ const draw = createDrawStub ( ) ;
53+ const videoMap = createVideoMapStub ( draw ) ;
54+ control . setVideoMap ( videoMap ) ;
55+ const styles = { line : { 'line-width' : 5 } } ;
56+ control . setStyles ( styles ) ;
57+ expect ( videoMap . _getDraw ) . toHaveBeenCalledWith ( { styles : control . options . styles } ) ;
58+ expect ( draw . setStyles ) . toHaveBeenCalledWith ( styles ) ;
59+ expect ( control . getStyles ( ) ) . toEqual ( { point : { } } ) ;
60+ } ) ;
61+
62+ it ( 'handles missing targets and each draw/trash button action' , ( ) => {
63+ const control = new VideoMapDrawControl ( ) ;
64+ control . _onButtonClick ( { mode : 'draw_point' } ) ;
65+
66+ const draw = createDrawStub ( ) ;
67+ const videoMap = createVideoMapStub ( draw ) ;
68+ control . setVideoMap ( videoMap ) ;
69+ control . _onButtonClick ( { mode : 'draw_point' } ) ;
70+ expect ( draw . changeMode ) . toHaveBeenCalledWith ( 'draw_point' ) ;
71+
72+ draw . getUiMode . and . returnValue ( 'draw_point' ) ;
73+ control . _onButtonClick ( { mode : 'draw_point' } ) ;
74+ expect ( draw . changeMode ) . toHaveBeenCalledWith ( 'simple_select' ) ;
75+
76+ draw . getSelectedIds . and . returnValue ( [ 'feature-1' ] ) ;
77+ control . _onButtonClick ( { mode : 'trash' } ) ;
78+ expect ( draw . delete ) . toHaveBeenCalled ( ) ;
79+
80+ draw . getSelectedIds . and . returnValue ( [ ] ) ;
81+ draw . getMode . and . returnValue ( 'LineString' ) ;
82+ control . _onButtonClick ( { mode : 'trash' } ) ;
83+ expect ( draw . cancel ) . toHaveBeenCalled ( ) ;
84+ } ) ;
85+ } ) ;
0 commit comments