Release 2.22.0 (#2983)

## [2.22.0] - 2023-01-01

Thanks to: @angeldeejay, @buxxi, @dariom, @dWoolridge,
@KristjanESPERANTO, @MagMar94, @naveensrinivasan, @retroflex, @SkySails
and @Tom.

Special thanks to @khassel, @rejas and @sdetweil for taking over most
(if not all) of the work on this release as project collaborators. This
version would not be there without their effort. Thank you!

### Added

- Added test for remoteFile option in compliments module
- Added hourlyWeather functionality to Weather.gov weather provider
- Removed weatherEndpoint definition from weathergov.js (not used)
- Added css class names "today" and "tomorrow" for default calendar
- Added Collaboration.md
- Added new github action for dependency review (#2862)
- Added a WeatherProvider for Open-Meteo
- Added Yr as a weather provider
- Added config options "ignoreXOriginHeader" and
"ignoreContentSecurityPolicy"

### Removed

- Removed usage of internal fetch function of node until it is more
stable

### Updated

- Cleaned up test directory (#2937) and jest config (#2959)
- Wait for all modules to start before declaring the system ready
(#2487)
- Updated e2e tests (moved `done()` in helper functions) and use es6
syntax in all tests
- Updated da translation
- Rework weather module
- Make sure smhi provider api only gets a maximum of 6 digits
coordinates (#2955)
  - Use fetch instead of XMLHttpRequest in weatherprovider (#2935)
  - Reworked how weatherproviders handle units (#2849)
  - Use unix() method for parsing times, fix suntimes on the way (#2950)
  - Refactor conversion functions into utils class (#2958)
- The `cors`-method in `server.js` now supports sending and recieving
HTTP headers
- Replace `…` by `…`
- Cleanup compliments module
- Updated dependencies including electron to v22 (#2903)

### Fixed

- Correctly show apparent temperature in SMHI weather provider
- Ensure updatenotification module isn't shown when local is _ahead_ of
remote
- Handle node_helper errors during startup (#2944)
- Possibility to change FontAwesome class in calendar, so icons like
`fab fa-facebook-square` works.
- Fix cors problems with newsfeed articles (as far as possible), allow
disabling cors per feed with option `useCorsProxy: false` (#2840)
- Tests not waiting for the application to start and stop before
starting the next test
- Fix electron tests failing sometimes in github workflow
- Fixed gap in clock module when displayed on the left side with
displayType=digital
- Fixed playwright issue by upgrading to v1.29.1 (#2969)

Signed-off-by: naveen <172697+naveensrinivasan@users.noreply.github.com>
Co-authored-by: Karsten Hassel <hassel@gmx.de>
Co-authored-by: Malte Hallström <46646495+SkySails@users.noreply.github.com>
Co-authored-by: Veeck <github@veeck.de>
Co-authored-by: veeck <michael@veeck.de>
Co-authored-by: dWoolridge <dwoolridge@charter.net>
Co-authored-by: Johan <jojjepersson@yahoo.se>
Co-authored-by: Dario Mratovich <dario_mratovich@hotmail.com>
Co-authored-by: Dario Mratovich <dario.mratovich@outlook.com>
Co-authored-by: Magnus <34011212+MagMar94@users.noreply.github.com>
Co-authored-by: Naveen <172697+naveensrinivasan@users.noreply.github.com>
Co-authored-by: buxxi <buxxi@omfilm.net>
Co-authored-by: Thomas Hirschberger <47733292+Tom-Hirschberger@users.noreply.github.com>
Co-authored-by: Kristjan ESPERANTO <35647502+KristjanESPERANTO@users.noreply.github.com>
Co-authored-by: Andrés Vanegas Jiménez <142350+angeldeejay@users.noreply.github.com>
This commit is contained in:
Michael Teeuw
2023-01-01 18:09:08 +01:00
committed by GitHub
parent 9e0293047f
commit 0300ce05d5
151 changed files with 5890 additions and 4949 deletions

View File

@@ -1,34 +1,27 @@
const fetch = require("fetch");
const helpers = require("./global-setup");
const helpers = require("./helpers/global-setup");
describe("App environment", () => {
beforeAll((done) => {
helpers.startApplication("tests/configs/default.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/default.js");
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²");
});
});

View File

@@ -1,7 +1,6 @@
const fetch = require("fetch");
const helpers = require("./global-setup");
const helpers = require("./helpers/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 () {
helpers.startApplication("tests/configs/without_modules.js");
beforeAll(async () => {
await 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);
});
});

View File

@@ -11,7 +11,7 @@ const basicAuth = auth({
app.use(basicAuth);
// Set available directories
const directories = ["/tests/configs"];
const directories = ["/tests/configs", "/tests/mocks"];
const rootPath = path.resolve(__dirname + "/../../../");
for (let directory of directories) {
@@ -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();
};

View File

@@ -1,8 +1,11 @@
const jsdom = require("jsdom");
const corefetch = require("fetch");
exports.startApplication = (configFilename, exec) => {
exports.startApplication = async (configFilename, exec) => {
jest.resetModules();
this.stopApplication();
if (global.app) {
await this.stopApplication();
}
// Set config sample for use in test
if (configFilename === "") {
process.env.MM_CONFIG_FILE = "config/config.js";
@@ -11,24 +14,33 @@ exports.startApplication = (configFilename, exec) => {
}
if (exec) exec;
global.app = require("app.js");
global.app.start();
return new Promise((resolve) => {
global.app.start(resolve);
});
};
exports.stopApplication = async () => {
if (global.app) {
global.app.stop();
return new Promise((resolve) => {
global.app.stop(resolve);
delete global.app;
});
}
await new Promise((resolve) => setTimeout(resolve, 100));
return Promise.resolve();
};
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.fetch = corefetch;
dom.window.onload = () => {
global.document = dom.window.document;
resolve();
};
});
});
};
@@ -71,3 +83,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);
};

View File

@@ -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(),

View File

@@ -0,0 +1,29 @@
const helpers = require("./global-setup");
const path = require("path");
const fs = require("fs");
const { generateWeather, generateWeatherForecast } = require("../../mocks/weather_test");
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);
await helpers.startApplication("");
await helpers.getDocument();
};

View File

@@ -1,36 +1,31 @@
const fetch = require("fetch");
const helpers = require("./global-setup");
const helpers = require("./helpers/global-setup");
describe("ipWhitelist directive configuration", function () {
describe("Set ipWhitelist without access", function () {
beforeAll(function () {
helpers.startApplication("tests/configs/noIpWhiteList.js");
describe("ipWhitelist directive configuration", () => {
describe("Set ipWhitelist without access", () => {
beforeAll(async () => {
await 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 () {
helpers.startApplication("tests/configs/empty_ipWhiteList.js");
describe("Set ipWhitelist []", () => {
beforeAll(async () => {
await 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);
});
});
});

View File

@@ -1,19 +1,17 @@
const helpers = require("../global-setup");
const helpers = require("../helpers/global-setup");
describe("Alert module", () => {
beforeAll((done) => {
helpers.startApplication("tests/configs/modules/alert/default.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/alert/default.js");
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!");
});
});

View File

@@ -1,31 +1,26 @@
const helpers = require("../global-setup");
const serverBasicAuth = require("./basic-auth.js");
const helpers = require("../helpers/global-setup");
const serverBasicAuth = require("../helpers/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) => {
helpers.startApplication("tests/configs/modules/calendar/default.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/calendar/default.js");
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) => {
helpers.startApplication("tests/configs/modules/calendar/custom.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/calendar/custom.js");
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) => {
helpers.startApplication("tests/configs/modules/calendar/recurring.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/calendar/recurring.js");
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.startApplication("tests/configs/modules/calendar/recurring.js");
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) => {
helpers.startApplication("tests/configs/modules/calendar/changed-port.js");
beforeAll(async () => {
await 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) => {
helpers.startApplication("tests/configs/modules/calendar/basic-auth.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/calendar/basic-auth.js");
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) => {
helpers.startApplication("tests/configs/modules/calendar/auth-default.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/calendar/auth-default.js");
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) => {
helpers.startApplication("tests/configs/modules/calendar/old-basic-auth.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/calendar/old-basic-auth.js");
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) => {
helpers.startApplication("tests/configs/modules/calendar/fail-basic-auth.js");
beforeAll(async () => {
await 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");
});
});
});

View File

@@ -1,73 +1,65 @@
const helpers = require("../global-setup");
const helpers = require("../helpers/global-setup");
describe("Clock set to spanish language module", () => {
afterAll(async () => {
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) => {
helpers.startApplication("tests/configs/modules/clock/es/clock_24hr.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/clock/es/clock_24hr.js");
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) => {
helpers.startApplication("tests/configs/modules/clock/es/clock_12hr.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/clock/es/clock_12hr.js");
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) => {
helpers.startApplication("tests/configs/modules/clock/es/clock_showPeriodUpper.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/clock/es/clock_showPeriodUpper.js");
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) => {
helpers.startApplication("tests/configs/modules/clock/es/clock_showWeek.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/clock/es/clock_showWeek.js");
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);
});
});
});

View File

@@ -1,4 +1,4 @@
const helpers = require("../global-setup");
const helpers = require("../helpers/global-setup");
const moment = require("moment");
describe("Clock module", () => {
@@ -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) => {
helpers.startApplication("tests/configs/modules/clock/clock_24hr.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/clock/clock_24hr.js");
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) => {
helpers.startApplication("tests/configs/modules/clock/clock_12hr.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/clock/clock_12hr.js");
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) => {
helpers.startApplication("tests/configs/modules/clock/clock_showPeriodUpper.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/clock/clock_showPeriodUpper.js");
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) => {
helpers.startApplication("tests/configs/modules/clock/clock_displaySeconds_false.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/clock/clock_displaySeconds_false.js");
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) => {
helpers.startApplication("tests/configs/modules/clock/clock_showTime.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/clock/clock_showTime.js");
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) => {
helpers.startApplication("tests/configs/modules/clock/clock_showWeek.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/clock/clock_showWeek.js");
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) => {
helpers.startApplication("tests/configs/modules/clock/clock_analog.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/clock/clock_analog.js");
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);
});
});
});

View File

@@ -1,98 +1,55 @@
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);
});
});
};
const helpers = require("../helpers/global-setup");
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) => {
helpers.startApplication("tests/configs/modules/compliments/compliments_parts_day.js");
helpers.getDocument(done);
});
it("if Morning compliments for that part of day", (done) => {
const hour = new Date().getHours();
if (hour >= 3 && hour < 12) {
// if morning check
doTest(done, ["Hi", "Good Morning", "Morning test"]);
} else {
done();
}
});
it("if Afternoon show Compliments for that part of day", (done) => {
const hour = new Date().getHours();
if (hour >= 12 && hour < 17) {
// if afternoon check
doTest(done, ["Hello", "Good Afternoon", "Afternoon test"]);
} else {
done();
}
});
it("if Evening show Compliments for that part of day", (done) => {
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();
}
});
});
describe("Feature anytime in compliments module", () => {
describe("Set anytime and empty compliments for morning, evening and afternoon ", () => {
beforeAll((done) => {
helpers.startApplication("tests/configs/modules/compliments/compliments_anytime.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/compliments/compliments_anytime.js");
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) => {
helpers.startApplication("tests/configs/modules/compliments/compliments_only_anytime.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/compliments/compliments_only_anytime.js");
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) => {
helpers.startApplication("tests/configs/modules/compliments/compliments_date.js");
helpers.getDocument(done);
});
describe("remoteFile option", () => {
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/compliments/compliments_remote.js");
await helpers.getDocument();
});
it("Show happy new year compliment on new years day", (done) => {
doTest(done, ["Happy new year!"]);
});
it("should show compliments from a remote file", async () => {
await doTest(["Remote compliment file works!"]);
});
});
});

