diff --git a/modules/default/weather/weather.js b/modules/default/weather/weather.js index 523949aba6..d68e5a36ad 100644 --- a/modules/default/weather/weather.js +++ b/modules/default/weather/weather.js @@ -208,7 +208,7 @@ Module.register("weather", { * @returns {number} */ convertTemp(tempInC) { - return this.config.tempUnits === "imperial" ? tempInC * 1.8 + 32 : tempInC; + return this.config.tempUnits === "imperial" ? this.roundValue(tempInC * 1.8 + 32) : tempInC; }, convertWind(windInMS) { diff --git a/tests/configs/modules/weather/currentweather_options.js b/tests/configs/modules/weather/currentweather_options.js index bd433f6435..2dd9216327 100644 --- a/tests/configs/modules/weather/currentweather_options.js +++ b/tests/configs/modules/weather/currentweather_options.js @@ -11,7 +11,7 @@ let config = { config: { location: "Munich", mockData: '"#####WEATHERDATA#####"', - useBeaufort: false, + windUnits: "beaufort", showWindDirectionAsArrow: true, showSun: false, showHumidity: true, diff --git a/tests/e2e/modules/weather_current_spec.js b/tests/e2e/modules/weather_current_spec.js index 694782b160..daa792bbdb 100644 --- a/tests/e2e/modules/weather_current_spec.js +++ b/tests/e2e/modules/weather_current_spec.js @@ -14,39 +14,15 @@ describe("Weather module", () => { }); it("should render wind speed and wind direction", async () => { - await weatherFunc.getText(".weather .normal.medium span:nth-child(2)", "6 WSW"); // now "12" + await weatherFunc.getText(".weather .normal.medium span:nth-child(2)", "12 WSW"); }); it("should render temperature with icon", async () => { - await weatherFunc.getText(".weather .large.light span.bright", "1.5°"); // now "1°C" + await weatherFunc.getText(".weather .large.light span.bright", "1.5°"); }); it("should render feels like temperature", async () => { - await weatherFunc.getText(".weather .normal.medium.feelslike span.dimmed", "Feels like -5.6°"); // now "Feels like -6°C" - }); - }); - - describe("Default configuration with sunrise", () => { - beforeAll(async () => { - const sunrise = moment().startOf("day").unix(); - const sunset = moment().startOf("day").unix(); - await weatherFunc.startApp("tests/configs/modules/weather/currentweather_default.js", { sys: { sunrise, sunset } }); - }); - - it("should render sunrise", async () => { - await weatherFunc.getText(".weather .normal.medium span:nth-child(4)", "12:00 am"); - }); - }); - - describe("Default configuration with sunset", () => { - beforeAll(async () => { - const sunrise = moment().startOf("day").unix(); - const sunset = moment().endOf("day").unix(); - await weatherFunc.startApp("tests/configs/modules/weather/currentweather_default.js", { sys: { sunrise, sunset } }); - }); - - it("should render sunset", async () => { - await weatherFunc.getText(".weather .normal.medium span:nth-child(4)", "11:59 pm"); + await weatherFunc.getText(".weather .normal.medium.feelslike span.dimmed", "Feels like -5.6°"); }); }); }); @@ -66,65 +42,44 @@ describe("Weather module", () => { await weatherFunc.startApp("tests/configs/modules/weather/currentweather_options.js", {}); }); - it("should render useBeaufort = false", async () => { - await weatherFunc.getText(".weather .normal.medium span:nth-child(2)", "12"); + it("should render windUnits in beaufort", async () => { + await weatherFunc.getText(".weather .normal.medium span:nth-child(2)", "6"); }); - it("should render showWindDirectionAsArrow = true", async () => { + it("should render windDirection with an arrow", async () => { const elem = await helpers.waitForElement(".weather .normal.medium sup i.fa-long-arrow-alt-up"); expect(elem).not.toBe(null); expect(elem.outerHTML).toContain("transform:rotate(250deg);"); }); - it("should render showHumidity = true", async () => { + it("should render humidity", async () => { await weatherFunc.getText(".weather .normal.medium span:nth-child(3)", "93.7"); }); - it("should render degreeLabel = true for temp", async () => { + it("should render degreeLabel for temp", async () => { await weatherFunc.getText(".weather .large.light span.bright", "1°C"); }); - it("should render degreeLabel = true for feels like", async () => { + it("should render degreeLabel for feels like", async () => { await weatherFunc.getText(".weather .normal.medium.feelslike span.dimmed", "Feels like -6°C"); }); }); - describe("Current weather units", () => { + describe("Current weather with imperial units", () => { beforeAll(async () => { - await weatherFunc.startApp("tests/configs/modules/weather/currentweather_units.js", { - main: { - temp: (1.49 * 9) / 5 + 32, - temp_min: (1 * 9) / 5 + 32, - temp_max: (2 * 9) / 5 + 32 - }, - wind: { - speed: 11.8 * 2.23694 - } - }); - }); - - it("should render imperial units for wind", async () => { - await weatherFunc.getText(".weather .normal.medium span:nth-child(2)", "6 WSW"); - }); - - it("should render imperial units for temp", async () => { - await weatherFunc.getText(".weather .large.light span.bright", "34,7°"); - }); - - it("should render imperial units for feels like", async () => { - await weatherFunc.getText(".weather .normal.medium.feelslike span.dimmed", "Feels like 22,0°"); + await weatherFunc.startApp("tests/configs/modules/weather/currentweather_units.js", {}); }); - it("should render custom decimalSymbol = ',' for humidity", async () => { - await weatherFunc.getText(".weather .normal.medium span:nth-child(3)", "93,7"); + it("should render wind in imperial units", async () => { + await weatherFunc.getText(".weather .normal.medium span:nth-child(2)", "26 WSW"); }); - it("should render custom decimalSymbol = ',' for temp", async () => { + it("should render temperatures in fahrenheit", async () => { await weatherFunc.getText(".weather .large.light span.bright", "34,7°"); }); - it("should render custom decimalSymbol = ',' for feels like", async () => { - await weatherFunc.getText(".weather .normal.medium.feelslike span.dimmed", "Feels like 22,0°"); + it("should render 'feels like' in fahrenheit", async () => { + await weatherFunc.getText(".weather .normal.medium.feelslike span.dimmed", "Feels like 21,9°"); }); }); }); diff --git a/tests/e2e/modules/weather_forecast_spec.js b/tests/e2e/modules/weather_forecast_spec.js index 9268c6d157..cd03691609 100644 --- a/tests/e2e/modules/weather_forecast_spec.js +++ b/tests/e2e/modules/weather_forecast_spec.js @@ -86,7 +86,7 @@ describe("Weather module: Weather Forecast", () => { await weatherFunc.startApp("tests/configs/modules/weather/forecastweather_units.js", {}); }); - const temperatures = ["24_4°", "21_0°", "22_9°", "23_4°", "20_6°"]; + const temperatures = ["75_9°", "69_8°", "73_2°", "74_1°", "69_1°"]; for (const [index, temp] of temperatures.entries()) { it("should render custom decimalSymbol = '_' for temp " + temp, async () => { await weatherFunc.getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp); diff --git a/tests/electron/helpers/weather-setup.js b/tests/electron/helpers/weather-setup.js new file mode 100644 index 0000000000..2c9b9ad1f5 --- /dev/null +++ b/tests/electron/helpers/weather-setup.js @@ -0,0 +1,29 @@ +const helpers = require("./global-setup"); +const path = require("path"); +const fs = require("fs"); +const { generateWeather, generateWeatherForecast } = require("../../mocks/weather_test"); + +exports.getText = async (element, result) => { + const elem = await helpers.getElement(element); + await expect(elem).not.toBe(null); + const text = await elem.textContent(); + await expect( + text + .trim() + .replace(/(\r\n|\n|\r)/gm, "") + .replace(/[ ]+/g, " ") + ).toBe(result); +}; + +exports.startApp = async (configFile, systemDate) => { + let mockWeather; + if (configFile.includes("forecast")) { + mockWeather = generateWeatherForecast(); + } else { + mockWeather = generateWeather(); + } + let content = fs.readFileSync(path.resolve(__dirname + "../../../../" + configFile)).toString(); + content = content.replace("#####WEATHERDATA#####", mockWeather); + fs.writeFileSync(path.resolve(__dirname + "../../../../config/config.js"), content); + await helpers.startApplication("", systemDate); +}; diff --git a/tests/electron/modules/weather_spec.js b/tests/electron/modules/weather_spec.js new file mode 100644 index 0000000000..fe77743110 --- /dev/null +++ b/tests/electron/modules/weather_spec.js @@ -0,0 +1,28 @@ +const helpers = require("../helpers/global-setup"); +const weatherHelper = require("../helpers/weather-setup"); + +describe("Weather module", () => { + afterEach(async () => { + await helpers.stopApplication(); + }); + + describe("Current weather with sunrise", () => { + beforeAll(async () => { + await weatherHelper.startApp("tests/configs/modules/weather/currentweather_default.js", "13 Jan 2019 00:30:00 GMT"); + }); + + it("should render sunrise", async () => { + await weatherHelper.getText(".weather .normal.medium span:nth-child(4)", "7:00 am"); + }); + }); + + describe("Current weather with sunset", () => { + beforeAll(async () => { + await weatherHelper.startApp("tests/configs/modules/weather/currentweather_default.js", "13 Jan 2019 12:30:00 GMT"); + }); + + it("should render sunset", async () => { + await weatherHelper.getText(".weather .normal.medium span:nth-child(4)", "3:45 pm"); + }); + }); +});