@@ -61,6 +61,33 @@ test('geocoder', function(tt) {
6161 setup ( { proximity : { longitude : - 79.45 , latitude : 43.65 } } ) ;
6262
6363 map . once ( 'style.load' , ( ) => {
64+ // Stub the geocoder service to return predictable coordinates for Queen Street
65+ var forwardGeocodeStub = sinon . stub ( geocoder . geocoderService , 'forwardGeocode' ) . returns ( {
66+ send : function ( ) {
67+ return Promise . resolve ( {
68+ statusCode : '200' ,
69+ body : {
70+ type : 'FeatureCollection' ,
71+ features : [ {
72+ id : 'address.123' ,
73+ type : 'Feature' ,
74+ place_type : [ 'address' ] ,
75+ text : 'Queen Street' ,
76+ place_name : 'Queen Street, Toronto, Ontario, Canada' ,
77+ center : [ - 79.3832 , 43.6532 ] ,
78+ geometry : {
79+ type : 'Point' ,
80+ coordinates : [ - 79.3832 , 43.6532 ]
81+ } ,
82+ properties : { }
83+ } ]
84+ } ,
85+ request : { } ,
86+ headers : { }
87+ } ) ;
88+ }
89+ } ) ;
90+
6491 geocoder . query ( 'Queen Street' ) ;
6592 var mapMoveSpy = sinon . spy ( map , "flyTo" ) ;
6693 geocoder . on (
@@ -71,6 +98,7 @@ test('geocoder', function(tt) {
7198 t . ok ( mapMoveSpy . calledOnce , 'the map#flyTo method was called when a result was selected' ) ;
7299 t . notEquals ( mapMoveArgs . center [ 0 ] , - 92.25 , 'center.lng changed' )
73100 t . notEquals ( mapMoveArgs . center [ 1 ] , 37.75 , 'center.lat changed' )
101+ forwardGeocodeStub . restore ( ) ;
74102 } )
75103 ) ;
76104 } ) ;
@@ -765,6 +793,32 @@ test('geocoder', function(tt) {
765793 flyTo : true
766794 } ) ;
767795
796+ var forwardGeocodeStub = sinon . stub ( geocoder . geocoderService , 'forwardGeocode' ) . returns ( {
797+ send : function ( ) {
798+ return Promise . resolve ( {
799+ statusCode : '200' ,
800+ body : {
801+ type : 'FeatureCollection' ,
802+ features : [ {
803+ id : 'poi.123' ,
804+ type : 'Feature' ,
805+ place_type : [ 'poi' ] ,
806+ text : 'Golden Gate Bridge' ,
807+ place_name : 'Golden Gate Bridge, San Francisco, California, United States' ,
808+ center : [ - 122.4802 , 37.8317 ] ,
809+ geometry : {
810+ type : 'Point' ,
811+ coordinates : [ - 122.4802 , 37.8317 ]
812+ } ,
813+ properties : { }
814+ } ]
815+ } ,
816+ request : { } ,
817+ headers : { }
818+ } ) ;
819+ }
820+ } ) ;
821+
768822 var mapFlyMethod = sinon . spy ( map , "flyTo" ) ;
769823 geocoder . query ( 'Golden Gate Bridge' ) ;
770824 geocoder . on (
@@ -775,6 +829,7 @@ test('geocoder', function(tt) {
775829 t . equals ( + calledWithArgs . center [ 0 ] . toFixed ( 4 ) , + - 122.4802 . toFixed ( 4 ) , 'the map is directed to fly to the right longitude' ) ;
776830 t . equals ( + calledWithArgs . center [ 1 ] . toFixed ( 4 ) , + 37.8317 . toFixed ( 4 ) , 'the map is directed to fly to the right latitude' ) ;
777831 t . deepEqual ( calledWithArgs . zoom , 16 , 'the map is directed to fly to the right zoom' ) ;
832+ forwardGeocodeStub . restore ( ) ;
778833 } )
779834 ) ;
780835 } ) ;
@@ -789,6 +844,33 @@ test('geocoder', function(tt) {
789844 }
790845 } ) ;
791846
847+ // Stub the geocoder service to return predictable coordinates for Golden Gate Bridge
848+ var forwardGeocodeStub = sinon . stub ( geocoder . geocoderService , 'forwardGeocode' ) . returns ( {
849+ send : function ( ) {
850+ return Promise . resolve ( {
851+ statusCode : '200' ,
852+ body : {
853+ type : 'FeatureCollection' ,
854+ features : [ {
855+ id : 'poi.123' ,
856+ type : 'Feature' ,
857+ place_type : [ 'poi' ] ,
858+ text : 'Golden Gate Bridge' ,
859+ place_name : 'Golden Gate Bridge, San Francisco, California, United States' ,
860+ center : [ - 122.4802 , 37.8317 ] ,
861+ geometry : {
862+ type : 'Point' ,
863+ coordinates : [ - 122.4802 , 37.8317 ]
864+ } ,
865+ properties : { }
866+ } ]
867+ } ,
868+ request : { } ,
869+ headers : { }
870+ } ) ;
871+ }
872+ } ) ;
873+
792874 var mapFlyMethod = sinon . spy ( map , "flyTo" ) ;
793875 geocoder . query ( 'Golden Gate Bridge' ) ;
794876 geocoder . on (
@@ -797,8 +879,10 @@ test('geocoder', function(tt) {
797879 t . ok ( mapFlyMethod . calledOnce , "The map flyTo was called when the option was set to true" ) ;
798880 var calledWithArgs = mapFlyMethod . args [ 0 ] [ 0 ] ;
799881 t . equals ( + calledWithArgs . center [ 0 ] . toFixed ( 4 ) , + - 122.4802 . toFixed ( 4 ) , 'the map is directed to fly to the right longitude' ) ;
800- t . equals ( + calledWithArgs . center [ 1 ] . toFixed ( 4 ) , + 37.8317 . toFixed ( 4 ) , 'the map is directed to fly to the right latitude' ) ; t . deepEqual ( calledWithArgs . zoom , 4 , 'the selected result overrides the constructor zoom option' ) ;
882+ t . equals ( + calledWithArgs . center [ 1 ] . toFixed ( 4 ) , + 37.8317 . toFixed ( 4 ) , 'the map is directed to fly to the right latitude' ) ;
883+ t . deepEqual ( calledWithArgs . zoom , 4 , 'the selected result overrides the constructor zoom option' ) ;
801884 t . deepEqual ( calledWithArgs . speed , 5 , 'speed argument is passed to the flyTo method' ) ;
885+ forwardGeocodeStub . restore ( ) ;
802886 } )
803887 ) ;
804888 } ) ;
@@ -1133,7 +1217,7 @@ test('geocoder', function(tt) {
11331217 geocoder . setFuzzyMatch ( true ) ;
11341218 t . equals ( geocoder . options . fuzzyMatch , true , 'setFuzzyMatch changes the fuzzyMatch value in the geocoder options' ) ;
11351219 geocoder . setFuzzyMatch ( false ) ;
1136- geocoder . query ( 'wahsingtno ' ) ;
1220+ geocoder . query ( 'wshngtn ' ) ;
11371221 geocoder . on ( 'results' , once ( function ( e ) {
11381222 t . equals ( e . features . length , 0 , 'disabling fuzzyMatch correctly affects geocoding results' ) ;
11391223 } ) ) ;
@@ -1283,11 +1367,28 @@ test('geocoder', function(tt) {
12831367 tt . test ( 'message is shown if no results are returned' , function ( t ) {
12841368 setup ( { } ) ;
12851369 var renderMessageSpy = sinon . spy ( geocoder , '_renderNoResults' ) ;
1286- geocoder . query ( 'abcdefghijkl!@#$%^&*()_+' ) ; //this will return no results
1370+
1371+ // Stub the geocoder service to return no results
1372+ var forwardGeocodeStub = sinon . stub ( geocoder . geocoderService , 'forwardGeocode' ) . returns ( {
1373+ send : function ( ) {
1374+ return Promise . resolve ( {
1375+ statusCode : '200' ,
1376+ body : {
1377+ type : 'FeatureCollection' ,
1378+ features : [ ]
1379+ } ,
1380+ request : { } ,
1381+ headers : { }
1382+ } ) ;
1383+ }
1384+ } ) ;
1385+
1386+ geocoder . query ( 'abcdefghijkl!@#$%^&*()_+' ) ;
12871387 geocoder . on (
12881388 'results' ,
12891389 once ( function ( ) {
12901390 t . ok ( renderMessageSpy . called , 'a message was rendered' ) ;
1391+ forwardGeocodeStub . restore ( ) ;
12911392 t . end ( ) ;
12921393 } )
12931394 ) ;
0 commit comments