|
1 |
| -import { datesAreWithinMaxRange } from "./utils"; |
| 1 | +import { datesAreWithinMaxRange, isDateRangeTheWholeMonth } from "./utils"; |
2 | 2 |
|
3 | 3 | describe("DatePicker utils", () => {
|
4 | 4 | describe("checking if two dates are fall within a range", () => {
|
5 | 5 | it("returns true if the two dates are within the range", () => {
|
6 |
| - const date1 = new Date("07-01-2025"); |
7 |
| - const date2 = new Date("07-08-2025"); |
| 6 | + const startDate = new Date("07-01-2025"); |
| 7 | + const endDate = new Date("07-08-2025"); |
8 | 8 |
|
9 |
| - expect(datesAreWithinMaxRange(date1, date2, 15)).toBeTruthy(); |
| 9 | + expect(datesAreWithinMaxRange(startDate, endDate, 15)).toBeTruthy(); |
10 | 10 | });
|
11 | 11 |
|
12 | 12 | it("returns false if the two dates are not within the range", () => {
|
13 |
| - const date1 = new Date("07-01-2025"); |
14 |
| - const date2 = new Date("07-31-2025"); |
| 13 | + const startDate = new Date("07-01-2025"); |
| 14 | + const endDate = new Date("07-31-2025"); |
15 | 15 |
|
16 |
| - expect(datesAreWithinMaxRange(date1, date2, 15)).toBeFalsy(); |
17 |
| - }) |
| 16 | + expect(datesAreWithinMaxRange(startDate, endDate, 15)).toBeFalsy(); |
| 17 | + }); |
18 | 18 |
|
19 | 19 | it("is inclusive with dates", () => {
|
20 |
| - const date1 = new Date("07-01-2025"); |
21 |
| - const date2 = new Date("07-16-2025"); |
| 20 | + const startDate = new Date("07-01-2025"); |
| 21 | + const endDate = new Date("07-16-2025"); |
22 | 22 |
|
23 |
| - expect(datesAreWithinMaxRange(date1, date2, 15)).toBeTruthy(); |
24 |
| - }) |
| 23 | + expect(datesAreWithinMaxRange(startDate, endDate, 15)).toBeTruthy(); |
| 24 | + }); |
| 25 | + }); |
| 26 | + |
| 27 | + describe("checking if a date range occupies an entire month", () => { |
| 28 | + it("returns false is the date range don't have the same month", () => { |
| 29 | + const startDate = new Date("07-01-2025"); |
| 30 | + const endDate = new Date("08-16-2025"); |
| 31 | + expect(isDateRangeTheWholeMonth({ startDate, endDate })).toBeFalsy(); |
| 32 | + }); |
| 33 | + |
| 34 | + it("returns false is the date range starts before the first day in the same month", () => { |
| 35 | + const startDate = new Date("07-02-2025"); |
| 36 | + const endDate = new Date("07-31-2025"); |
| 37 | + expect(isDateRangeTheWholeMonth({ startDate, endDate })).toBeFalsy(); |
| 38 | + }); |
| 39 | + |
| 40 | + it("returns false is the date range ends before the last day in the same month", () => { |
| 41 | + const startDate = new Date("07-01-2025"); |
| 42 | + const endDate = new Date("07-30-2025"); |
| 43 | + expect(isDateRangeTheWholeMonth({ startDate, endDate })).toBeFalsy(); |
| 44 | + }); |
| 45 | + |
| 46 | + it("returns true is the date range occupies the whole month", () => { |
| 47 | + let startDate = new Date("07-01-2025"); |
| 48 | + let endDate = new Date("07-31-2025"); |
| 49 | + expect(isDateRangeTheWholeMonth({ startDate, endDate })).toBeTruthy(); |
| 50 | + |
| 51 | + startDate = new Date("08-01-2025"); |
| 52 | + endDate = new Date("08-31-2025"); |
| 53 | + expect(isDateRangeTheWholeMonth({ startDate, endDate })).toBeTruthy(); |
| 54 | + |
| 55 | + startDate = new Date("09-01-2025"); |
| 56 | + endDate = new Date("09-30-2025"); |
| 57 | + expect(isDateRangeTheWholeMonth({ startDate, endDate })).toBeTruthy(); |
| 58 | + |
| 59 | + startDate = new Date("02-01-2025"); |
| 60 | + endDate = new Date("02-28-2025"); |
| 61 | + expect(isDateRangeTheWholeMonth({ startDate, endDate })).toBeTruthy(); |
| 62 | + }); |
| 63 | + |
| 64 | + it("handles leap years", () => { |
| 65 | + // 2024 was a leap year |
| 66 | + let startDate = new Date("02-01-2024"); |
| 67 | + let endDate = new Date("02-29-2024"); |
| 68 | + expect(isDateRangeTheWholeMonth({ startDate, endDate })).toBeTruthy(); |
| 69 | + |
| 70 | + startDate = new Date("02-01-2024"); |
| 71 | + endDate = new Date("02-28-2024"); |
| 72 | + expect(isDateRangeTheWholeMonth({ startDate, endDate })).toBeFalsy(); |
| 73 | + }); |
25 | 74 | });
|
26 | 75 | });
|
0 commit comments