@@ -2,7 +2,6 @@ import moment from 'moment';
22import {
33 getDateString ,
44 getMaxEndDate ,
5- getMinStartDate ,
65 getRange ,
76 getRangeDisplayText ,
87 getShortcuts ,
@@ -39,43 +38,6 @@ describe('DateRangePicker helpers', () => {
3938 } ) ;
4039 } ) ;
4140
42- describe ( 'getMinStartDate' , ( ) => {
43- describe ( 'When moment is set to March 10th 2020' , ( ) => {
44- beforeEach ( ( ) => {
45- jest
46- . spyOn ( Date , 'now' )
47- . mockImplementation ( ( ) => new Date ( 2020 , 2 , 10 ) . getTime ( ) ) ;
48- } ) ;
49-
50- describe ( 'and maxDays = 1' , ( ) => {
51- it ( 'should return date March 9th 2020.' , ( ) => {
52- const maxDays = 1 ;
53- const output = getMinStartDate ( maxDays ) ;
54-
55- expect ( output . toISOString ( ) ) . toEqual ( '2020-03-09T07:00:00.000Z' ) ;
56- } ) ;
57- } ) ;
58-
59- describe ( 'and maxDays = 3' , ( ) => {
60- it ( 'should return date March 7th 2020.' , ( ) => {
61- const maxDays = 3 ;
62- const output = getMinStartDate ( maxDays ) ;
63-
64- expect ( output . toISOString ( ) ) . toEqual ( '2020-03-07T08:00:00.000Z' ) ;
65- } ) ;
66- } ) ;
67-
68- describe ( 'and maxDays = 30' , ( ) => {
69- it ( 'should return date Feburary 9th 2020.' , ( ) => {
70- const maxDays = 30 ;
71- const output = getMinStartDate ( maxDays ) ;
72-
73- expect ( output . toISOString ( ) ) . toEqual ( '2020-02-09T08:00:00.000Z' ) ;
74- } ) ;
75- } ) ;
76- } ) ;
77- } ) ;
78-
7941 describe ( 'getRange' , ( ) => {
8042 describe ( 'When dateRange = "".' , ( ) => {
8143 it ( 'should return [].' , ( ) => {
@@ -370,27 +332,18 @@ describe('DateRangePicker helpers', () => {
370332 } ) ;
371333
372334 describe ( 'getShortcuts' , ( ) => {
373- describe ( 'When maxDays = 1' , ( ) => {
335+ describe ( 'When maxDays = 1 and minStartDate is defined ' , ( ) => {
374336 const maxDays = 1 ;
375-
376- describe ( 'and onClick function is called' , ( ) => {
377- it ( 'should try to call the passed in onClickHandler.' , ( ) => {
378- const onClickHandler = jest . fn ( ) ;
379- const output = getShortcuts ( maxDays , onClickHandler ) ;
380-
381- output [ 0 ] . onClick ( ) ;
382- expect ( onClickHandler ) . toHaveBeenCalled ( ) ;
383- } ) ;
384- } ) ;
337+ const minStartDate = { } ;
385338
386339 it ( 'should return 4 shortcuts.' , ( ) => {
387- const output = getShortcuts ( maxDays ) ;
340+ const output = getShortcuts ( maxDays , minStartDate ) ;
388341
389342 expect ( output . length ) . toEqual ( 4 ) ;
390343 } ) ;
391344
392345 it ( 'should not contain "Last 24 hours".' , ( ) => {
393- const output = getShortcuts ( maxDays ) ;
346+ const output = getShortcuts ( maxDays , minStartDate ) ;
394347 const last24HourOption = output . find (
395348 option => option . text === 'Last 24 hours'
396349 ) ;
@@ -399,75 +352,97 @@ describe('DateRangePicker helpers', () => {
399352 } ) ;
400353
401354 it ( 'should return the last option as "Last 1 day".' , ( ) => {
402- const output = getShortcuts ( maxDays ) ;
355+ const output = getShortcuts ( maxDays , minStartDate ) ;
403356 const lastOption = output [ output . length - 1 ] ;
404357
405358 expect ( lastOption . text ) . toEqual ( 'Last 1 day' ) ;
406359 } ) ;
407360 } ) ;
408361
409- describe ( 'When maxDays = 3' , ( ) => {
362+ describe ( 'When maxDays = 3 and minStartDate is defined ' , ( ) => {
410363 const maxDays = 3 ;
364+ const minStartDate = { } ;
411365
412366 it ( 'should return 5 shortcuts.' , ( ) => {
413- const output = getShortcuts ( maxDays ) ;
367+ const output = getShortcuts ( maxDays , minStartDate ) ;
414368
415369 expect ( output . length ) . toEqual ( 5 ) ;
416370 } ) ;
417371
418372 it ( 'should return the last option as "Last 3 days".' , ( ) => {
419- const output = getShortcuts ( maxDays ) ;
373+ const output = getShortcuts ( maxDays , minStartDate ) ;
420374 const lastOption = output [ output . length - 1 ] ;
421375
422376 expect ( lastOption . text ) . toEqual ( 'Last 3 days' ) ;
423377 } ) ;
424378 } ) ;
425379
426- describe ( 'When maxDays = 7' , ( ) => {
380+ describe ( 'When maxDays = 7 and minStartDate is defined ' , ( ) => {
427381 const maxDays = 7 ;
382+ const minStartDate = { } ;
428383
429384 it ( 'should return 6 shortcuts.' , ( ) => {
430- const output = getShortcuts ( maxDays ) ;
385+ const output = getShortcuts ( maxDays , minStartDate ) ;
431386
432387 expect ( output . length ) . toEqual ( 6 ) ;
433388 } ) ;
434389
435390 it ( 'should return the last option as "Last 7 days".' , ( ) => {
436- const output = getShortcuts ( maxDays ) ;
391+ const output = getShortcuts ( maxDays , minStartDate ) ;
437392 const lastOption = output [ output . length - 1 ] ;
438393
439394 expect ( lastOption . text ) . toEqual ( 'Last 7 days' ) ;
440395 } ) ;
441396 } ) ;
442397
443- describe ( 'When maxDays = 30' , ( ) => {
398+ describe ( 'When maxDays = 30 and minStartDate is defined ' , ( ) => {
444399 const maxDays = 30 ;
400+ const minStartDate = { } ;
445401
446402 it ( 'should return 7 shortcuts.' , ( ) => {
447- const output = getShortcuts ( maxDays ) ;
403+ const output = getShortcuts ( maxDays , minStartDate ) ;
448404
449405 expect ( output . length ) . toEqual ( 7 ) ;
450406 } ) ;
451407
452408 it ( 'should return the last option as "Last 30 days".' , ( ) => {
453- const output = getShortcuts ( maxDays ) ;
409+ const output = getShortcuts ( maxDays , minStartDate ) ;
454410 const lastOption = output [ output . length - 1 ] ;
455411
456412 expect ( lastOption . text ) . toEqual ( 'Last 30 days' ) ;
457413 } ) ;
458414 } ) ;
459415
460- describe ( 'When maxDays = 90' , ( ) => {
416+ describe ( 'When maxDays = 90 and minStartDate is defined ' , ( ) => {
461417 const maxDays = 90 ;
418+ const minStartDate = { } ;
462419
463420 it ( 'should return 8 shortcuts.' , ( ) => {
464- const output = getShortcuts ( maxDays ) ;
421+ const output = getShortcuts ( maxDays , minStartDate ) ;
422+
423+ expect ( output . length ) . toEqual ( 8 ) ;
424+ } ) ;
425+
426+ it ( 'should return the last option as "Last 3 months".' , ( ) => {
427+ const output = getShortcuts ( maxDays , minStartDate ) ;
428+ const lastOption = output [ output . length - 1 ] ;
429+
430+ expect ( lastOption . text ) . toEqual ( 'Last 3 months' ) ;
431+ } ) ;
432+ } ) ;
433+
434+ describe ( 'When maxDays = 3 and minStartDate = null' , ( ) => {
435+ const maxDays = 3 ;
436+ const minStartDate = null ;
437+
438+ it ( 'should return 8 shortcuts' , ( ) => {
439+ const output = getShortcuts ( maxDays , minStartDate ) ;
465440
466441 expect ( output . length ) . toEqual ( 8 ) ;
467442 } ) ;
468443
469444 it ( 'should return the last option as "Last 3 months".' , ( ) => {
470- const output = getShortcuts ( maxDays ) ;
445+ const output = getShortcuts ( maxDays , minStartDate ) ;
471446 const lastOption = output [ output . length - 1 ] ;
472447
473448 expect ( lastOption . text ) . toEqual ( 'Last 3 months' ) ;
0 commit comments