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