11import { render , screen } from "@testing-library/react" ;
22import userEvent from "@testing-library/user-event" ;
3+ import "@testing-library/jest-dom" ;
34
45import { MapContainer , useMapEvents } from "react-leaflet" ;
56import ResetViewControl from "../src/ResetViewControl" ;
7+ import { ResetViewControlOptions } from "../src/ResetViewControl" ;
68
79describe ( "ResetViewControl" , ( ) => {
810 const mockHandleViewReset = jest . fn ( ) ;
911
10- const ControlWrapper = ( ) => {
12+ const ControlWrapper = ( { title , icon } : ResetViewControlOptions ) => {
1113 useMapEvents ( {
1214 viewreset : mockHandleViewReset ,
1315 } ) ;
1416
1517 return (
1618 < >
17- < ResetViewControl title = "Reset view" />
19+ < ResetViewControl
20+ title = { title ?? "Reset view" }
21+ icon = { icon ?? "\u2612" }
22+ />
1823 </ >
1924 ) ;
2025 } ;
21- const Map = ( ) => {
26+ const Map = ( { title , icon } : ResetViewControlOptions ) => {
2227 return (
2328 < MapContainer zoom = { 5 } center = { [ - 96.8716348 , 32.8205866 ] } >
24- < ControlWrapper />
29+ < ControlWrapper title = { title } icon = { icon } />
2530 </ MapContainer >
2631 ) ;
2732 } ;
@@ -34,4 +39,18 @@ describe("ResetViewControl", () => {
3439
3540 expect ( mockHandleViewReset ) . toHaveBeenCalledTimes ( 2 ) ;
3641 } ) ;
42+
43+ test ( "can see icon" , ( ) => {
44+ render ( < Map /> ) ;
45+
46+ screen . getByText ( "\u2612" ) ;
47+ } ) ;
48+
49+ test ( "can set icon" , ( ) => {
50+ render ( < Map icon = "url(/some/relative/path.png)" /> ) ;
51+
52+ expect ( screen . getByTitle ( "Reset view" ) ) . toHaveStyle ( {
53+ "background-image" : "url(/some/relative/path.png)" ,
54+ } ) ;
55+ } ) ;
3756} ) ;
0 commit comments