UNPKG

1.34 kBPlain TextView Raw
1import { dateLib } from "react-day-picker";
2
3import { getFormatters } from "./getFormatters";
4import { getYearOptions } from "./getYearOptions";
5
6test("return undefined if startMonth or endMonth is not provided", () => {
7 const displayMonth = new Date(2022, 0, 1); // January 2022
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
30test("return correct dropdown options", () => {
31 const displayMonth = new Date(2022, 0, 1); // January 2022
32 const startMonth = new Date(2022, 0, 1); // January 2022
33 const endMonth = new Date(2024, 11, 31); // December 2024
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});