improve tests (#2923)

use es6 syntax in all tests, split weather tests, remove callbacks
This commit is contained in:
Karsten Hassel
2022-10-04 10:15:24 +02:00
committed by GitHub
parent 7694d6fa86
commit f04d578704
41 changed files with 751 additions and 840 deletions

View File

@@ -1,19 +1,17 @@
const helpers = require("../global-setup");
describe("Alert module", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/alert/default.js");
helpers.getDocument(done);
await helpers.getDocument();
});
afterAll(async () => {
await helpers.stopApplication();
});
it("should show the welcome message", (done) => {
helpers.waitForElement(".ns-box .ns-box-inner .light.bright.small").then((elem) => {
done();
expect(elem).not.toBe(null);
expect(elem.textContent).toContain("Welcome, start was successful!");
});
it("should show the welcome message", async () => {
const elem = await helpers.waitForElement(".ns-box .ns-box-inner .light.bright.small");
expect(elem).not.toBe(null);
expect(elem.textContent).toContain("Welcome, start was successful!");
});
});

View File

@@ -20,10 +20,10 @@ for (let directory of directories) {
let server;
exports.listen = function () {
server = app.listen.apply(app, arguments);
exports.listen = (...args) => {
server = app.listen.apply(app, args);
};
exports.close = function (callback) {
server.close(callback);
exports.close = async () => {
await server.close();
};

View File

@@ -3,29 +3,24 @@ const serverBasicAuth = require("./basic-auth.js");
describe("Calendar module", () => {
/**
* @param {string} done test done
* @param {string} element css selector
* @param {string} result expected number
* @param {string} not reverse result
*/
const testElementLength = (done, element, result, not) => {
helpers.waitForAllElements(element).then((elem) => {
done();
expect(elem).not.toBe(null);
if (not === "not") {
expect(elem.length).not.toBe(result);
} else {
expect(elem.length).toBe(result);
}
});
const testElementLength = async (element, result, not) => {
const elem = await helpers.waitForAllElements(element);
expect(elem).not.toBe(null);
if (not === "not") {
expect(elem.length).not.toBe(result);
} else {
expect(elem.length).toBe(result);
}
};
const testTextContain = (done, element, text) => {
helpers.waitForElement(element, "undefinedLoading").then((elem) => {
done();
expect(elem).not.toBe(null);
expect(elem.textContent).toContain(text);
});
const testTextContain = async (element, text) => {
const elem = await helpers.waitForElement(element, "undefinedLoading");
expect(elem).not.toBe(null);
expect(elem.textContent).toContain(text);
};
afterAll(async () => {
@@ -33,133 +28,133 @@ describe("Calendar module", () => {
});
describe("Default configuration", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/calendar/default.js");
helpers.getDocument(done);
await helpers.getDocument();
});
it("should show the default maximumEntries of 10", (done) => {
testElementLength(done, ".calendar .event", 10);
it("should show the default maximumEntries of 10", async () => {
await testElementLength(".calendar .event", 10);
});
it("should show the default calendar symbol in each event", (done) => {
testElementLength(done, ".calendar .event .fa-calendar-alt", 0, "not");
it("should show the default calendar symbol in each event", async () => {
await testElementLength(".calendar .event .fa-calendar-alt", 0, "not");
});
});
describe("Custom configuration", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/calendar/custom.js");
helpers.getDocument(done);
await helpers.getDocument();
});
it("should show the custom maximumEntries of 4", (done) => {
testElementLength(done, ".calendar .event", 4);
it("should show the custom maximumEntries of 4", async () => {
await testElementLength(".calendar .event", 4);
});
it("should show the custom calendar symbol in each event", (done) => {
testElementLength(done, ".calendar .event .fa-birthday-cake", 4);
it("should show the custom calendar symbol in each event", async () => {
await testElementLength(".calendar .event .fa-birthday-cake", 4);
});
it("should show two custom icons for repeating events", (done) => {
testElementLength(done, ".calendar .event .fa-undo", 2);
it("should show two custom icons for repeating events", async () => {
await testElementLength(".calendar .event .fa-undo", 2);
});
it("should show two custom icons for day events", (done) => {
testElementLength(done, ".calendar .event .fa-calendar-day", 2);
it("should show two custom icons for day events", async () => {
await testElementLength(".calendar .event .fa-calendar-day", 2);
});
});
describe("Recurring event", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/calendar/recurring.js");
helpers.getDocument(done);
await helpers.getDocument();
});
it("should show the recurring birthday event 6 times", (done) => {
testElementLength(done, ".calendar .event", 6);
it("should show the recurring birthday event 6 times", async () => {
await testElementLength(".calendar .event", 6);
});
});
process.setMaxListeners(0);
for (let i = -12; i < 12; i++) {
describe("Recurring event per timezone", () => {
beforeAll((done) => {
beforeAll(async () => {
Date.prototype.getTimezoneOffset = () => {
return i * 60;
};
helpers.startApplication("tests/configs/modules/calendar/recurring.js");
helpers.getDocument(done);
await helpers.getDocument();
});
it('should contain text "Mar 25th" in timezone UTC ' + -i, (done) => {
testTextContain(done, ".calendar", "Mar 25th");
it('should contain text "Mar 25th" in timezone UTC ' + -i, async () => {
await testTextContain(".calendar", "Mar 25th");
});
});
}
describe("Changed port", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/calendar/changed-port.js");
serverBasicAuth.listen(8010);
helpers.getDocument(done);
await helpers.getDocument();
});
afterAll((done) => {
serverBasicAuth.close(done());
afterAll(async () => {
await serverBasicAuth.close();
});
it("should return TestEvents", (done) => {
testElementLength(done, ".calendar .event", 0, "not");
it("should return TestEvents", async () => {
await testElementLength(".calendar .event", 0, "not");
});
});
describe("Basic auth", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/calendar/basic-auth.js");
helpers.getDocument(done);
await helpers.getDocument();
});
it("should return TestEvents", (done) => {
testElementLength(done, ".calendar .event", 0, "not");
it("should return TestEvents", async () => {
await testElementLength(".calendar .event", 0, "not");
});
});
describe("Basic auth by default", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/calendar/auth-default.js");
helpers.getDocument(done);
await helpers.getDocument();
});
it("should return TestEvents", (done) => {
testElementLength(done, ".calendar .event", 0, "not");
it("should return TestEvents", async () => {
await testElementLength(".calendar .event", 0, "not");
});
});
describe("Basic auth backward compatibility configuration: DEPRECATED", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/calendar/old-basic-auth.js");
helpers.getDocument(done);
await helpers.getDocument();
});
it("should return TestEvents", (done) => {
testElementLength(done, ".calendar .event", 0, "not");
it("should return TestEvents", async () => {
await testElementLength(".calendar .event", 0, "not");
});
});
describe("Fail Basic auth", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/calendar/fail-basic-auth.js");
serverBasicAuth.listen(8020);
helpers.getDocument(done);
await helpers.getDocument();
});
afterAll((done) => {
serverBasicAuth.close(done());
afterAll(async () => {
await serverBasicAuth.close();
});
it("should show Unauthorized error", (done) => {
testTextContain(done, ".calendar", "Error in the calendar module. Authorization failed");
it("should show Unauthorized error", async () => {
await testTextContain(".calendar", "Error in the calendar module. Authorization failed");
});
});
});

View File

@@ -5,69 +5,61 @@ describe("Clock set to spanish language module", () => {
await helpers.stopApplication();
});
const testMatch = (done, element, regex) => {
helpers.waitForElement(element).then((elem) => {
done();
expect(elem).not.toBe(null);
expect(elem.textContent).toMatch(regex);
});
};
describe("with default 24hr clock config", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/clock/es/clock_24hr.js");
helpers.getDocument(done);
await helpers.getDocument();
});
it("shows date with correct format", (done) => {
it("shows date with correct format", async () => {
const dateRegex = /^(?:lunes|martes|miércoles|jueves|viernes|sábado|domingo), \d{1,2} de (?:enero|febrero|marzo|abril|mayo|junio|julio|agosto|septiembre|octubre|noviembre|diciembre) de \d{4}$/;
testMatch(done, ".clock .date", dateRegex);
await helpers.testMatch(".clock .date", dateRegex);
});
it("shows time in 24hr format", (done) => {
it("shows time in 24hr format", async () => {
const timeRegex = /^(?:2[0-3]|[01]\d):[0-5]\d[0-5]\d$/;
testMatch(done, ".clock .time", timeRegex);
await helpers.testMatch(".clock .time", timeRegex);
});
});
describe("with default 12hr clock config", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/clock/es/clock_12hr.js");
helpers.getDocument(done);
await helpers.getDocument();
});
it("shows date with correct format", (done) => {
it("shows date with correct format", async () => {
const dateRegex = /^(?:lunes|martes|miércoles|jueves|viernes|sábado|domingo), \d{1,2} de (?:enero|febrero|marzo|abril|mayo|junio|julio|agosto|septiembre|octubre|noviembre|diciembre) de \d{4}$/;
testMatch(done, ".clock .date", dateRegex);
await helpers.testMatch(".clock .date", dateRegex);
});
it("shows time in 12hr format", (done) => {
it("shows time in 12hr format", async () => {
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[ap]m$/;
testMatch(done, ".clock .time", timeRegex);
await helpers.testMatch(".clock .time", timeRegex);
});
});
describe("with showPeriodUpper config enabled", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/clock/es/clock_showPeriodUpper.js");
helpers.getDocument(done);
await helpers.getDocument();
});
it("shows 12hr time with upper case AM/PM", (done) => {
it("shows 12hr time with upper case AM/PM", async () => {
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[AP]M$/;
testMatch(done, ".clock .time", timeRegex);
await helpers.testMatch(".clock .time", timeRegex);
});
});
describe("with showWeek config enabled", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/clock/es/clock_showWeek.js");
helpers.getDocument(done);
await helpers.getDocument();
});
it("shows week with correct format", (done) => {
it("shows week with correct format", async () => {
const weekRegex = /^Semana [0-9]{1,2}$/;
testMatch(done, ".clock .week", weekRegex);
await helpers.testMatch(".clock .week", weekRegex);
});
});
});

View File

@@ -6,118 +6,105 @@ describe("Clock module", () => {
await helpers.stopApplication();
});
const testMatch = (done, element, regex) => {
helpers.waitForElement(element).then((elem) => {
done();
expect(elem).not.toBe(null);
expect(elem.textContent).toMatch(regex);
});
};
describe("with default 24hr clock config", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/clock/clock_24hr.js");
helpers.getDocument(done);
await helpers.getDocument();
});
it("should show the date in the correct format", (done) => {
it("should show the date in the correct format", async () => {
const dateRegex = /^(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (?:January|February|March|April|May|June|July|August|September|October|November|December) \d{1,2}, \d{4}$/;
testMatch(done, ".clock .date", dateRegex);
await helpers.testMatch(".clock .date", dateRegex);
});
it("should show the time in 24hr format", (done) => {
it("should show the time in 24hr format", async () => {
const timeRegex = /^(?:2[0-3]|[01]\d):[0-5]\d[0-5]\d$/;
testMatch(done, ".clock .time", timeRegex);
await helpers.testMatch(".clock .time", timeRegex);
});
});
describe("with default 12hr clock config", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/clock/clock_12hr.js");
helpers.getDocument(done);
await helpers.getDocument();
});
it("should show the date in the correct format", (done) => {
it("should show the date in the correct format", async () => {
const dateRegex = /^(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (?:January|February|March|April|May|June|July|August|September|October|November|December) \d{1,2}, \d{4}$/;
testMatch(done, ".clock .date", dateRegex);
await helpers.testMatch(".clock .date", dateRegex);
});
it("should show the time in 12hr format", (done) => {
it("should show the time in 12hr format", async () => {
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[ap]m$/;
testMatch(done, ".clock .time", timeRegex);
await helpers.testMatch(".clock .time", timeRegex);
});
});
describe("with showPeriodUpper config enabled", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/clock/clock_showPeriodUpper.js");
helpers.getDocument(done);
await helpers.getDocument();
});
it("should show 12hr time with upper case AM/PM", (done) => {
it("should show 12hr time with upper case AM/PM", async () => {
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[AP]M$/;
testMatch(done, ".clock .time", timeRegex);
await helpers.testMatch(".clock .time", timeRegex);
});
});
describe("with displaySeconds config disabled", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/clock/clock_displaySeconds_false.js");
helpers.getDocument(done);
await helpers.getDocument();
});
it("should show 12hr time without seconds am/pm", (done) => {
it("should show 12hr time without seconds am/pm", async () => {
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[ap]m$/;
testMatch(done, ".clock .time", timeRegex);
await helpers.testMatch(".clock .time", timeRegex);
});
});
describe("with showTime config disabled", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/clock/clock_showTime.js");
helpers.getDocument(done);
await helpers.getDocument();
});
it("should not show the time when digital clock is shown", (done) => {
const elem = document.querySelector(".clock .digital .time");
done();
it("should not show the time when digital clock is shown", async () => {
const elem = await document.querySelector(".clock .digital .time");
expect(elem).toBe(null);
});
});
describe("with showWeek config enabled", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/clock/clock_showWeek.js");
helpers.getDocument(done);
await helpers.getDocument();
});
it("should show the week in the correct format", (done) => {
it("should show the week in the correct format", async () => {
const weekRegex = /^Week [0-9]{1,2}$/;
testMatch(done, ".clock .week", weekRegex);
await helpers.testMatch(".clock .week", weekRegex);
});
it("should show the week with the correct number of week of year", (done) => {
it("should show the week with the correct number of week of year", async () => {
const currentWeekNumber = moment().week();
const weekToShow = "Week " + currentWeekNumber;
helpers.waitForElement(".clock .week").then((elem) => {
done();
expect(elem).not.toBe(null);
expect(elem.textContent).toBe(weekToShow);
});
const elem = await helpers.waitForElement(".clock .week");
expect(elem).not.toBe(null);
expect(elem.textContent).toBe(weekToShow);
});
});
describe("with analog clock face enabled", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/clock/clock_analog.js");
helpers.getDocument(done);
await helpers.getDocument();
});
it("should show the analog clock face", (done) => {
helpers.waitForElement(".clockCircle").then((elem) => {
done();
expect(elem).not.toBe(null);
});
it("should show the analog clock face", async () => {
const elem = helpers.waitForElement(".clockCircle");
expect(elem).not.toBe(null);
});
});
});

View File

@@ -1,97 +1,87 @@
const helpers = require("../global-setup");
/**
* move similar tests in function doTest
*
* @param {string} done test done
* @param {Array} complimentsArray The array of compliments.
*/
const doTest = (done, complimentsArray) => {
helpers.waitForElement(".compliments").then((elem) => {
expect(elem).not.toBe(null);
helpers.waitForElement(".module-content").then((elem) => {
done();
expect(elem).not.toBe(null);
expect(complimentsArray).toContain(elem.textContent);
});
});
};
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");
expect(elem).not.toBe(null);
elem = await helpers.waitForElement(".module-content");
expect(elem).not.toBe(null);
expect(complimentsArray).toContain(elem.textContent);
};
afterAll(async () => {
await helpers.stopApplication();
});
describe("parts of days", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/compliments/compliments_parts_day.js");
helpers.getDocument(done);
await helpers.getDocument();
});
it("if Morning compliments for that part of day", (done) => {
it("if Morning compliments for that part of day", async () => {
const hour = new Date().getHours();
if (hour >= 3 && hour < 12) {
// if morning check
doTest(done, ["Hi", "Good Morning", "Morning test"]);
} else {
done();
await doTest(["Hi", "Good Morning", "Morning test"]);
}
});
it("if Afternoon show Compliments for that part of day", (done) => {
it("if Afternoon show Compliments for that part of day", async () => {
const hour = new Date().getHours();
if (hour >= 12 && hour < 17) {
// if afternoon check
doTest(done, ["Hello", "Good Afternoon", "Afternoon test"]);
} else {
done();
await doTest(["Hello", "Good Afternoon", "Afternoon test"]);
}
});
it("if Evening show Compliments for that part of day", (done) => {
it("if Evening show Compliments for that part of day", async () => {
const hour = new Date().getHours();
if (!(hour >= 3 && hour < 12) && !(hour >= 12 && hour < 17)) {
// if evening check
doTest(done, ["Hello There", "Good Evening", "Evening test"]);
} else {
done();
await doTest(["Hello There", "Good Evening", "Evening test"]);
}
});
});
describe("Feature anytime in compliments module", () => {
describe("Set anytime and empty compliments for morning, evening and afternoon ", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/compliments/compliments_anytime.js");
helpers.getDocument(done);
await helpers.getDocument();
});
it("Show anytime because if configure empty parts of day compliments and set anytime compliments", (done) => {
doTest(done, ["Anytime here"]);
it("Show anytime because if configure empty parts of day compliments and set anytime compliments", async () => {
await doTest(["Anytime here"]);
});
});
describe("Only anytime present in configuration compliments", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/compliments/compliments_only_anytime.js");
helpers.getDocument(done);
await helpers.getDocument();
});
it("Show anytime compliments", (done) => {
doTest(done, ["Anytime here"]);
it("Show anytime compliments", async () => {
await doTest(["Anytime here"]);
});
});
});
describe("Feature date in compliments module", () => {
describe("Set date and empty compliments for anytime, morning, evening and afternoon", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/compliments/compliments_date.js");
helpers.getDocument(done);
await helpers.getDocument();
});
it("Show happy new year compliment on new years day", (done) => {
doTest(done, ["Happy new year!"]);
it("Show happy new year compliment on new years day", async () => {
await doTest(["Happy new year!"]);
});
});
});

View File

@@ -6,32 +6,28 @@ describe("Test helloworld module", () => {
});
describe("helloworld set config text", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/helloworld/helloworld.js");
helpers.getDocument(done);
await helpers.getDocument();
});
it("Test message helloworld module", (done) => {
helpers.waitForElement(".helloworld").then((elem) => {
done();
expect(elem).not.toBe(null);
expect(elem.textContent).toContain("Test HelloWorld Module");
});
it("Test message helloworld module", async () => {
const elem = await helpers.waitForElement(".helloworld");
expect(elem).not.toBe(null);
expect(elem.textContent).toContain("Test HelloWorld Module");
});
});
describe("helloworld default config text", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/helloworld/helloworld_default.js");
helpers.getDocument(done);
await helpers.getDocument();
});
it("Test message helloworld module", (done) => {
helpers.waitForElement(".helloworld").then((elem) => {
done();
expect(elem).not.toBe(null);
expect(elem.textContent).toContain("Hello World!");
});
it("Test message helloworld module", async () => {
const elem = await helpers.waitForElement(".helloworld");
expect(elem).not.toBe(null);
expect(elem.textContent).toContain("Hello World!");
});
});
});

View File

@@ -4,7 +4,7 @@ const _ = require("lodash");
* @param {object} extendedData extra data to add to the default mock data
* @returns {string} mocked current weather data
*/
function generateWeather(extendedData = {}) {
const generateWeather = (extendedData = {}) => {
return JSON.stringify(
_.merge(
{},
@@ -59,6 +59,6 @@ function generateWeather(extendedData = {}) {
extendedData
)
);
}
};
module.exports = generateWeather;

View File

@@ -4,7 +4,7 @@ const _ = require("lodash");
* @param {object} extendedData extra data to add to the default mock data
* @returns {string} mocked forecast weather data
*/
function generateWeatherForecast(extendedData = {}) {
const generateWeatherForecast = (extendedData = {}) => {
return JSON.stringify(
_.merge(
{},
@@ -110,6 +110,6 @@ function generateWeatherForecast(extendedData = {}) {
extendedData
)
);
}
};
module.exports = generateWeatherForecast;

View File

@@ -6,86 +6,72 @@ describe("Newsfeed module", () => {
});
describe("Default configuration", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/newsfeed/default.js");
helpers.getDocument(done);
await helpers.getDocument();
});
it("should show the newsfeed title", (done) => {
helpers.waitForElement(".newsfeed .newsfeed-source").then((elem) => {
done();
expect(elem).not.toBe(null);
expect(elem.textContent).toContain("Rodrigo Ramirez Blog");
});
it("should show the newsfeed title", async () => {
const elem = await helpers.waitForElement(".newsfeed .newsfeed-source");
expect(elem).not.toBe(null);
expect(elem.textContent).toContain("Rodrigo Ramirez Blog");
});
it("should show the newsfeed article", (done) => {
helpers.waitForElement(".newsfeed .newsfeed-title").then((elem) => {
done();
expect(elem).not.toBe(null);
expect(elem.textContent).toContain("QPanel");
});
it("should show the newsfeed article", async () => {
const elem = await helpers.waitForElement(".newsfeed .newsfeed-title");
expect(elem).not.toBe(null);
expect(elem.textContent).toContain("QPanel");
});
it("should NOT show the newsfeed description", (done) => {
helpers.waitForElement(".newsfeed").then((elem) => {
const element = document.querySelector(".newsfeed .newsfeed-desc");
done();
expect(element).toBe(null);
});
it("should NOT show the newsfeed description", async () => {
await helpers.waitForElement(".newsfeed");
const element = document.querySelector(".newsfeed .newsfeed-desc");
expect(element).toBe(null);
});
});
describe("Custom configuration", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/newsfeed/prohibited_words.js");
helpers.getDocument(done);
await helpers.getDocument();
});
it("should not show articles with prohibited words", (done) => {
helpers.waitForElement(".newsfeed .newsfeed-title").then((elem) => {
done();
expect(elem).not.toBe(null);
expect(elem.textContent).toContain("Problema VirtualBox");
});
it("should not show articles with prohibited words", async () => {
const elem = await helpers.waitForElement(".newsfeed .newsfeed-title");
expect(elem).not.toBe(null);
expect(elem.textContent).toContain("Problema VirtualBox");
});
it("should show the newsfeed description", (done) => {
helpers.waitForElement(".newsfeed .newsfeed-desc").then((elem) => {
done();
expect(elem).not.toBe(null);
expect(elem.textContent.length).not.toBe(0);
});
it("should show the newsfeed description", async () => {
const elem = await helpers.waitForElement(".newsfeed .newsfeed-desc");
expect(elem).not.toBe(null);
expect(elem.textContent.length).not.toBe(0);
});
});
describe("Invalid configuration", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/newsfeed/incorrect_url.js");
helpers.getDocument(done);
await helpers.getDocument();
});
it("should show malformed url warning", (done) => {
helpers.waitForElement(".newsfeed .small", "No news at the moment.").then((elem) => {
done();
expect(elem).not.toBe(null);
expect(elem.textContent).toContain("Error in the Newsfeed module. Malformed url.");
});
it("should show malformed url warning", async () => {
const elem = await helpers.waitForElement(".newsfeed .small", "No news at the moment.");
expect(elem).not.toBe(null);
expect(elem.textContent).toContain("Error in the Newsfeed module. Malformed url.");
});
});
describe("Ignore items", () => {
beforeAll((done) => {
beforeAll(async () => {
helpers.startApplication("tests/configs/modules/newsfeed/ignore_items.js");
helpers.getDocument(done);
await helpers.getDocument();
});
it("should show empty items info message", (done) => {
helpers.waitForElement(".newsfeed .small").then((elem) => {
done();
expect(elem).not.toBe(null);
expect(elem.textContent).toContain("No news at the moment.");
});
it("should show empty items info message", async () => {
const elem = await helpers.waitForElement(".newsfeed .small");
expect(elem).not.toBe(null);
expect(elem.textContent).toContain("No news at the moment.");
});
});
});

View File

@@ -0,0 +1,29 @@
const helpers = require("../global-setup");
const path = require("path");
const fs = require("fs");
const { generateWeather, generateWeatherForecast } = require("./mocks");
exports.getText = async (element, result) => {
const elem = await helpers.waitForElement(element);
expect(elem).not.toBe(null);
expect(
elem.textContent
.trim()
.replace(/(\r\n|\n|\r)/gm, "")
.replace(/[ ]+/g, " ")
).toBe(result);
};
exports.startApp = async (configFile, additionalMockData) => {
let mockWeather;
if (configFile.includes("forecast")) {
mockWeather = generateWeatherForecast(additionalMockData);
} else {
mockWeather = generateWeather(additionalMockData);
}
let content = fs.readFileSync(path.resolve(__dirname + "../../../../" + configFile)).toString();
content = content.replace("#####WEATHERDATA#####", mockWeather);
fs.writeFileSync(path.resolve(__dirname + "../../../../config/config.js"), content);
helpers.startApplication("");
await helpers.getDocument();
};

View File

@@ -0,0 +1,130 @@
const moment = require("moment");
const helpers = require("../global-setup");
const weatherFunc = require("./weather-functions");
describe("Weather module", () => {
afterAll(async () => {
await helpers.stopApplication();
});
describe("Current weather", () => {
describe("Default configuration", () => {
beforeAll(async () => {
await weatherFunc.startApp("tests/configs/modules/weather/currentweather_default.js", {});
});
it("should render wind speed and wind direction", async () => {
await weatherFunc.getText(".weather .normal.medium span:nth-child(2)", "6 WSW"); // now "12"
});
it("should render temperature with icon", async () => {
await weatherFunc.getText(".weather .large.light span.bright", "1.5°"); // now "1°C"
});
it("should render feels like temperature", async () => {
await weatherFunc.getText(".weather .normal.medium.feelslike span.dimmed", "Feels like -5.6°"); // now "Feels like -6°C"
});
});
describe("Default configuration with sunrise", () => {
beforeAll(async () => {
const sunrise = moment().startOf("day").unix();
const sunset = moment().startOf("day").unix();
await weatherFunc.startApp("tests/configs/modules/weather/currentweather_default.js", { sys: { sunrise, sunset } });
});
it("should render sunrise", async () => {
await weatherFunc.getText(".weather .normal.medium span:nth-child(4)", "12:00 am");
});
});
describe("Default configuration with sunset", () => {
beforeAll(async () => {
const sunrise = moment().startOf("day").unix();
const sunset = moment().endOf("day").unix();
await weatherFunc.startApp("tests/configs/modules/weather/currentweather_default.js", { sys: { sunrise, sunset } });
});
it("should render sunset", async () => {
await weatherFunc.getText(".weather .normal.medium span:nth-child(4)", "11:59 pm");
});
});
});
describe("Compliments Integration", () => {
beforeAll(async () => {
await weatherFunc.startApp("tests/configs/modules/weather/currentweather_compliments.js", {});
});
it("should render a compliment based on the current weather", async () => {
await weatherFunc.getText(".compliments .module-content span", "snow");
});
});
describe("Configuration Options", () => {
beforeAll(async () => {
await weatherFunc.startApp("tests/configs/modules/weather/currentweather_options.js", {});
});
it("should render useBeaufort = false", async () => {
await weatherFunc.getText(".weather .normal.medium span:nth-child(2)", "12");
});
it("should render showWindDirectionAsArrow = true", async () => {
const elem = await helpers.waitForElement(".weather .normal.medium sup i.fa-long-arrow-alt-up");
expect(elem).not.toBe(null);
expect(elem.outerHTML).toContain("transform:rotate(250deg);");
});
it("should render showHumidity = true", async () => {
await weatherFunc.getText(".weather .normal.medium span:nth-child(3)", "93.7");
});
it("should render degreeLabel = true for temp", async () => {
await weatherFunc.getText(".weather .large.light span.bright", "1°C");
});
it("should render degreeLabel = true for feels like", async () => {
await weatherFunc.getText(".weather .normal.medium.feelslike span.dimmed", "Feels like -6°C");
});
});
describe("Current weather units", () => {
beforeAll(async () => {
await weatherFunc.startApp("tests/configs/modules/weather/currentweather_units.js", {
main: {
temp: (1.49 * 9) / 5 + 32,
temp_min: (1 * 9) / 5 + 32,
temp_max: (2 * 9) / 5 + 32
},
wind: {
speed: 11.8 * 2.23694
}
});
});
it("should render imperial units for wind", async () => {
await weatherFunc.getText(".weather .normal.medium span:nth-child(2)", "6 WSW");
});
it("should render imperial units for temp", async () => {
await weatherFunc.getText(".weather .large.light span.bright", "34,7°");
});
it("should render imperial units for feels like", async () => {
await weatherFunc.getText(".weather .normal.medium.feelslike span.dimmed", "Feels like 22,0°");
});
it("should render custom decimalSymbol = ',' for humidity", async () => {
await weatherFunc.getText(".weather .normal.medium span:nth-child(3)", "93,7");
});
it("should render custom decimalSymbol = ',' for temp", async () => {
await weatherFunc.getText(".weather .large.light span.bright", "34,7°");
});
it("should render custom decimalSymbol = ',' for feels like", async () => {
await weatherFunc.getText(".weather .normal.medium.feelslike span.dimmed", "Feels like 22,0°");
});
});
});

View File

@@ -0,0 +1,96 @@
const helpers = require("../global-setup");
const weatherFunc = require("./weather-functions");
describe("Weather module: Weather Forecast", () => {
afterAll(async () => {
await helpers.stopApplication();
});
describe("Default configuration", () => {
beforeAll(async () => {
await weatherFunc.startApp("tests/configs/modules/weather/forecastweather_default.js", {});
});
const days = ["Today", "Tomorrow", "Sun", "Mon", "Tue"];
for (const [index, day] of days.entries()) {
it("should render day " + day, async () => {
await weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`, day);
});
}
const icons = ["day-cloudy", "rain", "day-sunny", "day-sunny", "day-sunny"];
for (const [index, icon] of icons.entries()) {
it("should render icon " + icon, async () => {
const elem = await helpers.waitForElement(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(2) span.wi-${icon}`);
expect(elem).not.toBe(null);
});
}
const maxTemps = ["24.4°", "21.0°", "22.9°", "23.4°", "20.6°"];
for (const [index, temp] of maxTemps.entries()) {
it("should render max temperature " + temp, async () => {
await weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp);
});
}
const minTemps = ["15.3°", "13.6°", "13.8°", "13.9°", "10.9°"];
for (const [index, temp] of minTemps.entries()) {
it("should render min temperature " + temp, async () => {
await weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(4)`, temp);
});
}
const opacities = [1, 1, 0.8, 0.5333333333333333, 0.2666666666666667];
for (const [index, opacity] of opacities.entries()) {
it("should render fading of rows with opacity=" + opacity, async () => {
const elem = await helpers.waitForElement(`.weather table.small tr:nth-child(${index + 1})`);
expect(elem).not.toBe(null);
expect(elem.outerHTML).toContain(`<tr style="opacity: ${opacity};">`);
});
}
});
describe("Absolute configuration", () => {
beforeAll(async () => {
await weatherFunc.startApp("tests/configs/modules/weather/forecastweather_absolute.js", {});
});
const days = ["Fri", "Sat", "Sun", "Mon", "Tue"];
for (const [index, day] of days.entries()) {
it("should render day " + day, async () => {
await weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`, day);
});
}
});
describe("Configuration Options", () => {
beforeAll(async () => {
await weatherFunc.startApp("tests/configs/modules/weather/forecastweather_options.js", {});
});
it("should render custom table class", async () => {
const elem = await helpers.waitForElement(".weather table.myTableClass");
expect(elem).not.toBe(null);
});
it("should render colored rows", async () => {
const table = await helpers.waitForElement(".weather table.myTableClass");
expect(table).not.toBe(null);
expect(table.rows).not.toBe(null);
expect(table.rows.length).toBe(5);
});
});
describe("Forecast weather units", () => {
beforeAll(async () => {
await weatherFunc.startApp("tests/configs/modules/weather/forecastweather_units.js", {});
});
const temperatures = ["24_4°", "21_0°", "22_9°", "23_4°", "20_6°"];
for (const [index, temp] of temperatures.entries()) {
it("should render custom decimalSymbol = '_' for temp " + temp, async () => {
await weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp);
});
}
});
});

View File

@@ -1,273 +0,0 @@
const moment = require("moment");
const helpers = require("../global-setup");
const path = require("path");
const fs = require("fs");
const { generateWeather, generateWeatherForecast } = require("./mocks");
describe("Weather module", () => {
/**
* @param {string} done test done
* @param {string} element css selector
* @param {string} result Expected text in given selector
*/
const getText = (done, element, result) => {
helpers.waitForElement(element).then((elem) => {
done();
expect(elem).not.toBe(null);
expect(
elem.textContent
.trim()
.replace(/(\r\n|\n|\r)/gm, "")
.replace(/[ ]+/g, " ")
).toBe(result);
});
};
/**
* @param {string} configFile path to configuration file
* @param {string} additionalMockData special data for mocking
* @param {string} callback callback
*/
const startApp = (configFile, additionalMockData, callback) => {
let mockWeather;
if (configFile.includes("forecast")) {
mockWeather = generateWeatherForecast(additionalMockData);
} else {
mockWeather = generateWeather(additionalMockData);
}
let content = fs.readFileSync(path.resolve(__dirname + "../../../../" + configFile)).toString();
content = content.replace("#####WEATHERDATA#####", mockWeather);
fs.writeFileSync(path.resolve(__dirname + "../../../../config/config.js"), content);
helpers.startApplication("");
helpers.getDocument(callback);
};
afterAll(async () => {
await helpers.stopApplication();
});
describe("Current weather", () => {
describe("Default configuration", () => {
beforeAll((done) => {
startApp("tests/configs/modules/weather/currentweather_default.js", {}, done);
});
it("should render wind speed and wind direction", (done) => {
getText(done, ".weather .normal.medium span:nth-child(2)", "6 WSW"); // now "12"
});
it("should render temperature with icon", (done) => {
getText(done, ".weather .large.light span.bright", "1.5°"); // now "1°C"
});
it("should render feels like temperature", (done) => {
getText(done, ".weather .normal.medium.feelslike span.dimmed", "Feels like -5.6°"); // now "Feels like -6°C"
});
});
describe("Default configuration with sunrise", () => {
beforeAll((done) => {
const sunrise = moment().startOf("day").unix();
const sunset = moment().startOf("day").unix();
startApp("tests/configs/modules/weather/currentweather_default.js", { sys: { sunrise, sunset } }, done);
});
it("should render sunrise", (done) => {
getText(done, ".weather .normal.medium span:nth-child(4)", "12:00 am");
});
});
describe("Default configuration with sunset", () => {
beforeAll((done) => {
const sunrise = moment().startOf("day").unix();
const sunset = moment().endOf("day").unix();
startApp("tests/configs/modules/weather/currentweather_default.js", { sys: { sunrise, sunset } }, done);
});
it("should render sunset", (done) => {
getText(done, ".weather .normal.medium span:nth-child(4)", "11:59 pm");
});
});
});
describe("Compliments Integration", () => {
beforeAll((done) => {
startApp("tests/configs/modules/weather/currentweather_compliments.js", {}, done);
});
it("should render a compliment based on the current weather", (done) => {
getText(done, ".compliments .module-content span", "snow");
});
});
describe("Configuration Options", () => {
beforeAll((done) => {
startApp("tests/configs/modules/weather/currentweather_options.js", {}, done);
});
it("should render useBeaufort = false", (done) => {
getText(done, ".weather .normal.medium span:nth-child(2)", "12");
});
it("should render showWindDirectionAsArrow = true", (done) => {
helpers.waitForElement(".weather .normal.medium sup i.fa-long-arrow-alt-up").then((elem) => {
done();
expect(elem).not.toBe(null);
expect(elem.outerHTML).toContain("transform:rotate(250deg);");
});
});
it("should render showHumidity = true", (done) => {
getText(done, ".weather .normal.medium span:nth-child(3)", "93.7");
});
it("should render degreeLabel = true for temp", (done) => {
getText(done, ".weather .large.light span.bright", "1°C");
});
it("should render degreeLabel = true for feels like", (done) => {
getText(done, ".weather .normal.medium.feelslike span.dimmed", "Feels like -6°C");
});
});
describe("Current weather units", () => {
beforeAll((done) => {
startApp(
"tests/configs/modules/weather/currentweather_units.js",
{
main: {
temp: (1.49 * 9) / 5 + 32,
temp_min: (1 * 9) / 5 + 32,
temp_max: (2 * 9) / 5 + 32
},
wind: {
speed: 11.8 * 2.23694
}
},
done
);
});
it("should render imperial units for wind", (done) => {
getText(done, ".weather .normal.medium span:nth-child(2)", "6 WSW");
});
it("should render imperial units for temp", (done) => {
getText(done, ".weather .large.light span.bright", "34,7°");
});
it("should render imperial units for feels like", (done) => {
getText(done, ".weather .normal.medium.feelslike span.dimmed", "Feels like 22,0°");
});
it("should render custom decimalSymbol = ',' for humidity", (done) => {
getText(done, ".weather .normal.medium span:nth-child(3)", "93,7");
});
it("should render custom decimalSymbol = ',' for temp", (done) => {
getText(done, ".weather .large.light span.bright", "34,7°");
});
it("should render custom decimalSymbol = ',' for feels like", (done) => {
getText(done, ".weather .normal.medium.feelslike span.dimmed", "Feels like 22,0°");
});
});
describe("Weather Forecast", () => {
describe("Default configuration", () => {
beforeAll((done) => {
startApp("tests/configs/modules/weather/forecastweather_default.js", {}, done);
});
const days = ["Today", "Tomorrow", "Sun", "Mon", "Tue"];
for (const [index, day] of days.entries()) {
it("should render day " + day, (done) => {
getText(done, `.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`, day);
});
}
const icons = ["day-cloudy", "rain", "day-sunny", "day-sunny", "day-sunny"];
for (const [index, icon] of icons.entries()) {
it("should render icon " + icon, (done) => {
helpers.waitForElement(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(2) span.wi-${icon}`).then((elem) => {
done();
expect(elem).not.toBe(null);
});
});
}
const maxTemps = ["24.4°", "21.0°", "22.9°", "23.4°", "20.6°"];
for (const [index, temp] of maxTemps.entries()) {
it("should render max temperature " + temp, (done) => {
getText(done, `.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp);
});
}
const minTemps = ["15.3°", "13.6°", "13.8°", "13.9°", "10.9°"];
for (const [index, temp] of minTemps.entries()) {
it("should render min temperature " + temp, (done) => {
getText(done, `.weather table.small tr:nth-child(${index + 1}) td:nth-child(4)`, temp);
});
}
const opacities = [1, 1, 0.8, 0.5333333333333333, 0.2666666666666667];
for (const [index, opacity] of opacities.entries()) {
it("should render fading of rows with opacity=" + opacity, (done) => {
helpers.waitForElement(`.weather table.small tr:nth-child(${index + 1})`).then((elem) => {
done();
expect(elem).not.toBe(null);
expect(elem.outerHTML).toContain(`<tr style="opacity: ${opacity};">`);
});
});
}
});
describe("Absolute configuration", () => {
beforeAll((done) => {
startApp("tests/configs/modules/weather/forecastweather_absolute.js", {}, done);
});
const days = ["Fri", "Sat", "Sun", "Mon", "Tue"];
for (const [index, day] of days.entries()) {
it("should render day " + day, (done) => {
getText(done, `.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`, day);
});
}
});
describe("Configuration Options", () => {
beforeAll((done) => {
startApp("tests/configs/modules/weather/forecastweather_options.js", {}, done);
});
it("should render custom table class", (done) => {
helpers.waitForElement(".weather table.myTableClass").then((elem) => {
done();
expect(elem).not.toBe(null);
});
});
it("should render colored rows", (done) => {
helpers.waitForElement(".weather table.myTableClass").then((table) => {
done();
expect(table).not.toBe(null);
expect(table.rows).not.toBe(null);
expect(table.rows.length).toBe(5);
});
});
});
describe("Forecast weather units", () => {
beforeAll((done) => {
startApp("tests/configs/modules/weather/forecastweather_units.js", {}, done);
});
const temperatures = ["24_4°", "21_0°", "22_9°", "23_4°", "20_6°"];
for (const [index, temp] of temperatures.entries()) {
it("should render custom decimalSymbol = '_' for temp " + temp, (done) => {
getText(done, `.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp);
});
}
});
});
});