From 058aeb26774cbef9d8155a356733a5cf5a518122 Mon Sep 17 00:00:00 2001 From: Wojciech Maj Date: Thu, 16 Jan 2020 21:35:09 +0100 Subject: [PATCH] Add new tests for activeStartDate change --- src/Calendar.spec.jsx | 52 ++++++++++++++++++++++++++----------------- 1 file changed, 32 insertions(+), 20 deletions(-) diff --git a/src/Calendar.spec.jsx b/src/Calendar.spec.jsx index f51fc3eb..ba792ee7 100644 --- a/src/Calendar.spec.jsx +++ b/src/Calendar.spec.jsx @@ -343,6 +343,38 @@ describe('Calendar', () => { }); }); + describe('handles active start date change properly', () => { + it('changes active start date when allowed', () => { + const component = mount( + , + ); + + 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( + , + ); + + 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(); @@ -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( - , - ); - - 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);