Skip to content

Commit 861767c

Browse files
Enhance/doc coverage
1 parent c93caa4 commit 861767c

File tree

5 files changed

+353
-10
lines changed

5 files changed

+353
-10
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,12 @@ const Map = () => {
3030
};
3131
```
3232

33+
## Props
34+
35+
| Name | Type | Default | Description |
36+
|------------|----------------------------------------------------------------------|--------------|------------------------------------|
37+
| position? | [ControlOptions](https://leafletjs.com/reference.html#control-position) | "topleft" | The position of the control |
38+
| title? | string | "Reset map view" | The control title. |
39+
| icon? | string | "\u2610" | The control icon. Can be either a path for `url()` or a unicode character. |
40+
3341

__tests__/ResetViewControl.spec.tsx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,32 @@
11
import { render, screen } from "@testing-library/react";
22
import userEvent from "@testing-library/user-event";
3+
import "@testing-library/jest-dom";
34

45
import { MapContainer, useMapEvents } from "react-leaflet";
56
import ResetViewControl from "../src/ResetViewControl";
7+
import { ResetViewControlOptions } from "../src/ResetViewControl";
68

79
describe("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
});

jest.config.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)