1 | import React from "react";
|
2 |
|
3 | import { addDays } from "date-fns";
|
4 |
|
5 | import { dateButton, app, gridcell } from "@/test/elements";
|
6 | import { renderApp } from "@/test/renderApp";
|
7 | import { user } from "@/test/user";
|
8 |
|
9 | import { ModifiersToday } from "./ModifiersToday";
|
10 |
|
11 | const today = new Date(2022, 5, 10);
|
12 |
|
13 | beforeAll(() => jest.setSystemTime(today));
|
14 | afterAll(() => jest.useRealTimers());
|
15 |
|
16 | beforeEach(() => {
|
17 | renderApp(<ModifiersToday />);
|
18 | });
|
19 |
|
20 | describe("when rendering a month that contains today", () => {
|
21 | test("it should add the default class name for today", () => {
|
22 | expect(gridcell(today, true)).toHaveClass("rdp-today");
|
23 | });
|
24 | test('it should have exactly one ".day_today" class', () => {
|
25 | const todays = app().querySelectorAll(".rdp-today");
|
26 | expect(todays).toHaveLength(1);
|
27 | });
|
28 | });
|
29 |
|
30 | describe("when the today date is clicked", () => {
|
31 | beforeEach(async () => {
|
32 | await user.click(dateButton(today));
|
33 | });
|
34 | test("should update the footer", () => {
|
35 | expect(app()).toHaveTextContent("You clicked the today’s date");
|
36 | });
|
37 | });
|
38 |
|
39 | describe("when another date is clicked", () => {
|
40 | const date = addDays(today, 1);
|
41 | beforeEach(async () => user.click(dateButton(date)));
|
42 | test("should update the footer", () => {
|
43 | expect(app()).toHaveTextContent("This is not the today’s date.");
|
44 | });
|
45 | });
|