@@ -154,6 +154,7 @@ describe('<Calendar />', () => {
154154
155155 test ( 'click year from list' , ( ) => {
156156 let wrapper = mount ( defaultCalendar ) ;
157+ const currentDateDisplayed = Object . assign ( new Date ( ) , wrapper . state ( 'currentDateDisplayed' ) ) ;
157158 expect ( wrapper . state ( 'showYears' ) ) . toBeFalsy ( ) ;
158159 wrapper
159160 . find (
@@ -169,11 +170,9 @@ describe('<Calendar />', () => {
169170 . at ( 3 )
170171 . simulate ( 'click' ) ;
171172
172- // check that April was selected
173- const currentDateDisplayed = wrapper . state ( 'currentDateDisplayed' ) ;
174- let currentYearDisplayed = new Date ( wrapper . state ( 'currentYear' ) ) ;
175- expect ( currentDateDisplayed . getFullYear ( ) ) . toEqual (
176- currentYearDisplayed . getFullYear ( ) + 3
173+ let newDateDisplayed = new Date ( wrapper . state ( 'currentDateDisplayed' ) ) ;
174+ expect ( newDateDisplayed . getFullYear ( ) ) . toEqual (
175+ currentDateDisplayed . getFullYear ( ) + 3
177176 ) ;
178177 } ) ;
179178
@@ -203,6 +202,7 @@ describe('<Calendar />', () => {
203202
204203 test ( 'click year from list from range selector' , ( ) => {
205204 let wrapper = mount ( rangeSelect ) ;
205+ const currentDateDisplayed = Object . assign ( new Date ( ) , wrapper . state ( 'currentDateDisplayed' ) ) ;
206206 expect ( wrapper . state ( 'showYears' ) ) . toBeFalsy ( ) ;
207207 wrapper
208208 . find (
@@ -218,29 +218,26 @@ describe('<Calendar />', () => {
218218 . at ( 3 )
219219 . simulate ( 'click' ) ;
220220
221- // check that April was selected
222- const currentDateDisplayed = wrapper . state ( 'currentDateDisplayed' ) ;
223- let currentYearDisplayed = new Date ( wrapper . state ( 'currentYear' ) ) ;
224- expect ( currentDateDisplayed . getFullYear ( ) ) . toEqual (
225- currentYearDisplayed . getFullYear ( ) + 3
221+ const newDateDisplayed = new Date ( wrapper . state ( 'currentDateDisplayed' ) ) ;
222+ expect ( newDateDisplayed . getFullYear ( ) ) . toEqual (
223+ currentDateDisplayed . getFullYear ( ) + 3
226224 ) ;
227225 } ) ;
228226
229227 test ( 'click previous button' , ( ) => {
230228 let wrapper = mount ( defaultCalendar ) ;
231- let currentDateDisplayed = new Date ( wrapper . state ( 'currentDateDisplayed' ) ) ;
229+ const currentDateDisplayed = Object . assign ( new Date ( ) , wrapper . state ( 'currentDateDisplayed' ) ) ;
232230
233231 wrapper
234232 . find (
235233 'header.fd-calendar__header button.fd-button--light.fd-button--compact'
236234 )
237235 . at ( 0 )
238236 . simulate ( 'click' ) ;
239- let newDateDisplayed = wrapper . state ( 'currentDateDisplayed' ) ;
240- currentDateDisplayed . setMonth ( currentDateDisplayed . getMonth ( ) - 1 ) ;
237+ const newDateDisplayed = wrapper . state ( 'currentDateDisplayed' ) ;
241238
242239 expect ( newDateDisplayed . getMonth ( ) ) . toEqual (
243- currentDateDisplayed . getMonth ( )
240+ currentDateDisplayed . getMonth ( ) - 1
244241 ) ;
245242
246243 // previous button when year shown
@@ -253,37 +250,33 @@ describe('<Calendar />', () => {
253250
254251 expect ( wrapper . state ( 'showYears' ) ) . toBeTruthy ( ) ;
255252
256- let currentYearDisplayed = new Date ( wrapper . state ( 'currentYear' ) ) ;
257253 wrapper
258254 . find (
259255 'header.fd-calendar__header button.fd-button--light.fd-button--compact'
260256 )
261257 . at ( 0 )
262258 . simulate ( 'click' ) ;
263259
264- let newYearDisplayed = wrapper . state ( 'currentYear' ) ;
265- currentYearDisplayed . setFullYear ( currentYearDisplayed . getFullYear ( ) - 12 ) ;
260+ const newYearDisplayed = wrapper . state ( 'currentDateDisplayed' ) ;
266261 expect ( newYearDisplayed . getFullYear ( ) ) . toEqual (
267- currentYearDisplayed . getFullYear ( )
262+ currentDateDisplayed . getFullYear ( ) - 12
268263 ) ;
269264 } ) ;
270265
271266 test ( 'click next button' , ( ) => {
272267 let wrapper = mount ( defaultCalendar ) ;
273- let currentDateDisplayed = new Date ( wrapper . state ( 'currentDateDisplayed' ) ) ;
268+ const currentDateDisplayed = Object . assign ( new Date ( ) , wrapper . state ( 'currentDateDisplayed' ) ) ;
274269
275270 wrapper
276271 . find (
277272 'header.fd-calendar__header button.fd-button--light.fd-button--compact'
278273 )
279274 . at ( 3 )
280275 . simulate ( 'click' ) ;
281- let newDateDisplayed = wrapper . state ( 'currentDateDisplayed' ) ;
282-
283- currentDateDisplayed . setMonth ( currentDateDisplayed . getMonth ( ) + 1 ) ;
276+ const newDateDisplayed = wrapper . state ( 'currentDateDisplayed' ) ;
284277
285278 expect ( newDateDisplayed . getMonth ( ) ) . toEqual (
286- currentDateDisplayed . getMonth ( )
279+ currentDateDisplayed . getMonth ( ) + 1
287280 ) ;
288281
289282 // previous button when year shown
@@ -296,20 +289,17 @@ describe('<Calendar />', () => {
296289
297290 expect ( wrapper . state ( 'showYears' ) ) . toBeTruthy ( ) ;
298291
299- let currentYearDisplayed = new Date ( wrapper . state ( 'currentYear' ) ) ;
300-
301292 wrapper
302293 . find (
303294 'header.fd-calendar__header button.fd-button--light.fd-button--compact'
304295 )
305296 . at ( 3 )
306297 . simulate ( 'click' ) ;
307298
308- let newYearDisplayed = wrapper . state ( 'currentYear ' ) ;
299+ const newYearDisplayed = wrapper . state ( 'currentDateDisplayed ' ) ;
309300
310- currentYearDisplayed . setFullYear ( currentYearDisplayed . getFullYear ( ) + 12 ) ;
311301 expect ( newYearDisplayed . getFullYear ( ) ) . toEqual (
312- currentYearDisplayed . getFullYear ( )
302+ currentDateDisplayed . getFullYear ( ) + 12
313303 ) ;
314304 } ) ;
315305
0 commit comments