import userEvent from '@testing-library/user-event'
import * as React from 'react'
import renderWithTheme from '../../tests/helpers/renderWithTheme'
import TextInput from './TextInput'
describe('component: TextInput', () => {
test('should render an input with a placeholder', () => {
const { getByPlaceholderText } = renderWithTheme()
expect(getByPlaceholderText('hold my place')).toBeInTheDocument()
})
test('should support margin space props', () => {
const { getByPlaceholderText } = renderWithTheme(
)
const textInput = getByPlaceholderText('Do I wanna know?').parentElement
const styles = window.getComputedStyle(textInput as HTMLElement)
expect(styles.marginTop).toBe('16px')
})
test('should support ref prop', () => {
const ref = React.createRef()
const { getByTestId } = renderWithTheme(
)
expect(getByTestId('with-ref')).toBe(ref.current)
expect(ref.current).toHaveValue('sentinel')
})
test('should trigger onChange handler', () => {
const onChange = jest.fn()
const { getByPlaceholderText } = renderWithTheme(
)
userEvent.type(getByPlaceholderText('get this'), 'typing...')
expect(onChange).toHaveBeenCalled()
})
describe('with theme customization', () => {
test('should have 2px border', () => {
const { getByPlaceholderText } = renderWithTheme(
,
{ border: 'thick' }
)
const textInput = getByPlaceholderText('Do I wanna know?')
const styles = window.getComputedStyle(textInput)
expect(styles.borderWidth).toBe('2px')
})
test('should have 8px border radius', () => {
const { getByPlaceholderText } = renderWithTheme(
,
{ shape: 'intermediate' }
)
const textInput = getByPlaceholderText('Do I wanna know?')
const styles = window.getComputedStyle(textInput)
expect(styles.borderRadius).toBe('8px')
})
test('should have 0px border radius', () => {
const { getByPlaceholderText } = renderWithTheme(
,
{ shape: 'square' }
)
const textInput = getByPlaceholderText('Do I wanna know?')
const styles = window.getComputedStyle(textInput)
expect(styles.borderRadius).toBe('0px')
})
})
})