2020-03-20 22:31:27 +01:00
|
|
|
import React from 'react';
|
|
|
|
import PlanningEventManager from "../PlanningEventManager";
|
|
|
|
|
2020-03-20 22:50:28 +01:00
|
|
|
test('isDescriptionEmpty', () => {
|
|
|
|
expect(PlanningEventManager.isDescriptionEmpty("")).toBeTrue();
|
2020-03-21 11:24:30 +01:00
|
|
|
expect(PlanningEventManager.isDescriptionEmpty(" ")).toBeTrue();
|
2020-03-21 18:46:12 +01:00
|
|
|
// noinspection CheckTagEmptyBody
|
2020-03-20 22:50:28 +01:00
|
|
|
expect(PlanningEventManager.isDescriptionEmpty("<p></p>")).toBeTrue();
|
2020-03-21 11:24:30 +01:00
|
|
|
expect(PlanningEventManager.isDescriptionEmpty("<p> </p>")).toBeTrue();
|
2020-03-20 22:50:28 +01:00
|
|
|
expect(PlanningEventManager.isDescriptionEmpty("<p><br></p>")).toBeTrue();
|
2020-03-21 11:24:30 +01:00
|
|
|
expect(PlanningEventManager.isDescriptionEmpty("<p><br></p><p><br></p>")).toBeTrue();
|
|
|
|
expect(PlanningEventManager.isDescriptionEmpty("<p><br><br><br></p>")).toBeTrue();
|
2020-03-20 22:50:28 +01:00
|
|
|
expect(PlanningEventManager.isDescriptionEmpty("<p><br>")).toBeTrue();
|
|
|
|
expect(PlanningEventManager.isDescriptionEmpty(null)).toBeTrue();
|
|
|
|
expect(PlanningEventManager.isDescriptionEmpty(undefined)).toBeTrue();
|
|
|
|
expect(PlanningEventManager.isDescriptionEmpty("coucou")).toBeFalse();
|
|
|
|
expect(PlanningEventManager.isDescriptionEmpty("<p>coucou</p>")).toBeFalse();
|
2020-03-20 22:31:27 +01:00
|
|
|
});
|
|
|
|
|
2020-03-21 18:59:42 +01:00
|
|
|
test('isEventDateStringFormatValid', () => {
|
2020-03-22 11:58:24 +01:00
|
|
|
expect(PlanningEventManager.isEventDateStringFormatValid("2020-03-21 09:00")).toBeTrue();
|
|
|
|
expect(PlanningEventManager.isEventDateStringFormatValid("3214-64-12 01:16")).toBeTrue();
|
2020-03-21 17:23:59 +01:00
|
|
|
|
2020-03-22 11:58:24 +01:00
|
|
|
expect(PlanningEventManager.isEventDateStringFormatValid("3214-64-12 01:16:00")).toBeFalse();
|
|
|
|
expect(PlanningEventManager.isEventDateStringFormatValid("3214-64-12 1:16")).toBeFalse();
|
|
|
|
expect(PlanningEventManager.isEventDateStringFormatValid("3214-f4-12 01:16")).toBeFalse();
|
|
|
|
expect(PlanningEventManager.isEventDateStringFormatValid("sqdd 09:00")).toBeFalse();
|
2020-03-21 18:59:42 +01:00
|
|
|
expect(PlanningEventManager.isEventDateStringFormatValid("2020-03-21")).toBeFalse();
|
|
|
|
expect(PlanningEventManager.isEventDateStringFormatValid("2020-03-21 truc")).toBeFalse();
|
|
|
|
expect(PlanningEventManager.isEventDateStringFormatValid("3214-64-12 1:16:65")).toBeFalse();
|
|
|
|
expect(PlanningEventManager.isEventDateStringFormatValid("garbage")).toBeFalse();
|
|
|
|
expect(PlanningEventManager.isEventDateStringFormatValid("")).toBeFalse();
|
|
|
|
expect(PlanningEventManager.isEventDateStringFormatValid(undefined)).toBeFalse();
|
|
|
|
expect(PlanningEventManager.isEventDateStringFormatValid(null)).toBeFalse();
|
2020-03-21 17:23:59 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('stringToDate', () => {
|
|
|
|
let testDate = new Date();
|
2020-03-22 11:21:55 +01:00
|
|
|
expect(PlanningEventManager.stringToDate(undefined)).toBeNull();
|
|
|
|
expect(PlanningEventManager.stringToDate("")).toBeNull();
|
|
|
|
expect(PlanningEventManager.stringToDate("garbage")).toBeNull();
|
|
|
|
expect(PlanningEventManager.stringToDate("2020-03-21")).toBeNull();
|
|
|
|
expect(PlanningEventManager.stringToDate("09:00:00")).toBeNull();
|
2020-03-22 11:58:24 +01:00
|
|
|
expect(PlanningEventManager.stringToDate("2020-03-21 09:g0")).toBeNull();
|
2020-03-22 11:21:55 +01:00
|
|
|
expect(PlanningEventManager.stringToDate("2020-03-21 09:g0:")).toBeNull();
|
2020-03-21 17:23:59 +01:00
|
|
|
testDate.setFullYear(2020, 2, 21);
|
|
|
|
testDate.setHours(9, 0, 0, 0);
|
2020-03-22 11:58:24 +01:00
|
|
|
expect(PlanningEventManager.stringToDate("2020-03-21 09:00")).toEqual(testDate);
|
2020-03-21 17:23:59 +01:00
|
|
|
testDate.setFullYear(2020, 0, 31);
|
2020-03-22 11:58:24 +01:00
|
|
|
testDate.setHours(18, 30, 0, 0);
|
|
|
|
expect(PlanningEventManager.stringToDate("2020-01-31 18:30")).toEqual(testDate);
|
2020-03-21 17:23:59 +01:00
|
|
|
testDate.setFullYear(2020, 50, 50);
|
2020-03-22 11:58:24 +01:00
|
|
|
testDate.setHours(65, 65, 0, 0);
|
|
|
|
expect(PlanningEventManager.stringToDate("2020-51-50 65:65")).toEqual(testDate);
|
2020-03-21 17:23:59 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('getFormattedEventTime', () => {
|
|
|
|
expect(PlanningEventManager.getFormattedEventTime(null, null))
|
|
|
|
.toBe('/ - /');
|
|
|
|
expect(PlanningEventManager.getFormattedEventTime(undefined, undefined))
|
|
|
|
.toBe('/ - /');
|
2020-03-22 11:58:24 +01:00
|
|
|
expect(PlanningEventManager.getFormattedEventTime("20:30", "23:00"))
|
2020-03-21 17:23:59 +01:00
|
|
|
.toBe('/ - /');
|
|
|
|
expect(PlanningEventManager.getFormattedEventTime("2020-03-30", "2020-03-31"))
|
|
|
|
.toBe('/ - /');
|
|
|
|
|
|
|
|
|
2020-03-22 11:58:24 +01:00
|
|
|
expect(PlanningEventManager.getFormattedEventTime("2020-03-21 09:00", "2020-03-21 09:00"))
|
2020-03-21 17:23:59 +01:00
|
|
|
.toBe('09:00');
|
2020-03-22 11:58:24 +01:00
|
|
|
expect(PlanningEventManager.getFormattedEventTime("2020-03-21 09:00", "2020-03-22 17:00"))
|
2020-03-21 20:32:28 +01:00
|
|
|
.toBe('09:00 - 23:59');
|
2020-03-22 11:58:24 +01:00
|
|
|
expect(PlanningEventManager.getFormattedEventTime("2020-03-30 20:30", "2020-03-30 23:00"))
|
2020-03-21 17:23:59 +01:00
|
|
|
.toBe('20:30 - 23:00');
|
|
|
|
});
|
2020-03-20 22:50:28 +01:00
|
|
|
|
2020-03-21 18:46:12 +01:00
|
|
|
test('getDateOnlyString', () => {
|
2020-03-22 11:58:24 +01:00
|
|
|
expect(PlanningEventManager.getDateOnlyString("2020-03-21 09:00")).toBe("2020-03-21");
|
|
|
|
expect(PlanningEventManager.getDateOnlyString("2021-12-15 09:00")).toBe("2021-12-15");
|
|
|
|
expect(PlanningEventManager.getDateOnlyString("2021-12-o5 09:00")).toBeNull();
|
2020-03-22 11:21:55 +01:00
|
|
|
expect(PlanningEventManager.getDateOnlyString("2021-12-15 09:")).toBeNull();
|
|
|
|
expect(PlanningEventManager.getDateOnlyString("2021-12-15")).toBeNull();
|
|
|
|
expect(PlanningEventManager.getDateOnlyString("garbage")).toBeNull();
|
2020-03-21 18:46:12 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
test('isEventBefore', () => {
|
|
|
|
expect(PlanningEventManager.isEventBefore(
|
2020-03-22 11:58:24 +01:00
|
|
|
"2020-03-21 09:00", "2020-03-21 10:00")).toBeTrue();
|
2020-03-21 18:46:12 +01:00
|
|
|
expect(PlanningEventManager.isEventBefore(
|
2020-03-22 11:58:24 +01:00
|
|
|
"2020-03-21 10:00", "2020-03-21 10:15")).toBeTrue();
|
2020-03-21 18:46:12 +01:00
|
|
|
expect(PlanningEventManager.isEventBefore(
|
2020-03-22 11:58:24 +01:00
|
|
|
"2020-03-21 10:15", "2021-03-21 10:15")).toBeTrue();
|
2020-03-21 18:46:12 +01:00
|
|
|
expect(PlanningEventManager.isEventBefore(
|
2020-03-22 11:58:24 +01:00
|
|
|
"2020-03-21 10:15", "2020-05-21 10:15")).toBeTrue();
|
2020-03-21 18:46:12 +01:00
|
|
|
expect(PlanningEventManager.isEventBefore(
|
2020-03-22 11:58:24 +01:00
|
|
|
"2020-03-21 10:15", "2020-03-30 10:15")).toBeTrue();
|
2020-03-21 18:46:12 +01:00
|
|
|
|
2020-03-22 16:05:28 +01:00
|
|
|
expect(PlanningEventManager.isEventBefore(
|
|
|
|
"2020-03-21 10:00", "2020-03-21 10:00")).toBeFalse();
|
2020-03-21 18:46:12 +01:00
|
|
|
expect(PlanningEventManager.isEventBefore(
|
2020-03-22 11:58:24 +01:00
|
|
|
"2020-03-21 10:00", "2020-03-21 09:00")).toBeFalse();
|
2020-03-21 18:46:12 +01:00
|
|
|
expect(PlanningEventManager.isEventBefore(
|
2020-03-22 11:58:24 +01:00
|
|
|
"2020-03-21 10:15", "2020-03-21 10:00")).toBeFalse();
|
2020-03-21 18:46:12 +01:00
|
|
|
expect(PlanningEventManager.isEventBefore(
|
2020-03-22 11:58:24 +01:00
|
|
|
"2021-03-21 10:15", "2020-03-21 10:15")).toBeFalse();
|
2020-03-21 18:46:12 +01:00
|
|
|
expect(PlanningEventManager.isEventBefore(
|
2020-03-22 11:58:24 +01:00
|
|
|
"2020-05-21 10:15", "2020-03-21 10:15")).toBeFalse();
|
2020-03-21 18:46:12 +01:00
|
|
|
expect(PlanningEventManager.isEventBefore(
|
2020-03-22 11:58:24 +01:00
|
|
|
"2020-03-30 10:15", "2020-03-21 10:15")).toBeFalse();
|
2020-03-21 18:46:12 +01:00
|
|
|
|
|
|
|
expect(PlanningEventManager.isEventBefore(
|
2020-03-22 11:58:24 +01:00
|
|
|
"garbage", "2020-03-21 10:15")).toBeFalse();
|
2020-03-21 18:46:12 +01:00
|
|
|
expect(PlanningEventManager.isEventBefore(
|
|
|
|
undefined, undefined)).toBeFalse();
|
|
|
|
});
|
|
|
|
|
2020-03-21 18:59:42 +01:00
|
|
|
test('dateToString', () => {
|
|
|
|
let testDate = new Date();
|
|
|
|
testDate.setFullYear(2020, 2, 21);
|
2020-03-21 20:32:28 +01:00
|
|
|
testDate.setHours(9, 0, 0, 0);
|
2020-03-22 11:58:24 +01:00
|
|
|
expect(PlanningEventManager.dateToString(testDate)).toBe("2020-03-21 09:00");
|
2020-03-21 18:59:42 +01:00
|
|
|
testDate.setFullYear(2021, 0, 12);
|
2020-03-21 20:32:28 +01:00
|
|
|
testDate.setHours(9, 10, 0, 0);
|
2020-03-22 11:58:24 +01:00
|
|
|
expect(PlanningEventManager.dateToString(testDate)).toBe("2021-01-12 09:10");
|
2020-03-21 18:59:42 +01:00
|
|
|
testDate.setFullYear(2022, 11, 31);
|
2020-03-21 20:32:28 +01:00
|
|
|
testDate.setHours(9, 10, 15, 0);
|
2020-03-22 11:58:24 +01:00
|
|
|
expect(PlanningEventManager.dateToString(testDate)).toBe("2022-12-31 09:10");
|
|
|
|
});
|
|
|
|
|
|
|
|
test('generateEmptyCalendar', () => {
|
2020-03-22 16:05:28 +01:00
|
|
|
jest.spyOn(Date, 'now')
|
|
|
|
.mockImplementation(() =>
|
|
|
|
new Date('2020-01-14T00:00:00.000Z').getTime()
|
|
|
|
);
|
|
|
|
let calendar = PlanningEventManager.generateEmptyCalendar(1);
|
|
|
|
expect(calendar).toHaveProperty("2020-01-14");
|
|
|
|
expect(calendar).toHaveProperty("2020-01-20");
|
|
|
|
expect(calendar).toHaveProperty("2020-02-10");
|
|
|
|
expect(Object.keys(calendar).length).toBe(32);
|
|
|
|
calendar = PlanningEventManager.generateEmptyCalendar(3);
|
|
|
|
expect(calendar).toHaveProperty("2020-01-14");
|
|
|
|
expect(calendar).toHaveProperty("2020-01-20");
|
|
|
|
expect(calendar).toHaveProperty("2020-02-10");
|
|
|
|
expect(calendar).toHaveProperty("2020-02-14");
|
|
|
|
expect(calendar).toHaveProperty("2020-03-20");
|
|
|
|
expect(calendar).toHaveProperty("2020-04-12");
|
|
|
|
expect(Object.keys(calendar).length).toBe(92);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('pushEventInOrder', () => {
|
|
|
|
let eventArray = [];
|
|
|
|
let event1 = {date_begin: "2020-01-14 09:15"};
|
|
|
|
PlanningEventManager.pushEventInOrder(eventArray, event1);
|
|
|
|
expect(eventArray.length).toBe(1);
|
|
|
|
expect(eventArray[0]).toBe(event1);
|
|
|
|
|
|
|
|
let event2 = {date_begin: "2020-01-14 10:15"};
|
|
|
|
PlanningEventManager.pushEventInOrder(eventArray, event2);
|
|
|
|
expect(eventArray.length).toBe(2);
|
|
|
|
expect(eventArray[0]).toBe(event1);
|
|
|
|
expect(eventArray[1]).toBe(event2);
|
2020-03-22 11:58:24 +01:00
|
|
|
|
2020-03-22 16:05:28 +01:00
|
|
|
let event3 = {date_begin: "2020-01-14 10:15", title: "garbage"};
|
|
|
|
PlanningEventManager.pushEventInOrder(eventArray, event3);
|
|
|
|
expect(eventArray.length).toBe(3);
|
|
|
|
expect(eventArray[0]).toBe(event1);
|
|
|
|
expect(eventArray[1]).toBe(event2);
|
|
|
|
expect(eventArray[2]).toBe(event3);
|
|
|
|
|
|
|
|
let event4 = {date_begin: "2020-01-13 09:00"};
|
|
|
|
PlanningEventManager.pushEventInOrder(eventArray, event4);
|
|
|
|
expect(eventArray.length).toBe(4);
|
|
|
|
expect(eventArray[0]).toBe(event4);
|
|
|
|
expect(eventArray[1]).toBe(event1);
|
|
|
|
expect(eventArray[2]).toBe(event2);
|
|
|
|
expect(eventArray[3]).toBe(event3);
|
|
|
|
});
|
|
|
|
|
|
|
|
test('generateEventAgenda', () => {
|
|
|
|
jest.spyOn(Date, 'now')
|
|
|
|
.mockImplementation(() =>
|
|
|
|
new Date('2020-01-14T00:00:00.000Z').getTime()
|
|
|
|
);
|
|
|
|
let eventList = [
|
|
|
|
{date_begin: "2020-01-14 09:15"},
|
|
|
|
{date_begin: "2020-02-01 09:15"},
|
|
|
|
{date_begin: "2020-01-15 09:15"},
|
|
|
|
{date_begin: "2020-02-01 09:30"},
|
|
|
|
{date_begin: "2020-02-01 08:30"},
|
|
|
|
];
|
|
|
|
const calendar = PlanningEventManager.generateEventAgenda(eventList, 2);
|
|
|
|
expect(calendar["2020-01-14"].length).toBe(1);
|
|
|
|
expect(calendar["2020-01-14"][0]).toBe(eventList[0]);
|
|
|
|
expect(calendar["2020-01-15"].length).toBe(1);
|
|
|
|
expect(calendar["2020-01-15"][0]).toBe(eventList[2]);
|
|
|
|
expect(calendar["2020-02-01"].length).toBe(3);
|
|
|
|
expect(calendar["2020-02-01"][0]).toBe(eventList[4]);
|
|
|
|
expect(calendar["2020-02-01"][1]).toBe(eventList[1]);
|
|
|
|
expect(calendar["2020-02-01"][2]).toBe(eventList[3]);
|
2020-03-21 18:59:42 +01:00
|
|
|
});
|
|
|
|
|
2020-03-22 16:05:28 +01:00
|
|
|
test('getCurrentDateString', () => {
|
|
|
|
jest.spyOn(Date, 'now')
|
|
|
|
.mockImplementation(() => {
|
|
|
|
let date = new Date();
|
|
|
|
date.setFullYear(2020, 0, 14);
|
|
|
|
date.setHours(15, 30, 54, 65);
|
|
|
|
return date.getTime();
|
|
|
|
});
|
|
|
|
expect(PlanningEventManager.getCurrentDateString()).toBe('2020-01-14 15:30');
|
|
|
|
});
|