Skip to content

Commit

Permalink
Enhance/doc coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinogagliardi authored Nov 18, 2021
1 parent c93caa4 commit 861767c
Show file tree
Hide file tree
Showing 5 changed files with 353 additions and 10 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,12 @@ const Map = () => {
};
```

## Props

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


27 changes: 23 additions & 4 deletions __tests__/ResetViewControl.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
import { render, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import "@testing-library/jest-dom";

import { MapContainer, useMapEvents } from "react-leaflet";
import ResetViewControl from "../src/ResetViewControl";
import { ResetViewControlOptions } from "../src/ResetViewControl";

describe("ResetViewControl", () => {
const mockHandleViewReset = jest.fn();

const ControlWrapper = () => {
const ControlWrapper = ({ title, icon }: ResetViewControlOptions) => {
useMapEvents({
viewreset: mockHandleViewReset,
});

return (
<>
<ResetViewControl title="Reset view" />
<ResetViewControl
title={title ?? "Reset view"}
icon={icon ?? "\u2612"}
/>
</>
);
};
const Map = () => {
const Map = ({ title, icon }: ResetViewControlOptions) => {
return (
<MapContainer zoom={5} center={[-96.8716348, 32.8205866]}>
<ControlWrapper />
<ControlWrapper title={title} icon={icon} />
</MapContainer>
);
};
Expand All @@ -34,4 +39,18 @@ describe("ResetViewControl", () => {

expect(mockHandleViewReset).toHaveBeenCalledTimes(2);
});

test("can see icon", () => {
render(<Map />);

screen.getByText("\u2612");
});

test("can set icon", () => {
render(<Map icon="url(/some/relative/path.png)" />);

expect(screen.getByTitle("Reset view")).toHaveStyle({
"background-image": "url(/some/relative/path.png)",
});
});
});
5 changes: 0 additions & 5 deletions jest.config.ts

This file was deleted.

Loading

0 comments on commit 861767c

Please sign in to comment.