import * as React from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { TextArea } from '../TextArea';
import { ComponentClassNames } from '../../shared';
describe('TextArea component', () => {
it('should render custom classname for TextArea', async () => {
render();
const textarea = await screen.findByRole('textbox');
expect(textarea).toHaveClass('custom-class');
expect(textarea).toHaveClass(ComponentClassNames.Textarea);
});
it('should render expected classname, id TextArea field', async () => {
render(
);
const textarea = await screen.findByRole('textbox');
expect(textarea).toHaveClass('my-textarea');
expect(textarea.id).toBe('testField');
});
it('should forward ref to DOM element', async () => {
const ref = React.createRef();
render();
await screen.findByRole('textbox');
expect(ref.current?.nodeName).toBe('TEXTAREA');
});
it('should render the state attributes', async () => {
render();
const textarea = await screen.findByRole('textbox');
expect(textarea).toHaveAttribute('disabled', '');
expect(textarea).toHaveAttribute('readonly', '');
expect(textarea).toHaveAttribute('required', '');
});
it('should set size and variation data attributes', async () => {
render();
const textarea = await screen.findByRole('textbox');
expect(textarea).toHaveAttribute('data-size', 'small');
expect(textarea).toHaveAttribute('data-variation', 'quiet');
});
it('can set defaultValue (uncontrolled)', async () => {
render();
const textarea = await screen.findByRole('textbox');
expect(textarea).toHaveValue('test');
});
it('can set value (controlled component)', async () => {
// onChange added to silence console error
render(