View File

@@ -1,4 +1,4 @@
const helpers = require("../global-setup");
const helpers = require("../helpers/global-setup");
describe("Test helloworld module", () => {
afterAll(async () => {
@@ -6,32 +6,28 @@ describe("Test helloworld module", () => {
});
describe("helloworld set config text", () => {
beforeAll((done) => {
helpers.startApplication("tests/configs/modules/helloworld/helloworld.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/helloworld/helloworld.js");
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) => {
helpers.startApplication("tests/configs/modules/helloworld/helloworld_default.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/helloworld/helloworld_default.js");
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!");
});
});
});

View File

@@ -1,4 +0,0 @@
const generateWeather = require("./weather_current");
const generateWeatherForecast = require("./weather_forecast");
module.exports = { generateWeather, generateWeatherForecast };

View File

@@ -1,64 +0,0 @@
const _ = require("lodash");
/**
* @param {object} extendedData extra data to add to the default mock data
* @returns {string} mocked current weather data
*/
function generateWeather(extendedData = {}) {
return JSON.stringify(
_.merge(
{},
{
coord: {
lon: 11.58,
lat: 48.14
},
weather: [
{
id: 615,
main: "Snow",
description: "light rain and snow",
icon: "13d"
},
{
id: 500,
main: "Rain",
description: "light rain",
icon: "10d"
}
],
base: "stations",
main: {
temp: 1.49,
pressure: 1005,
humidity: 93.7,
temp_min: 1,
temp_max: 2
},
visibility: 7000,
wind: {
speed: 11.8,
deg: 250
},
clouds: {
all: 75
},
dt: 1547387400,
sys: {
type: 1,
id: 1267,
message: 0.0031,
country: "DE",
sunrise: 1547362817,
sunset: 1547394301
},
id: 2867714,
name: "Munich",
cod: 200
},
extendedData
)
);
}
module.exports = generateWeather;

View File

@@ -1,115 +0,0 @@
const _ = require("lodash");
/**
* @param {object} extendedData extra data to add to the default mock data
* @returns {string} mocked forecast weather data
*/
function generateWeatherForecast(extendedData = {}) {
return JSON.stringify(
_.merge(
{},
{
city: {
id: 2867714,
name: "Munich",
coord: { lon: 11.5754, lat: 48.1371 },
country: "DE",
population: 1260391,
timezone: 7200
},
cod: "200",
message: 0.9653487,
cnt: 7,
list: [
{
dt: 1568372400,
sunrise: 1568350044,
sunset: 1568395948,
temp: { day: 24.44, min: 15.35, max: 24.44, night: 15.35, eve: 18, morn: 23.03 },
pressure: 1031.65,
humidity: 70,
weather: [{ id: 801, main: "Clouds", description: "few clouds", icon: "02d" }],
speed: 3.35,
deg: 314,
clouds: 21
},
{
dt: 1568458800,
sunrise: 1568436525,
sunset: 1568482223,
temp: { day: 20.81, min: 13.56, max: 21.02, night: 13.56, eve: 16.6, morn: 15.88 },
pressure: 1028.81,
humidity: 72,
weather: [{ id: 500, main: "Rain", description: "light rain", icon: "10d" }],
speed: 2.21,
deg: 81,
clouds: 100
},
{
dt: 1568545200,
sunrise: 1568523007,
sunset: 1568568497,
temp: { day: 22.65, min: 13.76, max: 22.88, night: 15.27, eve: 17.45, morn: 13.76 },
pressure: 1023.75,
humidity: 64,
weather: [{ id: 800, main: "Clear", description: "sky is clear", icon: "01d" }],
speed: 1.15,
deg: 7,
clouds: 0
},
{
dt: 1568631600,
sunrise: 1568609489,
sunset: 1568654771,
temp: { day: 23.45, min: 13.95, max: 23.45, night: 13.95, eve: 17.75, morn: 15.21 },
pressure: 1020.41,
humidity: 64,
weather: [{ id: 800, main: "Clear", description: "sky is clear", icon: "01d" }],
speed: 3.07,
deg: 298,
clouds: 7
},
{
dt: 1568718000,
sunrise: 1568695970,
sunset: 1568741045,
temp: { day: 20.55, min: 10.95, max: 20.55, night: 10.95, eve: 14.82, morn: 13.24 },
pressure: 1019.4,
humidity: 66,
weather: [{ id: 800, main: "Clear", description: "sky is clear", icon: "01d" }],
speed: 2.8,
deg: 333,
clouds: 2
},
{
dt: 1568804400,
sunrise: 1568782452,
sunset: 1568827319,
temp: { day: 18.15, min: 7.75, max: 18.15, night: 7.75, eve: 12.45, morn: 9.41 },
pressure: 1017.56,
humidity: 52,
weather: [{ id: 800, main: "Clear", description: "sky is clear", icon: "01d" }],
speed: 2.92,
deg: 34,
clouds: 0
},
{
dt: 1568890800,
sunrise: 1568868934,
sunset: 1568913593,
temp: { day: 14.85, min: 5.56, max: 15.05, night: 5.56, eve: 9.56, morn: 6.25 },
pressure: 1022.7,
humidity: 59,
weather: [{ id: 800, main: "Clear", description: "sky is clear", icon: "01d" }],
speed: 2.89,
deg: 51,
clouds: 1
}
]
},
extendedData
)
);
}
module.exports = generateWeatherForecast;

View File

@@ -1,4 +1,4 @@
const helpers = require("../global-setup");
const helpers = require("../helpers/global-setup");
describe("Newsfeed module", () => {
afterAll(async () => {
@@ -6,86 +6,72 @@ describe("Newsfeed module", () => {
});
describe("Default configuration", () => {
beforeAll((done) => {
helpers.startApplication("tests/configs/modules/newsfeed/default.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/newsfeed/default.js");
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) => {
helpers.startApplication("tests/configs/modules/newsfeed/prohibited_words.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/newsfeed/prohibited_words.js");
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) => {
helpers.startApplication("tests/configs/modules/newsfeed/incorrect_url.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/newsfeed/incorrect_url.js");
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) => {
helpers.startApplication("tests/configs/modules/newsfeed/ignore_items.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/newsfeed/ignore_items.js");
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.");
});
});
});

View File

@@ -0,0 +1,84 @@
const helpers = require("../helpers/global-setup");
const weatherFunc = require("../helpers/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)", "12 WSW");
});
it("should render temperature with icon", async () => {
await weatherFunc.getText(".weather .large.light span.bright", "1.5°");
});
it("should render feels like temperature", async () => {
await weatherFunc.getText(".weather .normal.medium.feelslike span.dimmed", "Feels like -5.6°");
});
});
});
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 windUnits in beaufort", async () => {
await weatherFunc.getText(".weather .normal.medium span:nth-child(2)", "6");
});
it("should render windDirection with an arrow", 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 humidity", async () => {
await weatherFunc.getText(".weather .normal.medium span:nth-child(3)", "93.7");
});
it("should render degreeLabel for temp", async () => {
await weatherFunc.getText(".weather .large.light span.bright", "1°C");
});
it("should render degreeLabel for feels like", async () => {
await weatherFunc.getText(".weather .normal.medium.feelslike span.dimmed", "Feels like -6°C");
});
});
describe("Current weather with imperial units", () => {
beforeAll(async () => {
await weatherFunc.startApp("tests/configs/modules/weather/currentweather_units.js", {});
});
it("should render wind in imperial units", async () => {
await weatherFunc.getText(".weather .normal.medium span:nth-child(2)", "26 WSW");
});
it("should render temperatures in fahrenheit", async () => {
await weatherFunc.getText(".weather .large.light span.bright", "34,7°");
});
it("should render 'feels like' in fahrenheit", async () => {
await weatherFunc.getText(".weather .normal.medium.feelslike span.dimmed", "Feels like 21,9°");
});
});
});

