UNPKG

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