2021-08-31 23:26:06 +02:00
|
|
|
const WeatherObject = require("../../../modules/default/weather/weatherobject.js");
|
|
|
|
|
2021-09-06 21:15:23 +02:00
|
|
|
global.moment = require("moment-timezone");
|
2021-08-31 23:26:06 +02:00
|
|
|
global.SunCalc = require("suncalc");
|
|
|
|
|
2022-10-04 10:15:24 +02:00
|
|
|
describe("WeatherObject", () => {
|
2021-09-06 21:15:23 +02:00
|
|
|
let originalTimeZone;
|
2021-08-31 23:26:06 +02:00
|
|
|
let weatherobject;
|
|
|
|
|
2022-10-04 10:15:24 +02:00
|
|
|
beforeAll(() => {
|
2021-09-06 21:15:23 +02:00
|
|
|
originalTimeZone = moment.tz.guess();
|
|
|
|
moment.tz.setDefault("Africa/Dar_es_Salaam");
|
2022-10-24 19:41:34 +02:00
|
|
|
weatherobject = new WeatherObject();
|
2021-08-31 23:26:06 +02:00
|
|
|
});
|
|
|
|
|
2022-10-04 10:15:24 +02:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2022-10-04 10:15:24 +02:00
|
|
|
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);
|
|
|
|
});
|
2021-09-06 21:15:23 +02:00
|
|
|
|
2022-10-24 19:41:34 +02:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2022-10-04 10:15:24 +02:00
|
|
|
afterAll(() => {
|
2021-09-06 21:15:23 +02:00
|
|
|
moment.tz.setDefault(originalTimeZone);
|
|
|
|
});
|
2021-08-31 23:26:06 +02:00
|
|
|
});
|