- 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.
66 lines
1.9 KiB
TypeScript
66 lines
1.9 KiB
TypeScript
import { render, screen, fireEvent } from '@testing-library/react';
|
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
|
import OrderSuccess from '../OrderSuccess';
|
|
|
|
const mockPush = vi.fn();
|
|
vi.mock('next/navigation', () => ({
|
|
useRouter: () => ({
|
|
push: mockPush,
|
|
}),
|
|
}));
|
|
|
|
vi.mock('motion/react', () => ({
|
|
motion: {
|
|
div: ({ children, className }: any) => <div className={className}>{children}</div>,
|
|
},
|
|
}));
|
|
|
|
const mockOrders = [
|
|
{
|
|
id: 'ord-1234',
|
|
items: [{ product: { id: 'canhydrox-gag' } }],
|
|
isRefill: true,
|
|
},
|
|
];
|
|
|
|
const mockActivePet: any = { name: 'تدی' };
|
|
|
|
vi.mock('../../lib/store/cartStore', () => ({
|
|
useCartStore: () => ({
|
|
orders: mockOrders,
|
|
}),
|
|
}));
|
|
|
|
vi.mock('../../lib/store/usePetStore', () => ({
|
|
usePetStore: () => ({
|
|
getActivePet: () => mockActivePet,
|
|
}),
|
|
}));
|
|
|
|
describe('OrderSuccess Component', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it('renders order confirmation details for valid order', () => {
|
|
render(<OrderSuccess orderId="ord-1234" />);
|
|
expect(screen.getByText('سفارش شما با موفقیت ثبت شد!')).toBeInTheDocument();
|
|
expect(screen.getByText('ord-1234')).toBeInTheDocument();
|
|
expect(screen.getAllByText(/تدی/)[0]).toBeInTheDocument();
|
|
expect(screen.getByText(/Canhydrox/)).toBeInTheDocument();
|
|
expect(screen.getByText(/سرویس تمدید خودکار \(Refill\)/)).toBeInTheDocument();
|
|
});
|
|
|
|
it('navigates to tracking page when track button is clicked', () => {
|
|
render(<OrderSuccess orderId="ord-1234" />);
|
|
const trackBtn = screen.getByText('مشاهده و پیگیری زنده سفارش');
|
|
fireEvent.click(trackBtn);
|
|
expect(mockPush).toHaveBeenCalledWith('/track');
|
|
});
|
|
|
|
it('returns null if order is not found', () => {
|
|
const { container } = render(<OrderSuccess orderId="non-existing-id" />);
|
|
expect(container.firstChild).toBeNull();
|
|
});
|
|
});
|