UNPKG

1.31 kBTypeScriptView Raw
1import React from "react";
2
3import { addDays } from "date-fns";
4
5import { dateButton, app, gridcell } from "@/test/elements";
6import { renderApp } from "@/test/renderApp";
7import { user } from "@/test/user";
8
9import { ModifiersToday } from "./ModifiersToday";
10
11const today = new Date(2022, 5, 10);
12
13beforeAll(() => jest.setSystemTime(today));
14afterAll(() => jest.useRealTimers());
15
16beforeEach(() => {
17 renderApp(<ModifiersToday />);
18});
19
20describe("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
30describe("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
39describe("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});