added all files to project

This commit is contained in:
2022-03-10 10:36:59 +01:00
parent 09dd957b33
commit 46a936d7de
25351 changed files with 3883356 additions and 0 deletions
+108
View File
@@ -0,0 +1,108 @@
const path = require("path");
const { JSDOM } = require("jsdom");
describe("File js/class", function () {
describe("Test function cloneObject", function () {
let clone;
let dom;
beforeAll(function (done) {
dom = new JSDOM(
`<script>var Log = {log: function() {}};</script>\
<script src="file://${path.join(__dirname, "..", "..", "..", "js", "class.js")}">`,
{ runScripts: "dangerously", resources: "usable" }
);
dom.window.onload = function () {
const { cloneObject } = dom.window;
clone = cloneObject;
done();
};
});
it("should clone object", function () {
const expected = { name: "Rodrigo", web: "https://rodrigoramirez.com", project: "MagicMirror" };
const obj = clone(expected);
expect(obj).toEqual(expected);
expect(expected === obj).toBe(false);
});
it("should clone array", function () {
const expected = [1, null, undefined, "TEST"];
const obj = clone(expected);
expect(obj).toEqual(expected);
expect(expected === obj).toBe(false);
});
it("should clone number", function () {
let expected = 1;
let obj = clone(expected);
expect(obj).toBe(expected);
expected = 1.23;
obj = clone(expected);
expect(obj).toBe(expected);
});
it("should clone string", function () {
const expected = "Perfect stranger";
const obj = clone(expected);
expect(obj).toBe(expected);
});
it("should clone undefined", function () {
const expected = undefined;
const obj = clone(expected);
expect(obj).toBe(expected);
});
it("should clone null", function () {
const expected = null;
const obj = clone(expected);
expect(obj).toBe(expected);
});
it("should clone nested object", function () {
const expected = {
name: "fewieden",
link: "https://github.com/fewieden",
versions: ["2.0", "2.1", "2.2"],
answerForAllQuestions: 42,
properties: {
items: [{ foo: "bar" }, { lorem: "ipsum" }],
invalid: undefined,
nothing: null
}
};
const obj = clone(expected);
expect(obj).toEqual(expected);
expect(expected === obj).toBe(false);
expect(expected.versions === obj.versions).toBe(false);
expect(expected.properties === obj.properties).toBe(false);
expect(expected.properties.items === obj.properties.items).toBe(false);
expect(expected.properties.items[0] === obj.properties.items[0]).toBe(false);
expect(expected.properties.items[1] === obj.properties.items[1]).toBe(false);
});
describe("Test lockstring code", function () {
let log;
beforeAll(function () {
log = dom.window.Log.log;
dom.window.Log.log = function cmp(str) {
expect(str).toBe("lockStrings");
};
});
afterAll(function () {
dom.window.Log.log = log;
});
it("should clone object and log lockStrings", function () {
const expected = { name: "Module", lockStrings: "stringLock" };
const obj = clone(expected);
expect(obj).toEqual(expected);
expect(expected === obj).toBe(false);
});
});
});
});
+15
View File
@@ -0,0 +1,15 @@
const deprecated = require("../../../js/deprecated");
describe("Deprecated", function () {
it("should be an object", function () {
expect(typeof deprecated).toBe("object");
});
it("should contain configs array with deprecated options as strings", function () {
expect(Array.isArray(["deprecated.configs"])).toBe(true);
for (let option of deprecated.configs) {
expect(typeof option).toBe("string");
}
expect(deprecated.configs).toEqual(expect.arrayContaining(["kioskmode"]));
});
});
+288
View File
@@ -0,0 +1,288 @@
const path = require("path");
const helmet = require("helmet");
const { JSDOM } = require("jsdom");
const express = require("express");
const sockets = new Set();
describe("Translator", function () {
let server;
beforeAll(function () {
const app = express();
app.use(helmet());
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
next();
});
app.use("/translations", express.static(path.join(__dirname, "..", "..", "..", "tests", "configs", "data")));
server = app.listen(3000);
server.on("connection", (socket) => {
sockets.add(socket);
});
});
afterAll(function () {
for (const socket of sockets) {
socket.destroy();
sockets.delete(socket);
}
server.close();
});
describe("translate", function () {
const translations = {
"MMM-Module": {
Hello: "Hallo",
"Hello {username}": "Hallo {username}"
}
};
const coreTranslations = {
Hello: "XXX",
"Hello {username}": "XXX",
FOO: "Foo",
"BAR {something}": "Bar {something}"
};
const translationsFallback = {
"MMM-Module": {
Hello: "XXX",
"Hello {username}": "XXX",
FOO: "XXX",
"BAR {something}": "XXX",
"A key": "A translation"
}
};
const coreTranslationsFallback = {
FOO: "XXX",
"BAR {something}": "XXX",
Hello: "XXX",
"Hello {username}": "XXX",
"A key": "XXX",
Fallback: "core fallback"
};
/**
* @param {object} Translator the global Translator object
*/
function setTranslations(Translator) {
Translator.translations = translations;
Translator.coreTranslations = coreTranslations;
Translator.translationsFallback = translationsFallback;
Translator.coreTranslationsFallback = coreTranslationsFallback;
}
it("should return custom module translation", function (done) {
const dom = new JSDOM(`<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
dom.window.onload = function () {
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", function (done) {
const dom = new JSDOM(`<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
dom.window.onload = function () {
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", function (done) {
const dom = new JSDOM(`<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
dom.window.onload = function () {
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", function (done) {
const dom = new JSDOM(`<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
dom.window.onload = function () {
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", function (done) {
const dom = new JSDOM(`<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
dom.window.onload = function () {
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", function (done) {
const dom = new JSDOM(`<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
dom.window.onload = function () {
const { Translator } = dom.window;
setTranslations(Translator);
const translation = Translator.translate({ name: "MMM-Module" }, "MISSING");
expect(translation).toBe("MISSING");
done();
};
});
});
describe("load", function () {
const mmm = {
name: "TranslationTest",
file(file) {
return `http://localhost:3000/translations/${file}`;
}
};
it("should load translations", function (done) {
const dom = new JSDOM(`<script>var Log = {log: function(){}};</script><script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
dom.window.onload = function () {
const { Translator } = dom.window;
const file = "TranslationTest.json";
Translator.load(mmm, file, false, function () {
const json = require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", file));
expect(Translator.translations[mmm.name]).toEqual(json);
done();
});
};
});
it("should load translation fallbacks", function (done) {
const dom = new JSDOM(`<script>var Log = {log: function(){}};</script><script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
dom.window.onload = function () {
const { Translator } = dom.window;
const file = "TranslationTest.json";
Translator.load(mmm, file, true, function () {
const json = require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", file));
expect(Translator.translationsFallback[mmm.name]).toEqual(json);
done();
});
};
});
it("should not load translations, if module fallback exists", function (done) {
const dom = new JSDOM(`<script>var Log = {log: function(){}};</script><script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously", resources: "usable" });
dom.window.onload = function () {
const { Translator, XMLHttpRequest } = dom.window;
const file = "TranslationTest.json";
XMLHttpRequest.prototype.send = function () {
throw "Shouldn't load files";
};
Translator.translationsFallback[mmm.name] = {
Hello: "Hallo"
};
Translator.load(mmm, file, false, function () {
expect(Translator.translations[mmm.name]).toBe(undefined);
expect(Translator.translationsFallback[mmm.name]).toEqual({
Hello: "Hallo"
});
done();
});
};
});
});
describe("loadCoreTranslations", function () {
it("should load core translations and fallback", function (done) {
const dom = new JSDOM(
`<script>var translations = {en: "http://localhost:3000/translations/en.json"}; var Log = {log: function(){}};</script>\
<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`,
{ runScripts: "dangerously", resources: "usable" }
);
dom.window.onload = function () {
const { Translator } = dom.window;
Translator.loadCoreTranslations("en");
const en = require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", "en.json"));
setTimeout(function () {
expect(Translator.coreTranslations).toEqual(en);
expect(Translator.coreTranslationsFallback).toEqual(en);
done();
}, 500);
};
});
it("should load core fallback if language cannot be found", function (done) {
const dom = new JSDOM(
`<script>var translations = {en: "http://localhost:3000/translations/en.json"}; var Log = {log: function(){}};</script>\
<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`,
{ runScripts: "dangerously", resources: "usable" }
);
dom.window.onload = function () {
const { Translator } = dom.window;
Translator.loadCoreTranslations("MISSINGLANG");
const en = require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", "en.json"));
setTimeout(function () {
expect(Translator.coreTranslations).toEqual({});
expect(Translator.coreTranslationsFallback).toEqual(en);
done();
}, 500);
};
});
});
describe("loadCoreTranslationsFallback", function () {
it("should load core translations fallback", function (done) {
const dom = new JSDOM(
`<script>var translations = {en: "http://localhost:3000/translations/en.json"}; var Log = {log: function(){}};</script>\
<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`,
{ runScripts: "dangerously", resources: "usable" }
);
dom.window.onload = function () {
const { Translator } = dom.window;
Translator.loadCoreTranslationsFallback();
const en = require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", "en.json"));
setTimeout(function () {
expect(Translator.coreTranslationsFallback).toEqual(en);
done();
}, 500);
};
});
it("should load core fallback if language cannot be found", function (done) {
const dom = new JSDOM(
`<script>var translations = {}; var Log = {log: function(){}};</script>\
<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`,
{ runScripts: "dangerously", resources: "usable" }
);
dom.window.onload = function () {
const { Translator } = dom.window;
Translator.loadCoreTranslations();
setTimeout(function () {
expect(Translator.coreTranslationsFallback).toEqual({});
done();
}, 500);
};
});
});
});
+38
View File
@@ -0,0 +1,38 @@
const Utils = require("../../../js/utils.js");
const colors = require("colors/safe");
describe("Utils", function () {
describe("colors", function () {
const colorsEnabled = colors.enabled;
afterEach(function () {
colors.enabled = colorsEnabled;
});
it("should have info, warn and error properties", function () {
expect(Utils.colors).toHaveProperty("info");
expect(Utils.colors).toHaveProperty("warn");
expect(Utils.colors).toHaveProperty("error");
});
it("properties should be functions", function () {
expect(typeof Utils.colors.info).toBe("function");
expect(typeof Utils.colors.warn).toBe("function");
expect(typeof Utils.colors.error).toBe("function");
});
it("should print colored message in supported consoles", function () {
colors.enabled = true;
expect(Utils.colors.info("some informations")).toBe("\u001b[34msome informations\u001b[39m");
expect(Utils.colors.warn("a warning")).toBe("\u001b[33ma warning\u001b[39m");
expect(Utils.colors.error("ERROR!")).toBe("\u001b[31mERROR!\u001b[39m");
});
it("should print message in unsupported consoles", function () {
colors.enabled = false;
expect(Utils.colors.info("some informations")).toBe("some informations");
expect(Utils.colors.warn("a warning")).toBe("a warning");
expect(Utils.colors.error("ERROR!")).toBe("ERROR!");
});
});
});
+128
View File
@@ -0,0 +1,128 @@
global.moment = require("moment");
describe("Functions into modules/default/calendar/calendar.js", function () {
// Fake for use by calendar.js
Module = {};
Module.definitions = {};
Module.register = function (name, moduleDefinition) {
Module.definitions[name] = moduleDefinition;
};
beforeAll(function () {
// load calendar.js
require("../../../modules/default/calendar/calendar.js");
});
describe("capFirst", function () {
const words = {
rodrigo: "Rodrigo",
"123m": "123m",
"magic mirror": "Magic mirror",
",a": ",a",
ñandú: "Ñandú"
};
Object.keys(words).forEach((word) => {
it(`for '${word}' should return '${words[word]}'`, function () {
expect(Module.definitions.calendar.capFirst(word)).toBe(words[word]);
});
});
});
describe("getLocaleSpecification", function () {
it("should return a valid moment.LocaleSpecification for a 12-hour format", function () {
expect(Module.definitions.calendar.getLocaleSpecification(12)).toEqual({ longDateFormat: { LT: "h:mm A" } });
});
it("should return a valid moment.LocaleSpecification for a 24-hour format", function () {
expect(Module.definitions.calendar.getLocaleSpecification(24)).toEqual({ longDateFormat: { LT: "HH:mm" } });
});
it("should return the current system locale when called without timeFormat number", function () {
expect(Module.definitions.calendar.getLocaleSpecification()).toEqual({ longDateFormat: { LT: moment.localeData().longDateFormat("LT") } });
});
it("should return a 12-hour longDateFormat when using the 'en' locale", function () {
const localeBackup = moment.locale();
moment.locale("en");
expect(Module.definitions.calendar.getLocaleSpecification()).toEqual({ longDateFormat: { LT: "h:mm A" } });
moment.locale(localeBackup);
});
it("should return a 12-hour longDateFormat when using the 'au' locale", function () {
const localeBackup = moment.locale();
moment.locale("au");
expect(Module.definitions.calendar.getLocaleSpecification()).toEqual({ longDateFormat: { LT: "h:mm A" } });
moment.locale(localeBackup);
});
it("should return a 12-hour longDateFormat when using the 'eg' locale", function () {
const localeBackup = moment.locale();
moment.locale("eg");
expect(Module.definitions.calendar.getLocaleSpecification()).toEqual({ longDateFormat: { LT: "h:mm A" } });
moment.locale(localeBackup);
});
it("should return a 24-hour longDateFormat when using the 'nl' locale", function () {
const localeBackup = moment.locale();
moment.locale("nl");
expect(Module.definitions.calendar.getLocaleSpecification()).toEqual({ longDateFormat: { LT: "HH:mm" } });
moment.locale(localeBackup);
});
it("should return a 24-hour longDateFormat when using the 'fr' locale", function () {
const localeBackup = moment.locale();
moment.locale("fr");
expect(Module.definitions.calendar.getLocaleSpecification()).toEqual({ longDateFormat: { LT: "HH:mm" } });
moment.locale(localeBackup);
});
it("should return a 24-hour longDateFormat when using the 'uk' locale", function () {
const localeBackup = moment.locale();
moment.locale("uk");
expect(Module.definitions.calendar.getLocaleSpecification()).toEqual({ longDateFormat: { LT: "HH:mm" } });
moment.locale(localeBackup);
});
});
describe("shorten", function () {
const strings = {
" String with whitespace at the beginning that needs trimming": { length: 16, return: "String with whit&hellip;" },
"long string that needs shortening": { length: 16, return: "long string that&hellip;" },
"short string": { length: 16, return: "short string" },
"long string with no maxLength defined": { return: "long string with no maxLength defined" }
};
Object.keys(strings).forEach((string) => {
it(`for '${string}' should return '${strings[string].return}'`, function () {
expect(Module.definitions.calendar.shorten(string, strings[string].length)).toBe(strings[string].return);
});
});
it("should return an empty string if shorten is called with a non-string", function () {
expect(Module.definitions.calendar.shorten(100)).toBe("");
});
it("should not shorten the string if shorten is called with a non-number maxLength", function () {
expect(Module.definitions.calendar.shorten("This is a test string", "This is not a number")).toBe("This is a test string");
});
it("should wrap the string instead of shorten it if shorten is called with wrapEvents = true (with maxLength defined as 20)", function () {
expect(Module.definitions.calendar.shorten("This is a wrapEvent test. Should wrap the string instead of shorten it if called with wrapEvent = true", 20, true)).toBe(
"This is a <br>wrapEvent test. Should wrap <br>the string instead of <br>shorten it if called with <br>wrapEvent = true"
);
});
it("should wrap the string instead of shorten it if shorten is called with wrapEvents = true (without maxLength defined, default 25)", function () {
expect(Module.definitions.calendar.shorten("This is a wrapEvent test. Should wrap the string instead of shorten it if called with wrapEvent = true", undefined, true)).toBe(
"This is a wrapEvent <br>test. Should wrap the string <br>instead of shorten it if called <br>with wrapEvent = true"
);
});
it("should wrap and shorten the string in the second line if called with wrapEvents = true and maxTitleLines = 2", function () {
expect(Module.definitions.calendar.shorten("This is a wrapEvent and maxTitleLines test. Should wrap and shorten the string in the second line if called with wrapEvents = true and maxTitleLines = 2", undefined, true, 2)).toBe(
"This is a wrapEvent and <br>maxTitleLines test. Should wrap and &hellip;"
);
});
});
});
+31
View File
@@ -0,0 +1,31 @@
const path = require("path");
const { JSDOM } = require("jsdom");
describe("Test function cmpVersions in js/module.js", function () {
let cmp;
beforeAll(function (done) {
const dom = new JSDOM(
`<script>var Class = {extend: function() { return {}; }};</script>\
<script src="file://${path.join(__dirname, "..", "..", "..", "js", "module.js")}">`,
{ runScripts: "dangerously", resources: "usable" }
);
dom.window.onload = function () {
const { cmpVersions } = dom.window;
cmp = cmpVersions;
done();
};
});
it("should return -1 when comparing 2.1 to 2.2", function () {
expect(cmp("2.1", "2.2")).toBe(-1);
});
it("should be return 0 when comparing 2.2 to 2.2", function () {
expect(cmp("2.2", "2.2")).toBe(0);
});
it("should be return 1 when comparing 1.1 to 1.0", function () {
expect(cmp("1.1", "1.0")).toBe(1);
});
});
@@ -0,0 +1,66 @@
/* eslint no-multi-spaces: 0 */
describe("Functions module currentweather", function () {
// Fake for use by currentweather.js
Module = {};
config = {};
Module.definitions = {};
Module.register = function (name, moduleDefinition) {
Module.definitions[name] = moduleDefinition;
};
beforeAll(function () {
require("../../../modules/default/currentweather/currentweather.js");
Module.definitions.currentweather.config = {};
});
describe("roundValue", function () {
describe("this.config.roundTemp is true", function () {
beforeAll(function () {
Module.definitions.currentweather.config.roundTemp = true;
});
const values = [
// index 0 value
// index 1 expect
[1, "1"],
[1.0, "1"],
[1.02, "1"],
[10.12, "10"],
[2.0, "2"],
["2.12", "2"],
[10.1, "10"]
];
values.forEach((value) => {
it(`for ${value[0]} should be return ${value[1]}`, function () {
expect(Module.definitions.currentweather.roundValue(value[0])).toBe(value[1]);
});
});
});
describe("this.config.roundTemp is false", function () {
beforeAll(function () {
Module.definitions.currentweather.config.roundTemp = false;
});
const values = [
// index 0 value
// index 1 expect
[1, "1.0"],
[1.0, "1.0"],
[1.02, "1.0"],
[10.12, "10.1"],
[2.0, "2.0"],
["2.12", "2.1"],
[10.1, "10.1"],
[10.1, "10.1"]
];
values.forEach((value) => {
it(`for ${value[0]} should be return ${value[1]}`, function () {
expect(Module.definitions.currentweather.roundValue(value[0])).toBe(value[1]);
});
});
});
});
});
+15
View File
@@ -0,0 +1,15 @@
describe("Functions into modules/default/newsfeed/newsfeed.js", function () {
// Fake for use by newsletter.js
Module = {};
Module.definitions = {};
Module.register = function (name, moduleDefinition) {
Module.definitions[name] = moduleDefinition;
};
beforeAll(function () {
// load newsfeed.js
require("../../../modules/default/newsfeed/newsfeed.js");
});
test.skip("skip", () => {});
});
@@ -0,0 +1,126 @@
const path = require("path");
const git_Helper = require("../../../modules/default/updatenotification/git_helper.js");
const gitHelper = new git_Helper.gitHelper();
gitHelper.add("default");
const test1 = {
module: "test1",
folder: "",
res: {
stdout: "## master...origin/master [behind 8]",
stderr: ""
},
gitInfo: {
module: "default",
// commits behind:
behind: 0,
// branch name:
current: "develop",
// current hash:
hash: "",
// remote branch:
tracking: "",
isBehindInStatus: false
}
};
const test2 = {
module: "test2",
folder: "",
res: {
stdout: "## develop...origin/develop",
stderr: ""
}
};
const test3 = {
module: "test3",
folder: "",
res: {
stdout: "",
stderr: "error"
},
gitInfo: {
module: "default",
// commits behind:
behind: 2,
// branch name:
current: "develop",
// current hash:
hash: "",
// remote branch:
tracking: "",
isBehindInStatus: true
}
};
const test4 = {
module: "default",
folder: path.join(__dirname, "../../.."),
res: {
stdout: "",
stderr: " e40ddd4..06389e3 develop -> origin/develop"
},
gitInfo: {
module: "default",
// commits behind:
behind: 0,
// branch name:
current: "develop",
// current hash:
hash: "",
// remote branch:
tracking: "",
isBehindInStatus: false
}
};
describe("Updatenotification", function () {
it("should return valid output for git status", async function () {
const arr = await gitHelper.getStatus();
expect(arr.length).toBe(1);
const gitInfo = arr[0];
expect(gitInfo.current).not.toBe("");
expect(gitInfo.hash).not.toBe("");
}, 15000);
it("should return behind=8 for test1", async function () {
const gitInfo = await gitHelper.getStatusInfo(test1);
expect(gitInfo.behind).toBe(8);
expect(gitInfo.isBehindInStatus).toBe(true);
});
it("should return behind=0 for test2", async function () {
const gitInfo = await gitHelper.getStatusInfo(test2);
expect(gitInfo.behind).toBe(0);
expect(gitInfo.isBehindInStatus).toBe(false);
});
it("should return empty status object for test3", async function () {
const gitInfo = await gitHelper.getStatusInfo(test3);
expect(gitInfo).toBe(undefined);
});
it("should return empty repo object for test2", async function () {
// no gitInfo provided in res, so returns undefined
const gitInfo = await gitHelper.getRepoInfo(test2);
expect(gitInfo).toBe(undefined);
});
it("should return empty repo object for test1", async function () {
// no regex match for refs in empty string, so returns undefined
const gitInfo = await gitHelper.getRepoInfo(test1);
expect(gitInfo).toBe(undefined);
});
it("should return empty repo object for test4", async function () {
// git ref list throws error, so returns undefined
const gitInfo = await gitHelper.getRepoInfo(test4);
expect(gitInfo).toBe(undefined);
});
it("should return behind=2 for test3", async function () {
const gitInfo = await gitHelper.getRepoInfo(test3);
expect(gitInfo.behind).toBe(2);
});
});
@@ -0,0 +1,31 @@
const WeatherObject = require("../../../modules/default/weather/weatherobject.js");
global.moment = require("moment-timezone");
global.SunCalc = require("suncalc");
describe("WeatherObject", function () {
let originalTimeZone;
let weatherobject;
beforeAll(function () {
originalTimeZone = moment.tz.guess();
moment.tz.setDefault("Africa/Dar_es_Salaam");
weatherobject = new WeatherObject("metric", "metric", "metric", true);
});
it("should return true for daytime at noon", function () {
weatherobject.date = moment(12, "HH");
weatherobject.updateSunTime(-6.774877582342688, 37.63345667023327);
expect(weatherobject.isDayTime()).toBe(true);
});
it("should return false for daytime at midnight", function () {
weatherobject.date = moment(0, "HH");
weatherobject.updateSunTime(-6.774877582342688, 37.63345667023327);
expect(weatherobject.isDayTime()).toBe(false);
});
afterAll(function () {
moment.tz.setDefault(originalTimeZone);
});
});
@@ -0,0 +1,116 @@
/* eslint no-multi-spaces: 0 */
const moment = require("moment-timezone");
const data = require("../../configs/data/weatherforecast_data.json");
describe("Functions module weatherforecast", function () {
beforeAll(function () {
Module = {};
config = {};
Module.definitions = {};
Module.register = function (name, moduleDefinition) {
Module.definitions[name] = moduleDefinition;
};
require("../../../modules/default/weatherforecast/weatherforecast.js");
Module.definitions.weatherforecast.config = {};
});
describe("roundValue", function () {
describe("this.config.roundTemp is true", function () {
beforeAll(function () {
Module.definitions.weatherforecast.config.roundTemp = true;
});
const values = [
// index 0 value
// index 1 expect
[1, "1"],
[1.0, "1"],
[1.02, "1"],
[10.12, "10"],
[2.0, "2"],
["2.12", "2"],
[10.1, "10"]
];
values.forEach((value) => {
it(`for ${value[0]} should be return ${value[1]}`, function () {
expect(Module.definitions.weatherforecast.roundValue(value[0])).toBe(value[1]);
});
});
});
describe("this.config.roundTemp is false", function () {
beforeAll(function () {
Module.definitions.weatherforecast.config.roundTemp = false;
});
const values = [
// index 0 value
// index 1 expect
[1, "1.0"],
[1.0, "1.0"],
[1.02, "1.0"],
[10.12, "10.1"],
[2.0, "2.0"],
["2.12", "2.1"],
[10.1, "10.1"],
[10.1, "10.1"]
];
values.forEach((value) => {
it(`for ${value[0]} should be return ${value[1]}`, function () {
expect(Module.definitions.weatherforecast.roundValue(value[0])).toBe(value[1]);
});
});
});
});
describe("forecastIcons", function () {
Log = {
error: function () {}
};
let originalLocale;
let originalTimeZone;
beforeAll(function () {
originalLocale = moment.locale();
originalTimeZone = moment.tz.guess();
moment.locale("hi");
moment.tz.setDefault("Europe/Warsaw");
});
describe("forecastIcons sunset specified", function () {
beforeAll(function () {
Module.definitions.weatherforecast.Log = {};
Module.definitions.weatherforecast.forecast = [];
Module.definitions.weatherforecast.show = Module.definitions.weatherforecast.updateDom = function () {};
Module.definitions.weatherforecast.config = Module.definitions.weatherforecast.defaults;
});
it(`returns correct icons with sunset time`, function () {
Module.definitions.weatherforecast.processWeather(data.withSunset, moment);
let forecastData = Module.definitions.weatherforecast.forecast;
expect(forecastData.length).toBe(4);
expect(forecastData[2].icon).toBe("wi-rain");
});
});
describe("forecastIcons sunset not specified", function () {
beforeAll(function () {
Module.definitions.weatherforecast.forecast = [];
});
it(`returns correct icons with out sunset time`, function () {
Module.definitions.weatherforecast.processWeather(data.withoutSunset, moment);
let forecastData = Module.definitions.weatherforecast.forecast;
expect(forecastData.length).toBe(4);
expect(forecastData[2].icon).toBe("wi-rain");
});
});
afterAll(function () {
moment.locale(originalLocale);
moment.tz.setDefault(originalTimeZone);
});
});
});
@@ -0,0 +1,14 @@
const fs = require("fs");
const path = require("path");
const root_path = path.join(__dirname, "../../..");
describe("Default modules set in modules/default/defaultmodules.js", function () {
const expectedDefaultModules = require("../../../modules/default/defaultmodules");
for (const defaultModule of expectedDefaultModules) {
it(`contains a folder for modules/default/${defaultModule}"`, function () {
expect(fs.existsSync(path.join(root_path, "modules/default", defaultModule))).toBe(true);
});
}
});
+28
View File
@@ -0,0 +1,28 @@
const fs = require("fs");
const path = require("path");
const root_path = path.join(__dirname, "../../..");
const version = require(`${__dirname}/../../../package.json`).version;
describe("'global.root_path' set in js/app.js", function () {
const expectedSubPaths = ["modules", "serveronly", "js", "js/app.js", "js/main.js", "js/electron.js", "config"];
expectedSubPaths.forEach((subpath) => {
it(`contains a file/folder "${subpath}"`, function () {
expect(fs.existsSync(path.join(root_path, subpath))).toBe(true);
});
});
it("should not modify global.root_path for testing", function () {
expect(global.root_path).toBe(undefined);
});
it("should not modify global.version for testing", function () {
expect(global.version).toBe(undefined);
});
it("should expect the global.version equals package.json file", function () {
const versionPackage = JSON.parse(fs.readFileSync("package.json", "utf8")).version;
expect(version).toBe(versionPackage);
});
});