mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 03:39:55 +00:00
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>
40 lines
1.2 KiB
JavaScript
40 lines
1.2 KiB
JavaScript
const WeatherObject = require("../../../modules/default/weather/weatherobject.js");
|
|
|
|
global.moment = require("moment-timezone");
|
|
global.SunCalc = require("suncalc");
|
|
|
|
describe("WeatherObject", () => {
|
|
let originalTimeZone;
|
|
let weatherobject;
|
|
|
|
beforeAll(() => {
|
|
originalTimeZone = moment.tz.guess();
|
|
moment.tz.setDefault("Africa/Dar_es_Salaam");
|
|
weatherobject = new WeatherObject();
|
|
});
|
|
|
|
it("should return true for daytime at noon", () => {
|
|
weatherobject.date = moment(12, "HH");
|
|
weatherobject.updateSunTime(-6.774877582342688, 37.63345667023327);
|
|
expect(weatherobject.isDayTime()).toBe(true);
|
|
});
|
|
|
|
it("should return false for daytime at midnight", () => {
|
|
weatherobject.date = moment(0, "HH");
|
|
weatherobject.updateSunTime(-6.774877582342688, 37.63345667023327);
|
|
expect(weatherobject.isDayTime()).toBe(false);
|
|
});
|
|
|
|
it("should convert windspeed correctly from mph to mps", () => {
|
|
expect(Math.round(weatherobject.convertWindToMetric(93.951324266285))).toBe(42);
|
|
});
|
|
|
|
it("should convert wind direction correctly from cardinal to value", () => {
|
|
expect(weatherobject.valueWindDirection("SSE")).toBe(157);
|
|
});
|
|
|
|
afterAll(() => {
|
|
moment.tz.setDefault(originalTimeZone);
|
|
});
|
|
});
|