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';
|
2020-08-26 21:03:23 +03:00
|
|
|
import { Mock } from 'ts-mockery';
|
2022-05-28 12:16:59 +03:00
|
|
|
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-26 00:39:27 +03:00
|
|
|
|
2018-08-12 10:01:11 +03:00
|
|
|
return wrapped;
|
|
|
|
};
|
2018-08-26 00:39:27 +03:00
|
|
|
|
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', () => {
|
2021-06-24 21:13:06 +03:00
|
|
|
wrapped = createComponent({ isClearable: true, selected: new Date() });
|
2018-08-12 10:01:11 +03:00
|
|
|
expect(wrapped.find(FontAwesomeIcon)).toHaveLength(0);
|
|
|
|
});
|
|
|
|
});
|