From 8b685ecc95ff6757540de8d9c62fb50edf56d25e Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 7 Mar 2024 22:01:50 +0100 Subject: [PATCH 1/7] Change multiday fullday event behaviour --- modules/default/calendar/calendar.js | 8 +++-- .../modules/calendar/long-fullday-event.js | 28 ++++++++++++++++ .../modules/calendar/single-fullday-event.js | 28 ++++++++++++++++ tests/e2e/modules/calendar_spec.js | 29 ++++++++++++++++ tests/mocks/calendar_test_full_day_events.ics | 33 +++++++++++++++++++ ...calendar_test_multi_day_starting_today.ics | 33 +++++++++++++++++++ 6 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 tests/configs/modules/calendar/long-fullday-event.js create mode 100644 tests/configs/modules/calendar/single-fullday-event.js create mode 100644 tests/mocks/calendar_test_full_day_events.ics create mode 100644 tests/mocks/calendar_test_multi_day_starting_today.ics diff --git a/modules/default/calendar/calendar.js b/modules/default/calendar/calendar.js index 0ce41cc050..351fabc30b 100644 --- a/modules/default/calendar/calendar.js +++ b/modules/default/calendar/calendar.js @@ -203,6 +203,10 @@ Module.register("calendar", { this.updateDom(this.config.animationSpeed); }, + eventEndingWithinNextFullTimeUnit: function (event, ONE_DAY) { + const now = new Date(); + return event.endDate - now <= ONE_DAY; + }, // Override dom generator. getDom () { @@ -438,7 +442,7 @@ Module.register("calendar", { } } else { // Show relative times - if (event.startDate >= now || (event.fullDayEvent && event.today)) { + if (event.startDate >= now || (event.fullDayEvent && this.eventEndingWithinNextFullTimeUnit(event, ONE_DAY))) { // Use relative time if (!this.config.hideTime && !event.fullDayEvent) { timeWrapper.innerHTML = CalendarUtils.capFirst(moment(event.startDate, "x").calendar(null, { sameElse: this.config.dateFormat })); @@ -454,7 +458,7 @@ Module.register("calendar", { } if (event.fullDayEvent) { // Full days events within the next two days - if (event.today) { + if (event.today || (event.fullDayEvent && this.eventEndingWithinNextFullTimeUnit(event, ONE_DAY))) { timeWrapper.innerHTML = CalendarUtils.capFirst(this.translate("TODAY")); } else if (event.dayBeforeYesterday) { if (this.translate("DAYBEFOREYESTERDAY") !== "DAYBEFOREYESTERDAY") { diff --git a/tests/configs/modules/calendar/long-fullday-event.js b/tests/configs/modules/calendar/long-fullday-event.js new file mode 100644 index 0000000000..efbc244886 --- /dev/null +++ b/tests/configs/modules/calendar/long-fullday-event.js @@ -0,0 +1,28 @@ +/* MagicMirror² Test config for fullday calendar entries over multiple days + * + * By Paranoid93 https://github.com/Paranoid93/ + * MIT Licensed. + */ +let config = { + timeFormat: 12, + + modules: [ + { + module: "calendar", + position: "bottom_bar", + config: { + calendars: [ + { + maximumNumberOfDays: 2, + url: "http://localhost:8080/tests/mocks/calendar_test_multi_day_starting_today.ics" + } + ] + } + } + ] +}; + +/*************** DO NOT EDIT THE LINE BELOW ***************/ +if (typeof module !== "undefined") { + module.exports = config; +} diff --git a/tests/configs/modules/calendar/single-fullday-event.js b/tests/configs/modules/calendar/single-fullday-event.js new file mode 100644 index 0000000000..9149d2d9ab --- /dev/null +++ b/tests/configs/modules/calendar/single-fullday-event.js @@ -0,0 +1,28 @@ +/* MagicMirror² Test config for fullday calendar entries over multiple days + * + * By Paranoid93 https://github.com/Paranoid93/ + * MIT Licensed. + */ +let config = { + timeFormat: 12, + + modules: [ + { + module: "calendar", + position: "bottom_bar", + config: { + calendars: [ + { + maximumNumberOfDays: 2, + url: "http://localhost:8080/tests/mocks/calendar_test_full_day_events.ics" + } + ] + } + } + ] +}; + +/*************** DO NOT EDIT THE LINE BELOW ***************/ +if (typeof module !== "undefined") { + module.exports = config; +} diff --git a/tests/e2e/modules/calendar_spec.js b/tests/e2e/modules/calendar_spec.js index e72917820f..0d006a6708 100644 --- a/tests/e2e/modules/calendar_spec.js +++ b/tests/e2e/modules/calendar_spec.js @@ -99,6 +99,35 @@ describe("Calendar module", () => { }); }); + //Will contain everyday an fullDayEvent that starts today and ends tomorrow, and one starting tomorrow and ending the day after tomorrow + describe("FullDayEvent over several days should show how many days are left from the from the starting date on", () => { + beforeAll(async () => { + await helpers.startApplication("tests/configs/modules/calendar/long-fullday-event.js"); + await helpers.getDocument(); + }); + + it(`should contain text "Ends in" with the left days`, async () => { + await testTextContain(".calendar .time", "Ends in a day"); + }); + it(`should contain in total two events`, async () => { + await testElementLength(".calendar .event", 2); + }); + }); + + describe("FullDayEvent Single day, should show Today", () => { + beforeAll(async () => { + await helpers.startApplication("tests/configs/modules/calendar/single-fullday-event.js"); + await helpers.getDocument(); + }); + + it(`should contain text "Today"`, async () => { + await testTextContain(".calendar .time", "Today"); + }); + it(`should contain in total two events`, async () => { + await testElementLength(".calendar .event", 2); + }); + }); + process.setMaxListeners(0); for (let i = -12; i < 12; i++) { describe("Recurring event per timezone", () => { diff --git a/tests/mocks/calendar_test_full_day_events.ics b/tests/mocks/calendar_test_full_day_events.ics new file mode 100644 index 0000000000..a3c48719c8 --- /dev/null +++ b/tests/mocks/calendar_test_full_day_events.ics @@ -0,0 +1,33 @@ +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//ical.marudot.com//iCal Event Maker +CALSCALE:GREGORIAN +BEGIN:VTIMEZONE +TZID:Europe/Berlin +LAST-MODIFIED:20231222T233358Z +TZURL:https://www.tzurl.org/zoneinfo-outlook/Europe/Berlin +X-LIC-LOCATION:Europe/Berlin +BEGIN:DAYLIGHT +TZNAME:CEST +TZOFFSETFROM:+0100 +TZOFFSETTO:+0200 +DTSTART:19700329T020000 +RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU +END:DAYLIGHT +BEGIN:STANDARD +TZNAME:CET +TZOFFSETFROM:+0200 +TZOFFSETTO:+0100 +DTSTART:19701025T030000 +RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU +END:STANDARD +END:VTIMEZONE +BEGIN:VEVENT +DTSTAMP:20240306T225415Z +UID:1709765647426-75770@ical.marudot.com +DTSTART;VALUE=DATE:20240306 +RRULE:FREQ=DAILY +DTEND;VALUE=DATE:20240307 +SUMMARY:daily full days +END:VEVENT +END:VCALENDAR diff --git a/tests/mocks/calendar_test_multi_day_starting_today.ics b/tests/mocks/calendar_test_multi_day_starting_today.ics new file mode 100644 index 0000000000..7a9151175b --- /dev/null +++ b/tests/mocks/calendar_test_multi_day_starting_today.ics @@ -0,0 +1,33 @@ +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//ical.marudot.com//iCal Event Maker +CALSCALE:GREGORIAN +BEGIN:VTIMEZONE +TZID:Europe/Berlin +LAST-MODIFIED:20231222T233358Z +TZURL:https://www.tzurl.org/zoneinfo-outlook/Europe/Berlin +X-LIC-LOCATION:Europe/Berlin +BEGIN:DAYLIGHT +TZNAME:CEST +TZOFFSETFROM:+0100 +TZOFFSETTO:+0200 +DTSTART:19700329T020000 +RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU +END:DAYLIGHT +BEGIN:STANDARD +TZNAME:CET +TZOFFSETFROM:+0200 +TZOFFSETTO:+0100 +DTSTART:19701025T030000 +RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU +END:STANDARD +END:VTIMEZONE +BEGIN:VEVENT +DTSTAMP:20240306T222634Z +UID:1709763965312-82782@ical.marudot.com +DTSTART;VALUE=DATE:20240301 +RRULE:FREQ=DAILY +DTEND;VALUE=DATE:20240303 +SUMMARY:2 day events +END:VEVENT +END:VCALENDAR From e7e26ee5d7a51e852ae6f1de654e9ca23778d129 Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 7 Mar 2024 22:03:48 +0100 Subject: [PATCH 2/7] fill CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8353ea0e3..c8fd207c9f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ _This release is scheduled to be released on 2024-04-01._ - [chore] Update dependencies including electron to v28 (#3357) and node-ical - Updated translations for estonian (#3371) - Update electron to v29 and update other dependencies +- Update calendar: fullDay events over several days now show the left days from the first day on and 'today' on the last day ### Fixed From 7253715483f3860b8782b32f5866017ddbdc0f32 Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 7 Mar 2024 22:36:03 +0100 Subject: [PATCH 3/7] fix test --- tests/e2e/modules/calendar_spec.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/e2e/modules/calendar_spec.js b/tests/e2e/modules/calendar_spec.js index 0d006a6708..d04092b934 100644 --- a/tests/e2e/modules/calendar_spec.js +++ b/tests/e2e/modules/calendar_spec.js @@ -107,10 +107,10 @@ describe("Calendar module", () => { }); it(`should contain text "Ends in" with the left days`, async () => { - await testTextContain(".calendar .time", "Ends in a day"); + await expect(testTextContain(".calendar .time", "Ends in a day")).resolves.toBe(true); }); it(`should contain in total two events`, async () => { - await testElementLength(".calendar .event", 2); + await expect(testElementLength(".calendar .event", 2)).resolves.toBe(true); }); }); @@ -121,10 +121,10 @@ describe("Calendar module", () => { }); it(`should contain text "Today"`, async () => { - await testTextContain(".calendar .time", "Today"); + await expect(testTextContain(".calendar .time", "Today")).resolves.toBe(true); }); it(`should contain in total two events`, async () => { - await testElementLength(".calendar .event", 2); + await expect(testElementLength(".calendar .event", 2)).resolves.toBe(true); }); }); From 4d32670b523fe82b237cf3aafacdeff132664d55 Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 7 Mar 2024 22:42:11 +0100 Subject: [PATCH 4/7] fix test --- tests/e2e/modules/calendar_spec.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/e2e/modules/calendar_spec.js b/tests/e2e/modules/calendar_spec.js index d04092b934..810665646b 100644 --- a/tests/e2e/modules/calendar_spec.js +++ b/tests/e2e/modules/calendar_spec.js @@ -106,10 +106,10 @@ describe("Calendar module", () => { await helpers.getDocument(); }); - it(`should contain text "Ends in" with the left days`, async () => { + it("should contain text 'Ends in' with the left days", async () => { await expect(testTextContain(".calendar .time", "Ends in a day")).resolves.toBe(true); }); - it(`should contain in total two events`, async () => { + it("should contain in total two events", async () => { await expect(testElementLength(".calendar .event", 2)).resolves.toBe(true); }); }); @@ -120,10 +120,10 @@ describe("Calendar module", () => { await helpers.getDocument(); }); - it(`should contain text "Today"`, async () => { + it("should contain text 'Today' ", async () => { await expect(testTextContain(".calendar .time", "Today")).resolves.toBe(true); }); - it(`should contain in total two events`, async () => { + it("should contain in total two events", async () => { await expect(testElementLength(".calendar .event", 2)).resolves.toBe(true); }); }); From bb624ec1b1de8953745571ab00af36d4e4fc2afd Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 7 Mar 2024 22:45:37 +0100 Subject: [PATCH 5/7] fix lint errors --- modules/default/calendar/calendar.js | 3 ++- tests/e2e/modules/calendar_spec.js | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/modules/default/calendar/calendar.js b/modules/default/calendar/calendar.js index 351fabc30b..a3f597592f 100644 --- a/modules/default/calendar/calendar.js +++ b/modules/default/calendar/calendar.js @@ -203,7 +203,8 @@ Module.register("calendar", { this.updateDom(this.config.animationSpeed); }, - eventEndingWithinNextFullTimeUnit: function (event, ONE_DAY) { + + eventEndingWithinNextFullTimeUnit (event, ONE_DAY) { const now = new Date(); return event.endDate - now <= ONE_DAY; }, diff --git a/tests/e2e/modules/calendar_spec.js b/tests/e2e/modules/calendar_spec.js index 810665646b..75e3a17ca9 100644 --- a/tests/e2e/modules/calendar_spec.js +++ b/tests/e2e/modules/calendar_spec.js @@ -120,7 +120,7 @@ describe("Calendar module", () => { await helpers.getDocument(); }); - it("should contain text 'Today' ", async () => { + it("should contain text 'Today'", async () => { await expect(testTextContain(".calendar .time", "Today")).resolves.toBe(true); }); it("should contain in total two events", async () => { From 493ce5ce1834588edd5cd27658069780182afe98 Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 7 Mar 2024 23:01:39 +0100 Subject: [PATCH 6/7] fix and extend test --- tests/e2e/modules/calendar_spec.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/e2e/modules/calendar_spec.js b/tests/e2e/modules/calendar_spec.js index 75e3a17ca9..bfec4c5a87 100644 --- a/tests/e2e/modules/calendar_spec.js +++ b/tests/e2e/modules/calendar_spec.js @@ -107,10 +107,12 @@ describe("Calendar module", () => { }); it("should contain text 'Ends in' with the left days", async () => { - await expect(testTextContain(".calendar .time", "Ends in a day")).resolves.toBe(true); + await expect(testTextContain(".calendar .today .time", "Ends in a day")).resolves.toBe(true); + await expect(testTextContain(".calendar .yesterday .time", "Today")).resolves.toBe(true); + await expect(testTextContain(".calendar .tomorrow .time", "Tomorrow")).resolves.toBe(true); }); - it("should contain in total two events", async () => { - await expect(testElementLength(".calendar .event", 2)).resolves.toBe(true); + it("should contain in total three events", async () => { + await expect(testElementLength(".calendar .event", 3)).resolves.toBe(true); }); }); From 6309f49252102d481f599741b801a9d37625b431 Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 28 Mar 2024 20:12:55 +0100 Subject: [PATCH 7/7] edit test --- tests/e2e/modules/calendar_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/modules/calendar_spec.js b/tests/e2e/modules/calendar_spec.js index bfec4c5a87..0dcd562cd1 100644 --- a/tests/e2e/modules/calendar_spec.js +++ b/tests/e2e/modules/calendar_spec.js @@ -107,7 +107,7 @@ describe("Calendar module", () => { }); it("should contain text 'Ends in' with the left days", async () => { - await expect(testTextContain(".calendar .today .time", "Ends in a day")).resolves.toBe(true); + await expect(testTextContain(".calendar .today .time", "Ends in")).resolves.toBe(true); await expect(testTextContain(".calendar .yesterday .time", "Today")).resolves.toBe(true); await expect(testTextContain(".calendar .tomorrow .time", "Tomorrow")).resolves.toBe(true); });