From fc00900ff36d00d172057ea0ce664651f0d3097f Mon Sep 17 00:00:00 2001 From: Hosung Lim Date: Sun, 31 Mar 2019 23:59:54 +0900 Subject: [PATCH] test: fix broken test (#14) --- test/Calendar.test.tsx | 2 +- test/CalendarBody.test.tsx | 3 ++- test/CalendarContainer.test.tsx | 6 +++--- test/DatePicker.test.tsx | 12 +++++------ test/DateUtil.test.ts | 36 ++++++++++++++++----------------- test/DayView.test.tsx | 21 ++++++++----------- test/RangeDatePicker.test.tsx | 20 +++++++++--------- 7 files changed, 48 insertions(+), 52 deletions(-) diff --git a/test/Calendar.test.tsx b/test/Calendar.test.tsx index 15cb9d7..3a4eb09 100644 --- a/test/Calendar.test.tsx +++ b/test/Calendar.test.tsx @@ -9,7 +9,7 @@ describe('', () => { let shallowComponent: ShallowWrapper>; let mountComponent: ReactWrapper; const defaultProps = { - base: new Date(2018, 4, 1), + base: dayjs(new Date(2018, 4, 1)), }; it('redners with no props', () => { diff --git a/test/CalendarBody.test.tsx b/test/CalendarBody.test.tsx index 973d48f..1022a93 100644 --- a/test/CalendarBody.test.tsx +++ b/test/CalendarBody.test.tsx @@ -1,5 +1,6 @@ import { mount, shallow, ReactWrapper, ShallowWrapper } from 'enzyme'; import * as sinon from 'sinon'; +import * as dayjs from 'dayjs'; import * as React from 'react'; import DayView from '../src/components/DayView'; import CalendarBody from '../src/components/CalendarBody'; @@ -7,7 +8,7 @@ import { IDatePicker } from '../src/common/@types'; describe('', () => { const defaultProps = { - current: new Date(2018, 11, 1), + current: dayjs(new Date(2018, 11, 1)), onClick: sinon.spy(), }; let shallowComponent: ShallowWrapper; diff --git a/test/CalendarContainer.test.tsx b/test/CalendarContainer.test.tsx index 30f5966..5b4288a 100644 --- a/test/CalendarContainer.test.tsx +++ b/test/CalendarContainer.test.tsx @@ -11,9 +11,9 @@ import CalendarContainer, { Props, State } from '../src/components/CalendarConta import { IDatePicker } from '../src/common/@types'; describe('', () => { - const current = new Date(2018, 11, 5); + const current = dayjs(new Date(2018, 11, 5)); let base = current; - const setBase = (val: Date) => { + const setBase = (val: dayjs.Dayjs) => { base = val; }; const defaultProps = { @@ -133,7 +133,7 @@ describe('', () => { mountComponent = mount( diff --git a/test/DatePicker.test.tsx b/test/DatePicker.test.tsx index c648489..0abdaef 100644 --- a/test/DatePicker.test.tsx +++ b/test/DatePicker.test.tsx @@ -15,7 +15,7 @@ describe('', () => { let mountComponent: ReactWrapper; const defaultProps = { - initialDate: new Date(2018, 11, 1), + initialDate: dayjs(new Date(2018, 11, 1)), }; const pickerShow = (component: ReactWrapper) => { @@ -69,7 +69,7 @@ describe('', () => { it('should props showMonthCnt correctly', () => { // 20180501 - const mockDate = new Date(2018, 5, 1); + const mockDate = dayjs(new Date(2018, 5, 1)); mountComponent = mount(); pickerShow(mountComponent); expect(mountComponent.find('.calendar__container')).toHaveLength(3); @@ -177,7 +177,7 @@ describe('', () => { it('should date picker input invalid value return original date', () => { const { dateFormat } = DatePickerDefaults; - const originalDate = new Date(2018, 4, 1); + const originalDate = dayjs(new Date(2018, 4, 1)); const testValue = 'teste333'; mountComponent.setState({ ...mountComponent.state, @@ -197,7 +197,7 @@ describe('', () => { it('should date picker input valid value setState date', () => { const { dateFormat } = DatePickerDefaults; - const originalDate = new Date(2018, 4, 1); + const originalDate = dayjs(new Date(2018, 4, 1)); const correctValue = '2018-05-02'; mountComponent.setState({ ...mountComponent.state, @@ -229,7 +229,7 @@ describe('', () => { initialTimeType={timeType} /> ); - const originalDate = new Date(2018, 4, 1); + const originalDate = dayjs(new Date(2018, 4, 1)); mountComponent.setState({ ...mountComponent.state, @@ -264,7 +264,7 @@ describe('', () => { initialTimeType={timeType} /> ); - const originalDate = new Date(2018, 4, 1); + const originalDate = dayjs(new Date(2018, 4, 1)); mountComponent.setState({ ...mountComponent.state, diff --git a/test/DateUtil.test.ts b/test/DateUtil.test.ts index 3be046f..6c05030 100644 --- a/test/DateUtil.test.ts +++ b/test/DateUtil.test.ts @@ -3,13 +3,13 @@ import { getDayMatrix, isDayEqual, isDayRange } from '../src/utils/DateUtil'; describe('DateUtil', () => { describe('isDayEqual', () => { - let day1: Date; - let day2: Date; + let day1: dayjs.Dayjs; + let day2: dayjs.Dayjs; it('should eq date return true', () => { // given - day1 = new Date(2019, 1, 1); - day2 = new Date(2019, 1, 1); + day1 = dayjs(new Date(2019, 1, 1)); + day2 = dayjs(new Date(2019, 1, 1)); // when const isEqual = isDayEqual(day1, day2); @@ -20,8 +20,8 @@ describe('DateUtil', () => { it('should not eq date return false', () => { // given - day1 = new Date(2019, 1, 1); - day2 = new Date(2019, 1, 2); + day1 = dayjs(new Date(2019, 1, 1)); + day2 = dayjs(new Date(2019, 1, 2)); // when const isEqual = isDayEqual(day1, day2); @@ -32,15 +32,15 @@ describe('DateUtil', () => { }); describe('isDayRange', () => { - let between: Date; - let start: Date; - let end: Date; + let between: dayjs.Dayjs; + let start: dayjs.Dayjs; + let end: dayjs.Dayjs; it('should between eq start return false', () => { // given - between = new Date(2019, 1, 1); - start = new Date(2019, 1, 1); - end = new Date(2019, 1, 6); + between = dayjs(new Date(2019, 1, 1)); + start = dayjs(new Date(2019, 1, 1)); + end = dayjs(new Date(2019, 1, 6)); // when const isRange = isDayRange(between, start, end); @@ -51,9 +51,9 @@ describe('DateUtil', () => { it('should between eq end return false', () => { // given - between = new Date(2019, 1, 6); - start = new Date(2019, 1, 1); - end = new Date(2019, 1, 6); + between = dayjs(new Date(2019, 1, 6)); + start = dayjs(new Date(2019, 1, 1)); + end = dayjs(new Date(2019, 1, 6)); // when const isRange = isDayRange(between, start, end); @@ -64,9 +64,9 @@ describe('DateUtil', () => { it('should between gt start return true', () => { // given - between = new Date(2019, 1, 2); - start = new Date(2019, 1, 1); - end = new Date(2019, 1, 6); + between = dayjs(new Date(2019, 1, 2)); + start = dayjs(new Date(2019, 1, 1)); + end = dayjs(new Date(2019, 1, 6)); // when const isRange = isDayRange(between, start, end); diff --git a/test/DayView.test.tsx b/test/DayView.test.tsx index 1bc574e..5c7c04c 100644 --- a/test/DayView.test.tsx +++ b/test/DayView.test.tsx @@ -7,18 +7,13 @@ import { mount, ReactWrapper } from 'enzyme'; describe('', () => { const defaultProps = { - current: new Date(2018, 11, 5), + current: dayjs(new Date(2018, 11, 5)), }; let mountComponent: ReactWrapper; describe('prop: selected', () => { beforeEach(() => { - const selected = [ - dayjs('20181201'), - dayjs('20181212'), - dayjs('20181215'), - dayjs('20181222'), - ].map(v => v.toDate()); + const selected = [dayjs('20181201'), dayjs('20181212'), dayjs('20181215'), dayjs('20181222')]; mountComponent = mount(); }); @@ -37,7 +32,7 @@ describe('', () => { let onClick: sinon.SinonSpy; beforeEach(() => { - const disableDay = (date: Date) => { + const disableDay = (date: dayjs.Dayjs) => { return dayjs(date).isSame(dayjs('20181201'), 'date'); }; onClick = sinon.spy(); @@ -61,8 +56,8 @@ describe('', () => { describe('prop: startDay, endDay', () => { beforeEach(() => { - const startDay = dayjs('20181205').toDate(); - const endDay = dayjs('20181211').toDate(); + const startDay = dayjs('20181205'); + const endDay = dayjs('20181211'); mountComponent = mount(); }); @@ -77,7 +72,7 @@ describe('', () => { }); it('should only occur when startDay, endDay exists', () => { - const startDay = dayjs('20181205').toDate(); + const startDay = dayjs('20181205'); mountComponent = mount(); expect(mountComponent.find('td.calendar__day--range')).toHaveLength(0); }); @@ -85,7 +80,7 @@ describe('', () => { describe('prop:customClass, customText', () => { beforeEach(() => { - const customDayClass = (date: Date) => { + const customDayClass = (date: dayjs.Dayjs) => { const dayClassMap = { '20181202': ['custom-day', 'day-test1', 'day-test2'], '20181211': 'custom-day', @@ -93,7 +88,7 @@ describe('', () => { return dayClassMap[dayjs(date).format('YYYYMMDD')]; }; - const customDayText = (date: Date) => { + const customDayText = (date: dayjs.Dayjs) => { // custom day class string or array const dayTextMap = { '20181202': '신정', diff --git a/test/RangeDatePicker.test.tsx b/test/RangeDatePicker.test.tsx index ffb1cc7..25786f9 100644 --- a/test/RangeDatePicker.test.tsx +++ b/test/RangeDatePicker.test.tsx @@ -11,7 +11,7 @@ const INPUT_FORMAT = 'YYYY-MM-DD'; describe('', () => { const defaultProps = { - initialDate: new Date(2018, 4, 1), + initialDate: dayjs(new Date(2018, 4, 1)), }; const pickerShow = (component: ReactWrapper) => { @@ -53,7 +53,7 @@ describe('', () => { mountComponent = mount(); mountComponent.find(START_INPUT_CLASS).simulate('click'); mountComponent.setState({ - start: new Date(2018, 4, 5), + start: dayjs(new Date(2018, 4, 5)), }); dayClick(0)(2); const start = mountComponent.state('start'); @@ -67,7 +67,7 @@ describe('', () => { mountComponent = mount(); mountComponent.find(START_INPUT_CLASS).simulate('click'); mountComponent.setState({ - start: new Date(2018, 4, 2), + start: dayjs(new Date(2018, 4, 2)), }); dayClick(0)(5); const end = mountComponent.state('end'); @@ -81,8 +81,8 @@ describe('', () => { mountComponent = mount(); mountComponent.find(START_INPUT_CLASS).simulate('click'); mountComponent.setState({ - start: new Date(2019, 4, 2), - end: new Date(2018, 4, 9), + start: dayjs(new Date(2019, 4, 2)), + end: dayjs(new Date(2018, 4, 9)), }); dayClick(0)(5); const start = mountComponent.state('start'); @@ -124,8 +124,8 @@ describe('', () => { describe('handleInputBlur', () => { let mountComponent: ReactWrapper; - const start = new Date(2018, 4, 1); - const end = new Date(2018, 4, 11); + const start = dayjs(new Date(2018, 4, 1)); + const end = dayjs(new Date(2018, 4, 11)); beforeEach(() => { mountComponent = mount(); @@ -265,8 +265,8 @@ describe('', () => { describe('handleInputClear', () => { let mountComponent: ReactWrapper; const rangeInputClass = (value: string) => `.range-picker-input__${value}`; - const start = new Date(2018, 4, 1); - const end = new Date(2018, 4, 11); + const start = dayjs(new Date(2018, 4, 1)); + const end = dayjs(new Date(2018, 4, 11)); beforeEach(() => { mountComponent = mount(); @@ -339,7 +339,7 @@ describe('', () => { pickerShow(mountComponent); mountComponent.setState({ ...mountComponent.state, - start: new Date(2018, 4, 1), + start: dayjs(new Date(2018, 4, 1)), }); mountComponent