UNPKG

1.86 kBPlain TextView Raw
1import { addMonths, isSameMonth } from "date-fns";
2import { dateLib } from "react-day-picker";
3
4import { getInitialMonth } from "./getInitialMonth";
5
6describe("when no endMonth is given", () => {
7 describe("when month is in context", () => {
8 const month = new Date(2010, 11, 12);
9 it("return that month", () => {
10 const startMonth = getInitialMonth({ month }, dateLib);
11 expect(isSameMonth(startMonth, month)).toBe(true);
12 });
13 });
14 describe("when defaultMonth is in context", () => {
15 const defaultMonth = new Date(2010, 11, 12);
16 it("return that month", () => {
17 const startMonth = getInitialMonth({ defaultMonth }, dateLib);
18 expect(isSameMonth(startMonth, defaultMonth)).toBe(true);
19 });
20 });
21 describe("when no month or defaultMonth", () => {
22 const today = new Date(2010, 11, 12);
23 it("return the today month", () => {
24 const startMonth = getInitialMonth({ today }, dateLib);
25 expect(isSameMonth(startMonth, today)).toBe(true);
26 });
27 });
28});
29describe("when endMonth is given", () => {
30 describe("when endMonth is before the default initial date", () => {
31 const month = new Date(2010, 11, 12);
32 const endMonth = addMonths(month, -2);
33 describe("when the number of month is 1", () => {
34 it("return the endMonth", () => {
35 const startMonth = getInitialMonth({ month, endMonth }, dateLib);
36 expect(isSameMonth(startMonth, endMonth)).toBe(true);
37 });
38 });
39 describe("when the number of month is 3", () => {
40 it("return the endMonth plus the number of months", () => {
41 const startMonth = getInitialMonth(
42 { month, numberOfMonths: 3, endMonth },
43 dateLib
44 );
45 const expectedMonth = addMonths(endMonth, -1 * (3 - 1));
46 expect(isSameMonth(startMonth, expectedMonth)).toBe(true);
47 });
48 });
49 });
50});