Skip to content

Commit

Permalink
Add new tests for activeStartDate change
Browse files Browse the repository at this point in the history
  • Loading branch information
wojtekmaj committed Jan 16, 2020
1 parent 59a98ca commit 058aeb2
Showing 1 changed file with 32 additions and 20 deletions.
52 changes: 32 additions & 20 deletions src/Calendar.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,38 @@ describe('Calendar', () => {
});
});

describe('handles active start date change properly', () => {
it('changes active start date when allowed', () => {
const component = mount(
<Calendar />,
);

component.instance().setActiveStartDate(new Date(2019, 0, 1));

expect(component.state().activeStartDate).toEqual(new Date(2019, 0, 1));
});

it('calls onActiveStartDateChange on activeStartDate change', () => {
const activeStartDate = new Date(2017, 0, 1);
const newActiveStartDate = new Date(2018, 0, 1);
const onActiveStartDateChange = jest.fn();
const component = mount(
<Calendar
activeStartDate={activeStartDate}
onActiveStartDateChange={onActiveStartDateChange}
view="year"
/>,
);

component.instance().setActiveStartDate(newActiveStartDate);

expect(onActiveStartDateChange).toHaveBeenCalledWith({
activeStartDate: newActiveStartDate,
view: 'year',
});
});
});

describe('calls onChange properly', () => {
it('calls onChange function returning the beginning of selected period by default', () => {
const onChange = jest.fn();
Expand Down Expand Up @@ -526,26 +558,6 @@ describe('Calendar', () => {
});
});

it('calls onActiveStartDateChange on activeStartDate change', () => {
const activeStartDate = new Date(2017, 0, 1);
const newActiveStartDate = new Date(2018, 0, 1);
const onActiveStartDateChange = jest.fn();
const component = mount(
<Calendar
activeStartDate={activeStartDate}
onActiveStartDateChange={onActiveStartDateChange}
view="year"
/>,
);

component.instance().setActiveStartDate(newActiveStartDate);

expect(onActiveStartDateChange).toHaveBeenCalledWith({
activeStartDate: newActiveStartDate,
view: 'year',
});
});

it('changes Calendar view given new activeStartDate value', () => {
const activeStartDate = new Date(2017, 0, 1);
const newActiveStartDate = new Date(2018, 0, 1);
Expand Down

0 comments on commit 058aeb2

Please sign in to comment.