mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-09-13 23:55:11 +00:00
Release 2.26.0 (#3319)
## [2.26.0] - 01-01-2024 Thanks to: @bnitkin, @bugsounet, @dependabot, @jkriegshauser, @kaennchenstruggle, @KristjanESPERANTO and @Ybbet. Special thanks to @khassel, @rejas and @sdetweil for taking over most (if not all) of the work on this release as project collaborators. This version would not be there without their effort. Thank you guys! You are awesome! This release also marks the latest release by Michael Teeuw. For more info, please read the following post: [A New Chapter for MagicMirror: The Community Takes the Lead](https://forum.magicmirror.builders/topic/18329/a-new-chapter-for-magicmirror-the-community-takes-the-lead). ### Added - Added update notification updater (for 3rd party modules) - Added node 21 to the test matrix - Added transform object to calendar:customEvents - Added ESLint rules for jest (including jest/expect-expect and jest/no-done-callback) ### Removed - Removed Codecov workflow (not working anymore, other workflow required) (#3107) - Removed titleReplace from calendar, replaced + extended by customEvents (backward compatibility included) (#3249) - Removed failing unit test (#3254) - Removed some unused variables ### Updated - Update electron to v27 and update other dependencies as well as github actions - Update newsfeed: Use `html-to-text` instead of regex for transform description - Review ESLint config (#3269) - Updated dependencies - Clock module: optionally display current moon phase in addition to rise/set times - electron is now per default started without gpu, if needed it must be enabled with new env var `ELECTRON_ENABLE_GPU=1` on startup (#3226) - Replace prettier by stylistic in ESLint config to lint JavaScript (and disable some rules for `config/config.js*` files) - Update node-ical to v0.17.1 and fix tests ### Fixed - Avoid fade out/in on updateDom when many calendars are used - Fix the option eventClass on customEvents. - Fix yr API version in locationforecast and sunrise call (#3227) - Fix cloneObject() function to respect RegExp (#3237) - Fix newsfeed module for feeds using "a10:updated" tag (#3238) - Fix issue template (#3167) - Fix #3256 filter out bad results from rrule.between - Fix calendar events sometimes not respecting deleted events (#3250) - Fix electron loadurl locally on Windows when address "0.0.0.0" (#2550) - Fix updatanotification (update_helper.js): catch error if reponse is not an JSON format (check PM2) - Fix missing typeof in calendar module - Fix style issues after prettier update - Fix calendar test (#3291) by moving "Exdate check" from e2e to electron to run on a Thursday - Fix calendar config params `fetchInterval` and `excludedEvents` were never used from single calendar config (#3297) - Fix MM_PORT variable not used in electron and allow full path for MM_CONFIG_FILE variable (#3302) --------- Signed-off-by: naveen <172697+naveensrinivasan@users.noreply.github.com> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: Karsten Hassel <hassel@gmx.de> Co-authored-by: Malte Hallström <46646495+SkySails@users.noreply.github.com> Co-authored-by: Veeck <github@veeck.de> Co-authored-by: veeck <michael@veeck.de> Co-authored-by: dWoolridge <dwoolridge@charter.net> Co-authored-by: Johan <jojjepersson@yahoo.se> Co-authored-by: Dario Mratovich <dario_mratovich@hotmail.com> Co-authored-by: Dario Mratovich <dario.mratovich@outlook.com> Co-authored-by: Magnus <34011212+MagMar94@users.noreply.github.com> Co-authored-by: Naveen <172697+naveensrinivasan@users.noreply.github.com> Co-authored-by: buxxi <buxxi@omfilm.net> Co-authored-by: Thomas Hirschberger <47733292+Tom-Hirschberger@users.noreply.github.com> Co-authored-by: Kristjan ESPERANTO <35647502+KristjanESPERANTO@users.noreply.github.com> Co-authored-by: Andrés Vanegas Jiménez <142350+angeldeejay@users.noreply.github.com> Co-authored-by: Dave Child <dave@addedbytes.com> Co-authored-by: grenagit <46225780+grenagit@users.noreply.github.com> Co-authored-by: Grena <grena@grenabox.fr> Co-authored-by: Magnus Marthinsen <magmar@online.no> Co-authored-by: Patrick <psieg@users.noreply.github.com> Co-authored-by: Piotr Rajnisz <56397164+rajniszp@users.noreply.github.com> Co-authored-by: Suthep Yonphimai <tomzt@users.noreply.github.com> Co-authored-by: CarJem Generations (Carter Wallace) <cwallacecs@gmail.com> Co-authored-by: Nicholas Fogal <nfogal.misc@gmail.com> Co-authored-by: JakeBinney <126349119+JakeBinney@users.noreply.github.com> Co-authored-by: OWL4C <124401812+OWL4C@users.noreply.github.com> Co-authored-by: Oscar Björkman <17575446+oscarb@users.noreply.github.com> Co-authored-by: Ismar Slomic <ismar@slomic.no> Co-authored-by: Jørgen Veum-Wahlberg <jorgen.wahlberg@amedia.no> Co-authored-by: Eddie Hung <6740044+eddiehung@users.noreply.github.com> Co-authored-by: Bugsounet - Cédric <github@bugsounet.fr> Co-authored-by: bugsounet <bugsounet@bugsounet.fr> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Knapoc <Knapoc@users.noreply.github.com> Co-authored-by: sam detweiler <sdetweil@gmail.com> Co-authored-by: veeck <michael.veeck@nebenan.de> Co-authored-by: Paranoid93 <6515818+Paranoid93@users.noreply.github.com> Co-authored-by: NolanKingdon <27908974+NolanKingdon@users.noreply.github.com> Co-authored-by: J. Kenzal Hunter <kenzal.hunter@gmail.com> Co-authored-by: Teddy <teddy.payet@gmail.com> Co-authored-by: TeddyStarinvest <teddy.payet@starinvest.com> Co-authored-by: martingron <61826403+martingron@users.noreply.github.com> Co-authored-by: dgoth <132394363+dgoth@users.noreply.github.com> Co-authored-by: kaennchenstruggle <54073894+kaennchenstruggle@users.noreply.github.com> Co-authored-by: jkriegshauser <jkriegshauser@gmail.com> Co-authored-by: Ben Nitkin <ben@nitkin.net>
This commit is contained in:
@@ -6,17 +6,19 @@ describe("File js/class", () => {
|
||||
let clone;
|
||||
let dom;
|
||||
|
||||
beforeAll((done) => {
|
||||
dom = new JSDOM(
|
||||
`<script>var Log = {log: () => {}};</script>\
|
||||
beforeAll(() => {
|
||||
return new Promise((done) => {
|
||||
dom = new JSDOM(
|
||||
`<script>var Log = {log: () => {}};</script>\
|
||||
<script src="file://${path.join(__dirname, "..", "..", "..", "js", "class.js")}">`,
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
);
|
||||
dom.window.onload = () => {
|
||||
const { cloneObject } = dom.window;
|
||||
clone = cloneObject;
|
||||
done();
|
||||
};
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
);
|
||||
dom.window.onload = () => {
|
||||
const { cloneObject } = dom.window;
|
||||
clone = cloneObject;
|
||||
done();
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
it("should clone object", () => {
|
||||
@@ -49,6 +51,13 @@ describe("File js/class", () => {
|
||||
expect(obj).toBe(expected);
|
||||
});
|
||||
|
||||
it("should clone regex", () => {
|
||||
const expected = /.*Magic/;
|
||||
const obj = clone(expected);
|
||||
expect(obj).toEqual(expected);
|
||||
expect(expected === obj).toBe(false);
|
||||
});
|
||||
|
||||
it("should clone undefined", () => {
|
||||
const expected = undefined;
|
||||
const obj = clone(expected);
|
||||
|
@@ -77,209 +77,235 @@ describe("Translator", () => {
|
||||
Translator.coreTranslationsFallback = coreTranslationsFallback;
|
||||
};
|
||||
|
||||
it("should return custom module translation", (done) => {
|
||||
const dom = new JSDOM(`<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
|
||||
dom.window.onload = () => {
|
||||
const { Translator } = dom.window;
|
||||
setTranslations(Translator);
|
||||
let translation = Translator.translate({ name: "MMM-Module" }, "Hello");
|
||||
expect(translation).toBe("Hallo");
|
||||
translation = Translator.translate({ name: "MMM-Module" }, "Hello {username}", { username: "fewieden" });
|
||||
expect(translation).toBe("Hallo fewieden");
|
||||
done();
|
||||
};
|
||||
it("should return custom module translation", () => {
|
||||
return new Promise((done) => {
|
||||
const dom = new JSDOM(`<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
|
||||
dom.window.onload = () => {
|
||||
const { Translator } = dom.window;
|
||||
setTranslations(Translator);
|
||||
let translation = Translator.translate({ name: "MMM-Module" }, "Hello");
|
||||
expect(translation).toBe("Hallo");
|
||||
translation = Translator.translate({ name: "MMM-Module" }, "Hello {username}", { username: "fewieden" });
|
||||
expect(translation).toBe("Hallo fewieden");
|
||||
done();
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
it("should return core translation", (done) => {
|
||||
const dom = new JSDOM(`<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
|
||||
dom.window.onload = () => {
|
||||
const { Translator } = dom.window;
|
||||
setTranslations(Translator);
|
||||
let translation = Translator.translate({ name: "MMM-Module" }, "FOO");
|
||||
expect(translation).toBe("Foo");
|
||||
translation = Translator.translate({ name: "MMM-Module" }, "BAR {something}", { something: "Lorem Ipsum" });
|
||||
expect(translation).toBe("Bar Lorem Ipsum");
|
||||
done();
|
||||
};
|
||||
it("should return core translation", () => {
|
||||
return new Promise((done) => {
|
||||
const dom = new JSDOM(`<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
|
||||
dom.window.onload = () => {
|
||||
const { Translator } = dom.window;
|
||||
setTranslations(Translator);
|
||||
let translation = Translator.translate({ name: "MMM-Module" }, "FOO");
|
||||
expect(translation).toBe("Foo");
|
||||
translation = Translator.translate({ name: "MMM-Module" }, "BAR {something}", { something: "Lorem Ipsum" });
|
||||
expect(translation).toBe("Bar Lorem Ipsum");
|
||||
done();
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
it("should return custom module translation fallback", (done) => {
|
||||
const dom = new JSDOM(`<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
|
||||
dom.window.onload = () => {
|
||||
const { Translator } = dom.window;
|
||||
setTranslations(Translator);
|
||||
const translation = Translator.translate({ name: "MMM-Module" }, "A key");
|
||||
expect(translation).toBe("A translation");
|
||||
done();
|
||||
};
|
||||
it("should return custom module translation fallback", () => {
|
||||
return new Promise((done) => {
|
||||
const dom = new JSDOM(`<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
|
||||
dom.window.onload = () => {
|
||||
const { Translator } = dom.window;
|
||||
setTranslations(Translator);
|
||||
const translation = Translator.translate({ name: "MMM-Module" }, "A key");
|
||||
expect(translation).toBe("A translation");
|
||||
done();
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
it("should return core translation fallback", (done) => {
|
||||
const dom = new JSDOM(`<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
|
||||
dom.window.onload = () => {
|
||||
const { Translator } = dom.window;
|
||||
setTranslations(Translator);
|
||||
const translation = Translator.translate({ name: "MMM-Module" }, "Fallback");
|
||||
expect(translation).toBe("core fallback");
|
||||
done();
|
||||
};
|
||||
it("should return core translation fallback", () => {
|
||||
return new Promise((done) => {
|
||||
const dom = new JSDOM(`<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
|
||||
dom.window.onload = () => {
|
||||
const { Translator } = dom.window;
|
||||
setTranslations(Translator);
|
||||
const translation = Translator.translate({ name: "MMM-Module" }, "Fallback");
|
||||
expect(translation).toBe("core fallback");
|
||||
done();
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
it("should return translation with placeholder for missing variables", (done) => {
|
||||
const dom = new JSDOM(`<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
|
||||
dom.window.onload = () => {
|
||||
const { Translator } = dom.window;
|
||||
setTranslations(Translator);
|
||||
const translation = Translator.translate({ name: "MMM-Module" }, "Hello {username}");
|
||||
expect(translation).toBe("Hallo {username}");
|
||||
done();
|
||||
};
|
||||
it("should return translation with placeholder for missing variables", () => {
|
||||
return new Promise((done) => {
|
||||
const dom = new JSDOM(`<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
|
||||
dom.window.onload = () => {
|
||||
const { Translator } = dom.window;
|
||||
setTranslations(Translator);
|
||||
const translation = Translator.translate({ name: "MMM-Module" }, "Hello {username}");
|
||||
expect(translation).toBe("Hallo {username}");
|
||||
done();
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
it("should return key if no translation was found", (done) => {
|
||||
const dom = new JSDOM(`<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
|
||||
dom.window.onload = () => {
|
||||
const { Translator } = dom.window;
|
||||
setTranslations(Translator);
|
||||
const translation = Translator.translate({ name: "MMM-Module" }, "MISSING");
|
||||
expect(translation).toBe("MISSING");
|
||||
done();
|
||||
};
|
||||
it("should return key if no translation was found", () => {
|
||||
return new Promise((done) => {
|
||||
const dom = new JSDOM(`<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
|
||||
dom.window.onload = () => {
|
||||
const { Translator } = dom.window;
|
||||
setTranslations(Translator);
|
||||
const translation = Translator.translate({ name: "MMM-Module" }, "MISSING");
|
||||
expect(translation).toBe("MISSING");
|
||||
done();
|
||||
};
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("load", () => {
|
||||
const mmm = {
|
||||
name: "TranslationTest",
|
||||
file(file) {
|
||||
file (file) {
|
||||
return `http://localhost:3000/translations/${file}`;
|
||||
}
|
||||
};
|
||||
|
||||
it("should load translations", (done) => {
|
||||
const dom = new JSDOM(`<script>var Log = {log: () => {}};</script><script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
|
||||
dom.window.onload = async () => {
|
||||
const { Translator } = dom.window;
|
||||
const file = "translation_test.json";
|
||||
it("should load translations", () => {
|
||||
return new Promise((done) => {
|
||||
const dom = new JSDOM(`<script>var Log = {log: () => {}};</script><script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
|
||||
dom.window.onload = async () => {
|
||||
const { Translator } = dom.window;
|
||||
const file = "translation_test.json";
|
||||
|
||||
await Translator.load(mmm, file, false);
|
||||
const json = require(path.join(__dirname, "..", "..", "..", "tests", "mocks", file));
|
||||
expect(Translator.translations[mmm.name]).toEqual(json);
|
||||
done();
|
||||
};
|
||||
await Translator.load(mmm, file, false);
|
||||
const json = require(path.join(__dirname, "..", "..", "..", "tests", "mocks", file));
|
||||
expect(Translator.translations[mmm.name]).toEqual(json);
|
||||
done();
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
it("should load translation fallbacks", (done) => {
|
||||
const dom = new JSDOM(`<script>var Log = {log: () => {}};</script><script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
|
||||
dom.window.onload = async () => {
|
||||
const { Translator } = dom.window;
|
||||
const file = "translation_test.json";
|
||||
it("should load translation fallbacks", () => {
|
||||
return new Promise((done) => {
|
||||
const dom = new JSDOM(`<script>var Log = {log: () => {}};</script><script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
|
||||
dom.window.onload = async () => {
|
||||
const { Translator } = dom.window;
|
||||
const file = "translation_test.json";
|
||||
|
||||
await Translator.load(mmm, file, true);
|
||||
const json = require(path.join(__dirname, "..", "..", "..", "tests", "mocks", file));
|
||||
expect(Translator.translationsFallback[mmm.name]).toEqual(json);
|
||||
done();
|
||||
};
|
||||
await Translator.load(mmm, file, true);
|
||||
const json = require(path.join(__dirname, "..", "..", "..", "tests", "mocks", file));
|
||||
expect(Translator.translationsFallback[mmm.name]).toEqual(json);
|
||||
done();
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
it("should not load translations, if module fallback exists", (done) => {
|
||||
const dom = new JSDOM(`<script>var Log = {log: () => {}};</script><script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
|
||||
dom.window.onload = async () => {
|
||||
const { Translator, XMLHttpRequest } = dom.window;
|
||||
const file = "translation_test.json";
|
||||
it("should not load translations, if module fallback exists", () => {
|
||||
return new Promise((done) => {
|
||||
const dom = new JSDOM(`<script>var Log = {log: () => {}};</script><script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
|
||||
dom.window.onload = async () => {
|
||||
const { Translator, XMLHttpRequest } = dom.window;
|
||||
const file = "translation_test.json";
|
||||
|
||||
XMLHttpRequest.prototype.send = () => {
|
||||
throw new Error("Shouldn't load files");
|
||||
XMLHttpRequest.prototype.send = () => {
|
||||
throw new Error("Shouldn't load files");
|
||||
};
|
||||
|
||||
Translator.translationsFallback[mmm.name] = {
|
||||
Hello: "Hallo"
|
||||
};
|
||||
|
||||
await Translator.load(mmm, file, false);
|
||||
expect(Translator.translations[mmm.name]).toBeUndefined();
|
||||
expect(Translator.translationsFallback[mmm.name]).toEqual({
|
||||
Hello: "Hallo"
|
||||
});
|
||||
done();
|
||||
};
|
||||
|
||||
Translator.translationsFallback[mmm.name] = {
|
||||
Hello: "Hallo"
|
||||
};
|
||||
|
||||
await Translator.load(mmm, file, false);
|
||||
expect(Translator.translations[mmm.name]).toBe(undefined);
|
||||
expect(Translator.translationsFallback[mmm.name]).toEqual({
|
||||
Hello: "Hallo"
|
||||
});
|
||||
done();
|
||||
};
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("loadCoreTranslations", () => {
|
||||
it("should load core translations and fallback", (done) => {
|
||||
const dom = new JSDOM(
|
||||
`<script>var translations = {en: "http://localhost:3000/translations/translation_test.json"}; var Log = {log: () => {}};</script>\
|
||||
it("should load core translations and fallback", () => {
|
||||
return new Promise((done) => {
|
||||
const dom = new JSDOM(
|
||||
`<script>var translations = {en: "http://localhost:3000/translations/translation_test.json"}; var Log = {log: () => {}};</script>\
|
||||
<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`,
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
);
|
||||
dom.window.onload = async () => {
|
||||
const { Translator } = dom.window;
|
||||
await Translator.loadCoreTranslations("en");
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
);
|
||||
dom.window.onload = async () => {
|
||||
const { Translator } = dom.window;
|
||||
await Translator.loadCoreTranslations("en");
|
||||
|
||||
const en = require(path.join(__dirname, "..", "..", "..", "tests", "mocks", "translation_test.json"));
|
||||
setTimeout(() => {
|
||||
expect(Translator.coreTranslations).toEqual(en);
|
||||
expect(Translator.coreTranslationsFallback).toEqual(en);
|
||||
done();
|
||||
}, 500);
|
||||
};
|
||||
const en = require(path.join(__dirname, "..", "..", "..", "tests", "mocks", "translation_test.json"));
|
||||
setTimeout(() => {
|
||||
expect(Translator.coreTranslations).toEqual(en);
|
||||
expect(Translator.coreTranslationsFallback).toEqual(en);
|
||||
done();
|
||||
}, 500);
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
it("should load core fallback if language cannot be found", (done) => {
|
||||
const dom = new JSDOM(
|
||||
`<script>var translations = {en: "http://localhost:3000/translations/translation_test.json"}; var Log = {log: () => {}};</script>\
|
||||
it("should load core fallback if language cannot be found", () => {
|
||||
return new Promise((done) => {
|
||||
const dom = new JSDOM(
|
||||
`<script>var translations = {en: "http://localhost:3000/translations/translation_test.json"}; var Log = {log: () => {}};</script>\
|
||||
<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`,
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
);
|
||||
dom.window.onload = async () => {
|
||||
const { Translator } = dom.window;
|
||||
await Translator.loadCoreTranslations("MISSINGLANG");
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
);
|
||||
dom.window.onload = async () => {
|
||||
const { Translator } = dom.window;
|
||||
await Translator.loadCoreTranslations("MISSINGLANG");
|
||||
|
||||
const en = require(path.join(__dirname, "..", "..", "..", "tests", "mocks", "translation_test.json"));
|
||||
setTimeout(() => {
|
||||
expect(Translator.coreTranslations).toEqual({});
|
||||
expect(Translator.coreTranslationsFallback).toEqual(en);
|
||||
done();
|
||||
}, 500);
|
||||
};
|
||||
const en = require(path.join(__dirname, "..", "..", "..", "tests", "mocks", "translation_test.json"));
|
||||
setTimeout(() => {
|
||||
expect(Translator.coreTranslations).toEqual({});
|
||||
expect(Translator.coreTranslationsFallback).toEqual(en);
|
||||
done();
|
||||
}, 500);
|
||||
};
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("loadCoreTranslationsFallback", () => {
|
||||
it("should load core translations fallback", (done) => {
|
||||
const dom = new JSDOM(
|
||||
`<script>var translations = {en: "http://localhost:3000/translations/translation_test.json"}; var Log = {log: () => {}};</script>\
|
||||
it("should load core translations fallback", () => {
|
||||
return new Promise((done) => {
|
||||
const dom = new JSDOM(
|
||||
`<script>var translations = {en: "http://localhost:3000/translations/translation_test.json"}; var Log = {log: () => {}};</script>\
|
||||
<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`,
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
);
|
||||
dom.window.onload = async () => {
|
||||
const { Translator } = dom.window;
|
||||
await Translator.loadCoreTranslationsFallback();
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
);
|
||||
dom.window.onload = async () => {
|
||||
const { Translator } = dom.window;
|
||||
await Translator.loadCoreTranslationsFallback();
|
||||
|
||||
const en = require(path.join(__dirname, "..", "..", "..", "tests", "mocks", "translation_test.json"));
|
||||
setTimeout(() => {
|
||||
expect(Translator.coreTranslationsFallback).toEqual(en);
|
||||
done();
|
||||
}, 500);
|
||||
};
|
||||
const en = require(path.join(__dirname, "..", "..", "..", "tests", "mocks", "translation_test.json"));
|
||||
setTimeout(() => {
|
||||
expect(Translator.coreTranslationsFallback).toEqual(en);
|
||||
done();
|
||||
}, 500);
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
it("should load core fallback if language cannot be found", (done) => {
|
||||
const dom = new JSDOM(
|
||||
`<script>var translations = {}; var Log = {log: () => {}};</script>\
|
||||
it("should load core fallback if language cannot be found", () => {
|
||||
return new Promise((done) => {
|
||||
const dom = new JSDOM(
|
||||
`<script>var translations = {}; var Log = {log: () => {}};</script>\
|
||||
<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`,
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
);
|
||||
dom.window.onload = async () => {
|
||||
const { Translator } = dom.window;
|
||||
await Translator.loadCoreTranslations();
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
);
|
||||
dom.window.onload = async () => {
|
||||
const { Translator } = dom.window;
|
||||
await Translator.loadCoreTranslations();
|
||||
|
||||
setTimeout(() => {
|
||||
expect(Translator.coreTranslationsFallback).toEqual({});
|
||||
done();
|
||||
}, 500);
|
||||
};
|
||||
setTimeout(() => {
|
||||
expect(Translator.coreTranslationsFallback).toEqual({});
|
||||
done();
|
||||
}, 500);
|
||||
};
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -4,17 +4,19 @@ const { JSDOM } = require("jsdom");
|
||||
describe("Test function cmpVersions in js/module.js", () => {
|
||||
let cmp;
|
||||
|
||||
beforeAll((done) => {
|
||||
const dom = new JSDOM(
|
||||
`<script>var Class = {extend: () => { return {}; }};</script>\
|
||||
beforeAll(() => {
|
||||
return new Promise((done) => {
|
||||
const dom = new JSDOM(
|
||||
`<script>var Class = {extend: () => { return {}; }};</script>\
|
||||
<script src="file://${path.join(__dirname, "..", "..", "..", "js", "module.js")}">`,
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
);
|
||||
dom.window.onload = () => {
|
||||
const { cmpVersions } = dom.window;
|
||||
cmp = cmpVersions;
|
||||
done();
|
||||
};
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
);
|
||||
dom.window.onload = () => {
|
||||
const { cmpVersions } = dom.window;
|
||||
cmp = cmpVersions;
|
||||
done();
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
it("should return -1 when comparing 2.1 to 2.2", () => {
|
||||
|
@@ -31,47 +31,47 @@ describe("server_functions tests", () => {
|
||||
};
|
||||
|
||||
request = {
|
||||
url: `/cors?url=www.test.com`
|
||||
url: "/cors?url=www.test.com"
|
||||
};
|
||||
});
|
||||
|
||||
test("Calls correct URL once", async () => {
|
||||
it("Calls correct URL once", async () => {
|
||||
const urlToCall = "http://www.test.com/path?param1=value1";
|
||||
request.url = `/cors?url=${urlToCall}`;
|
||||
|
||||
await cors(request, corsResponse);
|
||||
|
||||
expect(fetchMock.mock.calls.length).toBe(1);
|
||||
expect(fetchMock.mock.calls).toHaveLength(1);
|
||||
expect(fetchMock.mock.calls[0][0]).toBe(urlToCall);
|
||||
});
|
||||
|
||||
test("Forewards Content-Type if json", async () => {
|
||||
it("Forewards Content-Type if json", async () => {
|
||||
fetchResponseHeadersGet.mockImplementation(() => "json");
|
||||
|
||||
await cors(request, corsResponse);
|
||||
|
||||
expect(fetchResponseHeadersGet.mock.calls.length).toBe(1);
|
||||
expect(fetchResponseHeadersGet.mock.calls).toHaveLength(1);
|
||||
expect(fetchResponseHeadersGet.mock.calls[0][0]).toBe("Content-Type");
|
||||
|
||||
expect(corsResponse.set.mock.calls.length).toBe(1);
|
||||
expect(corsResponse.set.mock.calls).toHaveLength(1);
|
||||
expect(corsResponse.set.mock.calls[0][0]).toBe("Content-Type");
|
||||
expect(corsResponse.set.mock.calls[0][1]).toBe("json");
|
||||
});
|
||||
|
||||
test("Forewards Content-Type if xml", async () => {
|
||||
it("Forewards Content-Type if xml", async () => {
|
||||
fetchResponseHeadersGet.mockImplementation(() => "xml");
|
||||
|
||||
await cors(request, corsResponse);
|
||||
|
||||
expect(fetchResponseHeadersGet.mock.calls.length).toBe(1);
|
||||
expect(fetchResponseHeadersGet.mock.calls).toHaveLength(1);
|
||||
expect(fetchResponseHeadersGet.mock.calls[0][0]).toBe("Content-Type");
|
||||
|
||||
expect(corsResponse.set.mock.calls.length).toBe(1);
|
||||
expect(corsResponse.set.mock.calls).toHaveLength(1);
|
||||
expect(corsResponse.set.mock.calls[0][0]).toBe("Content-Type");
|
||||
expect(corsResponse.set.mock.calls[0][1]).toBe("xml");
|
||||
});
|
||||
|
||||
test("Sends correct data from response", async () => {
|
||||
it("Sends correct data from response", async () => {
|
||||
const responseData = "some data";
|
||||
fetchResponseHeadersText.mockImplementation(() => responseData);
|
||||
|
||||
@@ -82,11 +82,11 @@ describe("server_functions tests", () => {
|
||||
|
||||
await cors(request, corsResponse);
|
||||
|
||||
expect(fetchResponseHeadersText.mock.calls.length).toBe(1);
|
||||
expect(fetchResponseHeadersText.mock.calls).toHaveLength(1);
|
||||
expect(sentData).toBe(responseData);
|
||||
});
|
||||
|
||||
test("Sends error data from response", async () => {
|
||||
it("Sends error data from response", async () => {
|
||||
const error = new Error("error data");
|
||||
fetchResponseHeadersText.mockImplementation(() => {
|
||||
throw error;
|
||||
@@ -99,32 +99,32 @@ describe("server_functions tests", () => {
|
||||
|
||||
await cors(request, corsResponse);
|
||||
|
||||
expect(fetchResponseHeadersText.mock.calls.length).toBe(1);
|
||||
expect(fetchResponseHeadersText.mock.calls).toHaveLength(1);
|
||||
expect(sentData).toBe(error);
|
||||
});
|
||||
|
||||
test("Fetches with user agent by default", async () => {
|
||||
it("Fetches with user agent by default", async () => {
|
||||
await cors(request, corsResponse);
|
||||
|
||||
expect(fetchMock.mock.calls.length).toBe(1);
|
||||
expect(fetchMock.mock.calls).toHaveLength(1);
|
||||
expect(fetchMock.mock.calls[0][1]).toHaveProperty("headers");
|
||||
expect(fetchMock.mock.calls[0][1].headers).toHaveProperty("User-Agent");
|
||||
});
|
||||
|
||||
test("Fetches with specified headers", async () => {
|
||||
it("Fetches with specified headers", async () => {
|
||||
const headersParam = "sendheaders=header1:value1,header2:value2";
|
||||
const urlParam = "http://www.test.com/path?param1=value1";
|
||||
request.url = `/cors?${headersParam}&url=${urlParam}`;
|
||||
|
||||
await cors(request, corsResponse);
|
||||
|
||||
expect(fetchMock.mock.calls.length).toBe(1);
|
||||
expect(fetchMock.mock.calls).toHaveLength(1);
|
||||
expect(fetchMock.mock.calls[0][1]).toHaveProperty("headers");
|
||||
expect(fetchMock.mock.calls[0][1].headers).toHaveProperty("header1", "value1");
|
||||
expect(fetchMock.mock.calls[0][1].headers).toHaveProperty("header2", "value2");
|
||||
});
|
||||
|
||||
test("Sends specified headers", async () => {
|
||||
it("Sends specified headers", async () => {
|
||||
fetchResponseHeadersGet.mockImplementation((input) => input.replace("header", "value"));
|
||||
|
||||
const expectedheaders = "expectedheaders=header1,header2";
|
||||
@@ -133,9 +133,9 @@ describe("server_functions tests", () => {
|
||||
|
||||
await cors(request, corsResponse);
|
||||
|
||||
expect(fetchMock.mock.calls.length).toBe(1);
|
||||
expect(fetchMock.mock.calls).toHaveLength(1);
|
||||
expect(fetchMock.mock.calls[0][1]).toHaveProperty("headers");
|
||||
expect(corsResponse.set.mock.calls.length).toBe(3);
|
||||
expect(corsResponse.set.mock.calls).toHaveLength(3);
|
||||
expect(corsResponse.set.mock.calls[0][0]).toBe("Content-Type");
|
||||
expect(corsResponse.set.mock.calls[1][0]).toBe("header1");
|
||||
expect(corsResponse.set.mock.calls[1][1]).toBe("value1");
|
||||
|
@@ -32,7 +32,7 @@ describe("Updatenotification", () => {
|
||||
const { promisify } = require("util");
|
||||
promisify.mockReturnValue(execMock);
|
||||
|
||||
const GitHelper = require(`../../../modules/default/updatenotification/git_helper`);
|
||||
const GitHelper = require("../../../modules/default/updatenotification/git_helper");
|
||||
gitHelper = new GitHelper();
|
||||
});
|
||||
|
||||
@@ -103,7 +103,7 @@ describe("Updatenotification", () => {
|
||||
execMock.mockRejectedValueOnce(errorMessage);
|
||||
|
||||
const repos = await gitHelper.getRepos();
|
||||
expect(repos.length).toBe(0);
|
||||
expect(repos).toHaveLength(0);
|
||||
|
||||
const { error } = require("logger");
|
||||
expect(error).toHaveBeenCalledWith(`Failed to retrieve repo info for ${moduleName}: Failed to retrieve status`);
|
||||
@@ -142,7 +142,7 @@ describe("Updatenotification", () => {
|
||||
execMock.mockRejectedValueOnce(errorMessage);
|
||||
|
||||
const repos = await gitHelper.getRepos();
|
||||
expect(repos.length).toBe(0);
|
||||
expect(repos).toHaveLength(0);
|
||||
|
||||
const { error } = require("logger");
|
||||
expect(error).toHaveBeenCalledWith(`Failed to retrieve repo info for ${moduleName}: Failed to retrieve status`);
|
||||
@@ -183,7 +183,7 @@ describe("Updatenotification", () => {
|
||||
execMock.mockRejectedValueOnce(errorMessage);
|
||||
|
||||
const repos = await gitHelper.getRepos();
|
||||
expect(repos.length).toBe(0);
|
||||
expect(repos).toHaveLength(0);
|
||||
|
||||
const { error } = require("logger");
|
||||
expect(error).toHaveBeenCalledWith(`Failed to retrieve repo info for ${moduleName}: Failed to retrieve status`);
|
||||
@@ -224,7 +224,7 @@ describe("Updatenotification", () => {
|
||||
execMock.mockRejectedValueOnce(errorMessage);
|
||||
|
||||
const repos = await gitHelper.getRepos();
|
||||
expect(repos.length).toBe(0);
|
||||
expect(repos).toHaveLength(0);
|
||||
|
||||
const { error } = require("logger");
|
||||
expect(error).toHaveBeenCalledWith(`Failed to retrieve repo info for ${moduleName}: Failed to retrieve status`);
|
||||
|
@@ -14,11 +14,11 @@ describe("'global.root_path' set in js/app.js", () => {
|
||||
});
|
||||
|
||||
it("should not modify global.root_path for testing", () => {
|
||||
expect(global.root_path).toBe(undefined);
|
||||
expect(global.root_path).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should not modify global.version for testing", () => {
|
||||
expect(global.version).toBe(undefined);
|
||||
expect(global.version).toBeUndefined();
|
||||
});
|
||||
|
||||
it("should expect the global.version equals package.json file", () => {
|
||||
|
@@ -1,3 +1,3 @@
|
||||
module.exports = async () => {
|
||||
process.env.TZ = "Europe/Berlin";
|
||||
process.env.TZ = "UTC";
|
||||
};
|
||||
|
@@ -0,0 +1,29 @@
|
||||
global.moment = require("moment-timezone");
|
||||
|
||||
const CalendarFetcherUtils = require("../../../../../modules/default/calendar/calendarfetcherutils");
|
||||
|
||||
describe("Calendar fetcher utils test", () => {
|
||||
const defaultConfig = {
|
||||
excludedEvents: []
|
||||
};
|
||||
|
||||
describe("filterEvents", () => {
|
||||
it("no events, not crash", () => {
|
||||
const minusOneHour = moment().subtract(1, "hours").toDate();
|
||||
const minusTwoHours = moment().subtract(2, "hours").toDate();
|
||||
const plusOneHour = moment().add(1, "hours").toDate();
|
||||
const plusTwoHours = moment().add(2, "hours").toDate();
|
||||
|
||||
const filteredEvents = CalendarFetcherUtils.filterEvents(
|
||||
{
|
||||
pastEvent: { type: "VEVENT", start: minusTwoHours, end: minusOneHour, summary: "pastEvent" },
|
||||
ongoingEvent: { type: "VEVENT", start: minusOneHour, end: plusOneHour, summary: "ongoingEvent" },
|
||||
upcomingEvent: { type: "VEVENT", start: plusOneHour, end: plusTwoHours, summary: "upcomingEvent" }
|
||||
},
|
||||
defaultConfig
|
||||
);
|
||||
|
||||
expect(filteredEvents).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
});
|
@@ -26,7 +26,7 @@ describe("Calendar fetcher utils test", () => {
|
||||
defaultConfig
|
||||
);
|
||||
|
||||
expect(filteredEvents.length).toEqual(2);
|
||||
expect(filteredEvents).toHaveLength(2);
|
||||
expect(filteredEvents[0].title).toBe("ongoingEvent");
|
||||
expect(filteredEvents[1].title).toBe("upcomingEvent");
|
||||
});
|
||||
@@ -45,7 +45,7 @@ describe("Calendar fetcher utils test", () => {
|
||||
defaultConfig
|
||||
);
|
||||
|
||||
expect(filteredEvents.length).toEqual(2);
|
||||
expect(filteredEvents).toHaveLength(2);
|
||||
expect(filteredEvents[0].title).toBe("ongoingEvent");
|
||||
expect(filteredEvents[1].title).toBe("upcomingEvent");
|
||||
});
|
||||
|
@@ -138,11 +138,16 @@ describe("Calendar utils tests", () => {
|
||||
|
||||
describe("titleTransform and shorten combined", () => {
|
||||
it("should replace the birthday and wrap nicely", () => {
|
||||
const transformedTitle = CalendarUtils.titleTransform("Michael Teeuw's birthday", {
|
||||
"De verjaardag van ": "",
|
||||
"'s birthday": ""
|
||||
});
|
||||
const transformedTitle = CalendarUtils.titleTransform("Michael Teeuw's birthday", [{ search: "'s birthday", replace: "" }]);
|
||||
expect(CalendarUtils.shorten(transformedTitle, 10, true, 2)).toBe("Michael <br>Teeuw");
|
||||
});
|
||||
});
|
||||
|
||||
describe("titleTransform with yearmatchgroup", () => {
|
||||
it("should replace the birthday and wrap nicely", () => {
|
||||
const transformedTitle = CalendarUtils.titleTransform("Luciella '2000", [{ search: "^([^']*) '(\\d{4})$", replace: "$1 ($2.)", yearmatchgroup: 2 }]);
|
||||
const expectedResult = `Luciella (${new Date().getFullYear() - 2000}.)`;
|
||||
expect(transformedTitle).toBe(expectedResult);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -24,16 +24,16 @@ describe("Default modules utils tests", () => {
|
||||
}
|
||||
});
|
||||
|
||||
test("Calls correct URL once", async () => {
|
||||
it("Calls correct URL once", async () => {
|
||||
urlToCall = "http://www.test.com/path?param1=value1";
|
||||
|
||||
await performWebRequest(urlToCall, "json", true);
|
||||
|
||||
expect(fetchMock.mock.calls.length).toBe(1);
|
||||
expect(fetchMock.mock.calls).toHaveLength(1);
|
||||
expect(fetchMock.mock.calls[0][0]).toBe(`${locationProtocol}//${locationHost}/cors?url=${urlToCall}`);
|
||||
});
|
||||
|
||||
test("Sends correct headers", async () => {
|
||||
it("Sends correct headers", async () => {
|
||||
urlToCall = "http://www.test.com/path?param1=value1";
|
||||
|
||||
const headers = [
|
||||
@@ -43,22 +43,22 @@ describe("Default modules utils tests", () => {
|
||||
|
||||
await performWebRequest(urlToCall, "json", true, headers);
|
||||
|
||||
expect(fetchMock.mock.calls.length).toBe(1);
|
||||
expect(fetchMock.mock.calls).toHaveLength(1);
|
||||
expect(fetchMock.mock.calls[0][0]).toBe(`${locationProtocol}//${locationHost}/cors?sendheaders=header1:value1,header2:value2&url=${urlToCall}`);
|
||||
});
|
||||
});
|
||||
|
||||
describe("When not using cors proxy", () => {
|
||||
test("Calls correct URL once", async () => {
|
||||
it("Calls correct URL once", async () => {
|
||||
urlToCall = "http://www.test.com/path?param1=value1";
|
||||
|
||||
await performWebRequest(urlToCall);
|
||||
|
||||
expect(fetchMock.mock.calls.length).toBe(1);
|
||||
expect(fetchMock.mock.calls).toHaveLength(1);
|
||||
expect(fetchMock.mock.calls[0][0]).toBe(urlToCall);
|
||||
});
|
||||
|
||||
test("Sends correct headers", async () => {
|
||||
it("Sends correct headers", async () => {
|
||||
urlToCall = "http://www.test.com/path?param1=value1";
|
||||
const headers = [
|
||||
{ name: "header1", value: "value1" },
|
||||
@@ -68,36 +68,36 @@ describe("Default modules utils tests", () => {
|
||||
await performWebRequest(urlToCall, "json", false, headers);
|
||||
|
||||
const expectedHeaders = { headers: { header1: "value1", header2: "value2" } };
|
||||
expect(fetchMock.mock.calls.length).toBe(1);
|
||||
expect(fetchMock.mock.calls).toHaveLength(1);
|
||||
expect(fetchMock.mock.calls[0][1]).toStrictEqual(expectedHeaders);
|
||||
});
|
||||
});
|
||||
|
||||
describe("When receiving json format", () => {
|
||||
test("Returns undefined when no data is received", async () => {
|
||||
it("Returns undefined when no data is received", async () => {
|
||||
urlToCall = "www.test.com";
|
||||
|
||||
const response = await performWebRequest(urlToCall);
|
||||
|
||||
expect(response).toBe(undefined);
|
||||
expect(response).toBeUndefined();
|
||||
});
|
||||
|
||||
test("Returns object when data is received", async () => {
|
||||
it("Returns object when data is received", async () => {
|
||||
urlToCall = "www.test.com";
|
||||
fetchResponse = new Response('{"body": "some content"}');
|
||||
fetchResponse = new Response("{\"body\": \"some content\"}");
|
||||
|
||||
const response = await performWebRequest(urlToCall);
|
||||
|
||||
expect(response.body).toBe("some content");
|
||||
});
|
||||
|
||||
test("Returns expected headers when data is received", async () => {
|
||||
it("Returns expected headers when data is received", async () => {
|
||||
urlToCall = "www.test.com";
|
||||
fetchResponse = new Response('{"body": "some content"}', { headers: { header1: "value1", header2: "value2" } });
|
||||
fetchResponse = new Response("{\"body\": \"some content\"}", { headers: { header1: "value1", header2: "value2" } });
|
||||
|
||||
const response = await performWebRequest(urlToCall, "json", false, undefined, ["header1"]);
|
||||
|
||||
expect(response.headers.length).toBe(1);
|
||||
expect(response.headers).toHaveLength(1);
|
||||
expect(response.headers[0].name).toBe("header1");
|
||||
expect(response.headers[0].value).toBe("value1");
|
||||
});
|
||||
@@ -150,17 +150,5 @@ describe("Default modules utils tests", () => {
|
||||
)
|
||||
).toBe("1:13");
|
||||
});
|
||||
|
||||
it("should convert correctly into another timezone", () => {
|
||||
expect(
|
||||
formatTime(
|
||||
{
|
||||
timeFormat: 24,
|
||||
timezone: "America/Toronto"
|
||||
},
|
||||
time
|
||||
)
|
||||
).toBe("07:13");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -2,7 +2,13 @@ const weather = require("../../../../../modules/default/weather/weatherutils");
|
||||
const WeatherUtils = require("../../../../../modules/default/weather/weatherutils");
|
||||
|
||||
describe("Weather utils tests", () => {
|
||||
describe("windspeed conversion", () => {
|
||||
describe("windspeed conversion to imperial", () => {
|
||||
it("should convert temp correctly from Celsius to Fahrenheit", () => {
|
||||
expect(Math.round(WeatherUtils.convertTemp(10, "imperial"))).toBe(50);
|
||||
});
|
||||
});
|
||||
|
||||
describe("windspeed conversion to beaufort", () => {
|
||||
it("should convert windspeed correctly from mps to beaufort", () => {
|
||||
expect(Math.round(WeatherUtils.convertWind(5, "beaufort"))).toBe(3);
|
||||
expect(Math.round(WeatherUtils.convertWind(300, "beaufort"))).toBe(12);
|
||||
@@ -32,15 +38,16 @@ describe("Weather utils tests", () => {
|
||||
describe("wind direction conversion", () => {
|
||||
it("should convert wind direction correctly from cardinal to value", () => {
|
||||
expect(WeatherUtils.convertWindDirection("SSE")).toBe(157);
|
||||
expect(WeatherUtils.convertWindDirection("XXX")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe("feelsLike calculation", () => {
|
||||
it("should return a calculated feelsLike info", () => {
|
||||
it("should return a calculated feelsLike info (negative value)", () => {
|
||||
expect(WeatherUtils.calculateFeelsLike(0, 20, 40)).toBe(-9.444444444444445);
|
||||
});
|
||||
|
||||
it("should return a calculated feelsLike info", () => {
|
||||
it("should return a calculated feelsLike info (positiv value)", () => {
|
||||
expect(WeatherUtils.calculateFeelsLike(30, 0, 60)).toBe(32.8320322777777);
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user