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

chore: write and update tests

parent fb24975c
No related branches found
No related tags found
No related merge requests found
......@@ -4,7 +4,6 @@ import {expect} from "chai"
import {RestAPI} from "../../../../../../application/source/data/datasource/server/restapi.mjs";
import {validateObject} from "../../../../../../application/source/types/validate.mjs";
describe('RestAPI', function () {
let fetchReference;
......
......@@ -197,4 +197,37 @@ describe('Transformer', function () {
}).to.throw(TypeError);
});
});
describe('i18n', function () {
let html1 = `
<div id="test1">
</div>
`;
beforeEach(() => {
let mocks = document.getElementById('mocks');
mocks.innerHTML = html1;
})
afterEach(() => {
let mocks = document.getElementById('mocks');
mocks.innerHTML = "";
})
before(function (done) {
initJSDOM().then(() => {
done()
});
});
it('should', function () {
const t = new Transformer('i18n:en:de');
});
})
});
\ No newline at end of file
......@@ -35,7 +35,6 @@ describe('Attributes', function () {
})
});
......@@ -45,11 +44,15 @@ describe('Attributes', function () {
it('return language en', function () {
let html = document.getElementsByTagName('html');
let node = html.item(0);
let lang= node.getAttribute('lang');
node.removeAttribute('lang');
const locale = getLocaleOfDocument();
expect(locale).to.be.instanceOf(Locale);
expect(locale.localeString).to.be.equal('en-US');
expect(locale.localeString).to.be.equal(navigator.language);
node.setAttribute('lang', lang);
})
......
import {expect} from "chai"
import {ATTRIBUTE_OBJECTLINK} from "../../../../application/source/dom/constants.mjs";
import {getLinkedObjects} from "../../../../application/source/dom/attributes.mjs";
import {Provider} from "../../../../application/source/i18n/provider.mjs";
import {initJSDOM} from "../../util/jsdom.mjs";
import {getDocumentTranslations, Translations} from "../../../../application/source/i18n/translations.mjs";
describe('Provider', function () {
describe('Instance and Init', function () {
it('create instance', function () {
expect((new Provider()).getTranslations('en')).is.instanceof(Promise);
let html1 = `
<div id="test1">
</div>
`;
beforeEach(() => {
let mocks = document.getElementById('mocks');
mocks.innerHTML = html1;
})
afterEach(() => {
let mocks = document.getElementById('mocks');
mocks.innerHTML = "";
})
before(function (done) {
initJSDOM().then(() => {
done()
});
});
describe('Provider and Dom', function () {
const translationsLinkSymbol = Symbol.for("@schukai/monster/i18n/translations@@link");
it('assignToElement', function (done) {
const element = document.getElementById('test1');
const p = new Provider();
const r = p.assignToElement(undefined, element);
r.then((e) => {
const s = element.getAttribute(ATTRIBUTE_OBJECTLINK);
if (s === null) {
done(new Error("Attribute not set"));
return;
}
const i = getLinkedObjects(element, translationsLinkSymbol)
if (i === null) {
done(new Error("No linked object found"));
return;
}
let counter = 0;
for (let v of i) {
counter++;
}
if (counter !== 1) {
done(new Error("No linked object found"));
return;
}
const docTrans = getDocumentTranslations(element)
expect(docTrans).is.instanceof(Translations);
done();
}).catch(e => done(e));
});
});
......
import {expect} from "chai"
import {parseLocale} from "../../../../application/source/i18n/locale.mjs";
import {Translations} from "../../../../application/source/i18n/translations.mjs";
import {Embed} from "../../../../application/source/i18n/providers/embed.mjs";
import {
Translations,
getDocumentTranslations
} from "../../../../application/source/i18n/translations.mjs";
import {initJSDOM} from "../../util/jsdom.mjs";
describe('Translations', function () {
......@@ -53,5 +59,76 @@ describe('Translations', function () {
});
/**
* initDocumentTranslation
*/
describe("test initDocumentTranslation ", function () {
let html1 = `<div id="mock-translations"></div>
<script type="application/json" data-monster-role="translations">
{
"test1": "abc",
"test2": {
"other": "xyz"
}
}
</script>
<script type="application/json" data-monster-role="translations">
{
"test1": "xyz",
"test3": {
"other": "xyz"
}
}
</script>
`;
beforeEach(() => {
let mocks = document.getElementById('mocks');
mocks.innerHTML = html1;
})
afterEach(() => {
let mocks = document.getElementById('mocks');
mocks.innerHTML = "";
})
before(function (done) {
initJSDOM().then(() => {
done()
});
});
it('Init translations', function (done) {
let elem = document.getElementById('mock-translations');
Embed.assignTranslationsToElement(elem).then((o) => {
let mocks = document.getElementById('mocks');
// no exception because of default
expect(getDocumentTranslations(elem).getText('no-key','with-default'))
.is.equal('with-default');
expect(getDocumentTranslations(elem).getText('test1'))
.is.equal('xyz');
done();
}).catch((e) => {
done(e);
})
});
})
});
\ No newline at end of file
......@@ -4,7 +4,6 @@ import {extend} from "../../../application/source/data/extend.mjs";
import {getGlobal} from "../../../application/source/types/global.mjs";
export const isBrowser = new Function("try {return this===window;}catch(e){ return false;}");
export const isNode = new Function("try {return this===global;}catch(e){return false;}");
......
......@@ -28,6 +28,7 @@ import "../cases/dom/assembler.mjs";
import "../cases/i18n/translations.mjs";
import "../cases/i18n/locale.mjs";
import "../cases/i18n/formatter.mjs";
import "../cases/i18n/providers/embed.mjs";
import "../cases/i18n/providers/fetch.mjs";
import "../cases/i18n/provider.mjs";
import "../cases/net/webconnect/message.mjs";
......
......@@ -14,8 +14,8 @@
</head>
<body>
<div id="headline" style="display: flex;align-items: center;justify-content: center;flex-direction: column;">
<h1 style='margin-bottom: 0.1em;'>Monster 3.4.0</h1>
<div id="lastupdate" style='font-size:0.7em'>last update So 8. Jan 17:17:24 CET 2023</div>
<h1 style='margin-bottom: 0.1em;'>Monster 3.8.0</h1>
<div id="lastupdate" style='font-size:0.7em'>last update Do 2. Feb 11:38:37 CET 2023</div>
</div>
<div id="mocks"></div>
<div id="mocha"></div>
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment