Created DateInput component test

This commit is contained in:
Alejandro Celaya 2018-08-12 09:01:11 +02:00
parent faa828c58a
commit f23245a39c
2 changed files with 45 additions and 5 deletions

View file

@ -24,11 +24,13 @@ export default class DateInput extends React.Component {
readOnly
ref={this.inputRef}
/>
{showCalendarIcon && <FontAwesomeIcon
icon={calendarIcon}
className="date-input-container__icon"
onClick={() => this.inputRef.current.input.focus()}
/>}
{showCalendarIcon && (
<FontAwesomeIcon
icon={calendarIcon}
className="date-input-container__icon"
onClick={() => this.inputRef.current.input.focus()}
/>
)}
</div>
);
}

View file

@ -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('<DateInput />', () => {
let wrapped;
const createComponent = (props = {}) => {
wrapped = shallow(<DateInput {...props} />);
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);
});
});