1 | import { dateLib } from "../lib";
|
2 |
|
3 | import { getNavMonths } from "./getNavMonth";
|
4 |
|
5 | describe('when "startMonth" is not passed in', () => {
|
6 | test('"startMonth" should be undefined', () => {
|
7 | const [navStartMonth] = getNavMonths({}, dateLib);
|
8 | expect(navStartMonth).toBeUndefined();
|
9 | });
|
10 | });
|
11 | describe('when "startMonth" is passed in', () => {
|
12 | const [navStartMonth] = getNavMonths(
|
13 | {
|
14 | startMonth: new Date(2021, 4, 3)
|
15 | },
|
16 | dateLib
|
17 | );
|
18 | test('"startMonth" should be the start of that month', () => {
|
19 | expect(navStartMonth).toEqual(new Date(2021, 4, 1));
|
20 | });
|
21 | describe('when "fromYear" is passed in', () => {
|
22 | test('"startMonth" should be the start of that month', () => {
|
23 | expect(navStartMonth).toEqual(new Date(2021, 4, 1));
|
24 | });
|
25 | });
|
26 | });
|
27 | describe('when "fromYear" is passed in', () => {
|
28 | const [navStartMonth] = getNavMonths({ fromYear: 2021 }, dateLib);
|
29 | test('"startMonth" should be the start of that year', () => {
|
30 | expect(navStartMonth).toEqual(new Date(2021, 0, 1));
|
31 | });
|
32 | });
|
33 | describe('when "endMonth" is passed in', () => {
|
34 | const [, navEndMonth] = getNavMonths(
|
35 | {
|
36 | endMonth: new Date(2021, 4, 3)
|
37 | },
|
38 | dateLib
|
39 | );
|
40 | test('"endMonth" should be the end of that month', () => {
|
41 | expect(navEndMonth).toEqual(new Date(2021, 4, 31));
|
42 | });
|
43 | describe('when "fromYear" is passed in', () => {
|
44 | test('"endMonth" should be the end of that month', () => {
|
45 | expect(navEndMonth).toEqual(new Date(2021, 4, 31));
|
46 | });
|
47 | });
|
48 | });
|
49 |
|
50 | describe('when "toYear" is passed in', () => {
|
51 | const toYear = 2021;
|
52 | const expectedendMonth = new Date(2021, 11, 31);
|
53 | const [, navEndMonth] = getNavMonths({ toYear }, dateLib);
|
54 | test('"endMonth" should be the end of that year', () => {
|
55 | expect(navEndMonth).toEqual(expectedendMonth);
|
56 | });
|
57 | });
|
58 |
|
59 | describe('when "captionLayout" is dropdown', () => {
|
60 | const today = new Date(2024, 4, 3);
|
61 | const [navStartMonth, navEndMonth] = getNavMonths(
|
62 | {
|
63 | captionLayout: "dropdown",
|
64 | today
|
65 | },
|
66 | dateLib
|
67 | );
|
68 | test('"startMonth" should be 100 years ago', () => {
|
69 | expect(navStartMonth).toEqual(new Date(1924, 0, 1));
|
70 | });
|
71 | test('"endMonth" should be the end of this year', () => {
|
72 | expect(navEndMonth).toEqual(new Date(2024, 11, 31));
|
73 | });
|
74 | describe('when "fromYear" is set', () => {
|
75 | const today = new Date(2024, 4, 3);
|
76 | const fromYear = 2022;
|
77 | const [navStartMonth, navEndMonth] = getNavMonths(
|
78 | {
|
79 | captionLayout: "dropdown",
|
80 | fromYear,
|
81 | today
|
82 | },
|
83 | dateLib
|
84 | );
|
85 | test('"startMonth" should be equal to the "fromYear"', () => {
|
86 | expect(navStartMonth).toEqual(new Date(2022, 0, 1));
|
87 | });
|
88 | test('"endMonth" should be the end of this year', () => {
|
89 | expect(navEndMonth).toEqual(new Date(2024, 11, 31));
|
90 | });
|
91 | });
|
92 | describe('when "toYear" is set', () => {
|
93 | const today = new Date(2021, 4, 3);
|
94 | const toYear = 2022;
|
95 | const [navStartMonth, navEndMonth] = getNavMonths(
|
96 | {
|
97 | captionLayout: "dropdown",
|
98 | toYear,
|
99 | today
|
100 | },
|
101 | dateLib
|
102 | );
|
103 | test('"startMonth" should be 100 years ago', () => {
|
104 | expect(navStartMonth).toEqual(new Date(1921, 0, 1));
|
105 | });
|
106 | test('"endMonth" should be equal to "toYear"', () => {
|
107 | expect(navEndMonth).toEqual(new Date(2022, 11, 31));
|
108 | });
|
109 | });
|
110 | });
|