58 lines
2.4 KiB
JavaScript
58 lines
2.4 KiB
JavaScript
// __tests__/components/pois/PoiUpdateModalWindow.test.js
|
|
|
|
import React from "react";
|
|
import { render, screen } from "@testing-library/react";
|
|
import "@testing-library/jest-dom";
|
|
import PoiUpdateModalWindow from "../../../components/pois/PoiUpdateModalWindow";
|
|
import PoiUpdateModal from "../../../components/pois/PoiUpdateModal";
|
|
|
|
// Mock the PoiUpdateModal component to avoid testing its internal implementation here
|
|
jest.mock("../../../components/pois/PoiUpdateModal", () => ({ onClose, poiData, onSubmit, latlng }) => (
|
|
<div data-testid="poi-update-modal">
|
|
<button onClick={onClose}>Close</button>
|
|
<div>POI Data: {poiData ? poiData.name : "No Data"}</div>
|
|
<div>LatLng: {latlng ? `${latlng.lat}, ${latlng.lng}` : "No Coordinates"}</div>
|
|
</div>
|
|
));
|
|
|
|
describe("PoiUpdateModalWindow", () => {
|
|
const closePoiUpdateModalMock = jest.fn();
|
|
const currentPoiDataMock = {
|
|
idPoi: "123",
|
|
name: "Test POI",
|
|
description: "Test Description",
|
|
idPoiTyp: "1",
|
|
idLD: "2",
|
|
};
|
|
|
|
const popupCoordinatesMock = { lat: 52.52, lng: 13.405 };
|
|
|
|
beforeEach(() => {
|
|
closePoiUpdateModalMock.mockClear();
|
|
});
|
|
|
|
test("renders PoiUpdateModal when showPoiUpdateModal is true", () => {
|
|
render(<PoiUpdateModalWindow showPoiUpdateModal={true} closePoiUpdateModal={closePoiUpdateModalMock} currentPoiData={currentPoiDataMock} popupCoordinates={popupCoordinatesMock} />);
|
|
|
|
// Check if the modal and its contents are in the document
|
|
expect(screen.getByTestId("poi-update-modal")).toBeInTheDocument();
|
|
expect(screen.getByText("POI Data: Test POI")).toBeInTheDocument();
|
|
expect(screen.getByText("LatLng: 52.52, 13.405")).toBeInTheDocument();
|
|
});
|
|
|
|
test("does not render PoiUpdateModal when showPoiUpdateModal is false", () => {
|
|
render(<PoiUpdateModalWindow showPoiUpdateModal={false} closePoiUpdateModal={closePoiUpdateModalMock} currentPoiData={currentPoiDataMock} popupCoordinates={popupCoordinatesMock} />);
|
|
|
|
// Check if the modal is not in the document
|
|
expect(screen.queryByTestId("poi-update-modal")).not.toBeInTheDocument();
|
|
});
|
|
|
|
test("calls closePoiUpdateModal when the close button is clicked", () => {
|
|
render(<PoiUpdateModalWindow showPoiUpdateModal={true} closePoiUpdateModal={closePoiUpdateModalMock} currentPoiData={currentPoiDataMock} popupCoordinates={popupCoordinatesMock} />);
|
|
|
|
// Click the close button
|
|
screen.getByText("Close").click();
|
|
expect(closePoiUpdateModalMock).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|