mirror of
				https://github.com/MichMich/MagicMirror.git
				synced 2025-10-31 18:54:51 +00:00 
			
		
		
		
	move weather-test to e2e
This commit is contained in:
		| @@ -1,4 +0,0 @@ | ||||
| const generateWeather = require("./weather_current"); | ||||
| const generateWeatherForecast = require("./weather_forecast"); | ||||
|  | ||||
| module.exports = { generateWeather, generateWeatherForecast }; | ||||
| @@ -1,64 +0,0 @@ | ||||
| const _ = require("lodash"); | ||||
|  | ||||
| /** | ||||
|  * @param {object} extendedData extra data to add to the default mock data | ||||
|  * @returns {string} mocked current weather data | ||||
|  */ | ||||
| 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; | ||||
| @@ -1,115 +0,0 @@ | ||||
| const _ = require("lodash"); | ||||
|  | ||||
| /** | ||||
|  * @param {object} extendedData extra data to add to the default mock data | ||||
|  * @returns {string} mocked forecast weather data | ||||
|  */ | ||||
| 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; | ||||
| @@ -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<Element>} 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<boolean>} 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(`<tr style="opacity: ${opacity};">`); | ||||
| 				} | ||||
| 			}); | ||||
| 		}); | ||||
|  | ||||
| 		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); | ||||
| 				} | ||||
| 			}); | ||||
| 		}); | ||||
| 	}); | ||||
| }); | ||||
		Reference in New Issue
	
	Block a user