From 8d85d1aa2d40fe9831efab1ef26a437e3fd32e9c Mon Sep 17 00:00:00 2001 From: Felix Wiedenbach Date: Fri, 13 Sep 2019 13:53:15 +0200 Subject: [PATCH 1/8] move mocks to separate directory for better overview --- tests/e2e/modules/mocks/index.js | 4 + tests/e2e/modules/mocks/weather_current.js | 54 ++++++++++++ tests/e2e/modules/mocks/weather_forecast.js | 97 +++++++++++++++++++++ tests/e2e/modules/weather_spec.js | 58 +----------- 4 files changed, 159 insertions(+), 54 deletions(-) create mode 100644 tests/e2e/modules/mocks/index.js create mode 100644 tests/e2e/modules/mocks/weather_current.js create mode 100644 tests/e2e/modules/mocks/weather_forecast.js diff --git a/tests/e2e/modules/mocks/index.js b/tests/e2e/modules/mocks/index.js new file mode 100644 index 00000000..afd061c6 --- /dev/null +++ b/tests/e2e/modules/mocks/index.js @@ -0,0 +1,4 @@ +const generateWeather = require("./weather_current"); +const generateWeatherForecast = require("./weather_forecast"); + +module.exports = {generateWeather, generateWeatherForecast}; diff --git a/tests/e2e/modules/mocks/weather_current.js b/tests/e2e/modules/mocks/weather_current.js new file mode 100644 index 00000000..cd87aa11 --- /dev/null +++ b/tests/e2e/modules/mocks/weather_current.js @@ -0,0 +1,54 @@ +const _ = require('lodash'); + +function generateWeather(extendedData = {}) { + return JSON.stringify(_.merge({}, { + coord:{ + lon: 11.58, + lat: 48.14 + }, + weather:[ + { + id: 615, + main: "Snow", + description: "light rain and snow", + icon: "13d" + }, + { + id: 500, + main: "Rain", + description: "light rain", + icon: "10d" + } + ], + base: "stations", + main:{ + temp: 1.49, + pressure: 1005, + humidity: 93.7, + temp_min: 1, + temp_max: 2 + }, + visibility: 7000, + wind:{ + speed: 11.8, + deg: 250 + }, + clouds:{ + all: 75 + }, + dt: 1547387400, + sys:{ + type: 1, + id: 1267, + message: 0.0031, + country: "DE", + sunrise: 1547362817, + sunset: 1547394301 + }, + id: 2867714, + name: "Munich", + cod: 200 + }, extendedData)); +} + +module.exports = generateWeather; diff --git a/tests/e2e/modules/mocks/weather_forecast.js b/tests/e2e/modules/mocks/weather_forecast.js new file mode 100644 index 00000000..420367a0 --- /dev/null +++ b/tests/e2e/modules/mocks/weather_forecast.js @@ -0,0 +1,97 @@ +const _ = require('lodash'); + +function generateWeatherForecast(extendedData = {}) { + return JSON.stringify(_.merge({}, { + "city": { + "id": 2867714, + "name": "Munich", + "coord": {"lon": 11.5754, "lat": 48.1371}, + "country": "DE", + "population": 1260391, + "timezone": 7200 + }, + "cod": "200", + "message": 0.9653487, + "cnt": 7, + "list": [{ + "dt": 1568372400, + "sunrise": 1568350044, + "sunset": 1568395948, + "temp": {"day": 24.44, "min": 15.35, "max": 24.44, "night": 15.35, "eve": 18, "morn": 23.03}, + "pressure": 1031.65, + "humidity": 70, + "weather": [{"id": 801, "main": "Clouds", "description": "few clouds", "icon": "02d"}], + "speed": 3.35, + "deg": 314, + "clouds": 21 + }, { + "dt": 1568458800, + "sunrise": 1568436525, + "sunset": 1568482223, + "temp": {"day": 20.81, "min": 13.56, "max": 21.02, "night": 13.56, "eve": 16.6, "morn": 15.88}, + "pressure": 1028.81, + "humidity": 72, + "weather": [{"id": 500, "main": "Rain", "description": "light rain", "icon": "10d"}], + "speed": 2.21, + "deg": 81, + "clouds": 100 + }, { + "dt": 1568545200, + "sunrise": 1568523007, + "sunset": 1568568497, + "temp": {"day": 22.65, "min": 13.76, "max": 22.88, "night": 15.27, "eve": 17.45, "morn": 13.76}, + "pressure": 1023.75, + "humidity": 64, + "weather": [{"id": 800, "main": "Clear", "description": "sky is clear", "icon": "01d"}], + "speed": 1.15, + "deg": 7, + "clouds": 0 + }, { + "dt": 1568631600, + "sunrise": 1568609489, + "sunset": 1568654771, + "temp": {"day": 23.45, "min": 13.95, "max": 23.45, "night": 13.95, "eve": 17.75, "morn": 15.21}, + "pressure": 1020.41, + "humidity": 64, + "weather": [{"id": 800, "main": "Clear", "description": "sky is clear", "icon": "01d"}], + "speed": 3.07, + "deg": 298, + "clouds": 7 + }, { + "dt": 1568718000, + "sunrise": 1568695970, + "sunset": 1568741045, + "temp": {"day": 20.55, "min": 10.95, "max": 20.55, "night": 10.95, "eve": 14.82, "morn": 13.24}, + "pressure": 1019.4, + "humidity": 66, + "weather": [{"id": 800, "main": "Clear", "description": "sky is clear", "icon": "01d"}], + "speed": 2.8, + "deg": 333, + "clouds": 2 + }, { + "dt": 1568804400, + "sunrise": 1568782452, + "sunset": 1568827319, + "temp": {"day": 18.15, "min": 7.75, "max": 18.15, "night": 7.75, "eve": 12.45, "morn": 9.41}, + "pressure": 1017.56, + "humidity": 52, + "weather": [{"id": 800, "main": "Clear", "description": "sky is clear", "icon": "01d"}], + "speed": 2.92, + "deg": 34, + "clouds": 0 + }, { + "dt": 1568890800, + "sunrise": 1568868934, + "sunset": 1568913593, + "temp": {"day": 14.85, "min": 5.56, "max": 15.05, "night": 5.56, "eve": 9.56, "morn": 6.25}, + "pressure": 1022.7, + "humidity": 59, + "weather": [{"id": 800, "main": "Clear", "description": "sky is clear", "icon": "01d"}], + "speed": 2.89, + "deg": 51, + "clouds": 1 + }] + }, extendedData)); +} + +module.exports = generateWeatherForecast; diff --git a/tests/e2e/modules/weather_spec.js b/tests/e2e/modules/weather_spec.js index ffcab77b..5eba03ad 100644 --- a/tests/e2e/modules/weather_spec.js +++ b/tests/e2e/modules/weather_spec.js @@ -1,12 +1,15 @@ const expect = require("chai").expect; const fs = require("fs"); -const _ = require("lodash"); const moment = require("moment"); const path = require("path"); const wdajaxstub = require("webdriverajaxstub"); const helpers = require("../global-setup"); +const {generateWeather, generateWeatherForecast} = require("./mocks"); + +const wait = () => new Promise(res => setTimeout(res, 3000)); + describe("Weather module", function() { let app; @@ -27,57 +30,6 @@ describe("Weather module", function() { }); describe("Current weather", function() { - function generateWeather(extendedData = {}) { - return JSON.stringify(_.merge({}, { - coord:{ - lon: 11.58, - lat: 48.14 - }, - weather:[ - { - id: 615, - main: "Snow", - description: "light rain and snow", - icon: "13d" - }, - { - id: 500, - main: "Rain", - description: "light rain", - icon: "10d" - } - ], - base: "stations", - main:{ - temp: 1.49, - pressure: 1005, - humidity: 93.7, - temp_min: 1, - temp_max: 2 - }, - visibility: 7000, - wind:{ - speed: 11.8, - deg: 250 - }, - clouds:{ - all: 75 - }, - dt: 1547387400, - sys:{ - type: 1, - id: 1267, - message: 0.0031, - country: "DE", - sunrise: 1547362817, - sunset: 1547394301 - }, - id: 2867714, - name: "Munich", - cod: 200 - }, extendedData)); - } - let template; before(function() { @@ -137,8 +89,6 @@ describe("Weather module", function() { }); }); - const wait = () => new Promise(res => setTimeout(res, 3000)); - describe("Configuration Options", function() { before(function() { process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/currentweather_options.js"; From 5b2efc43b9dc96dab33aff85c91220367d01dcdc Mon Sep 17 00:00:00 2001 From: Felix Wiedenbach Date: Fri, 13 Sep 2019 13:54:17 +0200 Subject: [PATCH 2/8] default weather forecast test config --- .../weather/forecastweather_default.js | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/configs/modules/weather/forecastweather_default.js diff --git a/tests/configs/modules/weather/forecastweather_default.js b/tests/configs/modules/weather/forecastweather_default.js new file mode 100644 index 00000000..697cbeb4 --- /dev/null +++ b/tests/configs/modules/weather/forecastweather_default.js @@ -0,0 +1,37 @@ +/* Magic Mirror Test config default weather + * + * By fewieden https://github.com/fewieden + * + * MIT Licensed. + */ + +let config = { + port: 8080, + ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], + + language: "en", + timeFormat: 12, + units: "metric", + electronOptions: { + webPreferences: { + nodeIntegration: true, + }, + }, + + modules: [ + { + module: "weather", + position: "bottom_bar", + config: { + type: "forecast", + location: "Munich", + apiKey: "fake key", + weatherEndpoint: "/forecast/daily", + initialLoadDelay: 3000 + } + } + ] +}; + +/*************** DO NOT EDIT THE LINE BELOW ***************/ +if (typeof module !== "undefined") {module.exports = config;} From fbceab707e418f983c41248483ef15c4558cad41 Mon Sep 17 00:00:00 2001 From: Felix Wiedenbach Date: Fri, 13 Sep 2019 13:54:55 +0200 Subject: [PATCH 3/8] draft for default weather forecast test cases --- tests/e2e/modules/weather_spec.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/e2e/modules/weather_spec.js b/tests/e2e/modules/weather_spec.js index 5eba03ad..3b9dcffd 100644 --- a/tests/e2e/modules/weather_spec.js +++ b/tests/e2e/modules/weather_spec.js @@ -171,4 +171,28 @@ describe("Weather module", function() { }); }); }); + + describe("Weather Forecast", function() { + let template; + + before(function() { + template = fs.readFileSync(path.join(__dirname, "..", "..", "..", "modules", "default", "weather", "forecast.njk"), "utf8"); + }); + + describe("Default configuration", function() { + before(function() { + process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/forecastweather_default.js"; + }); + + it("should render days", function() {}); + + it("should render icon", function() {}); + + it("should render max temperature", function() {}); + + it("should render min temperature", function() {}); + + it("should render fading of rows", function() {}); + }); + }); }); From 11e144ca64be59b263b7e28b4a040476bc27daa0 Mon Sep 17 00:00:00 2001 From: Felix Wiedenbach Date: Fri, 13 Sep 2019 14:58:04 +0200 Subject: [PATCH 4/8] it should render days and icons in weather forecast --- tests/e2e/modules/weather_spec.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/e2e/modules/weather_spec.js b/tests/e2e/modules/weather_spec.js index 3b9dcffd..f80479eb 100644 --- a/tests/e2e/modules/weather_spec.js +++ b/tests/e2e/modules/weather_spec.js @@ -184,9 +184,27 @@ describe("Weather module", function() { process.env.MM_CONFIG_FILE = "tests/configs/modules/weather/forecastweather_default.js"; }); - it("should render days", function() {}); + it("should render days", async function() { + const weather = generateWeatherForecast(); + await setup([weather, template]); - it("should render icon", function() {}); + const days = ["Fri", "Sat", "Sun", "Mon", "Tue"]; + + for (const [index, day] of days.entries()) { + await app.client.waitUntilTextExists(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`, day, 10000); + } + }); + + it("should render icons", async function() { + const weather = generateWeatherForecast(); + await setup([weather, template]); + + const icons = ["day-cloudy", "rain", "day-sunny", "day-sunny", "day-sunny"]; + + for (const [index, icon] of icons.entries()) { + await app.client.waitForExist(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(2) span.wi-${icon}`, 10000); + } + }); it("should render max temperature", function() {}); From f3e893fddbfc91ef155c55f845467238f98e72bc Mon Sep 17 00:00:00 2001 From: Felix Wiedenbach Date: Fri, 13 Sep 2019 15:08:44 +0200 Subject: [PATCH 5/8] it should render min and max temperatures --- tests/e2e/modules/weather_spec.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/tests/e2e/modules/weather_spec.js b/tests/e2e/modules/weather_spec.js index f80479eb..e2b3b7a9 100644 --- a/tests/e2e/modules/weather_spec.js +++ b/tests/e2e/modules/weather_spec.js @@ -206,9 +206,27 @@ describe("Weather module", function() { } }); - it("should render max temperature", function() {}); + it("should render max temperatures", async function() { + const weather = generateWeatherForecast(); + await setup([weather, template]); - it("should render min temperature", function() {}); + const temperatures = ["24.4°", "21.0°", "22.9°", "23.4°", "20.6°"]; + + for (const [index, temp] of temperatures.entries()) { + await app.client.waitUntilTextExists(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp, 10000); + } + }); + + it("should render min temperatures", async function() { + const weather = generateWeatherForecast(); + await setup([weather, template]); + + const temperatures = ["15.3°", "13.6°", "13.8°", "13.9°", "10.9°"]; + + for (const [index, temp] of temperatures.entries()) { + await app.client.waitUntilTextExists(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(4)`, temp, 10000); + } + }); it("should render fading of rows", function() {}); }); From 9430c70d0d0516bc00fe98d796f0cf9290e66cb1 Mon Sep 17 00:00:00 2001 From: Felix Wiedenbach Date: Fri, 13 Sep 2019 15:44:38 +0200 Subject: [PATCH 6/8] it should render fading rows in weather forecast --- tests/e2e/modules/weather_spec.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tests/e2e/modules/weather_spec.js b/tests/e2e/modules/weather_spec.js index e2b3b7a9..47c9e58f 100644 --- a/tests/e2e/modules/weather_spec.js +++ b/tests/e2e/modules/weather_spec.js @@ -228,7 +228,19 @@ describe("Weather module", function() { } }); - it("should render fading of rows", function() {}); + it("should render fading of rows", async function() { + const weather = generateWeatherForecast(); + await setup([weather, template]); + + const opacities = [1, 1, 0.8, 0.5333333333333333, 0.2666666666666667]; + + await app.client.waitForExist('.weather table.small', 10000); + + for (const [index, opacity] of opacities.entries()) { + const html = await app.client.getHTML(`.weather table.small tr:nth-child(${index + 1})`); + expect(html).to.includes(``); + } + }); }); }); }); From a774718607b63b3cc0903b084eea4004e841a922 Mon Sep 17 00:00:00 2001 From: Felix Wiedenbach Date: Fri, 13 Sep 2019 16:21:12 +0200 Subject: [PATCH 7/8] it should render custom table class --- .../weather/forecastweather_options.js | 40 +++++++++++++++++++ tests/e2e/modules/weather_spec.js | 13 ++++++ 2 files changed, 53 insertions(+) create mode 100644 tests/configs/modules/weather/forecastweather_options.js diff --git a/tests/configs/modules/weather/forecastweather_options.js b/tests/configs/modules/weather/forecastweather_options.js new file mode 100644 index 00000000..cc1b8773 --- /dev/null +++ b/tests/configs/modules/weather/forecastweather_options.js @@ -0,0 +1,40 @@ +/* Magic Mirror Test config default weather + * + * By fewieden https://github.com/fewieden + * + * MIT Licensed. + */ + +let config = { + port: 8080, + ipWhitelist: ["127.0.0.1", "::ffff:127.0.0.1", "::1"], + + language: "en", + timeFormat: 12, + units: "metric", + electronOptions: { + webPreferences: { + nodeIntegration: true, + }, + }, + + modules: [ + { + module: "weather", + position: "bottom_bar", + config: { + type: "forecast", + location: "Munich", + apiKey: "fake key", + weatherEndpoint: "/forecast/daily", + initialLoadDelay: 3000, + showPrecipitationAmount: true, + colored: true, + tableClass: "myTableClass" + } + } + ] +}; + +/*************** DO NOT EDIT THE LINE BELOW ***************/ +if (typeof module !== "undefined") {module.exports = config;} diff --git a/tests/e2e/modules/weather_spec.js b/tests/e2e/modules/weather_spec.js index 47c9e58f..abe4e3a0 100644 --- a/tests/e2e/modules/weather_spec.js +++ b/tests/e2e/modules/weather_spec.js @@ -242,5 +242,18 @@ describe("Weather module", function() { } }); }); + + describe("Configuration Options", function() { + before(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([weather, template]); + + await app.client.waitForExist(`.weather table.myTableClass`, 10000); + }); + }); }); }); From c630c387d67db3df453a0bc2492c747ffeaa40a8 Mon Sep 17 00:00:00 2001 From: Felix Wiedenbach Date: Fri, 13 Sep 2019 17:06:58 +0200 Subject: [PATCH 8/8] it should render colored rows --- tests/e2e/modules/weather_spec.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/e2e/modules/weather_spec.js b/tests/e2e/modules/weather_spec.js index abe4e3a0..be7a46e6 100644 --- a/tests/e2e/modules/weather_spec.js +++ b/tests/e2e/modules/weather_spec.js @@ -254,6 +254,17 @@ describe("Weather module", function() { await app.client.waitForExist(`.weather table.myTableClass`, 10000); }); + + it("should render colored rows", async function() { + const weather = generateWeatherForecast(); + await setup([weather, template]); + + await app.client.waitForExist(`.weather table.myTableClass`, 10000); + + const rows = await app.client.$$('.weather table.myTableClass tr.colored'); + + expect(rows.length).to.be.equal(5); + }); }); }); });