mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-23 13:24:06 +00:00
Use metric units internally in all weatherproviders (#2849)
So finally I think this refactorin is ready to be reviewed :-) DONE: - [x] Removed all conversion functions for wind and temperature from specific weatherproviders - [x] Use internally only metric units: celsius for temperature, meters per seconds for wind - [x] Convert temp and wind into the configured units when displaying data on the UI - [x] look how beaufort calculation uses metrics, added knots as new windunit - [x] add more e2e tests Checked providers: - [x] Darksky - [x] EnvCanada - [x] OpenWeatherMap - [x] SMHI provider - [x] UK Met Office - [x] UK Met Office DataHub - [x] WeatherBit - [x] WeatherFlow - [x] WeatherGov TODO in different tickets: - check weatherproviders for usage of weatherEndpoint (as seen in https://github.com/MichMich/MagicMirror-Documentation/issues/131) -> see #2926 - cleanup precipations -> #2953 Co-authored-by: veeck <michael@veeck.de>
This commit is contained in:
29
tests/electron/helpers/weather-setup.js
Normal file
29
tests/electron/helpers/weather-setup.js
Normal file
@@ -0,0 +1,29 @@
|
||||
const helpers = require("./global-setup");
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const { generateWeather, generateWeatherForecast } = require("../../mocks/weather_test");
|
||||
|
||||
exports.getText = async (element, result) => {
|
||||
const elem = await helpers.getElement(element);
|
||||
await expect(elem).not.toBe(null);
|
||||
const text = await elem.textContent();
|
||||
await expect(
|
||||
text
|
||||
.trim()
|
||||
.replace(/(\r\n|\n|\r)/gm, "")
|
||||
.replace(/[ ]+/g, " ")
|
||||
).toBe(result);
|
||||
};
|
||||
|
||||
exports.startApp = async (configFile, systemDate) => {
|
||||
let mockWeather;
|
||||
if (configFile.includes("forecast")) {
|
||||
mockWeather = generateWeatherForecast();
|
||||
} else {
|
||||
mockWeather = generateWeather();
|
||||
}
|
||||
let content = fs.readFileSync(path.resolve(__dirname + "../../../../" + configFile)).toString();
|
||||
content = content.replace("#####WEATHERDATA#####", mockWeather);
|
||||
fs.writeFileSync(path.resolve(__dirname + "../../../../config/config.js"), content);
|
||||
await helpers.startApplication("", systemDate);
|
||||
};
|
28
tests/electron/modules/weather_spec.js
Normal file
28
tests/electron/modules/weather_spec.js
Normal file
@@ -0,0 +1,28 @@
|
||||
const helpers = require("../helpers/global-setup");
|
||||
const weatherHelper = require("../helpers/weather-setup");
|
||||
|
||||
describe("Weather module", () => {
|
||||
afterEach(async () => {
|
||||
await helpers.stopApplication();
|
||||
});
|
||||
|
||||
describe("Current weather with sunrise", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherHelper.startApp("tests/configs/modules/weather/currentweather_default.js", "13 Jan 2019 00:30:00 GMT");
|
||||
});
|
||||
|
||||
it("should render sunrise", async () => {
|
||||
await weatherHelper.getText(".weather .normal.medium span:nth-child(4)", "7:00 am");
|
||||
});
|
||||
});
|
||||
|
||||
describe("Current weather with sunset", () => {
|
||||
beforeAll(async () => {
|
||||
await weatherHelper.startApp("tests/configs/modules/weather/currentweather_default.js", "13 Jan 2019 12:30:00 GMT");
|
||||
});
|
||||
|
||||
it("should render sunset", async () => {
|
||||
await weatherHelper.getText(".weather .normal.medium span:nth-child(4)", "3:45 pm");
|
||||
});
|
||||
});
|
||||
});
|
Reference in New Issue
Block a user