1 | import { addDays } from "date-fns/addDays";
|
2 |
|
3 | import { DateRange } from "../types";
|
4 |
|
5 | import { rangeIncludesDate } from "./rangeIncludesDate";
|
6 |
|
7 | const date = new Date();
|
8 |
|
9 | describe('when range is missing the "from" date', () => {
|
10 | const range: DateRange = { from: undefined };
|
11 | const result = rangeIncludesDate(range, date);
|
12 | test("should return false", () => {
|
13 | expect(result).toBe(false);
|
14 | });
|
15 | });
|
16 |
|
17 | describe('when range is missing the "to" date', () => {
|
18 | const result = rangeIncludesDate({ from: date, to: undefined }, date);
|
19 | test("should return true", () => {
|
20 | expect(result).toBe(true);
|
21 | });
|
22 | });
|
23 |
|
24 | describe("when the range dates are the same as date", () => {
|
25 | const range: DateRange = { from: date, to: date };
|
26 | const result = rangeIncludesDate(range, date);
|
27 | test("should return true", () => {
|
28 | expect(result).toBe(true);
|
29 | });
|
30 | });
|
31 |
|
32 | describe("when the range dates are the same but not as date", () => {
|
33 | const range: DateRange = { from: date, to: date };
|
34 | const result = rangeIncludesDate(range, addDays(date, 1));
|
35 | test("should return false", () => {
|
36 | expect(result).toBe(false);
|
37 | });
|
38 | });
|
39 |
|
40 | describe("when the range is inverted", () => {
|
41 | const range: DateRange = { from: addDays(date, 1), to: date };
|
42 | const result = rangeIncludesDate(range, date);
|
43 | test("should return true", () => {
|
44 | expect(result).toBe(true);
|
45 | });
|
46 | });
|