File size: 1,364 Bytes
cf86710
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import { addDays } from "date-fns/addDays";

import type { DateRange } from "../types";

import { rangeIncludesDate } from "./rangeIncludesDate";

const date = new Date();

describe('when range is missing the "from" date', () => {
  const range: DateRange = { from: undefined };
  const result = rangeIncludesDate(range, date);
  test("should return false", () => {
    expect(result).toBe(false);
  });
});

describe('when range is missing the "to" date', () => {
  const result = rangeIncludesDate({ from: date, to: undefined }, date);
  test("should return true", () => {
    expect(result).toBe(true);
  });
});

describe("when the range dates are the same as date", () => {
  const range: DateRange = { from: date, to: date };
  const result = rangeIncludesDate(range, date);
  test("should return true", () => {
    expect(result).toBe(true);
  });
});

describe("when the range dates are the same but not as date", () => {
  const range: DateRange = { from: date, to: date };
  const result = rangeIncludesDate(range, addDays(date, 1));
  test("should return false", () => {
    expect(result).toBe(false);
  });
});

describe("when the range is inverted", () => {
  const range: DateRange = { from: addDays(date, 1), to: date };
  const result = rangeIncludesDate(range, date);
  test("should return true", () => {
    expect(result).toBe(true);
  });
});