MagicMirror/tests/e2e/modules/compliments_spec.js

100 lines
3.0 KiB
JavaScript
Raw Normal View History

2021-09-25 23:37:37 +02:00
const helpers = require("../global-setup");
describe("Compliments module", () => {
/**
* move similar tests in function doTest
*
* @param {Array} complimentsArray The array of compliments.
*/
const doTest = async (complimentsArray) => {
let elem = await helpers.waitForElement(".compliments");
2022-01-13 21:12:15 +01:00
expect(elem).not.toBe(null);
elem = await helpers.waitForElement(".module-content");
expect(elem).not.toBe(null);
expect(complimentsArray).toContain(elem.textContent);
};
2021-09-25 23:37:37 +02:00
afterAll(async () => {
await helpers.stopApplication();
2021-09-25 23:37:37 +02:00
});
describe("parts of days", () => {
beforeAll(async () => {
2021-09-25 23:45:34 +02:00
helpers.startApplication("tests/configs/modules/compliments/compliments_parts_day.js");
await helpers.getDocument();
2021-09-25 23:37:37 +02:00
});
it("if Morning compliments for that part of day", async () => {
2021-09-25 23:37:37 +02:00
const hour = new Date().getHours();
if (hour >= 3 && hour < 12) {
// if morning check
await doTest(["Hi", "Good Morning", "Morning test"]);
2021-09-25 23:37:37 +02:00
}
});
it("if Afternoon show Compliments for that part of day", async () => {
2021-09-25 23:37:37 +02:00
const hour = new Date().getHours();
if (hour >= 12 && hour < 17) {
// if afternoon check
await doTest(["Hello", "Good Afternoon", "Afternoon test"]);
2021-09-25 23:37:37 +02:00
}
});
it("if Evening show Compliments for that part of day", async () => {
2021-09-25 23:37:37 +02:00
const hour = new Date().getHours();
if (!(hour >= 3 && hour < 12) && !(hour >= 12 && hour < 17)) {
// if evening check
await doTest(["Hello There", "Good Evening", "Evening test"]);
2021-09-25 23:37:37 +02:00
}
});
});
describe("Feature anytime in compliments module", () => {
describe("Set anytime and empty compliments for morning, evening and afternoon ", () => {
beforeAll(async () => {
2021-09-25 23:45:34 +02:00
helpers.startApplication("tests/configs/modules/compliments/compliments_anytime.js");
await helpers.getDocument();
2021-09-25 23:37:37 +02:00
});
it("Show anytime because if configure empty parts of day compliments and set anytime compliments", async () => {
await doTest(["Anytime here"]);
2021-09-25 23:37:37 +02:00
});
});
describe("Only anytime present in configuration compliments", () => {
beforeAll(async () => {
2021-09-25 23:45:34 +02:00
helpers.startApplication("tests/configs/modules/compliments/compliments_only_anytime.js");
await helpers.getDocument();
2021-09-25 23:37:37 +02:00
});
it("Show anytime compliments", async () => {
await doTest(["Anytime here"]);
2021-09-25 23:37:37 +02:00
});
});
});
describe("Feature date in compliments module", () => {
describe("Set date and empty compliments for anytime, morning, evening and afternoon", () => {
beforeAll(async () => {
2021-09-25 23:45:34 +02:00
helpers.startApplication("tests/configs/modules/compliments/compliments_date.js");
await helpers.getDocument();
2021-09-25 23:37:37 +02:00
});
it("Show happy new year compliment on new years day", async () => {
await doTest(["Happy new year!"]);
2021-09-25 23:37:37 +02:00
});
});
});
describe("remoteFile option", () => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/compliments/compliments_remote.js");
await helpers.getDocument();
});
it("should show compliments from a remote file", async () => {
await doTest(["Remote compliment file works!"]);
});
});
2021-09-25 23:37:37 +02:00
});