This repository was archived by the owner on May 19, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 707
Expand file tree
/
Copy pathindex.test.js
More file actions
69 lines (62 loc) · 1.96 KB
/
index.test.js
File metadata and controls
69 lines (62 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import React from 'react';
import { mount } from 'enzyme';
import DateInput from './index';
const date = new Date('01/01/2021');
describe('DateInput tests', () => {
const onChange = jest.fn();
const onFocus = jest.fn();
test('Should set invalidFormat in state to true', () => {
const isDateInRange = jest.fn();
const wrapper = mount(
<DateInput
readOnly={false}
disabled={false}
value={date}
onChange={onChange}
onFocus={onFocus}
isDateInRange={isDateInRange}
dateDisplayFormat={'MMM d, yyyy'}
/>
);
const input = wrapper.find('input');
input.simulate('change', { target: { value: 'fooo' } });
input.simulate('keydown', { key: 'Enter' });
expect(wrapper.state().invalid.invalidFormat).toEqual(true);
});
test('Should set outOfRange in state to true', () => {
const isDateInRange = jest.fn(() => false);
const wrapper = mount(
<DateInput
readOnly={false}
disabled={false}
value={date}
onChange={onChange}
onFocus={onFocus}
isDateInRange={isDateInRange}
dateDisplayFormat={'MMM d, yyyy'}
/>
);
const input = wrapper.find('input');
input.simulate('change', { target: { value: 'Dec 8, 2021' } });
input.simulate('keydown', { key: 'Enter' });
expect(wrapper.state().invalid.outOfRange).toEqual(true);
});
test('Should call this.props.onChange if valid date', () => {
const isDateInRange = jest.fn(() => true);
const wrapper = mount(
<DateInput
readOnly={false}
disabled={false}
value={date}
onChange={onChange}
onFocus={onFocus}
isDateInRange={isDateInRange}
dateDisplayFormat={'MMM d, yyyy'}
/>
);
const input = wrapper.find('input');
input.simulate('change', { target: { value: 'Dec 8, 2021' } });
input.simulate('keydown', { key: 'Enter' });
expect(onChange).toHaveBeenCalledTimes(1);
});
});