1 | import React from "react";
|
2 |
|
3 | import { differenceInMonths } from "date-fns";
|
4 |
|
5 | import { nextButton, previousButton } from "@/test/elements";
|
6 | import { render } from "@/test/render";
|
7 | import { user } from "@/test/user";
|
8 |
|
9 | import { FromToYear } from "./FromToYear";
|
10 |
|
11 | const fromMonth = new Date(2024, 0);
|
12 | const toMonth = new Date(2026, 11);
|
13 | const today = new Date(2025, 10, 25);
|
14 |
|
15 | beforeAll(() => jest.setSystemTime(today));
|
16 | afterAll(() => jest.useRealTimers());
|
17 |
|
18 | beforeEach(() => {
|
19 | render(<FromToYear />);
|
20 | });
|
21 |
|
22 | test("the previous month button should be disabled", () => {
|
23 | expect(previousButton()).toHaveAttribute("disabled");
|
24 | });
|
25 | test("the next month button should not be disabled", () => {
|
26 | expect(nextButton()).not.toHaveAttribute("disabled");
|
27 | });
|
28 |
|
29 | describe("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 | });
|