- 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.
63 lines
2.1 KiB
TypeScript
63 lines
2.1 KiB
TypeScript
import { fireEvent,render,screen } from '@testing-library/react';
|
|
import { describe,expect,it,vi } from 'vitest';
|
|
import Button from './Button';
|
|
|
|
describe('Button Component', () => {
|
|
it('renders children correctly', () => {
|
|
render(<Button>کلیک کنید</Button>);
|
|
expect(screen.getByRole('button', { name: 'کلیک کنید' })).toBeInTheDocument();
|
|
});
|
|
|
|
it('renders with different variants and size styling classes', () => {
|
|
const { rerender } = render(<Button variant="danger" size="sm">حذف</Button>);
|
|
let btn = screen.getByRole('button');
|
|
expect(btn.className).toContain('bg-rose-600');
|
|
expect(btn.className).toContain('px-3');
|
|
|
|
rerender(<Button variant="success" size="lg">تایید</Button>);
|
|
btn = screen.getByRole('button');
|
|
expect(btn.className).toContain('bg-emerald-600');
|
|
expect(btn.className).toContain('px-5');
|
|
});
|
|
|
|
it('handles click events when enabled', () => {
|
|
const handleClick = vi.fn();
|
|
render(<Button onClick={handleClick}>کلیک</Button>);
|
|
|
|
fireEvent.click(screen.getByRole('button'));
|
|
expect(handleClick).toHaveBeenCalledTimes(1);
|
|
});
|
|
|
|
it('shows spinner and disables button when isLoading is true', () => {
|
|
const handleClick = vi.fn();
|
|
render(<Button isLoading onClick={handleClick}>ارسال</Button>);
|
|
|
|
const btn = screen.getByRole('button');
|
|
expect(btn).toBeDisabled();
|
|
expect(screen.queryByText('ارسال')).not.toBeInTheDocument();
|
|
|
|
fireEvent.click(btn);
|
|
expect(handleClick).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('renders startIcon, endIcon, badge, and info tooltip correctly', () => {
|
|
const MockIcon = ({ className }: { className?: string }) => <svg data-testid="mock-icon" className={className} />;
|
|
|
|
render(
|
|
<Button
|
|
startIcon={MockIcon}
|
|
endIcon={MockIcon}
|
|
badge={5}
|
|
info="اطلاعات کمکی"
|
|
>
|
|
آیتم
|
|
</Button>
|
|
);
|
|
|
|
const icons = screen.getAllByTestId('mock-icon');
|
|
expect(icons.length).toBe(2);
|
|
expect(screen.getByText('5')).toBeInTheDocument();
|
|
expect(screen.getByTitle('اطلاعات کمکی')).toBeInTheDocument();
|
|
});
|
|
});
|