import { render, screen, fireEvent, waitFor } from "@testing-library/react"; import MapPicker from "@/apps/new-ui/components/CustomeComponents/MapPicker"; import { notifyOnce } from "@/lib/toastManager-2"; jest.mock("@/lib/toastManager-2", () => ({ notifyOnce: jest.fn(), })); // mock map component jest.mock("@neshan-maps-platform/react-openlayers", () => { return ({ onInit }: any) => { const fakeMap = { addLayer: jest.fn(), on: jest.fn(), getView: () => ({ animate: jest.fn(), }), }; if (onInit) { setTimeout(() => onInit(fakeMap), 0); } return
; }; }); jest.mock("@neshan-maps-platform/ol", () => ({})); // Mock OpenLayers / Neshan OL constructors correctly jest.mock("@neshan-maps-platform/ol/style/Icon", () => { return jest.fn().mockImplementation(() => ({ // هرچیزی لازم نیست، فقط باید constructor باشد })); }); jest.mock("@neshan-maps-platform/ol/style/Style", () => { return jest.fn().mockImplementation(() => ({})); }); jest.mock("@neshan-maps-platform/ol/Feature", () => { return jest.fn().mockImplementation(() => ({ setStyle: jest.fn(), getGeometry: () => ({ setCoordinates: jest.fn(), }), })); }); jest.mock("@neshan-maps-platform/ol/geom/Point", () => { return jest.fn().mockImplementation(() => ({})); }); jest.mock("@neshan-maps-platform/ol/source/Vector", () => { return jest.fn().mockImplementation(() => ({ // فقط وجود داشته باشد کافیست })); }); jest.mock("@neshan-maps-platform/ol/layer/Vector", () => { return jest.fn().mockImplementation(() => ({ // فقط وجود داشته باشد کافیست })); }); jest.mock("@neshan-maps-platform/ol/proj", () => ({ fromLonLat: jest.fn(() => [100, 200]), toLonLat: jest.fn(() => [20, 10]), })); describe("MapPicker", () => { const onChange = jest.fn(); beforeEach(() => { jest.clearAllMocks(); }); it("renders map correctly", () => { render(