@schukai/monster 1.23.0 → 1.26.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. package/CHANGELOG +53 -0
  2. package/README.md +4 -4
  3. package/dist/modules/constants.js +2 -2
  4. package/dist/modules/constraints/abstract.js +1 -1
  5. package/dist/modules/constraints/abstractoperator.js +1 -1
  6. package/dist/modules/constraints/andoperator.js +1 -1
  7. package/dist/modules/constraints/invalid.js +1 -1
  8. package/dist/modules/constraints/isarray.js +1 -1
  9. package/dist/modules/constraints/isobject.js +1 -1
  10. package/dist/modules/constraints/namespace.js +1 -1
  11. package/dist/modules/constraints/oroperator.js +1 -1
  12. package/dist/modules/constraints/valid.js +1 -1
  13. package/dist/modules/data/buildmap.js +2 -2
  14. package/dist/modules/data/buildtree.js +2 -0
  15. package/dist/modules/data/datasource/namespace.js +1 -1
  16. package/dist/modules/data/datasource/restapi/writeerror.js +2 -0
  17. package/dist/modules/data/datasource/restapi.js +2 -2
  18. package/dist/modules/data/datasource/storage/localstorage.js +2 -2
  19. package/dist/modules/data/datasource/storage/namespace.js +1 -1
  20. package/dist/modules/data/datasource/storage/sessionstorage.js +2 -2
  21. package/dist/modules/data/datasource/storage.js +2 -2
  22. package/dist/modules/data/datasource.js +2 -2
  23. package/dist/modules/data/diff.js +2 -2
  24. package/dist/modules/data/extend.js +1 -1
  25. package/dist/modules/data/namespace.js +1 -1
  26. package/dist/modules/data/pathfinder.js +2 -2
  27. package/dist/modules/data/pipe.js +1 -1
  28. package/dist/modules/data/transformer.js +2 -2
  29. package/dist/modules/dom/assembler.js +1 -1
  30. package/dist/modules/dom/attributes.js +1 -1
  31. package/dist/modules/dom/constants.js +2 -2
  32. package/dist/modules/dom/customcontrol.js +2 -2
  33. package/dist/modules/dom/customelement.js +2 -2
  34. package/dist/modules/dom/events.js +1 -1
  35. package/dist/modules/dom/focusmanager.js +2 -0
  36. package/dist/modules/dom/locale.js +1 -1
  37. package/dist/modules/dom/namespace.js +1 -1
  38. package/dist/modules/dom/resource/data.js +2 -0
  39. package/dist/modules/dom/resource/link/stylesheet.js +2 -0
  40. package/dist/modules/dom/resource/link.js +2 -0
  41. package/dist/modules/dom/resource/script.js +2 -0
  42. package/dist/modules/dom/resource.js +2 -0
  43. package/dist/modules/dom/resourcemanager.js +2 -0
  44. package/dist/modules/dom/template.js +2 -2
  45. package/dist/modules/dom/theme.js +1 -1
  46. package/dist/modules/dom/updater.js +2 -2
  47. package/dist/modules/dom/util.js +1 -1
  48. package/dist/modules/dom/worker/factory.js +2 -0
  49. package/dist/modules/i18n/formatter.js +2 -0
  50. package/dist/modules/i18n/locale.js +1 -1
  51. package/dist/modules/i18n/namespace.js +1 -1
  52. package/dist/modules/i18n/provider.js +1 -1
  53. package/dist/modules/i18n/providers/fetch.js +2 -2
  54. package/dist/modules/i18n/providers/namespace.js +1 -1
  55. package/dist/modules/i18n/translations.js +1 -1
  56. package/dist/modules/logging/handler/console.js +1 -1
  57. package/dist/modules/logging/handler/namespace.js +1 -1
  58. package/dist/modules/logging/handler.js +1 -1
  59. package/dist/modules/logging/logentry.js +1 -1
  60. package/dist/modules/logging/logger.js +1 -1
  61. package/dist/modules/logging/namespace.js +1 -1
  62. package/dist/modules/math/namespace.js +1 -1
  63. package/dist/modules/math/random.js +2 -2
  64. package/dist/modules/monster.js +1 -1
  65. package/dist/modules/namespace.js +1 -1
  66. package/dist/modules/text/formatter.js +2 -2
  67. package/dist/modules/text/namespace.js +1 -1
  68. package/dist/modules/types/base.js +1 -1
  69. package/dist/modules/types/basewithoptions.js +2 -2
  70. package/dist/modules/types/binary.js +1 -1
  71. package/dist/modules/types/dataurl.js +1 -1
  72. package/dist/modules/types/global.js +1 -1
  73. package/dist/modules/types/id.js +1 -1
  74. package/dist/modules/types/is.js +2 -2
  75. package/dist/modules/types/mediatype.js +1 -1
  76. package/dist/modules/types/namespace.js +1 -1
  77. package/dist/modules/types/node.js +2 -0
  78. package/dist/modules/types/nodelist.js +2 -0
  79. package/dist/modules/types/noderecursiveiterator.js +2 -0
  80. package/dist/modules/types/observer.js +1 -1
  81. package/dist/modules/types/observerlist.js +2 -2
  82. package/dist/modules/types/proxyobserver.js +2 -2
  83. package/dist/modules/types/queue.js +1 -1
  84. package/dist/modules/types/randomid.js +1 -1
  85. package/dist/modules/types/regex.js +2 -0
  86. package/dist/modules/types/stack.js +1 -1
  87. package/dist/modules/types/tokenlist.js +2 -2
  88. package/dist/modules/types/typeof.js +1 -1
  89. package/dist/modules/types/uniquequeue.js +1 -1
  90. package/dist/modules/types/uuid.js +2 -0
  91. package/dist/modules/types/validate.js +1 -1
  92. package/dist/modules/types/version.js +2 -2
  93. package/dist/modules/util/clone.js +1 -1
  94. package/dist/modules/util/comparator.js +2 -2
  95. package/dist/modules/util/freeze.js +1 -1
  96. package/dist/modules/util/namespace.js +1 -1
  97. package/dist/modules/util/processing.js +2 -2
  98. package/dist/modules/util/trimspaces.js +2 -0
  99. package/dist/monster.dev.js +1684 -696
  100. package/dist/monster.dev.js.map +1 -1
  101. package/dist/monster.js +2 -2
  102. package/package.json +13 -2
  103. package/source/constants.js +16 -7
  104. package/source/constraints/abstract.js +5 -0
  105. package/source/constraints/abstractoperator.js +5 -0
  106. package/source/constraints/andoperator.js +10 -5
  107. package/source/constraints/invalid.js +8 -3
  108. package/source/constraints/isarray.js +9 -4
  109. package/source/constraints/isobject.js +8 -3
  110. package/source/constraints/oroperator.js +10 -5
  111. package/source/constraints/valid.js +8 -3
  112. package/source/data/buildmap.js +27 -11
  113. package/source/data/buildtree.js +95 -0
  114. package/source/data/datasource/restapi/writeerror.js +49 -0
  115. package/source/data/datasource/restapi.js +87 -20
  116. package/source/data/datasource/storage/localstorage.js +4 -10
  117. package/source/data/datasource/storage/sessionstorage.js +4 -12
  118. package/source/data/datasource/storage.js +7 -14
  119. package/source/data/datasource.js +55 -17
  120. package/source/data/diff.js +8 -8
  121. package/source/data/extend.js +5 -5
  122. package/source/data/pathfinder.js +12 -6
  123. package/source/data/pipe.js +6 -5
  124. package/source/data/transformer.js +131 -24
  125. package/source/dom/assembler.js +2 -2
  126. package/source/dom/attributes.js +24 -24
  127. package/source/dom/constants.js +305 -12
  128. package/source/dom/customcontrol.js +40 -19
  129. package/source/dom/customelement.js +121 -92
  130. package/source/dom/events.js +6 -6
  131. package/source/dom/focusmanager.js +250 -0
  132. package/source/dom/locale.js +10 -5
  133. package/source/dom/resource/data.js +170 -0
  134. package/source/dom/resource/link/stylesheet.js +54 -0
  135. package/source/dom/resource/link.js +125 -0
  136. package/source/dom/resource/script.js +112 -0
  137. package/source/dom/resource.js +268 -0
  138. package/source/dom/resourcemanager.js +214 -0
  139. package/source/dom/template.js +52 -12
  140. package/source/dom/theme.js +3 -3
  141. package/source/dom/updater.js +47 -33
  142. package/source/dom/util.js +6 -6
  143. package/source/dom/worker/factory.js +134 -0
  144. package/source/i18n/formatter.js +140 -0
  145. package/source/i18n/locale.js +10 -8
  146. package/source/i18n/provider.js +4 -4
  147. package/source/i18n/providers/fetch.js +24 -14
  148. package/source/i18n/translations.js +20 -10
  149. package/source/logging/handler/console.js +2 -2
  150. package/source/logging/handler.js +2 -2
  151. package/source/logging/logentry.js +2 -2
  152. package/source/logging/logger.js +4 -4
  153. package/source/math/random.js +11 -5
  154. package/source/namespace.js +1 -1
  155. package/source/text/formatter.js +244 -27
  156. package/source/types/base.js +4 -4
  157. package/source/types/basewithoptions.js +10 -15
  158. package/source/types/binary.js +4 -4
  159. package/source/types/dataurl.js +6 -6
  160. package/source/types/global.js +9 -7
  161. package/source/types/id.js +6 -3
  162. package/source/types/is.js +103 -85
  163. package/source/types/mediatype.js +4 -4
  164. package/source/types/node.js +179 -0
  165. package/source/types/nodelist.js +125 -0
  166. package/source/types/noderecursiveiterator.js +126 -0
  167. package/source/types/observer.js +3 -3
  168. package/source/types/observerlist.js +3 -3
  169. package/source/types/proxyobserver.js +24 -7
  170. package/source/types/queue.js +6 -6
  171. package/source/types/randomid.js +2 -2
  172. package/source/types/regex.js +49 -0
  173. package/source/types/stack.js +2 -2
  174. package/source/types/tokenlist.js +8 -9
  175. package/source/types/typeof.js +3 -3
  176. package/source/types/uniquequeue.js +4 -4
  177. package/source/types/uuid.js +102 -0
  178. package/source/types/validate.js +20 -20
  179. package/source/types/version.js +6 -6
  180. package/source/util/clone.js +4 -5
  181. package/source/util/comparator.js +5 -5
  182. package/source/util/freeze.js +5 -5
  183. package/source/util/processing.js +33 -36
  184. package/source/util/trimspaces.js +85 -0
  185. package/test/cases/data/buildtree.js +149 -0
  186. package/test/cases/data/datasource/restapi.js +1 -1
  187. package/test/cases/data/datasource.js +4 -4
  188. package/test/cases/data/diff.js +4 -4
  189. package/test/cases/data/pathfinder.js +18 -9
  190. package/test/cases/data/pipe.js +26 -2
  191. package/test/cases/data/transformer.js +41 -10
  192. package/test/cases/dom/attributes.js +18 -14
  193. package/test/cases/dom/customcontrol.js +6 -5
  194. package/test/cases/dom/customelement.js +14 -16
  195. package/test/cases/dom/focusmanager.js +111 -0
  196. package/test/cases/dom/locale.js +1 -4
  197. package/test/cases/dom/resource/data.js +129 -0
  198. package/test/cases/dom/resource/link/stylesheet.js +101 -0
  199. package/test/cases/dom/resource/link.js +101 -0
  200. package/test/cases/dom/resource/script.js +115 -0
  201. package/test/cases/dom/resourcemanager.js +118 -0
  202. package/test/cases/dom/updater.js +28 -4
  203. package/test/cases/dom/worker/factory.js +63 -0
  204. package/test/cases/i18n/formatter.js +66 -0
  205. package/test/cases/monster.js +1 -1
  206. package/test/cases/text/formatter.js +71 -8
  207. package/test/cases/types/node.js +196 -0
  208. package/test/cases/types/nodelist.js +64 -0
  209. package/test/cases/types/noderecursiveiterator.js +54 -0
  210. package/test/cases/types/proxyobserver.js +55 -11
  211. package/test/cases/types/regex.js +32 -0
  212. package/test/cases/types/uuid.js +42 -0
  213. package/test/cases/util/freeze.js +30 -4
  214. package/test/cases/util/trimspaces.js +24 -0
  215. package/test/util/cleanupdom.js +48 -0
  216. package/test/util/jsdom.js +22 -9
  217. package/test/web/import.js +15 -0
  218. package/test/web/monster-dev.html +3 -3
  219. package/test/web/monster.html +2 -2
  220. package/test/web/test.html +3 -3
  221. package/test/web/tests.js +7 -7
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  import chai from "chai"
4
- import {PROPERTY_KEY_INTERNALDATA} from "../../../source/constants.js";
4
+ import {internalSymbol} from "../../../source/constants.js";
5
5
  import {ATTRIBUTE_OPTIONS} from "../../../source/dom/constants.js";
