move calendar tests from category electron to e2e

This commit is contained in:
Karsten Hassel
2021-10-04 22:48:21 +02:00
parent e4a0a517d5
commit 1d12e57606
14 changed files with 161 additions and 170 deletions

View File

@@ -0,0 +1,29 @@
const path = require("path");
const auth = require("express-basic-auth");
const express = require("express");
const app = express();
const basicAuth = auth({
realm: "MagicMirror Area restricted.",
users: { MagicMirror: "CallMeADog" }
});
app.use(basicAuth);
// Set available directories
const directories = ["/tests/configs"];
const rootPath = path.resolve(__dirname + "/../../../");
for (let directory of directories) {
app.use(directory, express.static(path.resolve(rootPath + directory)));
}
let server;
exports.listen = function () {
server = app.listen.apply(app, arguments);
};
exports.close = function (callback) {
server.close(callback);
};

View File

@@ -0,0 +1,139 @@
const helpers = require("../global-setup");
const serverBasicAuth = require("./basic-auth.js");
describe("Calendar module", function () {
/**
* @param {string} element css selector
* @param {string} result expected number
* @param {string} not reverse result
*/
function testElementLength(element, result, not) {
const elem = document.querySelectorAll(element);
expect(elem).not.toBe(null);
if (not === "not") {
expect(elem.length).not.toBe(result);
} else {
expect(elem.length).toBe(result);
}
}
afterAll(function () {
helpers.stopApplication();
});
describe("Default configuration", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/calendar/default.js");
helpers.getDocument(done, 3000);
});
it("should show the default maximumEntries of 10", () => {
testElementLength(".calendar .event", 10);
});
it("should show the default calendar symbol in each event", () => {
testElementLength(".calendar .event .fa-calendar", 0, "not");
});
});
describe("Custom configuration", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/calendar/custom.js");
helpers.getDocument(done, 3000);
});
it("should show the custom maximumEntries of 4", () => {
testElementLength(".calendar .event", 4);
});
it("should show the custom calendar symbol in each event", () => {
testElementLength(".calendar .event .fa-birthday-cake", 4);
});
it("should show two custom icons for repeating events", () => {
testElementLength(".calendar .event .fa-undo", 2);
});
it("should show two custom icons for day events", () => {
testElementLength(".calendar .event .fa-calendar-day", 2);
});
});
describe("Recurring event", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/calendar/recurring.js");
helpers.getDocument(done, 3000);
});
it("should show the recurring birthday event 6 times", () => {
testElementLength(".calendar .event", 6);
});
});
describe("Changed port", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/calendar/changed-port.js");
serverBasicAuth.listen(8010);
helpers.getDocument(done, 3000);
});
afterAll(function (done) {
serverBasicAuth.close(done());
});
it("should return TestEvents", function () {
testElementLength(".calendar .event", 0, "not");
});
});
describe("Basic auth", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/calendar/basic-auth.js");
helpers.getDocument(done, 3000);
});
it("should return TestEvents", function () {
testElementLength(".calendar .event", 0, "not");
});
});
describe("Basic auth by default", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/calendar/auth-default.js");
helpers.getDocument(done, 3000);
});
it("should return TestEvents", function () {
testElementLength(".calendar .event", 0, "not");
});
});
describe("Basic auth backward compatibility configuration: DEPRECATED", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/calendar/old-basic-auth.js");
helpers.getDocument(done, 3000);
});
it("should return TestEvents", function () {
testElementLength(".calendar .event", 0, "not");
});
});
describe("Fail Basic auth", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/calendar/fail-basic-auth.js");
serverBasicAuth.listen(8020);
helpers.getDocument(done, 3000);
});
afterAll(function (done) {
serverBasicAuth.close(done());
});
it("should show Unauthorized error", function () {
const elem = document.querySelector(".calendar");
expect(elem).not.toBe(null);
expect(elem.textContent).toContain("Error in the calendar module. Authorization failed");
});
});
});