mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-21 12:55:22 +00:00
Merge branch 'develop' into feature/add-error-to-callback
# Conflicts: # CHANGELOG.md
This commit is contained in:
@@ -27,6 +27,8 @@ _This release is scheduled to be released on 2021-04-01._
|
||||
- Converted newsfeed module to use templates.
|
||||
- Update documentation and help screen about invalid config files.
|
||||
- Moving weather provider specific code and configuration into each provider and making hourly part of the interface.
|
||||
- Bump electron to v11.
|
||||
- Dont update the DOM when a module is not displayed.
|
||||
- Callback for `module.show` also gets triggered if lock strings are active but then contains an error `callback(error)`.
|
||||
|
||||
### Removed
|
||||
@@ -42,6 +44,7 @@ _This release is scheduled to be released on 2021-04-01._
|
||||
- Fix Issue with weather forecast icons unit tests with different timezones (#2221)
|
||||
- Fix issue with unencoded characters in translated strings when using nunjuck template (`Loading …` as an example)
|
||||
- Fix socket.io backward compatibility with socket v2 clients
|
||||
- 3rd party module language loading if language is English
|
||||
|
||||
## [2.14.0] - 2021-01-01
|
||||
|
||||
|
@@ -548,6 +548,11 @@ var MM = (function () {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!module.data.position) {
|
||||
Log.warn("module tries to update the DOM without being displayed.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Further implementation is done in the private method.
|
||||
updateDom(module, speed);
|
||||
},
|
||||
|
40
js/module.js
40
js/module.js
@@ -311,33 +311,31 @@ var Module = Class.extend({
|
||||
*
|
||||
* @param {Function} callback Function called when done.
|
||||
*/
|
||||
loadTranslations: function (callback) {
|
||||
var self = this;
|
||||
var translations = this.getTranslations();
|
||||
var lang = config.language.toLowerCase();
|
||||
loadTranslations(callback) {
|
||||
const translations = this.getTranslations() || {};
|
||||
const language = config.language.toLowerCase();
|
||||
|
||||
// The variable `first` will contain the first
|
||||
// defined translation after the following line.
|
||||
for (var first in translations) {
|
||||
break;
|
||||
const languages = Object.keys(translations);
|
||||
const fallbackLanguage = languages[0];
|
||||
|
||||
if (languages.length === 0) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
if (translations) {
|
||||
var translationFile = translations[lang] || undefined;
|
||||
var translationsFallbackFile = translations[first];
|
||||
const translationFile = translations[language];
|
||||
const translationsFallbackFile = translations[fallbackLanguage];
|
||||
|
||||
// If a translation file is set, load it and then also load the fallback translation file.
|
||||
// Otherwise only load the fallback translation file.
|
||||
if (translationFile !== undefined && translationFile !== translationsFallbackFile) {
|
||||
Translator.load(self, translationFile, false, function () {
|
||||
Translator.load(self, translationsFallbackFile, true, callback);
|
||||
});
|
||||
if (!translationFile) {
|
||||
return Translator.load(this, translationsFallbackFile, true, callback);
|
||||
}
|
||||
|
||||
Translator.load(this, translationFile, false, () => {
|
||||
if (translationFile !== translationsFallbackFile) {
|
||||
Translator.load(this, translationsFallbackFile, true, callback);
|
||||
} else {
|
||||
Translator.load(self, translationsFallbackFile, true, callback);
|
||||
callback();
|
||||
}
|
||||
} else {
|
||||
callback();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
|
@@ -103,26 +103,18 @@ var Translator = (function () {
|
||||
* @param {boolean} isFallback Flag to indicate fallback translations.
|
||||
* @param {Function} callback Function called when done.
|
||||
*/
|
||||
load: function (module, file, isFallback, callback) {
|
||||
if (!isFallback) {
|
||||
Log.log(module.name + " - Load translation: " + file);
|
||||
} else {
|
||||
Log.log(module.name + " - Load translation fallback: " + file);
|
||||
load(module, file, isFallback, callback) {
|
||||
Log.log(`${module.name} - Load translation${isFallback && " fallback"}: ${file}`);
|
||||
|
||||
if (this.translationsFallback[module.name]) {
|
||||
return callback();
|
||||
}
|
||||
|
||||
var self = this;
|
||||
if (!this.translationsFallback[module.name]) {
|
||||
loadJSON(module.file(file), function (json) {
|
||||
if (!isFallback) {
|
||||
self.translations[module.name] = json;
|
||||
} else {
|
||||
self.translationsFallback[module.name] = json;
|
||||
}
|
||||
callback();
|
||||
});
|
||||
} else {
|
||||
loadJSON(module.file(file), (json) => {
|
||||
const property = isFallback ? "translationsFallback" : "translations";
|
||||
this[property][module.name] = json;
|
||||
callback();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
/**
|
||||
|
2183
package-lock.json
generated
2183
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -58,14 +58,15 @@
|
||||
"nyc": "^15.1.0",
|
||||
"prettier": "^2.2.1",
|
||||
"pretty-quick": "^3.1.0",
|
||||
"spectron": "^10.0.1",
|
||||
"sinon": "^9.2.4",
|
||||
"spectron": "^13.0.0",
|
||||
"stylelint": "^13.8.0",
|
||||
"stylelint-config-prettier": "^8.0.2",
|
||||
"stylelint-config-standard": "^20.0.0",
|
||||
"stylelint-prettier": "^1.1.2"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"electron": "^8.5.3"
|
||||
"electron": "^11.2.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"colors": "^1.4.0",
|
||||
|
@@ -13,7 +13,8 @@ var config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -13,7 +13,8 @@ var config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -13,7 +13,8 @@ var config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -13,7 +13,8 @@ var config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -11,7 +11,8 @@ let config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -13,7 +13,8 @@ var config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -15,7 +15,8 @@ var config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -13,7 +13,8 @@ var config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -13,7 +13,8 @@ var config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -13,7 +13,8 @@ var config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -11,7 +11,8 @@ let config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -13,7 +13,8 @@ var config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -13,7 +13,8 @@ var config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -13,7 +13,8 @@ var config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -13,7 +13,8 @@ var config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -13,7 +13,8 @@ var config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -13,7 +13,8 @@ var config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -16,7 +16,8 @@ var config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -13,7 +13,8 @@ var config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -14,7 +14,8 @@ let config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -13,7 +13,8 @@ var config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -13,7 +13,8 @@ var config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -14,7 +14,8 @@ var config = {
|
||||
width: 800,
|
||||
height: 600,
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -13,7 +13,8 @@ var config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -13,7 +13,8 @@ var config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -13,7 +13,8 @@ var config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -15,7 +15,8 @@ var config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -15,7 +15,8 @@ let config = {
|
||||
electronOptions: {
|
||||
fullscreen: false,
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -14,7 +14,8 @@ let config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -14,7 +14,8 @@ let config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -14,7 +14,8 @@ let config = {
|
||||
units: "imperial",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -14,7 +14,8 @@ let config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -14,7 +14,8 @@ let config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -13,7 +13,8 @@ var config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -13,7 +13,8 @@ var config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
},
|
||||
|
||||
|
@@ -13,7 +13,8 @@ var config = {
|
||||
units: "metric",
|
||||
electronOptions: {
|
||||
webPreferences: {
|
||||
nodeIntegration: true
|
||||
nodeIntegration: true,
|
||||
enableRemoteModule: true
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@@ -31,25 +31,25 @@ describe("Electron app environment", function () {
|
||||
return helpers.stopApplication(app);
|
||||
});
|
||||
|
||||
it("should open a browserwindow", function () {
|
||||
it("should open a browserwindow", async function () {
|
||||
await app.client.waitUntilWindowLoaded();
|
||||
app.browserWindow.focus();
|
||||
const cnt = await app.client.getWindowCount();
|
||||
const min = await app.browserWindow.isMinimized();
|
||||
const dev = await app.browserWindow.isDevToolsOpened();
|
||||
const vis = await app.browserWindow.isVisible();
|
||||
const foc = await app.browserWindow.isFocused();
|
||||
const bounds = await app.browserWindow.getBounds();
|
||||
const title = await app.browserWindow.getTitle();
|
||||
return (
|
||||
app.client
|
||||
.waitUntilWindowLoaded()
|
||||
// .browserWindow.focus()
|
||||
.getWindowCount()
|
||||
.should.eventually.equal(1)
|
||||
.browserWindow.isMinimized()
|
||||
.should.eventually.be.false.browserWindow.isDevToolsOpened()
|
||||
.should.eventually.be.false.browserWindow.isVisible()
|
||||
.should.eventually.be.true.browserWindow.isFocused()
|
||||
.should.eventually.be.true.browserWindow.getBounds()
|
||||
.should.eventually.have.property("width")
|
||||
.and.be.above(0)
|
||||
.browserWindow.getBounds()
|
||||
.should.eventually.have.property("height")
|
||||
.and.be.above(0)
|
||||
.browserWindow.getTitle()
|
||||
.should.eventually.equal("MagicMirror²")
|
||||
cnt.should.equal(1) &&
|
||||
min.should.be.false &&
|
||||
dev.should.be.false &&
|
||||
vis.should.be.true &&
|
||||
foc.should.be.true &&
|
||||
bounds.should.have.property("width").and.be.above(0) &&
|
||||
bounds.should.have.property("height").and.be.above(0) &&
|
||||
title.should.equal("MagicMirror²")
|
||||
);
|
||||
});
|
||||
|
||||
|
@@ -30,14 +30,16 @@ describe("Clock set to spanish language module", function () {
|
||||
process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/es/clock_24hr.js";
|
||||
});
|
||||
|
||||
it("shows date with correct format", function () {
|
||||
const dateRegex = /^(?:lunes|martes|miércoles|jueves|viernes|sábado|domingo), \d{1,2} de (?:enero|febrero|marzo|abril|mayo|junio|julio|agosto|septiembre|octubre|noviembre|diciembre) de \d{4}$/;
|
||||
return app.client.waitUntilWindowLoaded().getText(".clock .date").should.eventually.match(dateRegex);
|
||||
it("shows date with correct format", async function () {
|
||||
const dateRegex = /^(?:lunes|martes|mi rcoles|jueves|viernes|s bado|domingo), \d{1,2} de (?:enero|febrero|marzo|abril|mayo|junio|julio|agosto|septiembre|octubre|noviembre|diciembre) de \d{4}$/;
|
||||
const elem = await app.client.$(".clock .date");
|
||||
return elem.getText(".clock .date").should.eventually.match(dateRegex);
|
||||
});
|
||||
|
||||
it("shows time in 24hr format", function () {
|
||||
it("shows time in 24hr format", async function () {
|
||||
const timeRegex = /^(?:2[0-3]|[01]\d):[0-5]\d[0-5]\d$/;
|
||||
return app.client.waitUntilWindowLoaded().getText(".clock .time").should.eventually.match(timeRegex);
|
||||
const elem = await app.client.$(".clock .time");
|
||||
return elem.getText(".clock .time").should.eventually.match(timeRegex);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -47,14 +49,16 @@ describe("Clock set to spanish language module", function () {
|
||||
process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/es/clock_12hr.js";
|
||||
});
|
||||
|
||||
it("shows date with correct format", function () {
|
||||
it("shows date with correct format", async function () {
|
||||
const dateRegex = /^(?:lunes|martes|miércoles|jueves|viernes|sábado|domingo), \d{1,2} de (?:enero|febrero|marzo|abril|mayo|junio|julio|agosto|septiembre|octubre|noviembre|diciembre) de \d{4}$/;
|
||||
return app.client.waitUntilWindowLoaded().getText(".clock .date").should.eventually.match(dateRegex);
|
||||
const elem = await app.client.$(".clock .date");
|
||||
return elem.getText(".clock .date").should.eventually.match(dateRegex);
|
||||
});
|
||||
|
||||
it("shows time in 12hr format", function () {
|
||||
it("shows time in 12hr format", async function () {
|
||||
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[ap]m$/;
|
||||
return app.client.waitUntilWindowLoaded().getText(".clock .time").should.eventually.match(timeRegex);
|
||||
const elem = await app.client.$(".clock .time");
|
||||
return elem.getText(".clock .time").should.eventually.match(timeRegex);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -64,9 +68,10 @@ describe("Clock set to spanish language module", function () {
|
||||
process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/es/clock_showPeriodUpper.js";
|
||||
});
|
||||
|
||||
it("shows 12hr time with upper case AM/PM", function () {
|
||||
it("shows 12hr time with upper case AM/PM", async function () {
|
||||
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[AP]M$/;
|
||||
return app.client.waitUntilWindowLoaded().getText(".clock .time").should.eventually.match(timeRegex);
|
||||
const elem = await app.client.$(".clock .time");
|
||||
return elem.getText(".clock .time").should.eventually.match(timeRegex);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -76,9 +81,10 @@ describe("Clock set to spanish language module", function () {
|
||||
process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/es/clock_showWeek.js";
|
||||
});
|
||||
|
||||
it("shows week with correct format", function () {
|
||||
it("shows week with correct format", async function () {
|
||||
const weekRegex = /^Semana [0-9]{1,2}$/;
|
||||
return app.client.waitUntilWindowLoaded().getText(".clock .week").should.eventually.match(weekRegex);
|
||||
const elem = await app.client.$(".clock .week");
|
||||
elem.getText(".clock .week").should.eventually.match(weekRegex);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -32,14 +32,16 @@ describe("Clock module", function () {
|
||||
process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/clock_24hr.js";
|
||||
});
|
||||
|
||||
it("should show the date in the correct format", function () {
|
||||
it("should show the date in the correct format", async function () {
|
||||
const dateRegex = /^(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (?:January|February|March|April|May|June|July|August|September|October|November|December) \d{1,2}, \d{4}$/;
|
||||
return app.client.waitUntilWindowLoaded().getText(".clock .date").should.eventually.match(dateRegex);
|
||||
const elem = await app.client.$(".clock .date");
|
||||
return elem.getText(".clock .date").should.eventually.match(dateRegex);
|
||||
});
|
||||
|
||||
it("should show the time in 24hr format", function () {
|
||||
it("should show the time in 24hr format", async function () {
|
||||
const timeRegex = /^(?:2[0-3]|[01]\d):[0-5]\d[0-5]\d$/;
|
||||
return app.client.waitUntilWindowLoaded().getText(".clock .time").should.eventually.match(timeRegex);
|
||||
const elem = await app.client.$(".clock .time");
|
||||
return elem.getText(".clock .time").should.eventually.match(timeRegex);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -49,14 +51,16 @@ describe("Clock module", function () {
|
||||
process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/clock_12hr.js";
|
||||
});
|
||||
|
||||
it("should show the date in the correct format", function () {
|
||||
it("should show the date in the correct format", async function () {
|
||||
const dateRegex = /^(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (?:January|February|March|April|May|June|July|August|September|October|November|December) \d{1,2}, \d{4}$/;
|
||||
return app.client.waitUntilWindowLoaded().getText(".clock .date").should.eventually.match(dateRegex);
|
||||
const elem = await app.client.$(".clock .date");
|
||||
return elem.getText(".clock .date").should.eventually.match(dateRegex);
|
||||
});
|
||||
|
||||
it("should show the time in 12hr format", function () {
|
||||
it("should show the time in 12hr format", async function () {
|
||||
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[ap]m$/;
|
||||
return app.client.waitUntilWindowLoaded().getText(".clock .time").should.eventually.match(timeRegex);
|
||||
const elem = await app.client.$(".clock .time");
|
||||
return elem.getText(".clock .time").should.eventually.match(timeRegex);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -66,9 +70,10 @@ describe("Clock module", function () {
|
||||
process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/clock_showPeriodUpper.js";
|
||||
});
|
||||
|
||||
it("should show 12hr time with upper case AM/PM", function () {
|
||||
it("should show 12hr time with upper case AM/PM", async function () {
|
||||
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[0-5]\d[AP]M$/;
|
||||
return app.client.waitUntilWindowLoaded().getText(".clock .time").should.eventually.match(timeRegex);
|
||||
const elem = await app.client.$(".clock .time");
|
||||
return elem.getText(".clock .time").should.eventually.match(timeRegex);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -78,9 +83,10 @@ describe("Clock module", function () {
|
||||
process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/clock_displaySeconds_false.js";
|
||||
});
|
||||
|
||||
it("should show 12hr time without seconds am/pm", function () {
|
||||
it("should show 12hr time without seconds am/pm", async function () {
|
||||
const timeRegex = /^(?:1[0-2]|[1-9]):[0-5]\d[ap]m$/;
|
||||
return app.client.waitUntilWindowLoaded().getText(".clock .time").should.eventually.match(timeRegex);
|
||||
const elem = await app.client.$(".clock .time");
|
||||
return elem.getText(".clock .time").should.eventually.match(timeRegex);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -90,15 +96,17 @@ describe("Clock module", function () {
|
||||
process.env.MM_CONFIG_FILE = "tests/configs/modules/clock/clock_showWeek.js";
|
||||
});
|
||||
|
||||
it("should show the week in the correct format", function () {
|
||||
it("should show the week in the correct format", async function () {
|
||||
const weekRegex = /^Week [0-9]{1,2}$/;
|
||||
return app.client.waitUntilWindowLoaded().getText(".clock .week").should.eventually.match(weekRegex);
|
||||
const elem = await app.client.$(".clock .week");
|
||||
return elem.getText(".clock .week").should.eventually.match(weekRegex);
|
||||
});
|
||||
|
||||
it("should show the week with the correct number of week of year", function () {
|
||||
it("should show the week with the correct number of week of year", async function () {
|
||||
const currentWeekNumber = moment().week();
|
||||
const weekToShow = "Week " + currentWeekNumber;
|
||||
return app.client.waitUntilWindowLoaded().getText(".clock .week").should.eventually.equal(weekToShow);
|
||||
const elem = await app.client.$(".clock .week");
|
||||
return elem.getText(".clock .week").should.eventually.equal(weekToShow);
|
||||
});
|
||||
});
|
||||
|
||||
|
@@ -31,42 +31,36 @@ describe("Compliments module", function () {
|
||||
process.env.MM_CONFIG_FILE = "tests/configs/modules/compliments/compliments_parts_day.js";
|
||||
});
|
||||
|
||||
it("if Morning compliments for that part of day", function () {
|
||||
it("if Morning compliments for that part of day", async function () {
|
||||
var hour = new Date().getHours();
|
||||
if (hour >= 3 && hour < 12) {
|
||||
// if morning check
|
||||
return app.client
|
||||
.waitUntilWindowLoaded()
|
||||
.getText(".compliments")
|
||||
.then(function (text) {
|
||||
expect(text).to.be.oneOf(["Hi", "Good Morning", "Morning test"]);
|
||||
});
|
||||
const elem = await app.client.$(".compliments");
|
||||
return elem.getText(".compliments").then(function (text) {
|
||||
expect(text).to.be.oneOf(["Hi", "Good Morning", "Morning test"]);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it("if Afternoon show Compliments for that part of day", function () {
|
||||
it("if Afternoon show Compliments for that part of day", async function () {
|
||||
var hour = new Date().getHours();
|
||||
if (hour >= 12 && hour < 17) {
|
||||
// if morning check
|
||||
return app.client
|
||||
.waitUntilWindowLoaded()
|
||||
.getText(".compliments")
|
||||
.then(function (text) {
|
||||
expect(text).to.be.oneOf(["Hello", "Good Afternoon", "Afternoon test"]);
|
||||
});
|
||||
const elem = await app.client.$(".compliments");
|
||||
return elem.getText(".compliments").then(function (text) {
|
||||
expect(text).to.be.oneOf(["Hello", "Good Afternoon", "Afternoon test"]);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
it("if Evening show Compliments for that part of day", function () {
|
||||
it("if Evening show Compliments for that part of day", async function () {
|
||||
var hour = new Date().getHours();
|
||||
if (!(hour >= 3 && hour < 12) && !(hour >= 12 && hour < 17)) {
|
||||
// if evening check
|
||||
return app.client
|
||||
.waitUntilWindowLoaded()
|
||||
.getText(".compliments")
|
||||
.then(function (text) {
|
||||
expect(text).to.be.oneOf(["Hello There", "Good Evening", "Evening test"]);
|
||||
});
|
||||
const elem = await app.client.$(".compliments");
|
||||
return elem.getText(".compliments").then(function (text) {
|
||||
expect(text).to.be.oneOf(["Hello There", "Good Evening", "Evening test"]);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -78,13 +72,11 @@ describe("Compliments module", function () {
|
||||
process.env.MM_CONFIG_FILE = "tests/configs/modules/compliments/compliments_anytime.js";
|
||||
});
|
||||
|
||||
it("Show anytime because if configure empty parts of day compliments and set anytime compliments", function () {
|
||||
return app.client
|
||||
.waitUntilWindowLoaded()
|
||||
.getText(".compliments")
|
||||
.then(function (text) {
|
||||
expect(text).to.be.oneOf(["Anytime here"]);
|
||||
});
|
||||
it("Show anytime because if configure empty parts of day compliments and set anytime compliments", async function () {
|
||||
const elem = await app.client.$(".compliments");
|
||||
return elem.getText(".compliments").then(function (text) {
|
||||
expect(text).to.be.oneOf(["Anytime here"]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -94,13 +86,11 @@ describe("Compliments module", function () {
|
||||
process.env.MM_CONFIG_FILE = "tests/configs/modules/compliments/compliments_only_anytime.js";
|
||||
});
|
||||
|
||||
it("Show anytime compliments", function () {
|
||||
return app.client
|
||||
.waitUntilWindowLoaded()
|
||||
.getText(".compliments")
|
||||
.then(function (text) {
|
||||
expect(text).to.be.oneOf(["Anytime here"]);
|
||||
});
|
||||
it("Show anytime compliments", async function () {
|
||||
const elem = await app.client.$(".compliments");
|
||||
return elem.getText(".compliments").then(function (text) {
|
||||
expect(text).to.be.oneOf(["Anytime here"]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -112,13 +102,11 @@ describe("Compliments module", function () {
|
||||
process.env.MM_CONFIG_FILE = "tests/configs/modules/compliments/compliments_date.js";
|
||||
});
|
||||
|
||||
it("Show happy new year compliment on new years day", function () {
|
||||
return app.client
|
||||
.waitUntilWindowLoaded()
|
||||
.getText(".compliments")
|
||||
.then(function (text) {
|
||||
expect(text).to.be.oneOf(["Happy new year!"]);
|
||||
});
|
||||
it("Show happy new year compliment on new years day", async function () {
|
||||
const elem = await app.client.$(".compliments");
|
||||
return elem.getText(".compliments").then(function (text) {
|
||||
expect(text).to.be.oneOf(["Happy new year!"]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -30,8 +30,9 @@ describe("Test helloworld module", function () {
|
||||
process.env.MM_CONFIG_FILE = "tests/configs/modules/helloworld/helloworld.js";
|
||||
});
|
||||
|
||||
it("Test message helloworld module", function () {
|
||||
return app.client.waitUntilWindowLoaded().getText(".helloworld").should.eventually.equal("Test HelloWorld Module");
|
||||
it("Test message helloworld module", async function () {
|
||||
const elem = await app.client.$("helloworld");
|
||||
return elem.getText(".helloworld").should.eventually.equal("Test HelloWorld Module");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -41,8 +42,9 @@ describe("Test helloworld module", function () {
|
||||
process.env.MM_CONFIG_FILE = "tests/configs/modules/helloworld/helloworld_default.js";
|
||||
});
|
||||
|
||||
it("Test message helloworld module", function () {
|
||||
return app.client.waitUntilWindowLoaded().getText(".helloworld").should.eventually.equal("Hello World!");
|
||||
it("Test message helloworld module", async function () {
|
||||
const elem = await app.client.$("helloworld");
|
||||
return elem.getText(".helloworld").should.eventually.equal("Hello World!");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -43,7 +43,7 @@ describe("Weather module", function () {
|
||||
const weather = generateWeather();
|
||||
await setup({ template, data: weather });
|
||||
|
||||
return app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(2)", "6 WSW", 10000);
|
||||
return await app.client.$(".weather .normal.medium span:nth-child(2)", "6 WSW", 10000);
|
||||
});
|
||||
|
||||
it("should render sunrise", async function () {
|
||||
@@ -53,9 +53,9 @@ describe("Weather module", function () {
|
||||
const weather = generateWeather({ sys: { sunrise, sunset } });
|
||||
await setup({ template, data: weather });
|
||||
|
||||
await app.client.waitForExist(".weather .normal.medium span.wi.dimmed.wi-sunrise", 10000);
|
||||
await app.client.$(".weather .normal.medium span.wi.dimmed.wi-sunrise", 10000);
|
||||
|
||||
return app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(4)", "12:00 am", 10000);
|
||||
return await app.client.$(".weather .normal.medium span:nth-child(4)", "12:00 am", 10000);
|
||||
});
|
||||
|
||||
it("should render sunset", async function () {
|
||||
@@ -65,25 +65,25 @@ describe("Weather module", function () {
|
||||
const weather = generateWeather({ sys: { sunrise, sunset } });
|
||||
await setup({ template, data: weather });
|
||||
|
||||
await app.client.waitForExist(".weather .normal.medium span.wi.dimmed.wi-sunset", 10000);
|
||||
await app.client.$(".weather .normal.medium span.wi.dimmed.wi-sunset", 10000);
|
||||
|
||||
return app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(4)", "11:59 pm", 10000);
|
||||
return await app.client.$(".weather .normal.medium span:nth-child(4)", "11:59 pm", 10000);
|
||||
});
|
||||
|
||||
it("should render temperature with icon", async function () {
|
||||
const weather = generateWeather();
|
||||
await setup({ template, data: weather });
|
||||
|
||||
await app.client.waitForExist(".weather .large.light span.wi.weathericon.wi-snow", 10000);
|
||||
await app.client.$(".weather .large.light span.wi.weathericon.wi-snow", 10000);
|
||||
|
||||
return app.client.waitUntilTextExists(".weather .large.light span.bright", "1.5°", 10000);
|
||||
return await app.client.$(".weather .large.light span.bright", "1.5°", 10000);
|
||||
});
|
||||
|
||||
it("should render feels like temperature", async function () {
|
||||
const weather = generateWeather();
|
||||
await setup({ template, data: weather });
|
||||
|
||||
return app.client.waitUntilTextExists(".weather .normal.medium span.dimmed", "Feels like -5.6°", 10000);
|
||||
return await app.client.$(".weather .normal.medium span.dimmed", "Feels like -5.6°", 10000);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -96,7 +96,7 @@ describe("Weather module", function () {
|
||||
const weather = generateWeather();
|
||||
await setup({ template, data: weather });
|
||||
|
||||
return app.client.waitUntilTextExists(".compliments .module-content span", "snow", 10000);
|
||||
return await app.client.$(".compliments .module-content span", "snow", 10000);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -109,15 +109,15 @@ describe("Weather module", function () {
|
||||
const weather = generateWeather();
|
||||
await setup({ template, data: weather });
|
||||
|
||||
return app.client.waitUntilTextExists(".weather .normal.medium span:nth-child(2)", "12", 10000);
|
||||
return await app.client.$(".weather .normal.medium span:nth-child(2)", "12", 10000);
|
||||
});
|
||||
|
||||
it("should render showWindDirectionAsArrow = true", async function () {
|
||||
const weather = generateWeather();
|
||||
await setup({ template, data: weather });
|
||||
|
||||
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");
|
||||
const elem = await app.client.$(".weather .normal.medium sup i.fa-long-arrow-up", 10000);
|
||||
const element = await elem.getHTML(".weather .normal.medium sup i.fa-long-arrow-up");
|
||||
|
||||
expect(element).to.include("transform:rotate(250deg);");
|
||||
});
|
||||
@@ -126,17 +126,17 @@ describe("Weather module", function () {
|
||||
const weather = generateWeather();
|
||||
await setup({ template, data: weather });
|
||||
|
||||
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);
|
||||
await app.client.$(".weather .normal.medium span:nth-child(3)", "93", 10000);
|
||||
return await app.client.$(".weather .normal.medium sup i.wi-humidity", 10000);
|
||||
});
|
||||
|
||||
it("should render degreeLabel = true", async function () {
|
||||
const weather = generateWeather();
|
||||
await setup({ template, data: weather });
|
||||
|
||||
await app.client.waitUntilTextExists(".weather .large.light span.bright", "1°C", 10000);
|
||||
await app.client.$(".weather .large.light span.bright", "1°C", 10000);
|
||||
|
||||
return app.client.waitUntilTextExists(".weather .normal.medium span.dimmed", "Feels like -6°C", 10000);
|
||||
return await app.client.$(".weather .normal.medium span.dimmed", "Feels like -6°C", 10000);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -158,9 +158,9 @@ describe("Weather module", function () {
|
||||
});
|
||||
await setup({ template, data: weather });
|
||||
|
||||
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);
|
||||
await app.client.$(".weather .normal.medium span:nth-child(2)", "6 WSW", 10000);
|
||||
await app.client.$(".weather .large.light span.bright", "34,7°", 10000);
|
||||
return await app.client.$(".weather .normal.medium span.dimmed", "22,0°", 10000);
|
||||
});
|
||||
|
||||
it("should render decimalSymbol = ','", async function () {
|
||||
@@ -176,9 +176,9 @@ describe("Weather module", function () {
|
||||
});
|
||||
await setup({ template, data: weather });
|
||||
|
||||
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);
|
||||
await app.client.$(".weather .normal.medium span:nth-child(3)", "93,7", 10000);
|
||||
await app.client.$(".weather .large.light span.bright", "34,7°", 10000);
|
||||
return await app.client.$(".weather .normal.medium span.dimmed", "22,0°", 10000);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -202,7 +202,7 @@ describe("Weather module", function () {
|
||||
const days = ["Today", "Tomorrow", "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);
|
||||
await app.client.$(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(1)`, day, 10000);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -213,7 +213,7 @@ describe("Weather module", function () {
|
||||
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);
|
||||
await app.client.$(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(2) span.wi-${icon}`, 10000);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -224,7 +224,7 @@ describe("Weather module", 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);
|
||||
await app.client.$(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(3)`, temp, 10000);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -235,7 +235,7 @@ describe("Weather module", function () {
|
||||
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);
|
||||
await app.client.$(`.weather table.small tr:nth-child(${index + 1}) td:nth-child(4)`, temp, 10000);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -245,10 +245,10 @@ describe("Weather module", function () {
|
||||
|
||||
const opacities = [1, 1, 0.8, 0.5333333333333333, 0.2666666666666667];
|
||||
|
||||
await app.client.waitForExist(".weather table.small", 10000);
|
||||
const elem = await app.client.$(".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})`);
|
||||
const html = await elem.getHTML(`.weather table.small tr:nth-child(${index + 1})`);
|
||||
expect(html).to.includes(`<tr style="opacity: ${opacity};">`);
|
||||
}
|
||||
});
|
||||
@@ -263,14 +263,14 @@ describe("Weather module", function () {
|
||||
const weather = generateWeatherForecast();
|
||||
await setup({ template, data: weather });
|
||||
|
||||
await app.client.waitForExist(".weather table.myTableClass", 10000);
|
||||
await app.client.$(".weather table.myTableClass", 10000);
|
||||
});
|
||||
|
||||
it("should render colored rows", async function () {
|
||||
const weather = generateWeatherForecast();
|
||||
await setup({ template, data: weather });
|
||||
|
||||
await app.client.waitForExist(".weather table.myTableClass", 10000);
|
||||
await app.client.$(".weather table.myTableClass", 10000);
|
||||
|
||||
const rows = await app.client.$$(".weather table.myTableClass tr.colored");
|
||||
|
||||
|
@@ -29,13 +29,13 @@ describe("Display of modules", function () {
|
||||
});
|
||||
|
||||
it("should show the test header", async () => {
|
||||
await app.client.waitForExist("#module_0_helloworld", 10000);
|
||||
return app.client.element("#module_0_helloworld .module-header").isVisible().should.eventually.equal(true).getText("#module_0_helloworld .module-header").should.eventually.equal("TEST_HEADER");
|
||||
const elem = await app.client.$("#module_0_helloworld .module-header", 10000);
|
||||
return elem.getText("#module_0_helloworld .module-header").should.eventually.equal("TEST_HEADER");
|
||||
});
|
||||
|
||||
it("should show no header if no header text is specified", async () => {
|
||||
await app.client.waitForExist("#module_1_helloworld", 10000);
|
||||
return app.client.element("#module_1_helloworld .module-header").isVisible().should.eventually.equal(false);
|
||||
const elem = await app.client.$("#module_1_helloworld .module-header", 10000);
|
||||
return elem.getText("#module_1_helloworld .module-header").should.eventually.equal(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@@ -33,10 +33,9 @@ describe("Position of modules", function () {
|
||||
position = positions[idx];
|
||||
className = position.replace("_", ".");
|
||||
it("show text in " + position, function () {
|
||||
return app.client
|
||||
.waitUntilWindowLoaded()
|
||||
.getText("." + className)
|
||||
.should.eventually.equal("Text in " + position);
|
||||
app.client.$("." + className).then((result) => {
|
||||
return this.getText("." + className).should.eventually.equal("Text in " + position);
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
@@ -7,6 +7,7 @@ const translations = require("../../translations/translations.js");
|
||||
const helmet = require("helmet");
|
||||
const { JSDOM } = require("jsdom");
|
||||
const express = require("express");
|
||||
const sinon = require("sinon");
|
||||
|
||||
describe("Translations", function () {
|
||||
let server;
|
||||
@@ -34,6 +35,97 @@ describe("Translations", function () {
|
||||
}
|
||||
});
|
||||
|
||||
describe("loadTranslations", () => {
|
||||
let dom;
|
||||
|
||||
beforeEach(() => {
|
||||
dom = new JSDOM(
|
||||
`<script>var Translator = {}; var Log = {log: function(){}}; var config = {language: 'de'};</script>\
|
||||
<script src="file://${path.join(__dirname, "..", "..", "js", "class.js")}"></script>\
|
||||
<script src="file://${path.join(__dirname, "..", "..", "js", "module.js")}"></script>`,
|
||||
{ runScripts: "dangerously", resources: "usable" }
|
||||
);
|
||||
});
|
||||
|
||||
it("should load translation file", (done) => {
|
||||
dom.window.onload = async function () {
|
||||
const { Translator, Module, config } = dom.window;
|
||||
config.language = "en";
|
||||
Translator.load = sinon.stub().callsFake((_m, _f, _fb, callback) => callback());
|
||||
|
||||
Module.register("name", { getTranslations: () => translations });
|
||||
const MMM = Module.create("name");
|
||||
|
||||
const loaded = sinon.stub();
|
||||
MMM.loadTranslations(loaded);
|
||||
|
||||
expect(loaded.callCount).to.equal(1);
|
||||
expect(Translator.load.args.length).to.equal(1);
|
||||
expect(Translator.load.calledWith(MMM, "translations/en.json", false, sinon.match.func)).to.be.true;
|
||||
|
||||
done();
|
||||
};
|
||||
});
|
||||
|
||||
it("should load translation + fallback file", (done) => {
|
||||
dom.window.onload = async function () {
|
||||
const { Translator, Module } = dom.window;
|
||||
Translator.load = sinon.stub().callsFake((_m, _f, _fb, callback) => callback());
|
||||
|
||||
Module.register("name", { getTranslations: () => translations });
|
||||
const MMM = Module.create("name");
|
||||
|
||||
const loaded = sinon.stub();
|
||||
MMM.loadTranslations(loaded);
|
||||
|
||||
expect(loaded.callCount).to.equal(1);
|
||||
expect(Translator.load.args.length).to.equal(2);
|
||||
expect(Translator.load.calledWith(MMM, "translations/de.json", false, sinon.match.func)).to.be.true;
|
||||
expect(Translator.load.calledWith(MMM, "translations/en.json", true, sinon.match.func)).to.be.true;
|
||||
|
||||
done();
|
||||
};
|
||||
});
|
||||
|
||||
it("should load translation fallback file", (done) => {
|
||||
dom.window.onload = async function () {
|
||||
const { Translator, Module, config } = dom.window;
|
||||
config.language = "--";
|
||||
Translator.load = sinon.stub().callsFake((_m, _f, _fb, callback) => callback());
|
||||
|
||||
Module.register("name", { getTranslations: () => translations });
|
||||
const MMM = Module.create("name");
|
||||
|
||||
const loaded = sinon.stub();
|
||||
MMM.loadTranslations(loaded);
|
||||
|
||||
expect(loaded.callCount).to.equal(1);
|
||||
expect(Translator.load.args.length).to.equal(1);
|
||||
expect(Translator.load.calledWith(MMM, "translations/en.json", true, sinon.match.func)).to.be.true;
|
||||
|
||||
done();
|
||||
};
|
||||
});
|
||||
|
||||
it("should load no file", (done) => {
|
||||
dom.window.onload = async function () {
|
||||
const { Translator, Module } = dom.window;
|
||||
Translator.load = sinon.stub();
|
||||
|
||||
Module.register("name", {});
|
||||
const MMM = Module.create("name");
|
||||
|
||||
const loaded = sinon.stub();
|
||||
MMM.loadTranslations(loaded);
|
||||
|
||||
expect(loaded.callCount).to.equal(1);
|
||||
expect(Translator.load.callCount).to.equal(0);
|
||||
|
||||
done();
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
const mmm = {
|
||||
name: "TranslationTest",
|
||||
file(file) {
|
||||
|
@@ -29,11 +29,13 @@ describe("Check configuration without modules", function () {
|
||||
process.env.MM_CONFIG_FILE = "tests/configs/without_modules.js";
|
||||
});
|
||||
|
||||
it("Show the message MagicMirror title", function () {
|
||||
return app.client.waitUntilWindowLoaded().getText("#module_1_helloworld .module-content").should.eventually.equal("Magic Mirror2");
|
||||
it("Show the message MagicMirror title", async function () {
|
||||
const elem = await app.client.$("#module_1_helloworld .module-content");
|
||||
return elem.getText("#module_1_helloworld .module-content").should.eventually.equal("Magic Mirror2");
|
||||
});
|
||||
|
||||
it("Show the text Michael's website", function () {
|
||||
return app.client.waitUntilWindowLoaded().getText("#module_5_helloworld .module-content").should.eventually.equal("www.michaelteeuw.nl");
|
||||
it("Show the text Michael's website", async function () {
|
||||
const elem = await app.client.$("#module_5_helloworld .module-content");
|
||||
return elem.getText("#module_5_helloworld .module-content").should.eventually.equal("www.michaelteeuw.nl");
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user