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 { MultipleMinMax } from "./MultipleMinMax";
|
10 |
|
11 | const today = new Date(2021, 10, 10);
|
12 |
|
13 | beforeAll(() => jest.setSystemTime(today));
|
14 | afterAll(() => jest.useRealTimers());
|
15 |
|
16 | const days = [
|
17 | today,
|
18 | addDays(today, 1),
|
19 | addDays(today, 2),
|
20 | addDays(today, 3),
|
21 | addDays(today, 4)
|
22 | ];
|
23 |
|
24 | beforeEach(() => {
|
25 | render(<MultipleMinMax />);
|
26 | });
|
27 |
|
28 | describe("when a day is clicked", () => {
|
29 | beforeEach(async () => {
|
30 | await user.click(dateButton(days[0]));
|
31 | });
|
32 | test("should appear as selected", () => {
|
33 | expect(gridcell(days[0], true)).toHaveAttribute("aria-selected", "true");
|
34 | });
|
35 | describe("when a second day is clicked", () => {
|
36 | beforeEach(async () => {
|
37 | await user.click(dateButton(days[1]));
|
38 | });
|
39 | test("the first day should appear as selected", () => {
|
40 | expect(gridcell(days[0], true)).toHaveAttribute("aria-selected", "true");
|
41 | });
|
42 | test("the second day should appear as selected", () => {
|
43 | expect(gridcell(days[1], true)).toHaveAttribute("aria-selected", "true");
|
44 | });
|
45 | describe("when clicked again", () => {
|
46 | beforeEach(async () => {
|
47 | await user.click(dateButton(days[1]));
|
48 | });
|
49 | test("the first day should still appear as selected", () => {
|
50 | expect(gridcell(days[0], true)).toHaveAttribute(
|
51 | "aria-selected",
|
52 | "true"
|
53 | );
|
54 | });
|
55 | test("the second day should still appear as selected", () => {
|
56 | expect(gridcell(days[1], true)).toHaveAttribute(
|
57 | "aria-selected",
|
58 | "true"
|
59 | );
|
60 | });
|
61 | });
|
62 | });
|
63 | });
|
64 |
|
65 | describe("when the first 5 days are clicked", () => {
|
66 | beforeEach(async () => {
|
67 | await user.click(dateButton(days[0]));
|
68 | await user.click(dateButton(days[1]));
|
69 | await user.click(dateButton(days[2]));
|
70 | await user.click(dateButton(days[3]));
|
71 | await user.click(dateButton(days[4]));
|
72 | });
|
73 | test.each(days)("the %s day should appear as selected", (day) => {
|
74 | expect(gridcell(day, true)).toHaveAttribute("aria-selected", "true");
|
75 | });
|
76 | test("the sixth day should not appear as selected", () => {
|
77 | const day6 = addDays(today, 5);
|
78 | expect(gridcell(day6, true)).not.toHaveAttribute("aria-selected");
|
79 | });
|
80 | });
|