MagicMirror/tests/unit/functions/weather_object_spec.js

32 lines
943 B
JavaScript
Raw Normal View History

2021-08-31 23:26:06 +02:00
const WeatherObject = require("../../../modules/default/weather/weatherobject.js");
global.moment = require("moment-timezone");
2021-08-31 23:26:06 +02:00
global.SunCalc = require("suncalc");
describe("WeatherObject", () => {
let originalTimeZone;
2021-08-31 23:26:06 +02:00
let weatherobject;
beforeAll(() => {
originalTimeZone = moment.tz.guess();
moment.tz.setDefault("Africa/Dar_es_Salaam");
2021-08-31 23:26:06 +02:00
weatherobject = new WeatherObject("metric", "metric", "metric", true);
});
it("should return true for daytime at noon", () => {
2021-08-31 23:26:06 +02:00
weatherobject.date = moment(12, "HH");
weatherobject.updateSunTime(-6.774877582342688, 37.63345667023327);
expect(weatherobject.isDayTime()).toBe(true);
});
it("should return false for daytime at midnight", () => {
2021-08-31 23:26:06 +02:00
weatherobject.date = moment(0, "HH");
weatherobject.updateSunTime(-6.774877582342688, 37.63345667023327);
expect(weatherobject.isDayTime()).toBe(false);
});
afterAll(() => {
moment.tz.setDefault(originalTimeZone);
});
2021-08-31 23:26:06 +02:00
});