1 | import { dateLib } from "..";
|
2 | import { getPreviousMonth } from "./getPreviousMonth";
|
3 |
|
4 | it("should return undefined if navigation is disabled", () => {
|
5 | const firstDisplayedMonth = new Date(2022, 0, 1);
|
6 | const calendarStartMonth = new Date(2022, 0, 1);
|
7 | const props = {
|
8 | disableNavigation: true,
|
9 | pagedNavigation: false,
|
10 | numberOfMonths: 1
|
11 | };
|
12 |
|
13 | const result = getPreviousMonth(
|
14 | firstDisplayedMonth,
|
15 | calendarStartMonth,
|
16 | props,
|
17 | dateLib
|
18 | );
|
19 |
|
20 | expect(result).toBeUndefined();
|
21 | });
|
22 |
|
23 | it("should return the previous month if startMonth is not provided", () => {
|
24 | const firstDisplayedMonth = new Date(2022, 1, 1);
|
25 | const props = {
|
26 | disableNavigation: false,
|
27 | pagedNavigation: false,
|
28 | numberOfMonths: 1
|
29 | };
|
30 |
|
31 | const result = getPreviousMonth(
|
32 | firstDisplayedMonth,
|
33 | undefined,
|
34 | props,
|
35 | dateLib
|
36 | );
|
37 |
|
38 | expect(result).toEqual(new Date(2022, 0, 1));
|
39 | });
|
40 |
|
41 | it("should return undefined if the previous month is before the startMonth", () => {
|
42 | const firstDisplayedMonth = new Date(2022, 0, 1);
|
43 | const calendarStartMonth = new Date(2022, 0, 1);
|
44 | const props = {
|
45 | disableNavigation: false,
|
46 | pagedNavigation: false,
|
47 | numberOfMonths: 1
|
48 | };
|
49 | const result = getPreviousMonth(
|
50 | firstDisplayedMonth,
|
51 | calendarStartMonth,
|
52 | props,
|
53 | dateLib
|
54 | );
|
55 | expect(result).toBeUndefined();
|
56 | });
|
57 |
|
58 | it("should return the correct previous month when pagedNavigation is true", () => {
|
59 | const firstDisplayedMonth = new Date(2022, 2, 1);
|
60 | const calendarStartMonth = new Date(2022, 0, 1);
|
61 | const props = {
|
62 | disableNavigation: false,
|
63 | pagedNavigation: true,
|
64 | numberOfMonths: 2,
|
65 | startMonth: new Date(2022, 0, 1),
|
66 | dateLib
|
67 | };
|
68 |
|
69 | const result = getPreviousMonth(
|
70 | firstDisplayedMonth,
|
71 | calendarStartMonth,
|
72 | props,
|
73 | dateLib
|
74 | );
|
75 |
|
76 | expect(result).toEqual(new Date(2022, 0, 1));
|
77 | });
|