@@ -8,12 +8,13 @@ import { MapContainer, useMapEvents } from "react-leaflet";
8
8
import ResetViewControl from "../src/ResetViewControl" ;
9
9
10
10
import type { ResetViewControlOptions } from "../src/ResetViewControl" ;
11
- import type { LatLngExpression , Map } from "leaflet" ;
11
+ import { LatLng } from "leaflet" ;
12
+ import type { Map } from "leaflet" ;
12
13
13
14
describe ( "ResetViewControl" , ( ) => {
14
15
const mockHandleViewReset = jest . fn ( ) ;
15
16
let mapInstance = null as Map | null
16
- const defaultMapCenter = [ - 96.8716348 , 32.8205866 ] as LatLngExpression ;
17
+ const defaultMapCenter = new LatLng ( - 96.8716348 , 32.8205866 ) ;
17
18
const defaultMapZoom = 5
18
19
19
20
const ControlWrapper = ( { title, icon, centerToReset, zoomToReset } : ResetViewControlOptions ) => {
@@ -40,38 +41,38 @@ describe("ResetViewControl", () => {
40
41
41
42
test ( "can reset map view" , ( ) => {
42
43
render ( < Map /> ) ;
43
- expect ( mapInstance ?. getCenter ( ) . lat ) . toBeCloseTo ( defaultMapCenter [ 0 ] , 1 ) ;
44
- expect ( mapInstance ?. getCenter ( ) . lng ) . toBeCloseTo ( defaultMapCenter [ 1 ] , 1 ) ;
44
+ expect ( mapInstance ?. getCenter ( ) . lat ) . toBeCloseTo ( defaultMapCenter . lat , 1 ) ;
45
+ expect ( mapInstance ?. getCenter ( ) . lng ) . toBeCloseTo ( defaultMapCenter . lng , 1 ) ;
45
46
expect ( mapInstance ?. getZoom ( ) ) . toEqual ( defaultMapZoom )
46
47
47
- mapInstance ?. setView ( [ 2 , 46 ] , 6 )
48
+ mapInstance ?. setView ( new LatLng ( 2 , 46 ) , 6 )
48
49
49
50
expect ( mapInstance ?. getCenter ( ) . lat ) . toBeCloseTo ( 2 , 1 ) ;
50
51
expect ( mapInstance ?. getCenter ( ) . lng ) . toBeCloseTo ( 46 , 1 ) ;
51
52
expect ( mapInstance ?. getZoom ( ) ) . toEqual ( 6 )
52
53
53
54
userEvent . click ( screen . getByTitle ( "Reset view" ) ) ;
54
55
55
- expect ( mapInstance ?. getCenter ( ) . lat ) . toBeCloseTo ( defaultMapCenter [ 0 ] , 1 ) ;
56
- expect ( mapInstance ?. getCenter ( ) . lng ) . toBeCloseTo ( defaultMapCenter [ 1 ] , 1 ) ;
56
+ expect ( mapInstance ?. getCenter ( ) . lat ) . toBeCloseTo ( defaultMapCenter . lat , 1 ) ;
57
+ expect ( mapInstance ?. getCenter ( ) . lng ) . toBeCloseTo ( defaultMapCenter . lng , 1 ) ;
57
58
expect ( mapInstance ?. getZoom ( ) ) . toEqual ( defaultMapZoom )
58
59
59
60
expect ( mockHandleViewReset ) . toHaveBeenCalledTimes ( 2 ) ;
60
61
} ) ;
61
62
62
63
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 centerToReset = new LatLng ( 44.8 , 6.3 ) ;
64
65
const zoomToReset = 17 ;
65
66
render ( < Map centerToReset = { centerToReset } zoomToReset = { zoomToReset } /> ) ;
66
67
67
- expect ( mapInstance ?. getCenter ( ) . lat ) . toBeCloseTo ( defaultMapCenter [ 0 ] , 1 ) ;
68
- expect ( mapInstance ?. getCenter ( ) . lng ) . toBeCloseTo ( defaultMapCenter [ 1 ] , 1 ) ;
68
+ expect ( mapInstance ?. getCenter ( ) . lat ) . toBeCloseTo ( defaultMapCenter . lat , 1 ) ;
69
+ expect ( mapInstance ?. getCenter ( ) . lng ) . toBeCloseTo ( defaultMapCenter . lng , 1 ) ;
69
70
expect ( mapInstance ?. getZoom ( ) ) . toEqual ( defaultMapZoom )
70
71
71
72
userEvent . click ( screen . getByTitle ( "Reset view" ) ) ;
72
73
73
- expect ( mapInstance ?. getCenter ( ) . lat ) . toBeCloseTo ( centerToReset [ 0 ] , 1 ) ;
74
- expect ( mapInstance ?. getCenter ( ) . lng ) . toBeCloseTo ( centerToReset [ 1 ] , 1 ) ;
74
+ expect ( mapInstance ?. getCenter ( ) . lat ) . toBeCloseTo ( centerToReset . lat , 1 ) ;
75
+ expect ( mapInstance ?. getCenter ( ) . lng ) . toBeCloseTo ( centerToReset . lng , 1 ) ;
75
76
expect ( mapInstance ?. getZoom ( ) ) . toEqual ( zoomToReset )
76
77
77
78
expect ( mockHandleViewReset ) . toHaveBeenCalledTimes ( 3 ) ;
0 commit comments