import * as React from 'react';
import { renderHook } from '@testing-library/react-hooks';
import { SelectField } from '../Select';
import render from '../../utils/_tests/render';
import { Size } from '../../types';
describe('props', () => {
it('should render correctly', () => {
const { container } = render(
);
expect(container.firstChild).toMatchSnapshot();
});
it('should assign a ref', () => {
const ref = React.createRef();
render(
);
expect(ref.current).toMatchSnapshot();
});
it('should render correctly with CSS props', () => {
const { container } = render(
);
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with a default value', () => {
const { container } = render(
);
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with disabled', () => {
const { container } = render(
);
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with isLoading', () => {
const { container } = render(
);
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with isRequired', () => {
const { container } = render(
);
expect(container.firstChild).toMatchSnapshot();
});
it('should render correctly with name', () => {
const { container } = render(
);
expect(container.firstChild).toMatchSnapshot();
});
['small', 'medium', 'large'].forEach((size) => {
it(`should render correctly for ${size} size`, () => {
const { container } = render(
);
expect(container.firstChild).toMatchSnapshot();
});
});
it('should render placeholder correctly', () => {
const { container } = render(
);
expect(container.firstChild).toMatchSnapshot();
});
['danger', 'warning', 'success'].forEach((state) => {
it(`should render correctly for ${state} state`, () => {
const { container } = render(
);
expect(container.firstChild).toMatchSnapshot();
});
});
});
describe('composition', () => {
describe('hook', () => {
it('should return with SelectField props', () => {
const { result } = renderHook(() =>
SelectField.useProps({
label: 'This is a label',
options: [
{ label: 'Sunny', value: 'sunny' },
{ label: 'Windy', value: 'windy' },
{ label: 'Overcast', value: 'overcast' },
],
})
);
expect(result.current).toMatchSnapshot();
});
});
});
describe('overrides', () => {
it('SelectField.base should render correctly', () => {
const { container } = render(
);
expect(container.firstChild).toMatchSnapshot();
});
});
describe('theming', () => {
it('SelectField.base should render correctly', () => {
const { container } = render(
,
{
// @ts-ignore
theme: { SelectField: { styles: { base: { backgroundColor: 'red' } } } },
}
);
expect(container.firstChild).toMatchSnapshot();
});
});
describe('defaultProps', () => {
it('should render correctly for className', () => {
const { container } = render(
,
{
// @ts-ignore
theme: { SelectField: { defaultProps: { className: 'test', color: 'primary' } } },
}
);
expect(container.firstChild).toMatchSnapshot();
});
});