mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-09-15 16:29:02 +00:00
improve tests (#2923)
use es6 syntax in all tests, split weather tests, remove callbacks
This commit is contained in:
@@ -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();
|
||||
expect(res.status).toBe(200);
|
||||
});
|
||||
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();
|
||||
expect(res.status).toBe(404);
|
||||
});
|
||||
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();
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toBe("MagicMirror²");
|
||||
});
|
||||
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) => {
|
||||
expect(res.status).toBe(200);
|
||||
done();
|
||||
});
|
||||
const res = await helpers.fetch(fontUrl);
|
||||
expect(res.status).toBe(200);
|
||||
});
|
||||
});
|
||||
|
@@ -1,4 +1,5 @@
|
||||
const jsdom = require("jsdom");
|
||||
const corefetch = require("fetch");
|
||||
|
||||
exports.startApplication = (configFilename, exec) => {
|
||||
jest.resetModules();
|
||||
@@ -21,14 +22,16 @@ exports.stopApplication = async () => {
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
};
|
||||
|
||||
exports.getDocument = (callback) => {
|
||||
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();
|
||||
};
|
||||
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;
|
||||
resolve();
|
||||
};
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
@@ -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) => {
|
||||
expect(res.status).toBe(403);
|
||||
done();
|
||||
});
|
||||
it("should return 403", async () => {
|
||||
const res = await helpers.fetch("http://localhost:8080");
|
||||
expect(res.status).toBe(403);
|
||||
});
|
||||
});
|
||||
|
||||
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) => {
|
||||
expect(res.status).toBe(200);
|
||||
done();
|
||||
});
|
||||
it("should return 200", async () => {
|
||||
const res = await helpers.fetch("http://localhost:8080");
|
||||
expect(res.status).toBe(200);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -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();
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("Welcome, start was successful!");
|
||||
});
|
||||
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();
|
||||
expect(elem).not.toBe(null);
|
||||
if (not === "not") {
|
||||
expect(elem.length).not.toBe(result);
|
||||
} else {
|
||||
expect(elem.length).toBe(result);
|
||||
}
|
||||
});
|
||||
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();
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain(text);
|
||||
});
|
||||
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();
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toBe(weekToShow);
|
||||
});
|
||||
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();
|
||||
expect(elem).not.toBe(null);
|
||||
});
|
||||
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");
|
||||
|
||||
/**
|
||||
* 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) => {
|
||||
expect(elem).not.toBe(null);
|
||||
helpers.waitForElement(".module-content").then((elem) => {
|
||||
done();
|
||||
expect(elem).not.toBe(null);
|
||||
expect(complimentsArray).toContain(elem.textContent);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
describe("Compliments module", () => {
|
||||
/**
|
||||
* move similar tests in function doTest
|
||||
*
|
||||
* @param {Array} complimentsArray The array of compliments.
|
||||
*/
|
||||
const doTest = async (complimentsArray) => {
|
||||
let elem = await helpers.waitForElement(".compliments");
|
||||
expect(elem).not.toBe(null);
|
||||
elem = await helpers.waitForElement(".module-content");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(complimentsArray).toContain(elem.textContent);
|
||||
};
|
||||
|
||||
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();
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("Test HelloWorld Module");
|
||||
});
|
||||
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();
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("Hello World!");
|
||||
});
|
||||
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();
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("Rodrigo Ramirez Blog");
|
||||
});
|
||||
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();
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("QPanel");
|
||||
});
|
||||
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) => {
|
||||
const element = document.querySelector(".newsfeed .newsfeed-desc");
|
||||
done();
|
||||
expect(element).toBe(null);
|
||||
});
|
||||
it("should NOT show the newsfeed description", async () => {
|
||||
await helpers.waitForElement(".newsfeed");
|
||||
const element = document.querySelector(".newsfeed .newsfeed-desc");
|
||||
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();
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("Problema VirtualBox");
|
||||
});
|
||||
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();
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent.length).not.toBe(0);
|
||||
});
|
||||
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();
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("Error in the Newsfeed module. Malformed url.");
|
||||
});
|
||||
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();
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("No news at the moment.");
|
||||
});
|
||||
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();
|
||||
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 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();
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toBe("undefined");
|
||||
});
|
||||
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();
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("Text in " + position);
|
||||
});
|
||||
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) => {
|
||||
expect(res.status).toBe(200);
|
||||
done();
|
||||
});
|
||||
it("should return 200", async () => {
|
||||
const res = await helpers.fetch("http://localhost:8090");
|
||||
expect(res.status).toBe(200);
|
||||
});
|
||||
});
|
||||
|
||||
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) => {
|
||||
expect(res.status).toBe(200);
|
||||
done();
|
||||
});
|
||||
it("should return 200", async () => {
|
||||
const res = await helpers.fetch("http://localhost:8100");
|
||||
expect(res.status).toBe(200);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -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) => {
|
||||
expect(res.status).toBe(200);
|
||||
done();
|
||||
});
|
||||
const res = await helpers.fetch(urlVendor);
|
||||
expect(res.status).toBe(200);
|
||||
});
|
||||
});
|
||||
|
||||
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) => {
|
||||
expect(res.status).toBe(404);
|
||||
done();
|
||||
});
|
||||
const res = await helpers.fetch(urlVendor);
|
||||
expect(res.status).toBe(404);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -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();
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("MagicMirror²");
|
||||
});
|
||||
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();
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("www.michaelteeuw.nl");
|
||||
});
|
||||
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");
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user