- 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.
80 lines
2.4 KiB
TypeScript
80 lines
2.4 KiB
TypeScript
import { render, screen, fireEvent } from '@testing-library/react';
|
|
import { describe, it, expect, vi } from 'vitest';
|
|
import DeleteConfirmModal from '../DeleteConfirmModal';
|
|
|
|
vi.mock('motion/react', () => ({
|
|
motion: {
|
|
div: ({ children, className, onClick }: any) => (
|
|
<div className={className} onClick={onClick}>
|
|
{children}
|
|
</div>
|
|
),
|
|
},
|
|
AnimatePresence: ({ children }: any) => <>{children}</>,
|
|
}));
|
|
|
|
describe('DeleteConfirmModal Component', () => {
|
|
it('does not render anything when isOpen is false', () => {
|
|
const { container } = render(
|
|
<DeleteConfirmModal
|
|
isOpen={false}
|
|
onClose={vi.fn()}
|
|
onConfirm={vi.fn()}
|
|
title="حذف آیتم"
|
|
message="آیا مطمئن هستید؟"
|
|
/>,
|
|
);
|
|
expect(container.firstChild).toBeNull();
|
|
});
|
|
|
|
it('renders modal content correctly when isOpen is true', () => {
|
|
render(
|
|
<DeleteConfirmModal
|
|
isOpen={true}
|
|
onClose={vi.fn()}
|
|
onConfirm={vi.fn()}
|
|
title="حذف آدرس"
|
|
message="آدرس مورد نظر به طور کامل حذف خواهد شد."
|
|
/>,
|
|
);
|
|
expect(screen.getByText('حذف آدرس')).toBeInTheDocument();
|
|
expect(
|
|
screen.getByText('آدرس مورد نظر به طور کامل حذف خواهد شد.'),
|
|
).toBeInTheDocument();
|
|
expect(screen.getByText('خیر، بماند')).toBeInTheDocument();
|
|
expect(screen.getByText('بله، حذف شود')).toBeInTheDocument();
|
|
});
|
|
|
|
it('calls onClose when cancel button is clicked', () => {
|
|
const handleClose = vi.fn();
|
|
render(
|
|
<DeleteConfirmModal
|
|
isOpen={true}
|
|
onClose={handleClose}
|
|
onConfirm={vi.fn()}
|
|
title="حذف پت"
|
|
message="آیا مطمئن هستید؟"
|
|
/>,
|
|
);
|
|
fireEvent.click(screen.getByText('خیر، بماند'));
|
|
expect(handleClose).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('calls onConfirm AND onClose when confirm button is clicked', () => {
|
|
const handleClose = vi.fn();
|
|
const handleConfirm = vi.fn();
|
|
render(
|
|
<DeleteConfirmModal
|
|
isOpen={true}
|
|
onClose={handleClose}
|
|
onConfirm={handleConfirm}
|
|
title="حذف پت"
|
|
message="آیا مطمئن هستید؟"
|
|
/>,
|
|
);
|
|
fireEvent.click(screen.getByText('بله، حذف شود'));
|
|
expect(handleConfirm).toHaveBeenCalledTimes(1);
|
|
expect(handleClose).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|