shlink-web-client/test/common/DateInput.test.js

40 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-08-12 10:01:11 +03:00
import React from 'react';
import { shallow } from 'enzyme';
import DateInput from '../../src/common/DateInput';
import FontAwesomeIcon from '@fortawesome/react-fontawesome';
2018-08-12 11:18:26 +03:00
import moment from 'moment';
2018-08-12 10:01:11 +03:00
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', () => {
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);
});
});