2019-09-11 12:27:06 +02:00
|
|
|
const expect = require("chai").expect;
|
2019-01-13 23:57:19 +01:00
|
|
|
const fs = require("fs");
|
|
|
|
const moment = require("moment");
|
2019-09-11 15:58:51 +02:00
|
|
|
const path = require("path");
|
2019-01-13 23:57:19 +01:00
|
|
|
const wdajaxstub = require("webdriverajaxstub");
|
|
|
|
|
|
|
|
const helpers = require("../global-setup");
|
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
const { generateWeather, generateWeatherForecast } = require("./mocks");
|
2020-01-23 19:38:15 +01:00
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
describe("Weather module", function () {
|
2019-01-13 23:57:19 +01:00
|
|
|
let app;
|
|
|
|
|
|
|
|
helpers.setupTimeout(this);
|
|
|
|
|
|
|
|
async function setup(responses) {
|
|
|
|
app = await helpers.startApplication({
|
|
|
|
args: ["js/electron.js"]
|
|
|
|
});
|
|
|
|
|
|
|
|
wdajaxstub.init(app.client, responses);
|
|
|
|
|
|
|
|
app.client.setupStub();
|
|
|
|
}
|
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
afterEach(function () {
|
2019-01-13 23:57:19 +01:00
|
|
|
return helpers.stopApplication(app);
|
|
|
|
});
|
2019-01-13 23:59:05 +01:00
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
describe("Current weather", function () {
|
2019-01-13 23:59:05 +01:00
|
|
|
let template;
|
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
before(function () {
|
2019-09-11 15:58:51 +02:00
|
|
|
template = fs.readFileSync(path.join(__dirname, "..", "..", "..", "modules", "default", "weather", "current.njk"), "utf8");
|
2019-01-13 23:59:05 +01:00
|
|
|
});
|
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
describe("Default configuration", function () {
|
|
|
|
before(function () {
|
2019-01-13 23:59:05 +01:00
|
|
|
process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/currentweather_default.js";
|
|
|
|
});
|
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
it("should render wind speed and wind direction", async function () {
|
2019-12-29 14:30:12 +01:00
|
|
|
const weather = generateWeather();
|
2020-05-11 22:22:32 +02:00
|
|
|
await setup({ template, data: weather });
|
2019-01-13 23:59:05 +01:00
|
|
|
|
2019-12-29 14:30:12 +01:00
|
|
|
return app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(2)", "6 WSW", 10000);
|
|
|
|
});
|
2019-01-13 23:59:05 +01:00
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
it("should render sunrise", async function () {
|
2019-09-11 15:58:51 +02:00
|
|
|
const sunrise = moment().startOf("day").unix();
|
|
|
|
const sunset = moment().startOf("day").unix();
|
2019-01-13 23:59:05 +01:00
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
const weather = generateWeather({ sys: { sunrise, sunset } });
|
|
|
|
await setup({ template, data: weather });
|
2019-01-13 23:59:05 +01:00
|
|
|
|
|
|
|
await app.client.waitForExist(".weather .normal.medium span.wi.dimmed.wi-sunrise", 10000);
|
|
|
|
|
2019-09-11 15:58:51 +02:00
|
|
|
return app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(4)", "12:00 am", 10000);
|
2019-01-13 23:59:05 +01:00
|
|
|
});
|
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
it("should render sunset", async function () {
|
2019-09-11 15:58:51 +02:00
|
|
|
const sunrise = moment().startOf("day").unix();
|
|
|
|
const sunset = moment().endOf("day").unix();
|
2019-01-13 23:59:05 +01:00
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
const weather = generateWeather({ sys: { sunrise, sunset } });
|
|
|
|
await setup({ template, data: weather });
|
2019-01-13 23:59:05 +01:00
|
|
|
|
|
|
|
await app.client.waitForExist(".weather .normal.medium span.wi.dimmed.wi-sunset", 10000);
|
|
|
|
|
2019-09-11 15:58:51 +02:00
|
|
|
return app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(4)", "11:59 pm", 10000);
|
2019-01-13 23:59:05 +01:00
|
|
|
});
|
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
it("should render temperature with icon", async function () {
|
2019-01-13 23:59:05 +01:00
|
|
|
const weather = generateWeather();
|
2020-05-11 22:22:32 +02:00
|
|
|
await setup({ template, data: weather });
|
2019-01-13 23:59:05 +01:00
|
|
|
|
|
|
|
await app.client.waitForExist(".weather .large.light span.wi.weathericon.wi-snow", 10000);
|
|
|
|
|
2019-09-11 15:58:51 +02:00
|
|
|
return app.client.waitUntilTextExists(".weather .large.light span.bright", "1.5°", 10000);
|
2019-01-13 23:59:05 +01:00
|
|
|
});
|
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
it("should render feels like temperature", async function () {
|
2019-01-13 23:59:05 +01:00
|
|
|
const weather = generateWeather();
|
2020-05-11 22:22:32 +02:00
|
|
|
await setup({ template, data: weather });
|
2019-01-13 23:59:05 +01:00
|
|
|
|
2019-09-11 15:58:51 +02:00
|
|
|
return app.client.waitUntilTextExists(".weather .normal.medium span.dimmed", "Feels like -5.6°", 10000);
|
2019-01-13 23:59:05 +01:00
|
|
|
});
|
|
|
|
});
|
2019-09-11 12:27:06 +02:00
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
describe("Configuration Options", function () {
|
|
|
|
before(function () {
|
2019-09-11 12:27:06 +02:00
|
|
|
process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/currentweather_options.js";
|
|
|
|
});
|
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
it("should render useBeaufort = false", async function () {
|
2019-09-11 12:27:06 +02:00
|
|
|
const weather = generateWeather();
|
2020-05-11 22:22:32 +02:00
|
|
|
await setup({ template, data: weather });
|
2019-09-11 12:27:06 +02:00
|
|
|
|
2019-09-11 15:58:51 +02:00
|
|
|
return app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(2)", "12", 10000);
|
2019-09-11 12:27:06 +02:00
|
|
|
});
|
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
it("should render showWindDirectionAsArrow = true", async function () {
|
2019-09-11 12:27:06 +02:00
|
|
|
const weather = generateWeather();
|
2020-05-11 22:22:32 +02:00
|
|
|
await setup({ template, data: weather });
|
2019-09-11 12:27:06 +02:00
|
|
|
|
2019-09-11 15:58:51 +02:00
|
|
|
await app.client.waitForExist(".weather .normal.medium sup i.fa-long-arrow-up", 10000);
|
|
|
|
const element = await app.client.getHTML(".weather .normal.medium sup i.fa-long-arrow-up");
|
2019-09-11 12:27:06 +02:00
|
|
|
|
|
|
|
expect(element).to.include("transform:rotate(250deg);");
|
|
|
|
});
|
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
it("should render showHumidity = true", async function () {
|
2019-09-11 12:27:06 +02:00
|
|
|
const weather = generateWeather();
|
2020-05-11 22:22:32 +02:00
|
|
|
await setup({ template, data: weather });
|
2019-09-11 12:27:06 +02:00
|
|
|
|
2019-09-11 15:58:51 +02:00
|
|
|
await app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(3)", "93", 10000);
|
|
|
|
return app.client.waitForExist(".weather .normal.medium sup i.wi-humidity", 10000);
|
2019-09-11 12:27:06 +02:00
|
|
|
});
|
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
it("should render degreeLabel = true", async function () {
|
2019-09-11 12:27:06 +02:00
|
|
|
const weather = generateWeather();
|
2020-05-11 22:22:32 +02:00
|
|
|
await setup({ template, data: weather });
|
2019-09-11 12:27:06 +02:00
|
|
|
|
2019-09-11 15:58:51 +02:00
|
|
|
await app.client.waitUntilTextExists(".weather .large.light span.bright", "1°C", 10000);
|
2019-09-11 12:27:06 +02:00
|
|
|
|
2019-09-11 15:58:51 +02:00
|
|
|
return app.client.waitUntilTextExists(".weather .normal.medium span.dimmed", "Feels like -6°C", 10000);
|
2019-09-11 12:27:06 +02:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
describe("Current weather units", function () {
|
|
|
|
before(function () {
|
2019-09-11 12:27:06 +02:00
|
|
|
process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/currentweather_units.js";
|
|
|
|
});
|
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
it("should render imperial units", async function () {
|
2019-09-11 12:27:06 +02:00
|
|
|
const weather = generateWeather({
|
2020-05-11 22:22:32 +02:00
|
|
|
main: {
|
|
|
|
temp: (1.49 * 9) / 5 + 32,
|
|
|
|
temp_min: (1 * 9) / 5 + 32,
|
|
|
|
temp_max: (2 * 9) / 5 + 32
|
2019-09-11 12:27:06 +02:00
|
|
|
},
|
2020-05-11 22:22:32 +02:00
|
|
|
wind: {
|
2019-09-11 12:27:06 +02:00
|
|
|
speed: 11.8 * 2.23694
|
2020-05-11 22:22:32 +02:00
|
|
|
}
|
2019-09-11 12:27:06 +02:00
|
|
|
});
|
2020-05-11 22:22:32 +02:00
|
|
|
await setup({ template, data: weather });
|
2019-09-11 12:27:06 +02:00
|
|
|
|
2019-09-11 15:58:51 +02:00
|
|
|
await app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(2)", "6 WSW", 10000);
|
|
|
|
await app.client.waitUntilTextExists(".weather .large.light span.bright", "34,7°", 10000);
|
|
|
|
return app.client.waitUntilTextExists(".weather .normal.medium span.dimmed", "22,0°", 10000);
|
2019-09-11 12:27:06 +02:00
|
|
|
});
|
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
it("should render decimalSymbol = ','", async function () {
|
2019-09-11 12:27:06 +02:00
|
|
|
const weather = generateWeather({
|
2020-05-11 22:22:32 +02:00
|
|
|
main: {
|
|
|
|
temp: (1.49 * 9) / 5 + 32,
|
|
|
|
temp_min: (1 * 9) / 5 + 32,
|
|
|
|
temp_max: (2 * 9) / 5 + 32
|
2019-09-11 12:27:06 +02:00
|
|
|
},
|
2020-05-11 22:22:32 +02:00
|
|
|
wind: {
|
2019-09-11 12:27:06 +02:00
|
|
|
speed: 11.8 * 2.23694
|
2020-05-11 22:22:32 +02:00
|
|
|
}
|
2019-09-11 12:27:06 +02:00
|
|
|
});
|
2020-05-11 22:22:32 +02:00
|
|
|
await setup({ template, data: weather });
|
2019-09-11 12:27:06 +02:00
|
|
|
|
2019-09-11 15:58:51 +02:00
|
|
|
await app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(3)", "93,7", 10000);
|
|
|
|
await app.client.waitUntilTextExists(".weather .large.light span.bright", "34,7°", 10000);
|
|
|
|
return app.client.waitUntilTextExists(".weather .normal.medium span.dimmed", "22,0°", 10000);
|
2019-09-11 12:27:06 +02:00
|
|
|
});
|
|
|
|
});
|
2019-01-13 23:59:05 +01:00
|
|
|
});
|
2019-09-13 13:54:55 +02:00
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
describe("Weather Forecast", function () {
|
2019-12-29 13:56:53 +01:00
|
|
|
let template;
|
2019-09-13 13:54:55 +02:00
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
before(function () {
|
2019-12-29 13:56:53 +01:00
|
|
|
template = fs.readFileSync(path.join(__dirname, "..", "..", "..", "modules", "default", "weather", "forecast.njk"), "utf8");
|
|
|
|
});
|
2019-09-13 13:54:55 +02:00
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
describe("Default configuration", function () {
|
|
|
|
before(function () {
|
2019-12-29 13:56:53 +01:00
|
|
|
process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/forecastweather_default.js";
|
|
|
|
});
|
2019-09-13 13:54:55 +02:00
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
it("should render days", async function () {
|
2019-12-29 13:56:53 +01:00
|
|
|
const weather = generateWeatherForecast();
|
2020-05-11 22:22:32 +02:00
|
|
|
await setup({ template, data: weather });
|
2019-09-13 13:54:55 +02:00
|
|
|
|
2019-12-29 13:56:53 +01:00
|
|
|
const days = ["Fri", "Sat", "Sun", "Mon", "Tue"];
|
2019-09-13 14:58:04 +02:00
|
|
|
|
2019-12-29 13:56:53 +01:00
|
|
|
for (const [index, day] of days.entries()) {
|
|
|
|
await app.client.waitUntilTextExists(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`, day, 10000);
|
|
|
|
}
|
|
|
|
});
|
2019-09-13 14:58:04 +02:00
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
it("should render icons", async function () {
|
2019-12-29 13:56:53 +01:00
|
|
|
const weather = generateWeatherForecast();
|
2020-05-11 22:22:32 +02:00
|
|
|
await setup({ template, data: weather });
|
2019-09-13 14:58:04 +02:00
|
|
|
|
2019-12-29 13:56:53 +01:00
|
|
|
const icons = ["day-cloudy", "rain", "day-sunny", "day-sunny", "day-sunny"];
|
2019-09-13 14:58:04 +02:00
|
|
|
|
2019-12-29 13:56:53 +01:00
|
|
|
for (const [index, icon] of icons.entries()) {
|
|
|
|
await app.client.waitForExist(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(2) span.wi-${icon}`, 10000);
|
|
|
|
}
|
|
|
|
});
|
2019-09-13 13:54:55 +02:00
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
it("should render max temperatures", async function () {
|
2019-12-29 13:56:53 +01:00
|
|
|
const weather = generateWeatherForecast();
|
2020-05-11 22:22:32 +02:00
|
|
|
await setup({ template, data: weather });
|
2019-09-13 15:08:44 +02:00
|
|
|
|
2019-12-29 13:56:53 +01:00
|
|
|
const temperatures = ["24.4°", "21.0°", "22.9°", "23.4°", "20.6°"];
|
2019-09-13 15:08:44 +02:00
|
|
|
|
2019-12-29 13:56:53 +01:00
|
|
|
for (const [index, temp] of temperatures.entries()) {
|
|
|
|
await app.client.waitUntilTextExists(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp, 10000);
|
|
|
|
}
|
|
|
|
});
|
2019-09-13 13:54:55 +02:00
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
it("should render min temperatures", async function () {
|
2019-12-29 13:56:53 +01:00
|
|
|
const weather = generateWeatherForecast();
|
2020-05-11 22:22:32 +02:00
|
|
|
await setup({ template, data: weather });
|
2019-09-13 15:08:44 +02:00
|
|
|
|
2019-12-29 13:56:53 +01:00
|
|
|
const temperatures = ["15.3°", "13.6°", "13.8°", "13.9°", "10.9°"];
|
2019-09-13 15:08:44 +02:00
|
|
|
|
2019-12-29 13:56:53 +01:00
|
|
|
for (const [index, temp] of temperatures.entries()) {
|
|
|
|
await app.client.waitUntilTextExists(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(4)`, temp, 10000);
|
|
|
|
}
|
|
|
|
});
|
2019-09-13 13:54:55 +02:00
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
it("should render fading of rows", async function () {
|
2019-12-29 13:56:53 +01:00
|
|
|
const weather = generateWeatherForecast();
|
2020-05-11 22:22:32 +02:00
|
|
|
await setup({ template, data: weather });
|
2019-09-13 15:44:38 +02:00
|
|
|
|
2019-12-29 13:56:53 +01:00
|
|
|
const opacities = [1, 1, 0.8, 0.5333333333333333, 0.2666666666666667];
|
2019-09-13 15:44:38 +02:00
|
|
|
|
2019-12-29 13:56:53 +01:00
|
|
|
await app.client.waitForExist(".weather table.small", 10000);
|
2019-09-13 15:44:38 +02:00
|
|
|
|
2019-12-29 13:56:53 +01:00
|
|
|
for (const [index, opacity] of opacities.entries()) {
|
|
|
|
const html = await app.client.getHTML(`.weather table.small tr:nth-child(${index + 1})`);
|
|
|
|
expect(html).to.includes(`<tr style="opacity: ${opacity};">`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
2019-09-13 16:21:12 +02:00
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
describe("Configuration Options", function () {
|
|
|
|
before(function () {
|
2019-12-29 13:56:53 +01:00
|
|
|
process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/forecastweather_options.js";
|
|
|
|
});
|
2019-09-13 16:21:12 +02:00
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
it("should render custom table class", async function () {
|
2019-12-29 13:56:53 +01:00
|
|
|
const weather = generateWeatherForecast();
|
2020-05-11 22:22:32 +02:00
|
|
|
await setup({ template, data: weather });
|
2019-09-13 16:21:12 +02:00
|
|
|
|
2019-12-29 13:56:53 +01:00
|
|
|
await app.client.waitForExist(".weather table.myTableClass", 10000);
|
|
|
|
});
|
2019-09-13 17:06:58 +02:00
|
|
|
|
2020-05-11 22:22:32 +02:00
|
|
|
it("should render colored rows", async function () {
|
2019-12-29 13:56:53 +01:00
|
|
|
const weather = generateWeatherForecast();
|
2020-05-11 22:22:32 +02:00
|
|
|
await setup({ template, data: weather });
|
2019-09-13 17:06:58 +02:00
|
|
|
|
2019-12-29 13:56:53 +01:00
|
|
|
await app.client.waitForExist(".weather table.myTableClass", 10000);
|
2019-09-13 17:06:58 +02:00
|
|
|
|
2019-12-29 13:56:53 +01:00
|
|
|
const rows = await app.client.$$(".weather table.myTableClass tr.colored");
|
2019-09-13 17:06:58 +02:00
|
|
|
|
2019-12-29 13:56:53 +01:00
|
|
|
expect(rows.length).to.be.equal(5);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2019-01-13 23:57:19 +01:00
|
|
|
});
|