@@ -774,7 +774,7 @@ describe('GeoSearch', () => {
774774 } ) ;
775775
776776 describe ( 'initial position' , ( ) => {
777- it ( 'expect to init the position from "initialPosition" when no items are available & map is not yet render ' , ( ) => {
777+ it ( 'expect to init the position from "initialPosition"' , ( ) => {
778778 const container = createContainer ( ) ;
779779 const instantSearchInstance = createFakeInstantSearch ( ) ;
780780 const helper = createFakeHelper ( ) ;
@@ -812,7 +812,7 @@ describe('GeoSearch', () => {
812812 expect ( mapInstance . setZoom ) . toHaveBeenCalledWith ( 8 ) ;
813813 } ) ;
814814
815- it ( 'expect to init the position from "position" when no items are available & map is not yet render ' , ( ) => {
815+ it ( 'expect to init the position from "position"' , ( ) => {
816816 const container = createContainer ( ) ;
817817 const instantSearchInstance = createFakeInstantSearch ( ) ;
818818 const helper = createFakeHelper ( ) ;
@@ -833,9 +833,8 @@ describe('GeoSearch', () => {
833833 } ,
834834 } ) ;
835835
836- // Simulate the configuration
837- const initialState = widget . getConfiguration ( { } ) ;
838- helper . setState ( initialState ) ;
836+ // Simulate the configuration for the position
837+ helper . setState ( widget . getConfiguration ( { } ) ) ;
839838
840839 widget . init ( {
841840 helper,
@@ -896,7 +895,7 @@ describe('GeoSearch', () => {
896895 expect ( mapInstance . setZoom ) . not . toHaveBeenCalled ( ) ;
897896 } ) ;
898897
899- it ( 'expect to not init the position when the refinement is coming from the map' , ( ) => {
898+ it ( 'expect to not init the position when the refinement is from the map' , ( ) => {
900899 const container = createContainer ( ) ;
901900 const instantSearchInstance = createFakeInstantSearch ( ) ;
902901 const helper = createFakeHelper ( ) ;
@@ -948,6 +947,60 @@ describe('GeoSearch', () => {
948947 expect ( mapInstance . setCenter ) . not . toHaveBeenCalled ( ) ;
949948 expect ( mapInstance . setZoom ) . not . toHaveBeenCalled ( ) ;
950949 } ) ;
950+
951+ it ( 'expect to not init the position when the map has moved' , ( ) => {
952+ const container = createContainer ( ) ;
953+ const instantSearchInstance = createFakeInstantSearch ( ) ;
954+ const helper = createFakeHelper ( ) ;
955+ const mapInstance = createFakeMapInstance ( ) ;
956+ const googleReference = createFakeGoogleReference ( { mapInstance } ) ;
957+
958+ const widget = geoSearch ( {
959+ googleReference,
960+ container,
961+ enableRefineOnMapMove : false ,
962+ initialZoom : 8 ,
963+ initialPosition : {
964+ lat : 10 ,
965+ lng : 12 ,
966+ } ,
967+ } ) ;
968+
969+ widget . init ( {
970+ helper,
971+ instantSearchInstance,
972+ state : helper . state ,
973+ } ) ;
974+
975+ simulateMapReadyEvent ( googleReference ) ;
976+
977+ expect ( mapInstance . setCenter ) . not . toHaveBeenCalled ( ) ;
978+ expect ( mapInstance . setZoom ) . not . toHaveBeenCalled ( ) ;
979+
980+ widget . render ( {
981+ helper,
982+ instantSearchInstance,
983+ results : {
984+ hits : [ { objectID : 123 , _geoloc : true } ] ,
985+ } ,
986+ } ) ;
987+
988+ // Simulate a refinement
989+ simulateEvent ( mapInstance , 'dragstart' ) ;
990+ simulateEvent ( mapInstance , 'center_changed' ) ;
991+ simulateEvent ( mapInstance , 'idle' ) ;
992+
993+ widget . render ( {
994+ helper,
995+ instantSearchInstance,
996+ results : {
997+ hits : [ ] ,
998+ } ,
999+ } ) ;
1000+
1001+ expect ( mapInstance . setCenter ) . not . toHaveBeenCalled ( ) ;
1002+ expect ( mapInstance . setZoom ) . not . toHaveBeenCalled ( ) ;
1003+ } ) ;
9511004 } ) ;
9521005
9531006 describe ( 'markers creation' , ( ) => {
0 commit comments