mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 03:39:55 +00:00
Add tests for new methods
This commit is contained in:
parent
43eb760bce
commit
f2bc10c5c0
@ -12,6 +12,13 @@
|
||||
* As soon as we start implementing the forecast, mode properties will be added.
|
||||
*/
|
||||
class WeatherObject {
|
||||
/**
|
||||
*
|
||||
* @param units
|
||||
* @param tempUnits
|
||||
* @param windUnits
|
||||
* @param useKmh
|
||||
*/
|
||||
constructor(units, tempUnits, windUnits, useKmh) {
|
||||
this.units = units;
|
||||
this.tempUnits = tempUnits;
|
||||
@ -132,8 +139,14 @@ class WeatherObject {
|
||||
* @param {number} lon longitude
|
||||
*/
|
||||
updateSunTime(lat, lon) {
|
||||
let times = SunCalc.getTimes(new Date(), lat, lon);
|
||||
let now = !this.date ? new Date() : this.date.toDate();
|
||||
let times = SunCalc.getTimes(now, lat, lon);
|
||||
this.sunrise = moment(times.sunrise, "X");
|
||||
this.sunset = moment(times.sunset, "X");
|
||||
}
|
||||
}
|
||||
|
||||
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
||||
if (typeof module !== "undefined") {
|
||||
module.exports = WeatherObject;
|
||||
}
|
||||
|
15
package-lock.json
generated
15
package-lock.json
generated
@ -44,7 +44,8 @@
|
||||
"stylelint": "^13.13.1",
|
||||
"stylelint-config-prettier": "^8.0.2",
|
||||
"stylelint-config-standard": "^22.0.0",
|
||||
"stylelint-prettier": "^1.2.0"
|
||||
"stylelint-prettier": "^1.2.0",
|
||||
"suncalc": "^1.8.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
@ -9373,6 +9374,12 @@
|
||||
"node": ">= 8.0"
|
||||
}
|
||||
},
|
||||
"node_modules/suncalc": {
|
||||
"version": "1.8.0",
|
||||
"resolved": "https://registry.npmjs.org/suncalc/-/suncalc-1.8.0.tgz",
|
||||
"integrity": "sha1-HZiYEJVjB4dQ9JlKlZ5lTYdqy/U=",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/supports-color": {
|
||||
"version": "7.2.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
|
||||
@ -17712,6 +17719,12 @@
|
||||
"debug": "^4.1.0"
|
||||
}
|
||||
},
|
||||
"suncalc": {
|
||||
"version": "1.8.0",
|
||||
"resolved": "https://registry.npmjs.org/suncalc/-/suncalc-1.8.0.tgz",
|
||||
"integrity": "sha1-HZiYEJVjB4dQ9JlKlZ5lTYdqy/U=",
|
||||
"dev": true
|
||||
},
|
||||
"supports-color": {
|
||||
"version": "7.2.0",
|
||||
"resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
|
||||
|
@ -62,7 +62,8 @@
|
||||
"stylelint": "^13.13.1",
|
||||
"stylelint-config-prettier": "^8.0.2",
|
||||
"stylelint-config-standard": "^22.0.0",
|
||||
"stylelint-prettier": "^1.2.0"
|
||||
"stylelint-prettier": "^1.2.0",
|
||||
"suncalc": "^1.8.0"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"electron": "^13.2.3"
|
||||
|
24
tests/unit/functions/weather_object_spec.js
Normal file
24
tests/unit/functions/weather_object_spec.js
Normal file
@ -0,0 +1,24 @@
|
||||
const WeatherObject = require("../../../modules/default/weather/weatherobject.js");
|
||||
|
||||
global.moment = require("moment");
|
||||
global.SunCalc = require("suncalc");
|
||||
|
||||
describe("WeatherObject", function () {
|
||||
let weatherobject;
|
||||
|
||||
beforeAll(function () {
|
||||
weatherobject = new WeatherObject("metric", "metric", "metric", true);
|
||||
});
|
||||
|
||||
it("should return true for daytime at noon", function () {
|
||||
weatherobject.date = moment(12, "HH");
|
||||
weatherobject.updateSunTime(-6.774877582342688, 37.63345667023327);
|
||||
expect(weatherobject.isDayTime()).toBe(true);
|
||||
});
|
||||
|
||||
it("should return false for daytime at midnight", function () {
|
||||
weatherobject.date = moment(0, "HH");
|
||||
weatherobject.updateSunTime(-6.774877582342688, 37.63345667023327);
|
||||
expect(weatherobject.isDayTime()).toBe(false);
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user