2018-08-12 10:01:11 +03:00
|
|
|
import React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import FontAwesomeIcon from '@fortawesome/react-fontawesome';
|
2018-08-12 11:18:26 +03:00
|
|
|
import moment from 'moment';
|
2018-08-26 00:39:27 +03:00
|
|
|
import DateInput from '../../src/common/DateInput';
|
2018-08-12 10:01:11 +03:00
|
|
|
|
|
|
|
describe('<DateInput />', () => {
|
|
|
|
let wrapped;
|
|
|
|
|
|
|
|
const createComponent = (props = {}) => {
|
|
|
|
wrapped = shallow(<DateInput {...props} />);
|
2018-08-26 00:39:27 +03:00
|
|
|
|
2018-08-12 10:01:11 +03:00
|
|
|
return wrapped;
|
|
|
|
};
|
2018-08-26 00:39:27 +03:00
|
|
|
|
2018-08-12 10:01:11 +03:00
|
|
|
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', () => {
|
2018-08-12 11:18:26 +03:00
|
|
|
wrapped = createComponent({ isClearable: true, selected: moment() });
|
2018-08-12 10:01:11 +03:00
|
|
|
expect(wrapped.find(FontAwesomeIcon)).toHaveLength(0);
|
|
|
|
});
|
|
|
|
});
|