1 | import { addMonths, isSameMonth } from "date-fns";
|
2 | import { dateLib } from "react-day-picker";
|
3 |
|
4 | import { getNextMonth } from "./getNextMonth";
|
5 |
|
6 | const startingMonth = new Date(2020, 4, 31);
|
7 |
|
8 | describe("when number of months is 1", () => {
|
9 | describe("when the navigation is disabled", () => {
|
10 | it("the next month is undefined", () => {
|
11 | const result = getNextMonth(
|
12 | startingMonth,
|
13 | undefined,
|
14 | {
|
15 | disableNavigation: true
|
16 | },
|
17 | dateLib
|
18 | );
|
19 | expect(result).toBe(undefined);
|
20 | });
|
21 | });
|
22 | describe("when in the navigable range", () => {
|
23 | const endMonth = addMonths(startingMonth, 3);
|
24 | it("the next month is not undefined", () => {
|
25 | const result = getNextMonth(startingMonth, endMonth, {}, dateLib);
|
26 | const expectedNextMonth = addMonths(startingMonth, 1);
|
27 | expect(result && isSameMonth(result, expectedNextMonth)).toBeTruthy();
|
28 | });
|
29 | });
|
30 | describe("when not in the navigable range", () => {
|
31 | const endMonth = startingMonth;
|
32 | it("the next month is undefined", () => {
|
33 | const result = getNextMonth(startingMonth, endMonth, {}, dateLib);
|
34 | expect(result).toBe(undefined);
|
35 | });
|
36 | });
|
37 | });
|
38 | describe("when displaying 3 months", () => {
|
39 | const numberOfMonths = 3;
|
40 | describe("when the navigation is paged", () => {
|
41 | const pagedNavigation = true;
|
42 | it("the next month is 3 months ahead", () => {
|
43 | const result = getNextMonth(
|
44 | startingMonth,
|
45 | undefined,
|
46 | {
|
47 | numberOfMonths,
|
48 | pagedNavigation
|
49 | },
|
50 | dateLib
|
51 | );
|
52 | const expectedNextMonth = addMonths(startingMonth, 3);
|
53 | expect(result && isSameMonth(result, expectedNextMonth)).toBeTruthy();
|
54 | });
|
55 | describe("when the to-date is ahead less than 3 months", () => {
|
56 | it("the next month is undefined", () => {
|
57 | const result = getNextMonth(
|
58 | startingMonth,
|
59 | addMonths(startingMonth, 1),
|
60 | {
|
61 | numberOfMonths,
|
62 | pagedNavigation
|
63 | },
|
64 | dateLib
|
65 | );
|
66 | expect(result).toBe(undefined);
|
67 | });
|
68 | });
|
69 | });
|
70 | describe("when the navigation is not paged", () => {
|
71 | const pagedNavigation = false;
|
72 | it("the next month is 1 months ahead", () => {
|
73 | const result = getNextMonth(
|
74 | startingMonth,
|
75 | undefined,
|
76 | {
|
77 | numberOfMonths,
|
78 | pagedNavigation
|
79 | },
|
80 | dateLib
|
81 | );
|
82 | const expectedNextMonth = addMonths(startingMonth, 1);
|
83 | expect(result && isSameMonth(result, expectedNextMonth)).toBeTruthy();
|
84 | });
|
85 | describe("when the to-date is ahead less than 3 months", () => {
|
86 | it("the next month is undefined", () => {
|
87 | const result = getNextMonth(
|
88 | startingMonth,
|
89 | addMonths(startingMonth, 2),
|
90 | {
|
91 | numberOfMonths,
|
92 | pagedNavigation
|
93 | },
|
94 | dateLib
|
95 | );
|
96 | expect(result).toBe(undefined);
|
97 | });
|
98 | });
|
99 | });
|
100 | });
|