-
Notifications
You must be signed in to change notification settings - Fork 77
fix: DatePicker update unit tests #332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,27 +33,25 @@ describe('<DatePicker />', () => { | |
|
|
||
| test('open/close calendar', () => { | ||
| wrapper = mount(defaultDatePicker); | ||
| // check to make sure calendar is hidden | ||
| expect(wrapper.state('hidden')).toBeTruthy(); | ||
|
|
||
| // click to show calendar | ||
| wrapper.find('input[type="text"]').simulate('click', { type: 'input' }); | ||
|
|
||
| // check to make sure calendar is shown | ||
| expect(wrapper.state('hidden')).toBeFalsy(); | ||
|
|
||
| // clicking on input text should keep calendar displayed | ||
| wrapper.find('input[type="text"]').simulate('click', { type: 'input' }); | ||
|
|
||
| // check to make sure calendar is shown | ||
| expect(wrapper.state('hidden')).toBeFalsy(); | ||
|
|
||
| wrapper.instance().componentWillMount(); | ||
|
|
||
| let event = new MouseEvent('mousedown', { | ||
| target: document.querySelector('body') | ||
| }); | ||
| document.dispatchEvent(event); | ||
|
|
||
| expect(wrapper.state('hidden')).toBeTruthy(); | ||
|
|
||
| // click to show calendar | ||
| wrapper.find('input[type="text"]').simulate('click', { type: '' }); | ||
|
|
||
| // check to make sure calendar is shown | ||
| expect(wrapper.state('hidden')).toBeFalsy(); | ||
| }); | ||
|
|
||
|
|
@@ -62,34 +60,61 @@ describe('<DatePicker />', () => { | |
| //open date picker calendar | ||
| expect(wrapper.state('hidden')).toBeTruthy(); | ||
|
|
||
| // click to show calendar | ||
| wrapper.find('input[type="text"]').simulate('click', { type: 'input' }); | ||
|
|
||
| // check to make sure calendar is shown | ||
| expect(wrapper.state('hidden')).toBeFalsy(); | ||
|
|
||
| wrapper.instance().componentWillMount(); | ||
|
|
||
| // click on body element | ||
| let event = new MouseEvent('mousedown', { | ||
| target: document.querySelector('body') | ||
| }); | ||
| document.dispatchEvent(event); | ||
|
|
||
| // check to make sure calendar is hidden | ||
| expect(wrapper.state('hidden')).toBeTruthy(); | ||
|
|
||
| // show date picker, select date range then close | ||
| wrapper.find('input[type="text"]').simulate('click', { type: '' }); | ||
|
|
||
| // check to make sure calendar is shown | ||
| expect(wrapper.state('hidden')).toBeFalsy(); | ||
| }); | ||
|
|
||
| test('start date and end date range', () => { | ||
| wrapper = mount(rangeDatePicker); | ||
| // set dates | ||
| let startRangeDate = new Date(); | ||
| let endRangeDate = new Date(); | ||
| endRangeDate.setDate(endRangeDate.getDate() + 3); | ||
|
|
||
| let arrDates = [startRangeDate, endRangeDate]; | ||
| wrapper.instance().updateDate(arrDates); | ||
|
|
||
| expect(wrapper.state('arrSelectedDates').length).toEqual(2); | ||
|
|
||
| // click on body element | ||
| let event = new MouseEvent('mousedown', { | ||
| target: document.querySelector('body') | ||
| }); | ||
| document.dispatchEvent(event); | ||
|
|
||
| // check to make sure calendar is hidden | ||
| expect(wrapper.state('hidden')).toBeTruthy(); | ||
| }); | ||
|
|
||
| test('check start date greater than end date for range', () => { | ||
| wrapper = mount(rangeDatePicker); | ||
| // set dates | ||
| let startRangeDate = new Date(); | ||
| let endRangeDate = new Date(); | ||
| endRangeDate.setDate(endRangeDate.getDate() + 3); | ||
|
|
||
| let arrDates = [startRangeDate, endRangeDate]; | ||
|
|
||
| // make start date bigger than end date | ||
| arrDates = [endRangeDate, startRangeDate]; | ||
| wrapper.instance().updateDate(arrDates); | ||
|
|
@@ -101,10 +126,37 @@ describe('<DatePicker />', () => { | |
| expect(wrapper.state('formattedDate')).toEqual(switchFormattedDate); | ||
| expect(wrapper.state('arrSelectedDates').length).toEqual(2); | ||
|
|
||
| // click on body element to hide calendar | ||
| let event = new MouseEvent('mousedown', { | ||
| target: document.querySelector('body') | ||
| }); | ||
| document.dispatchEvent(event); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why the added
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added assertion to check that calendar is hidden |
||
|
|
||
| // check to make sure calendar is hidden | ||
| expect(wrapper.state('hidden')).toBeTruthy(); | ||
| }); | ||
|
|
||
| test('entering invalid range dates', () => { | ||
| wrapper = mount(rangeDatePicker); | ||
| // set dates | ||
| let startRangeDate = new Date(); | ||
| let endRangeDate = new Date(); | ||
| endRangeDate.setDate(endRangeDate.getDate() + 3); | ||
|
|
||
| let startDate = `${startRangeDate.getMonth() + | ||
| 1}/${startRangeDate.getDate()}/${startRangeDate.getFullYear()}`; | ||
| let endDate = `${endRangeDate.getMonth() + | ||
| 1}/${endRangeDate.getDate()}/${endRangeDate.getFullYear() + 4000}`; | ||
|
|
||
| wrapper.find('input[type="text"]') | ||
| .simulate('change', { target: { value: `${startDate}-${endDate}` } }); | ||
|
|
||
| wrapper.find('input[type="text"]').simulate('keypress', { key: 'Enter' }); | ||
|
|
||
| expect(wrapper.state('arrSelectedDates')).toEqual('undefined'); | ||
| }); | ||
|
|
||
| test('update date method', () => { | ||
| test('updateDate method', () => { | ||
| // choose one day in default picker | ||
| wrapper = mount(defaultDatePicker); | ||
| const date = new Date(); | ||
|
|
@@ -143,7 +195,7 @@ describe('<DatePicker />', () => { | |
| expect(wrapper.state('arrSelectedDates').length).toEqual(2); | ||
| }); | ||
|
|
||
| test('enter date value', () => { | ||
| test('pressing enter key on date input', () => { | ||
| wrapper = mount(rangeDatePicker); | ||
|
|
||
| let startRangeDate = new Date(); | ||
|
|
@@ -175,20 +227,24 @@ describe('<DatePicker />', () => { | |
|
|
||
| wrapper.find('input[type="text"]').simulate('keypress', { key: 'Enter' }); | ||
|
|
||
| expect(wrapper.state('formattedDate')).toBe(''); | ||
| expect(wrapper.state('selectedDate')).toBe('undefined'); | ||
| }); | ||
|
|
||
| test('enter an invalid date string', () => { | ||
| wrapper = mount(defaultDatePicker); | ||
| let date = new Date(); | ||
| wrapper.instance().updateDate(date); | ||
| expect(wrapper.state('selectedDate')).toEqual(date); | ||
| formattedDate = `${date.getMonth() + | ||
| 1}/${date.getDate()}/${date.getFullYear()}`; | ||
| expect(wrapper.state('formattedDate')).toEqual(formattedDate); | ||
| let formattedDate = `${date.getMonth() + | ||
| 1}/${date.getDate()}/${date.getFullYear() + 4000}`; | ||
| wrapper.find('input[type="text"]') | ||
| .simulate('change', { target: { value: formattedDate } }); | ||
|
|
||
| wrapper.find('input[type="text"]').simulate('keypress', { key: 'Enter' }); | ||
|
|
||
| // press Esc key | ||
| wrapper.find('input[type="text"]').simulate('keypress', { key: 'Esc' }); | ||
| expect(wrapper.state('selectedDate')).toEqual('undefined'); | ||
| }); | ||
|
|
||
| test('format date', () => { | ||
| test('formatDate method', () => { | ||
| wrapper = mount(rangeDatePicker); | ||
| let startRangeDate = new Date(); | ||
| let endRangeDate = new Date(); | ||
|
|
@@ -225,6 +281,28 @@ describe('<DatePicker />', () => { | |
| expect(wrapper.instance().formatDate(startRangeDate)).toEqual(''); | ||
| }); | ||
|
|
||
| test('enter text string for date', () => { | ||
| wrapper = mount(defaultDatePicker); | ||
|
|
||
| wrapper.find('input[type="text"]') | ||
| .simulate('change', { target: { value: 'May 14th, 2018' } }); | ||
|
|
||
| wrapper.find('input[type="text"]').simulate('keypress', { key: 'Enter' }); | ||
|
|
||
| expect(wrapper.state('formattedDate')).toEqual(''); | ||
| }); | ||
|
|
||
| test('enter text string for date on date range component', () => { | ||
| wrapper = mount(rangeDatePicker); | ||
|
|
||
| wrapper.find('input[type="text"]') | ||
| .simulate('change', { target: { value: 'May 14th, 2018-May 15th, 2018' } }); | ||
|
|
||
| wrapper.find('input[type="text"]').simulate('keypress', { key: 'Enter' }); | ||
|
|
||
| expect(wrapper.state('formattedDate')).toEqual(''); | ||
| }); | ||
|
|
||
| test('modify date on change', () => { | ||
| wrapper = mount(defaultDatePicker); | ||
| wrapper | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand why the added
mousedownevent, but then no additional assertions. I'm probably just missing something.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed MouseEvent code since it was not necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am still seeing a couple of these in the files changed diff.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry, missed that mouseDown event. Just added an assertion to check that calendar is hidden.