UNPKG

2.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 { MultipleMinMax } from "./MultipleMinMax";
10
11const today = new Date(2021, 10, 10);
12
13beforeAll(() => jest.setSystemTime(today));
14afterAll(() => jest.useRealTimers());
15
16const days = [
17 today,
18 addDays(today, 1),
19 addDays(today, 2),
20 addDays(today, 3),
21 addDays(today, 4)
22];
23
24beforeEach(() => {
25 render(<MultipleMinMax />);
26});
27
28describe("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
65describe("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});