mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-24 22:13:33 +00:00
change getDocument, delay needed, now 2 tests moved
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
const jsdom = require("jsdom");
|
||||
const config = require("../configs/empty_ipWhiteList");
|
||||
|
||||
exports.startApplication = function (configFilename, exec, callback) {
|
||||
exports.startApplication = function (configFilename, exec) {
|
||||
jest.resetModules();
|
||||
// Set config sample for use in test
|
||||
process.env.MM_CONFIG_FILE = configFilename;
|
||||
@@ -9,16 +9,6 @@ exports.startApplication = function (configFilename, exec, callback) {
|
||||
const app = require("app.js");
|
||||
app.start();
|
||||
|
||||
if (callback) {
|
||||
const url = "http://" + (config.address || "localhost") + ":" + (config.port || "8080");
|
||||
jsdom.JSDOM.fromURL(url, { resources: "usable", runScripts: "dangerously" }).then((dom) => {
|
||||
dom.window.onload = function () {
|
||||
global.document = dom.window.document;
|
||||
callback();
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
return app;
|
||||
};
|
||||
|
||||
@@ -27,3 +17,15 @@ exports.stopApplication = function (app) {
|
||||
app.stop();
|
||||
}
|
||||
};
|
||||
|
||||
exports.getDocument = function (callback, ms) {
|
||||
const url = "http://" + (config.address || "localhost") + ":" + (config.port || "8080");
|
||||
jsdom.JSDOM.fromURL(url, { resources: "usable", runScripts: "dangerously" }).then((dom) => {
|
||||
dom.window.onload = function () {
|
||||
global.document = dom.window.document;
|
||||
setTimeout(() => {
|
||||
callback();
|
||||
}, ms);
|
||||
};
|
||||
});
|
||||
};
|
||||
|
@@ -1,5 +1,10 @@
|
||||
/**
|
||||
* Suppresses errors concerning web server already shut down.
|
||||
*
|
||||
* @param {string} err The error message.
|
||||
*/
|
||||
function myError(err) {
|
||||
if (err.includes("ECONNREFUSED")) {
|
||||
if (err.includes("ECONNREFUSED") || err.includes("ECONNRESET") || err.includes("socket hang up")) {
|
||||
jest.fn();
|
||||
} else {
|
||||
console.dir(err);
|
||||
|
@@ -3,21 +3,22 @@ let app = null;
|
||||
|
||||
describe("Display of modules", function () {
|
||||
beforeAll(function (done) {
|
||||
app = helpers.startApplication("tests/configs/modules/display.js", null, done);
|
||||
app = helpers.startApplication("tests/configs/modules/display.js");
|
||||
helpers.getDocument(done);
|
||||
});
|
||||
afterAll(function () {
|
||||
helpers.stopApplication(app);
|
||||
});
|
||||
|
||||
it("should show the test header", function () {
|
||||
elem = document.querySelector("#module_0_helloworld .module-header");
|
||||
const elem = document.querySelector("#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", function () {
|
||||
elem = document.querySelector("#module_1_helloworld .module-header");
|
||||
const elem = document.querySelector("#module_1_helloworld .module-header");
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toBe("undefined");
|
||||
});
|
||||
|
23
tests/e2e/modules_position_spec.js
Normal file
23
tests/e2e/modules_position_spec.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const helpers = require("./global-setup");
|
||||
let app = null;
|
||||
|
||||
describe("Position of modules", function () {
|
||||
beforeAll(function (done) {
|
||||
app = helpers.startApplication("tests/configs/modules/positions.js");
|
||||
helpers.getDocument(done, 1000);
|
||||
});
|
||||
afterAll(function () {
|
||||
helpers.stopApplication(app);
|
||||
});
|
||||
|
||||
const positions = ["top_bar", "top_left", "top_center", "top_right", "upper_third", "middle_center", "lower_third", "bottom_left", "bottom_center", "bottom_right", "bottom_bar", "fullscreen_above", "fullscreen_below"];
|
||||
|
||||
for (const position of positions) {
|
||||
const className = position.replace("_", ".");
|
||||
it("should show text in " + position, function () {
|
||||
const elem = document.querySelector("." + className);
|
||||
expect(elem).not.toBe(null);
|
||||
expect(elem.textContent).toContain("Text in " + position);
|
||||
});
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user