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

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