shlink-web-client/test/utils/DateInput.test.tsx

37 lines
1.2 KiB
TypeScript
Raw Normal View History

2020-08-26 21:03:23 +03:00
import { shallow, ShallowWrapper } from 'enzyme';
2019-01-06 01:16:13 +03:00
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
2018-08-12 11:18:26 +03:00
import moment from 'moment';
2020-08-26 21:03:23 +03:00
import { Mock } from 'ts-mockery';
import DateInput, { DateInputProps } from '../../src/utils/DateInput';
2018-08-12 10:01:11 +03:00
describe('<DateInput />', () => {
2020-08-26 21:03:23 +03:00
let wrapped: ShallowWrapper;
2018-08-12 10:01:11 +03:00
2020-08-26 21:03:23 +03:00
const createComponent = (props: Partial<DateInputProps> = {}) => {
wrapped = shallow(<DateInput {...Mock.of<DateInputProps>(props)} />);
2018-08-12 10:01:11 +03:00
return wrapped;
};
2020-08-26 21:03:23 +03:00
afterEach(() => wrapped?.unmount());
2018-08-12 10:01:11 +03:00
2020-08-26 21:03:23 +03:00
it('wraps a DatePicker', () => {
2018-08-12 10:01:11 +03:00
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);
});
});