testing wait alternatives

This commit is contained in:
Karsten Hassel
2022-01-13 00:13:29 +01:00
parent 65fada7ef1
commit 42b80b18f8
4 changed files with 52 additions and 27 deletions

View File

@@ -9,13 +9,20 @@ describe("Calendar module", function () {
* @param {string} not reverse result
*/
function testElementLength(element, result, not) {
const elem = document.querySelectorAll(element);
helpers.waitForElement(element).then((elem) => {
expect(elem).not.toBe(null);
if (not === "not") {
expect(elem.length).not.toBe(result);
} else {
expect(elem.length).toBe(result);
}
})
}
const testTextContain = function (element, text) {
const elem = document.querySelector(".calendar");
expect(elem).not.toBe(null);
if (not === "not") {
expect(elem.length).not.toBe(result);
} else {
expect(elem.length).toBe(result);
}
expect(elem.textContent).toContain(text);
}
afterAll(function () {
@@ -25,7 +32,7 @@ describe("Calendar module", function () {
describe("Default configuration", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/calendar/default.js");
helpers.getDocument(done, testDelay);
helpers.getDocument(done);
});
it("should show the default maximumEntries of 10", () => {
@@ -40,7 +47,7 @@ describe("Calendar module", function () {
describe("Custom configuration", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/calendar/custom.js");
helpers.getDocument(done, testDelay);
helpers.getDocument(done);
});
it("should show the custom maximumEntries of 4", () => {
@@ -63,7 +70,7 @@ describe("Calendar module", function () {
describe("Recurring event", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/calendar/recurring.js");
helpers.getDocument(done, testDelay);
helpers.getDocument(done);
});
it("should show the recurring birthday event 6 times", () => {
@@ -83,9 +90,7 @@ describe("Calendar module", function () {
});
it('should contain text "Mar 25th" in timezone UTC ' + -i, () => {
const elem = document.querySelector(".calendar");
expect(elem).not.toBe(null);
expect(elem.textContent).toContain("Mar 25th");
testTextContain(".calendar", "Mar 25th");
});
});
}
@@ -94,7 +99,7 @@ describe("Calendar module", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/calendar/changed-port.js");
serverBasicAuth.listen(8010);
helpers.getDocument(done, testDelay);
helpers.getDocument(done);
});
afterAll(function (done) {
@@ -109,7 +114,7 @@ describe("Calendar module", function () {
describe("Basic auth", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/calendar/basic-auth.js");
helpers.getDocument(done, testDelay);
helpers.getDocument(done);
});
it("should return TestEvents", function () {
@@ -120,7 +125,7 @@ describe("Calendar module", function () {
describe("Basic auth by default", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/calendar/auth-default.js");
helpers.getDocument(done, testDelay);
helpers.getDocument(done);
});
it("should return TestEvents", function () {
@@ -131,7 +136,7 @@ describe("Calendar module", function () {
describe("Basic auth backward compatibility configuration: DEPRECATED", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/calendar/old-basic-auth.js");
helpers.getDocument(done, testDelay);
helpers.getDocument(done);
});
it("should return TestEvents", function () {
@@ -151,9 +156,7 @@ describe("Calendar module", function () {
});
it("should show Unauthorized error", function () {
const elem = document.querySelector(".calendar");
expect(elem).not.toBe(null);
expect(elem.textContent).toContain("Error in the calendar module. Authorization failed");
testTextContain(".calendar", "Error in the calendar module. Authorization failed");
});
});
});

View File

@@ -15,7 +15,7 @@ describe("Clock module", function () {
describe("with default 24hr clock config", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/clock/clock_24hr.js");
helpers.getDocument(done, 1000);
helpers.getDocument(done);
});
it("should show the date in the correct format", function () {
@@ -32,7 +32,7 @@ describe("Clock module", function () {
describe("with default 12hr clock config", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/clock/clock_12hr.js");
helpers.getDocument(done, 1000);
helpers.getDocument(done);
});
it("should show the date in the correct format", function () {
@@ -49,7 +49,7 @@ describe("Clock module", function () {
describe("with showPeriodUpper config enabled", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/clock/clock_showPeriodUpper.js");
helpers.getDocument(done, 1000);
helpers.getDocument(done);
});
it("should show 12hr time with upper case AM/PM", function () {
@@ -61,7 +61,7 @@ describe("Clock module", function () {
describe("with displaySeconds config disabled", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/clock/clock_displaySeconds_false.js");
helpers.getDocument(done, 1000);
helpers.getDocument(done);
});
it("should show 12hr time without seconds am/pm", function () {
@@ -73,7 +73,7 @@ describe("Clock module", function () {
describe("with showTime config disabled", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/clock/clock_showTime.js");
helpers.getDocument(done, 1000);
helpers.getDocument(done);
});
it("should show not show the time when digital clock is shown", function () {
@@ -85,7 +85,7 @@ describe("Clock module", function () {
describe("with showWeek config enabled", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/clock/clock_showWeek.js");
helpers.getDocument(done, 1000);
helpers.getDocument(done);
});
it("should show the week in the correct format", function () {
@@ -105,7 +105,7 @@ describe("Clock module", function () {
describe("with analog clock face enabled", function () {
beforeAll(function (done) {
helpers.startApplication("tests/configs/modules/clock/clock_analog.js");
helpers.getDocument(done, 1000);
helpers.getDocument(done);
});
it("should show the analog clock face", () => {