UNPKG

2.16 kBTypeScriptView Raw
1import { CalendarDay } from "../classes";
2import { dateLib } from "../lib";
3import type { DayPickerProps, MoveFocusBy, MoveFocusDir } from "../types";
4
5import { getNextFocus } from "./getNextFocus";
6
7const props: Pick<
8 DayPickerProps,
9 "disabled" | "hidden" | "startMonth" | "endMonth" | "dateLib"
10> = {
11 disabled: [],
12 hidden: [],
13 dateLib
14};
15
16it("should return `undefined` if `attempt` exceeds 365", () => {
17 const focusedDay = new CalendarDay(
18 new Date(2020, 0, 1),
19 new Date(2020, 0, 1),
20 dateLib
21 );
22 const moveBy: MoveFocusBy = "day";
23 const moveDir: MoveFocusDir = "after";
24 const result = getNextFocus(
25 moveBy,
26 moveDir,
27 focusedDay,
28 undefined,
29 undefined,
30 props,
31 dateLib,
32 366
33 );
34 expect(result).toBeUndefined();
35});
36
37it("should return the focus date if it is not disabled or hidden", () => {
38 const focusedDay = new CalendarDay(
39 new Date(2020, 0, 1),
40 new Date(2020, 0, 1),
41 dateLib
42 );
43 const expectedDate = new Date(2020, 0, 2);
44 const result = getNextFocus(
45 "day",
46 "after",
47 focusedDay,
48 undefined,
49 undefined,
50 props,
51 dateLib
52 );
53 expect(result?.date).toEqual(expectedDate);
54});
55
56it("should return the next focus date if it is disabled", () => {
57 const focusedDay = new CalendarDay(
58 new Date(2020, 0, 1),
59 new Date(2020, 0, 1),
60 dateLib
61 );
62 const disabledDate = new Date(2020, 0, 2);
63 const expectedDate = new Date(2020, 0, 3);
64 const result = getNextFocus(
65 "day",
66 "after",
67 focusedDay,
68 undefined,
69 undefined,
70 {
71 ...props,
72 disabled: [disabledDate]
73 },
74 dateLib
75 );
76 expect(result?.date).toEqual(expectedDate);
77});
78
79it("should return the next focus date if it is hidden", () => {
80 const focusedDay = new CalendarDay(
81 new Date(2020, 0, 1),
82 new Date(2020, 0, 1),
83 dateLib
84 );
85 const hiddenDate = new Date(2020, 0, 2);
86 const expectedDate = new Date(2020, 0, 3);
87 const result = getNextFocus(
88 "day",
89 "after",
90 focusedDay,
91 undefined,
92 undefined,
93 {
94 ...props,
95 hidden: [hiddenDate]
96 },
97 dateLib
98 );
99 expect(result?.date).toEqual(expectedDate);
100});