UNPKG

1.24 kBTypeScriptView Raw
1import React from "react";
2
3import { differenceInMonths } from "date-fns";
4
5import { nextButton, previousButton } from "@/test/elements";
6import { render } from "@/test/render";
7import { user } from "@/test/user";
8
9import { FromToYear } from "./FromToYear";
10
11const fromMonth = new Date(2024, 0);
12const toMonth = new Date(2026, 11);
13const today = new Date(2025, 10, 25);
14
15beforeAll(() => jest.setSystemTime(today));
16afterAll(() => jest.useRealTimers());
17
18beforeEach(() => {
19 render(<FromToYear />);
20});
21
22test("the previous month button should be disabled", () => {
23 expect(previousButton()).toHaveAttribute("disabled");
24});
25test("the next month button should not be disabled", () => {
26 expect(nextButton()).not.toHaveAttribute("disabled");
27});
28
29describe("when navigating to the last month", () => {
30 const nOfMonths = differenceInMonths(toMonth, fromMonth);
31 beforeEach(async () => {
32 for (let i = 0; i < nOfMonths; i++) {
33 await user.click(nextButton());
34 }
35 });
36 test("the previous month button should not be disabled", () => {
37 expect(previousButton()).not.toHaveAttribute("disabled");
38 });
39 test("the next month button should be disabled", () => {
40 expect(nextButton()).toHaveAttribute("disabled");
41 });
42});