UNPKG

1.39 kBTypeScriptView Raw
1import React from "react";
2
3import { dateButton, gridcell } from "@/test/elements";
4import { render } from "@/test/render";
5import { user } from "@/test/user";
6
7import { Multiple } from "./Multiple";
8
9const today = new Date(2021, 10, 25);
10
11beforeAll(() => jest.setSystemTime(today));
12afterAll(() => jest.useRealTimers());
13
14beforeEach(() => {
15 render(<Multiple />);
16});
17
18describe("when a day is clicked", () => {
19 const day1 = new Date(2021, 10, 1);
20 beforeEach(async () => {
21 await user.click(dateButton(day1));
22 });
23 test("should appear as selected", () => {
24 expect(gridcell(day1, true)).toHaveAttribute("aria-selected", "true");
25 });
26 describe("when the same day is clicked again", () => {
27 beforeEach(async () => {
28 await user.click(dateButton(day1));
29 });
30 test("should appear as not selected", () => {
31 expect(gridcell(day1, true)).not.toHaveAttribute("aria-selected");
32 });
33 });
34 describe("when a second day is clicked", () => {
35 const day2 = new Date(2021, 10, 2);
36 beforeEach(async () => {
37 await user.click(dateButton(day2));
38 });
39 test("the first day should appear as selected", () => {
40 expect(gridcell(day1, true)).toHaveAttribute("aria-selected", "true");
41 });
42 test("the second day should appear as selected", () => {
43 expect(gridcell(day2, true)).toHaveAttribute("aria-selected", "true");
44 });
45 });
46});