Skip to content

Commit

Permalink
Update test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-schranz committed May 5, 2021
1 parent 47f17d8 commit e3063c0
Show file tree
Hide file tree
Showing 3 changed files with 176 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class DatePicker extends React.Component<Props> {
if (
(!this.value && date) ||
(this.value && !date) ||
!moment(this.value).isSame(date, 'day')
!moment(this.value, this.getFormat()).isSame(moment(date, this.getFormat()), 'day')
) {
this.setOpen(false);
}
Expand Down Expand Up @@ -189,7 +189,6 @@ class DatePicker extends React.Component<Props> {
const {className, disabled, options, placeholder, valid} = this.props;

const fieldOptions = {
closeOnSelect: true,
...options,
dateFormat: this.getDateFormat() || false,
timeFormat: this.getTimeFormat() || false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ test('DatePicker should render', () => {
const datePicker = mount(<DatePicker className="date-picker" onChange={onChange} value={null} />);

expect(datePicker.render()).toMatchSnapshot();
expect(datePicker.find('DateTime').render()).toMatchSnapshot();

expect(datePicker.find(ReactDatetime).render()).toMatchSnapshot();
});

test('DatePicker should show disabled Input when disabled', () => {
Expand All @@ -40,18 +41,18 @@ test('DatePicker should open overlay on icon-click', () => {
const onChange = jest.fn();
const datePicker = mount(<DatePicker onChange={onChange} value={null} />);

expect(datePicker.find('DateTime').props().open).toBeFalsy();
expect(datePicker.find(ReactDatetime).props().open).toBeFalsy();
datePicker.find('Icon').simulate('click');
expect(datePicker.find('DateTime').props().open).toBeTruthy();
expect(datePicker.find(ReactDatetime).props().open).toBeTruthy();
});

test('DatePicker should not open overlay on icon-click when disabled', () => {
const onChange = jest.fn();
const datePicker = mount(<DatePicker disabled={true} onChange={onChange} value={null} />);

expect(datePicker.find('DateTime').props().open).toBeFalsy();
expect(datePicker.find(ReactDatetime).props().open).toBeFalsy();
datePicker.find('Icon').simulate('click');
expect(datePicker.find('DateTime').props().open).toBeFalsy();
expect(datePicker.find(ReactDatetime).props().open).toBeFalsy();
});

test('DatePicker should render with placeholder', () => {
Expand Down Expand Up @@ -132,7 +133,7 @@ test('DatePicker should render date picker with time picker', () => {
const datePicker = mount(<DatePicker onChange={onChange} options={options} value={null} />);

expect(datePicker.render()).toMatchSnapshot();
expect(datePicker.find('DateTime').render()).toMatchSnapshot();
expect(datePicker.find(ReactDatetime).render()).toMatchSnapshot();
});

test('DatePicker should render error', () => {
Expand Down

0 comments on commit e3063c0

Please sign in to comment.