|
| 1 | +import expect from 'expect'; |
| 2 | +import React from 'react'; |
| 3 | +import theme from '../theme.scss'; |
| 4 | +import { DatePickerDialog } from '../DatePicker'; |
| 5 | +import utils from '../../utils/testing'; |
| 6 | + |
| 7 | +describe('DatePickerDialog', function () { |
| 8 | + describe('#on mount', function () { |
| 9 | + it('passes value through to calendar if no maxDate/minDate specified', function () { |
| 10 | + const value = new Date(2016, 1, 1); |
| 11 | + |
| 12 | + const wrapper = utils.shallowRenderComponent(DatePickerDialog, {theme, value}); |
| 13 | + |
| 14 | + expect(getDatePassedToCalendar(wrapper)).toBe(value); |
| 15 | + }); |
| 16 | + |
| 17 | + describe('when minDate but not maxDate specified', function () { |
| 18 | + const minDate = new Date(2016, 1, 2); |
| 19 | + |
| 20 | + it('passes through a value after minDate', function () { |
| 21 | + const value = new Date(2016, 1, 3); |
| 22 | + |
| 23 | + const wrapper = utils.shallowRenderComponent(DatePickerDialog, {theme, value, minDate}); |
| 24 | + |
| 25 | + expect(getDatePassedToCalendar(wrapper)).toBe(value); |
| 26 | + }); |
| 27 | + |
| 28 | + it('sanitises a value before minDate to minDate', function () { |
| 29 | + const wrapper = utils.shallowRenderComponent(DatePickerDialog, { |
| 30 | + theme, value: new Date(2016, 1, 1), minDate |
| 31 | + }); |
| 32 | + |
| 33 | + expect(getDatePassedToCalendar(wrapper)).toBe(minDate); |
| 34 | + }); |
| 35 | + }); |
| 36 | + |
| 37 | + describe('when maxDate but not minDate specified', function () { |
| 38 | + const maxDate = new Date(2016, 1, 2); |
| 39 | + |
| 40 | + it('passes through a value before maxDate', function () { |
| 41 | + const value = new Date(2016, 1, 1); |
| 42 | + |
| 43 | + const wrapper = utils.shallowRenderComponent(DatePickerDialog, {theme, value, maxDate}); |
| 44 | + |
| 45 | + expect(getDatePassedToCalendar(wrapper)).toBe(value); |
| 46 | + }); |
| 47 | + |
| 48 | + it('sanitises a value after maxDate to maxDate', function () { |
| 49 | + const wrapper = utils.shallowRenderComponent(DatePickerDialog, { |
| 50 | + theme, value: new Date(2016, 1, 3), maxDate |
| 51 | + }); |
| 52 | + |
| 53 | + expect(getDatePassedToCalendar(wrapper)).toBe(maxDate); |
| 54 | + }); |
| 55 | + }); |
| 56 | + |
| 57 | + describe('if both minDate and maxDate are set', function () { |
| 58 | + const minDate = new Date(2016, 1, 2); |
| 59 | + const maxDate = new Date(2016, 1, 4); |
| 60 | + |
| 61 | + it('sanitises value to minDate if value is before minDate', function () { |
| 62 | + const wrapper = utils.shallowRenderComponent(DatePickerDialog, { |
| 63 | + theme, |
| 64 | + value: new Date(2016, 1, 1), |
| 65 | + minDate, |
| 66 | + maxDate |
| 67 | + }); |
| 68 | + |
| 69 | + expect(getDatePassedToCalendar(wrapper)).toBe(minDate); |
| 70 | + }); |
| 71 | + |
| 72 | + it('sanitises value to maxDate if value is after maxDate', function () { |
| 73 | + const wrapper = utils.shallowRenderComponent(DatePickerDialog, { |
| 74 | + theme, |
| 75 | + value: new Date(2016, 1, 5), |
| 76 | + minDate, |
| 77 | + maxDate |
| 78 | + }); |
| 79 | + |
| 80 | + expect(getDatePassedToCalendar(wrapper)).toBe(maxDate); |
| 81 | + }); |
| 82 | + |
| 83 | + it('doesn\'t sanitise when value is between maxDate/minDate', function () { |
| 84 | + const value = new Date(2016, 1, 3); |
| 85 | + const wrapper = utils.shallowRenderComponent(DatePickerDialog, {theme, value, minDate, maxDate}); |
| 86 | + expect(getDatePassedToCalendar(wrapper)).toBe(value); |
| 87 | + }); |
| 88 | + }); |
| 89 | + |
| 90 | + function getDatePassedToCalendar(wrapper) { |
| 91 | + return wrapper.props.children[1].props.children.props.selectedDate; |
| 92 | + } |
| 93 | + }); |
| 94 | +}); |
0 commit comments