1 | import React from "react";
|
2 |
|
3 | import { addDays } from "date-fns";
|
4 |
|
5 | import { dateButton, gridcell } from "@/test/elements";
|
6 | import { render } from "@/test/render";
|
7 | import { user } from "@/test/user";
|
8 |
|
9 | import { RangeMinMax } from "./RangeMinMax";
|
10 |
|
11 | const today = new Date(2022, 8, 12);
|
12 |
|
13 | beforeAll(() => jest.setSystemTime(today));
|
14 | afterAll(() => jest.useRealTimers());
|
15 |
|
16 | beforeEach(() => render(<RangeMinMax />));
|
17 |
|
18 | describe("when a day is clicked", () => {
|
19 | const firstDay = new Date(2022, 8, 13);
|
20 | beforeEach(async () => {
|
21 | await user.click(dateButton(firstDay));
|
22 | });
|
23 | test("should be selected", () => {
|
24 | expect(gridcell(firstDay, true)).toHaveAttribute("aria-selected", "true");
|
25 | });
|
26 | describe("when the day after min is clicked", () => {
|
27 | const dayAfter = addDays(firstDay, 4);
|
28 | beforeEach(async () => {
|
29 | await user.click(dateButton(dayAfter));
|
30 | });
|
31 | test("a range should be selected", () => {
|
32 | expect(gridcell(firstDay, true)).toHaveAttribute("aria-selected", "true");
|
33 | expect(gridcell(addDays(firstDay, 1), true)).toHaveAttribute(
|
34 | "aria-selected",
|
35 | "true"
|
36 | );
|
37 | expect(gridcell(addDays(firstDay, 2), true)).toHaveAttribute(
|
38 | "aria-selected",
|
39 | "true"
|
40 | );
|
41 | expect(gridcell(addDays(firstDay, 3), true)).toHaveAttribute(
|
42 | "aria-selected",
|
43 | "true"
|
44 | );
|
45 | });
|
46 | });
|
47 | });
|