1 | import { dateLib } from "react-day-picker";
|
2 |
|
3 | import { getFormatters } from "./getFormatters";
|
4 | import { getYearOptions } from "./getYearOptions";
|
5 |
|
6 | test("return undefined if startMonth or endMonth is not provided", () => {
|
7 | const displayMonth = new Date(2022, 0, 1);
|
8 | const formatters = getFormatters({
|
9 | formatYearDropdown: (year: number) => `${year}`
|
10 | });
|
11 | const result1 = getYearOptions(
|
12 | displayMonth,
|
13 | undefined,
|
14 | new Date(2022, 11, 31),
|
15 | formatters,
|
16 | dateLib
|
17 | );
|
18 | const result2 = getYearOptions(
|
19 | displayMonth,
|
20 | new Date(2022, 0, 1),
|
21 | undefined,
|
22 | formatters,
|
23 | dateLib
|
24 | );
|
25 |
|
26 | expect(result1).toBeUndefined();
|
27 | expect(result2).toBeUndefined();
|
28 | });
|
29 |
|
30 | test("return correct dropdown options", () => {
|
31 | const displayMonth = new Date(2022, 0, 1);
|
32 | const startMonth = new Date(2022, 0, 1);
|
33 | const endMonth = new Date(2024, 11, 31);
|
34 | const formatters = getFormatters({
|
35 | formatYearDropdown: (year: number) => `${year}`
|
36 | });
|
37 |
|
38 | const result = getYearOptions(
|
39 | displayMonth,
|
40 | startMonth,
|
41 | endMonth,
|
42 | formatters,
|
43 | dateLib
|
44 | );
|
45 |
|
46 | expect(result).toEqual([
|
47 | { value: 2022, label: "2022", disabled: false },
|
48 | { value: 2023, label: "2023", disabled: false },
|
49 | { value: 2024, label: "2024", disabled: false }
|
50 | ]);
|
51 | });
|