@@ -16,24 +16,24 @@ describe("ResetViewControl", () => {
16
16
const defaultMapCenter = [ - 96.8716348 , 32.8205866 ] as LatLngExpression ;
17
17
const defaultMapZoom = 5
18
18
19
- const ControlWrapper = ( { title, icon } : ResetViewControlOptions ) => {
19
+ const ControlWrapper = ( { title, icon, centerToReset , zoomToReset } : ResetViewControlOptions ) => {
20
20
useMapEvents ( {
21
21
viewreset : mockHandleViewReset ,
22
22
} ) ;
23
23
24
24
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
+ />
31
31
) ;
32
32
} ;
33
- const Map = ( { title, icon } : ResetViewControlOptions ) => {
33
+ const Map = ( { title, icon, centerToReset , zoomToReset } : ResetViewControlOptions ) => {
34
34
return (
35
35
< 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 } />
37
37
</ MapContainer >
38
38
) ;
39
39
} ;
@@ -59,6 +59,24 @@ describe("ResetViewControl", () => {
59
59
expect ( mockHandleViewReset ) . toHaveBeenCalledTimes ( 2 ) ;
60
60
} ) ;
61
61
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
+
62
80
test ( "can see icon" , ( ) => {
63
81
render ( < Map /> ) ;
64
82
0 commit comments