View File

@@ -0,0 +1,96 @@
const helpers = require("../helpers/global-setup");
const weatherFunc = require("../helpers/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 = ["75_9°", "69_8°", "73_2°", "74_1°", "69_1°"];
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);
});
}
});
});

View File

@@ -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);
});
}
});
});
});

View File

@@ -1,28 +1,24 @@
const helpers = require("./global-setup");
const helpers = require("./helpers/global-setup");
describe("Display of modules", () => {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/display.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/display.js");
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");
});
});

View File

@@ -0,0 +1,23 @@
const helpers = require("./helpers/global-setup");
describe("Check configuration without modules", () => {
beforeAll(async () => {
await helpers.startApplication("tests/configs/without_modules.js");
await helpers.getDocument();
});
afterAll(async () => {
await helpers.stopApplication();
});
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 url of 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");
});
});

View File

@@ -1,9 +1,9 @@
const helpers = require("./global-setup");
const helpers = require("./helpers/global-setup");
describe("Position of modules", () => {
beforeAll((done) => {
helpers.startApplication("tests/configs/modules/positions.js");
helpers.getDocument(done);
beforeAll(async () => {
await helpers.startApplication("tests/configs/modules/positions.js");
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);
});
}
});

View File

@@ -1,36 +0,0 @@
const fetch = require("fetch");
const helpers = require("./global-setup");
describe("port directive configuration", function () {
describe("Set port 8090", function () {
beforeAll(function () {
helpers.startApplication("tests/configs/port_8090.js");
});
afterAll(async function () {
await helpers.stopApplication();
});
it("should return 200", function (done) {
fetch("http://localhost:8090").then((res) => {
expect(res.status).toBe(200);
done();
});
});
});
describe("Set port 8100 on environment variable MM_PORT", function () {
beforeAll(function () {
helpers.startApplication("tests/configs/port_8090.js", (process.env.MM_PORT = 8100));
});
afterAll(async function () {
await helpers.stopApplication();
});
it("should return 200", function (done) {
fetch("http://localhost:8100").then((res) => {
expect(res.status).toBe(200);
done();
});
});
});
});

