import React from 'react';
import { render } from '@testing-library/react';
import { colors } from '../../../constants';
import Dropdown, { Option } from './Dropdown';
describe('', () => {
it('renders the Dropdown with options', () => {
const { container } = render(
,
);
expect(container.firstChild).toMatchSnapshot();
});
it('renders the Dropdown with one option', () => {
const { container } = render(
,
);
expect(container.firstChild).toMatchSnapshot();
});
it('renders the Dropdown with options and a default selected value', () => {
const { container } = render(
,
);
expect(container.firstChild).toMatchSnapshot();
});
it('renders the Dropdown with options passed through an array.map', () => {
const options = [
{ value: 'value1', text: 'value1' },
{ value: 'value2', text: 'value2' },
];
const { container } = render(
{options.map(({ value, text }) => (
))}
,
);
expect(container.firstChild).toMatchSnapshot();
});
test.each`
hasError | expectBorderColor
${false} | ${colors.grey}
${undefined} | ${colors.grey}
${true} | ${colors.alert}
`(
'renders the border with the "$expectBorderColor" color if the hasError is "$hasError"',
({ hasError, expectBorderColor }) => {
const { container } = render(
,
);
expect(container.firstChild).toHaveStyleRule('border', expect.stringContaining(expectBorderColor));
},
);
test.each`
isValid | expectBorderColor
${false} | ${colors.grey}
${undefined} | ${colors.grey}
${true} | ${colors.success}
`(
'renders the border with the "$expectBorderColor" color if the isValid is "$isValid"',
({ isValid, expectBorderColor }) => {
const { container } = render(
,
);
expect(container.firstChild).toHaveStyleRule('border', expect.stringContaining(expectBorderColor));
},
);
});