mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-08-21 12:55:22 +00:00
loadcoretransations unit test
This commit is contained in:
32
tests/configs/data/en.json
Normal file
32
tests/configs/data/en.json
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
{
|
||||||
|
"LOADING": "Loading …",
|
||||||
|
|
||||||
|
"TODAY": "Today",
|
||||||
|
"TOMORROW": "Tomorrow",
|
||||||
|
"DAYAFTERTOMORROW": "In 2 days",
|
||||||
|
"RUNNING": "Ends in",
|
||||||
|
"EMPTY": "No upcoming events.",
|
||||||
|
|
||||||
|
"WEEK": "Week {weekNumber}",
|
||||||
|
|
||||||
|
"N": "N",
|
||||||
|
"NNE": "NNE",
|
||||||
|
"NE": "NE",
|
||||||
|
"ENE": "ENE",
|
||||||
|
"E": "E",
|
||||||
|
"ESE": "ESE",
|
||||||
|
"SE": "SE",
|
||||||
|
"SSE": "SSE",
|
||||||
|
"S": "S",
|
||||||
|
"SSW": "SSW",
|
||||||
|
"SW": "SW",
|
||||||
|
"WSW": "WSW",
|
||||||
|
"W": "W",
|
||||||
|
"WNW": "WNW",
|
||||||
|
"NW": "NW",
|
||||||
|
"NNW": "NNW",
|
||||||
|
|
||||||
|
"UPDATE_NOTIFICATION": "MagicMirror² update available.",
|
||||||
|
"UPDATE_NOTIFICATION_MODULE": "Update available for MODULE_NAME module.",
|
||||||
|
"UPDATE_INFO": "The current installation is COMMIT_COUNT behind on the BRANCH_NAME branch."
|
||||||
|
}
|
@@ -5,6 +5,26 @@ const fs = require("fs");
|
|||||||
const {JSDOM} = require("jsdom");
|
const {JSDOM} = require("jsdom");
|
||||||
const express = require("express");
|
const express = require("express");
|
||||||
|
|
||||||
|
describe("Translator", function() {
|
||||||
|
let server;
|
||||||
|
|
||||||
|
before(function() {
|
||||||
|
const app = express();
|
||||||
|
|
||||||
|
app.get("/translations/:file", function(req, res) {
|
||||||
|
res.status(200)
|
||||||
|
.header("Access-Control-Allow-Origin", "*")
|
||||||
|
.json(require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", req.params.file)));
|
||||||
|
});
|
||||||
|
|
||||||
|
server = app.listen(3000);
|
||||||
|
});
|
||||||
|
|
||||||
|
after(function() {
|
||||||
|
server.close();
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("translate", function() {
|
||||||
const translations = {
|
const translations = {
|
||||||
"MMM-Module": {
|
"MMM-Module": {
|
||||||
"Hello": "Hallo",
|
"Hello": "Hallo",
|
||||||
@@ -45,8 +65,6 @@ function setTranslations(Translator) {
|
|||||||
Translator.coreTranslationsFallback = coreTranslationsFallback;
|
Translator.coreTranslationsFallback = coreTranslationsFallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
describe("Translator", function() {
|
|
||||||
describe("translate", function() {
|
|
||||||
it("should return custom module translation", function(done) {
|
it("should return custom module translation", function(done) {
|
||||||
const dom = new JSDOM(`<script src="${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously",
|
const dom = new JSDOM(`<script src="${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously",
|
||||||
resources: "usable" });
|
resources: "usable" });
|
||||||
@@ -132,24 +150,6 @@ describe("Translator", function() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let server;
|
|
||||||
|
|
||||||
before(function() {
|
|
||||||
const app = express();
|
|
||||||
|
|
||||||
app.get("/translations/:file", function(req, res) {
|
|
||||||
res.status(200)
|
|
||||||
.header("Access-Control-Allow-Origin", "*")
|
|
||||||
.json(require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", req.params.file)));
|
|
||||||
});
|
|
||||||
|
|
||||||
server = app.listen(3000);
|
|
||||||
});
|
|
||||||
|
|
||||||
after(function() {
|
|
||||||
server.close();
|
|
||||||
});
|
|
||||||
|
|
||||||
it("should load translations", function(done) {
|
it("should load translations", function(done) {
|
||||||
const dom = new JSDOM(`<script>var Log = {log: function(){}};</script><script src="${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously",
|
const dom = new JSDOM(`<script>var Log = {log: function(){}};</script><script src="${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously",
|
||||||
resources: "usable" });
|
resources: "usable" });
|
||||||
@@ -205,4 +205,40 @@ describe("Translator", function() {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("loadCoreTranslations", function() {
|
||||||
|
it("should load core translations and fallback", function(done) {
|
||||||
|
const dom = new JSDOM(`<script>var translations = {en: "http://localhost:3000/translations/en.json"}; var Log = {log: function(){}};</script>\
|
||||||
|
<script src="${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously",
|
||||||
|
resources: "usable" });
|
||||||
|
dom.window.onload = function() {
|
||||||
|
const {Translator} = dom.window;
|
||||||
|
Translator.loadCoreTranslations("en");
|
||||||
|
|
||||||
|
const en = require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", "en.json"));
|
||||||
|
setTimeout(function() {
|
||||||
|
expect(Translator.coreTranslations).to.be.deep.equal(en);
|
||||||
|
expect(Translator.coreTranslationsFallback).to.be.deep.equal(en);
|
||||||
|
done();
|
||||||
|
}, 500);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should load core fallback if language cannot be found", function(done) {
|
||||||
|
const dom = new JSDOM(`<script>var translations = {en: "http://localhost:3000/translations/en.json"}; var Log = {log: function(){}};</script>\
|
||||||
|
<script src="${path.join(__dirname, "..", "..", "..", "js", "translator.js")}">`, { runScripts: "dangerously",
|
||||||
|
resources: "usable" });
|
||||||
|
dom.window.onload = function() {
|
||||||
|
const {Translator} = dom.window;
|
||||||
|
Translator.loadCoreTranslations("MISSINGLANG");
|
||||||
|
|
||||||
|
const en = require(path.join(__dirname, "..", "..", "..", "tests", "configs", "data", "en.json"));
|
||||||
|
setTimeout(function() {
|
||||||
|
expect(Translator.coreTranslations).to.be.deep.equal({});
|
||||||
|
expect(Translator.coreTranslationsFallback).to.be.deep.equal(en);
|
||||||
|
done();
|
||||||
|
}, 500);
|
||||||
|
};
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user