Files
salona/tests/setupTests.ts
farnoosh-krm ed3906fad6 add tests and UI modified
(fix): add appointment code in requests and profile completion reward
(test): add test coverage for multiple pages and components

(fix) - Added appointment code to the Requests section
(fix) - Added "Claim Gift" feature for completing the profile

(test) Added tests for the following pages/components:
1- Active Devices
2- Add Service
3- Appointment Request (cards display section)
4- Create Gift Card
5- Customer List component (used in Quick Booking, Advanced Booking, etc.)
6- Customer List in Customer Club
7- Delete and Edit buttons (used across the entire app)
8- Invoice
9- Create Individual Schedule Table
10- Notification SMS in SMS Center
11- Loyalty Card List
12- Loyal Customers in ResAssistant
13- Map component
14- Staff List in Staff Management
15- Services List (used in General Link, Custom Link, Advanced Booking, etc.)
16- Services List (used in Quick Booking, Gift Card, Discount Center, etc.)
2026-04-13 16:32:38 +03:30

132 lines
3.1 KiB
TypeScript

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: {},
}));