UNPKG

1.4 kBTypeScriptView Raw
1import React from "react";
2
3import { dateButton, gridcell } from "@/test/elements";
4import { render, screen } from "@/test/render";
5import { user } from "@/test/user";
6
7import { CustomMultiple } from "./CustomMultiple";
8
9const today = new Date(2021, 10, 25);
10
11beforeAll(() => jest.setSystemTime(today));
12afterAll(() => jest.useRealTimers());
13
14beforeEach(() => {
15 render(<CustomMultiple />);
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 test("should update the footer", () => {
27 expect(screen.getByText("You selected 1 days.")).toBeInTheDocument();
28 });
29 describe("when a second day is clicked", () => {
30 const day2 = new Date(2021, 10, 2);
31 beforeEach(async () => {
32 await user.click(dateButton(day2));
33 });
34 test("the first day should appear as selected", () => {
35 expect(gridcell(day1, true)).toHaveAttribute("aria-selected", "true");
36 });
37 test("the second day should appear as selected", () => {
38 expect(gridcell(day2, true)).toHaveAttribute("aria-selected", "true");
39 });
40 test("should update the footer", () => {
41 expect(screen.getByText("You selected 2 days.")).toBeInTheDocument();
42 });
43 });
44});