mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 03:39:55 +00:00
improve tests (#2923)
use es6 syntax in all tests, split weather tests, remove callbacks
This commit is contained in:
parent
7694d6fa86
commit
f04d578704
@ -15,6 +15,8 @@ _This release is scheduled to be released on 2023-01-01._
|
||||
|
||||
### Updated
|
||||
|
||||
- updated e2e tests (moved `done()` in helper functions) and use es6 syntax in all tests
|
||||
|
||||
### Fixed
|
||||
|
||||
## [2.21.0] - 2022-10-01
|
||||
|
@ -134,6 +134,7 @@
|
||||
"testPathIgnorePatterns": [
|
||||
"<rootDir>/tests/e2e/modules/mocks",
|
||||
"<rootDir>/tests/e2e/modules/basic-auth.js",
|
||||
"<rootDir>/tests/e2e/modules/weather-functions.js",
|
||||
"<rootDir>/tests/e2e/global-setup.js",
|
||||
"<rootDir>/tests/e2e/mock-console.js"
|
||||
]
|
||||
|
@ -3,7 +3,7 @@
|
||||
* By Rodrigo Ramírez Norambuena https://rodrigoramirez.com
|
||||
* MIT Licensed.
|
||||
*/
|
||||
exports.configFactory = function (options) {
|
||||
exports.configFactory = (options) => {
|
||||
return Object.assign(
|
||||
{
|
||||
electronOptions: {
|
||||
|
@ -6,7 +6,7 @@
|
||||
let config = {
|
||||
modules:
|
||||
// Using exotic content. This is why don't accept go to JSON configuration file
|
||||
(function () {
|
||||
(() => {
|
||||
let positions = ["top_bar", "top_left", "top_center", "top_right", "upper_third", "middle_center", "lower_third", "bottom_left", "bottom_center", "bottom_right", "bottom_bar", "fullscreen_above", "fullscreen_below"];
|
||||
let modules = Array();
|
||||
for (let idx in positions) {
|
||||
|
@ -1,34 +1,27 @@
|
||||
const fetch = require("fetch");
|
||||
const helpers = require("./global-setup");
|
||||
|
||||
describe("App environment", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/default.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
it("get request from http://localhost:8080 should return 200", (done) => {
|
||||
fetch("http://localhost:8080").then((res) => {
|
||||
done();
|
||||
it("get request from http://localhost:8080 should return 200", async () => {
|
||||
const res = await helpers.fetch("http://localhost:8080");
|
||||
expect(res.status).toBe(200);
|
||||
});
|
||||
});
|
||||
|
||||
it("get request from http://localhost:8080/nothing should return 404", (done) => {
|
||||
fetch("http://localhost:8080/nothing").then((res) => {
|
||||
done();
|
||||
it("get request from http://localhost:8080/nothing should return 404", async () => {
|
||||
const res = await helpers.fetch("http://localhost:8080/nothing");
|
||||
expect(res.status).toBe(404);
|
||||
});
|
||||
});
|
||||
|
||||
it("should show the title MagicMirror²", (done) => {
|
||||
helpers.waitForElement("title").then((elem) => {
|
||||
done();
|
||||
it("should show the title MagicMirror²", async () => {
|
||||
const elem = await helpers.waitForElement("title");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toBe("MagicMirror²");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,7 +1,6 @@
|
||||
const fetch = require("fetch");
|
||||
const helpers = require("./global-setup");
|
||||
|
||||
describe("All font files from roboto.css should be downloadable", function () {
|
||||
describe("All font files from roboto.css should be downloadable", () => {
|
||||
const fontFiles = [];
|
||||
// Statements below filters out all 'url' lines in the CSS file
|
||||
const fileContent = require("fs").readFileSync(__dirname + "/../../fonts/roboto.css", "utf8");
|
||||
@ -14,18 +13,16 @@ describe("All font files from roboto.css should be downloadable", function () {
|
||||
match = regex.exec(fileContent);
|
||||
}
|
||||
|
||||
beforeAll(function () {
|
||||
beforeAll(() => {
|
||||
helpers.startApplication("tests/configs/without_modules.js");
|
||||
});
|
||||
afterAll(async function () {
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
test.each(fontFiles)("should return 200 HTTP code for file '%s'", (fontFile, done) => {
|
||||
test.each(fontFiles)("should return 200 HTTP code for file '%s'", async (fontFile) => {
|
||||
const fontUrl = "http://localhost:8080/fonts/" + fontFile;
|
||||
fetch(fontUrl).then((res) => {
|
||||
const res = await helpers.fetch(fontUrl);
|
||||
expect(res.status).toBe(200);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,4 +1,5 @@
|
||||
const jsdom = require("jsdom");
|
||||
const corefetch = require("fetch");
|
||||
|
||||
exports.startApplication = (configFilename, exec) => {
|
||||
jest.resetModules();
|
||||
@ -21,15 +22,17 @@ exports.stopApplication = async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
};
|
||||
|
||||
exports.getDocument = (callback) => {
|
||||
exports.getDocument = () => {
|
||||
return new Promise((resolve) => {
|
||||
const url = "http://" + (config.address || "localhost") + ":" + (config.port || "8080");
|
||||
jsdom.JSDOM.fromURL(url, { resources: "usable", runScripts: "dangerously" }).then((dom) => {
|
||||
dom.window.name = "jsdom";
|
||||
dom.window.onload = () => {
|
||||
global.document = dom.window.document;
|
||||
callback();
|
||||
resolve();
|
||||
};
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
exports.waitForElement = (selector, ignoreValue = "") => {
|
||||
@ -71,3 +74,17 @@ exports.waitForAllElements = (selector) => {
|
||||
}, 100);
|
||||
});
|
||||
};
|
||||
|
||||
exports.fetch = (url) => {
|
||||
return new Promise((resolve) => {
|
||||
corefetch(url).then((res) => {
|
||||
resolve(res);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
exports.testMatch = async (element, regex) => {
|
||||
const elem = await this.waitForElement(element);
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toMatch(regex);
|
||||
};
|
||||
|
@ -1,36 +1,31 @@
|
||||
const fetch = require("fetch");
|
||||
const helpers = require("./global-setup");
|
||||
|
||||
describe("ipWhitelist directive configuration", function () {
|
||||
describe("Set ipWhitelist without access", function () {
|
||||
beforeAll(function () {
|
||||
describe("ipWhitelist directive configuration", () => {
|
||||
describe("Set ipWhitelist without access", () => {
|
||||
beforeAll(() => {
|
||||
helpers.startApplication("tests/configs/noIpWhiteList.js");
|
||||
});
|
||||
afterAll(async function () {
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
it("should return 403", function (done) {
|
||||
fetch("http://localhost:8080").then((res) => {
|
||||
it("should return 403", async () => {
|
||||
const res = await helpers.fetch("http://localhost:8080");
|
||||
expect(res.status).toBe(403);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Set ipWhitelist []", function () {
|
||||
beforeAll(function () {
|
||||
describe("Set ipWhitelist []", () => {
|
||||
beforeAll(() => {
|
||||
helpers.startApplication("tests/configs/empty_ipWhiteList.js");
|
||||
});
|
||||
afterAll(async function () {
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
it("should return 200", function (done) {
|
||||
fetch("http://localhost:8080").then((res) => {
|
||||
it("should return 200", async () => {
|
||||
const res = await helpers.fetch("http://localhost:8080");
|
||||
expect(res.status).toBe(200);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -3,13 +3,13 @@
|
||||
*
|
||||
* @param {string} err The error message.
|
||||
*/
|
||||
function mockError(err) {
|
||||
const mockError = (err) => {
|
||||
if (err.includes("ECONNREFUSED") || err.includes("ECONNRESET") || err.includes("socket hang up") || err.includes("exports is not defined") || err.includes("write EPIPE")) {
|
||||
jest.fn();
|
||||
} else {
|
||||
console.dir(err);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
global.console = {
|
||||
log: jest.fn(),
|
||||
|
@ -1,19 +1,17 @@
|
||||
const helpers = require("../global-setup");
|
||||
|
||||
describe("Alert module", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/alert/default.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
it("should show the welcome message", (done) => {
|
||||
helpers.waitForElement(".ns-box .ns-box-inner .light.bright.small").then((elem) => {
|
||||
done();
|
||||
it("should show the welcome message", async () => {
|
||||
const elem = await helpers.waitForElement(".ns-box .ns-box-inner .light.bright.small");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("Welcome, start was successful!");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -20,10 +20,10 @@ for (let directory of directories) {
|
||||
|
||||
let server;
|
||||
|
||||
exports.listen = function () {
|
||||
server = app.listen.apply(app, arguments);
|
||||
exports.listen = (...args) => {
|
||||
server = app.listen.apply(app, args);
|
||||
};
|
||||
|
||||
exports.close = function (callback) {
|
||||
server.close(callback);
|
||||
exports.close = async () => {
|
||||
await server.close();
|
||||
};
|
||||
|
@ -3,29 +3,24 @@ const serverBasicAuth = require("./basic-auth.js");
|
||||
|
||||
describe("Calendar module", () => {
|
||||
/**
|
||||
* @param {string} done test done
|
||||
* @param {string} element css selector
|
||||
* @param {string} result expected number
|
||||
* @param {string} not reverse result
|
||||
*/
|
||||
const testElementLength = (done, element, result, not) => {
|
||||
helpers.waitForAllElements(element).then((elem) => {
|
||||
done();
|
||||
const testElementLength = async (element, result, not) => {
|
||||
const elem = await helpers.waitForAllElements(element);
|
||||
expect(elem).not.toBe(null);
|
||||
if (not === "not") {
|
||||
expect(elem.length).not.toBe(result);
|
||||
} else {
|
||||
expect(elem.length).toBe(result);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
const testTextContain = (done, element, text) => {
|
||||
helpers.waitForElement(element, "undefinedLoading").then((elem) => {
|
||||
done();
|
||||
const testTextContain = async (element, text) => {
|
||||
const elem = await helpers.waitForElement(element, "undefinedLoading");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain(text);
|
||||
});
|
||||
};
|
||||
|
||||
afterAll(async () => {
|
||||
@ -33,133 +28,133 @@ describe("Calendar module", () => {
|
||||
});
|
||||
|
||||
describe("Default configuration", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/calendar/default.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should show the default maximumEntries of 10", (done) => {
|
||||
testElementLength(done, ".calendar .event", 10);
|
||||
it("should show the default maximumEntries of 10", async () => {
|
||||
await testElementLength(".calendar .event", 10);
|
||||
});
|
||||
|
||||
it("should show the default calendar symbol in each event", (done) => {
|
||||
testElementLength(done, ".calendar .event .fa-calendar-alt", 0, "not");
|
||||
it("should show the default calendar symbol in each event", async () => {
|
||||
await testElementLength(".calendar .event .fa-calendar-alt", 0, "not");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Custom configuration", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/calendar/custom.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should show the custom maximumEntries of 4", (done) => {
|
||||
testElementLength(done, ".calendar .event", 4);
|
||||
it("should show the custom maximumEntries of 4", async () => {
|
||||
await testElementLength(".calendar .event", 4);
|
||||
});
|
||||
|
||||
it("should show the custom calendar symbol in each event", (done) => {
|
||||
testElementLength(done, ".calendar .event .fa-birthday-cake", 4);
|
||||
it("should show the custom calendar symbol in each event", async () => {
|
||||
await testElementLength(".calendar .event .fa-birthday-cake", 4);
|
||||
});
|
||||
|
||||
it("should show two custom icons for repeating events", (done) => {
|
||||
testElementLength(done, ".calendar .event .fa-undo", 2);
|
||||
it("should show two custom icons for repeating events", async () => {
|
||||
await testElementLength(".calendar .event .fa-undo", 2);
|
||||
});
|
||||
|
||||
it("should show two custom icons for day events", (done) => {
|
||||
testElementLength(done, ".calendar .event .fa-calendar-day", 2);
|
||||
it("should show two custom icons for day events", async () => {
|
||||
await testElementLength(".calendar .event .fa-calendar-day", 2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Recurring event", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/calendar/recurring.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should show the recurring birthday event 6 times", (done) => {
|
||||
testElementLength(done, ".calendar .event", 6);
|
||||
it("should show the recurring birthday event 6 times", async () => {
|
||||
await testElementLength(".calendar .event", 6);
|
||||
});
|
||||
});
|
||||
|
||||
process.setMaxListeners(0);
|
||||
for (let i = -12; i < 12; i++) {
|
||||
describe("Recurring event per timezone", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
Date.prototype.getTimezoneOffset = () => {
|
||||
return i * 60;
|
||||
};
|
||||
helpers.startApplication("tests/configs/modules/calendar/recurring.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it('should contain text "Mar 25th" in timezone UTC ' + -i, (done) => {
|
||||
testTextContain(done, ".calendar", "Mar 25th");
|
||||
it('should contain text "Mar 25th" in timezone UTC ' + -i, async () => {
|
||||
await testTextContain(".calendar", "Mar 25th");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
describe("Changed port", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/calendar/changed-port.js");
|
||||
serverBasicAuth.listen(8010);
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
afterAll((done) => {
|
||||
serverBasicAuth.close(done());
|
||||
afterAll(async () => {
|
||||
await serverBasicAuth.close();
|
||||
});
|
||||
|
||||
it("should return TestEvents", (done) => {
|
||||
testElementLength(done, ".calendar .event", 0, "not");
|
||||
it("should return TestEvents", async () => {
|
||||
await testElementLength(".calendar .event", 0, "not");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Basic auth", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/calendar/basic-auth.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should return TestEvents", (done) => {
|
||||
testElementLength(done, ".calendar .event", 0, "not");
|
||||
it("should return TestEvents", async () => {
|
||||
await testElementLength(".calendar .event", 0, "not");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Basic auth by default", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/calendar/auth-default.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should return TestEvents", (done) => {
|
||||
testElementLength(done, ".calendar .event", 0, "not");
|
||||
it("should return TestEvents", async () => {
|
||||
await testElementLength(".calendar .event", 0, "not");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Basic auth backward compatibility configuration: DEPRECATED", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/calendar/old-basic-auth.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should return TestEvents", (done) => {
|
||||
testElementLength(done, ".calendar .event", 0, "not");
|
||||
it("should return TestEvents", async () => {
|
||||
await testElementLength(".calendar .event", 0, "not");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Fail Basic auth", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/calendar/fail-basic-auth.js");
|
||||
serverBasicAuth.listen(8020);
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
afterAll((done) => {
|
||||
serverBasicAuth.close(done());
|
||||
afterAll(async () => {
|
||||
await serverBasicAuth.close();
|
||||
});
|
||||
|
||||
it("should show Unauthorized error", (done) => {
|
||||
testTextContain(done, ".calendar", "Error in the calendar module. Authorization failed");
|
||||
it("should show Unauthorized error", async () => {
|
||||
await testTextContain(".calendar", "Error in the calendar module. Authorization failed");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -5,69 +5,61 @@ describe("Clock set to spanish language module", () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
const testMatch = (done, element, regex) => {
|
||||
helpers.waitForElement(element).then((elem) => {
|
||||
done();
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toMatch(regex);
|
||||
});
|
||||
};
|
||||
|
||||
describe("with default 24hr clock config", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/clock/es/clock_24hr.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("shows date with correct format", (done) => {
|
||||
it("shows date with correct format", async () => {
|
||||
const dateRegex = /^(?:lunes|martes|miércoles|jueves|viernes|sábado|domingo), \d{1,2} de (?:enero|febrero|marzo|abril|mayo|junio|julio|agosto|septiembre|octubre|noviembre|diciembre) de \d{4}$/;
|
||||
testMatch(done, ".clock .date", dateRegex);
|
||||
await helpers.testMatch(".clock .date", dateRegex);
|
||||
});
|
||||
|
||||
it("shows time in 24hr format", (done) => {
|
||||
it("shows time in 24hr format", async () => {
|
||||
const timeRegex = /^(?:2[0-3]|[01]\d):[0-5]\d[0-5]\d$/;
|
||||
testMatch(done, ".clock .time", timeRegex);
|
||||
await helpers.testMatch(".clock .time", timeRegex);
|
||||
});
|
||||
});
|
||||
|
||||
describe("with default 12hr clock config", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/clock/es/clock_12hr.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("shows date with correct format", (done) => {
|
||||
it("shows date with correct format", async () => {
|
||||
const dateRegex = /^(?:lunes|martes|miércoles|jueves|viernes|sábado|domingo), \d{1,2} de (?:enero|febrero|marzo|abril|mayo|junio|julio|agosto|septiembre|octubre|noviembre|diciembre) de \d{4}$/;
|
||||
testMatch(done, ".clock .date", dateRegex);
|
||||
await helpers.testMatch(".clock .date", dateRegex);
|
||||
});
|
||||
|
||||
it("shows time in 12hr format", (done) => {
|
||||
it("shows time in 12hr format", async () => {
|
||||
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[ap]m$/;
|
||||
testMatch(done, ".clock .time", timeRegex);
|
||||
await helpers.testMatch(".clock .time", timeRegex);
|
||||
});
|
||||
});
|
||||
|
||||
describe("with showPeriodUpper config enabled", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/clock/es/clock_showPeriodUpper.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("shows 12hr time with upper case AM/PM", (done) => {
|
||||
it("shows 12hr time with upper case AM/PM", async () => {
|
||||
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[AP]M$/;
|
||||
testMatch(done, ".clock .time", timeRegex);
|
||||
await helpers.testMatch(".clock .time", timeRegex);
|
||||
});
|
||||
});
|
||||
|
||||
describe("with showWeek config enabled", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/clock/es/clock_showWeek.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("shows week with correct format", (done) => {
|
||||
it("shows week with correct format", async () => {
|
||||
const weekRegex = /^Semana [0-9]{1,2}$/;
|
||||
testMatch(done, ".clock .week", weekRegex);
|
||||
await helpers.testMatch(".clock .week", weekRegex);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -6,118 +6,105 @@ describe("Clock module", () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
const testMatch = (done, element, regex) => {
|
||||
helpers.waitForElement(element).then((elem) => {
|
||||
done();
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toMatch(regex);
|
||||
});
|
||||
};
|
||||
|
||||
describe("with default 24hr clock config", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/clock/clock_24hr.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should show the date in the correct format", (done) => {
|
||||
it("should show the date in the correct format", async () => {
|
||||
const dateRegex = /^(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (?:January|February|March|April|May|June|July|August|September|October|November|December) \d{1,2}, \d{4}$/;
|
||||
testMatch(done, ".clock .date", dateRegex);
|
||||
await helpers.testMatch(".clock .date", dateRegex);
|
||||
});
|
||||
|
||||
it("should show the time in 24hr format", (done) => {
|
||||
it("should show the time in 24hr format", async () => {
|
||||
const timeRegex = /^(?:2[0-3]|[01]\d):[0-5]\d[0-5]\d$/;
|
||||
testMatch(done, ".clock .time", timeRegex);
|
||||
await helpers.testMatch(".clock .time", timeRegex);
|
||||
});
|
||||
});
|
||||
|
||||
describe("with default 12hr clock config", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/clock/clock_12hr.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should show the date in the correct format", (done) => {
|
||||
it("should show the date in the correct format", async () => {
|
||||
const dateRegex = /^(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (?:January|February|March|April|May|June|July|August|September|October|November|December) \d{1,2}, \d{4}$/;
|
||||
testMatch(done, ".clock .date", dateRegex);
|
||||
await helpers.testMatch(".clock .date", dateRegex);
|
||||
});
|
||||
|
||||
it("should show the time in 12hr format", (done) => {
|
||||
it("should show the time in 12hr format", async () => {
|
||||
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[ap]m$/;
|
||||
testMatch(done, ".clock .time", timeRegex);
|
||||
await helpers.testMatch(".clock .time", timeRegex);
|
||||
});
|
||||
});
|
||||
|
||||
describe("with showPeriodUpper config enabled", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/clock/clock_showPeriodUpper.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should show 12hr time with upper case AM/PM", (done) => {
|
||||
it("should show 12hr time with upper case AM/PM", async () => {
|
||||
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[AP]M$/;
|
||||
testMatch(done, ".clock .time", timeRegex);
|
||||
await helpers.testMatch(".clock .time", timeRegex);
|
||||
});
|
||||
});
|
||||
|
||||
describe("with displaySeconds config disabled", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/clock/clock_displaySeconds_false.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should show 12hr time without seconds am/pm", (done) => {
|
||||
it("should show 12hr time without seconds am/pm", async () => {
|
||||
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[ap]m$/;
|
||||
testMatch(done, ".clock .time", timeRegex);
|
||||
await helpers.testMatch(".clock .time", timeRegex);
|
||||
});
|
||||
});
|
||||
|
||||
describe("with showTime config disabled", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/clock/clock_showTime.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should not show the time when digital clock is shown", (done) => {
|
||||
const elem = document.querySelector(".clock .digital .time");
|
||||
done();
|
||||
it("should not show the time when digital clock is shown", async () => {
|
||||
const elem = await document.querySelector(".clock .digital .time");
|
||||
expect(elem).toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
describe("with showWeek config enabled", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/clock/clock_showWeek.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should show the week in the correct format", (done) => {
|
||||
it("should show the week in the correct format", async () => {
|
||||
const weekRegex = /^Week [0-9]{1,2}$/;
|
||||
testMatch(done, ".clock .week", weekRegex);
|
||||
await helpers.testMatch(".clock .week", weekRegex);
|
||||
});
|
||||
|
||||
it("should show the week with the correct number of week of year", (done) => {
|
||||
it("should show the week with the correct number of week of year", async () => {
|
||||
const currentWeekNumber = moment().week();
|
||||
const weekToShow = "Week " + currentWeekNumber;
|
||||
helpers.waitForElement(".clock .week").then((elem) => {
|
||||
done();
|
||||
const elem = await helpers.waitForElement(".clock .week");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toBe(weekToShow);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("with analog clock face enabled", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/clock/clock_analog.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should show the analog clock face", (done) => {
|
||||
helpers.waitForElement(".clockCircle").then((elem) => {
|
||||
done();
|
||||
it("should show the analog clock face", async () => {
|
||||
const elem = helpers.waitForElement(".clockCircle");
|
||||
expect(elem).not.toBe(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,97 +1,87 @@
|
||||
const helpers = require("../global-setup");
|
||||
|
||||
/**
|
||||
describe("Compliments module", () => {
|
||||
/**
|
||||
* move similar tests in function doTest
|
||||
*
|
||||
* @param {string} done test done
|
||||
* @param {Array} complimentsArray The array of compliments.
|
||||
*/
|
||||
const doTest = (done, complimentsArray) => {
|
||||
helpers.waitForElement(".compliments").then((elem) => {
|
||||
const doTest = async (complimentsArray) => {
|
||||
let elem = await helpers.waitForElement(".compliments");
|
||||
expect(elem).not.toBe(null);
|
||||
helpers.waitForElement(".module-content").then((elem) => {
|
||||
done();
|
||||
elem = await helpers.waitForElement(".module-content");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(complimentsArray).toContain(elem.textContent);
|
||||
});
|
||||
});
|
||||
};
|
||||
};
|
||||
|
||||
describe("Compliments module", () => {
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
describe("parts of days", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/compliments/compliments_parts_day.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("if Morning compliments for that part of day", (done) => {
|
||||
it("if Morning compliments for that part of day", async () => {
|
||||
const hour = new Date().getHours();
|
||||
if (hour >= 3 && hour < 12) {
|
||||
// if morning check
|
||||
doTest(done, ["Hi", "Good Morning", "Morning test"]);
|
||||
} else {
|
||||
done();
|
||||
await doTest(["Hi", "Good Morning", "Morning test"]);
|
||||
}
|
||||
});
|
||||
|
||||
it("if Afternoon show Compliments for that part of day", (done) => {
|
||||
it("if Afternoon show Compliments for that part of day", async () => {
|
||||
const hour = new Date().getHours();
|
||||
if (hour >= 12 && hour < 17) {
|
||||
// if afternoon check
|
||||
doTest(done, ["Hello", "Good Afternoon", "Afternoon test"]);
|
||||
} else {
|
||||
done();
|
||||
await doTest(["Hello", "Good Afternoon", "Afternoon test"]);
|
||||
}
|
||||
});
|
||||
|
||||
it("if Evening show Compliments for that part of day", (done) => {
|
||||
it("if Evening show Compliments for that part of day", async () => {
|
||||
const hour = new Date().getHours();
|
||||
if (!(hour >= 3 && hour < 12) && !(hour >= 12 && hour < 17)) {
|
||||
// if evening check
|
||||
doTest(done, ["Hello There", "Good Evening", "Evening test"]);
|
||||
} else {
|
||||
done();
|
||||
await doTest(["Hello There", "Good Evening", "Evening test"]);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("Feature anytime in compliments module", () => {
|
||||
describe("Set anytime and empty compliments for morning, evening and afternoon ", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/compliments/compliments_anytime.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("Show anytime because if configure empty parts of day compliments and set anytime compliments", (done) => {
|
||||
doTest(done, ["Anytime here"]);
|
||||
it("Show anytime because if configure empty parts of day compliments and set anytime compliments", async () => {
|
||||
await doTest(["Anytime here"]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Only anytime present in configuration compliments", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/compliments/compliments_only_anytime.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("Show anytime compliments", (done) => {
|
||||
doTest(done, ["Anytime here"]);
|
||||
it("Show anytime compliments", async () => {
|
||||
await doTest(["Anytime here"]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Feature date in compliments module", () => {
|
||||
describe("Set date and empty compliments for anytime, morning, evening and afternoon", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/compliments/compliments_date.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("Show happy new year compliment on new years day", (done) => {
|
||||
doTest(done, ["Happy new year!"]);
|
||||
it("Show happy new year compliment on new years day", async () => {
|
||||
await doTest(["Happy new year!"]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -6,32 +6,28 @@ describe("Test helloworld module", () => {
|
||||
});
|
||||
|
||||
describe("helloworld set config text", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/helloworld/helloworld.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("Test message helloworld module", (done) => {
|
||||
helpers.waitForElement(".helloworld").then((elem) => {
|
||||
done();
|
||||
it("Test message helloworld module", async () => {
|
||||
const elem = await helpers.waitForElement(".helloworld");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("Test HelloWorld Module");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("helloworld default config text", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/helloworld/helloworld_default.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("Test message helloworld module", (done) => {
|
||||
helpers.waitForElement(".helloworld").then((elem) => {
|
||||
done();
|
||||
it("Test message helloworld module", async () => {
|
||||
const elem = await helpers.waitForElement(".helloworld");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("Hello World!");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -4,7 +4,7 @@ const _ = require("lodash");
|
||||
* @param {object} extendedData extra data to add to the default mock data
|
||||
* @returns {string} mocked current weather data
|
||||
*/
|
||||
function generateWeather(extendedData = {}) {
|
||||
const generateWeather = (extendedData = {}) => {
|
||||
return JSON.stringify(
|
||||
_.merge(
|
||||
{},
|
||||
@ -59,6 +59,6 @@ function generateWeather(extendedData = {}) {
|
||||
extendedData
|
||||
)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = generateWeather;
|
||||
|
@ -4,7 +4,7 @@ const _ = require("lodash");
|
||||
* @param {object} extendedData extra data to add to the default mock data
|
||||
* @returns {string} mocked forecast weather data
|
||||
*/
|
||||
function generateWeatherForecast(extendedData = {}) {
|
||||
const generateWeatherForecast = (extendedData = {}) => {
|
||||
return JSON.stringify(
|
||||
_.merge(
|
||||
{},
|
||||
@ -110,6 +110,6 @@ function generateWeatherForecast(extendedData = {}) {
|
||||
extendedData
|
||||
)
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = generateWeatherForecast;
|
||||
|
@ -6,86 +6,72 @@ describe("Newsfeed module", () => {
|
||||
});
|
||||
|
||||
describe("Default configuration", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/newsfeed/default.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should show the newsfeed title", (done) => {
|
||||
helpers.waitForElement(".newsfeed .newsfeed-source").then((elem) => {
|
||||
done();
|
||||
it("should show the newsfeed title", async () => {
|
||||
const elem = await helpers.waitForElement(".newsfeed .newsfeed-source");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("Rodrigo Ramirez Blog");
|
||||
});
|
||||
});
|
||||
|
||||
it("should show the newsfeed article", (done) => {
|
||||
helpers.waitForElement(".newsfeed .newsfeed-title").then((elem) => {
|
||||
done();
|
||||
it("should show the newsfeed article", async () => {
|
||||
const elem = await helpers.waitForElement(".newsfeed .newsfeed-title");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("QPanel");
|
||||
});
|
||||
});
|
||||
|
||||
it("should NOT show the newsfeed description", (done) => {
|
||||
helpers.waitForElement(".newsfeed").then((elem) => {
|
||||
it("should NOT show the newsfeed description", async () => {
|
||||
await helpers.waitForElement(".newsfeed");
|
||||
const element = document.querySelector(".newsfeed .newsfeed-desc");
|
||||
done();
|
||||
expect(element).toBe(null);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Custom configuration", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/newsfeed/prohibited_words.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should not show articles with prohibited words", (done) => {
|
||||
helpers.waitForElement(".newsfeed .newsfeed-title").then((elem) => {
|
||||
done();
|
||||
it("should not show articles with prohibited words", async () => {
|
||||
const elem = await helpers.waitForElement(".newsfeed .newsfeed-title");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("Problema VirtualBox");
|
||||
});
|
||||
});
|
||||
|
||||
it("should show the newsfeed description", (done) => {
|
||||
helpers.waitForElement(".newsfeed .newsfeed-desc").then((elem) => {
|
||||
done();
|
||||
it("should show the newsfeed description", async () => {
|
||||
const elem = await helpers.waitForElement(".newsfeed .newsfeed-desc");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent.length).not.toBe(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Invalid configuration", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/newsfeed/incorrect_url.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should show malformed url warning", (done) => {
|
||||
helpers.waitForElement(".newsfeed .small", "No news at the moment.").then((elem) => {
|
||||
done();
|
||||
it("should show malformed url warning", async () => {
|
||||
const elem = await helpers.waitForElement(".newsfeed .small", "No news at the moment.");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("Error in the Newsfeed module. Malformed url.");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Ignore items", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/newsfeed/ignore_items.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
|
||||
it("should show empty items info message", (done) => {
|
||||
helpers.waitForElement(".newsfeed .small").then((elem) => {
|
||||
done();
|
||||
it("should show empty items info message", async () => {
|
||||
const elem = await helpers.waitForElement(".newsfeed .small");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("No news at the moment.");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
29
tests/e2e/modules/weather-functions.js
Normal file
29
tests/e2e/modules/weather-functions.js
Normal file
@ -0,0 +1,29 @@
|
||||
const helpers = require("../global-setup");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const { generateWeather, generateWeatherForecast } = require("./mocks");
|
||||
|
||||
exports.getText = async (element, result) => {
|
||||
const elem = await helpers.waitForElement(element);
|
||||
expect(elem).not.toBe(null);
|
||||
expect(
|
||||
elem.textContent
|
||||
.trim()
|
||||
.replace(/(\r\n|\n|\r)/gm, "")
|
||||
.replace(/[ ]+/g, " ")
|
||||
).toBe(result);
|
||||
};
|
||||
|
||||
exports.startApp = async (configFile, additionalMockData) => {
|
||||
let mockWeather;
|
||||
if (configFile.includes("forecast")) {
|
||||
mockWeather = generateWeatherForecast(additionalMockData);
|
||||
} else {
|
||||
mockWeather = generateWeather(additionalMockData);
|
||||
}
|
||||
let content = fs.readFileSync(path.resolve(__dirname + "../../../../" + configFile)).toString();
|
||||
content = content.replace("#####WEATHERDATA#####", mockWeather);
|
||||
fs.writeFileSync(path.resolve(__dirname + "../../../../config/config.js"), content);
|
||||
helpers.startApplication("");
|
||||
await helpers.getDocument();
|
||||
};
|
130
tests/e2e/modules/weather_current_spec.js
Normal file
130
tests/e2e/modules/weather_current_spec.js
Normal file
@ -0,0 +1,130 @@
|
||||
const moment = require("moment");
|
||||
const helpers = require("../global-setup");
|
||||
const weatherFunc = require("./weather-functions");
|
||||
|
||||
describe("Weather module", () => {
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
describe("Current weather", () => {
|
||||
describe("Default configuration", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApp("tests/configs/modules/weather/currentweather_default.js", {});
|
||||
});
|
||||
|
||||
it("should render wind speed and wind direction", async () => {
|
||||
await weatherFunc.getText(".weather .normal.medium span:nth-child(2)", "6 WSW"); // now "12"
|
||||
});
|
||||
|
||||
it("should render temperature with icon", async () => {
|
||||
await weatherFunc.getText(".weather .large.light span.bright", "1.5°"); // now "1°C"
|
||||
});
|
||||
|
||||
it("should render feels like temperature", async () => {
|
||||
await weatherFunc.getText(".weather .normal.medium.feelslike span.dimmed", "Feels like -5.6°"); // now "Feels like -6°C"
|
||||
});
|
||||
});
|
||||
|
||||
describe("Default configuration with sunrise", () => {
|
||||
beforeAll(async () => {
|
||||
const sunrise = moment().startOf("day").unix();
|
||||
const sunset = moment().startOf("day").unix();
|
||||
await weatherFunc.startApp("tests/configs/modules/weather/currentweather_default.js", { sys: { sunrise, sunset } });
|
||||
});
|
||||
|
||||
it("should render sunrise", async () => {
|
||||
await weatherFunc.getText(".weather .normal.medium span:nth-child(4)", "12:00 am");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Default configuration with sunset", () => {
|
||||
beforeAll(async () => {
|
||||
const sunrise = moment().startOf("day").unix();
|
||||
const sunset = moment().endOf("day").unix();
|
||||
await weatherFunc.startApp("tests/configs/modules/weather/currentweather_default.js", { sys: { sunrise, sunset } });
|
||||
});
|
||||
|
||||
it("should render sunset", async () => {
|
||||
await weatherFunc.getText(".weather .normal.medium span:nth-child(4)", "11:59 pm");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Compliments Integration", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApp("tests/configs/modules/weather/currentweather_compliments.js", {});
|
||||
});
|
||||
|
||||
it("should render a compliment based on the current weather", async () => {
|
||||
await weatherFunc.getText(".compliments .module-content span", "snow");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Configuration Options", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApp("tests/configs/modules/weather/currentweather_options.js", {});
|
||||
});
|
||||
|
||||
it("should render useBeaufort = false", async () => {
|
||||
await weatherFunc.getText(".weather .normal.medium span:nth-child(2)", "12");
|
||||
});
|
||||
|
||||
it("should render showWindDirectionAsArrow = true", async () => {
|
||||
const elem = await helpers.waitForElement(".weather .normal.medium sup i.fa-long-arrow-alt-up");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.outerHTML).toContain("transform:rotate(250deg);");
|
||||
});
|
||||
|
||||
it("should render showHumidity = true", async () => {
|
||||
await weatherFunc.getText(".weather .normal.medium span:nth-child(3)", "93.7");
|
||||
});
|
||||
|
||||
it("should render degreeLabel = true for temp", async () => {
|
||||
await weatherFunc.getText(".weather .large.light span.bright", "1°C");
|
||||
});
|
||||
|
||||
it("should render degreeLabel = true for feels like", async () => {
|
||||
await weatherFunc.getText(".weather .normal.medium.feelslike span.dimmed", "Feels like -6°C");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Current weather units", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApp("tests/configs/modules/weather/currentweather_units.js", {
|
||||
main: {
|
||||
temp: (1.49 * 9) / 5 + 32,
|
||||
temp_min: (1 * 9) / 5 + 32,
|
||||
temp_max: (2 * 9) / 5 + 32
|
||||
},
|
||||
wind: {
|
||||
speed: 11.8 * 2.23694
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("should render imperial units for wind", async () => {
|
||||
await weatherFunc.getText(".weather .normal.medium span:nth-child(2)", "6 WSW");
|
||||
});
|
||||
|
||||
it("should render imperial units for temp", async () => {
|
||||
await weatherFunc.getText(".weather .large.light span.bright", "34,7°");
|
||||
});
|
||||
|
||||
it("should render imperial units for feels like", async () => {
|
||||
await weatherFunc.getText(".weather .normal.medium.feelslike span.dimmed", "Feels like 22,0°");
|
||||
});
|
||||
|
||||
it("should render custom decimalSymbol = ',' for humidity", async () => {
|
||||
await weatherFunc.getText(".weather .normal.medium span:nth-child(3)", "93,7");
|
||||
});
|
||||
|
||||
it("should render custom decimalSymbol = ',' for temp", async () => {
|
||||
await weatherFunc.getText(".weather .large.light span.bright", "34,7°");
|
||||
});
|
||||
|
||||
it("should render custom decimalSymbol = ',' for feels like", async () => {
|
||||
await weatherFunc.getText(".weather .normal.medium.feelslike span.dimmed", "Feels like 22,0°");
|
||||
});
|
||||
});
|
||||
});
|
96
tests/e2e/modules/weather_forecast_spec.js
Normal file
96
tests/e2e/modules/weather_forecast_spec.js
Normal file
@ -0,0 +1,96 @@
|
||||
const helpers = require("../global-setup");
|
||||
const weatherFunc = require("./weather-functions");
|
||||
|
||||
describe("Weather module: Weather Forecast", () => {
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
describe("Default configuration", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApp("tests/configs/modules/weather/forecastweather_default.js", {});
|
||||
});
|
||||
|
||||
const days = ["Today", "Tomorrow", "Sun", "Mon", "Tue"];
|
||||
for (const [index, day] of days.entries()) {
|
||||
it("should render day " + day, async () => {
|
||||
await weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`, day);
|
||||
});
|
||||
}
|
||||
|
||||
const icons = ["day-cloudy", "rain", "day-sunny", "day-sunny", "day-sunny"];
|
||||
for (const [index, icon] of icons.entries()) {
|
||||
it("should render icon " + icon, async () => {
|
||||
const elem = await helpers.waitForElement(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(2) span.wi-${icon}`);
|
||||
expect(elem).not.toBe(null);
|
||||
});
|
||||
}
|
||||
|
||||
const maxTemps = ["24.4°", "21.0°", "22.9°", "23.4°", "20.6°"];
|
||||
for (const [index, temp] of maxTemps.entries()) {
|
||||
it("should render max temperature " + temp, async () => {
|
||||
await weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp);
|
||||
});
|
||||
}
|
||||
|
||||
const minTemps = ["15.3°", "13.6°", "13.8°", "13.9°", "10.9°"];
|
||||
for (const [index, temp] of minTemps.entries()) {
|
||||
it("should render min temperature " + temp, async () => {
|
||||
await weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(4)`, temp);
|
||||
});
|
||||
}
|
||||
|
||||
const opacities = [1, 1, 0.8, 0.5333333333333333, 0.2666666666666667];
|
||||
for (const [index, opacity] of opacities.entries()) {
|
||||
it("should render fading of rows with opacity=" + opacity, async () => {
|
||||
const elem = await helpers.waitForElement(`.weather table.small tr:nth-child(${index + 1})`);
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.outerHTML).toContain(`<tr style="opacity: ${opacity};">`);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe("Absolute configuration", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApp("tests/configs/modules/weather/forecastweather_absolute.js", {});
|
||||
});
|
||||
|
||||
const days = ["Fri", "Sat", "Sun", "Mon", "Tue"];
|
||||
for (const [index, day] of days.entries()) {
|
||||
it("should render day " + day, async () => {
|
||||
await weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`, day);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe("Configuration Options", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApp("tests/configs/modules/weather/forecastweather_options.js", {});
|
||||
});
|
||||
|
||||
it("should render custom table class", async () => {
|
||||
const elem = await helpers.waitForElement(".weather table.myTableClass");
|
||||
expect(elem).not.toBe(null);
|
||||
});
|
||||
|
||||
it("should render colored rows", async () => {
|
||||
const table = await helpers.waitForElement(".weather table.myTableClass");
|
||||
expect(table).not.toBe(null);
|
||||
expect(table.rows).not.toBe(null);
|
||||
expect(table.rows.length).toBe(5);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Forecast weather units", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherFunc.startApp("tests/configs/modules/weather/forecastweather_units.js", {});
|
||||
});
|
||||
|
||||
const temperatures = ["24_4°", "21_0°", "22_9°", "23_4°", "20_6°"];
|
||||
for (const [index, temp] of temperatures.entries()) {
|
||||
it("should render custom decimalSymbol = '_' for temp " + temp, async () => {
|
||||
await weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
@ -1,273 +0,0 @@
|
||||
const moment = require("moment");
|
||||
const helpers = require("../global-setup");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const { generateWeather, generateWeatherForecast } = require("./mocks");
|
||||
|
||||
describe("Weather module", () => {
|
||||
/**
|
||||
* @param {string} done test done
|
||||
* @param {string} element css selector
|
||||
* @param {string} result Expected text in given selector
|
||||
*/
|
||||
const getText = (done, element, result) => {
|
||||
helpers.waitForElement(element).then((elem) => {
|
||||
done();
|
||||
expect(elem).not.toBe(null);
|
||||
expect(
|
||||
elem.textContent
|
||||
.trim()
|
||||
.replace(/(\r\n|\n|\r)/gm, "")
|
||||
.replace(/[ ]+/g, " ")
|
||||
).toBe(result);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* @param {string} configFile path to configuration file
|
||||
* @param {string} additionalMockData special data for mocking
|
||||
* @param {string} callback callback
|
||||
*/
|
||||
const startApp = (configFile, additionalMockData, callback) => {
|
||||
let mockWeather;
|
||||
if (configFile.includes("forecast")) {
|
||||
mockWeather = generateWeatherForecast(additionalMockData);
|
||||
} else {
|
||||
mockWeather = generateWeather(additionalMockData);
|
||||
}
|
||||
let content = fs.readFileSync(path.resolve(__dirname + "../../../../" + configFile)).toString();
|
||||
content = content.replace("#####WEATHERDATA#####", mockWeather);
|
||||
fs.writeFileSync(path.resolve(__dirname + "../../../../config/config.js"), content);
|
||||
helpers.startApplication("");
|
||||
helpers.getDocument(callback);
|
||||
};
|
||||
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
describe("Current weather", () => {
|
||||
describe("Default configuration", () => {
|
||||
beforeAll((done) => {
|
||||
startApp("tests/configs/modules/weather/currentweather_default.js", {}, done);
|
||||
});
|
||||
|
||||
it("should render wind speed and wind direction", (done) => {
|
||||
getText(done, ".weather .normal.medium span:nth-child(2)", "6 WSW"); // now "12"
|
||||
});
|
||||
|
||||
it("should render temperature with icon", (done) => {
|
||||
getText(done, ".weather .large.light span.bright", "1.5°"); // now "1°C"
|
||||
});
|
||||
|
||||
it("should render feels like temperature", (done) => {
|
||||
getText(done, ".weather .normal.medium.feelslike span.dimmed", "Feels like -5.6°"); // now "Feels like -6°C"
|
||||
});
|
||||
});
|
||||
|
||||
describe("Default configuration with sunrise", () => {
|
||||
beforeAll((done) => {
|
||||
const sunrise = moment().startOf("day").unix();
|
||||
const sunset = moment().startOf("day").unix();
|
||||
startApp("tests/configs/modules/weather/currentweather_default.js", { sys: { sunrise, sunset } }, done);
|
||||
});
|
||||
|
||||
it("should render sunrise", (done) => {
|
||||
getText(done, ".weather .normal.medium span:nth-child(4)", "12:00 am");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Default configuration with sunset", () => {
|
||||
beforeAll((done) => {
|
||||
const sunrise = moment().startOf("day").unix();
|
||||
const sunset = moment().endOf("day").unix();
|
||||
startApp("tests/configs/modules/weather/currentweather_default.js", { sys: { sunrise, sunset } }, done);
|
||||
});
|
||||
|
||||
it("should render sunset", (done) => {
|
||||
getText(done, ".weather .normal.medium span:nth-child(4)", "11:59 pm");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Compliments Integration", () => {
|
||||
beforeAll((done) => {
|
||||
startApp("tests/configs/modules/weather/currentweather_compliments.js", {}, done);
|
||||
});
|
||||
|
||||
it("should render a compliment based on the current weather", (done) => {
|
||||
getText(done, ".compliments .module-content span", "snow");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Configuration Options", () => {
|
||||
beforeAll((done) => {
|
||||
startApp("tests/configs/modules/weather/currentweather_options.js", {}, done);
|
||||
});
|
||||
|
||||
it("should render useBeaufort = false", (done) => {
|
||||
getText(done, ".weather .normal.medium span:nth-child(2)", "12");
|
||||
});
|
||||
|
||||
it("should render showWindDirectionAsArrow = true", (done) => {
|
||||
helpers.waitForElement(".weather .normal.medium sup i.fa-long-arrow-alt-up").then((elem) => {
|
||||
done();
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.outerHTML).toContain("transform:rotate(250deg);");
|
||||
});
|
||||
});
|
||||
|
||||
it("should render showHumidity = true", (done) => {
|
||||
getText(done, ".weather .normal.medium span:nth-child(3)", "93.7");
|
||||
});
|
||||
|
||||
it("should render degreeLabel = true for temp", (done) => {
|
||||
getText(done, ".weather .large.light span.bright", "1°C");
|
||||
});
|
||||
|
||||
it("should render degreeLabel = true for feels like", (done) => {
|
||||
getText(done, ".weather .normal.medium.feelslike span.dimmed", "Feels like -6°C");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Current weather units", () => {
|
||||
beforeAll((done) => {
|
||||
startApp(
|
||||
"tests/configs/modules/weather/currentweather_units.js",
|
||||
{
|
||||
main: {
|
||||
temp: (1.49 * 9) / 5 + 32,
|
||||
temp_min: (1 * 9) / 5 + 32,
|
||||
temp_max: (2 * 9) / 5 + 32
|
||||
},
|
||||
wind: {
|
||||
speed: 11.8 * 2.23694
|
||||
}
|
||||
},
|
||||
done
|
||||
);
|
||||
});
|
||||
|
||||
it("should render imperial units for wind", (done) => {
|
||||
getText(done, ".weather .normal.medium span:nth-child(2)", "6 WSW");
|
||||
});
|
||||
|
||||
it("should render imperial units for temp", (done) => {
|
||||
getText(done, ".weather .large.light span.bright", "34,7°");
|
||||
});
|
||||
|
||||
it("should render imperial units for feels like", (done) => {
|
||||
getText(done, ".weather .normal.medium.feelslike span.dimmed", "Feels like 22,0°");
|
||||
});
|
||||
|
||||
it("should render custom decimalSymbol = ',' for humidity", (done) => {
|
||||
getText(done, ".weather .normal.medium span:nth-child(3)", "93,7");
|
||||
});
|
||||
|
||||
it("should render custom decimalSymbol = ',' for temp", (done) => {
|
||||
getText(done, ".weather .large.light span.bright", "34,7°");
|
||||
});
|
||||
|
||||
it("should render custom decimalSymbol = ',' for feels like", (done) => {
|
||||
getText(done, ".weather .normal.medium.feelslike span.dimmed", "Feels like 22,0°");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Weather Forecast", () => {
|
||||
describe("Default configuration", () => {
|
||||
beforeAll((done) => {
|
||||
startApp("tests/configs/modules/weather/forecastweather_default.js", {}, done);
|
||||
});
|
||||
|
||||
const days = ["Today", "Tomorrow", "Sun", "Mon", "Tue"];
|
||||
for (const [index, day] of days.entries()) {
|
||||
it("should render day " + day, (done) => {
|
||||
getText(done, `.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`, day);
|
||||
});
|
||||
}
|
||||
|
||||
const icons = ["day-cloudy", "rain", "day-sunny", "day-sunny", "day-sunny"];
|
||||
for (const [index, icon] of icons.entries()) {
|
||||
it("should render icon " + icon, (done) => {
|
||||
helpers.waitForElement(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(2) span.wi-${icon}`).then((elem) => {
|
||||
done();
|
||||
expect(elem).not.toBe(null);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
const maxTemps = ["24.4°", "21.0°", "22.9°", "23.4°", "20.6°"];
|
||||
for (const [index, temp] of maxTemps.entries()) {
|
||||
it("should render max temperature " + temp, (done) => {
|
||||
getText(done, `.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp);
|
||||
});
|
||||
}
|
||||
|
||||
const minTemps = ["15.3°", "13.6°", "13.8°", "13.9°", "10.9°"];
|
||||
for (const [index, temp] of minTemps.entries()) {
|
||||
it("should render min temperature " + temp, (done) => {
|
||||
getText(done, `.weather table.small tr:nth-child(${index + 1}) td:nth-child(4)`, temp);
|
||||
});
|
||||
}
|
||||
|
||||
const opacities = [1, 1, 0.8, 0.5333333333333333, 0.2666666666666667];
|
||||
for (const [index, opacity] of opacities.entries()) {
|
||||
it("should render fading of rows with opacity=" + opacity, (done) => {
|
||||
helpers.waitForElement(`.weather table.small tr:nth-child(${index + 1})`).then((elem) => {
|
||||
done();
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.outerHTML).toContain(`<tr style="opacity: ${opacity};">`);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe("Absolute configuration", () => {
|
||||
beforeAll((done) => {
|
||||
startApp("tests/configs/modules/weather/forecastweather_absolute.js", {}, done);
|
||||
});
|
||||
|
||||
const days = ["Fri", "Sat", "Sun", "Mon", "Tue"];
|
||||
for (const [index, day] of days.entries()) {
|
||||
it("should render day " + day, (done) => {
|
||||
getText(done, `.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`, day);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
describe("Configuration Options", () => {
|
||||
beforeAll((done) => {
|
||||
startApp("tests/configs/modules/weather/forecastweather_options.js", {}, done);
|
||||
});
|
||||
|
||||
it("should render custom table class", (done) => {
|
||||
helpers.waitForElement(".weather table.myTableClass").then((elem) => {
|
||||
done();
|
||||
expect(elem).not.toBe(null);
|
||||
});
|
||||
});
|
||||
|
||||
it("should render colored rows", (done) => {
|
||||
helpers.waitForElement(".weather table.myTableClass").then((table) => {
|
||||
done();
|
||||
expect(table).not.toBe(null);
|
||||
expect(table.rows).not.toBe(null);
|
||||
expect(table.rows.length).toBe(5);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Forecast weather units", () => {
|
||||
beforeAll((done) => {
|
||||
startApp("tests/configs/modules/weather/forecastweather_units.js", {}, done);
|
||||
});
|
||||
|
||||
const temperatures = ["24_4°", "21_0°", "22_9°", "23_4°", "20_6°"];
|
||||
for (const [index, temp] of temperatures.entries()) {
|
||||
it("should render custom decimalSymbol = '_' for temp " + temp, (done) => {
|
||||
getText(done, `.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
@ -1,28 +1,24 @@
|
||||
const helpers = require("./global-setup");
|
||||
|
||||
describe("Display of modules", () => {
|
||||
beforeAll(function (done) {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/display.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
it("should show the test header", (done) => {
|
||||
helpers.waitForElement("#module_0_helloworld .module-header").then((elem) => {
|
||||
done();
|
||||
it("should show the test header", async () => {
|
||||
const elem = await helpers.waitForElement("#module_0_helloworld .module-header");
|
||||
expect(elem).not.toBe(null);
|
||||
// textContent gibt hier lowercase zurück, das uppercase wird durch css realisiert, was daher nicht in textContent landet
|
||||
expect(elem.textContent).toBe("test_header");
|
||||
});
|
||||
});
|
||||
|
||||
it("should show no header if no header text is specified", (done) => {
|
||||
helpers.waitForElement("#module_1_helloworld .module-header").then((elem) => {
|
||||
done();
|
||||
it("should show no header if no header text is specified", async () => {
|
||||
const elem = await helpers.waitForElement("#module_1_helloworld .module-header");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toBe("undefined");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,9 +1,9 @@
|
||||
const helpers = require("./global-setup");
|
||||
|
||||
describe("Position of modules", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/modules/positions.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
@ -13,12 +13,10 @@ describe("Position of modules", () => {
|
||||
|
||||
for (const position of positions) {
|
||||
const className = position.replace("_", ".");
|
||||
it("should show text in " + position, (done) => {
|
||||
helpers.waitForElement("." + className).then((elem) => {
|
||||
done();
|
||||
it("should show text in " + position, async () => {
|
||||
const elem = await helpers.waitForElement("." + className);
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("Text in " + position);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@ -1,36 +1,31 @@
|
||||
const fetch = require("fetch");
|
||||
const helpers = require("./global-setup");
|
||||
|
||||
describe("port directive configuration", function () {
|
||||
describe("Set port 8090", function () {
|
||||
beforeAll(function () {
|
||||
describe("port directive configuration", () => {
|
||||
describe("Set port 8090", () => {
|
||||
beforeAll(() => {
|
||||
helpers.startApplication("tests/configs/port_8090.js");
|
||||
});
|
||||
afterAll(async function () {
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
it("should return 200", function (done) {
|
||||
fetch("http://localhost:8090").then((res) => {
|
||||
it("should return 200", async () => {
|
||||
const res = await helpers.fetch("http://localhost:8090");
|
||||
expect(res.status).toBe(200);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Set port 8100 on environment variable MM_PORT", function () {
|
||||
beforeAll(function () {
|
||||
describe("Set port 8100 on environment variable MM_PORT", () => {
|
||||
beforeAll(() => {
|
||||
helpers.startApplication("tests/configs/port_8090.js", (process.env.MM_PORT = 8100));
|
||||
});
|
||||
afterAll(async function () {
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
it("should return 200", function (done) {
|
||||
fetch("http://localhost:8100").then((res) => {
|
||||
it("should return 200", async () => {
|
||||
const res = await helpers.fetch("http://localhost:8100");
|
||||
expect(res.status).toBe(200);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -6,13 +6,13 @@ const { JSDOM } = require("jsdom");
|
||||
const express = require("express");
|
||||
const sinon = require("sinon");
|
||||
|
||||
describe("Translations", function () {
|
||||
describe("Translations", () => {
|
||||
let server;
|
||||
|
||||
beforeAll(function () {
|
||||
beforeAll(() => {
|
||||
const app = express();
|
||||
app.use(helmet());
|
||||
app.use(function (req, res, next) {
|
||||
app.use((req, res, next) => {
|
||||
res.header("Access-Control-Allow-Origin", "*");
|
||||
next();
|
||||
});
|
||||
@ -21,11 +21,11 @@ describe("Translations", function () {
|
||||
server = app.listen(3000);
|
||||
});
|
||||
|
||||
afterAll(function () {
|
||||
afterAll(() => {
|
||||
server.close();
|
||||
});
|
||||
|
||||
it("should have a translation file in the specified path", function () {
|
||||
it("should have a translation file in the specified path", () => {
|
||||
for (let language in translations) {
|
||||
const file = fs.statSync(translations[language]);
|
||||
expect(file.isFile()).toBe(true);
|
||||
@ -37,7 +37,7 @@ describe("Translations", function () {
|
||||
|
||||
beforeEach(() => {
|
||||
dom = new JSDOM(
|
||||
`<script>var Translator = {}; var Log = {log: function(){}}; var config = {language: 'de'};</script>\
|
||||
`<script>var Translator = {}; var Log = {log: () => {}}; var config = {language: 'de'};</script>\
|
||||
<script src="file://${path.join(__dirname, "..", "..", "js", "class.js")}"></script>\
|
||||
<script src="file://${path.join(__dirname, "..", "..", "js", "module.js")}"></script>`,
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
@ -45,7 +45,7 @@ describe("Translations", function () {
|
||||
});
|
||||
|
||||
it("should load translation file", (done) => {
|
||||
dom.window.onload = async function () {
|
||||
dom.window.onload = async () => {
|
||||
const { Translator, Module, config } = dom.window;
|
||||
config.language = "en";
|
||||
Translator.load = sinon.stub().callsFake((_m, _f, _fb, callback) => callback());
|
||||
@ -65,7 +65,7 @@ describe("Translations", function () {
|
||||
});
|
||||
|
||||
it("should load translation + fallback file", (done) => {
|
||||
dom.window.onload = async function () {
|
||||
dom.window.onload = async () => {
|
||||
const { Translator, Module } = dom.window;
|
||||
Translator.load = sinon.stub().callsFake((_m, _f, _fb, callback) => callback());
|
||||
|
||||
@ -85,7 +85,7 @@ describe("Translations", function () {
|
||||
});
|
||||
|
||||
it("should load translation fallback file", (done) => {
|
||||
dom.window.onload = async function () {
|
||||
dom.window.onload = async () => {
|
||||
const { Translator, Module, config } = dom.window;
|
||||
config.language = "--";
|
||||
Translator.load = sinon.stub().callsFake((_m, _f, _fb, callback) => callback());
|
||||
@ -105,7 +105,7 @@ describe("Translations", function () {
|
||||
});
|
||||
|
||||
it("should load no file", (done) => {
|
||||
dom.window.onload = async function () {
|
||||
dom.window.onload = async () => {
|
||||
const { Translator, Module } = dom.window;
|
||||
Translator.load = sinon.stub();
|
||||
|
||||
@ -130,18 +130,18 @@ describe("Translations", function () {
|
||||
}
|
||||
};
|
||||
|
||||
describe("Parsing language files through the Translator class", function () {
|
||||
describe("Parsing language files through the Translator class", () => {
|
||||
for (let language in translations) {
|
||||
it(`should parse ${language}`, function (done) {
|
||||
it(`should parse ${language}`, (done) => {
|
||||
const dom = new JSDOM(
|
||||
`<script>var translations = ${JSON.stringify(translations)}; var Log = {log: function(){}};</script>\
|
||||
`<script>var translations = ${JSON.stringify(translations)}; var Log = {log: () => {}};</script>\
|
||||
<script src="file://${path.join(__dirname, "..", "..", "js", "translator.js")}">`,
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
);
|
||||
dom.window.onload = function () {
|
||||
dom.window.onload = () => {
|
||||
const { Translator } = dom.window;
|
||||
|
||||
Translator.load(mmm, translations[language], false, function () {
|
||||
Translator.load(mmm, translations[language], false, () => {
|
||||
expect(typeof Translator.translations[mmm.name]).toBe("object");
|
||||
expect(Object.keys(Translator.translations[mmm.name]).length).toBeGreaterThanOrEqual(1);
|
||||
done();
|
||||
@ -151,27 +151,27 @@ describe("Translations", function () {
|
||||
}
|
||||
});
|
||||
|
||||
describe("Same keys", function () {
|
||||
describe("Same keys", () => {
|
||||
let base;
|
||||
let missing = [];
|
||||
|
||||
beforeAll(function (done) {
|
||||
beforeAll((done) => {
|
||||
const dom = new JSDOM(
|
||||
`<script>var translations = ${JSON.stringify(translations)}; var Log = {log: function(){}};</script>\
|
||||
`<script>var translations = ${JSON.stringify(translations)}; var Log = {log: () => {}};</script>\
|
||||
<script src="file://${path.join(__dirname, "..", "..", "js", "translator.js")}">`,
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
);
|
||||
dom.window.onload = function () {
|
||||
dom.window.onload = () => {
|
||||
const { Translator } = dom.window;
|
||||
|
||||
Translator.load(mmm, translations.de, false, function () {
|
||||
Translator.load(mmm, translations.de, false, () => {
|
||||
base = Object.keys(Translator.translations[mmm.name]).sort();
|
||||
done();
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
afterAll(function () {
|
||||
afterAll(() => {
|
||||
console.log(missing);
|
||||
});
|
||||
|
||||
@ -182,32 +182,32 @@ describe("Translations", function () {
|
||||
continue;
|
||||
}
|
||||
|
||||
describe(`Translation keys of ${language}`, function () {
|
||||
describe(`Translation keys of ${language}`, () => {
|
||||
let keys;
|
||||
|
||||
beforeAll(function (done) {
|
||||
beforeAll((done) => {
|
||||
const dom = new JSDOM(
|
||||
`<script>var translations = ${JSON.stringify(translations)}; var Log = {log: function(){}};</script>\
|
||||
`<script>var translations = ${JSON.stringify(translations)}; var Log = {log: () => {}};</script>\
|
||||
<script src="file://${path.join(__dirname, "..", "..", "js", "translator.js")}">`,
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
);
|
||||
dom.window.onload = function () {
|
||||
dom.window.onload = () => {
|
||||
const { Translator } = dom.window;
|
||||
|
||||
Translator.load(mmm, translations[language], false, function () {
|
||||
Translator.load(mmm, translations[language], false, () => {
|
||||
keys = Object.keys(Translator.translations[mmm.name]).sort();
|
||||
done();
|
||||
});
|
||||
};
|
||||
});
|
||||
|
||||
it(`${language} keys should be in base`, function () {
|
||||
keys.forEach(function (key) {
|
||||
it(`${language} keys should be in base`, () => {
|
||||
keys.forEach((key) => {
|
||||
expect(base.indexOf(key)).toBeGreaterThanOrEqual(0);
|
||||
});
|
||||
});
|
||||
|
||||
it(`${language} should contain all base keys`, function () {
|
||||
it(`${language} should contain all base keys`, () => {
|
||||
// TODO: when all translations are fixed, use
|
||||
// expect(keys).toEqual(base);
|
||||
// instead of the try-catch-block
|
||||
|
@ -1,34 +1,29 @@
|
||||
const fetch = require("fetch");
|
||||
const helpers = require("./global-setup");
|
||||
|
||||
describe("Vendors", function () {
|
||||
beforeAll(function () {
|
||||
describe("Vendors", () => {
|
||||
beforeAll(() => {
|
||||
helpers.startApplication("tests/configs/default.js");
|
||||
});
|
||||
afterAll(async function () {
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
describe("Get list vendors", function () {
|
||||
describe("Get list vendors", () => {
|
||||
const vendors = require(__dirname + "/../../vendor/vendor.js");
|
||||
|
||||
Object.keys(vendors).forEach((vendor) => {
|
||||
it(`should return 200 HTTP code for vendor "${vendor}"`, function (done) {
|
||||
it(`should return 200 HTTP code for vendor "${vendor}"`, async () => {
|
||||
const urlVendor = "http://localhost:8080/vendor/" + vendors[vendor];
|
||||
fetch(urlVendor).then((res) => {
|
||||
const res = await helpers.fetch(urlVendor);
|
||||
expect(res.status).toBe(200);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Object.keys(vendors).forEach((vendor) => {
|
||||
it(`should return 404 HTTP code for vendor https://localhost/"${vendor}"`, function (done) {
|
||||
it(`should return 404 HTTP code for vendor https://localhost/"${vendor}"`, async () => {
|
||||
const urlVendor = "http://localhost:8080/" + vendors[vendor];
|
||||
fetch(urlVendor).then((res) => {
|
||||
const res = await helpers.fetch(urlVendor);
|
||||
expect(res.status).toBe(404);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,27 +1,23 @@
|
||||
const helpers = require("./global-setup");
|
||||
|
||||
describe("Check configuration without modules", () => {
|
||||
beforeAll((done) => {
|
||||
beforeAll(async () => {
|
||||
helpers.startApplication("tests/configs/without_modules.js");
|
||||
helpers.getDocument(done);
|
||||
await helpers.getDocument();
|
||||
});
|
||||
afterAll(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
it("Show the message MagicMirror² title", (done) => {
|
||||
helpers.waitForElement("#module_1_helloworld .module-content").then((elem) => {
|
||||
done();
|
||||
it("Show the message MagicMirror² title", async () => {
|
||||
const elem = await helpers.waitForElement("#module_1_helloworld .module-content");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("MagicMirror²");
|
||||
});
|
||||
});
|
||||
|
||||
it("Show the text Michael's website", (done) => {
|
||||
helpers.waitForElement("#module_5_helloworld .module-content").then((elem) => {
|
||||
done();
|
||||
it("Show the text Michael's website", async () => {
|
||||
const elem = await helpers.waitForElement("#module_5_helloworld .module-content");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("www.michaelteeuw.nl");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -6,16 +6,16 @@ let electronApp = null;
|
||||
process.env.MM_CONFIG_FILE = "tests/configs/modules/display.js";
|
||||
jest.retryTimes(3);
|
||||
|
||||
describe("Electron app environment", function () {
|
||||
beforeEach(async function () {
|
||||
describe("Electron app environment", () => {
|
||||
beforeEach(async () => {
|
||||
electronApp = await electron.launch({ args: ["js/electron.js"] });
|
||||
});
|
||||
|
||||
afterEach(async function () {
|
||||
afterEach(async () => {
|
||||
await electronApp.close();
|
||||
});
|
||||
|
||||
it("should open browserwindow", async function () {
|
||||
it("should open browserwindow", async () => {
|
||||
expect(await electronApp.windows().length).toBe(1);
|
||||
const page = await electronApp.firstWindow();
|
||||
expect(await page.title()).toBe("MagicMirror²");
|
||||
@ -26,16 +26,16 @@ describe("Electron app environment", function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe("Development console tests", function () {
|
||||
beforeEach(async function () {
|
||||
describe("Development console tests", () => {
|
||||
beforeEach(async () => {
|
||||
electronApp = await electron.launch({ args: ["js/electron.js", "dev"] });
|
||||
});
|
||||
|
||||
afterEach(async function () {
|
||||
afterEach(async () => {
|
||||
await electronApp.close();
|
||||
});
|
||||
|
||||
it("should open browserwindow and dev console", async function () {
|
||||
it("should open browserwindow and dev console", async () => {
|
||||
const pageArray = await electronApp.windows();
|
||||
expect(pageArray.length).toBe(2);
|
||||
for (const page of pageArray) {
|
||||
|
@ -1,39 +1,39 @@
|
||||
const path = require("path");
|
||||
const { JSDOM } = require("jsdom");
|
||||
|
||||
describe("File js/class", function () {
|
||||
describe("Test function cloneObject", function () {
|
||||
describe("File js/class", () => {
|
||||
describe("Test function cloneObject", () => {
|
||||
let clone;
|
||||
let dom;
|
||||
|
||||
beforeAll(function (done) {
|
||||
beforeAll((done) => {
|
||||
dom = new JSDOM(
|
||||
`<script>var Log = {log: function() {}};</script>\
|
||||
`<script>var Log = {log: () => {}};</script>\
|
||||
<script src="file://${path.join(__dirname, "..", "..", "..", "js", "class.js")}">`,
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
);
|
||||
dom.window.onload = function () {
|
||||
dom.window.onload = () => {
|
||||
const { cloneObject } = dom.window;
|
||||
clone = cloneObject;
|
||||
done();
|
||||
};
|
||||
});
|
||||
|
||||
it("should clone object", function () {
|
||||
it("should clone object", () => {
|
||||
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 () {
|
||||
it("should clone array", () => {
|
||||
const expected = [1, null, undefined, "TEST"];
|
||||
const obj = clone(expected);
|
||||
expect(obj).toEqual(expected);
|
||||
expect(expected === obj).toBe(false);
|
||||
});
|
||||
|
||||
it("should clone number", function () {
|
||||
it("should clone number", () => {
|
||||
let expected = 1;
|
||||
let obj = clone(expected);
|
||||
expect(obj).toBe(expected);
|
||||
@ -43,25 +43,25 @@ describe("File js/class", function () {
|
||||
expect(obj).toBe(expected);
|
||||
});
|
||||
|
||||
it("should clone string", function () {
|
||||
it("should clone string", () => {
|
||||
const expected = "Perfect stranger";
|
||||
const obj = clone(expected);
|
||||
expect(obj).toBe(expected);
|
||||
});
|
||||
|
||||
it("should clone undefined", function () {
|
||||
it("should clone undefined", () => {
|
||||
const expected = undefined;
|
||||
const obj = clone(expected);
|
||||
expect(obj).toBe(expected);
|
||||
});
|
||||
|
||||
it("should clone null", function () {
|
||||
it("should clone null", () => {
|
||||
const expected = null;
|
||||
const obj = clone(expected);
|
||||
expect(obj).toBe(expected);
|
||||
});
|
||||
|
||||
it("should clone nested object", function () {
|
||||
it("should clone nested object", () => {
|
||||
const expected = {
|
||||
name: "fewieden",
|
||||
link: "https://github.com/fewieden",
|
||||
@ -83,21 +83,21 @@ describe("File js/class", function () {
|
||||
expect(expected.properties.items[1] === obj.properties.items[1]).toBe(false);
|
||||
});
|
||||
|
||||
describe("Test lockstring code", function () {
|
||||
describe("Test lockstring code", () => {
|
||||
let log;
|
||||
|
||||
beforeAll(function () {
|
||||
beforeAll(() => {
|
||||
log = dom.window.Log.log;
|
||||
dom.window.Log.log = function cmp(str) {
|
||||
dom.window.Log.log = (str) => {
|
||||
expect(str).toBe("lockStrings");
|
||||
};
|
||||
});
|
||||
|
||||
afterAll(function () {
|
||||
afterAll(() => {
|
||||
dom.window.Log.log = log;
|
||||
});
|
||||
|
||||
it("should clone object and log lockStrings", function () {
|
||||
it("should clone object and log lockStrings", () => {
|
||||
const expected = { name: "Module", lockStrings: "stringLock" };
|
||||
const obj = clone(expected);
|
||||
expect(obj).toEqual(expected);
|
||||
|
@ -1,11 +1,11 @@
|
||||
const deprecated = require("../../../js/deprecated");
|
||||
|
||||
describe("Deprecated", function () {
|
||||
it("should be an object", function () {
|
||||
describe("Deprecated", () => {
|
||||
it("should be an object", () => {
|
||||
expect(typeof deprecated).toBe("object");
|
||||
});
|
||||
|
||||
it("should contain configs array with deprecated options as strings", function () {
|
||||
it("should contain configs array with deprecated options as strings", () => {
|
||||
expect(Array.isArray(["deprecated.configs"])).toBe(true);
|
||||
for (let option of deprecated.configs) {
|
||||
expect(typeof option).toBe("string");
|
||||
|
@ -4,13 +4,13 @@ const { JSDOM } = require("jsdom");
|
||||
const express = require("express");
|
||||
const sockets = new Set();
|
||||
|
||||
describe("Translator", function () {
|
||||
describe("Translator", () => {
|
||||
let server;
|
||||
|
||||
beforeAll(function () {
|
||||
beforeAll(() => {
|
||||
const app = express();
|
||||
app.use(helmet());
|
||||
app.use(function (req, res, next) {
|
||||
app.use((req, res, next) => {
|
||||
res.header("Access-Control-Allow-Origin", "*");
|
||||
next();
|
||||
});
|
||||
@ -23,7 +23,7 @@ describe("Translator", function () {
|
||||
});
|
||||
});
|
||||
|
||||
afterAll(function () {
|
||||
afterAll(() => {
|
||||
for (const socket of sockets) {
|
||||
socket.destroy();
|
||||
|
||||
@ -33,7 +33,7 @@ describe("Translator", function () {
|
||||
server.close();
|
||||
});
|
||||
|
||||
describe("translate", function () {
|
||||
describe("translate", () => {
|
||||
const translations = {
|
||||
"MMM-Module": {
|
||||
Hello: "Hallo",
|
||||
@ -70,16 +70,16 @@ describe("Translator", function () {
|
||||
/**
|
||||
* @param {object} Translator the global Translator object
|
||||
*/
|
||||
function setTranslations(Translator) {
|
||||
const setTranslations = (Translator) => {
|
||||
Translator.translations = translations;
|
||||
Translator.coreTranslations = coreTranslations;
|
||||
Translator.translationsFallback = translationsFallback;
|
||||
Translator.coreTranslationsFallback = coreTranslationsFallback;
|
||||
}
|
||||
};
|
||||
|
||||
it("should return custom module translation", function (done) {
|
||||
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 = function () {
|
||||
dom.window.onload = () => {
|
||||
const { Translator } = dom.window;
|
||||
setTranslations(Translator);
|
||||
let translation = Translator.translate({ name: "MMM-Module" }, "Hello");
|
||||
@ -90,9 +90,9 @@ describe("Translator", function () {
|
||||
};
|
||||
});
|
||||
|
||||
it("should return core translation", function (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 = function () {
|
||||
dom.window.onload = () => {
|
||||
const { Translator } = dom.window;
|
||||
setTranslations(Translator);
|
||||
let translation = Translator.translate({ name: "MMM-Module" }, "FOO");
|
||||
@ -103,9 +103,9 @@ describe("Translator", function () {
|
||||
};
|
||||
});
|
||||
|
||||
it("should return custom module translation fallback", function (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 = function () {
|
||||
dom.window.onload = () => {
|
||||
const { Translator } = dom.window;
|
||||
setTranslations(Translator);
|
||||
const translation = Translator.translate({ name: "MMM-Module" }, "A key");
|
||||
@ -114,9 +114,9 @@ describe("Translator", function () {
|
||||
};
|
||||
});
|
||||
|
||||
it("should return core translation fallback", function (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 = function () {
|
||||
dom.window.onload = () => {
|
||||
const { Translator } = dom.window;
|
||||
setTranslations(Translator);
|
||||
const translation = Translator.translate({ name: "MMM-Module" }, "Fallback");
|
||||
@ -125,9 +125,9 @@ describe("Translator", function () {
|
||||
};
|
||||
});
|
||||
|
||||
it("should return translation with placeholder for missing variables", function (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 = function () {
|
||||
dom.window.onload = () => {
|
||||
const { Translator } = dom.window;
|
||||
setTranslations(Translator);
|
||||
const translation = Translator.translate({ name: "MMM-Module" }, "Hello {username}");
|
||||
@ -136,9 +136,9 @@ describe("Translator", function () {
|
||||
};
|
||||
});
|
||||
|
||||
it("should return key if no translation was found", function (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 = function () {
|
||||
dom.window.onload = () => {
|
||||
const { Translator } = dom.window;
|
||||
setTranslations(Translator);
|
||||
const translation = Translator.translate({ name: "MMM-Module" }, "MISSING");
|
||||
@ -148,7 +148,7 @@ describe("Translator", function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe("load", function () {
|
||||
describe("load", () => {
|
||||
const mmm = {
|
||||
name: "TranslationTest",
|
||||
file(file) {
|
||||
@ -156,13 +156,13 @@ describe("Translator", function () {
|
||||
}
|
||||
};
|
||||
|
||||
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 () {
|
||||
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 = () => {
|
||||
const { Translator } = dom.window;
|
||||
const file = "TranslationTest.json";
|
||||
|
||||
Translator.load(mmm, file, false, function () {
|
||||
Translator.load(mmm, file, false, () => {
|
||||
const json = require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", file));
|
||||
expect(Translator.translations[mmm.name]).toEqual(json);
|
||||
done();
|
||||
@ -170,13 +170,13 @@ describe("Translator", function () {
|
||||
};
|
||||
});
|
||||
|
||||
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 () {
|
||||
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 = () => {
|
||||
const { Translator } = dom.window;
|
||||
const file = "TranslationTest.json";
|
||||
|
||||
Translator.load(mmm, file, true, function () {
|
||||
Translator.load(mmm, file, true, () => {
|
||||
const json = require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", file));
|
||||
expect(Translator.translationsFallback[mmm.name]).toEqual(json);
|
||||
done();
|
||||
@ -184,13 +184,13 @@ describe("Translator", function () {
|
||||
};
|
||||
});
|
||||
|
||||
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 () {
|
||||
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 = () => {
|
||||
const { Translator, XMLHttpRequest } = dom.window;
|
||||
const file = "TranslationTest.json";
|
||||
|
||||
XMLHttpRequest.prototype.send = function () {
|
||||
XMLHttpRequest.prototype.send = () => {
|
||||
throw "Shouldn't load files";
|
||||
};
|
||||
|
||||
@ -198,7 +198,7 @@ describe("Translator", function () {
|
||||
Hello: "Hallo"
|
||||
};
|
||||
|
||||
Translator.load(mmm, file, false, function () {
|
||||
Translator.load(mmm, file, false, () => {
|
||||
expect(Translator.translations[mmm.name]).toBe(undefined);
|
||||
expect(Translator.translationsFallback[mmm.name]).toEqual({
|
||||
Hello: "Hallo"
|
||||
@ -209,19 +209,19 @@ describe("Translator", function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe("loadCoreTranslations", function () {
|
||||
it("should load core translations and fallback", function (done) {
|
||||
describe("loadCoreTranslations", () => {
|
||||
it("should load core translations and fallback", (done) => {
|
||||
const dom = new JSDOM(
|
||||
`<script>var translations = {en: "http://localhost:3000/translations/en.json"}; var Log = {log: function(){}};</script>\
|
||||
`<script>var translations = {en: "http://localhost:3000/translations/en.json"}; var Log = {log: () => {}};</script>\
|
||||
<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`,
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
);
|
||||
dom.window.onload = function () {
|
||||
dom.window.onload = () => {
|
||||
const { Translator } = dom.window;
|
||||
Translator.loadCoreTranslations("en");
|
||||
|
||||
const en = require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", "en.json"));
|
||||
setTimeout(function () {
|
||||
setTimeout(() => {
|
||||
expect(Translator.coreTranslations).toEqual(en);
|
||||
expect(Translator.coreTranslationsFallback).toEqual(en);
|
||||
done();
|
||||
@ -229,18 +229,18 @@ describe("Translator", function () {
|
||||
};
|
||||
});
|
||||
|
||||
it("should load core fallback if language cannot be found", function (done) {
|
||||
it("should load core fallback if language cannot be found", (done) => {
|
||||
const dom = new JSDOM(
|
||||
`<script>var translations = {en: "http://localhost:3000/translations/en.json"}; var Log = {log: function(){}};</script>\
|
||||
`<script>var translations = {en: "http://localhost:3000/translations/en.json"}; var Log = {log: () => {}};</script>\
|
||||
<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`,
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
);
|
||||
dom.window.onload = function () {
|
||||
dom.window.onload = () => {
|
||||
const { Translator } = dom.window;
|
||||
Translator.loadCoreTranslations("MISSINGLANG");
|
||||
|
||||
const en = require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", "en.json"));
|
||||
setTimeout(function () {
|
||||
setTimeout(() => {
|
||||
expect(Translator.coreTranslations).toEqual({});
|
||||
expect(Translator.coreTranslationsFallback).toEqual(en);
|
||||
done();
|
||||
@ -249,36 +249,36 @@ describe("Translator", function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe("loadCoreTranslationsFallback", function () {
|
||||
it("should load core translations fallback", function (done) {
|
||||
describe("loadCoreTranslationsFallback", () => {
|
||||
it("should load core translations fallback", (done) => {
|
||||
const dom = new JSDOM(
|
||||
`<script>var translations = {en: "http://localhost:3000/translations/en.json"}; var Log = {log: function(){}};</script>\
|
||||
`<script>var translations = {en: "http://localhost:3000/translations/en.json"}; var Log = {log: () => {}};</script>\
|
||||
<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`,
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
);
|
||||
dom.window.onload = function () {
|
||||
dom.window.onload = () => {
|
||||
const { Translator } = dom.window;
|
||||
Translator.loadCoreTranslationsFallback();
|
||||
|
||||
const en = require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", "en.json"));
|
||||
setTimeout(function () {
|
||||
setTimeout(() => {
|
||||
expect(Translator.coreTranslationsFallback).toEqual(en);
|
||||
done();
|
||||
}, 500);
|
||||
};
|
||||
});
|
||||
|
||||
it("should load core fallback if language cannot be found", function (done) {
|
||||
it("should load core fallback if language cannot be found", (done) => {
|
||||
const dom = new JSDOM(
|
||||
`<script>var translations = {}; var Log = {log: function(){}};</script>\
|
||||
`<script>var translations = {}; var Log = {log: () => {}};</script>\
|
||||
<script src="file://${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`,
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
);
|
||||
dom.window.onload = function () {
|
||||
dom.window.onload = () => {
|
||||
const { Translator } = dom.window;
|
||||
Translator.loadCoreTranslations();
|
||||
|
||||
setTimeout(function () {
|
||||
setTimeout(() => {
|
||||
expect(Translator.coreTranslationsFallback).toEqual({});
|
||||
done();
|
||||
}, 500);
|
||||
|
@ -1,34 +1,34 @@
|
||||
const Utils = require("../../../js/utils.js");
|
||||
const colors = require("colors/safe");
|
||||
|
||||
describe("Utils", function () {
|
||||
describe("colors", function () {
|
||||
describe("Utils", () => {
|
||||
describe("colors", () => {
|
||||
const colorsEnabled = colors.enabled;
|
||||
|
||||
afterEach(function () {
|
||||
afterEach(() => {
|
||||
colors.enabled = colorsEnabled;
|
||||
});
|
||||
|
||||
it("should have info, warn and error properties", function () {
|
||||
it("should have info, warn and error properties", () => {
|
||||
expect(Utils.colors).toHaveProperty("info");
|
||||
expect(Utils.colors).toHaveProperty("warn");
|
||||
expect(Utils.colors).toHaveProperty("error");
|
||||
});
|
||||
|
||||
it("properties should be functions", function () {
|
||||
it("properties should be functions", () => {
|
||||
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 () {
|
||||
it("should print colored message in supported consoles", () => {
|
||||
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 () {
|
||||
it("should print message in unsupported consoles", () => {
|
||||
colors.enabled = false;
|
||||
expect(Utils.colors.info("some informations")).toBe("some informations");
|
||||
expect(Utils.colors.warn("a warning")).toBe("a warning");
|
||||
|
@ -1,19 +1,19 @@
|
||||
global.moment = require("moment");
|
||||
|
||||
describe("Functions into modules/default/calendar/calendar.js", function () {
|
||||
describe("Functions into modules/default/calendar/calendar.js", () => {
|
||||
// Fake for use by calendar.js
|
||||
Module = {};
|
||||
Module.definitions = {};
|
||||
Module.register = function (name, moduleDefinition) {
|
||||
Module.register = (name, moduleDefinition) => {
|
||||
Module.definitions[name] = moduleDefinition;
|
||||
};
|
||||
|
||||
beforeAll(function () {
|
||||
beforeAll(() => {
|
||||
// load calendar.js
|
||||
require("../../../modules/default/calendar/calendar.js");
|
||||
});
|
||||
|
||||
describe("capFirst", function () {
|
||||
describe("capFirst", () => {
|
||||
const words = {
|
||||
rodrigo: "Rodrigo",
|
||||
"123m": "123m",
|
||||
@ -23,61 +23,61 @@ describe("Functions into modules/default/calendar/calendar.js", function () {
|
||||
};
|
||||
|
||||
Object.keys(words).forEach((word) => {
|
||||
it(`for '${word}' should return '${words[word]}'`, function () {
|
||||
it(`for '${word}' should return '${words[word]}'`, () => {
|
||||
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 () {
|
||||
describe("getLocaleSpecification", () => {
|
||||
it("should return a valid moment.LocaleSpecification for a 12-hour format", () => {
|
||||
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 () {
|
||||
it("should return a valid moment.LocaleSpecification for a 24-hour format", () => {
|
||||
expect(Module.definitions.calendar.getLocaleSpecification(24)).toEqual({ 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", () => {
|
||||
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 () {
|
||||
it("should return a 12-hour longDateFormat when using the 'en' locale", () => {
|
||||
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 () {
|
||||
it("should return a 12-hour longDateFormat when using the 'au' locale", () => {
|
||||
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 () {
|
||||
it("should return a 12-hour longDateFormat when using the 'eg' locale", () => {
|
||||
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 () {
|
||||
it("should return a 24-hour longDateFormat when using the 'nl' locale", () => {
|
||||
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 () {
|
||||
it("should return a 24-hour longDateFormat when using the 'fr' locale", () => {
|
||||
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 () {
|
||||
it("should return a 24-hour longDateFormat when using the 'uk' locale", () => {
|
||||
const localeBackup = moment.locale();
|
||||
moment.locale("uk");
|
||||
expect(Module.definitions.calendar.getLocaleSpecification()).toEqual({ longDateFormat: { LT: "HH:mm" } });
|
||||
@ -85,7 +85,7 @@ describe("Functions into modules/default/calendar/calendar.js", function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe("shorten", function () {
|
||||
describe("shorten", () => {
|
||||
const strings = {
|
||||
" String with whitespace at the beginning that needs trimming": { length: 16, return: "String with whit…" },
|
||||
"long string that needs shortening": { length: 16, return: "long string that…" },
|
||||
@ -94,32 +94,32 @@ describe("Functions into modules/default/calendar/calendar.js", function () {
|
||||
};
|
||||
|
||||
Object.keys(strings).forEach((string) => {
|
||||
it(`for '${string}' should return '${strings[string].return}'`, function () {
|
||||
it(`for '${string}' should return '${strings[string].return}'`, () => {
|
||||
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 () {
|
||||
it("should return an empty string if shorten is called with a non-string", () => {
|
||||
expect(Module.definitions.calendar.shorten(100)).toBe("");
|
||||
});
|
||||
|
||||
it("should not shorten the string if shorten is called with a non-number maxLength", function () {
|
||||
it("should not shorten the string if shorten is called with a non-number maxLength", () => {
|
||||
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 () {
|
||||
it("should wrap the string instead of shorten it if shorten is called with wrapEvents = true (with maxLength defined as 20)", () => {
|
||||
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 () {
|
||||
it("should wrap the string instead of shorten it if shorten is called with wrapEvents = true (without maxLength defined, default 25)", () => {
|
||||
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 () {
|
||||
it("should wrap and shorten the string in the second line if called with wrapEvents = true and maxTitleLines = 2", () => {
|
||||
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 …"
|
||||
);
|
||||
|
@ -1,31 +1,31 @@
|
||||
const path = require("path");
|
||||
const { JSDOM } = require("jsdom");
|
||||
|
||||
describe("Test function cmpVersions in js/module.js", function () {
|
||||
describe("Test function cmpVersions in js/module.js", () => {
|
||||
let cmp;
|
||||
|
||||
beforeAll(function (done) {
|
||||
beforeAll((done) => {
|
||||
const dom = new JSDOM(
|
||||
`<script>var Class = {extend: function() { return {}; }};</script>\
|
||||
`<script>var Class = {extend: () => { return {}; }};</script>\
|
||||
<script src="file://${path.join(__dirname, "..", "..", "..", "js", "module.js")}">`,
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
);
|
||||
dom.window.onload = function () {
|
||||
dom.window.onload = () => {
|
||||
const { cmpVersions } = dom.window;
|
||||
cmp = cmpVersions;
|
||||
done();
|
||||
};
|
||||
});
|
||||
|
||||
it("should return -1 when comparing 2.1 to 2.2", function () {
|
||||
it("should return -1 when comparing 2.1 to 2.2", () => {
|
||||
expect(cmp("2.1", "2.2")).toBe(-1);
|
||||
});
|
||||
|
||||
it("should be return 0 when comparing 2.2 to 2.2", function () {
|
||||
it("should be return 0 when comparing 2.2 to 2.2", () => {
|
||||
expect(cmp("2.2", "2.2")).toBe(0);
|
||||
});
|
||||
|
||||
it("should be return 1 when comparing 1.1 to 1.0", function () {
|
||||
it("should be return 1 when comparing 1.1 to 1.0", () => {
|
||||
expect(cmp("1.1", "1.0")).toBe(1);
|
||||
});
|
||||
});
|
||||
|
@ -1,12 +1,12 @@
|
||||
describe("Functions into modules/default/newsfeed/newsfeed.js", function () {
|
||||
describe("Functions into modules/default/newsfeed/newsfeed.js", () => {
|
||||
// Fake for use by newsletter.js
|
||||
Module = {};
|
||||
Module.definitions = {};
|
||||
Module.register = function (name, moduleDefinition) {
|
||||
Module.register = (name, moduleDefinition) => {
|
||||
Module.definitions[name] = moduleDefinition;
|
||||
};
|
||||
|
||||
beforeAll(function () {
|
||||
beforeAll(() => {
|
||||
// load newsfeed.js
|
||||
require("../../../modules/default/newsfeed/newsfeed.js");
|
||||
});
|
||||
|
@ -14,7 +14,7 @@ jest.mock("logger", () => ({
|
||||
info: jest.fn()
|
||||
}));
|
||||
|
||||
describe("Updatenotification", function () {
|
||||
describe("Updatenotification", () => {
|
||||
const execMock = jest.fn();
|
||||
|
||||
let gitHelper;
|
||||
@ -30,7 +30,7 @@ describe("Updatenotification", function () {
|
||||
let gitFetchErr;
|
||||
let gitRevListErr;
|
||||
|
||||
beforeAll(async function () {
|
||||
beforeAll(async () => {
|
||||
const { promisify } = require("util");
|
||||
promisify.mockReturnValue(execMock);
|
||||
|
||||
@ -38,7 +38,7 @@ describe("Updatenotification", function () {
|
||||
gitHelper = new GitHelper();
|
||||
});
|
||||
|
||||
beforeEach(function () {
|
||||
beforeEach(() => {
|
||||
gitRemoteOut = "";
|
||||
gitRevParseOut = "";
|
||||
gitStatusOut = "";
|
||||
@ -50,7 +50,7 @@ describe("Updatenotification", function () {
|
||||
gitFetchErr = "";
|
||||
gitRevListErr = "";
|
||||
|
||||
execMock.mockImplementation(function (command) {
|
||||
execMock.mockImplementation((command) => {
|
||||
if (command.includes("git remote -v")) {
|
||||
return { stdout: gitRemoteOut, stderr: gitRemoteErr };
|
||||
} else if (command.includes("git rev-parse HEAD")) {
|
||||
@ -65,7 +65,7 @@ describe("Updatenotification", function () {
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(async function () {
|
||||
afterEach(async () => {
|
||||
gitHelper.gitRepos = [];
|
||||
|
||||
jest.clearAllMocks();
|
||||
@ -74,7 +74,7 @@ describe("Updatenotification", function () {
|
||||
describe("default", () => {
|
||||
const moduleName = "default";
|
||||
|
||||
beforeEach(async function () {
|
||||
beforeEach(async () => {
|
||||
gitRemoteOut = "origin\tgit@github.com:MichMich/MagicMirror.git (fetch)\norigin\tgit@github.com:MichMich/MagicMirror.git (push)\n";
|
||||
gitRevParseOut = "332e429a41f1a2339afd4f0ae96dd125da6beada";
|
||||
gitStatusOut = "## develop...origin/develop\n M tests/unit/functions/updatenotification_spec.js\n";
|
||||
@ -84,13 +84,13 @@ describe("Updatenotification", function () {
|
||||
await gitHelper.add(moduleName);
|
||||
});
|
||||
|
||||
it("returns status information", async function () {
|
||||
it("returns status information", async () => {
|
||||
const repos = await gitHelper.getRepos();
|
||||
expect(repos[0]).toMatchSnapshot();
|
||||
expect(execMock).toHaveBeenCalledTimes(5);
|
||||
});
|
||||
|
||||
it("returns status information early if isBehindInStatus", async function () {
|
||||
it("returns status information early if isBehindInStatus", async () => {
|
||||
gitStatusOut = "## develop...origin/develop [behind 5]";
|
||||
|
||||
const repos = await gitHelper.getRepos();
|
||||
@ -98,7 +98,7 @@ describe("Updatenotification", function () {
|
||||
expect(execMock).toHaveBeenCalledTimes(3);
|
||||
});
|
||||
|
||||
it("excludes repo if status can't be retrieved", async function () {
|
||||
it("excludes repo if status can't be retrieved", async () => {
|
||||
const errorMessage = "Failed to retrieve status";
|
||||
execMock.mockRejectedValueOnce(errorMessage);
|
||||
|
||||
@ -109,7 +109,7 @@ describe("Updatenotification", function () {
|
||||
expect(error).toHaveBeenCalledWith(`Failed to retrieve repo info for ${moduleName}: Failed to retrieve status`);
|
||||
});
|
||||
|
||||
it("excludes repo if refs don't match regex", async function () {
|
||||
it("excludes repo if refs don't match regex", async () => {
|
||||
gitFetchErr = "";
|
||||
|
||||
const repos = await gitHelper.getRepos();
|
||||
@ -120,7 +120,7 @@ describe("Updatenotification", function () {
|
||||
describe("custom module", () => {
|
||||
const moduleName = "MMM-Fuel";
|
||||
|
||||
beforeEach(async function () {
|
||||
beforeEach(async () => {
|
||||
gitRemoteOut = `origin\thttps://github.com/fewieden/${moduleName}.git (fetch)\norigin\thttps://github.com/fewieden/${moduleName}.git (push)\n`;
|
||||
gitRevParseOut = "9d8310163da94441073a93cead711ba43e8888d0";
|
||||
gitStatusOut = "## master...origin/master";
|
||||
@ -130,7 +130,7 @@ describe("Updatenotification", function () {
|
||||
await gitHelper.add(moduleName);
|
||||
});
|
||||
|
||||
it("returns status information without hash", async function () {
|
||||
it("returns status information without hash", async () => {
|
||||
const repos = await gitHelper.getRepos();
|
||||
expect(repos[0]).toMatchSnapshot();
|
||||
expect(execMock).toHaveBeenCalledTimes(4);
|
||||
|
@ -3,29 +3,29 @@ const WeatherObject = require("../../../modules/default/weather/weatherobject.js
|
||||
global.moment = require("moment-timezone");
|
||||
global.SunCalc = require("suncalc");
|
||||
|
||||
describe("WeatherObject", function () {
|
||||
describe("WeatherObject", () => {
|
||||
let originalTimeZone;
|
||||
let weatherobject;
|
||||
|
||||
beforeAll(function () {
|
||||
beforeAll(() => {
|
||||
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 () {
|
||||
it("should return true for daytime at noon", () => {
|
||||
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 () {
|
||||
it("should return false for daytime at midnight", () => {
|
||||
weatherobject.date = moment(0, "HH");
|
||||
weatherobject.updateSunTime(-6.774877582342688, 37.63345667023327);
|
||||
expect(weatherobject.isDayTime()).toBe(false);
|
||||
});
|
||||
|
||||
afterAll(function () {
|
||||
afterAll(() => {
|
||||
moment.tz.setDefault(originalTimeZone);
|
||||
});
|
||||
});
|
||||
|
@ -3,11 +3,11 @@ const path = require("path");
|
||||
|
||||
const root_path = path.join(__dirname, "../../..");
|
||||
|
||||
describe("Default modules set in modules/default/defaultmodules.js", function () {
|
||||
describe("Default modules set in modules/default/defaultmodules.js", () => {
|
||||
const expectedDefaultModules = require("../../../modules/default/defaultmodules");
|
||||
|
||||
for (const defaultModule of expectedDefaultModules) {
|
||||
it(`contains a folder for modules/default/${defaultModule}"`, function () {
|
||||
it(`contains a folder for modules/default/${defaultModule}"`, () => {
|
||||
expect(fs.existsSync(path.join(root_path, "modules/default", defaultModule))).toBe(true);
|
||||
});
|
||||
}
|
||||
|
@ -4,24 +4,24 @@ 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 () {
|
||||
describe("'global.root_path' set in js/app.js", () => {
|
||||
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 () {
|
||||
it(`contains a file/folder "${subpath}"`, () => {
|
||||
expect(fs.existsSync(path.join(root_path, subpath))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
it("should not modify global.root_path for testing", function () {
|
||||
it("should not modify global.root_path for testing", () => {
|
||||
expect(global.root_path).toBe(undefined);
|
||||
});
|
||||
|
||||
it("should not modify global.version for testing", function () {
|
||||
it("should not modify global.version for testing", () => {
|
||||
expect(global.version).toBe(undefined);
|
||||
});
|
||||
|
||||
it("should expect the global.version equals package.json file", function () {
|
||||
it("should expect the global.version equals package.json file", () => {
|
||||
const versionPackage = JSON.parse(fs.readFileSync("package.json", "utf8")).version;
|
||||
expect(version).toBe(versionPackage);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user