From 1d12e576060e0d211a53259f9d4ec01ce335fd8f Mon Sep 17 00:00:00 2001 From: Karsten Hassel Date: Mon, 4 Oct 2021 22:48:21 +0200 Subject: [PATCH] move calendar tests from category `electron` to `e2e` --- CHANGELOG.md | 2 + package.json | 6 +- .../configs/modules/calendar/auth-default.js | 4 +- tests/configs/modules/calendar/basic-auth.js | 4 +- .../configs/modules/calendar/changed-port.js | 4 +- tests/configs/modules/calendar/custom.js | 4 +- tests/configs/modules/calendar/default.js | 4 +- .../modules/calendar/fail-basic-auth.js | 4 +- .../modules/calendar/old-basic-auth.js | 4 +- tests/configs/modules/calendar/recurring.js | 4 +- tests/e2e/mock-console.js | 2 +- tests/{electron => e2e}/modules/basic-auth.js | 0 tests/e2e/modules/calendar_spec.js | 139 ++++++++++++++++ tests/electron/modules/calendar_spec.js | 150 ------------------ 14 files changed, 161 insertions(+), 170 deletions(-) rename tests/{electron => e2e}/modules/basic-auth.js (100%) create mode 100644 tests/e2e/modules/calendar_spec.js delete mode 100644 tests/electron/modules/calendar_spec.js diff --git a/CHANGELOG.md b/CHANGELOG.md index ee989c71..e3ed64ac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ _This release is scheduled to be released on 2022-01-01._ ### Updated +- Move calendar tests from category `electron` to `e2e`. + ### Fixed ## [2.17.1] - 2021-10-01 diff --git a/package.json b/package.json index 2a0107df..b00cfea5 100644 --- a/package.json +++ b/package.json @@ -114,8 +114,7 @@ ], "testPathIgnorePatterns": [ "/tests/electron/modules/mocks", - "/tests/electron/global-setup.js", - "/tests/electron/modules/basic-auth.js" + "/tests/electron/global-setup.js" ] }, { @@ -131,7 +130,8 @@ ], "testPathIgnorePatterns": [ "/tests/e2e/global-setup.js", - "/tests/e2e/mock-console.js" + "/tests/e2e/mock-console.js", + "/tests/e2e/modules/basic-auth.js" ] } ] diff --git a/tests/configs/modules/calendar/auth-default.js b/tests/configs/modules/calendar/auth-default.js index 8375bfcd..a120c7ca 100644 --- a/tests/configs/modules/calendar/auth-default.js +++ b/tests/configs/modules/calendar/auth-default.js @@ -3,7 +3,7 @@ * By Rodrigo Ramírez Norambuena https://rodrigoramirez.com * MIT Licensed. */ -let config = require(process.cwd() + "/tests/configs/default.js").configFactory({ +let config = { timeFormat: 12, modules: [ @@ -24,7 +24,7 @@ let config = require(process.cwd() + "/tests/configs/default.js").configFactory( } } ] -}); +}; /*************** DO NOT EDIT THE LINE BELOW ***************/ if (typeof module !== "undefined") { diff --git a/tests/configs/modules/calendar/basic-auth.js b/tests/configs/modules/calendar/basic-auth.js index a1150281..ebca135a 100644 --- a/tests/configs/modules/calendar/basic-auth.js +++ b/tests/configs/modules/calendar/basic-auth.js @@ -3,7 +3,7 @@ * By Rodrigo Ramírez Norambuena https://rodrigoramirez.com * MIT Licensed. */ -let config = require(process.cwd() + "/tests/configs/default.js").configFactory({ +let config = { timeFormat: 12, modules: [ @@ -25,7 +25,7 @@ let config = require(process.cwd() + "/tests/configs/default.js").configFactory( } } ] -}); +}; /*************** DO NOT EDIT THE LINE BELOW ***************/ if (typeof module !== "undefined") { diff --git a/tests/configs/modules/calendar/changed-port.js b/tests/configs/modules/calendar/changed-port.js index e43feafa..05d6d1ff 100644 --- a/tests/configs/modules/calendar/changed-port.js +++ b/tests/configs/modules/calendar/changed-port.js @@ -3,7 +3,7 @@ * By Rodrigo Ramírez Norambuena https://rodrigoramirez.com * MIT Licensed. */ -let config = require(process.cwd() + "/tests/configs/default.js").configFactory({ +let config = { timeFormat: 12, modules: [ @@ -24,7 +24,7 @@ let config = require(process.cwd() + "/tests/configs/default.js").configFactory( } } ] -}); +}; /*************** DO NOT EDIT THE LINE BELOW ***************/ if (typeof module !== "undefined") { diff --git a/tests/configs/modules/calendar/custom.js b/tests/configs/modules/calendar/custom.js index 16f82ea0..068db9be 100644 --- a/tests/configs/modules/calendar/custom.js +++ b/tests/configs/modules/calendar/custom.js @@ -3,7 +3,7 @@ * By Rejas * MIT Licensed. */ -let config = require(process.cwd() + "/tests/configs/default.js").configFactory({ +let config = { timeFormat: 12, modules: [ @@ -24,7 +24,7 @@ let config = require(process.cwd() + "/tests/configs/default.js").configFactory( } } ] -}); +}; /*************** DO NOT EDIT THE LINE BELOW ***************/ if (typeof module !== "undefined") { diff --git a/tests/configs/modules/calendar/default.js b/tests/configs/modules/calendar/default.js index 5964b294..0c9b8151 100644 --- a/tests/configs/modules/calendar/default.js +++ b/tests/configs/modules/calendar/default.js @@ -3,7 +3,7 @@ * By Rodrigo Ramírez Norambuena https://rodrigoramirez.com * MIT Licensed. */ -let config = require(process.cwd() + "/tests/configs/default.js").configFactory({ +let config = { timeFormat: 12, modules: [ @@ -20,7 +20,7 @@ let config = require(process.cwd() + "/tests/configs/default.js").configFactory( } } ] -}); +}; /*************** DO NOT EDIT THE LINE BELOW ***************/ if (typeof module !== "undefined") { diff --git a/tests/configs/modules/calendar/fail-basic-auth.js b/tests/configs/modules/calendar/fail-basic-auth.js index 54d04064..1d2f8c76 100644 --- a/tests/configs/modules/calendar/fail-basic-auth.js +++ b/tests/configs/modules/calendar/fail-basic-auth.js @@ -5,7 +5,7 @@ * By Rodrigo Ramírez Norambuena https://rodrigoramirez.com * MIT Licensed. */ -let config = require(process.cwd() + "/tests/configs/default.js").configFactory({ +let config = { timeFormat: 12, modules: [ @@ -27,7 +27,7 @@ let config = require(process.cwd() + "/tests/configs/default.js").configFactory( } } ] -}); +}; /*************** DO NOT EDIT THE LINE BELOW ***************/ if (typeof module !== "undefined") { diff --git a/tests/configs/modules/calendar/old-basic-auth.js b/tests/configs/modules/calendar/old-basic-auth.js index 06570eb1..743ff04d 100644 --- a/tests/configs/modules/calendar/old-basic-auth.js +++ b/tests/configs/modules/calendar/old-basic-auth.js @@ -3,7 +3,7 @@ * By Rodrigo Ramírez Norambuena https://rodrigoramirez.com * MIT Licensed. */ -let config = require(process.cwd() + "/tests/configs/default.js").configFactory({ +let config = { timeFormat: 12, modules: [ @@ -22,7 +22,7 @@ let config = require(process.cwd() + "/tests/configs/default.js").configFactory( } } ] -}); +}; /*************** DO NOT EDIT THE LINE BELOW ***************/ if (typeof module !== "undefined") { diff --git a/tests/configs/modules/calendar/recurring.js b/tests/configs/modules/calendar/recurring.js index 879b966e..567a366c 100644 --- a/tests/configs/modules/calendar/recurring.js +++ b/tests/configs/modules/calendar/recurring.js @@ -3,7 +3,7 @@ * By Rejas * MIT Licensed. */ -let config = require(process.cwd() + "/tests/configs/default.js").configFactory({ +let config = { timeFormat: 12, modules: [ @@ -21,7 +21,7 @@ let config = require(process.cwd() + "/tests/configs/default.js").configFactory( } } ] -}); +}; /*************** DO NOT EDIT THE LINE BELOW ***************/ if (typeof module !== "undefined") { diff --git a/tests/e2e/mock-console.js b/tests/e2e/mock-console.js index 90b70f12..454a8e46 100644 --- a/tests/e2e/mock-console.js +++ b/tests/e2e/mock-console.js @@ -4,7 +4,7 @@ * @param {string} err The error message. */ function mockError(err) { - if (err.includes("ECONNREFUSED") || err.includes("ECONNRESET") || err.includes("socket hang up") || err.includes("exports is not defined")) { + 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); diff --git a/tests/electron/modules/basic-auth.js b/tests/e2e/modules/basic-auth.js similarity index 100% rename from tests/electron/modules/basic-auth.js rename to tests/e2e/modules/basic-auth.js diff --git a/tests/e2e/modules/calendar_spec.js b/tests/e2e/modules/calendar_spec.js new file mode 100644 index 00000000..4ccd3e08 --- /dev/null +++ b/tests/e2e/modules/calendar_spec.js @@ -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"); + }); + }); +}); diff --git a/tests/electron/modules/calendar_spec.js b/tests/electron/modules/calendar_spec.js deleted file mode 100644 index b6420e83..00000000 --- a/tests/electron/modules/calendar_spec.js +++ /dev/null @@ -1,150 +0,0 @@ -const helpers = require("../global-setup"); -const serverBasicAuth = require("./basic-auth.js"); - -describe("Calendar module", function () { - helpers.setupTimeout(this); - - let app = null; - - beforeEach(function () { - return helpers - .startApplication({ - args: ["js/electron.js"] - }) - .then(function (startedApp) { - app = startedApp; - }); - }); - - afterEach(function () { - return helpers.stopApplication(app); - }); - - describe("Default configuration", function () { - beforeAll(function () { - // Set config sample for use in test - process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/default.js"; - }); - - it("should show the default maximumEntries of 10", async () => { - await app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); - const events = await app.client.$$(".calendar .event"); - return expect(events.length).toBe(10); - }); - - it("should show the default calendar symbol in each event", async () => { - await app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); - const icons = await app.client.$$(".calendar .event .fa-calendar"); - return expect(icons.length).not.toBe(0); - }); - }); - - describe("Custom configuration", function () { - beforeAll(function () { - // Set config sample for use in test - process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/custom.js"; - }); - - it("should show the custom maximumEntries of 4", async () => { - await app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); - const events = await app.client.$$(".calendar .event"); - return expect(events.length).toBe(4); - }); - - it("should show the custom calendar symbol in each event", async () => { - await app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); - const icons = await app.client.$$(".calendar .event .fa-birthday-cake"); - return expect(icons.length).toBe(4); - }); - - it("should show two custom icons for repeating events", async () => { - await app.client.waitUntilTextExists(".calendar", "TestEventRepeat", 10000); - const icons = await app.client.$$(".calendar .event .fa-undo"); - return expect(icons.length).toBe(2); - }); - - it("should show two custom icons for day events", async () => { - await app.client.waitUntilTextExists(".calendar", "TestEventDay", 10000); - const icons = await app.client.$$(".calendar .event .fa-calendar-day"); - return expect(icons.length).toBe(2); - }); - }); - - describe("Recurring event", function () { - beforeAll(function () { - // Set config sample for use in test - process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/recurring.js"; - }); - - it("should show the recurring birthday event 6 times", async () => { - await app.client.waitUntilTextExists(".calendar", "Mar 25th", 10000); - const events = await app.client.$$(".calendar .event"); - return expect(events.length).toBe(6); - }); - }); - - describe("Changed port", function () { - beforeAll(function () { - serverBasicAuth.listen(8010); - // Set config sample for use in test - process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/changed-port.js"; - }); - - afterAll(function (done) { - serverBasicAuth.close(done()); - }); - - it("should return TestEvents", function () { - return app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); - }); - }); - - describe("Basic auth", function () { - beforeAll(function () { - // Set config sample for use in test - process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/basic-auth.js"; - }); - - it("should return TestEvents", function () { - return app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); - }); - }); - - describe("Basic auth by default", function () { - beforeAll(function () { - // Set config sample for use in test - process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/auth-default.js"; - }); - - it("should return TestEvents", function () { - return app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); - }); - }); - - describe("Basic auth backward compatibility configuration: DEPRECATED", function () { - beforeAll(function () { - // Set config sample for use in test - process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/old-basic-auth.js"; - }); - - it("should return TestEvents", function () { - return app.client.waitUntilTextExists(".calendar", "TestEvent", 10000); - }); - }); - - describe("Fail Basic auth", function () { - beforeAll(function () { - serverBasicAuth.listen(8020); - // Set config sample for use in test - process.env.MM_CONFIG_FILE = "tests/configs/modules/calendar/fail-basic-auth.js"; - }); - - afterAll(function (done) { - serverBasicAuth.close(done()); - }); - - it("should show Unauthorized error", function () { - return app.client.waitUntilTextExists(".calendar", "Error in the calendar module. Authorization failed", 10000); - }); - }); -});