Merge pull request #2417 from ashishtank/Issue2221

Fixed Unit test case error for #2221
This commit is contained in:
Michael Teeuw 2021-01-21 15:04:33 +01:00 committed by GitHub
commit 314c3cb516
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 4 deletions

View File

@ -30,6 +30,7 @@ _This release is scheduled to be released on 2021-04-01._
- Added default log levels to stop calendar log spamming.
- Fix socket.io cors errors, see [breaking change since socket.io v3](https://socket.io/docs/v3/handling-cors/)
- Fix Issue with weather forecast icons due to fixed day start and end time (#2221)
- Fix Issue with weather forecast icons unit tests with different timezones (#2221)
## [2.14.0] - 2021-01-01

View File

@ -355,8 +355,8 @@ Module.register("weatherforecast", {
var dayEnds = 17;
if (data.city && data.city.sunrise && data.city.sunset) {
dayStarts = moment.unix(data.city.sunrise).toDate().getHours();
dayEnds = moment.unix(data.city.sunset).toDate().getHours();
dayStarts = new Date(moment.unix(data.city.sunrise).locale("en").format("YYYY/MM/DD HH:mm:ss")).getHours();
dayEnds = new Date(moment.unix(data.city.sunset).locale("en").format("YYYY/MM/DD HH:mm:ss")).getHours();
}
// Handle different structs between forecast16 and onecall endpoints
@ -378,10 +378,10 @@ Module.register("weatherforecast", {
var hour;
if (forecast.dt_txt) {
day = moment(forecast.dt_txt, "YYYY-MM-DD hh:mm:ss").format("ddd");
hour = moment(forecast.dt_txt, "YYYY-MM-DD hh:mm:ss").toDate().getHours();
hour = new Date(moment(forecast.dt_txt).locale("en").format("YYYY-MM-DD HH:mm:ss")).getHours();
} else {
day = moment(forecast.dt, "X").format("ddd");
hour = moment(forecast.dt, "X").toDate().getHours();
hour = new Date(moment(forecast.dt, "X")).getHours();
}
if (day !== lastDay) {

View File

@ -1,5 +1,6 @@
/* eslint no-multi-spaces: 0 */
const expect = require("chai").expect;
const moment = require("moment-timezone");
var data = require("../functions/weatherforecast_data.json");
describe("Functions module weatherforecast", function () {
@ -69,6 +70,16 @@ describe("Functions module weatherforecast", function () {
Log = {
error: function () {}
};
var originalLocale;
var originalTimeZone;
before(function () {
originalLocale = moment.locale();
originalTimeZone = moment.tz.guess();
moment.locale("hi");
moment.tz.setDefault("Europe/Warsaw");
});
describe("forecastIcons sunset specified", function () {
before(function () {
Module.definitions.weatherforecast.Log = {};
@ -97,5 +108,10 @@ describe("Functions module weatherforecast", function () {
expect(forecastData[2].icon).to.equal("wi-rain");
});
});
after(function () {
moment.locale(originalLocale);
moment.tz.setDefault(originalTimeZone);
});
});
});