Skip to content

Commit

Permalink
test: fix broken test (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
y0c committed Mar 31, 2019
1 parent e9b590c commit fc00900
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 52 deletions.
2 changes: 1 addition & 1 deletion test/Calendar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ describe('<Calendar/>', () => {
let shallowComponent: ShallowWrapper<React.Component<Props, State>>;
let mountComponent: ReactWrapper<Props, State>;
const defaultProps = {
base: new Date(2018, 4, 1),
base: dayjs(new Date(2018, 4, 1)),
};

it('redners with no props', () => {
Expand Down
3 changes: 2 additions & 1 deletion test/CalendarBody.test.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
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';
import { IDatePicker } from '../src/common/@types';

describe('<CalendarBody />', () => {
const defaultProps = {
current: new Date(2018, 11, 1),
current: dayjs(new Date(2018, 11, 1)),
onClick: sinon.spy(),
};
let shallowComponent: ShallowWrapper<React.Component>;
Expand Down
6 changes: 3 additions & 3 deletions test/CalendarContainer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import CalendarContainer, { Props, State } from '../src/components/CalendarConta
import { IDatePicker } from '../src/common/@types';

describe('<CalendarContainer/>', () => {
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 = {
Expand Down Expand Up @@ -133,7 +133,7 @@ describe('<CalendarContainer/>', () => {
mountComponent = mount(
<CalendarContainer
{...defaultProps}
base={new Date(2018, 12, 4)}
base={dayjs(new Date(2018, 12, 4))}
showMonthCnt={2}
onChange={onChange}
/>
Expand Down
12 changes: 6 additions & 6 deletions test/DatePicker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('<DatePicker/>', () => {
let mountComponent: ReactWrapper<Props, State>;

const defaultProps = {
initialDate: new Date(2018, 11, 1),
initialDate: dayjs(new Date(2018, 11, 1)),
};

const pickerShow = (component: ReactWrapper) => {
Expand Down Expand Up @@ -69,7 +69,7 @@ describe('<DatePicker/>', () => {

it('should props showMonthCnt correctly', () => {
// 20180501
const mockDate = new Date(2018, 5, 1);
const mockDate = dayjs(new Date(2018, 5, 1));
mountComponent = mount(<DatePicker initialDate={mockDate} showMonthCnt={3} />);
pickerShow(mountComponent);
expect(mountComponent.find('.calendar__container')).toHaveLength(3);
Expand Down Expand Up @@ -177,7 +177,7 @@ describe('<DatePicker/>', () => {

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,
Expand All @@ -197,7 +197,7 @@ describe('<DatePicker/>', () => {

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,
Expand Down Expand Up @@ -229,7 +229,7 @@ describe('<DatePicker/>', () => {
initialTimeType={timeType}
/>
);
const originalDate = new Date(2018, 4, 1);
const originalDate = dayjs(new Date(2018, 4, 1));

mountComponent.setState({
...mountComponent.state,
Expand Down Expand Up @@ -264,7 +264,7 @@ describe('<DatePicker/>', () => {
initialTimeType={timeType}
/>
);
const originalDate = new Date(2018, 4, 1);
const originalDate = dayjs(new Date(2018, 4, 1));

mountComponent.setState({
...mountComponent.state,
Expand Down
36 changes: 18 additions & 18 deletions test/DateUtil.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
21 changes: 8 additions & 13 deletions test/DayView.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,13 @@ import { mount, ReactWrapper } from 'enzyme';

describe('<DayView/>', () => {
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(<DayView {...defaultProps} selected={selected} />);
});
Expand All @@ -37,7 +32,7 @@ describe('<DayView/>', () => {
let onClick: sinon.SinonSpy;

beforeEach(() => {
const disableDay = (date: Date) => {
const disableDay = (date: dayjs.Dayjs) => {
return dayjs(date).isSame(dayjs('20181201'), 'date');
};
onClick = sinon.spy();
Expand All @@ -61,8 +56,8 @@ describe('<DayView/>', () => {

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(<DayView {...defaultProps} startDay={startDay} endDay={endDay} />);
});
Expand All @@ -77,23 +72,23 @@ describe('<DayView/>', () => {
});

it('should only occur when startDay, endDay exists', () => {
const startDay = dayjs('20181205').toDate();
const startDay = dayjs('20181205');
mountComponent = mount(<DayView {...defaultProps} startDay={startDay} />);
expect(mountComponent.find('td.calendar__day--range')).toHaveLength(0);
});
});

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',
};
return dayClassMap[dayjs(date).format('YYYYMMDD')];
};

const customDayText = (date: Date) => {
const customDayText = (date: dayjs.Dayjs) => {
// custom day class string or array
const dayTextMap = {
'20181202': '신정',
Expand Down
20 changes: 10 additions & 10 deletions test/RangeDatePicker.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const INPUT_FORMAT = 'YYYY-MM-DD';

describe('<RangeDatePicker/>', () => {
const defaultProps = {
initialDate: new Date(2018, 4, 1),
initialDate: dayjs(new Date(2018, 4, 1)),
};

const pickerShow = (component: ReactWrapper) => {
Expand Down Expand Up @@ -53,7 +53,7 @@ describe('<RangeDatePicker/>', () => {
mountComponent = mount(<RangeDatePicker {...defaultProps} />);
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');
Expand All @@ -67,7 +67,7 @@ describe('<RangeDatePicker/>', () => {
mountComponent = mount(<RangeDatePicker {...defaultProps} />);
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');
Expand All @@ -81,8 +81,8 @@ describe('<RangeDatePicker/>', () => {
mountComponent = mount(<RangeDatePicker {...defaultProps} />);
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');
Expand Down Expand Up @@ -124,8 +124,8 @@ describe('<RangeDatePicker/>', () => {

describe('handleInputBlur', () => {
let mountComponent: ReactWrapper<Props, State>;
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(<RangeDatePicker dateFormat={INPUT_FORMAT} {...defaultProps} />);
Expand Down Expand Up @@ -265,8 +265,8 @@ describe('<RangeDatePicker/>', () => {
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(<RangeDatePicker clear {...defaultProps} />);
Expand Down Expand Up @@ -339,7 +339,7 @@ describe('<RangeDatePicker/>', () => {
pickerShow(mountComponent);
mountComponent.setState({
...mountComponent.state,
start: new Date(2018, 4, 1),
start: dayjs(new Date(2018, 4, 1)),
});

mountComponent
Expand Down

0 comments on commit fc00900

Please sign in to comment.