@@ -23,45 +23,81 @@ describe('createCalendarInfo function', () => {
2323 expect ( result . weeksInMonth ) . toBe ( 5 )
2424 } )
2525
26- it ( 'getTargetDate return Date value ' , ( ) => {
26+ it ( 'getCurrentWeekIndex return current week (number) ' , ( ) => {
2727 // Given
28- const date = new Date ( 2020 , 11 , 27 )
29- const weekStartsOn = 0 // start Sunday
3028 // When
31- const result = createCalendarInfo ( date , weekStartsOn ) . getTargetDate ( 1 , 1 )
29+ const info1 = createCalendarInfo ( new Date ( 2020 , 11 , 27 ) , 0 )
30+ const info2 = createCalendarInfo ( new Date ( 2020 , 10 , 1 ) , 0 )
31+ const info3 = createCalendarInfo ( new Date ( 2020 , 11 , 7 ) , 0 )
3232 // Then
33- expect ( result . getMonth ( ) ) . toBe ( 11 )
34- expect ( result . getDate ( ) ) . toBe ( 7 )
33+ expect ( info1 . getCurrentWeekIndex ( ) ) . toBe ( 4 )
34+ expect ( info2 . getCurrentWeekIndex ( ) ) . toBe ( 0 )
35+ expect ( info3 . getCurrentWeekIndex ( ) ) . toBe ( 1 )
3536 } )
3637
37- it ( 'getCurrentWeek return current week (number) ' , ( ) => {
38+ it ( 'getDateCellByIndex return Date value ' , ( ) => {
3839 // Given
40+ const date = new Date ( 2020 , 11 , 27 )
41+ const weekStartsOn = 0 // start Sunday
3942 // When
40- const info1 = createCalendarInfo ( new Date ( 2020 , 11 , 27 ) , 0 )
41- const info2 = createCalendarInfo ( new Date ( 2020 , 10 , 1 ) , 0 )
42- const info3 = createCalendarInfo ( new Date ( 2020 , 11 , 7 ) , 0 )
43+ const result = createCalendarInfo ( date , weekStartsOn ) . getDateCellByIndex (
44+ 1 ,
45+ 1 ,
46+ )
4347 // Then
44- expect ( info1 . getCurrentWeek ( ) ) . toBe ( 4 )
45- expect ( info2 . getCurrentWeek ( ) ) . toBe ( 0 )
46- expect ( info3 . getCurrentWeek ( ) ) . toBe ( 1 )
48+ expect ( result . value ) . toStrictEqual ( new Date ( 2020 , 11 , 7 ) )
4749 } )
4850
49- it ( 'getWeek return target week' , ( ) => {
51+ it ( 'getWeekRow return target week' , ( ) => {
5052 // Given
5153 const weekIndex = 4
52-
54+
5355 // When
5456 const calendar = createCalendarInfo ( new Date ( 2020 , 11 , 27 ) , 0 )
5557 // Then
5658 const expected = [
57- new Date ( 2020 , 11 , 27 ) ,
58- new Date ( 2020 , 11 , 28 ) ,
59- new Date ( 2020 , 11 , 29 ) ,
60- new Date ( 2020 , 11 , 30 ) ,
61- new Date ( 2020 , 11 , 31 ) ,
62- new Date ( 2021 , 0 , 1 ) ,
63- new Date ( 2021 , 0 , 2 ) ,
59+ { value : new Date ( 2020 , 11 , 27 ) } ,
60+ { value : new Date ( 2020 , 11 , 28 ) } ,
61+ { value : new Date ( 2020 , 11 , 29 ) } ,
62+ { value : new Date ( 2020 , 11 , 30 ) } ,
63+ { value : new Date ( 2020 , 11 , 31 ) } ,
64+ { value : new Date ( 2021 , 0 , 1 ) } ,
65+ { value : new Date ( 2021 , 0 , 2 ) } ,
6466 ]
65- expect ( calendar . getWeek ( weekIndex ) ) . toEqual ( expected )
67+ expect ( calendar . getWeekRow ( weekIndex ) . value ) . toStrictEqual ( expected )
68+ } )
69+
70+ it ( 'getMonth return target month' , ( ) => {
71+ // Given
72+ const weeks = 2
73+
74+ // When
75+ const result = createCalendarInfo ( new Date ( 2020 , 11 , 27 ) , 0 ) . getMonth ( weeks )
76+
77+ // Then
78+ expect ( result . value ) . toStrictEqual ( [
79+ {
80+ value : [
81+ { value : new Date ( 2020 , 10 , 29 ) } ,
82+ { value : new Date ( 2020 , 10 , 30 ) } ,
83+ { value : new Date ( 2020 , 11 , 1 ) } ,
84+ { value : new Date ( 2020 , 11 , 2 ) } ,
85+ { value : new Date ( 2020 , 11 , 3 ) } ,
86+ { value : new Date ( 2020 , 11 , 4 ) } ,
87+ { value : new Date ( 2020 , 11 , 5 ) } ,
88+ ] ,
89+ } ,
90+ {
91+ value : [
92+ { value : new Date ( 2020 , 11 , 6 ) } ,
93+ { value : new Date ( 2020 , 11 , 7 ) } ,
94+ { value : new Date ( 2020 , 11 , 8 ) } ,
95+ { value : new Date ( 2020 , 11 , 9 ) } ,
96+ { value : new Date ( 2020 , 11 , 10 ) } ,
97+ { value : new Date ( 2020 , 11 , 11 ) } ,
98+ { value : new Date ( 2020 , 11 , 12 ) } ,
99+ ] ,
100+ } ,
101+ ] )
66102 } )
67103} )
0 commit comments