diff --git a/CHANGELOG.md b/CHANGELOG.md index b112cb2a..12c0d3dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,9 +15,10 @@ _This release is scheduled to be released on 2022-01-01._ - ESLint version supports now ECMAScript 2018 - Cleaned up `updatenotification` module and switched to nunjuck template. -- Move calendar tests from category `electron` to `e2e`. +- Moved calendar tests from category `electron` to `e2e`. - Update missed translations for Korean language (ko.json) - Cleaned up `alert` module and switched to nunjuck template. +- Moved weather tests from category `electron` to `e2e`. ### Fixed diff --git a/modules/default/weather/weatherprovider.js b/modules/default/weather/weatherprovider.js index c193ef08..5721dad6 100644 --- a/modules/default/weather/weatherprovider.js +++ b/modules/default/weather/weatherprovider.js @@ -113,20 +113,30 @@ const WeatherProvider = Class.extend({ // A convenience function to make requests. It returns a promise. fetchData: function (url, method = "GET", data = null) { - return new Promise(function (resolve, reject) { - const request = new XMLHttpRequest(); - request.open(method, url, true); - request.onreadystatechange = function () { - if (this.readyState === 4) { - if (this.status === 200) { - resolve(JSON.parse(this.response)); - } else { - reject(request); - } + const getData = function (mockData) { + return new Promise(function (resolve, reject) { + if (mockData) { + let data = mockData; + data = data.substring(1, data.length - 1); + resolve(JSON.parse(data)); + } else { + const request = new XMLHttpRequest(); + request.open(method, url, true); + request.onreadystatechange = function () { + if (this.readyState === 4) { + if (this.status === 200) { + resolve(JSON.parse(this.response)); + } else { + reject(request); + } + } + }; + request.send(); } - }; - request.send(); - }); + }); + }; + + return getData(this.config.mockData); } }); diff --git a/package.json b/package.json index 4fa33cd0..e2a17c34 100644 --- a/package.json +++ b/package.json @@ -113,7 +113,6 @@ "**/tests/electron/**/*.[jt]s?(x)" ], "testPathIgnorePatterns": [ - "/tests/electron/modules/mocks", "/tests/electron/global-setup.js" ] }, @@ -129,9 +128,10 @@ "/js/" ], "testPathIgnorePatterns": [ + "/tests/e2e/modules/mocks", + "/tests/e2e/modules/basic-auth.js", "/tests/e2e/global-setup.js", - "/tests/e2e/mock-console.js", - "/tests/e2e/modules/basic-auth.js" + "/tests/e2e/mock-console.js" ] } ] diff --git a/tests/configs/modules/weather/currentweather_compliments.js b/tests/configs/modules/weather/currentweather_compliments.js index 35d5ffb5..6efd43fe 100644 --- a/tests/configs/modules/weather/currentweather_compliments.js +++ b/tests/configs/modules/weather/currentweather_compliments.js @@ -3,7 +3,7 @@ * By rejas https://github.com/rejas * MIT Licensed. */ -let config = require(process.cwd() + "/tests/configs/default.js").configFactory({ +let config = { modules: [ { module: "compliments", @@ -12,7 +12,7 @@ let config = require(process.cwd() + "/tests/configs/default.js").configFactory( compliments: { snow: ["snow"] }, - updateInterval: 4000 + updateInterval: 3000 } }, { @@ -20,12 +20,11 @@ let config = require(process.cwd() + "/tests/configs/default.js").configFactory( position: "bottom_bar", config: { location: "Munich", - apiKey: "fake key", - initialLoadDelay: 3000 + mockData: '"#####WEATHERDATA#####"' } } ] -}); +}; /*************** DO NOT EDIT THE LINE BELOW ***************/ if (typeof module !== "undefined") { diff --git a/tests/configs/modules/weather/currentweather_default.js b/tests/configs/modules/weather/currentweather_default.js index 5c7edd5c..d7efb0a3 100644 --- a/tests/configs/modules/weather/currentweather_default.js +++ b/tests/configs/modules/weather/currentweather_default.js @@ -3,7 +3,7 @@ * By fewieden https://github.com/fewieden * MIT Licensed. */ -let config = require(process.cwd() + "/tests/configs/default.js").configFactory({ +let config = { timeFormat: 12, modules: [ @@ -12,12 +12,11 @@ let config = require(process.cwd() + "/tests/configs/default.js").configFactory( position: "bottom_bar", config: { location: "Munich", - apiKey: "fake key", - initialLoadDelay: 3000 + mockData: '"#####WEATHERDATA#####"' } } ] -}); +}; /*************** DO NOT EDIT THE LINE BELOW ***************/ if (typeof module !== "undefined") { diff --git a/tests/configs/modules/weather/currentweather_options.js b/tests/configs/modules/weather/currentweather_options.js index f3ff9d5d..db4f8ff7 100644 --- a/tests/configs/modules/weather/currentweather_options.js +++ b/tests/configs/modules/weather/currentweather_options.js @@ -3,15 +3,14 @@ * By fewieden https://github.com/fewieden * MIT Licensed. */ -let config = require(process.cwd() + "/tests/configs/default.js").configFactory({ +let config = { modules: [ { module: "weather", position: "bottom_bar", config: { location: "Munich", - apiKey: "fake key", - initialLoadDelay: 3000, + mockData: '"#####WEATHERDATA#####"', useBeaufort: false, showWindDirectionAsArrow: true, showSun: false, @@ -21,7 +20,7 @@ let config = require(process.cwd() + "/tests/configs/default.js").configFactory( } } ] -}); +}; /*************** DO NOT EDIT THE LINE BELOW ***************/ if (typeof module !== "undefined") { diff --git a/tests/configs/modules/weather/currentweather_units.js b/tests/configs/modules/weather/currentweather_units.js index af73d058..48c46f60 100644 --- a/tests/configs/modules/weather/currentweather_units.js +++ b/tests/configs/modules/weather/currentweather_units.js @@ -3,7 +3,7 @@ * By fewieden https://github.com/fewieden * MIT Licensed. */ -let config = require(process.cwd() + "/tests/configs/default.js").configFactory({ +let config = { units: "imperial", modules: [ @@ -12,14 +12,13 @@ let config = require(process.cwd() + "/tests/configs/default.js").configFactory( position: "bottom_bar", config: { location: "Munich", - apiKey: "fake key", - initialLoadDelay: 3000, + mockData: '"#####WEATHERDATA#####"', decimalSymbol: ",", showHumidity: true } } ] -}); +}; /*************** DO NOT EDIT THE LINE BELOW ***************/ if (typeof module !== "undefined") { diff --git a/tests/configs/modules/weather/forecastweather_default.js b/tests/configs/modules/weather/forecastweather_default.js index f4b401f6..05dc10ea 100644 --- a/tests/configs/modules/weather/forecastweather_default.js +++ b/tests/configs/modules/weather/forecastweather_default.js @@ -3,7 +3,7 @@ * By fewieden https://github.com/fewieden * MIT Licensed. */ -let config = require(process.cwd() + "/tests/configs/default.js").configFactory({ +let config = { timeFormat: 12, modules: [ @@ -13,13 +13,12 @@ let config = require(process.cwd() + "/tests/configs/default.js").configFactory( config: { type: "forecast", location: "Munich", - apiKey: "fake key", - weatherEndpoint: "/forecast/daily", - initialLoadDelay: 3000 + mockData: '"#####WEATHERDATA#####"', + weatherEndpoint: "/forecast/daily" } } ] -}); +}; /*************** DO NOT EDIT THE LINE BELOW ***************/ if (typeof module !== "undefined") { diff --git a/tests/configs/modules/weather/forecastweather_options.js b/tests/configs/modules/weather/forecastweather_options.js index 094d9a00..755407e5 100644 --- a/tests/configs/modules/weather/forecastweather_options.js +++ b/tests/configs/modules/weather/forecastweather_options.js @@ -3,7 +3,7 @@ * By fewieden https://github.com/fewieden * MIT Licensed. */ -let config = require(process.cwd() + "/tests/configs/default.js").configFactory({ +let config = { timeFormat: 12, modules: [ @@ -13,16 +13,15 @@ let config = require(process.cwd() + "/tests/configs/default.js").configFactory( config: { type: "forecast", location: "Munich", - apiKey: "fake key", + mockData: '"#####WEATHERDATA#####"', weatherEndpoint: "/forecast/daily", - initialLoadDelay: 3000, showPrecipitationAmount: true, colored: true, tableClass: "myTableClass" } } ] -}); +}; /*************** DO NOT EDIT THE LINE BELOW ***************/ if (typeof module !== "undefined") { diff --git a/tests/configs/modules/weather/forecastweather_units.js b/tests/configs/modules/weather/forecastweather_units.js index 843f874b..6fc2d456 100644 --- a/tests/configs/modules/weather/forecastweather_units.js +++ b/tests/configs/modules/weather/forecastweather_units.js @@ -3,7 +3,7 @@ * By rejas * MIT Licensed. */ -let config = require(process.cwd() + "/tests/configs/default.js").configFactory({ +let config = { units: "imperial", modules: [ @@ -13,14 +13,13 @@ let config = require(process.cwd() + "/tests/configs/default.js").configFactory( config: { type: "forecast", location: "Munich", - apiKey: "fake key", + mockData: '"#####WEATHERDATA#####"', weatherEndpoint: "/forecast/daily", - initialLoadDelay: 3000, decimalSymbol: "_" } } ] -}); +}; /*************** DO NOT EDIT THE LINE BELOW ***************/ if (typeof module !== "undefined") { diff --git a/tests/e2e/global-setup.js b/tests/e2e/global-setup.js index 45726493..bb9b1a2e 100644 --- a/tests/e2e/global-setup.js +++ b/tests/e2e/global-setup.js @@ -6,7 +6,11 @@ exports.startApplication = function (configFilename, exec) { global.app.stop(); } // Set config sample for use in test - process.env.MM_CONFIG_FILE = configFilename; + if (configFilename === "") { + process.env.MM_CONFIG_FILE = "config/config.js"; + } else { + process.env.MM_CONFIG_FILE = configFilename; + } if (exec) exec; global.app = require("app.js"); global.app.start(); diff --git a/tests/electron/modules/mocks/index.js b/tests/e2e/modules/mocks/index.js similarity index 100% rename from tests/electron/modules/mocks/index.js rename to tests/e2e/modules/mocks/index.js diff --git a/tests/electron/modules/mocks/weather_current.js b/tests/e2e/modules/mocks/weather_current.js similarity index 100% rename from tests/electron/modules/mocks/weather_current.js rename to tests/e2e/modules/mocks/weather_current.js diff --git a/tests/electron/modules/mocks/weather_forecast.js b/tests/e2e/modules/mocks/weather_forecast.js similarity index 100% rename from tests/electron/modules/mocks/weather_forecast.js rename to tests/e2e/modules/mocks/weather_forecast.js diff --git a/tests/e2e/modules/weather_spec.js b/tests/e2e/modules/weather_spec.js new file mode 100644 index 00000000..b2dce4fb --- /dev/null +++ b/tests/e2e/modules/weather_spec.js @@ -0,0 +1,243 @@ +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 + * @returns {Promise} Promise with the element once it is rendered + */ + function getElement(element) { + const elem = document.querySelector(element); + expect(elem).not.toBe(null); + return elem; + } + + /** + * @param {string} element css selector + * @param {string} result Expected text in given selector + */ + function getText(element, result) { + const elem = getElement(element); + 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, 3000); + } + + afterAll(function () { + helpers.stopApplication(); + }); + + describe("Current weather", function () { + describe("Default configuration", function () { + beforeAll(function (done) { + startApp("tests/configs/modules/weather/currentweather_default.js", {}, 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°"); + }); + }); + + describe("Default configuration with sunrise", function () { + beforeAll(function (done) { + const sunrise = moment().startOf("day").unix(); + const sunset = moment().startOf("day").unix(); + startApp("tests/configs/modules/weather/currentweather_default.js", { sys: { sunrise, sunset } }, done); + }); + + it("should render sunrise", function () { + getText(".weather .normal.medium span:nth-child(4)", "12:00 am"); + }); + }); + + describe("Default configuration with sunset", 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 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 () { + const elem = getElement(".weather .normal.medium sup i.fa-long-arrow-up"); + 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) { + startApp("tests/configs/modules/weather/forecastweather_default.js", {}, done); + }); + + it("should render days", function () { + const days = ["Today", "Tomorrow", "Sun", "Mon", "Tue"]; + + for (const [index, day] of days.entries()) { + getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`, day); + } + }); + + it("should render icons", function () { + const icons = ["day-cloudy", "rain", "day-sunny", "day-sunny", "day-sunny"]; + + for (const [index, icon] of icons.entries()) { + getElement(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(2) span.wi-${icon}`); + } + }); + + it("should render max temperatures", function () { + const temperatures = ["24.4°", "21.0°", "22.9°", "23.4°", "20.6°"]; + + for (const [index, temp] of temperatures.entries()) { + getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp); + } + }); + + it("should render min temperatures", function () { + const temperatures = ["15.3°", "13.6°", "13.8°", "13.9°", "10.9°"]; + + for (const [index, temp] of temperatures.entries()) { + getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(4)`, temp); + } + }); + + it("should render fading of rows", function () { + const opacities = [1, 1, 0.8, 0.5333333333333333, 0.2666666666666667]; + + for (const [index, opacity] of opacities.entries()) { + const elem = getElement(`.weather table.small tr:nth-child(${index + 1})`); + expect(elem.outerHTML).toContain(``); + } + }); + }); + + describe("Configuration Options", function () { + beforeAll(function (done) { + startApp("tests/configs/modules/weather/forecastweather_options.js", {}, done); + }); + + it("should render custom table class", function () { + getElement(".weather table.myTableClass"); + }); + + it("should render colored rows", function () { + const table = getElement(".weather table.myTableClass"); + expect(table.rows).not.toBe(null); + expect(table.rows.length).toBe(5); + }); + }); + + describe("Forecast weather units", function () { + beforeAll(function (done) { + startApp("tests/configs/modules/weather/forecastweather_units.js", {}, done); + }); + + it("should render custom decimalSymbol = '_'", function () { + const temperatures = ["24_4°", "21_0°", "22_9°", "23_4°", "20_6°"]; + + for (const [index, temp] of temperatures.entries()) { + getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp); + } + }); + }); + }); +}); diff --git a/tests/electron/modules/weather_spec.js b/tests/electron/modules/weather_spec.js deleted file mode 100644 index 6be9d6e2..00000000 --- a/tests/electron/modules/weather_spec.js +++ /dev/null @@ -1,309 +0,0 @@ -const fs = require("fs"); -const moment = require("moment"); -const path = require("path"); -const wdajaxstub = require("webdriverajaxstub"); - -const helpers = require("../global-setup"); - -const { generateWeather, generateWeatherForecast } = require("./mocks"); - -describe("Weather module", function () { - let app; - - helpers.setupTimeout(this); - - /** - * - * @param {object} responses mocked data to be returned - * @returns {Promise} Resolved once the electron app is started - */ - async function setup(responses) { - app = await helpers.startApplication({ - args: ["js/electron.js"], - waitTimeout: 100000 - }); - - wdajaxstub.init(app.client, responses); - - app.client.setupStub(); - } - - /** - * - * @param {string} element css selector - * @returns {Promise} Promise with the element once it is rendered - */ - async function getElement(element) { - return await app.client.$(element); - } - - /** - * @param {string} element css selector - * @param {string} result Expected text in given selector - * @returns {Promise} Promise with True if the text matches - */ - async function getText(element, result) { - const elem = await getElement(element); - return await elem.getText(element).then(function (text) { - expect(text.trim()).toBe(result); - }); - } - - afterEach(function () { - return helpers.stopApplication(app); - }); - - describe("Current weather", function () { - let template; - - beforeAll(function () { - template = fs.readFileSync(path.join(__dirname, "..", "..", "..", "modules", "default", "weather", "current.njk"), "utf8"); - }); - - describe("Default configuration", function () { - beforeAll(function () { - process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/currentweather_default.js"; - }); - - it("should render wind speed and wind direction", async function () { - const weather = generateWeather(); - await setup({ template, data: weather }); - - return getText(".weather .normal.medium span:nth-child(2)", "6 WSW"); - }); - - it("should render sunrise", async function () { - const sunrise = moment().startOf("day").unix(); - const sunset = moment().startOf("day").unix(); - - const weather = generateWeather({ sys: { sunrise, sunset } }); - await setup({ template, data: weather }); - - return getText(".weather .normal.medium span:nth-child(4)", "12:00 am"); - }); - - it("should render sunset", async function () { - const sunrise = moment().startOf("day").unix(); - const sunset = moment().endOf("day").unix(); - - const weather = generateWeather({ sys: { sunrise, sunset } }); - await setup({ template, data: weather }); - - return getText(".weather .normal.medium span:nth-child(4)", "11:59 pm"); - }); - - it("should render temperature with icon", async function () { - const weather = generateWeather(); - await setup({ template, data: weather }); - - return getText(".weather .large.light span.bright", "1.5°"); - }); - - it("should render feels like temperature", async function () { - const weather = generateWeather(); - await setup({ template, data: weather }); - - return getText(".weather .normal.medium.feelslike span.dimmed", "Feels like -5.6°"); - }); - }); - - describe("Compliments Integration", function () { - beforeAll(function () { - process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/currentweather_compliments.js"; - }); - - it("should render a compliment based on the current weather", async function () { - const weather = generateWeather(); - await setup({ template, data: weather }); - - return app.client.waitUntilTextExists(".compliments .module-content span", "snow"); - }); - }); - - describe("Configuration Options", function () { - beforeAll(function () { - process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/currentweather_options.js"; - }); - - it("should render useBeaufort = false", async function () { - const weather = generateWeather(); - await setup({ template, data: weather }); - - return getText(".weather .normal.medium span:nth-child(2)", "12"); - }); - - it("should render showWindDirectionAsArrow = true", async function () { - const weather = generateWeather(); - await setup({ template, data: weather }); - - const elem = await getElement(".weather .normal.medium sup i.fa-long-arrow-up"); - return elem.getHTML(".weather .normal.medium sup i.fa-long-arrow-up").then(function (text) { - expect(text).toContain("transform:rotate(250deg);"); - }); - }); - - it("should render showHumidity = true", async function () { - const weather = generateWeather(); - await setup({ template, data: weather }); - - return getText(".weather .normal.medium span:nth-child(3)", "93.7"); - }); - - it("should render degreeLabel = true", async function () { - const weather = generateWeather(); - await setup({ template, data: weather }); - - return (await getText(".weather .large.light span.bright", "1°C")) && (await getText(".weather .normal.medium.feelslike span.dimmed", "Feels like -6°C")); - }); - }); - - describe("Current weather units", function () { - beforeAll(function () { - process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/currentweather_units.js"; - }); - - it("should render imperial units", async function () { - const weather = generateWeather({ - 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 - } - }); - await setup({ template, data: weather }); - - return (await getText(".weather .normal.medium span:nth-child(2)", "6 WSW")) && (await getText(".weather .large.light span.bright", "34,7°")) && getText(".weather .normal.medium.feelslike span.dimmed", "Feels like 22,0°"); - }); - - it("should render custom decimalSymbol = ','", async function () { - const weather = generateWeather({ - 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 - } - }); - await setup({ template, data: weather }); - - return (await getText(".weather .normal.medium span:nth-child(3)", "93,7")) && (await getText(".weather .large.light span.bright", "34,7°")) && getText(".weather .normal.medium.feelslike span.dimmed", "Feels like 22,0°"); - }); - }); - }); - - describe("Weather Forecast", function () { - let template; - - beforeAll(function () { - template = fs.readFileSync(path.join(__dirname, "..", "..", "..", "modules", "default", "weather", "forecast.njk"), "utf8"); - }); - - describe("Default configuration", function () { - beforeAll(function () { - process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/forecastweather_default.js"; - }); - - it("should render days", async function () { - const weather = generateWeatherForecast(); - await setup({ template, data: weather }); - - const days = ["Today", "Tomorrow", "Sun", "Mon", "Tue"]; - - for (const [index, day] of days.entries()) { - await getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`, day); - } - }); - - it("should render icons", async function () { - const weather = generateWeatherForecast(); - await setup({ template, data: weather }); - - const icons = ["day-cloudy", "rain", "day-sunny", "day-sunny", "day-sunny"]; - - for (const [index, icon] of icons.entries()) { - await getElement(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(2) span.wi-${icon}`); - } - }); - - it("should render max temperatures", async function () { - const weather = generateWeatherForecast(); - await setup({ template, data: weather }); - - const temperatures = ["24.4°", "21.0°", "22.9°", "23.4°", "20.6°"]; - - for (const [index, temp] of temperatures.entries()) { - await getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp); - } - }); - - it("should render min temperatures", async function () { - const weather = generateWeatherForecast(); - await setup({ template, data: weather }); - - const temperatures = ["15.3°", "13.6°", "13.8°", "13.9°", "10.9°"]; - - for (const [index, temp] of temperatures.entries()) { - await getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(4)`, temp); - } - }); - - it("should render fading of rows", async function () { - const weather = generateWeatherForecast(); - await setup({ template, data: weather }); - - const opacities = [1, 1, 0.8, 0.5333333333333333, 0.2666666666666667]; - - const elem = await getElement(".weather table.small"); - - for (const [index, opacity] of opacities.entries()) { - const html = await elem.getHTML(`.weather table.small tr:nth-child(${index + 1})`); - expect(html).toContain(``); - } - }); - }); - - describe("Configuration Options", function () { - beforeAll(function () { - process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/forecastweather_options.js"; - }); - - it("should render custom table class", async function () { - const weather = generateWeatherForecast(); - await setup({ template, data: weather }); - - await getElement(".weather table.myTableClass"); - }); - - it("should render colored rows", async function () { - const weather = generateWeatherForecast(); - await setup({ template, data: weather }); - - const rows = await app.client.$$(".weather table.myTableClass tr.colored"); - - expect(rows.length).toBe(5); - }); - }); - - describe("Forecast weather units", function () { - beforeAll(function () { - process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/forecastweather_units.js"; - }); - - it("should render custom decimalSymbol = '_'", async function () { - const weather = generateWeatherForecast(); - await setup({ template, data: weather }); - - const temperatures = ["24_4°", "21_0°", "22_9°", "23_4°", "20_6°"]; - - for (const [index, temp] of temperatures.entries()) { - await getText(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp); - } - }); - }); - }); -}); diff --git a/tests/node_modules/webdriverajaxstub/index.js b/tests/node_modules/webdriverajaxstub/index.js deleted file mode 100644 index 186033b6..00000000 --- a/tests/node_modules/webdriverajaxstub/index.js +++ /dev/null @@ -1,33 +0,0 @@ -function plugin (wdInstance, requests) { - if (typeof wdInstance.addCommand !== "function") { - throw new Error("You can't use WebdriverAjaxStub with this version of WebdriverIO"); - } - - function stub({template, data}, done) { - window.XMLHttpRequest = function () { - this.open = function (method, url) { - this.method = method; - this.url = url; - }; - - this.send = function () { - this.status = 200; - this.readyState = 4; - const response = this.url.includes(".njk") ? template : data; - this.response = response; - this.responseText = response; - this.onreadystatechange(); - }; - - return this; - }; - - done(); - } - - wdInstance.addCommand("setupStub", function() { - return wdInstance.executeAsync(stub, requests); - }); -} - -module.exports.init = plugin;