|
1 | 1 | import { render } from "@testing-library/react"; |
2 | | -import { subDays } from "date-fns"; |
| 2 | +import { addDays, subDays } from "date-fns"; |
3 | 3 | import React from "react"; |
4 | 4 |
|
5 | 5 | import DatePicker from "../index"; |
6 | 6 |
|
7 | 7 | describe("DatePicker", () => { |
8 | | - const excludeDates = [new Date(), subDays(new Date(), 1)]; |
| 8 | + const today = new Date(); |
| 9 | + // otherDate must be in same month, otherwise it will not be shown on the calendar |
| 10 | + const otherDate = |
| 11 | + today.getDate() === 1 ? addDays(today, 1) : subDays(today, 1); |
| 12 | + const excludeDates = [today, otherDate]; |
9 | 13 | const excludeDatesWithMessages = [ |
10 | | - { date: subDays(new Date(), 1), message: "This day is excluded" }, |
11 | | - { date: new Date(), message: "Today is excluded" }, |
| 14 | + { date: otherDate, message: "This day is excluded" }, |
| 15 | + { date: today, message: "Today is excluded" }, |
12 | 16 | ]; |
13 | 17 |
|
14 | 18 | it("should disable dates specified in excludeDates props", () => { |
@@ -40,11 +44,11 @@ describe("DatePicker", () => { |
40 | 44 | ); |
41 | 45 |
|
42 | 46 | expect(disabledTimeItems.length).toBe(excludeDatesWithMessages.length); |
43 | | - expect(disabledTimeItems[0]?.getAttribute("title")).toBe( |
44 | | - "This day is excluded", |
45 | | - ); |
46 | | - expect(disabledTimeItems[1]?.getAttribute("title")).toBe( |
47 | | - "Today is excluded", |
48 | | - ); |
| 47 | + expect( |
| 48 | + disabledTimeItems[today < otherDate ? 1 : 0]?.getAttribute("title"), |
| 49 | + ).toBe("This day is excluded"); |
| 50 | + expect( |
| 51 | + disabledTimeItems[today < otherDate ? 0 : 1]?.getAttribute("title"), |
| 52 | + ).toBe("Today is excluded"); |
49 | 53 | }); |
50 | 54 | }); |
0 commit comments