diff --git a/src/common/DateInput.js b/src/common/DateInput.js index b246405c..2981810a 100644 --- a/src/common/DateInput.js +++ b/src/common/DateInput.js @@ -24,11 +24,13 @@ export default class DateInput extends React.Component { readOnly ref={this.inputRef} /> - {showCalendarIcon && this.inputRef.current.input.focus()} - />} + {showCalendarIcon && ( + this.inputRef.current.input.focus()} + /> + )} ); } diff --git a/test/common/DateInput.test.js b/test/common/DateInput.test.js new file mode 100644 index 00000000..fe68ece9 --- /dev/null +++ b/test/common/DateInput.test.js @@ -0,0 +1,38 @@ +import React from 'react'; +import { shallow } from 'enzyme'; +import DateInput from '../../src/common/DateInput'; +import FontAwesomeIcon from '@fortawesome/react-fontawesome'; + +describe('', () => { + let wrapped; + + const createComponent = (props = {}) => { + wrapped = shallow(); + return wrapped; + }; + afterEach(() => { + if (wrapped !== undefined) { + wrapped.unmount(); + wrapped = undefined; + } + }); + + it('wrapps a DatePicker', () => { + wrapped = createComponent(); + }); + + it('shows calendar icon when input is not clearable', () => { + wrapped = createComponent({ isClearable: false }); + expect(wrapped.find(FontAwesomeIcon)).toHaveLength(1); + }); + + it('shows calendar icon when input is clearable but selected value is nil', () => { + wrapped = createComponent({ isClearable: true, selected: null }); + expect(wrapped.find(FontAwesomeIcon)).toHaveLength(1); + }); + + it('does not show calendar icon when input is clearable', () => { + wrapped = createComponent({ isClearable: true, selected: '' }); + expect(wrapped.find(FontAwesomeIcon)).toHaveLength(0); + }); +});