6
6
  import {getDocument} from "../../../source/dom/util.js";
7
7
  import {chaiDom} from "../../util/chai-dom.js";
@@ -16,13 +16,12 @@ let html1 = `
16
16
  </div>
17
17
  `;
18
18
 
19
- const internalDataSymbol = Symbol.for(PROPERTY_KEY_INTERNALDATA);
19
+
20
20
 
21
21
  describe('DOM', function () {
22
22
 
23
23
  let CustomElement, registerCustomElement, TestComponent, document, TestComponent2;
24
24
 
25
-
26
25
  describe('CustomElement()', function () {
27
26
 
28
27
 
@@ -98,7 +97,8 @@ describe('DOM', function () {
98
97
  let d = document.createElement('monster-testclass');
99
98
  document.getElementById('test1').appendChild(d);
100
99
  expect(document.getElementsByTagName('monster-testclass').length).is.equal(1);
101
- expect(document.getElementById('test1')).contain.html('<monster-testclass data-monster-objectlink="Symbol(monsterUpdater)"></monster-testclass>');
100
+ // no data-monster-objectlink="Symbol(monsterUpdater)" because it has nothing to update
101
+ expect(document.getElementById('test1')).contain.html('<monster-testclass></monster-testclass>');
102
102
  });
103
103
  });
104
104
 
@@ -113,11 +113,11 @@ describe('DOM', function () {
113
113
  expect(document.getElementsByTagName('monster-testclass2').length).is.equal(1);
114
114
  expect(document.getElementsByTagName('monster-testclass2').item(0).shadowRoot.innerHTML).is.equal('<h1></h1><article><p>test</p><div id="container"></div></article>');
115
115
  expect(document.getElementById('test1')).contain.html('<monster-testclass2 data-monster-objectlink="Symbol(monsterUpdater)"></monster-testclass2>');
116
- return done();
116
+ return done();
117
117
  } catch (e) {
118
118
  done(e);
119
119
  }
120
-
120
+
121
121
  }, 10);
122
122
 
123
123
  });
