From 0183d7a0809238d6ceafcb9b4dd577f74b8f1316 Mon Sep 17 00:00:00 2001 From: Karsten Hassel Date: Sat, 25 Sep 2021 23:37:37 +0200 Subject: [PATCH] update modules alert and compliments --- tests/configs/modules/alert/default.js | 10 +- .../compliments/compliments_anytime.js | 8 +- .../modules/compliments/compliments_date.js | 8 +- .../compliments/compliments_only_anytime.js | 8 +- .../compliments/compliments_parts_day.js | 8 +- tests/e2e/compliments_spec.js | 84 ++++++++++++++ tests/e2e/global-setup.js | 8 +- tests/e2e/mock-console.js | 2 +- tests/e2e/modules/alert_spec.js | 18 +++ tests/electron/modules/alert_spec.js | 32 ------ tests/electron/modules/compliments_spec.js | 107 ------------------ 11 files changed, 141 insertions(+), 152 deletions(-) create mode 100644 tests/e2e/compliments_spec.js create mode 100644 tests/e2e/modules/alert_spec.js delete mode 100644 tests/electron/modules/alert_spec.js delete mode 100644 tests/electron/modules/compliments_spec.js diff --git a/tests/configs/modules/alert/default.js b/tests/configs/modules/alert/default.js index b75a41f8..d9c5c968 100644 --- a/tests/configs/modules/alert/default.js +++ b/tests/configs/modules/alert/default.js @@ -3,7 +3,13 @@ * By rejas * MIT Licensed. */ -let config = require(process.cwd() + "/tests/configs/default.js").configFactory({ +let config = { + port: 8080, + ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], + language: "en", + timeFormat: 24, + units: "metric", + modules: [ { module: "alert", @@ -13,7 +19,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/compliments/compliments_anytime.js b/tests/configs/modules/compliments/compliments_anytime.js index f6731edf..813bd32c 100644 --- a/tests/configs/modules/compliments/compliments_anytime.js +++ b/tests/configs/modules/compliments/compliments_anytime.js @@ -3,8 +3,12 @@ * By Rodrigo Ramírez Norambuena https://rodrigoramirez.com * MIT Licensed. */ -let config = require(process.cwd() + "/tests/configs/default.js").configFactory({ +let config = { + port: 8080, + ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], + language: "en", timeFormat: 12, + units: "metric", modules: [ { @@ -20,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/compliments/compliments_date.js b/tests/configs/modules/compliments/compliments_date.js index c9549816..bf0ae2da 100644 --- a/tests/configs/modules/compliments/compliments_date.js +++ b/tests/configs/modules/compliments/compliments_date.js @@ -3,8 +3,12 @@ * By Rejas * MIT Licensed. */ -let config = require(process.cwd() + "/tests/configs/default.js").configFactory({ +let config = { + port: 8080, + ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], + language: "en", timeFormat: 12, + units: "metric", modules: [ { @@ -21,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/compliments/compliments_only_anytime.js b/tests/configs/modules/compliments/compliments_only_anytime.js index d65bc67d..6e52f57e 100644 --- a/tests/configs/modules/compliments/compliments_only_anytime.js +++ b/tests/configs/modules/compliments/compliments_only_anytime.js @@ -3,8 +3,12 @@ * By Rodrigo Ramírez Norambuena https://rodrigoramirez.com * MIT Licensed. */ -let config = require(process.cwd() + "/tests/configs/default.js").configFactory({ +let config = { + port: 8080, + ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], + language: "en", timeFormat: 12, + units: "metric", modules: [ { @@ -17,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/configs/modules/compliments/compliments_parts_day.js b/tests/configs/modules/compliments/compliments_parts_day.js index e490a710..89b06814 100644 --- a/tests/configs/modules/compliments/compliments_parts_day.js +++ b/tests/configs/modules/compliments/compliments_parts_day.js @@ -3,8 +3,12 @@ * By Rodrigo Ramírez Norambuena https://rodrigoramirez.com * MIT Licensed. */ -let config = require(process.cwd() + "/tests/configs/default.js").configFactory({ +let config = { + port: 8080, + ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], + language: "en", timeFormat: 12, + units: "metric", modules: [ { @@ -19,7 +23,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/compliments_spec.js b/tests/e2e/compliments_spec.js new file mode 100644 index 00000000..aefb273e --- /dev/null +++ b/tests/e2e/compliments_spec.js @@ -0,0 +1,84 @@ +const helpers = require("../global-setup"); +let app = null; + +doTest = function (complimentsArray) { + let elem = document.querySelector(".compliments"); + expect(elem).not.toBe(null); + elem = document.querySelector(".module-content"); + expect(elem).not.toBe(null); + expect(complimentsArray).toContain(elem.textContent); +}; + +describe("Compliments module", function () { + afterAll(function () { + helpers.stopApplication(app); + }); + + describe("parts of days", function () { + beforeAll(function (done) { + app = helpers.startApplication("tests/configs/modules/compliments/compliments_parts_day.js"); + helpers.getDocument(done, 1000); + }); + + it("if Morning compliments for that part of day", function () { + const hour = new Date().getHours(); + if (hour >= 3 && hour < 12) { + // if morning check + doTest(["Hi", "Good Morning", "Morning test"]); + } + }); + + it("if Afternoon show Compliments for that part of day", function () { + const hour = new Date().getHours(); + if (hour >= 12 && hour < 17) { + // if afternoon check + doTest(["Hello", "Good Afternoon", "Afternoon test"]); + } + }); + + it("if Evening show Compliments for that part of day", function () { + const hour = new Date().getHours(); + if (!(hour >= 3 && hour < 12) && !(hour >= 12 && hour < 17)) { + // if evening check + doTest(["Hello There", "Good Evening", "Evening test"]); + } + }); + }); + + describe("Feature anytime in compliments module", function () { + describe("Set anytime and empty compliments for morning, evening and afternoon ", function () { + beforeAll(function (done) { + app = helpers.startApplication("tests/configs/modules/compliments/compliments_anytime.js"); + helpers.getDocument(done, 1000); + }); + + it("Show anytime because if configure empty parts of day compliments and set anytime compliments", async function () { + doTest(["Anytime here"]); + }); + }); + + describe("Only anytime present in configuration compliments", function () { + beforeAll(function (done) { + app = helpers.startApplication("tests/configs/modules/compliments/compliments_only_anytime.js"); + helpers.getDocument(done, 1000); + }); + + it("Show anytime compliments", async function () { + doTest(["Anytime here"]); + }); + }); + }); + + describe("Feature date in compliments module", function () { + describe("Set date and empty compliments for anytime, morning, evening and afternoon", function () { + beforeAll(function (done) { + app = helpers.startApplication("tests/configs/modules/compliments/compliments_date.js"); + helpers.getDocument(done, 1000); + }); + + it("Show happy new year compliment on new years day", async function () { + doTest(["Happy new year!"]); + }); + }); + }); +}); diff --git a/tests/e2e/global-setup.js b/tests/e2e/global-setup.js index 72bee653..918047fe 100644 --- a/tests/e2e/global-setup.js +++ b/tests/e2e/global-setup.js @@ -3,12 +3,16 @@ const config = require("../configs/empty_ipWhiteList"); exports.startApplication = function (configFilename, exec) { jest.resetModules(); + let app = global.app; + if (app) { + app.stop(); + } // Set config sample for use in test process.env.MM_CONFIG_FILE = configFilename; if (exec) exec; - const app = require("app.js"); + app = require("app.js"); app.start(); - + global.app = app; return app; }; diff --git a/tests/e2e/mock-console.js b/tests/e2e/mock-console.js index 745a8fbb..03402a05 100644 --- a/tests/e2e/mock-console.js +++ b/tests/e2e/mock-console.js @@ -4,7 +4,7 @@ * @param {string} err The error message. */ function myError(err) { - if (err.includes("ECONNREFUSED") || err.includes("ECONNRESET") || err.includes("socket hang up")) { + if (err.includes("ECONNREFUSED") || err.includes("ECONNRESET") || err.includes("socket hang up") || err.includes("exports is not defined")) { jest.fn(); } else { console.dir(err); diff --git a/tests/e2e/modules/alert_spec.js b/tests/e2e/modules/alert_spec.js new file mode 100644 index 00000000..19f657a2 --- /dev/null +++ b/tests/e2e/modules/alert_spec.js @@ -0,0 +1,18 @@ +const helpers = require("../global-setup"); +let app = null; + +describe("Alert module", function () { + beforeAll(function (done) { + app = helpers.startApplication("tests/configs/modules/alert/default.js"); + helpers.getDocument(done, 1000); + }); + afterAll(function () { + helpers.stopApplication(app); + }); + + it("should show the welcome message", function () { + const elem = document.querySelector(".ns-box .ns-box-inner .light.bright.small"); + expect(elem).not.toBe(null); + expect(elem.textContent).toContain("Welcome, start was successful!"); + }); +}); diff --git a/tests/electron/modules/alert_spec.js b/tests/electron/modules/alert_spec.js deleted file mode 100644 index 12e724f0..00000000 --- a/tests/electron/modules/alert_spec.js +++ /dev/null @@ -1,32 +0,0 @@ -const helpers = require("../global-setup"); - -describe("Alert 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/alert/default.js"; - }); - - it("should show the welcome message", function () { - return app.client.waitUntilTextExists(".ns-box .ns-box-inner .light.bright.small", "Welcome, start was successful!", 10000); - }); - }); -}); diff --git a/tests/electron/modules/compliments_spec.js b/tests/electron/modules/compliments_spec.js deleted file mode 100644 index 81c6e982..00000000 --- a/tests/electron/modules/compliments_spec.js +++ /dev/null @@ -1,107 +0,0 @@ -const helpers = require("../global-setup"); - -describe("Compliments 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("parts of days", function () { - beforeAll(function () { - // Set config sample for use in test - process.env.MM_CONFIG_FILE = "tests/configs/modules/compliments/compliments_parts_day.js"; - }); - - it("if Morning compliments for that part of day", async function () { - const hour = new Date().getHours(); - if (hour >= 3 && hour < 12) { - // if morning check - const elem = await app.client.$(".compliments"); - return elem.getText(".compliments").then(function (text) { - expect(["Hi", "Good Morning", "Morning test"]).toContain(text); - }); - } - }); - - it("if Afternoon show Compliments for that part of day", async function () { - const hour = new Date().getHours(); - if (hour >= 12 && hour < 17) { - // if afternoon check - const elem = await app.client.$(".compliments"); - return elem.getText(".compliments").then(function (text) { - expect(["Hello", "Good Afternoon", "Afternoon test"]).toContain(text); - }); - } - }); - - it("if Evening show Compliments for that part of day", async function () { - const hour = new Date().getHours(); - if (!(hour >= 3 && hour < 12) && !(hour >= 12 && hour < 17)) { - // if evening check - const elem = await app.client.$(".compliments"); - return elem.getText(".compliments").then(function (text) { - expect(["Hello There", "Good Evening", "Evening test"]).toContain(text); - }); - } - }); - }); - - describe("Feature anytime in compliments module", function () { - describe("Set anytime and empty compliments for morning, evening and afternoon ", function () { - beforeAll(function () { - // Set config sample for use in test - process.env.MM_CONFIG_FILE = "tests/configs/modules/compliments/compliments_anytime.js"; - }); - - it("Show anytime because if configure empty parts of day compliments and set anytime compliments", async function () { - const elem = await app.client.$(".compliments"); - return elem.getText(".compliments").then(function (text) { - expect(["Anytime here"]).toContain(text); - }); - }); - }); - - describe("Only anytime present in configuration compliments", function () { - beforeAll(function () { - // Set config sample for use in test - process.env.MM_CONFIG_FILE = "tests/configs/modules/compliments/compliments_only_anytime.js"; - }); - - it("Show anytime compliments", async function () { - const elem = await app.client.$(".compliments"); - return elem.getText(".compliments").then(function (text) { - expect(["Anytime here"]).toContain(text); - }); - }); - }); - }); - - describe("Feature date in compliments module", function () { - describe("Set date and empty compliments for anytime, morning, evening and afternoon", function () { - beforeAll(function () { - // Set config sample for use in test - process.env.MM_CONFIG_FILE = "tests/configs/modules/compliments/compliments_date.js"; - }); - - it("Show happy new year compliment on new years day", async function () { - const elem = await app.client.$(".compliments"); - return elem.getText(".compliments").then(function (text) { - expect(["Happy new year!"]).toContain(text); - }); - }); - }); - }); -});