File size: 2,283 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { defaultDateLib } from "../classes/DateLib";

import { rangeOverlaps } from "./rangeOverlaps";

const sunday = new Date(2024, 8, 1);
const monday = new Date(2024, 8, 2);
const tuesday = new Date(2024, 8, 3);
const thursday = new Date(2024, 8, 5);
const saturday = new Date(2024, 8, 7);
const nextWeekSunday = new Date(2024, 8, 8);

const leftRange = { from: monday, to: saturday };

test('should return true when matching the "from" date', () => {
  const rightRange = { from: sunday, to: monday };
  const result = rangeOverlaps(leftRange, rightRange, defaultDateLib);
  expect(result).toBe(true);
});

test('should return true when matching the "to" date', () => {
  const rightRange = { from: saturday, to: nextWeekSunday };
  const result = rangeOverlaps(leftRange, rightRange, defaultDateLib);
  expect(result).toBe(true);
});

test("should return true when left date range contains right date range", () => {
  const rightRange = { from: tuesday, to: thursday };
  const result = rangeOverlaps(leftRange, rightRange, defaultDateLib);
  expect(result).toBe(true);
});

test("should return true when right date range contains left date range", () => {
  const rightRange = { from: sunday, to: nextWeekSunday };
  const result = rangeOverlaps(leftRange, rightRange, defaultDateLib);
  expect(result).toBe(true);
});

test("should return true when a date range is inverted", () => {
  const rightRange = { to: sunday, from: nextWeekSunday };
  const result = rangeOverlaps(leftRange, rightRange, defaultDateLib);
  expect(result).toBe(true);
});

test('should return false on the edge of the "from" date', () => {
  const rightRange = { from: new Date(2000, 1, 1), to: sunday };
  const result = rangeOverlaps(leftRange, rightRange, defaultDateLib);
  expect(result).toBe(false);
});

test('should return false on the edge of the "to" date', () => {
  const rightRange = { from: nextWeekSunday, to: new Date(2077, 1, 1) };
  const result = rangeOverlaps(leftRange, rightRange, defaultDateLib);
  expect(result).toBe(false);
});

test("should return false when a date range is inverted", () => {
  const rightRange = { to: nextWeekSunday, from: new Date(2077, 1, 1) };
  const result = rangeOverlaps(leftRange, rightRange, defaultDateLib);
  expect(result).toBe(false);
});