MagicMirror/tests/e2e/modules/calendar_spec.js

163 lines
4.4 KiB
JavaScript
Raw Normal View History

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) {
2022-01-13 00:13:29 +01:00
helpers.waitForElement(element).then((elem) => {
expect(elem).not.toBe(null);
if (not === "not") {
expect(elem.length).not.toBe(result);
} else {
expect(elem.length).toBe(result);
}
2022-01-13 21:12:15 +01:00
});
2022-01-13 00:13:29 +01:00
}
const testTextContain = function (element, text) {
2022-01-13 21:12:15 +01:00
helpers.waitForElement(element).then((elem) => {
expect(elem).not.toBe(null);
expect(elem.textContent).toContain(text);
});
};
afterAll(async function () {
await helpers.stopApplication();
});
describe("Default configuration", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/calendar/default.js");
2022-01-13 00:13:29 +01:00
helpers.getDocument(done);
});
it("should show the default maximumEntries of 10", () => {
testElementLength(".calendar .event", 10);
});
it("should show the default calendar symbol in each event", () => {
2022-01-09 11:10:00 +01:00
testElementLength(".calendar .event .fa-calendar-alt", 0, "not");
});
});
describe("Custom configuration", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/calendar/custom.js");
2022-01-13 00:13:29 +01:00
helpers.getDocument(done);
});
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");
2022-01-13 00:13:29 +01:00
helpers.getDocument(done);
});
it("should show the recurring birthday event 6 times", () => {
testElementLength(".calendar .event", 6);
});
2021-12-26 16:10:04 +01:00
});
2021-12-26 16:10:04 +01:00
process.setMaxListeners(0);
for (let i = -12; i < 12; i++) {
describe("Recurring event per timezone", function () {
beforeAll(function (done) {
Date.prototype.getTimezoneOffset = function () {
return i * 60;
};
helpers.startApplication("tests/configs/modules/calendar/recurring.js");
2022-01-13 21:12:15 +01:00
helpers.getDocument(done);
2021-12-26 16:10:04 +01:00
});
it('should contain text "Mar 25th" in timezone UTC ' + -i, () => {
2022-01-13 00:13:29 +01:00
testTextContain(".calendar", "Mar 25th");
2021-12-26 16:10:04 +01:00
});
});
2021-12-26 16:10:04 +01:00
}
describe("Changed port", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/calendar/changed-port.js");
serverBasicAuth.listen(8010);
2022-01-13 00:13:29 +01:00
helpers.getDocument(done);
});
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");
2022-01-13 00:13:29 +01:00
helpers.getDocument(done);
});
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");
2022-01-13 00:13:29 +01:00
helpers.getDocument(done);
});
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");
2022-01-13 00:13:29 +01:00
helpers.getDocument(done);
});
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);
2022-01-13 21:12:15 +01:00
helpers.getDocument(done);
});
afterAll(function (done) {
serverBasicAuth.close(done());
});
it("should show Unauthorized error", function () {
2022-01-13 00:13:29 +01:00
testTextContain(".calendar", "Error in the calendar module. Authorization failed");
});
});
});