mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Add a test for the Aircraft component.
Leaflet (or maybe react-leaflet?) isn't very testable, so we can really only test that mocks were called with the right props for the leaflet components we expect, but that's still better than nothing.
This commit is contained in:
parent
71c2eb3567
commit
2c9dcd430f
53
client/src/components/aircraft/Aircraft.test.tsx
Normal file
53
client/src/components/aircraft/Aircraft.test.tsx
Normal file
@ -0,0 +1,53 @@
|
||||
import Aircraft from "./Aircraft";
|
||||
import { render } from "@testing-library/react";
|
||||
import { Icon } from "leaflet";
|
||||
|
||||
const mockMarker = jest.fn();
|
||||
jest.mock("react-leaflet", () => ({
|
||||
Marker: (props: any) => {
|
||||
mockMarker(props);
|
||||
},
|
||||
}));
|
||||
|
||||
test("grounded aircraft do not render", async () => {
|
||||
const { container } = render(
|
||||
<Aircraft
|
||||
flight={{
|
||||
id: "",
|
||||
blue: true,
|
||||
position: undefined,
|
||||
sidc: "",
|
||||
waypoints: [],
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(container).toBeEmptyDOMElement();
|
||||
});
|
||||
|
||||
test("in-flight aircraft render", async () => {
|
||||
render(
|
||||
<Aircraft
|
||||
flight={{
|
||||
id: "",
|
||||
blue: true,
|
||||
position: {
|
||||
lat: 10,
|
||||
lng: 20,
|
||||
},
|
||||
sidc: "foobar",
|
||||
waypoints: [],
|
||||
}}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(mockMarker).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
position: {
|
||||
lat: 10,
|
||||
lng: 20,
|
||||
},
|
||||
icon: expect.any(Icon),
|
||||
})
|
||||
);
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user