MagicMirror/tests/e2e/modules/compliments_spec.js

89 lines
2.7 KiB
JavaScript
Raw Normal View History

2021-09-25 23:37:37 +02:00
const helpers = require("../global-setup");
2021-09-26 00:29:03 +02:00
/**
* move similar tests in function doTest
*
* @param {Array} complimentsArray The array of compliments.
*/
function doTest(complimentsArray) {
2021-09-25 23:37:37 +02:00
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);
2021-09-26 00:29:03 +02:00
}
2021-09-25 23:37:37 +02:00
describe("Compliments module", function () {
afterAll(function () {
2021-09-25 23:45:34 +02:00
helpers.stopApplication();
2021-09-25 23:37:37 +02:00
});
describe("parts of days", function () {
beforeAll(function (done) {
2021-09-25 23:45:34 +02:00
helpers.startApplication("tests/configs/modules/compliments/compliments_parts_day.js");
2021-09-25 23:37:37 +02:00
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) {
2021-09-25 23:45:34 +02:00
helpers.startApplication("tests/configs/modules/compliments/compliments_anytime.js");
2021-09-25 23:37:37 +02:00
helpers.getDocument(done, 1000);
});
2021-09-26 21:58:59 +02:00
it("Show anytime because if configure empty parts of day compliments and set anytime compliments", function () {
2021-09-25 23:37:37 +02:00
doTest(["Anytime here"]);
});
});
describe("Only anytime present in configuration compliments", function () {
beforeAll(function (done) {
2021-09-25 23:45:34 +02:00
helpers.startApplication("tests/configs/modules/compliments/compliments_only_anytime.js");
2021-09-25 23:37:37 +02:00
helpers.getDocument(done, 1000);
});
2021-09-26 21:58:59 +02:00
it("Show anytime compliments", function () {
2021-09-25 23:37:37 +02:00
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) {
2021-09-25 23:45:34 +02:00
helpers.startApplication("tests/configs/modules/compliments/compliments_date.js");
2021-09-25 23:37:37 +02:00
helpers.getDocument(done, 1000);
});
2021-09-26 21:58:59 +02:00
it("Show happy new year compliment on new years day", function () {
2021-09-25 23:37:37 +02:00
doTest(["Happy new year!"]);
});
});
});
});