1 | import React from "react";
|
2 |
|
3 | import { grid, monthDropdown, yearDropdown } from "@/test/elements";
|
4 | import { render, within } from "@/test/render";
|
5 | import { user } from "@/test/user";
|
6 |
|
7 | import { Dropdown } from "./Dropdown";
|
8 |
|
9 | const today = new Date(2015, 6, 1);
|
10 |
|
11 | beforeAll(() => jest.setSystemTime(today));
|
12 | afterAll(() => jest.useRealTimers());
|
13 |
|
14 | beforeEach(() => {
|
15 | render(<Dropdown />);
|
16 | });
|
17 |
|
18 | test("should display the month dropdown", () => {
|
19 | expect(monthDropdown()).toBeInTheDocument();
|
20 | });
|
21 |
|
22 | test("should display the year dropdown", () => {
|
23 | expect(yearDropdown()).toBeInTheDocument();
|
24 | });
|
25 |
|
26 | test("should disable the months out of range", () => {
|
27 | expect(
|
28 | within(monthDropdown()).getByRole("option", { name: "January" })
|
29 | ).toBeDisabled();
|
30 | });
|
31 |
|
32 | describe("when choosing a month", () => {
|
33 | const monthName = "December";
|
34 | beforeEach(async () => {
|
35 | await user.selectOptions(monthDropdown(), monthName);
|
36 | });
|
37 | test("should display the month", () => {
|
38 | expect(grid()).toHaveAccessibleName(`${monthName} 2015`);
|
39 | });
|
40 | test("should disable the years out of range", () => {
|
41 | expect(
|
42 | within(yearDropdown()).getByRole("option", { name: "2025" })
|
43 | ).toBeDisabled();
|
44 | });
|
45 | });
|
46 |
|
47 | describe("when choosing a year", () => {
|
48 | const year = "2021";
|
49 | beforeEach(async () => {
|
50 | await user.selectOptions(yearDropdown(), year);
|
51 | });
|
52 | test("should display the year", () => {
|
53 | expect(grid()).toHaveAccessibleName(`July ${year}`);
|
54 | });
|
55 | });
|
56 |
|
57 | describe("when choosing a disabled month", () => {
|
58 | const monthName = "February";
|
59 | beforeEach(async () => {
|
60 | await user.selectOptions(monthDropdown(), monthName);
|
61 | });
|
62 | test("should display the first available month", () => {
|
63 | expect(grid()).toHaveAccessibleName(`July 2015`);
|
64 | });
|
65 | });
|