UNPKG

1.09 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 { FromToMonth } from "./FromToMonth";
10
11beforeEach(() => {
12 render(<FromToMonth />);
13});
14
15test("the previous button should be disabled", () => {
16 expect(previousButton()).toHaveAttribute("disabled");
17});
18
19test("the next button should be enabled", () => {
20 expect(nextButton()).not.toHaveAttribute("disabled");
21});
22
23describe("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});