test: comprehensive test suites and quality gates pass across backend, storefront and admin
- Backend (NestJS): 82 suites, 641 tests passing; 0 ESLint errors; 0 tsc errors. Hardened SSL cert/key matching, SSRF IP pinning, and eBank validation. - Admin Panel (Vite/React): 48 suites, 300 tests passing; 0 ESLint errors; 0 tsc errors. Full coverage across all pages and settings. - Storefront (Next.js): 62 suites, 368 tests passing; 0 ESLint errors; 0 tsc errors. - Fixed unmount lifecycle guards, promise error handling, and component edge cases.
This commit is contained in:
1 parent
1e73715169
commit
ddbf1ca026
439 files changed
+32911
-6107
No files matched your search
@@ -0,0 +1,102 @@
|
||||
"use client";
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import { render, screen, fireEvent } from "@testing-library/react";
|
||||
import React from "react";
|
||||
import OrderDetailsModal from "../OrderDetailsModal";
|
||||
|
||||
vi.mock("../lib/store/settingsStore", () => ({
|
||||
useSettingsStore: vi.fn((selector) =>
|
||||
selector({
|
||||
getText: vi.fn((key, def) => def),
|
||||
})
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock("../lib/services/api", () => ({
|
||||
default: {
|
||||
post: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock("sonner", () => ({
|
||||
toast: {
|
||||
success: vi.fn(),
|
||||
error: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
describe("OrderDetailsModal Component", () => {
|
||||
const mockOrder = {
|
||||
id: "ord-998877",
|
||||
trackingNumber: "CN-TRACK-1234",
|
||||
status: "processing",
|
||||
date: "2026-10-10T12:00:00Z",
|
||||
total: 1250000,
|
||||
charityDonation: 50000,
|
||||
shippingAddress: {
|
||||
province: "تهران",
|
||||
city: "تهران",
|
||||
address: "میدان ونک، خیابان ملاصدرا",
|
||||
postalCode: "1994912345",
|
||||
phone: "09121112233",
|
||||
recipientName: "پرهام علوی",
|
||||
},
|
||||
items: [
|
||||
{
|
||||
id: "item-1",
|
||||
quantity: 2,
|
||||
priceValue: 600000,
|
||||
product: {
|
||||
nameFa: "مکمل مفاصل پتویتال",
|
||||
imageUrl: "/products/petvital.png",
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("should render modal with order details when isOpen is true", () => {
|
||||
render(
|
||||
<OrderDetailsModal
|
||||
isOpen={true}
|
||||
onClose={vi.fn()}
|
||||
order={mockOrder}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByText(/جزئیات کامل سفارش/)).toBeInTheDocument();
|
||||
expect(screen.getByText("مکمل مفاصل پتویتال")).toBeInTheDocument();
|
||||
expect(screen.getByText("میدان ونک، خیابان ملاصدرا")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should not render when isOpen is false", () => {
|
||||
render(
|
||||
<OrderDetailsModal
|
||||
isOpen={false}
|
||||
onClose={vi.fn()}
|
||||
order={mockOrder}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.queryByText(/جزئیات کامل سفارش/)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should call onClose when back button is clicked", () => {
|
||||
const handleClose = vi.fn();
|
||||
render(
|
||||
<OrderDetailsModal
|
||||
isOpen={true}
|
||||
onClose={handleClose}
|
||||
order={mockOrder}
|
||||
/>
|
||||
);
|
||||
|
||||
const backBtn = screen.getByRole("button", { name: "بازگشت" });
|
||||
fireEvent.click(backBtn);
|
||||
|
||||
expect(handleClose).toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user