mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 11:50:00 +00:00
Merge pull request #1766 from fewieden/feature/automated-weather-tests
Automated tests for new weather module
This commit is contained in:
commit
9db54831c8
@ -17,6 +17,7 @@
|
||||
},
|
||||
"parserOptions": {
|
||||
"sourceType": "module",
|
||||
"ecmaVersion": 2017,
|
||||
"ecmaFeatures": {
|
||||
"globalReturn": true
|
||||
}
|
||||
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -11,7 +11,7 @@ coverage
|
||||
.grunt
|
||||
.lock-wscript
|
||||
build/Release
|
||||
node_modules
|
||||
/node_modules/**/*
|
||||
jspm_modules
|
||||
.npm
|
||||
.node_repl_history
|
||||
@ -81,3 +81,5 @@ Temporary Items
|
||||
*.orig
|
||||
*.rej
|
||||
*.bak
|
||||
|
||||
!/tests/node_modules/**/*
|
@ -15,6 +15,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
- Spanish translation for "PRECIP"
|
||||
- Adding a Malay (Malaysian) translation for MagicMirror²
|
||||
- Add test check URLs of vendors 200 and 404 HTTP CODE.
|
||||
- Add tests for new weather module and helper to stub ajax requests
|
||||
|
||||
### Updated
|
||||
- Updatenotification module: Display update notification for a limited (configurable) time.
|
||||
|
0
modules/default/weather/weather.js
Executable file → Normal file
0
modules/default/weather/weather.js
Executable file → Normal file
4011
package-lock.json
generated
4011
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -63,6 +63,7 @@
|
||||
"feedme": "latest",
|
||||
"helmet": "^3.9.0",
|
||||
"iconv-lite": "latest",
|
||||
"lodash": "^4.17.11",
|
||||
"moment": "latest",
|
||||
"request": "^2.88.0",
|
||||
"rrule": "^2.6.2",
|
||||
|
35
tests/configs/modules/weather/currentweather_default.js
Normal file
35
tests/configs/modules/weather/currentweather_default.js
Normal file
@ -0,0 +1,35 @@
|
||||
/* 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: {
|
||||
location: "Munich",
|
||||
apiKey: "fake key",
|
||||
initialLoadDelay: 3000
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
||||
if (typeof module !== "undefined") {module.exports = config;}
|
40
tests/configs/modules/weather/currentweather_options.js
Normal file
40
tests/configs/modules/weather/currentweather_options.js
Normal file
@ -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: 24,
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
},
|
||||
},
|
||||
|
||||
modules: [
|
||||
{
|
||||
module: "weather",
|
||||
position: "bottom_bar",
|
||||
config: {
|
||||
location: "Munich",
|
||||
apiKey: "fake key",
|
||||
initialLoadDelay: 3000,
|
||||
useBeaufort: false,
|
||||
showWindDirectionAsArrow: true,
|
||||
showHumidity: true,
|
||||
roundTemp: true,
|
||||
degreeLabel: true
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
||||
if (typeof module !== "undefined") {module.exports = config;}
|
37
tests/configs/modules/weather/currentweather_units.js
Normal file
37
tests/configs/modules/weather/currentweather_units.js
Normal file
@ -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: 24,
|
||||
units: "imperial",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true,
|
||||
},
|
||||
},
|
||||
|
||||
modules: [
|
||||
{
|
||||
module: "weather",
|
||||
position: "bottom_bar",
|
||||
config: {
|
||||
location: "Munich",
|
||||
apiKey: "fake key",
|
||||
initialLoadDelay: 3000,
|
||||
decimalSymbol: ",",
|
||||
showHumidity: true
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
/*************** DO NOT EDIT THE LINE BELOW ***************/
|
||||
if (typeof module !== "undefined") {module.exports = config;}
|
224
tests/e2e/modules/weather_spec.js
Normal file
224
tests/e2e/modules/weather_spec.js
Normal file
@ -0,0 +1,224 @@
|
||||
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");
|
||||
|
||||
describe("Weather module", function() {
|
||||
let app;
|
||||
|
||||
helpers.setupTimeout(this);
|
||||
|
||||
async function setup(responses) {
|
||||
app = await helpers.startApplication({
|
||||
args: ["js/electron.js"]
|
||||
});
|
||||
|
||||
wdajaxstub.init(app.client, responses);
|
||||
|
||||
app.client.setupStub();
|
||||
}
|
||||
|
||||
afterEach(function() {
|
||||
return helpers.stopApplication(app);
|
||||
});
|
||||
|
||||
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() {
|
||||
template = fs.readFileSync(path.join(__dirname, "..", "..", "..", "modules", "default", "weather", "current.njk"), "utf8");
|
||||
});
|
||||
|
||||
describe("Default configuration", function() {
|
||||
before(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([weather, template]);
|
||||
|
||||
return app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(2)", "6 WSW", 10000);
|
||||
});
|
||||
|
||||
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([weather, template]);
|
||||
|
||||
await app.client.waitForExist(".weather .normal.medium span.wi.dimmed.wi-sunrise", 10000);
|
||||
|
||||
return app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(4)", "12:00 am", 10000);
|
||||
});
|
||||
|
||||
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([weather, template]);
|
||||
|
||||
await app.client.waitForExist(".weather .normal.medium span.wi.dimmed.wi-sunset", 10000);
|
||||
|
||||
return app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(4)", "11:59 pm", 10000);
|
||||
});
|
||||
|
||||
it("should render temperature with icon", async function() {
|
||||
const weather = generateWeather();
|
||||
await setup([weather, template]);
|
||||
|
||||
await app.client.waitForExist(".weather .large.light span.wi.weathericon.wi-snow", 10000);
|
||||
|
||||
return app.client.waitUntilTextExists(".weather .large.light span.bright", "1.5°", 10000);
|
||||
});
|
||||
|
||||
it("should render feels like temperature", async function() {
|
||||
const weather = generateWeather();
|
||||
await setup([weather, template]);
|
||||
|
||||
return app.client.waitUntilTextExists(".weather .normal.medium span.dimmed", "Feels like -5.6°", 10000);
|
||||
});
|
||||
});
|
||||
|
||||
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";
|
||||
});
|
||||
|
||||
it("should render useBeaufort = false", async function() {
|
||||
const weather = generateWeather();
|
||||
await setup([weather, template]);
|
||||
|
||||
return app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(2)", "12", 10000);
|
||||
});
|
||||
|
||||
it("should render showWindDirectionAsArrow = true", async function() {
|
||||
const weather = generateWeather();
|
||||
await setup([weather, template]);
|
||||
|
||||
await app.client.waitForExist(".weather .normal.medium sup i.fa-long-arrow-up", 10000);
|
||||
const element = await app.client.getHTML(".weather .normal.medium sup i.fa-long-arrow-up");
|
||||
|
||||
expect(element).to.include("transform:rotate(250deg);");
|
||||
});
|
||||
|
||||
it("should render showHumidity = true", async function() {
|
||||
const weather = generateWeather();
|
||||
await setup([weather, template]);
|
||||
|
||||
await app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(3)", "93", 10000);
|
||||
return app.client.waitForExist(".weather .normal.medium sup i.wi-humidity", 10000);
|
||||
});
|
||||
|
||||
it("should render degreeLabel = true", async function() {
|
||||
const weather = generateWeather();
|
||||
await setup([weather, template]);
|
||||
|
||||
await app.client.waitUntilTextExists(".weather .large.light span.bright", "1°C", 10000);
|
||||
|
||||
return app.client.waitUntilTextExists(".weather .normal.medium span.dimmed", "Feels like -6°C", 10000);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Current weather units", function() {
|
||||
before(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([weather, template]);
|
||||
|
||||
await app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(2)", "6 WSW", 10000);
|
||||
await app.client.waitUntilTextExists(".weather .large.light span.bright", "34,7°", 10000);
|
||||
return app.client.waitUntilTextExists(".weather .normal.medium span.dimmed", "22,0°", 10000);
|
||||
});
|
||||
|
||||
it("should render 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([weather, template]);
|
||||
|
||||
await app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(3)", "93,7", 10000);
|
||||
await app.client.waitUntilTextExists(".weather .large.light span.bright", "34,7°", 10000);
|
||||
return app.client.waitUntilTextExists(".weather .normal.medium span.dimmed", "22,0°", 10000);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@ -10,7 +10,6 @@ const mlog = require("mocha-logger");
|
||||
|
||||
describe("Vendors", function () {
|
||||
|
||||
|
||||
helpers.setupTimeout(this);
|
||||
|
||||
var app = null;
|
||||
|
33
tests/node_modules/webdriverajaxstub/index.js
generated
vendored
Normal file
33
tests/node_modules/webdriverajaxstub/index.js
generated
vendored
Normal file
@ -0,0 +1,33 @@
|
||||
function plugin (wdInstance, requests) {
|
||||
if (typeof wdInstance.addCommand !== "function") {
|
||||
throw new Error("You can't use WebdriverAjaxStub with this version of WebdriverIO");
|
||||
}
|
||||
|
||||
function stub(requests, 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 = requests.shift() || [];
|
||||
this.response = response;
|
||||
this.responseText = response;
|
||||
this.onreadystatechange();
|
||||
};
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
done();
|
||||
}
|
||||
|
||||
wdInstance.addCommand("setupStub", function() {
|
||||
return wdInstance.executeAsync(stub, requests);
|
||||
});
|
||||
}
|
||||
|
||||
module.exports.init = plugin;
|
2
vendor/package-lock.json
generated
vendored
2
vendor/package-lock.json
generated
vendored
@ -5,7 +5,7 @@
|
||||
"dependencies": {
|
||||
"@fortawesome/fontawesome-free": {
|
||||
"version": "5.6.3",
|
||||
"resolved": "https://npm.fontawesome.com/@fortawesome/fontawesome-free/-/fontawesome-free-5.6.3.tgz",
|
||||
"resolved": "https://registry.npmjs.org/@fortawesome/fontawesome-free/-/fontawesome-free-5.6.3.tgz",
|
||||
"integrity": "sha512-s5PLdI9NYgjBvfrv6rhirPHlAHWx+Sfo/IjsAeiXYfmemC/GSjwsyz1wLnGPazbLPXWfk62ks980o9AmsxYUEQ=="
|
||||
},
|
||||
"a-sync-waterfall": {
|
||||
|
Loading…
x
Reference in New Issue
Block a user