import { render, screen, fireEvent } from '@testing-library/react'; import { describe, it, expect, vi } from 'vitest'; import { Input, SearchInput } from './input'; import { Search } from 'lucide-react'; describe('Input Component', () => { it('renders with default props', () => { render(); const input = screen.getByPlaceholderText('Enter text'); expect(input).toBeInTheDocument(); expect(input).toHaveClass('bg-kodo-graphite'); }); it('renders with label', () => { render(); const label = screen.getByText('Username'); expect(label).toBeInTheDocument(); const input = screen.getByRole('textbox'); expect(input).toBeInTheDocument(); }); it('renders with icon', () => { const icon = ; render(); const input = screen.getByPlaceholderText('Search'); expect(input).toBeInTheDocument(); expect(input).toHaveClass('pl-11'); }); it('handles onChange event', () => { const handleChange = vi.fn(); render(); const input = screen.getByRole('textbox'); fireEvent.change(input, { target: { value: 'test' } }); expect(handleChange).toHaveBeenCalledTimes(1); expect(input).toHaveValue('test'); }); it('applies custom className', () => { render(); const input = screen.getByRole('textbox'); expect(input).toHaveClass('custom-class'); }); it('handles disabled state', () => { render(); const input = screen.getByRole('textbox'); expect(input).toBeDisabled(); }); it('handles different input types', () => { const { rerender } = render(); let input = screen.getByRole('textbox'); expect(input).toHaveAttribute('type', 'email'); rerender(); input = screen.getByDisplayValue(''); expect(input).toHaveAttribute('type', 'password'); }); }); describe('SearchInput Component', () => { it('renders search input', () => { render(); const input = screen.getByPlaceholderText('Search platform...'); expect(input).toBeInTheDocument(); expect(input).toHaveAttribute('type', 'search'); expect(input).toHaveClass('rounded-full'); }); it('handles onChange event', () => { const handleChange = vi.fn(); render(); const input = screen.getByRole('searchbox'); fireEvent.change(input, { target: { value: 'test query' } }); expect(handleChange).toHaveBeenCalledTimes(1); expect(input).toHaveValue('test query'); }); it('applies custom className', () => { render(); const input = screen.getByRole('searchbox'); expect(input).toHaveClass('custom-search'); }); });