import * as React from 'react'
import renderWithTheme from '../../tests/helpers/renderWithTheme'
import { RangeField } from '../'
describe('component: RangeField', () => {
test('should render a disabled RangeField', () => {
const { getByLabelText } = renderWithTheme(
)
expect(getByLabelText('Come on, type something')).toBeDisabled()
})
test('should render a success RangeField', () => {
const { getByText, getByLabelText } = renderWithTheme(
)
expect(
getByLabelText('No seriously, type something').getAttribute('aria-describedby')
).toContain(getByText('Great! you typed something!').id)
})
test('should render a warning RangeField', () => {
const { getByText, getByLabelText } = renderWithTheme(
)
expect(getByLabelText('Do it again').getAttribute('aria-describedby')).toContain(
getByText(`Really? That's all you got?`).id
)
})
test('should render an error RangeField', () => {
const { getByText, getByLabelText } = renderWithTheme(
)
expect(getByLabelText('Try again').getAttribute('aria-describedby')).toContain(
getByText(`That's it, we're done here`).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('Referred')).toBe(ref.current)
expect(ref.current).toHaveValue('42')
})
})