22
33const test = require ( 'tape' ) ;
44const once = require ( 'lodash.once' ) ;
5+ const MapboxDirections = require ( '..' ) ;
56
6- test ( 'directions' , ( tt ) => {
7- var container , map , directions ;
7+ function setup ( ) {
8+ var container = document . createElement ( 'div' ) ;
9+ var map = new mapboxgl . Map ( { container : container , style : {
10+ "version" : 8 ,
11+ "sources" : {
12+ } ,
13+ "layers" : [
14+ {
15+ "id" : "background" , "type" : "background" ,
16+ "paint" : {
17+ "background-color" : "#fff"
18+ }
19+ } ] } } ) ;
820
9- function setup ( opts ) {
10- container = document . createElement ( 'div' ) ;
11- map = new mapboxgl . Map ( { container : container } ) ;
12- const MapboxDirections = require ( '..' ) ;
13- directions = new MapboxDirections ( opts ) ;
14- map . addControl ( directions ) ;
15- }
21+ return map ;
22+ }
1623
24+ test ( 'directions' , ( tt ) => {
1725 tt . test ( 'initialized' , t => {
18- setup ( ) ;
26+ var map = setup ( ) ;
27+ var directions = new MapboxDirections ( ) ;
28+ map . addControl ( directions ) ;
29+
1930 t . ok ( directions , 'directions is initialized' ) ;
2031 t . end ( ) ;
2132 } ) ;
2233
2334 tt . test ( 'set/get inputs' , t => {
24- setup ( {
35+ var map = setup ( ) ;
36+
37+ var directions = new MapboxDirections ( {
2538 geocoder : {
2639 proximity : [ - 79.45 , 43.65 ]
2740 }
2841 } ) ;
42+ map . addControl ( directions ) ;
43+
2944
3045 directions . setOrigin ( 'Queen Street NY' ) ;
3146 directions . setDestination ( [ - 77 , 41 ] ) ;
3247
33- directions . on ( 'origin' , function ( e ) {
48+ directions . on ( 'origin' , ( e ) => {
3449 t . ok ( directions . getOrigin ( ) , 'origin feature is present from get' ) ;
3550 t . ok ( e . feature , 'origin feature is in the event object' ) ;
3651 } ) ;
3752
38- directions . on ( 'destination' , once ( ( e ) => {
53+ directions . on ( 'destination' , ( e ) => {
3954 t . ok ( directions . getDestination ( ) , 'destination feature is present from get' ) ;
4055 t . ok ( e . feature , 'destination feature is in the event object' ) ;
41- } ) ) ;
56+ } ) ;
4257
4358 directions . on ( 'route' , once ( ( e ) => {
4459 t . ok ( e . route , 'routing data was passed' ) ;
@@ -50,3 +65,22 @@ test('directions', (tt) => {
5065 tt . end ( ) ;
5166} ) ;
5267
68+ test ( 'Directions#onRemove' , t => {
69+ var map = setup ( ) ;
70+ var directions = new MapboxDirections ( {
71+ geocoder : {
72+ proximity : [ - 79.45 , 43.65 ]
73+ }
74+ } ) ;
75+ map . addControl ( directions ) ;
76+
77+
78+ directions . setOrigin ( 'Queen Street NY' ) ;
79+ directions . setDestination ( [ - 77 , 41 ] ) ;
80+ directions . on ( 'route' , once ( ( ) => {
81+ t . true ( ! ! map . getSource ( 'directions' ) , 'directions source is added' ) ;
82+ map . removeControl ( directions ) ;
83+ t . false ( ! ! map . getSource ( 'directions' ) , 'directions source is removed' ) ;
84+ t . end ( ) ;
85+ } ) ) ;
86+ } ) ;
0 commit comments