Skip to content
Snippets Groups Projects
Verified Commit 69e30f68 authored by Volker Schukai's avatar Volker Schukai :alien:
Browse files

chore: add pipe and i18n test

parent 1ceabf1a
No related branches found
No related tags found
No related merge requests found
...@@ -109,7 +109,7 @@ class Embed extends Provider { ...@@ -109,7 +109,7 @@ class Embed extends Provider {
let translations = null; let translations = null;
try { try {
translations = JSON.parse(this.translateElement.innerHTML); translations = JSON.parse(this.translateElement.innerHTML.trim());
} catch (e) { } catch (e) {
reject(e); reject(e);
return; return;
...@@ -150,8 +150,6 @@ class Embed extends Provider { ...@@ -150,8 +150,6 @@ class Embed extends Provider {
const promises = []; const promises = [];
let result
list.forEach((translationElement) => { list.forEach((translationElement) => {
const p = new Embed(translationElement); const p = new Embed(translationElement);
promises.push(p.assignToElement(undefined, element)); promises.push(p.assignToElement(undefined, element));
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
import {expect} from "chai" import {expect} from "chai"
import {Pipe} from "../../../../application/source/data/pipe.mjs"; import {Pipe} from "../../../../application/source/data/pipe.mjs";
import {initJSDOM} from "../../util/jsdom.mjs"; import {initJSDOM} from "../../util/jsdom.mjs";
import {Embed} from "../../../../application/source/i18n/providers/embed.mjs";
describe('Pipe', function () { describe('Pipe', function () {
...@@ -83,4 +84,63 @@ describe('Pipe', function () { ...@@ -83,4 +84,63 @@ describe('Pipe', function () {
}); });
describe('new Pipe and locale', function () {
let html1 = `
<div id="mock-translations"></div>
<script type="application/json" data-monster-role="translations">
{
"51": "xyz",
"52": "abc",
"53": "def"
}
</script>
`;
beforeEach((done) => {
let mocks = document.getElementById('mocks');
mocks.innerHTML = html1;
let elem = document.getElementById('mock-translations');
Embed.assignTranslationsToElement(elem).then((o) => {
done()
}).catch((e) => {
done(e)
})
})
afterEach(() => {
let mocks = document.getElementById('mocks');
mocks.innerHTML = "";
})
before(function (done) {
initJSDOM().then(() => {
done()
});
});
[
['path:status | tostring | i18n', {status: 51}, "xyz"]
].forEach(function (data) {
let pipe = data.shift()
let obj = data.shift()
let expected = data.shift()
it('should transform(' + pipe + ').run(' + JSON.stringify(obj) + ') return ' + JSON.stringify(expected), function () {
let t = new Pipe(pipe);
expect(t.run(obj)).to.be.equal(expected);
});
})
})
}); });
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment