1 | import React from "react";
|
2 |
|
3 | import { dateButton, gridcell } from "@/test/elements";
|
4 | import { render } from "@/test/render";
|
5 | import { user } from "@/test/user";
|
6 |
|
7 | import { CustomWeek } from "./CustomWeek";
|
8 |
|
9 | const today = new Date(2021, 10, 25);
|
10 |
|
11 | beforeAll(() => jest.setSystemTime(today));
|
12 | afterAll(() => jest.useRealTimers());
|
13 |
|
14 | beforeEach(() => {
|
15 | render(<CustomWeek />);
|
16 | });
|
17 |
|
18 | describe("when a day is clicked", () => {
|
19 | beforeEach(async () => {
|
20 | await user.click(dateButton(today));
|
21 | });
|
22 | test("the whole week should appear selected", () => {
|
23 | const week = [
|
24 | gridcell(new Date(2021, 10, 21), true),
|
25 | gridcell(new Date(2021, 10, 22), true),
|
26 | gridcell(new Date(2021, 10, 23), true),
|
27 | gridcell(new Date(2021, 10, 24), true),
|
28 | gridcell(new Date(2021, 10, 25), true),
|
29 | gridcell(new Date(2021, 10, 26), true),
|
30 | gridcell(new Date(2021, 10, 27), true)
|
31 | ];
|
32 | week.forEach((day) => {
|
33 | expect(day).toHaveAttribute("aria-selected", "true");
|
34 | });
|
35 | });
|
36 | describe("when clicking the day again", () => {
|
37 | beforeEach(async () => {
|
38 | await user.click(dateButton(today));
|
39 | });
|
40 | test("the whole week should not be selected", () => {
|
41 | const week = [
|
42 | dateButton(new Date(2021, 10, 21)),
|
43 | dateButton(new Date(2021, 10, 22)),
|
44 | dateButton(new Date(2021, 10, 23)),
|
45 | dateButton(new Date(2021, 10, 24)),
|
46 | dateButton(new Date(2021, 10, 25)),
|
47 | dateButton(new Date(2021, 10, 26)),
|
48 | dateButton(new Date(2021, 10, 27))
|
49 | ];
|
50 | week.forEach((day) => {
|
51 | expect(day).not.toHaveAttribute("aria-selected", "true");
|
52 | });
|
53 | });
|
54 | });
|
55 | });
|