1 | import { DayPickerProps } from "react-day-picker";
|
2 |
|
3 | import { CalendarMonth } from "../classes";
|
4 | import { dateLib } from "../lib";
|
5 |
|
6 | import { getMonths } from "./getMonths";
|
7 |
|
8 | const mockDates = [
|
9 | new Date(2023, 4, 27),
|
10 | new Date(2023, 5, 1),
|
11 | new Date(2023, 5, 8),
|
12 | new Date(2023, 5, 15),
|
13 | new Date(2023, 5, 22),
|
14 | new Date(2023, 5, 30),
|
15 | new Date(2023, 6, 6)
|
16 | ];
|
17 |
|
18 | const mockProps: Pick<
|
19 | DayPickerProps,
|
20 | | "fixedWeeks"
|
21 | | "ISOWeek"
|
22 | | "locale"
|
23 | | "weekStartsOn"
|
24 | | "reverseMonths"
|
25 | | "firstWeekContainsDate"
|
26 | > = {
|
27 | fixedWeeks: false,
|
28 | ISOWeek: false,
|
29 | locale: undefined,
|
30 | weekStartsOn: 0,
|
31 | reverseMonths: false,
|
32 | firstWeekContainsDate: 1
|
33 | };
|
34 |
|
35 | it("should return the correct months without ISO weeks and reverse months", () => {
|
36 | const displayMonths = [new Date(2023, 5, 1)];
|
37 |
|
38 | const result = getMonths(displayMonths, mockDates, mockProps, dateLib);
|
39 |
|
40 | expect(result).toHaveLength(1);
|
41 | expect(result[0]).toBeInstanceOf(CalendarMonth);
|
42 | expect(result[0].weeks).toHaveLength(5);
|
43 | });
|
44 |
|
45 | it("should handle ISO weeks", () => {
|
46 | const displayMonths = [new Date(2023, 5, 1)];
|
47 |
|
48 | const isoProps = { ...mockProps, ISOWeek: true };
|
49 |
|
50 | const result = getMonths(displayMonths, mockDates, isoProps, dateLib);
|
51 |
|
52 | expect(result).toHaveLength(1);
|
53 | expect(result[0]).toBeInstanceOf(CalendarMonth);
|
54 | expect(result[0].weeks).toHaveLength(5);
|
55 | });
|
56 |
|
57 | it("should handle reverse months", () => {
|
58 | const displayMonths = [
|
59 | new Date(2023, 4, 1),
|
60 | new Date(2023, 5, 1)
|
61 | ];
|
62 |
|
63 | const reverseProps = { ...mockProps, reverseMonths: true };
|
64 |
|
65 | const result = getMonths(displayMonths, mockDates, reverseProps, dateLib);
|
66 |
|
67 | expect(result).toHaveLength(2);
|
68 | expect(result[0].date).toEqual(new Date(2023, 5, 1));
|
69 | expect(result[1].date).toEqual(new Date(2023, 4, 1));
|
70 | });
|
71 |
|
72 | it("should handle fixed weeks", () => {
|
73 | const displayMonths = [new Date(2023, 5, 1)];
|
74 |
|
75 | const fixedWeeksProps = { ...mockProps, fixedWeeks: true };
|
76 |
|
77 | const result = getMonths(displayMonths, mockDates, fixedWeeksProps, dateLib);
|
78 |
|
79 | expect(result).toHaveLength(1);
|
80 | expect(result[0]).toBeInstanceOf(CalendarMonth);
|
81 | expect(result[0].weeks).toHaveLength(6);
|
82 | });
|
83 |
|
84 | it("should handle months with no dates", () => {
|
85 | const displayMonths = [new Date(2023, 5, 1)];
|
86 |
|
87 | const result = getMonths(displayMonths, [], mockProps, dateLib);
|
88 |
|
89 | expect(result).toHaveLength(1);
|
90 | expect(result[0]).toBeInstanceOf(CalendarMonth);
|
91 | expect(result[0].weeks).toHaveLength(0);
|
92 | });
|