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,133 @@
|
||||
"use client";
|
||||
import { describe, it, expect, vi, beforeEach } from "vitest";
|
||||
import { render, screen, fireEvent } from "@testing-library/react";
|
||||
import React from "react";
|
||||
import ProductDetailModal from "../catalog/ProductDetailModal";
|
||||
import { Product } from "../../lib/data/products";
|
||||
|
||||
// Mock SafeImage
|
||||
vi.mock("../SafeImage", () => ({
|
||||
default: ({ src, alt, className }: { src: string; alt: string; className?: string }) => (
|
||||
<img src={src} alt={alt} className={className} data-testid="safe-image" />
|
||||
),
|
||||
}));
|
||||
|
||||
const mockProduct: Product = {
|
||||
id: "canhydrox-gag-100",
|
||||
artNo: "12345",
|
||||
name: "Canina Canhydrox GAG",
|
||||
category: "مفاصل و استخوان",
|
||||
price: "۱,۲۰۰,۰۰۰ تومان",
|
||||
priceValue: 1200000,
|
||||
image: "/images/canhydrox.png",
|
||||
unit: "100 عدد قرص",
|
||||
packageSize: 100,
|
||||
suitableFor: "سگهای تمامی نژادها",
|
||||
scientificTagline: "فرمول پیشرفته تقویت غضروف و مفاصل",
|
||||
description: "<p>محصولی فوقالعاده برای بازسازی مفاصل و پیشگیری از آرتروز</p>",
|
||||
main_ingredients: ["هیدروکسی آپاتیت", "عصاره صدف سبز", "سیلیکا"],
|
||||
dosage_logic: "روزانه ۲ عدد قرص به ازای هر ۱۰ کیلوگرم وزن بدن",
|
||||
specialist: {
|
||||
name: "دکتر مریم حسینی",
|
||||
title: "متخصص ارتوپدی دامپزشکی",
|
||||
message: "بهترین انتخاب برای رفع ناهنجاریهای مفصلی و اسکلتی تولهها و سگهای مسن.",
|
||||
image: "/images/specialist.png",
|
||||
},
|
||||
symptoms: ["درد مفاصل", "لنگش"],
|
||||
benefits: "افزایش انعطافپذیری و مقاومت استخوان",
|
||||
calculateDosage: vi.fn(),
|
||||
};
|
||||
|
||||
describe("ProductDetailModal Component (Catalog)", () => {
|
||||
const mockOnClose = vi.fn();
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("renders nothing when product is null", () => {
|
||||
const { container } = render(
|
||||
<ProductDetailModal product={null} onClose={mockOnClose} />
|
||||
);
|
||||
expect(container.firstChild).toBeNull();
|
||||
});
|
||||
|
||||
it("renders product information correctly when product is provided", () => {
|
||||
render(
|
||||
<ProductDetailModal
|
||||
product={mockProduct}
|
||||
categoryColor="#0284C7"
|
||||
onClose={mockOnClose}
|
||||
/>
|
||||
);
|
||||
|
||||
// Title and Category
|
||||
expect(screen.getByText("Canina Canhydrox GAG")).toBeInTheDocument();
|
||||
expect(screen.getByText("مفاصل و استخوان")).toBeInTheDocument();
|
||||
expect(screen.getByText(/کد کالا: 12345/)).toBeInTheDocument();
|
||||
expect(screen.getByText("فرمول پیشرفته تقویت غضروف و مفاصل")).toBeInTheDocument();
|
||||
|
||||
// Unit & Suitable for
|
||||
expect(screen.getByText(/وزن\/حجم: 100 عدد قرص/)).toBeInTheDocument();
|
||||
expect(screen.getByText(/مناسب: سگهای تمامی نژادها/)).toBeInTheDocument();
|
||||
expect(screen.getByText("گرید دارویی آلمان")).toBeInTheDocument();
|
||||
|
||||
// Description (HTML sanitized)
|
||||
expect(screen.getByText(/محصولی فوقالعاده برای بازسازی مفاصل/)).toBeInTheDocument();
|
||||
|
||||
// Ingredients
|
||||
expect(screen.getByText("هیدروکسی آپاتیت")).toBeInTheDocument();
|
||||
expect(screen.getByText("عصاره صدف سبز")).toBeInTheDocument();
|
||||
expect(screen.getByText("سیلیکا")).toBeInTheDocument();
|
||||
|
||||
// Clinical dosage
|
||||
expect(screen.getByText("دستور مصرف بالینی و دوز توصیه شده:")).toBeInTheDocument();
|
||||
expect(screen.getByText("روزانه ۲ عدد قرص به ازای هر ۱۰ کیلوگرم وزن بدن")).toBeInTheDocument();
|
||||
|
||||
// Specialist advice
|
||||
expect(screen.getByText("دکتر مریم حسینی")).toBeInTheDocument();
|
||||
expect(screen.getByText("(متخصص ارتوپدی دامپزشکی)")).toBeInTheDocument();
|
||||
expect(screen.getByText(/بهترین انتخاب برای رفع ناهنجاریهای مفصلی/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("calls onClose when close button in header or footer is clicked", () => {
|
||||
render(
|
||||
<ProductDetailModal
|
||||
product={mockProduct}
|
||||
categoryColor="#10B981"
|
||||
onClose={mockOnClose}
|
||||
/>
|
||||
);
|
||||
|
||||
// Click header close button (aria-label="بستن")
|
||||
const headerCloseBtn = screen.getByLabelText("بستن");
|
||||
fireEvent.click(headerCloseBtn);
|
||||
expect(mockOnClose).toHaveBeenCalledTimes(1);
|
||||
|
||||
// Click footer close button ("بستن جزئیات")
|
||||
const footerCloseBtn = screen.getByText("بستن جزئیات");
|
||||
fireEvent.click(footerCloseBtn);
|
||||
expect(mockOnClose).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
|
||||
it("renders plain text description if description does not contain HTML tags", () => {
|
||||
const plainProduct = {
|
||||
...mockProduct,
|
||||
description: "این یک توضیح متنی ساده بدون هیچ برچسب اچتیامال است.",
|
||||
main_ingredients: [],
|
||||
dosage_logic: undefined,
|
||||
specialist: undefined,
|
||||
};
|
||||
|
||||
render(
|
||||
<ProductDetailModal
|
||||
product={plainProduct}
|
||||
onClose={mockOnClose}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByText("این یک توضیح متنی ساده بدون هیچ برچسب اچتیامال است.")).toBeInTheDocument();
|
||||
expect(screen.queryByText("ترکیبات فعال و مواد موثره دارویی:")).not.toBeInTheDocument();
|
||||
expect(screen.queryByText("دستور مصرف بالینی و دوز توصیه شده:")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user