Skip to content

Commit

Permalink
add test around focus/blur
Browse files Browse the repository at this point in the history
  • Loading branch information
onlyann committed Nov 14, 2018
1 parent 907c18e commit 6cdfa36
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tests/Calendar.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,32 @@ describe('Calendar', () => {
expect(onSelect.mock.calls[0][0].format('DD/MM/YYYY')).toBe(expected);
expect(onChange.mock.calls[0][0].format('DD/MM/YYYY')).toBe(expected);
});

it('only reformat the date when the input loses focus', () => {
const value = '21/01/17';

const onSelect = jest.fn();
const onChange = jest.fn();

const calendar = mount(<Calendar
format={['DD/MM/YYYY', 'DD/MM/YY']}
showToday
onSelect={onSelect}
onChange={onChange}
/>);

const input = calendar.find('.rc-calendar-input').hostNodes().at(0);
input.simulate('focus');
input.simulate('change', { target: { value } });

let inputValue = calendar.find('.rc-calendar-input').props().value;
expect(inputValue).toBe('21/01/17');

input.simulate('blur');

inputValue = calendar.find('.rc-calendar-input').props().value;
expect(inputValue).toBe('21/01/2017');
});
});

it('handle clear', () => {
Expand Down

0 comments on commit 6cdfa36

Please sign in to comment.