31
tests/e2e/port_spec.js Normal file
View File

@@ -0,0 +1,31 @@
const helpers = require("./helpers/global-setup");
describe("port directive configuration", () => {
describe("Set port 8090", () => {
beforeAll(async () => {
await helpers.startApplication("tests/configs/port_8090.js");
});
afterAll(async () => {
await helpers.stopApplication();
});
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", () => {
beforeAll(async () => {
await helpers.startApplication("tests/configs/port_8090.js", (process.env.MM_PORT = 8100));
});
afterAll(async () => {
await helpers.stopApplication();
});
it("should return 200", async () => {
const res = await helpers.fetch("http://localhost:8100");
expect(res.status).toBe(200);
});
});
});

View File

@@ -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

View File

@@ -1,34 +1,29 @@
const fetch = require("fetch");
const helpers = require("./global-setup");
const helpers = require("./helpers/global-setup");
describe("Vendors", function () {
beforeAll(function () {
helpers.startApplication("tests/configs/default.js");
describe("Vendors", () => {
beforeAll(async () => {
await 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);
});
});
});

View File

@@ -1,27 +0,0 @@
const helpers = require("./global-setup");
describe("Check configuration without modules", () => {
beforeAll((done) => {
helpers.startApplication("tests/configs/without_modules.js");
helpers.getDocument(done);
});
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 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");
});
});
});