update modules alert and compliments

This commit is contained in:
Karsten Hassel 2021-09-25 23:37:37 +02:00
parent 89e803ee42
commit 0183d7a080
11 changed files with 141 additions and 152 deletions

View File

@ -3,7 +3,13 @@
* By rejas * By rejas
* MIT Licensed. * 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: [ modules: [
{ {
module: "alert", module: "alert",
@ -13,7 +19,7 @@ let config = require(process.cwd() + "/tests/configs/default.js").configFactory(
} }
} }
] ]
}); };
/*************** DO NOT EDIT THE LINE BELOW ***************/ /*************** DO NOT EDIT THE LINE BELOW ***************/
if (typeof module !== "undefined") { if (typeof module !== "undefined") {

View File

@ -3,8 +3,12 @@
* By Rodrigo Ramírez Norambuena https://rodrigoramirez.com * By Rodrigo Ramírez Norambuena https://rodrigoramirez.com
* MIT Licensed. * 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, timeFormat: 12,
units: "metric",
modules: [ modules: [
{ {
@ -20,7 +24,7 @@ let config = require(process.cwd() + "/tests/configs/default.js").configFactory(
} }
} }
] ]
}); };
/*************** DO NOT EDIT THE LINE BELOW ***************/ /*************** DO NOT EDIT THE LINE BELOW ***************/
if (typeof module !== "undefined") { if (typeof module !== "undefined") {

View File

@ -3,8 +3,12 @@
* By Rejas * By Rejas
* MIT Licensed. * 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, timeFormat: 12,
units: "metric",
modules: [ modules: [
{ {
@ -21,7 +25,7 @@ let config = require(process.cwd() + "/tests/configs/default.js").configFactory(
} }
} }
] ]
}); };
/*************** DO NOT EDIT THE LINE BELOW ***************/ /*************** DO NOT EDIT THE LINE BELOW ***************/
if (typeof module !== "undefined") { if (typeof module !== "undefined") {

View File

@ -3,8 +3,12 @@
* By Rodrigo Ramírez Norambuena https://rodrigoramirez.com * By Rodrigo Ramírez Norambuena https://rodrigoramirez.com
* MIT Licensed. * 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, timeFormat: 12,
units: "metric",
modules: [ modules: [
{ {
@ -17,7 +21,7 @@ let config = require(process.cwd() + "/tests/configs/default.js").configFactory(
} }
} }
] ]
}); };
/*************** DO NOT EDIT THE LINE BELOW ***************/ /*************** DO NOT EDIT THE LINE BELOW ***************/
if (typeof module !== "undefined") { if (typeof module !== "undefined") {

View File

@ -3,8 +3,12 @@
* By Rodrigo Ramírez Norambuena https://rodrigoramirez.com * By Rodrigo Ramírez Norambuena https://rodrigoramirez.com
* MIT Licensed. * 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, timeFormat: 12,
units: "metric",
modules: [ modules: [
{ {
@ -19,7 +23,7 @@ let config = require(process.cwd() + "/tests/configs/default.js").configFactory(
} }
} }
] ]
}); };
/*************** DO NOT EDIT THE LINE BELOW ***************/ /*************** DO NOT EDIT THE LINE BELOW ***************/
if (typeof module !== "undefined") { if (typeof module !== "undefined") {

View File

@ -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!"]);
});
});
});
});

View File

@ -3,12 +3,16 @@ const config = require("../configs/empty_ipWhiteList");
exports.startApplication = function (configFilename, exec) { exports.startApplication = function (configFilename, exec) {
jest.resetModules(); jest.resetModules();
let app = global.app;
if (app) {
app.stop();
}
// Set config sample for use in test // Set config sample for use in test
process.env.MM_CONFIG_FILE = configFilename; process.env.MM_CONFIG_FILE = configFilename;
if (exec) exec; if (exec) exec;
const app = require("app.js"); app = require("app.js");
app.start(); app.start();
global.app = app;
return app; return app;
}; };

View File

@ -4,7 +4,7 @@
* @param {string} err The error message. * @param {string} err The error message.
*/ */
function myError(err) { 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(); jest.fn();
} else { } else {
console.dir(err); console.dir(err);

View File

@ -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!");
});
});

View File

@ -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);
});
});
});

View File

@ -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);
});
});
});
});
});