UNPKG

1.37 kBTypeScriptView Raw
1import React from "react";
2
3import { addDays } from "date-fns";
4
5import { dateButton, gridcell } from "@/test/elements";
6import { render } from "@/test/render";
7import { user } from "@/test/user";
8
9import { RangeMinMax } from "./RangeMinMax";
10
11const today = new Date(2022, 8, 12);
12
13beforeAll(() => jest.setSystemTime(today));
14afterAll(() => jest.useRealTimers());
15
16beforeEach(() => render(<RangeMinMax />));
17
18describe("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});