diff --git a/tests/e2e/modules/weather_current_spec.js b/tests/e2e/modules/weather_current_spec.js new file mode 100644 index 0000000000..e41bbe4b9a --- /dev/null +++ b/tests/e2e/modules/weather_current_spec.js @@ -0,0 +1,143 @@ +const moment = require("moment"); +const helpers = require("../global-setup"); +const path = require("path"); +const fs = require("fs"); +const { generateWeather, generateWeatherForecast } = require("./mocks"); + +describe("Weather module", function () { + /** + * @param {string} element css selector + * @param {string} result Expected text in given selector + */ + function getText(element, result) { + helpers.waitForElement(element).then((elem) => { + expect(elem).not.toBe(null); + expect( + elem.textContent + .trim() + .replace(/(\r\n|\n|\r)/gm, "") + .replace(/[ ]+/g, " ") + ).toBe(result); + }); + } + + /** + * @param {string} configFile path to configuration file + * @param {string} additionalMockData special data for mocking + * @param {string} callback callback + */ + function startApp(configFile, additionalMockData, callback) { + let mockWeather; + if (configFile.includes("forecast")) { + mockWeather = generateWeatherForecast(additionalMockData); + } else { + mockWeather = generateWeather(additionalMockData); + } + let content = fs.readFileSync(path.resolve(__dirname + "../../../../" + configFile)).toString(); + content = content.replace("#####WEATHERDATA#####", mockWeather); + fs.writeFileSync(path.resolve(__dirname + "../../../../config/config.js"), content); + helpers.startApplication(""); + helpers.getDocument(callback); + } + + afterAll(async function () { + await helpers.stopApplication(); + }); + + describe("Current weather", function () { + describe("Default configuration", function () { + beforeAll(function (done) { + const sunrise = moment().startOf("day").unix(); + const sunset = moment().endOf("day").unix(); + startApp("tests/configs/modules/weather/currentweather_default.js", { sys: { sunrise, sunset } }, done); + }); + + it("should render wind speed and wind direction", function () { + getText(".weather .normal.medium span:nth-child(2)", "6 WSW"); + }); + + it("should render temperature with icon", function () { + getText(".weather .large.light span.bright", "1.5°"); + }); + + it("should render feels like temperature", function () { + getText(".weather .normal.medium.feelslike span.dimmed", "Feels like -5.6°"); + }); + + it("should render sunrise", function () { + getText(".weather .normal.medium span:nth-child(4)", "12:00 am"); + }); + + it("should render sunset", function () { + getText(".weather .normal.medium span:nth-child(4)", "11:59 pm"); + }); + }); + }); + + describe("Compliments Integration", function () { + beforeAll(function (done) { + startApp("tests/configs/modules/weather/currentweather_compliments.js", {}, done); + }); + + it("should render a compliment based on the current weather", function () { + getText(".compliments .module-content span", "snow"); + }); + }); + + describe("Configuration Options", function () { + beforeAll(function (done) { + startApp("tests/configs/modules/weather/currentweather_options.js", {}, done); + }); + + it("should render useBeaufort = false", function () { + getText(".weather .normal.medium span:nth-child(2)", "12"); + }); + + it("should render showWindDirectionAsArrow = true", function () { + helpers.waitForElement(".weather .normal.medium sup i.fa-long-arrow-alt-up").then((elem) => { + expect(elem).not.toBe(null); + expect(elem.outerHTML).toContain("transform:rotate(250deg);"); + }); + }); + + it("should render showHumidity = true", function () { + getText(".weather .normal.medium span:nth-child(3)", "93.7"); + }); + + it("should render degreeLabel = true", function () { + getText(".weather .large.light span.bright", "1°C"); + getText(".weather .normal.medium.feelslike span.dimmed", "Feels like -6°C"); + }); + }); + + describe("Current weather units", function () { + beforeAll(function (done) { + 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 + } + }, + done + ); + }); + + it("should render imperial units", function () { + getText(".weather .normal.medium span:nth-child(2)", "6 WSW"); + getText(".weather .large.light span.bright", "34,7°"); + getText(".weather .normal.medium.feelslike span.dimmed", "Feels like 22,0°"); + }); + + it("should render custom decimalSymbol = ','", function () { + getText(".weather .normal.medium span:nth-child(3)", "93,7"); + getText(".weather .large.light span.bright", "34,7°"); + getText(".weather .normal.medium.feelslike span.dimmed", "Feels like 22,0°"); + }); + }); +}); diff --git a/tests/e2e/modules/weather_spec.js b/tests/e2e/modules/weather_forecast_spec.js similarity index 59% rename from tests/e2e/modules/weather_spec.js rename to tests/e2e/modules/weather_forecast_spec.js index 4ed0f458d4..b1156f9de6 100644 --- a/tests/e2e/modules/weather_spec.js +++ b/tests/e2e/modules/weather_forecast_spec.js @@ -1,4 +1,3 @@ -const moment = require("moment"); const helpers = require("../global-setup"); const path = require("path"); const fs = require("fs"); @@ -44,103 +43,6 @@ describe("Weather module", function () { await helpers.stopApplication(); }); - describe("Current weather", function () { - describe("Default configuration", function () { - beforeAll(function (done) { - const sunrise = moment().startOf("day").unix(); - const sunset = moment().endOf("day").unix(); - startApp("tests/configs/modules/weather/currentweather_default.js", { sys: { sunrise, sunset } }, done); - }); - - it("should render wind speed and wind direction", function () { - getText(".weather .normal.medium span:nth-child(2)", "6 WSW"); - }); - - it("should render temperature with icon", function () { - getText(".weather .large.light span.bright", "1.5°"); - }); - - it("should render feels like temperature", function () { - getText(".weather .normal.medium.feelslike span.dimmed", "Feels like -5.6°"); - }); - - it("should render sunrise", function () { - getText(".weather .normal.medium span:nth-child(4)", "12:00 am"); - }); - - it("should render sunset", function () { - getText(".weather .normal.medium span:nth-child(4)", "11:59 pm"); - }); - }); - }); - - describe("Compliments Integration", function () { - beforeAll(function (done) { - startApp("tests/configs/modules/weather/currentweather_compliments.js", {}, done); - }); - - it("should render a compliment based on the current weather", function () { - getText(".compliments .module-content span", "snow"); - }); - }); - - describe("Configuration Options", function () { - beforeAll(function (done) { - startApp("tests/configs/modules/weather/currentweather_options.js", {}, done); - }); - - it("should render useBeaufort = false", function () { - getText(".weather .normal.medium span:nth-child(2)", "12"); - }); - - it("should render showWindDirectionAsArrow = true", function () { - helpers.waitForElement(".weather .normal.medium sup i.fa-long-arrow-alt-up").then((elem) => { - expect(elem).not.toBe(null); - expect(elem.outerHTML).toContain("transform:rotate(250deg);"); - }); - }); - - it("should render showHumidity = true", function () { - getText(".weather .normal.medium span:nth-child(3)", "93.7"); - }); - - it("should render degreeLabel = true", function () { - getText(".weather .large.light span.bright", "1°C"); - getText(".weather .normal.medium.feelslike span.dimmed", "Feels like -6°C"); - }); - }); - - describe("Current weather units", function () { - beforeAll(function (done) { - 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 - } - }, - done - ); - }); - - it("should render imperial units", function () { - getText(".weather .normal.medium span:nth-child(2)", "6 WSW"); - getText(".weather .large.light span.bright", "34,7°"); - getText(".weather .normal.medium.feelslike span.dimmed", "Feels like 22,0°"); - }); - - it("should render custom decimalSymbol = ','", function () { - getText(".weather .normal.medium span:nth-child(3)", "93,7"); - getText(".weather .large.light span.bright", "34,7°"); - getText(".weather .normal.medium.feelslike span.dimmed", "Feels like 22,0°"); - }); - }); - describe("Weather Forecast", function () { describe("Default configuration", function () { beforeAll(function (done) {