import React from 'react'; import { render, fireEvent, screen } from '@testing-library/react'; import '@testing-library/jest-dom/extend-expect'; import { Input } from '../input'; describe('Input Component', () => { it('rendered input', () => { render(); const input = screen.getByRole('textbox'); expect(input).toBeTruthy(); }); it('should render a placeholder input correctly', () => { render(); const input = screen.getByPlaceholderText('Test placeholder'); expect(input).toBeInTheDocument(); }); it('has given class names', () => { render(); const input = screen.getByRole('textbox'); expect(input).toHaveClass('test-class'); }); it('should render a disabled input correctly', () => { render(); const input = screen.getByRole('textbox'); expect(input).toHaveAttribute('disabled'); expect(input).toBeDisabled(); }); it('should be focus correctly', () => { render(); const input = screen.getByRole('textbox'); setTimeout(() => expect(input.focus).toHaveBeenCalled(), 250); }); it('should be label', () => { const { getByText } = render(); expect(getByText('Example Label')).toBeTruthy(); }); it('should be error message', () => { const error = { type: '', message: 'Error message' }; render(); const errorMessage = screen.getByText(error.message); expect(errorMessage).toBeTruthy(); }); it('should change the value without error', () => { render(); const input = screen.getByRole('textbox'); fireEvent.change(input, { target: { value: 'test' } }); expect(input).toHaveValue('test'); }); });