UNPKG

1.43 kBPlain TextView Raw
1import { type Locale, format } from "date-fns";
2import { enUS as locale } from "date-fns/locale";
3import { dateLib } from "react-day-picker";
4
5import { getFormatters } from "./getFormatters";
6import { getMonthOptions } from "./getMonthOptions";
7
8test("return correct dropdown options", () => {
9 const displayMonth = new Date(2022, 0, 1); // January 2022
10 const startMonth = new Date(2022, 0, 1); // January 2022
11 const endMonth = new Date(2022, 11, 31); // December 2022
12 const formatters = getFormatters({
13 formatMonthDropdown: (month: number, locale?: Locale) =>
14 format(new Date(2022, month), "MMMM", { locale })
15 });
16 const result = getMonthOptions(
17 displayMonth,
18 startMonth,
19 endMonth,
20 formatters,
21 locale,
22 dateLib
23 );
24
25 expect(result).toEqual([
26 { value: 0, label: "January", disabled: false },
27 { value: 1, label: "February", disabled: false },
28 { value: 2, label: "March", disabled: false },
29 { value: 3, label: "April", disabled: false },
30 { value: 4, label: "May", disabled: false },
31 { value: 5, label: "June", disabled: false },
32 { value: 6, label: "July", disabled: false },
33 { value: 7, label: "August", disabled: false },
34 { value: 8, label: "September", disabled: false },
35 { value: 9, label: "October", disabled: false },
36 { value: 10, label: "November", disabled: false },
37 { value: 11, label: "December", disabled: false }
38 ]);
39});