import "@testing-library/jest-dom"; import { TextEncoder, TextDecoder } from "util"; import React from "react"; // لازم برای بعضی از پکیج‌ها در محیط jsdom (global as any).TextEncoder = TextEncoder; (global as any).TextDecoder = TextDecoder; // فیک کردن matchMedia چون در jsdom نیست if (!window.matchMedia) { window.matchMedia = function () { return { matches: false, media: "", onchange: null, addListener() {}, removeListener() {}, addEventListener() {}, removeEventListener() {}, dispatchEvent() { return false; }, }; } as any; } // فیک کردن IntersectionObserver if (!("IntersectionObserver" in global)) { class FakeObserver { observe() {} unobserve() {} disconnect() {} } (global as any).IntersectionObserver = FakeObserver; } jest.mock("react-router-dom", () => { const actual = jest.requireActual("react-router-dom"); const wrapWithFuture = (Comp: any) => ({ children, ...rest }: any) => actual[Comp]({ children, ...rest, future: { v7_startTransition: true, v7_relativeSplatPath: true, }, }); return { ...actual, MemoryRouter: wrapWithFuture("MemoryRouter"), BrowserRouter: wrapWithFuture("BrowserRouter"), }; }); // jest.mock("@/apps/new-ui/services/Customer.ts", () => ({ // __esModule: true, // // LoyaltyCardListItem // useGetCustomerProfilePicture: () => ({ // mutateAsync: jest.fn().mockResolvedValue({ data: {} }), // }), // // CustomerCard // useGetAllCustomers: jest.fn(() => ({ // data: [], // isLoading: false, // isError: false, // refetch: jest.fn(), // })), // })); jest.mock("@/apps/new-ui/services/Customer", () => ({ __esModule: true, // For LoyaltyCardListItem useGetCustomerProfilePicture: () => ({ mutateAsync: jest.fn(() => ({ then: (resolve: any) => { resolve({ data: {} }); return { catch: () => {} }; }, catch: () => {}, })), }), // For CustomerCard useGetAllCustomers: jest.fn(() => ({ data: [], isLoading: false, isError: false, refetch: jest.fn(), })), })); // mock scrollIntoView for jsdom window.HTMLElement.prototype.scrollIntoView = function () {}; jest.spyOn(console, "log").mockImplementation(() => {}); jest.spyOn(console, "error").mockImplementation(() => {}); // Silence React Router future warnings const originalWarn = console.warn; console.warn = (...args) => { const message = args[0] || ""; if ( typeof message === "string" && (message.includes("React Router Future Flag Warning") || message.includes("v7_startTransition") || message.includes("v7_relativeSplatPath")) ) { return; } originalWarn(...args); }; jest.mock("swiper/react", () => ({ Swiper: ({ children }: any) => React.createElement("div", { "data-testid": "swiper" }, children), SwiperSlide: ({ children }: any) => React.createElement("div", { "data-testid": "slide" }, children), })); jest.mock("swiper/modules", () => ({ Navigation: {}, }));