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 { FromToMonth } from "./FromToMonth";
|
10 |
|
11 | beforeEach(() => {
|
12 | render(<FromToMonth />);
|
13 | });
|
14 |
|
15 | test("the previous button should be disabled", () => {
|
16 | expect(previousButton()).toHaveAttribute("disabled");
|
17 | });
|
18 |
|
19 | test("the next button should be enabled", () => {
|
20 | expect(nextButton()).not.toHaveAttribute("disabled");
|
21 | });
|
22 |
|
23 | describe("when navigating to the last month", () => {
|
24 | const fromDate = new Date(2015, 5);
|
25 | const toDate = new Date(2015, 10);
|
26 | const nOfMonths = differenceInMonths(toDate, fromDate);
|
27 | beforeEach(async () => {
|
28 | for (let i = 0; i < nOfMonths; i++) {
|
29 | await user.click(nextButton());
|
30 | }
|
31 | });
|
32 |
|
33 | test("the previous button should not be disabled", () => {
|
34 | expect(previousButton()).not.toHaveAttribute("disabled");
|
35 | });
|
36 |
|
37 | test("the next button should be disabled", () => {
|
38 | expect(nextButton()).toHaveAttribute("disabled");
|
39 | });
|
40 | });
|