// __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 }) => (
POI Data: {poiData ? poiData.name : "No Data"}
LatLng: {latlng ? `${latlng.lat}, ${latlng.lng}` : "No Coordinates"}
));
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();
// 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();
// 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();
// Click the close button
screen.getByText("Close").click();
expect(closePoiUpdateModalMock).toHaveBeenCalledTimes(1);
});
});