import userEvent from '@testing-library/user-event' import * as React from 'react' import renderWithTheme from '../../tests/helpers/renderWithTheme' import TextAreaField from './TextAreaField' describe('component: TextAreaField', () => { test('should render a disabled TextAreaField', () => { const { getByLabelText } = renderWithTheme( ) expect(getByLabelText('boolest')).toBeDisabled() }) test('should render a TextAreaField with a placeholder', () => { const { getByPlaceholderText } = renderWithTheme( ) expect(getByPlaceholderText('no question about it')).toBeInTheDocument() }) test('should render a success TextAreaField', () => { const { getByText, getByLabelText } = renderWithTheme( ) expect(getByLabelText('master of darts').getAttribute('aria-describedby')).toContain( getByText('undoubtedly').id ) }) test('should render a warning TextAreaField', () => { const { getByText, getByLabelText } = renderWithTheme( ) expect(getByLabelText('master of darts').getAttribute('aria-describedby')).toContain( getByText('undoubtedly').id ) }) test('should render an error TextAreaField', () => { const { getByText, getByLabelText } = renderWithTheme( ) expect(getByLabelText('master of darts').getAttribute('aria-describedby')).toContain( getByText('undoubtedly').id ) }) test('should support margin space props', () => { const { getByTestId } = renderWithTheme( <> ) const blank = { marginTop: '', marginRight: '', marginBottom: '', marginLeft: '' } expect(getByTestId('first').parentElement?.parentElement).toHaveStyle(blank) expect(getByTestId('default').parentElement?.parentElement).toHaveStyle({ ...blank, marginTop: '16px', marginBottom: '4px', }) expect(getByTestId('override').parentElement?.parentElement).toHaveStyle({ ...blank, marginTop: '2px', }) }) test('should support flex item props', () => { const { container } = renderWithTheme( ) expect(container.firstElementChild).toHaveStyle('flex: 1') expect(container.firstElementChild).toHaveStyle('flex-grow: 1') expect(container.firstElementChild).toHaveStyle('flex-shrink: 0') expect(container.firstElementChild).toHaveStyle('flex-basis: 0') }) test('should support ref prop', () => { const ref = React.createRef() const { getByLabelText } = renderWithTheme( ) expect(getByLabelText('Arreff Them!')).toBe(ref.current) expect(ref.current).toHaveValue('something') }) test('should trigger onChange handler', () => { const onChange = jest.fn() const { getByPlaceholderText } = renderWithTheme( ) userEvent.type(getByPlaceholderText('punch some throats'), 'miss you buddy') expect(onChange).toHaveBeenCalled() }) })