Skip to content

Commit 058aeb2

Browse files
committed
Add new tests for activeStartDate change
1 parent 59a98ca commit 058aeb2

File tree

1 file changed

+32
-20
lines changed

1 file changed

+32
-20
lines changed

src/Calendar.spec.jsx

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,38 @@ describe('Calendar', () => {
343343
});
344344
});
345345

346+
describe('handles active start date change properly', () => {
347+
it('changes active start date when allowed', () => {
348+
const component = mount(
349+
<Calendar />,
350+
);
351+
352+
component.instance().setActiveStartDate(new Date(2019, 0, 1));
353+
354+
expect(component.state().activeStartDate).toEqual(new Date(2019, 0, 1));
355+
});
356+
357+
it('calls onActiveStartDateChange on activeStartDate change', () => {
358+
const activeStartDate = new Date(2017, 0, 1);
359+
const newActiveStartDate = new Date(2018, 0, 1);
360+
const onActiveStartDateChange = jest.fn();
361+
const component = mount(
362+
<Calendar
363+
activeStartDate={activeStartDate}
364+
onActiveStartDateChange={onActiveStartDateChange}
365+
view="year"
366+
/>,
367+
);
368+
369+
component.instance().setActiveStartDate(newActiveStartDate);
370+
371+
expect(onActiveStartDateChange).toHaveBeenCalledWith({
372+
activeStartDate: newActiveStartDate,
373+
view: 'year',
374+
});
375+
});
376+
});
377+
346378
describe('calls onChange properly', () => {
347379
it('calls onChange function returning the beginning of selected period by default', () => {
348380
const onChange = jest.fn();
@@ -526,26 +558,6 @@ describe('Calendar', () => {
526558
});
527559
});
528560

529-
it('calls onActiveStartDateChange on activeStartDate change', () => {
530-
const activeStartDate = new Date(2017, 0, 1);
531-
const newActiveStartDate = new Date(2018, 0, 1);
532-
const onActiveStartDateChange = jest.fn();
533-
const component = mount(
534-
<Calendar
535-
activeStartDate={activeStartDate}
536-
onActiveStartDateChange={onActiveStartDateChange}
537-
view="year"
538-
/>,
539-
);
540-
541-
component.instance().setActiveStartDate(newActiveStartDate);
542-
543-
expect(onActiveStartDateChange).toHaveBeenCalledWith({
544-
activeStartDate: newActiveStartDate,
545-
view: 'year',
546-
});
547-
});
548-
549561
it('changes Calendar view given new activeStartDate value', () => {
550562
const activeStartDate = new Date(2017, 0, 1);
551563
const newActiveStartDate = new Date(2018, 0, 1);

0 commit comments

Comments
 (0)