fix e2e tests after spectron update

This commit is contained in:
Karsten Hassel
2021-02-06 23:52:44 +01:00
parent 6fadc76fe3
commit 7ba76020d8
6 changed files with 54 additions and 56 deletions

View File

@@ -23,6 +23,17 @@ describe("Weather module", function () {
app.client.setupStub();
}
async function getElement(element) {
return await app.client.$(element);
}
async function getText(element, result) {
const elem = await getElement(element);
return await elem.getText(element).then(function (text) {
expect(text.trim()).to.equal(result);
});
}
afterEach(function () {
return helpers.stopApplication(app);
});
@@ -43,7 +54,7 @@ describe("Weather module", function () {
const weather = generateWeather();
await setup({ template, data: weather });
return await app.client.$(".weather .normal.medium span:nth-child(2)", "6 WSW", 10000);
return getText(".weather .normal.medium span:nth-child(2)", "6 WSW");
});
it("should render sunrise", async function () {
@@ -53,9 +64,7 @@ describe("Weather module", function () {
const weather = generateWeather({ sys: { sunrise, sunset } });
await setup({ template, data: weather });
await app.client.$(".weather .normal.medium span.wi.dimmed.wi-sunrise", 10000);
return await app.client.$(".weather .normal.medium span:nth-child(4)", "12:00 am", 10000);
return getText(".weather .normal.medium span:nth-child(4)", "12:00 am");
});
it("should render sunset", async function () {
@@ -65,25 +74,21 @@ describe("Weather module", function () {
const weather = generateWeather({ sys: { sunrise, sunset } });
await setup({ template, data: weather });
await app.client.$(".weather .normal.medium span.wi.dimmed.wi-sunset", 10000);
return await app.client.$(".weather .normal.medium span:nth-child(4)", "11:59 pm", 10000);
return getText(".weather .normal.medium span:nth-child(4)", "11:59 pm");
});
it("should render temperature with icon", async function () {
const weather = generateWeather();
await setup({ template, data: weather });
await app.client.$(".weather .large.light span.wi.weathericon.wi-snow", 10000);
return await app.client.$(".weather .large.light span.bright", "1.5°", 10000);
return getText(".weather .large.light span.bright", "1.5°");
});
it("should render feels like temperature", async function () {
const weather = generateWeather();
await setup({ template, data: weather });
return await app.client.$(".weather .normal.medium span.dimmed", "Feels like -5.6°", 10000);
return getText(".weather .normal.medium.feelslike span.dimmed", "Feels like -5.6°");
});
});
@@ -96,7 +101,16 @@ describe("Weather module", function () {
const weather = generateWeather();
await setup({ template, data: weather });
return await app.client.$(".compliments .module-content span", "snow", 10000);
const wait = (time) => new Promise((resolve) => setTimeout(resolve, time));
var text = "";
do {
await wait(3000);
elem = await app.client.$(".compliments");
text = await elem.getText(".compliments .module-content span");
} while (text === "");
return expect(text.trim()).to.equal("snow");
});
});
@@ -109,34 +123,31 @@ describe("Weather module", function () {
const weather = generateWeather();
await setup({ template, data: weather });
return await app.client.$(".weather .normal.medium span:nth-child(2)", "12", 10000);
return getText(".weather .normal.medium span:nth-child(2)", "12");
});
it("should render showWindDirectionAsArrow = true", async function () {
const weather = generateWeather();
await setup({ template, data: weather });
const elem = await app.client.$(".weather .normal.medium sup i.fa-long-arrow-up", 10000);
const element = await elem.getHTML(".weather .normal.medium sup i.fa-long-arrow-up");
expect(element).to.include("transform:rotate(250deg);");
const elem = await getElement(".weather .normal.medium sup i.fa-long-arrow-up");
return elem.getHTML(".weather .normal.medium sup i.fa-long-arrow-up").then(function (text) {
expect(text).to.include("transform:rotate(250deg);");
});
});
it("should render showHumidity = true", async function () {
const weather = generateWeather();
await setup({ template, data: weather });
await app.client.$(".weather .normal.medium span:nth-child(3)", "93", 10000);
return await app.client.$(".weather .normal.medium sup i.wi-humidity", 10000);
return getText(".weather .normal.medium span:nth-child(3)", "93.7");
});
it("should render degreeLabel = true", async function () {
const weather = generateWeather();
await setup({ template, data: weather });
await app.client.$(".weather .large.light span.bright", "1°C", 10000);
return await app.client.$(".weather .normal.medium span.dimmed", "Feels like -6°C", 10000);
return getText(".weather .large.light span.bright", "1°C") && getText(".weather .normal.medium.feelslike span.dimmed", "Feels like -6°C");
});
});
@@ -158,9 +169,7 @@ describe("Weather module", function () {
});
await setup({ template, data: weather });
await app.client.$(".weather .normal.medium span:nth-child(2)", "6 WSW", 10000);
await app.client.$(".weather .large.light span.bright", "34,7°", 10000);
return await app.client.$(".weather .normal.medium span.dimmed", "22,0°", 10000);
return getText(".weather .normal.medium span:nth-child(2)", "6 WSW") && getText(".weather .large.light span.bright", "34,7°") && getText(".weather .normal.medium.feelslike span.dimmed", "Feels like 22,0°");
});
it("should render decimalSymbol = ','", async function () {
@@ -176,9 +185,7 @@ describe("Weather module", function () {
});
await setup({ template, data: weather });
await app.client.$(".weather .normal.medium span:nth-child(3)", "93,7", 10000);
await app.client.$(".weather .large.light span.bright", "34,7°", 10000);
return await app.client.$(".weather .normal.medium span.dimmed", "22,0°", 10000);
return getText(".weather .normal.medium span:nth-child(3)", "93,7") && getText(".weather .large.light span.bright", "34,7°") && getText(".weather .normal.medium.feelslike span.dimmed", "Feels like 22,0°");
});
});
});
@@ -202,7 +209,7 @@ describe("Weather module", function () {
const days = ["Today", "Tomorrow", "Sun", "Mon", "Tue"];
for (const [index, day] of days.entries()) {
await app.client.$(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`, day, 10000);
getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`, day);
}
});
@@ -213,7 +220,7 @@ describe("Weather module", function () {
const icons = ["day-cloudy", "rain", "day-sunny", "day-sunny", "day-sunny"];
for (const [index, icon] of icons.entries()) {
await app.client.$(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(2) span.wi-${icon}`, 10000);
getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(2) span.wi-${icon}`);
}
});
@@ -224,7 +231,7 @@ describe("Weather module", function () {
const temperatures = ["24.4°", "21.0°", "22.9°", "23.4°", "20.6°"];
for (const [index, temp] of temperatures.entries()) {
await app.client.$(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp, 10000);
getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp);
}
});
@@ -235,7 +242,7 @@ describe("Weather module", function () {
const temperatures = ["15.3°", "13.6°", "13.8°", "13.9°", "10.9°"];
for (const [index, temp] of temperatures.entries()) {
await app.client.$(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(4)`, temp, 10000);
getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(4)`, temp);
}
});
@@ -245,7 +252,7 @@ describe("Weather module", function () {
const opacities = [1, 1, 0.8, 0.5333333333333333, 0.2666666666666667];
const elem = await app.client.$(".weather table.small", 10000);
const elem = await getElement(".weather table.small");
for (const [index, opacity] of opacities.entries()) {
const html = await elem.getHTML(`.weather table.small tr:nth-child(${index + 1})`);
@@ -263,15 +270,13 @@ describe("Weather module", function () {
const weather = generateWeatherForecast();
await setup({ template, data: weather });
await app.client.$(".weather table.myTableClass", 10000);
await getElement(".weather table.myTableClass");
});
it("should render colored rows", async function () {
const weather = generateWeatherForecast();
await setup({ template, data: weather });
await app.client.$(".weather table.myTableClass", 10000);
const rows = await app.client.$$(".weather table.myTableClass tr.colored");
expect(rows.length).to.be.equal(5);