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,124 @@
|
||||
"use client";
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import { render, screen, fireEvent } from "@testing-library/react";
|
||||
import React from "react";
|
||||
import OrderTracking from "../OrderTracking";
|
||||
import { useCartStore } from "../../lib/store/cartStore";
|
||||
|
||||
vi.mock("next/navigation", () => ({
|
||||
useRouter: () => ({
|
||||
push: vi.fn(),
|
||||
back: vi.fn(),
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("../../lib/store/cartStore", () => ({
|
||||
useCartStore: vi.fn(),
|
||||
}));
|
||||
|
||||
describe("OrderTracking Component", () => {
|
||||
const mockOrders = [
|
||||
{
|
||||
id: "ord-101",
|
||||
trackingNumber: "TRK-9988",
|
||||
date: "2026-10-10T12:00:00Z",
|
||||
status: "processing",
|
||||
total: 1500000,
|
||||
items: [
|
||||
{
|
||||
product: { name: "مکمل مفاصل سگ" },
|
||||
quantity: 2,
|
||||
},
|
||||
],
|
||||
shippingAddress: {
|
||||
province: "تهران",
|
||||
city: "تهران",
|
||||
detail: "خیابان ولیعصر پلاک ۱",
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "ord-102",
|
||||
trackingNumber: "TRK-7766",
|
||||
date: "2026-10-11T12:00:00Z",
|
||||
status: "delivered",
|
||||
total: 850000,
|
||||
items: [
|
||||
{
|
||||
product: { name: "روغن سالمون" },
|
||||
quantity: 1,
|
||||
},
|
||||
],
|
||||
shippingAddress: {
|
||||
province: "اصفهان",
|
||||
city: "اصفهان",
|
||||
detail: "چهارباغ عباسی",
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("should display the first order by default when orders exist", () => {
|
||||
vi.mocked(useCartStore).mockReturnValue({
|
||||
orders: mockOrders,
|
||||
} as any);
|
||||
|
||||
render(<OrderTracking />);
|
||||
|
||||
expect(screen.getByText("وضعیت لحظهای سفارش")).toBeInTheDocument();
|
||||
expect(screen.getByText("TRK-9988")).toBeInTheDocument();
|
||||
expect(screen.getByText("آمادهسازی در انبار")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should show empty state message if no orders exist", () => {
|
||||
vi.mocked(useCartStore).mockReturnValue({
|
||||
orders: [],
|
||||
} as any);
|
||||
|
||||
render(<OrderTracking />);
|
||||
|
||||
expect(
|
||||
screen.getByText(/سفارشی یافت نشد/)
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should find and display specific order when searched by tracking number", () => {
|
||||
vi.mocked(useCartStore).mockReturnValue({
|
||||
orders: mockOrders,
|
||||
} as any);
|
||||
|
||||
render(<OrderTracking />);
|
||||
|
||||
const searchInput = screen.getByPlaceholderText(
|
||||
"شماره سفارش (CN-XXXXX) یا کد رهگیری پستی را وارد کنید..."
|
||||
);
|
||||
const searchButton = screen.getByText("رهگیری آنی");
|
||||
|
||||
fireEvent.change(searchInput, { target: { value: "TRK-7766" } });
|
||||
fireEvent.click(searchButton);
|
||||
|
||||
expect(screen.getByText("TRK-7766")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("should show empty order state if search query does not match any order", () => {
|
||||
vi.mocked(useCartStore).mockReturnValue({
|
||||
orders: mockOrders,
|
||||
} as any);
|
||||
|
||||
render(<OrderTracking />);
|
||||
|
||||
const searchInput = screen.getByPlaceholderText(
|
||||
"شماره سفارش (CN-XXXXX) یا کد رهگیری پستی را وارد کنید..."
|
||||
);
|
||||
const searchButton = screen.getByText("رهگیری آنی");
|
||||
|
||||
fireEvent.change(searchInput, { target: { value: "NON-EXISTENT" } });
|
||||
fireEvent.click(searchButton);
|
||||
|
||||
expect(
|
||||
screen.getByText(/سفارشی یافت نشد/)
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user