import { describe, it, expect, vi, beforeEach } from 'vitest'; import { render, screen, fireEvent } from '@testing-library/react'; import Button from '../Button'; describe('Button Component', () => { beforeEach(() => { vi.clearAllMocks(); }); describe('Rendering', () => { it('should render with default props', () => { render(); const button = screen.getByRole('button', { name: /click me/i }); expect(button).toBeInTheDocument(); }); it('should render with custom text', () => { render(); expect(screen.getByRole('button', { name: /submit/i })).toBeInTheDocument(); }); it('should render with different variants', () => { const { rerender } = render(); expect(screen.getByRole('button', { name: /contained/i })).toBeInTheDocument(); rerender(); expect(screen.getByRole('button', { name: /outlined/i })).toBeInTheDocument(); rerender(); expect(screen.getByRole('button', { name: /text/i })).toBeInTheDocument(); }); }); describe('Interaction', () => { it('should call onClick when clicked', () => { const handleClick = vi.fn(); render(); fireEvent.click(screen.getByRole('button', { name: /click me/i })); expect(handleClick).toHaveBeenCalledTimes(1); }); it('should not call onClick when disabled', () => { const handleClick = vi.fn(); render(); fireEvent.click(screen.getByRole('button', { name: /disabled button/i })); expect(handleClick).not.toHaveBeenCalled(); }); }); describe('Styling', () => { it('should apply fullWidth prop', () => { render(); const button = screen.getByRole('button', { name: /full width/i }); expect(button).toHaveClass('MuiButton-fullWidth'); }); }); describe('States', () => { it('should render in loading state', () => { render(); const button = screen.getByRole('button', { name: /loading/i }); expect(button).toHaveClass('MuiButton-loading'); }); it('should render as disabled', () => { render(); const button = screen.getByRole('button', { name: /disabled/i }); expect(button).toBeDisabled(); }); }); });