- 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.
84 lines
2.3 KiB
TypeScript
84 lines
2.3 KiB
TypeScript
"use client";
|
|
import { describe, it, expect, vi, beforeEach } from "vitest";
|
|
import { render, screen, fireEvent } from "@testing-library/react";
|
|
import React from "react";
|
|
import ProductImageZoomModal from "../ProductImageZoomModal";
|
|
|
|
describe("ProductImageZoomModal Component", () => {
|
|
const mockImages = [
|
|
"/images/prod-1.jpg",
|
|
"/images/prod-2.jpg",
|
|
"/images/prod-3.jpg",
|
|
];
|
|
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it("should render modal with images and controls when isOpen is true", () => {
|
|
render(
|
|
<ProductImageZoomModal
|
|
isOpen={true}
|
|
onClose={vi.fn()}
|
|
images={mockImages}
|
|
activeImage={mockImages[0]}
|
|
onSelectImage={vi.fn()}
|
|
productName="پتویتال کلسیم"
|
|
/>
|
|
);
|
|
|
|
expect(screen.getByText("پتویتال کلسیم")).toBeInTheDocument();
|
|
expect(screen.getByAltText("پتویتال کلسیم")).toBeInTheDocument();
|
|
});
|
|
|
|
it("should not render modal content when isOpen is false", () => {
|
|
render(
|
|
<ProductImageZoomModal
|
|
isOpen={false}
|
|
onClose={vi.fn()}
|
|
images={mockImages}
|
|
activeImage={mockImages[0]}
|
|
onSelectImage={vi.fn()}
|
|
productName="پتویتال کلسیم"
|
|
/>
|
|
);
|
|
|
|
expect(screen.queryByText("پتویتال کلسیم")).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("should navigate to next and previous images", () => {
|
|
const handleSelectImage = vi.fn();
|
|
render(
|
|
<ProductImageZoomModal
|
|
isOpen={true}
|
|
onClose={vi.fn()}
|
|
images={mockImages}
|
|
activeImage={mockImages[0]}
|
|
onSelectImage={handleSelectImage}
|
|
productName="پتویتال کلسیم"
|
|
/>
|
|
);
|
|
|
|
const thumbnails = screen.getAllByRole("button");
|
|
expect(thumbnails.length).toBeGreaterThan(0);
|
|
});
|
|
|
|
it("should trigger onClose when close button is clicked", () => {
|
|
const handleClose = vi.fn();
|
|
render(
|
|
<ProductImageZoomModal
|
|
isOpen={true}
|
|
onClose={handleClose}
|
|
images={mockImages}
|
|
activeImage={mockImages[0]}
|
|
onSelectImage={vi.fn()}
|
|
productName="پتویتال کلسیم"
|
|
/>
|
|
);
|
|
|
|
const closeBtn = screen.getByTitle("بستن (Esc)");
|
|
fireEvent.click(closeBtn);
|
|
expect(handleClose).toHaveBeenCalled();
|
|
});
|
|
});
|