@@ -128,20 +128,20 @@ describe('DOM', function () {
128
128
  it('delegatesFocus should change from true to false', function () {
129
129
  let element = document.createElement('monster-testclass')
130
130
 
131
- const o = element[internalDataSymbol].realSubject;
132
- expect(Object.is(element[internalDataSymbol].realSubject, o)).to.be.true;
131
+ const o = element[internalSymbol].realSubject;
132
+ expect(Object.is(element[internalSymbol].realSubject, o)).to.be.true;
133
133
 
134
- expect(element[internalDataSymbol].realSubject.options.delegatesFocus).to.be.true;
135
- expect(element[internalDataSymbol].subject.options.delegatesFocus).to.be.true;
134
+ expect(element[internalSymbol].realSubject.options.delegatesFocus).to.be.true;
135
+ expect(element[internalSymbol].subject.options.delegatesFocus).to.be.true;
136
136
  expect(element.getOption('delegatesFocus')).to.be.true;
137
- expect(Object.is(element[internalDataSymbol].realSubject, o)).to.be.true;
137
+ expect(Object.is(element[internalSymbol].realSubject, o)).to.be.true;
138
138
 
139
139
  element.setAttribute(ATTRIBUTE_OPTIONS, JSON.stringify({delegatesFocus: false}));
140
- expect(Object.is(element[internalDataSymbol].realSubject, o)).to.be.true;
140
+ expect(Object.is(element[internalSymbol].realSubject, o)).to.be.true;
141
141
 
142
142
  expect(element.getOption('delegatesFocus')).to.be.false;
143
- expect(element[internalDataSymbol].realSubject.options.delegatesFocus).to.be.false;
144
- expect(Object.is(element[internalDataSymbol].realSubject, o)).to.be.true;
143
+ expect(element[internalSymbol].realSubject.options.delegatesFocus).to.be.false;
144
+ expect(Object.is(element[internalSymbol].realSubject, o)).to.be.true;
145
145
 
146
146
  })
147
147
 
@@ -239,8 +239,6 @@ describe('DOM', function () {
239
239
 
240
240
  let n1 = document.createElement('p');
241
241
 
242
- console.log(document.body.innerHTML)
243
-
244
242
  expect(d.hasNode(n1)).to.be.false;
245
243
  expect(d.hasNode(t)).to.be.true;
246
244
  expect(d.hasNode(p)).to.be.true;
@@ -0,0 +1,111 @@
1
+ 'use strict';
2
+
3
+ import {expect} from "chai";
4
+ import {FocusManager} from "../../../source/dom/focusmanager.js";
5
+ import {cleanupDOMFromTesting, initMutationObserverForTesting} from "../../util/cleanupdom.js";
6
+ import {initJSDOM} from "../../util/jsdom.js";
7
+
8
+ describe('FocusManager', function () {
9
+ before(function (done) {
10
+ initJSDOM().then(() => {
11
+ done()
12
+ });
13
+ });
14
+
15
+ beforeEach(() => {
16
+ initMutationObserverForTesting()
17
+ })
18
+
19
+ afterEach(() => {
20
+ cleanupDOMFromTesting();
21
+ document.getElementById('mocks').innerHTML = ''
22
+ })
23
+
24
+ describe('new', function () {
25
+
26
+ it('should instance of FocusManager', function () {
27
+ expect(new FocusManager()).is.instanceof(FocusManager);
28
+ })
29
+
30
+ })
31
+
32
+ describe('store and restore', function () {
33
+ let manager;
34
+
35
+ beforeEach(() => {
36
+ manager = new FocusManager();
37
+ document.getElementById('mocks').innerHTML = `
38
+ <input class="testit" id="tx1">
39
+ <input class="testit" id="tx2">
40
+ <input class="testit" id="tx3" disabled>
41
+ <input class="testit" id="tx4">
42
+ <p class="testit" tabindex="2" id="tx5">hello</p>
43
+ <input class="testit" id="tx6" aria-hidden="true">
44
+ <button class="testit" id="tx7"></button>
45
+ `;
46
+
47
+ for (const [, element] of Object.entries(document.querySelectorAll('.testit'))) {
48
+ element.getBoundingClientRect = () => ({
49
+ width: 200,
50
+ height: 200,
51
+ top: 0,
52
+ left: 0,
53
+ right: 200,
54
+ bottom: 200,
55
+ });
56
+ }
57
+
58
+
59
+ })
60
+
61
+ it('run ist', function () {
62
+
63
+ manager.focus(document.getElementById('tx1'));
64
+ manager.storeFocus();
65
+
66
+ const e1 = manager.getActive();
67
+ expect(e1.getAttribute('id'), 'error1').to.be.equal('tx1');
68
+
69
+ manager.focus(document.getElementById('tx2'));
70
+
71
+ manager.storeFocus();
72
+ expect(manager.getActive().getAttribute('id'), 'error2').to.be.equal('tx2');
73
+ manager.focusNext();
74
+ expect(manager.getActive().getAttribute('id'), 'error3').to.be.equal('tx4');
75
+ manager.focusNext();
76
+ expect(manager.getActive().getAttribute('id'), 'error4').to.be.equal('tx5');
77
+ manager.restoreFocus();
78
+ expect(manager.getActive().getAttribute('id'), 'error5').to.be.equal('tx2');
79
+ manager.restoreFocus();
80
+ expect(manager.getActive().getAttribute('id'), 'error6').to.be.equal('tx1');
81
+ manager.restoreFocus();
82
+ expect(manager.getActive().getAttribute('id'), 'error7').to.be.equal('tx1');
83
+ })
84
+
85
+
86
+ })
87
+
88
+ describe('returntype', function () {
89
+
90
+ let focusmanager;
91
+
92
+ beforeEach(() => {
93
+ focusmanager = new FocusManager();
94
+ })
95
+
96
+ it('check returns', function () {
97
+
98
+ expect(focusmanager.getFocusable()).is.instanceof(Array);
99
+ expect(focusmanager.getActive()).is.instanceof(HTMLElement);
100
+ expect(focusmanager.focusNext()).is.instanceof(FocusManager);
101
+ expect(focusmanager.focusPrev()).is.instanceof(FocusManager);
102
+ expect(focusmanager.storeFocus()).is.instanceof(FocusManager);
103
+ expect(focusmanager.focus(document.body)).is.instanceof(FocusManager);
104
+ expect(focusmanager.restoreFocus()).is.instanceof(FocusManager);
105
+
106
+ })
107
+
108
+ })
109
+
110
+
111
+ });
@@ -2,10 +2,7 @@
2
2
 
3
3
  import {expect} from "chai"
4
4
 
5
- import {
6
- getLocaleOfDocument
7
- } from "../../../source/dom/locale.js";
8
- import {Template} from "../../../source/dom/template.js";
5
+ import {getLocaleOfDocument} from "../../../source/dom/locale.js";
9
6
  import {initJSDOM} from "../../util/jsdom.js";
10
7
 
11
8
  describe('Attributes', function () {
@@ -0,0 +1,129 @@
1
+ 'use strict';
2
+
3
+ import chai from "chai"
4
+ import {Data} from "../../../../source/dom/resource/data.js";
5
+ import {DataUrl} from "../../../../source/types/dataurl.js";
6
+ import {ID} from "../../../../source/types/id.js";
7
+ import {chaiDom} from "../../../util/chai-dom.js";
8
+ import {cleanupDOMFromTesting, initMutationObserverForTesting} from "../../../util/cleanupdom.js";
9
+ import {initJSDOM} from "../../../util/jsdom.js";
10
+
11
+ let expect = chai.expect;
12
+
13
+ chai.use(chaiDom);
14
+
15
+ let html1 = `
16
+
17
+ `;
18
+
19
+
20
+ describe('Data', function () {
21
+
22
+ let fetchReference, returnStatus, mutationobserver, addedNodes = [];
23
+
24
+
25
+ before(function (done) {
26
+ initJSDOM().then(() => {
27
+ done()
28
+ });
29
+ });
30
+
31
+ beforeEach(() => {
32
+
33
+ initMutationObserverForTesting()
34
+
35
+ returnStatus = 200;
36
+ fetchReference = global['fetch'];
37
+ global['fetch'] = function (url, options) {
38
+
39
+ if (!url) throw new Error('missing url')
40
+
41
+ return new Promise((resolve, reject) => {
42
+ resolve({
43
+ text: function () {
44
+ return JSON.stringify({
45
+ a: "test"
46
+ })
47
+ },
48
+ status: returnStatus
49
+ });
50
+ })
51
+
52
+ };
53
+
54
+
55
+ })
56
+
57
+ afterEach(() => {
58
+ global['fetch'] = fetchReference;
59
+ cleanupDOMFromTesting();
60
+ })
61
+
62
+ describe('Data()', function () {
63
+ it('setEventTypes()', function (done) {
64
+
65
+ const data = new Data({
66
+ src: new DataUrl('', 'text/javascript').toString()
67
+ });
68
+
69
+ data.connect().available().then(() => {
70
+ done()
71
+ }).catch(e => done(e));
72
+
73
+ })
74
+ });
75
+
76
+ describe('External Data', () => {
77
+
78
+ let id = new ID('data').toString();
79
+ let server, data, url = 'https://monsterjs.org/assets/empty.js?' + id;
80
+
81
+ beforeEach(() => {
82
+
83
+ data = new Data({
84
+ src: url,
85
+ id: id
86
+ });
87
+
88
+ });
89
+
90
+ it('data is not connected', () => {
91
+ expect(data.isConnected()).to.be.false;
92
+ })
93
+
94
+ it('connect and check availability', (done) => {
95
+
96
+ data.connect().available().then(() => {
97
+ expect(data.isConnected(), 'isConnected 1').to.be.true;
98
+ expect(document.querySelector('[type="application/json"]'), 'exists 1').to.exist;
99
+
100
+ const e = document.getElementById(id).parentElement;
101
+
102
+
103
+ document.getElementById(id).remove();
104
+
105
+ expect(data.isConnected(), 'isConnected 2').to.be.false;
106
+ expect(document.querySelector('[type="application/json"]'), 'exists 2').not.to.exist;
107
+
108
+ data.connect().available().then(() => {
109
+ expect(data.isConnected(), 'isConnected 3').to.be.true;
110
+ expect(document.querySelector('[type="application/json"]'), 'exists 3').to.exist;
111
+
112
+ document.getElementById(id).remove();
113
+ expect(document.querySelector('[type="application/json"]'), 'exists 4').not.to.exist;
114
+ expect(data.isConnected(), 'isConnected 4').to.be.false;
115
+
116
+ done()
117
+ }).catch(e => done(e));
118
+
119
+
120
+ }).catch(e => done(e));
121
+
122
+
123
+ });
124
+
125
+
126
+ });
127
+
128
+
129
+ });
@@ -0,0 +1,101 @@
1
+ 'use strict';
2
+
3
+ import chai from "chai"
4
+ import {Stylesheet} from "../../../../../source/dom/resource/link/stylesheet.js";
5
+ import {DataUrl} from "../../../../../source/types/dataurl.js";
6
+ import {ID} from "../../../../../source/types/id.js";
7
+ import {chaiDom} from "../../../../util/chai-dom.js";
8
+ import {cleanupDOMFromTesting, initMutationObserverForTesting} from "../../../../util/cleanupdom.js";
9
+ import {initJSDOM} from "../../../../util/jsdom.js";
10
+
11
+ let expect = chai.expect;
12
+
13
+ chai.use(chaiDom);
14
+
15
+ let html1 = `
16
+
17
+ `;
18
+
19
+
20
+ describe('Stylesheet', function () {
21
+
22
+ before(function (done) {
23
+ initJSDOM({
24
+ runScripts: "dangerously",
25
+ resources: "usable"
26
+ }).then(() => {
27
+ done()
28
+ }).catch(e => done(e));
29
+ });
30
+
31
+ beforeEach(() => {
32
+ initMutationObserverForTesting()
33
+ })
34
+
35
+ afterEach(() => {
36
+ cleanupDOMFromTesting();
37
+ })
38
+
39
+ describe('Stylesheet()', function () {
40
+ it('connect().available()', function (done) {
41
+
42
+ const stylesheet = new Stylesheet({
43
+ href: new DataUrl('', 'text/css').toString(),
44
+ });
45
+
46
+ stylesheet.connect().available().then(() => {
47
+ const id = stylesheet.getOption('id')
48
+ done()
49
+ }).catch(e => done(e));
50
+
51
+ })
52
+ });
53
+
54
+ describe('External Stylesheet', () => {
55
+
56
+ let id = new ID('Stylesheet').toString();
57
+ let stylesheet, url = 'https://monsterjs.org/assets/empty.css?' + id;
58
+
59
+ beforeEach(() => {
60
+
61
+ stylesheet = new Stylesheet({
62
+ href: url,
63
+ id: id,
64
+ });
65
+
66
+ });
67
+
68
+ it('append and remove Stylesheet ', (done) => {
69
+
70
+ expect(stylesheet.isConnected()).to.be.false;
71
+
72
+ stylesheet.connect().available().then(() => {
73
+ expect(stylesheet.isConnected()).to.be.true;
74
+ expect(document.querySelector('[href="' + url + '"]')).to.exist;
75
+
76
+ document.getElementById(id).remove();
77
+ expect(stylesheet.isConnected()).to.be.false;
78
+ expect(document.querySelector('[href="' + url + '"]')).not.to.exist;
79
+
80
+ stylesheet.connect().available().then(() => {
81
+ expect(stylesheet.isConnected()).to.be.true;
82
+ expect(document.querySelector('[href="' + url + '"]')).to.exist;
83
+
84
+ document.getElementById(id).remove();
85
+ expect(document.querySelector('[href="' + url + '"]')).not.to.exist;
86
+ expect(stylesheet.isConnected()).to.be.false;
87
+
88
+ done()
89
+ }).catch(e => done(e));
90
+
91
+
92
+ }).catch(e => done(e));
93
+
94
+
95
+ });
96
+
97
+
98
+ });
99
+
100
+
101
+ });
@@ -0,0 +1,101 @@
1
+ 'use strict';
2
+
3
+ import chai from "chai"
4
+ import {Link} from "../../../../source/dom/resource/link.js";
5
+ import {DataUrl} from "../../../../source/types/dataurl.js";
6
+ import {ID} from "../../../../source/types/id.js";
7
+ import {chaiDom} from "../../../util/chai-dom.js";
8
+ import {cleanupDOMFromTesting, initMutationObserverForTesting} from "../../../util/cleanupdom.js";
9
+ import {initJSDOM} from "../../../util/jsdom.js";
10
+
11
+ let expect = chai.expect;
12
+
13
+ chai.use(chaiDom);
14
+
15
+ let html1 = `
16
+
17
+ `;
18
+
19
+
20
+ describe('Link', function () {
21
+
22
+ let mutationobserver, addedNodes=[];
23
+
24
+ before(function (done) {
25
+ initJSDOM().then(() => {
26
+ done()
27
+ });
28
+ });
29
+
30
+ beforeEach(() => {
31
+ initMutationObserverForTesting()
32
+ })
33
+
34
+ afterEach(() => {
35
+ cleanupDOMFromTesting();
36
+ })
37
+
38
+ describe('Link()', function () {
39
+ it('connect().available()', function (done) {
40
+
41
+ const link = new Link({
42
+ href: new DataUrl('', 'text/css').toString(),
43
+ rel: 'stylesheet'
44
+ });
45
+
46
+ link.connect().available().then(() => {
47
+ done()
48
+ }).catch(e => done(e));
49
+
50
+ })
51
+ });
52
+
53
+ describe('External Link', () => {
54
+
55
+ let id = new ID('link').toString();
56
+ let link, url = 'https://monsterjs.org/assets/empty.css?' + id;
57
+
58
+ beforeEach(() => {
59
+
60
+ link = new Link({
61
+ href: url,
62
+ id: id,
63
+ rel: 'stylesheet'
64
+ });
65
+
66
+ });
67
+
68
+ it('append and remove Link ', (done) => {
69
+
70
+ expect(link.isConnected()).to.be.false;
71
+
72
+ link.connect().available().then(() => {
73
+ expect(link.isConnected()).to.be.true;
74
+ expect(document.querySelector('[href="' + url + '"]')).to.exist;
75
+
76
+ document.getElementById(id).remove();
77
+ expect(link.isConnected()).to.be.false;
78
+ expect(document.querySelector('[href="' + url + '"]')).not.to.exist;
79
+
80
+ link.connect().available().then(() => {
81
+ expect(link.isConnected()).to.be.true;
82
+ expect(document.querySelector('[href="' + url + '"]')).to.exist;
83
+
84
+ document.getElementById(id).remove();
85
+ expect(document.querySelector('[href="' + url + '"]')).not.to.exist;
86
+ expect(link.isConnected()).to.be.false;
87
+
88
+ done()
89
+ }).catch(e => done(e));
90
+
91
+
92
+ }).catch(e => done(e));
93
+
94
+
95
+ });
96
+
97
+
98
+ });
99
+
100
+
101
+ });
@@ -0,0 +1,115 @@
1
+ 'use strict';
2
+
3
+ import chai from "chai"
4
+ import {Script} from "../../../../source/dom/resource/script.js";
5
+ import {DataUrl} from "../../../../source/types/dataurl.js";
6
+ import {ID} from "../../../../source/types/id.js";
7
+ import {chaiDom} from "../../../util/chai-dom.js";
8
+ import {cleanupDOMFromTesting, initMutationObserverForTesting} from "../../../util/cleanupdom.js";
9
+ import {initJSDOM} from "../../../util/jsdom.js";
10
+
11
+ let expect = chai.expect;
12
+
13
+ chai.use(chaiDom);
14
+
15
+ let html1 = `
16
+
17
+ `;
18
+
19
+
20
+ describe('Script', function () {
21
+
22
+ before(function (done) {
23
+ initJSDOM().then(() => {
24
+ done()
25
+ });
26
+ });
27
+
28
+ beforeEach(() => {
29
+ initMutationObserverForTesting()
30
+ })
31
+
32
+ afterEach(() => {
33
+ cleanupDOMFromTesting();
34
+ })
35
+
36
+ describe('Script()', function () {
37
+ it('setEventTypes()', function (done) {
38
+
39
+ const script = new Script({
40
+ src: new DataUrl('', 'text/javascript').toString(),
41
+ async: true,
42
+ crossOrigin: 'anonymous',
43
+ defer: false,
44
+ integrity: undefined,
45
+ nomodule: false,
46
+ nonce: undefined,
47
+ referrerpolicy: undefined,
48
+ type: 'text/javascript'
49
+ });
50
+
51
+ script.connect().available().then(() => {
52
+
53
+ const id = script.getOption('id')
54
+ done()
55
+ }).catch(e => done(e));
56
+
57
+ })
58
+ });
59
+
60
+ describe('External JS', () => {
61
+
62
+ let id = new ID('script').toString();
63
+ let server, script, url = 'https://monsterjs.org/assets/empty.js?' + id;
64
+
65
+ beforeEach(() => {
66
+
67
+ script = new Script({
68
+ src: url,
69
+ async: true,
70
+ crossOrigin: 'anonymous',
71
+ defer: false,
72
+ integrity: undefined,
73
+ nomodule: false,
74
+ nonce: undefined,
75
+ referrerpolicy: undefined,
76
+ type: 'text/javascript',
77
+ id: id
78
+ });
79
+
80
+ });
81
+
82
+ it('append and remove script ', (done) => {
83
+
84
+ expect(script.isConnected()).to.be.false;
85
+
86
+ script.connect().available().then(() => {
87
+ expect(script.isConnected()).to.be.true;
88
+ expect(document.querySelector('[src="' + url + '"]')).to.exist;
89
+
90
+ document.getElementById(id).remove();
91
+ expect(script.isConnected()).to.be.false;
92
+ expect(document.querySelector('[src="' + url + '"]')).not.to.exist;
93
+
94
+ script.connect().available().then(() => {
95
+ expect(script.isConnected()).to.be.true;
96
+ expect(document.querySelector('[src="' + url + '"]')).to.exist;
97
+
98
+ document.getElementById(id).remove();
99
+ expect(document.querySelector('[src="' + url + '"]')).not.to.exist;
100
+ expect(script.isConnected()).to.be.false;
101
+
102
+ done()
103
+ }).catch(e => done(e));
104
+
105
+
106
+ }).catch(e => done(e));
107
+
108
+
109
+ });
110
+
111
+
112
+ });
113
+
114
+
115
+ });