From 3b5a0e8d66d9cc2289fc57b39805177fcb22ed4e Mon Sep 17 00:00:00 2001 From: rejas Date: Wed, 8 Jul 2020 21:53:34 +0200 Subject: [PATCH 01/10] Added config option to calendar-icons for recurring- and fullday-events --- CHANGELOG.md | 1 + modules/default/calendar/calendar.js | 22 ++++++++++++++------- modules/default/calendar/calendarfetcher.js | 1 + 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a9824c81..0f75d5e1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ _This release is scheduled to be released on 2020-10-01._ - Test coverage with Istanbul, run it with `npm run test:coverage`. - Add lithuanian language. - Added support in weatherforecast for OpenWeather onecall API. +- Added config option to calendar-icons for recurring- and fullday-events ### Updated diff --git a/modules/default/calendar/calendar.js b/modules/default/calendar/calendar.js index 5c6ce453..f59b663c 100755 --- a/modules/default/calendar/calendar.js +++ b/modules/default/calendar/calendar.js @@ -13,6 +13,8 @@ Module.register("calendar", { maximumNumberOfDays: 365, displaySymbol: true, defaultSymbol: "calendar", // Fontawesome Symbol see https://fontawesome.com/cheatsheet?from=io + fullDaySymbol: "calendar", // Fontawesome Symbol + recurringSymbol: "calendar", // Fontawesome Symbol showLocation: false, displayRepeatingCountTitle: false, defaultRepeatingCountTitle: "", @@ -217,7 +219,7 @@ Module.register("calendar", { var symbolClass = this.symbolClassForUrl(event.url); symbolWrapper.className = "symbol align-right " + symbolClass; - var symbols = this.symbolsForUrl(event.url); + var symbols = this.symbolsForEvent(event); if (typeof symbols === "string") { symbols = [symbols]; } @@ -559,15 +561,21 @@ Module.register("calendar", { }, /** - * symbolsForUrl(url) - * Retrieves the symbols for a specific url. + * symbolsForEvent(event) + * Retrieves the symbols for a specific event. * - * argument url string - Url to look for. + * argument event object - Event to look for. * * return string/array - The Symbols */ - symbolsForUrl: function (url) { - return this.getCalendarProperty(url, "symbol", this.config.defaultSymbol); + symbolsForEvent: function (event) { + if (event.recurringEvent === true) { + return this.getCalendarProperty(event.url, "recurringSymbol", this.config.recurringSymbol); + } + if (event.fullDayEvent === true) { + return this.getCalendarProperty(event.url, "fullDaySymbol", this.config.recurringSymbol); + } + return this.getCalendarProperty(event.url, "symbol", this.config.defaultSymbol); }, /** @@ -756,7 +764,7 @@ Module.register("calendar", { var calendar = this.calendarData[url]; for (var e in calendar) { var event = cloneObject(calendar[e]); - event.symbol = this.symbolsForUrl(url); + event.symbol = this.symbolsForEvent(event); event.calendarName = this.calendarNameForUrl(url); event.color = this.colorForUrl(url); delete event.url; diff --git a/modules/default/calendar/calendarfetcher.js b/modules/default/calendar/calendarfetcher.js index acae13dc..d58ba2bb 100644 --- a/modules/default/calendar/calendarfetcher.js +++ b/modules/default/calendar/calendarfetcher.js @@ -254,6 +254,7 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumNu startDate: startDate.format("x"), endDate: endDate.format("x"), fullDayEvent: isFullDayEvent(event), + recurringEvent: true, class: event.class, firstYear: event.start.getFullYear(), location: location, From 7489d19784a31d8495c6827a4f8a570a8effdda1 Mon Sep 17 00:00:00 2001 From: rejas Date: Tue, 14 Jul 2020 21:05:44 +0200 Subject: [PATCH 02/10] Merge calendar symbols --- modules/default/calendar/calendar.js | 31 +++++++++++++++++++++------- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/modules/default/calendar/calendar.js b/modules/default/calendar/calendar.js index f59b663c..087e3962 100755 --- a/modules/default/calendar/calendar.js +++ b/modules/default/calendar/calendar.js @@ -220,10 +220,6 @@ Module.register("calendar", { symbolWrapper.className = "symbol align-right " + symbolClass; var symbols = this.symbolsForEvent(event); - if (typeof symbols === "string") { - symbols = [symbols]; - } - for (var i = 0; i < symbols.length; i++) { var symbol = document.createElement("span"); symbol.className = "fa fa-fw fa-" + symbols[i]; @@ -232,6 +228,7 @@ Module.register("calendar", { } symbolWrapper.appendChild(symbol); } + eventWrapper.appendChild(symbolWrapper); } else if (this.config.timeFormat === "dateheaders") { var blankCell = document.createElement("td"); @@ -566,16 +563,28 @@ Module.register("calendar", { * * argument event object - Event to look for. * - * return string/array - The Symbols + * return array - The Symbols */ symbolsForEvent: function (event) { + let symbols = this.getCalendarPropertyAsArray(event.url, "symbol", this.config.defaultSymbol); + if (event.recurringEvent === true) { - return this.getCalendarProperty(event.url, "recurringSymbol", this.config.recurringSymbol); + symbols = this.mergeUnique(symbols, this.getCalendarPropertyAsArray(event.url, "recurringSymbol", this.config.recurringSymbol)); } + if (event.fullDayEvent === true) { - return this.getCalendarProperty(event.url, "fullDaySymbol", this.config.recurringSymbol); + symbols = this.mergeUnique(symbols, this.getCalendarPropertyAsArray(event.url, "fullDaySymbol", this.config.recurringSymbol)); } - return this.getCalendarProperty(event.url, "symbol", this.config.defaultSymbol); + + return symbols; + }, + + mergeUnique: function (arr1, arr2) { + return arr1.concat( + arr2.filter(function (item) { + return arr1.indexOf(item) === -1; + }) + ); }, /** @@ -667,6 +676,12 @@ Module.register("calendar", { return defaultValue; }, + getCalendarPropertyAsArray: function (url, property, defaultValue) { + let p = this.getCalendarProperty(url, property, defaultValue); + if (!(p instanceof Array)) p = [p]; + return p; + }, + /** * Shortens a string if it's longer than maxLength and add a ellipsis to the end * From ec2fedd797cda80c7381e25ad3c0bfe86a72f9b9 Mon Sep 17 00:00:00 2001 From: rejas Date: Wed, 15 Jul 2020 12:22:42 +0200 Subject: [PATCH 03/10] Make sure default symbol is first from right-to-left --- modules/default/calendar/calendar.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/default/calendar/calendar.js b/modules/default/calendar/calendar.js index 087e3962..f8af4a8f 100755 --- a/modules/default/calendar/calendar.js +++ b/modules/default/calendar/calendar.js @@ -569,11 +569,11 @@ Module.register("calendar", { let symbols = this.getCalendarPropertyAsArray(event.url, "symbol", this.config.defaultSymbol); if (event.recurringEvent === true) { - symbols = this.mergeUnique(symbols, this.getCalendarPropertyAsArray(event.url, "recurringSymbol", this.config.recurringSymbol)); + symbols = this.mergeUnique(this.getCalendarPropertyAsArray(event.url, "recurringSymbol", this.config.recurringSymbol), symbols); } if (event.fullDayEvent === true) { - symbols = this.mergeUnique(symbols, this.getCalendarPropertyAsArray(event.url, "fullDaySymbol", this.config.recurringSymbol)); + symbols = this.mergeUnique(this.getCalendarPropertyAsArray(event.url, "fullDaySymbol", this.config.recurringSymbol), symbols); } return symbols; From 319a13c0ef1efb11abc3cba971588726783592ff Mon Sep 17 00:00:00 2001 From: rejas Date: Mon, 22 Jun 2020 21:05:51 +0200 Subject: [PATCH 04/10] Remove orphaned ical entry --- .prettierignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.prettierignore b/.prettierignore index e4a77657..3b87fcd2 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,5 +1,4 @@ package-lock.json /config/**/* -/modules/default/calendar/vendor/ical.js/**/* /vendor/**/* !/vendor/vendor.js From 530c5d416ac5b18031dbe17d075a554d3bdfc4fe Mon Sep 17 00:00:00 2001 From: rejas Date: Sat, 18 Jul 2020 11:32:01 +0200 Subject: [PATCH 05/10] Remove now unused test data --- tests/configs/data/StripComments.json | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 tests/configs/data/StripComments.json diff --git a/tests/configs/data/StripComments.json b/tests/configs/data/StripComments.json deleted file mode 100644 index e9d1c403..00000000 --- a/tests/configs/data/StripComments.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - // Escaped - "FOO\"BAR": "Today", - - /* - * The following lines - * represent cardinal directions - */ - "N": "N", - "E": "E", - "S": "S", - "W": "W" -} From a391445e5f18b7512f131952cd2a2df0afb76f48 Mon Sep 17 00:00:00 2001 From: rejas Date: Sat, 18 Jul 2020 13:57:48 +0200 Subject: [PATCH 06/10] Add test setup for custom calendar configuration --- modules/default/calendar/calendar.js | 2 +- tests/configs/modules/calendar/custom.js | 38 ++++++++++++++++++++++++ tests/e2e/modules/calendar_spec.js | 20 +++++++++++-- 3 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 tests/configs/modules/calendar/custom.js diff --git a/modules/default/calendar/calendar.js b/modules/default/calendar/calendar.js index f8af4a8f..d0dd4022 100755 --- a/modules/default/calendar/calendar.js +++ b/modules/default/calendar/calendar.js @@ -207,7 +207,7 @@ Module.register("calendar", { eventWrapper.style.cssText = "color:" + this.colorForUrl(event.url); } - eventWrapper.className = "normal"; + eventWrapper.className = "normal event"; if (this.config.displaySymbol) { var symbolWrapper = document.createElement("td"); diff --git a/tests/configs/modules/calendar/custom.js b/tests/configs/modules/calendar/custom.js new file mode 100644 index 00000000..2060bb1c --- /dev/null +++ b/tests/configs/modules/calendar/custom.js @@ -0,0 +1,38 @@ +/* Magic Mirror Test config custom calendar + * + * MIT Licensed. + */ +let config = { + port: 8080, + ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], + + language: "en", + timeFormat: 12, + units: "metric", + electronOptions: { + webPreferences: { + nodeIntegration: true + } + }, + + modules: [ + { + module: "calendar", + position: "bottom_bar", + config: { + calendars: [ + { + maximumEntries: 3, + maximumNumberOfDays: 10000, + url: "http://localhost:8080/tests/configs/data/calendar_test.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 7af78201..19501158 100644 --- a/tests/e2e/modules/calendar_spec.js +++ b/tests/e2e/modules/calendar_spec.js @@ -1,5 +1,6 @@ const helpers = require("../global-setup"); const serverBasicAuth = require("../../servers/basic-auth.js"); +const expect = require("chai").expect; const describe = global.describe; const it = global.it; @@ -31,8 +32,23 @@ describe("Calendar module", function () { process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/default.js"; }); - it("Should return TestEvents", function () { - return app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); + it("Should show the default maximumEntries of 10", async () => { + await app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); + const events = await app.client.$$(".calendar .event"); + return expect(events.length).equals(10); + }); + }); + + describe("Custom configuration", function () { + before(function () { + // Set config sample for use in test + process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/custom.js"; + }); + + it("Should show the custom maximumEntries of 3", async () => { + await app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); + const events = await app.client.$$(".calendar .event"); + return expect(events.length).equals(3); }); }); From 73aa35ea2c1310a8953c3c380bf6153db8899b30 Mon Sep 17 00:00:00 2001 From: rejas Date: Sat, 18 Jul 2020 17:51:21 +0200 Subject: [PATCH 07/10] Pass maximumEntries for each calender to fetcher Fixes failing test --- modules/default/calendar/calendarfetcher.js | 4 ++-- modules/default/calendar/node_helper.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/default/calendar/calendarfetcher.js b/modules/default/calendar/calendarfetcher.js index d58ba2bb..888830ba 100644 --- a/modules/default/calendar/calendarfetcher.js +++ b/modules/default/calendar/calendarfetcher.js @@ -9,7 +9,7 @@ const ical = require("ical"); const moment = require("moment"); const request = require("request"); -const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumNumberOfDays, auth, includePastEvents) { +const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, includePastEvents) { const self = this; let reloadTimer = null; @@ -318,7 +318,7 @@ const CalendarFetcher = function (url, reloadInterval, excludedEvents, maximumNu return a.startDate - b.startDate; }); - events = newEvents; + events = newEvents.slice(0, maximumEntries); self.broadcastEvents(); scheduleTimer(); diff --git a/modules/default/calendar/node_helper.js b/modules/default/calendar/node_helper.js index 5248919b..e731ca6c 100644 --- a/modules/default/calendar/node_helper.js +++ b/modules/default/calendar/node_helper.js @@ -20,7 +20,7 @@ module.exports = NodeHelper.create({ // Override socketNotificationReceived method. socketNotificationReceived: function (notification, payload) { if (notification === "ADD_CALENDAR") { - this.createFetcher(payload.url, payload.fetchInterval, payload.excludedEvents, payload.maximumNumberOfDays, payload.auth, payload.broadcastPastEvents, payload.id); + this.createFetcher(payload.url, payload.fetchInterval, payload.excludedEvents, payload.maximumEntries, payload.maximumNumberOfDays, payload.auth, payload.broadcastPastEvents, payload.id); } }, @@ -31,7 +31,7 @@ module.exports = NodeHelper.create({ * attribute url string - URL of the news feed. * attribute reloadInterval number - Reload interval in milliseconds. */ - createFetcher: function (url, fetchInterval, excludedEvents, maximumNumberOfDays, auth, broadcastPastEvents, identifier) { + createFetcher: function (url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents, identifier) { var self = this; if (!validUrl.isUri(url)) { @@ -42,7 +42,7 @@ module.exports = NodeHelper.create({ var fetcher; if (typeof self.fetchers[identifier + url] === "undefined") { Log.log("Create new calendar fetcher for url: " + url + " - Interval: " + fetchInterval); - fetcher = new CalendarFetcher(url, fetchInterval, excludedEvents, maximumNumberOfDays, auth, broadcastPastEvents); + fetcher = new CalendarFetcher(url, fetchInterval, excludedEvents, maximumEntries, maximumNumberOfDays, auth, broadcastPastEvents); fetcher.onReceive(function (fetcher) { self.sendSocketNotification("CALENDAR_EVENTS", { From 8b1d1671f73d330c6d7656a8e1849407b16dffa6 Mon Sep 17 00:00:00 2001 From: rejas Date: Sat, 18 Jul 2020 21:10:36 +0200 Subject: [PATCH 08/10] Add test for changing the calendar symbol --- modules/default/calendar/calendar.js | 14 ++++++++------ tests/configs/modules/calendar/custom.js | 1 + tests/e2e/modules/calendar_spec.js | 12 ++++++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/modules/default/calendar/calendar.js b/modules/default/calendar/calendar.js index d0dd4022..06026363 100755 --- a/modules/default/calendar/calendar.js +++ b/modules/default/calendar/calendar.js @@ -13,8 +13,6 @@ Module.register("calendar", { maximumNumberOfDays: 365, displaySymbol: true, defaultSymbol: "calendar", // Fontawesome Symbol see https://fontawesome.com/cheatsheet?from=io - fullDaySymbol: "calendar", // Fontawesome Symbol - recurringSymbol: "calendar", // Fontawesome Symbol showLocation: false, displayRepeatingCountTitle: false, defaultRepeatingCountTitle: "", @@ -568,12 +566,12 @@ Module.register("calendar", { symbolsForEvent: function (event) { let symbols = this.getCalendarPropertyAsArray(event.url, "symbol", this.config.defaultSymbol); - if (event.recurringEvent === true) { - symbols = this.mergeUnique(this.getCalendarPropertyAsArray(event.url, "recurringSymbol", this.config.recurringSymbol), symbols); + if (event.recurringEvent === true && this.hasCalendarProperty(event.url, "recurringSymbol")) { + symbols = this.mergeUnique(this.getCalendarPropertyAsArray(event.url, "recurringSymbol", this.config.defaultSymbol), symbols); } - if (event.fullDayEvent === true) { - symbols = this.mergeUnique(this.getCalendarPropertyAsArray(event.url, "fullDaySymbol", this.config.recurringSymbol), symbols); + if (event.fullDayEvent === true && this.hasCalendarProperty(event.url, "fullDaySymbol")) { + symbols = this.mergeUnique(this.getCalendarPropertyAsArray(event.url, "fullDaySymbol", this.config.defaultSymbol), symbols); } return symbols; @@ -682,6 +680,10 @@ Module.register("calendar", { return p; }, + hasCalendarProperty: function (url, property) { + return !!this.getCalendarProperty(url, property, undefined); + }, + /** * Shortens a string if it's longer than maxLength and add a ellipsis to the end * diff --git a/tests/configs/modules/calendar/custom.js b/tests/configs/modules/calendar/custom.js index 2060bb1c..48a735b7 100644 --- a/tests/configs/modules/calendar/custom.js +++ b/tests/configs/modules/calendar/custom.js @@ -22,6 +22,7 @@ let config = { config: { calendars: [ { + symbol: "birthday-cake", maximumEntries: 3, maximumNumberOfDays: 10000, url: "http://localhost:8080/tests/configs/data/calendar_test.ics" diff --git a/tests/e2e/modules/calendar_spec.js b/tests/e2e/modules/calendar_spec.js index 19501158..b17212f4 100644 --- a/tests/e2e/modules/calendar_spec.js +++ b/tests/e2e/modules/calendar_spec.js @@ -37,6 +37,12 @@ describe("Calendar module", function () { const events = await app.client.$$(".calendar .event"); return expect(events.length).equals(10); }); + + it("Should show the default calendar symbol in each event", async () => { + await app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); + const icons = await app.client.$$(".calendar .event .fa-calendar"); + return expect(icons.length).not.equals(0); + }); }); describe("Custom configuration", function () { @@ -50,6 +56,12 @@ describe("Calendar module", function () { const events = await app.client.$$(".calendar .event"); return expect(events.length).equals(3); }); + + it("Should show the custom calendar symbol in each event", async () => { + await app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); + const icons = await app.client.$$(".calendar .event .fa-birthday-cake"); + return expect(icons.length).not.equals(0); + }); }); describe("Basic auth", function () { From 8fa858ca8c002c844255cfe465879365546d994b Mon Sep 17 00:00:00 2001 From: rejas Date: Sat, 18 Jul 2020 22:16:44 +0200 Subject: [PATCH 09/10] Cleanup test descriptions --- tests/e2e/modules/calendar_spec.js | 16 ++++++++-------- tests/unit/functions/calendar_spec.js | 18 +++++++++--------- 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/tests/e2e/modules/calendar_spec.js b/tests/e2e/modules/calendar_spec.js index b17212f4..806e4e4a 100644 --- a/tests/e2e/modules/calendar_spec.js +++ b/tests/e2e/modules/calendar_spec.js @@ -32,13 +32,13 @@ describe("Calendar module", function () { process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/default.js"; }); - it("Should show the default maximumEntries of 10", async () => { + it("should show the default maximumEntries of 10", async () => { await app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); const events = await app.client.$$(".calendar .event"); return expect(events.length).equals(10); }); - it("Should show the default calendar symbol in each event", async () => { + it("should show the default calendar symbol in each event", async () => { await app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); const icons = await app.client.$$(".calendar .event .fa-calendar"); return expect(icons.length).not.equals(0); @@ -51,13 +51,13 @@ describe("Calendar module", function () { process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/custom.js"; }); - it("Should show the custom maximumEntries of 3", async () => { + it("should show the custom maximumEntries of 3", async () => { await app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); const events = await app.client.$$(".calendar .event"); return expect(events.length).equals(3); }); - it("Should show the custom calendar symbol in each event", async () => { + it("should show the custom calendar symbol in each event", async () => { await app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); const icons = await app.client.$$(".calendar .event .fa-birthday-cake"); return expect(icons.length).not.equals(0); @@ -75,7 +75,7 @@ describe("Calendar module", function () { serverBasicAuth.close(done()); }); - it("Should return TestEvents", function () { + it("should return TestEvents", function () { return app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); }); }); @@ -91,7 +91,7 @@ describe("Calendar module", function () { serverBasicAuth.close(done()); }); - it("Should return TestEvents", function () { + it("should return TestEvents", function () { return app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); }); }); @@ -107,7 +107,7 @@ describe("Calendar module", function () { serverBasicAuth.close(done()); }); - it("Should return TestEvents", function () { + it("should return TestEvents", function () { return app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); }); }); @@ -123,7 +123,7 @@ describe("Calendar module", function () { serverBasicAuth.close(done()); }); - it("Should return No upcoming events", function () { + it("should return No upcoming events", function () { return app.client.waitUntilTextExists(".calendar", "No upcoming events.", 10000); }); }); diff --git a/tests/unit/functions/calendar_spec.js b/tests/unit/functions/calendar_spec.js index e1d44e4a..44091816 100644 --- a/tests/unit/functions/calendar_spec.js +++ b/tests/unit/functions/calendar_spec.js @@ -32,54 +32,54 @@ describe("Functions into modules/default/calendar/calendar.js", function () { }); describe("getLocaleSpecification", function () { - it("Should return a valid moment.LocaleSpecification for a 12-hour format", function () { + it("should return a valid moment.LocaleSpecification for a 12-hour format", function () { expect(Module.definitions.calendar.getLocaleSpecification(12)).to.deep.equal({ longDateFormat: { LT: "h:mm A" } }); }); - it("Should return a valid moment.LocaleSpecification for a 24-hour format", function () { + it("should return a valid moment.LocaleSpecification for a 24-hour format", function () { expect(Module.definitions.calendar.getLocaleSpecification(24)).to.deep.equal({ longDateFormat: { LT: "HH:mm" } }); }); - it("Should return the current system locale when called without timeFormat number", function () { + it("should return the current system locale when called without timeFormat number", function () { expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: { LT: moment.localeData().longDateFormat("LT") } }); }); - it("Should return a 12-hour longDateFormat when using the 'en' locale", function () { + it("should return a 12-hour longDateFormat when using the 'en' locale", function () { var localeBackup = moment.locale(); moment.locale("en"); expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: { LT: "h:mm A" } }); moment.locale(localeBackup); }); - it("Should return a 12-hour longDateFormat when using the 'au' locale", function () { + it("should return a 12-hour longDateFormat when using the 'au' locale", function () { var localeBackup = moment.locale(); moment.locale("au"); expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: { LT: "h:mm A" } }); moment.locale(localeBackup); }); - it("Should return a 12-hour longDateFormat when using the 'eg' locale", function () { + it("should return a 12-hour longDateFormat when using the 'eg' locale", function () { var localeBackup = moment.locale(); moment.locale("eg"); expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: { LT: "h:mm A" } }); moment.locale(localeBackup); }); - it("Should return a 24-hour longDateFormat when using the 'nl' locale", function () { + it("should return a 24-hour longDateFormat when using the 'nl' locale", function () { var localeBackup = moment.locale(); moment.locale("nl"); expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: { LT: "HH:mm" } }); moment.locale(localeBackup); }); - it("Should return a 24-hour longDateFormat when using the 'fr' locale", function () { + it("should return a 24-hour longDateFormat when using the 'fr' locale", function () { var localeBackup = moment.locale(); moment.locale("fr"); expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: { LT: "HH:mm" } }); moment.locale(localeBackup); }); - it("Should return a 24-hour longDateFormat when using the 'uk' locale", function () { + it("should return a 24-hour longDateFormat when using the 'uk' locale", function () { var localeBackup = moment.locale(); moment.locale("uk"); expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: { LT: "HH:mm" } }); From 50f3f32ba8cab1c547438b32a13b367f6cb0b218 Mon Sep 17 00:00:00 2001 From: rejas Date: Sun, 19 Jul 2020 11:54:03 +0200 Subject: [PATCH 10/10] Add tests for custom icons --- tests/configs/data/calendar_test_icons.ics | 56 ++++++++++++++++++++++ tests/configs/modules/calendar/custom.js | 6 ++- tests/e2e/modules/calendar_spec.js | 18 +++++-- 3 files changed, 75 insertions(+), 5 deletions(-) create mode 100644 tests/configs/data/calendar_test_icons.ics diff --git a/tests/configs/data/calendar_test_icons.ics b/tests/configs/data/calendar_test_icons.ics new file mode 100644 index 00000000..7f24060d --- /dev/null +++ b/tests/configs/data/calendar_test_icons.ics @@ -0,0 +1,56 @@ +BEGIN:VCALENDAR +VERSION:2.0 +PRODID:-//ical.marudot.com//iCal Event Maker +X-WR-CALNAME:TestEvents +NAME:TestEvents +CALSCALE:GREGORIAN +BEGIN:VTIMEZONE +TZID:Europe/Berlin +TZURL:http://tzurl.org/zoneinfo-outlook/Europe/Berlin +X-LIC-LOCATION:Europe/Berlin +BEGIN:DAYLIGHT +TZOFFSETFROM:+0100 +TZOFFSETTO:+0200 +TZNAME:CEST +DTSTART:19700329T020000 +RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU +END:DAYLIGHT +BEGIN:STANDARD +TZOFFSETFROM:+0200 +TZOFFSETTO:+0100 +TZNAME:CET +DTSTART:19701025T030000 +RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU +END:STANDARD +END:VTIMEZONE +BEGIN:VEVENT +DTSTAMP:20200719T094531Z +UID:20200719T094531Z-1871115387@marudot.com +DTSTART;TZID=Europe/Berlin:20300101T120000 +DTEND;TZID=Europe/Berlin:20300101T130000 +SUMMARY:TestEvent +END:VEVENT +BEGIN:VEVENT +DTSTAMP:20200719T094531Z +UID:20200719T094531Z-1929725136@marudot.com +DTSTART;TZID=Europe/Berlin:20300701T120000 +RRULE:FREQ=YEARLY;BYMONTH=7;BYMONTHDAY=1 +DTEND;TZID=Europe/Berlin:20300701T130000 +SUMMARY:TestEventRepeat +END:VEVENT +BEGIN:VEVENT +DTSTAMP:20200719T094531Z +UID:20200719T094531Z-371801474@marudot.com +DTSTART;VALUE=DATE:20300401 +DTEND;VALUE=DATE:20300402 +SUMMARY:TestEventDay +END:VEVENT +BEGIN:VEVENT +DTSTAMP:20200719T094531Z +UID:20200719T094531Z-133401084@marudot.com +DTSTART;VALUE=DATE:20301001 +RRULE:FREQ=YEARLY;BYMONTH=10;BYMONTHDAY=1 +DTEND;VALUE=DATE:20301002 +SUMMARY:TestEventRepeatDay +END:VEVENT +END:VCALENDAR \ No newline at end of file diff --git a/tests/configs/modules/calendar/custom.js b/tests/configs/modules/calendar/custom.js index 48a735b7..2084419d 100644 --- a/tests/configs/modules/calendar/custom.js +++ b/tests/configs/modules/calendar/custom.js @@ -23,9 +23,11 @@ let config = { calendars: [ { symbol: "birthday-cake", - maximumEntries: 3, + fullDaySymbol: "calendar-day", + recurringSymbol: "undo", + maximumEntries: 4, maximumNumberOfDays: 10000, - url: "http://localhost:8080/tests/configs/data/calendar_test.ics" + url: "http://localhost:8080/tests/configs/data/calendar_test_icons.ics" } ] } diff --git a/tests/e2e/modules/calendar_spec.js b/tests/e2e/modules/calendar_spec.js index 806e4e4a..3712871c 100644 --- a/tests/e2e/modules/calendar_spec.js +++ b/tests/e2e/modules/calendar_spec.js @@ -51,16 +51,28 @@ describe("Calendar module", function () { process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/custom.js"; }); - it("should show the custom maximumEntries of 3", async () => { + it("should show the custom maximumEntries of 4", async () => { await app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); const events = await app.client.$$(".calendar .event"); - return expect(events.length).equals(3); + return expect(events.length).equals(4); }); it("should show the custom calendar symbol in each event", async () => { await app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); const icons = await app.client.$$(".calendar .event .fa-birthday-cake"); - return expect(icons.length).not.equals(0); + return expect(icons.length).equals(4); + }); + + it("should show two custom icons for repeating events", async () => { + await app.client.waitUntilTextExists(".calendar", "TestEventRepeat", 10000); + const icons = await app.client.$$(".calendar .event .fa-undo"); + return expect(icons.length).equals(2); + }); + + it("should show two custom icons for day events", async () => { + await app.client.waitUntilTextExists(".calendar", "TestEventDay", 10000); + const icons = await app.client.$$(".calendar .event .fa-calendar-day"); + return expect(icons.length).equals(2); }); });