import React from 'react'; import { shallow, mount } from 'enzyme'; import { Input } from '../'; describe('Input', () => { it('should render with "input" tag when no type is provided', () => { const wrapper = shallow(Yo!); expect(wrapper.type()).toBe('input'); }); it('should render with "type" tag when type is "select"', () => { const wrapper = shallow(Yo!); expect(wrapper.type()).toBe('select'); }); it('should render with "textarea" tag when type is "textarea"', () => { const wrapper = shallow(Yo!); expect(wrapper.type()).toBe('textarea'); }); it('should render with "input" tag when plaintext prop is truthy', () => { const wrapper = shallow(); expect(wrapper.type()).toBe('input'); }); it('should render with "form-control-plaintext" class when plaintext prop is truthy', () => { const wrapper = shallow(); expect(wrapper.hasClass('form-control-plaintext')).toBe(true); }); it('should not render with "form-control" class when plaintext prop is truthy', () => { const wrapper = shallow(); expect(wrapper.hasClass('form-control')).toBe(false); }); it('should render with custom tag when plaintext prop is truthy and tag is provided', () => { const wrapper = shallow(); expect(wrapper.type()).toBe('div'); }); it('should render with custom tag when plaintext prop is not truthy and tag is provided', () => { const wrapper = shallow(); expect(wrapper.type()).toBe('div'); }); it('should render with "input" tag when type is not a special case', () => { const wrapper = shallow(); expect(wrapper.type()).toBe('input'); }); it('should not render children', () => { const wrapper = shallow(Yo!); expect(wrapper.text()).toBe(''); }); it('should render without children when type is "textarea"', () => { const wrapper = shallow(Yo!); expect(wrapper.text()).toBe(''); }); it('should render children when type is select', () => { const wrapper = shallow(Yo!); expect(wrapper.text()).toBe('Yo!'); }); it('should render children when tag is select', () => { const wrapper = shallow(Yo!); expect(wrapper.text()).toBe('Yo!'); }); it('should pass children when tag is a custom component', () => { const wrapper = mount( props.children}>Yo!); expect(wrapper.text()).toBe('Yo!'); }); it('should not render with "is-invalid" class when valid is false', () => { const wrapper = shallow(); expect(wrapper.hasClass('is-invalid')).toBe(false); }); it('should not render with "is-valid" class when invalid is false', () => { const wrapper = shallow(); expect(wrapper.hasClass('is-valid')).toBe(false); }); it('should render with "is-invalid" class when invalid is true', () => { const wrapper = shallow(); expect(wrapper.hasClass('is-invalid')).toBe(true); }); it('should render with "is-valid" class when valid is true', () => { const wrapper = shallow(); expect(wrapper.hasClass('is-valid')).toBe(true); }); it('should render with "form-control-${size}" class when size is "lg" or "sm"', () => { const wrapper = shallow(); expect(wrapper.hasClass('form-control-lg')).toBe(true); }); it('should render with "form-control" class when size is nor "lg" nor "sm"', () => { const wrapper = shallow(); expect(wrapper.hasClass('form-control-sm')).toBe(false); expect(wrapper.hasClass('form-control-lg')).toBe(false); expect(wrapper.hasClass('form-control')).toBe(true); }); it('should render with "form-control-${bsSize}" class when bsSize is provided', () => { const wrapper = shallow(); expect(wrapper.hasClass('form-control-sm')).toBe(true); }); it('should render with "form-control" class by default', () => { const wrapper = shallow(); expect(wrapper.hasClass('form-control')).toBe(true); }); it('should not render with "form-control-file" nor "form-control-plaintext" nor "form-check-input" class by default', () => { const wrapper = shallow(); expect(wrapper.hasClass('form-control-file')).toBe(false); expect(wrapper.hasClass('form-control-plaintext')).toBe(false); expect(wrapper.hasClass('form-check-input')).toBe(false); }); it('should not render with "form-control" nor "form-control-plaintext" nor "form-check-input" class when type is file', () => { const wrapper = shallow(); expect(wrapper.hasClass('form-control')).toBe(false); expect(wrapper.hasClass('form-control-plaintext')).toBe(false); expect(wrapper.hasClass('form-check-input')).toBe(false); }); it('should not render with "form-control-file" nor "form-control" nor "form-check-input" class when plaintext prop is truthy', () => { const wrapper = shallow(); expect(wrapper.hasClass('form-control-file')).toBe(false); expect(wrapper.hasClass('form-control')).toBe(false); expect(wrapper.hasClass('form-check-input')).toBe(false); }); it('should not render with "form-control-file" nor "form-control-plaintext" nor "form-control" class when type is radio', () => { const wrapper = shallow(); expect(wrapper.hasClass('form-control-file')).toBe(false); expect(wrapper.hasClass('form-control-plaintext')).toBe(false); expect(wrapper.hasClass('form-control')).toBe(false); }); it('should not render with "form-control-file" nor "form-control-plaintext" nor "form-control" class when type is checkbox', () => { const wrapper = shallow(); expect(wrapper.hasClass('form-control-file')).toBe(false); expect(wrapper.hasClass('form-control-plaintext')).toBe(false); expect(wrapper.hasClass('form-control')).toBe(false); }); it('should render with "form-check-input" class when type is checkbox', () => { const wrapper = shallow(); expect(wrapper.hasClass('form-check-input')).toBe(true); }); it('should render with "form-check-input" class when type is radio', () => { const wrapper = shallow(); expect(wrapper.hasClass('form-check-input')).toBe(true); }); it('should not render with "form-check-input" nor "form-control" class when type is checkbox and addon is truthy', () => { const wrapper = shallow(); expect(wrapper.hasClass('form-check-input')).toBe(false); expect(wrapper.hasClass('form-control')).toBe(false); }); it('should not render with "form-check-input" nor "form-control" class when type is radio and addon is truthy', () => { const wrapper = shallow(); expect(wrapper.hasClass('form-check-input')).toBe(false); expect(wrapper.hasClass('form-control')).toBe(false); }); it('should render with "form-control-file" class when type is file', () => { const wrapper = shallow(); expect(wrapper.hasClass('form-control-file')).toBe(true); }); it('should render additional classes', () => { const wrapper = shallow(Yo!); expect(wrapper.hasClass('other')).toBe(true); }); it('should render "select" and "textarea" without type property', () => { const input = shallow(Yo!); const textarea = shallow(Yo!); expect(input.find('[type="select"]').exists()).toBe(false); expect(textarea.find('[type="textarea"]').exists()).toBe(false); }); });