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,65 @@
|
||||
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();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user