import * as React from 'react'; import { applyTheme } from 'bumbag/utils/applyTheme'; import { Input } from '../Input'; import render from '../../utils/_tests/render'; describe('props', () => { it('should render correctly', () => { const { container } = render(); expect(container.firstChild).toMatchSnapshot(); }); it('should assign a ref via inputRef', () => { 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 when disabled', () => { const { container } = render(); expect(container.firstChild).toMatchSnapshot(); }); describe('sizes', () => { ['small', 'medium', 'large'].forEach((size) => { it(`should render ${size} correctly`, () => { const { container } = render(); expect(container.firstChild).toMatchSnapshot(); }); }); }); describe('states', () => { ['danger', 'success', 'warning', 'primary'].forEach((state) => { it(`should render ${state} correctly`, () => { const { container } = render(); expect(container.firstChild).toMatchSnapshot(); }); }); }); describe('icons', () => { ['iconAfter', 'iconBefore'].forEach((iconProp) => { it(`should render ${iconProp} correctly`, () => { const { container } = render(); expect(container.firstChild).toMatchSnapshot(); }); }); }); }); describe('theming', () => { it('Input.styles.base should render correctly', () => { const { container } = render(, { theme: { Input: { styles: { base: { backgroundColor: 'red' } } } }, }); expect(container.firstChild).toMatchSnapshot(); }); it('Input.styles.base should render correctly', () => { const { container } = render(, { theme: { Input: { styles: { base: { backgroundColor: 'red' } } } }, }); expect(container.firstChild).toMatchSnapshot(); }); it('Input.styles.base should render correctly', () => { const { container } = render(, { theme: { Input: { styles: { base: (props) => ({ backgroundColor: props.color }) } }, }, }); expect(container.firstChild).toMatchSnapshot(); }); it('Input.IconWrapper.styles.base should render correctly', () => { const { container } = render(, { theme: { Input: { IconWrapper: { styles: { base: { backgroundColor: 'red' } } } } }, }); expect(container.firstChild).toMatchSnapshot(); }); it('Input.LabelWrapper.styles.base should render correctly', () => { const { container } = render(, { theme: { Input: { LabelWrapper: { styles: { base: { backgroundColor: 'red' } } } } }, }); expect(container.firstChild).toMatchSnapshot(); }); it('Input.Label.styles.base should render correctly', () => { const { container } = render(, { theme: { Input: { Label: { styles: { base: { backgroundColor: 'red' } } } } }, }); expect(container.firstChild).toMatchSnapshot(); }); }); describe('overrides', () => { it('should render correctly', () => { const { container } = render( ); expect(container.firstChild).toMatchSnapshot(); }); }); describe('applyTheme', () => { it('renders correctly', () => { const Card = applyTheme(Input, { styles: { base: { backgroundColor: 'red', }, }, defaultProps: { altitude: '100', padding: 'major-2', }, }); const { container } = render(); expect(container.firstChild).toMatchSnapshot(); }); }); describe('variants', () => { it('styles.base should render correctly', () => { const { container } = render(, { theme: { Input: { variants: { test: { styles: { base: { backgroundColor: 'red' } } } }, }, }, }); expect(container.firstChild).toMatchSnapshot(); }); it('renders correctly for overrides', () => { const { container } = render( ); expect(container.firstChild).toMatchSnapshot(); }); it('renders correctly for applyTheme', () => { const Card = applyTheme(Input, { defaultProps: { altitude: '100', padding: 'major-2', }, variants: { test: { defaultProps: { color: 'red', }, }, }, }); const { container } = render(); expect(container.firstChild).toMatchSnapshot(); }); }); describe('modes', () => { it('should render correctly when colorMode is set globally', () => { const { container } = render(, { colorMode: 'test', theme: { Input: { modes: { test: { styles: { base: { backgroundColor: 'red' } }, defaultProps: { color: 'primaryTint' }, }, }, }, }, }); expect(container.firstChild).toMatchSnapshot(); }); it('should render correctly when colorMode set as prop', () => { const { container } = render(, { theme: { Input: { modes: { test: { styles: { base: { backgroundColor: 'red' } }, defaultProps: { color: 'primaryTint' }, }, }, }, }, }); expect(container.firstChild).toMatchSnapshot(); }); it('renders correctly for overrides', () => { const { container } = render( ); expect(container.firstChild).toMatchSnapshot(); }); it('renders correctly for applyTheme', () => { const Card = applyTheme(Input, { defaultProps: { altitude: '100', padding: 'major-2', }, modes: { test: { styles: { base: { backgroundColor: 'red' } }, defaultProps: { color: 'primaryTint' }, }, }, }); const { container } = render(); expect(container.firstChild).toMatchSnapshot(); }); }); describe('defaultProps', () => { it('should render correctly for color', () => { const { container } = render(, { theme: { Input: { defaultProps: { color: 'primary' } } }, }); expect(container.firstChild).toMatchSnapshot(); }); });