@schukai/monster 3.8.0 → 3.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,12 +1,75 @@
1
1
  import {expect} from "chai"
2
+ import {ATTRIBUTE_OBJECTLINK} from "../../../../application/source/dom/constants.mjs";
3
+ import {getLinkedObjects} from "../../../../application/source/dom/attributes.mjs";
2
4
  import {Provider} from "../../../../application/source/i18n/provider.mjs";
5
+ import {initJSDOM} from "../../util/jsdom.mjs";
6
+ import {getDocumentTranslations, Translations} from "../../../../application/source/i18n/translations.mjs";
3
7
 
4
8
  describe('Provider', function () {
5
9
 
6
- describe('Instance and Init', function () {
7
10
 
8
- it('create instance', function () {
9
- expect((new Provider()).getTranslations('en')).is.instanceof(Promise);
11
+ let html1 = `
12
+ <div id="test1">
13
+ </div>
14
+ `;
15
+
16
+ beforeEach(() => {
17
+ let mocks = document.getElementById('mocks');
18
+ mocks.innerHTML = html1;
19
+
20
+
21
+ })
22
+
23
+ afterEach(() => {
24
+ let mocks = document.getElementById('mocks');
25
+ mocks.innerHTML = "";
26
+ })
27
+
28
+ before(function (done) {
29
+ initJSDOM().then(() => {
30
+ done()
31
+ });
32
+ });
33
+
34
+ describe('Provider and Dom', function () {
35
+
36
+ const translationsLinkSymbol = Symbol.for("@schukai/monster/i18n/translations@@link");
37
+
38
+ it('assignToElement', function (done) {
39
+ const element = document.getElementById('test1');
40
+ const p = new Provider();
41
+ const r = p.assignToElement(undefined, element);
42
+
43
+ r.then((e) => {
44
+ const s = element.getAttribute(ATTRIBUTE_OBJECTLINK);
45
+ if (s === null) {
46
+ done(new Error("Attribute not set"));
47
+ return;
48
+ }
49
+
50
+ const i = getLinkedObjects(element, translationsLinkSymbol)
51
+ if (i === null) {
52
+ done(new Error("No linked object found"));
53
+ return;
54
+ }
55
+ let counter = 0;
56
+
57
+ for (let v of i) {
58
+ counter++;
59
+ }
60
+
61
+ if (counter !== 1) {
62
+ done(new Error("No linked object found"));
63
+ return;
64
+ }
65
+
66
+ const docTrans = getDocumentTranslations(element)
67
+ expect(docTrans).is.instanceof(Translations);
68
+
69
+
70
+ done();
71
+ }).catch(e => done(e));
72
+
10
73
  });
11
74
 
12
75
  });
@@ -1,6 +1,12 @@
1
1
  import {expect} from "chai"
2
2
  import {parseLocale} from "../../../../application/source/i18n/locale.mjs";
3
- import {Translations} from "../../../../application/source/i18n/translations.mjs";
3
+ import {Embed} from "../../../../application/source/i18n/providers/embed.mjs";
4
+ import {
5
+ Translations,
6
+ getDocumentTranslations
7
+
8
+ } from "../../../../application/source/i18n/translations.mjs";
9
+ import {initJSDOM} from "../../util/jsdom.mjs";
4
10
 
5
11
  describe('Translations', function () {
6
12
 
@@ -53,5 +59,76 @@ describe('Translations', function () {
53
59
 
54
60
  });
55
61
 
62
+ /**
63
+ * initDocumentTranslation
64
+ */
65
+
66
+ describe("test initDocumentTranslation ", function () {
67
+
68
+
69
+ let html1 = `<div id="mock-translations"></div>
70
+
71
+ <script type="application/json" data-monster-role="translations">
72
+ {
73
+ "test1": "abc",
74
+ "test2": {
75
+ "other": "xyz"
76
+ }
77
+ }
78
+ </script>
79
+
80
+ <script type="application/json" data-monster-role="translations">
81
+ {
82
+ "test1": "xyz",
83
+ "test3": {
84
+ "other": "xyz"
85
+ }
86
+ }
87
+ </script>
88
+
89
+ `;
90
+
91
+ beforeEach(() => {
92
+ let mocks = document.getElementById('mocks');
93
+ mocks.innerHTML = html1;
94
+
95
+ })
96
+
97
+ afterEach(() => {
98
+ let mocks = document.getElementById('mocks');
99
+ mocks.innerHTML = "";
100
+ })
101
+
102
+ before(function (done) {
103
+ initJSDOM().then(() => {
104
+ done()
105
+ });
106
+ });
107
+
108
+
109
+ it('Init translations', function (done) {
110
+
111
+ let elem = document.getElementById('mock-translations');
112
+ Embed.assignTranslationsToElement(elem).then((o) => {
113
+
114
+ let mocks = document.getElementById('mocks');
115
+
116
+ // no exception because of default
117
+ expect(getDocumentTranslations(elem).getText('no-key','with-default'))
118
+ .is.equal('with-default');
119
+
120
+ expect(getDocumentTranslations(elem).getText('test1'))
121
+ .is.equal('xyz');
122
+
123
+ done();
124
+
125
+ }).catch((e) => {
126
+ done(e);
127
+ })
128
+
129
+
130
+ });
131
+ })
132
+
56
133
 
57
134
  });
@@ -7,7 +7,7 @@ describe('Monster', function () {
7
7
  let monsterVersion
8
8
 
9
9
  /** don´t touch, replaced by make with package.json version */
10
- monsterVersion = new Version("3.8.0")
10
+ monsterVersion = new Version("3.9.0")
11
11
 
12
12
  let m = getMonsterVersion();
13
13
 
@@ -4,7 +4,6 @@ import {extend} from "../../../application/source/data/extend.mjs";
4
4
  import {getGlobal} from "../../../application/source/types/global.mjs";
5
5
 
6
6
  export const isBrowser = new Function("try {return this===window;}catch(e){ return false;}");
7
-
8
7
  export const isNode = new Function("try {return this===global;}catch(e){return false;}");
9
8
 
10
9
 
@@ -25,7 +24,7 @@ function initJSDOM(options) {
25
24
  storageQuota: 10000000,
26
25
  runScripts: "dangerously",
27
26
  resources: "usable"
28
- }, options||{})
27
+ }, options || {})
29
28
 
30
29
  return import("jsdom").then(({JSDOM}) => {
31
30
  const {window} = new JSDOM(`<html>
@@ -28,6 +28,7 @@ import "../cases/dom/assembler.mjs";
28
28
  import "../cases/i18n/translations.mjs";
29
29
  import "../cases/i18n/locale.mjs";
30
30
  import "../cases/i18n/formatter.mjs";
31
+ import "../cases/i18n/providers/embed.mjs";
31
32
  import "../cases/i18n/providers/fetch.mjs";
32
33
  import "../cases/i18n/provider.mjs";
33
34
  import "../cases/net/webconnect/message.mjs";
@@ -14,8 +14,8 @@
14
14
  </head>
15
15
  <body>
16
16
  <div id="headline" style="display: flex;align-items: center;justify-content: center;flex-direction: column;">
17
- <h1 style='margin-bottom: 0.1em;'>Monster 3.4.0</h1>
18
- <div id="lastupdate" style='font-size:0.7em'>last update So 8. Jan 17:17:24 CET 2023</div>
17
+ <h1 style='margin-bottom: 0.1em;'>Monster 3.8.0</h1>
18
+ <div id="lastupdate" style='font-size:0.7em'>last update Do 2. Feb 11:38:37 CET 2023</div>
19
19
  </div>
20
20
  <div id="mocks"></div>
21
21
  <div id="mocha"></div>