@@ -16,24 +16,24 @@ describe("ResetViewControl", () => {
1616 const defaultMapCenter = [ - 96.8716348 , 32.8205866 ] as LatLngExpression ;
1717 const defaultMapZoom = 5
1818
19- const ControlWrapper = ( { title, icon } : ResetViewControlOptions ) => {
19+ const ControlWrapper = ( { title, icon, centerToReset , zoomToReset } : ResetViewControlOptions ) => {
2020 useMapEvents ( {
2121 viewreset : mockHandleViewReset ,
2222 } ) ;
2323
2424 return (
25- < >
26- < ResetViewControl
27- title = { title ?? "Reset view " }
28- icon = { icon ?? "\u2612" }
29- />
30- < />
25+ < ResetViewControl
26+ title = { title ?? "Reset view" }
27+ icon = { icon ?? "\u2612 " }
28+ centerToReset = { centerToReset }
29+ zoomToReset = { zoomToReset }
30+ />
3131 ) ;
3232 } ;
33- const Map = ( { title, icon } : ResetViewControlOptions ) => {
33+ const Map = ( { title, icon, centerToReset , zoomToReset } : ResetViewControlOptions ) => {
3434 return (
3535 < MapContainer zoom = { defaultMapZoom } center = { defaultMapCenter } ref = { map => mapInstance = map } >
36- < ControlWrapper title = { title } icon = { icon } />
36+ < ControlWrapper title = { title } icon = { icon } centerToReset = { centerToReset } zoomToReset = { zoomToReset } />
3737 </ MapContainer >
3838 ) ;
3939 } ;
@@ -59,6 +59,24 @@ describe("ResetViewControl", () => {
5959 expect ( mockHandleViewReset ) . toHaveBeenCalledTimes ( 2 ) ;
6060 } ) ;
6161
62+ test ( "can reset the map view to a zoom and center different from those mounted by the map" , ( ) => {
63+ const centerToReset = [ 44.8 , 6.3 ] as LatLngExpression ;
64+ const zoomToReset = 17 ;
65+ render ( < Map centerToReset = { centerToReset } zoomToReset = { zoomToReset } /> ) ;
66+
67+ expect ( mapInstance ?. getCenter ( ) . lat ) . toBeCloseTo ( defaultMapCenter [ 0 ] , 1 ) ;
68+ expect ( mapInstance ?. getCenter ( ) . lng ) . toBeCloseTo ( defaultMapCenter [ 1 ] , 1 ) ;
69+ expect ( mapInstance ?. getZoom ( ) ) . toEqual ( defaultMapZoom )
70+
71+ userEvent . click ( screen . getByTitle ( "Reset view" ) ) ;
72+
73+ expect ( mapInstance ?. getCenter ( ) . lat ) . toBeCloseTo ( centerToReset [ 0 ] , 1 ) ;
74+ expect ( mapInstance ?. getCenter ( ) . lng ) . toBeCloseTo ( centerToReset [ 1 ] , 1 ) ;
75+ expect ( mapInstance ?. getZoom ( ) ) . toEqual ( zoomToReset )
76+
77+ expect ( mockHandleViewReset ) . toHaveBeenCalledTimes ( 3 ) ;
78+ } ) ;
79+
6280 test ( "can see icon" , ( ) => {
6381 render ( < Map /> ) ;
6482
0 commit comments