@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.
- package/CHANGELOG +53 -0
- package/README.md +4 -4
- package/dist/modules/constants.js +2 -2
- package/dist/modules/constraints/abstract.js +1 -1
- package/dist/modules/constraints/abstractoperator.js +1 -1
- package/dist/modules/constraints/andoperator.js +1 -1
- package/dist/modules/constraints/invalid.js +1 -1
- package/dist/modules/constraints/isarray.js +1 -1
- package/dist/modules/constraints/isobject.js +1 -1
- package/dist/modules/constraints/namespace.js +1 -1
- package/dist/modules/constraints/oroperator.js +1 -1
- package/dist/modules/constraints/valid.js +1 -1
- package/dist/modules/data/buildmap.js +2 -2
- package/dist/modules/data/buildtree.js +2 -0
- package/dist/modules/data/datasource/namespace.js +1 -1
- package/dist/modules/data/datasource/restapi/writeerror.js +2 -0
- package/dist/modules/data/datasource/restapi.js +2 -2
- package/dist/modules/data/datasource/storage/localstorage.js +2 -2
- package/dist/modules/data/datasource/storage/namespace.js +1 -1
- package/dist/modules/data/datasource/storage/sessionstorage.js +2 -2
- package/dist/modules/data/datasource/storage.js +2 -2
- package/dist/modules/data/datasource.js +2 -2
- package/dist/modules/data/diff.js +2 -2
- package/dist/modules/data/extend.js +1 -1
- package/dist/modules/data/namespace.js +1 -1
- package/dist/modules/data/pathfinder.js +2 -2
- package/dist/modules/data/pipe.js +1 -1
- package/dist/modules/data/transformer.js +2 -2
- package/dist/modules/dom/assembler.js +1 -1
- package/dist/modules/dom/attributes.js +1 -1
- package/dist/modules/dom/constants.js +2 -2
- package/dist/modules/dom/customcontrol.js +2 -2
- package/dist/modules/dom/customelement.js +2 -2
- package/dist/modules/dom/events.js +1 -1
- package/dist/modules/dom/focusmanager.js +2 -0
- package/dist/modules/dom/locale.js +1 -1
- package/dist/modules/dom/namespace.js +1 -1
- package/dist/modules/dom/resource/data.js +2 -0
- package/dist/modules/dom/resource/link/stylesheet.js +2 -0
- package/dist/modules/dom/resource/link.js +2 -0
- package/dist/modules/dom/resource/script.js +2 -0
- package/dist/modules/dom/resource.js +2 -0
- package/dist/modules/dom/resourcemanager.js +2 -0
- package/dist/modules/dom/template.js +2 -2
- package/dist/modules/dom/theme.js +1 -1
- package/dist/modules/dom/updater.js +2 -2
- package/dist/modules/dom/util.js +1 -1
- package/dist/modules/dom/worker/factory.js +2 -0
- package/dist/modules/i18n/formatter.js +2 -0
- package/dist/modules/i18n/locale.js +1 -1
- package/dist/modules/i18n/namespace.js +1 -1
- package/dist/modules/i18n/provider.js +1 -1
- package/dist/modules/i18n/providers/fetch.js +2 -2
- package/dist/modules/i18n/providers/namespace.js +1 -1
- package/dist/modules/i18n/translations.js +1 -1
- package/dist/modules/logging/handler/console.js +1 -1
- package/dist/modules/logging/handler/namespace.js +1 -1
- package/dist/modules/logging/handler.js +1 -1
- package/dist/modules/logging/logentry.js +1 -1
- package/dist/modules/logging/logger.js +1 -1
- package/dist/modules/logging/namespace.js +1 -1
- package/dist/modules/math/namespace.js +1 -1
- package/dist/modules/math/random.js +2 -2
- package/dist/modules/monster.js +1 -1
- package/dist/modules/namespace.js +1 -1
- package/dist/modules/text/formatter.js +2 -2
- package/dist/modules/text/namespace.js +1 -1
- package/dist/modules/types/base.js +1 -1
- package/dist/modules/types/basewithoptions.js +2 -2
- package/dist/modules/types/binary.js +1 -1
- package/dist/modules/types/dataurl.js +1 -1
- package/dist/modules/types/global.js +1 -1
- package/dist/modules/types/id.js +1 -1
- package/dist/modules/types/is.js +2 -2
- package/dist/modules/types/mediatype.js +1 -1
- package/dist/modules/types/namespace.js +1 -1
- package/dist/modules/types/node.js +2 -0
- package/dist/modules/types/nodelist.js +2 -0
- package/dist/modules/types/noderecursiveiterator.js +2 -0
- package/dist/modules/types/observer.js +1 -1
- package/dist/modules/types/observerlist.js +2 -2
- package/dist/modules/types/proxyobserver.js +2 -2
- package/dist/modules/types/queue.js +1 -1
- package/dist/modules/types/randomid.js +1 -1
- package/dist/modules/types/regex.js +2 -0
- package/dist/modules/types/stack.js +1 -1
- package/dist/modules/types/tokenlist.js +2 -2
- package/dist/modules/types/typeof.js +1 -1
- package/dist/modules/types/uniquequeue.js +1 -1
- package/dist/modules/types/uuid.js +2 -0
- package/dist/modules/types/validate.js +1 -1
- package/dist/modules/types/version.js +2 -2
- package/dist/modules/util/clone.js +1 -1
- package/dist/modules/util/comparator.js +2 -2
- package/dist/modules/util/freeze.js +1 -1
- package/dist/modules/util/namespace.js +1 -1
- package/dist/modules/util/processing.js +2 -2
- package/dist/modules/util/trimspaces.js +2 -0
- package/dist/monster.dev.js +1684 -696
- package/dist/monster.dev.js.map +1 -1
- package/dist/monster.js +2 -2
- package/package.json +13 -2
- package/source/constants.js +16 -7
- package/source/constraints/abstract.js +5 -0
- package/source/constraints/abstractoperator.js +5 -0
- package/source/constraints/andoperator.js +10 -5
- package/source/constraints/invalid.js +8 -3
- package/source/constraints/isarray.js +9 -4
- package/source/constraints/isobject.js +8 -3
- package/source/constraints/oroperator.js +10 -5
- package/source/constraints/valid.js +8 -3
- package/source/data/buildmap.js +27 -11
- package/source/data/buildtree.js +95 -0
- package/source/data/datasource/restapi/writeerror.js +49 -0
- package/source/data/datasource/restapi.js +87 -20
- package/source/data/datasource/storage/localstorage.js +4 -10
- package/source/data/datasource/storage/sessionstorage.js +4 -12
- package/source/data/datasource/storage.js +7 -14
- package/source/data/datasource.js +55 -17
- package/source/data/diff.js +8 -8
- package/source/data/extend.js +5 -5
- package/source/data/pathfinder.js +12 -6
- package/source/data/pipe.js +6 -5
- package/source/data/transformer.js +131 -24
- package/source/dom/assembler.js +2 -2
- package/source/dom/attributes.js +24 -24
- package/source/dom/constants.js +305 -12
- package/source/dom/customcontrol.js +40 -19
- package/source/dom/customelement.js +121 -92
- package/source/dom/events.js +6 -6
- package/source/dom/focusmanager.js +250 -0
- package/source/dom/locale.js +10 -5
- package/source/dom/resource/data.js +170 -0
- package/source/dom/resource/link/stylesheet.js +54 -0
- package/source/dom/resource/link.js +125 -0
- package/source/dom/resource/script.js +112 -0
- package/source/dom/resource.js +268 -0
- package/source/dom/resourcemanager.js +214 -0
- package/source/dom/template.js +52 -12
- package/source/dom/theme.js +3 -3
- package/source/dom/updater.js +47 -33
- package/source/dom/util.js +6 -6
- package/source/dom/worker/factory.js +134 -0
- package/source/i18n/formatter.js +140 -0
- package/source/i18n/locale.js +10 -8
- package/source/i18n/provider.js +4 -4
- package/source/i18n/providers/fetch.js +24 -14
- package/source/i18n/translations.js +20 -10
- package/source/logging/handler/console.js +2 -2
- package/source/logging/handler.js +2 -2
- package/source/logging/logentry.js +2 -2
- package/source/logging/logger.js +4 -4
- package/source/math/random.js +11 -5
- package/source/namespace.js +1 -1
- package/source/text/formatter.js +244 -27
- package/source/types/base.js +4 -4
- package/source/types/basewithoptions.js +10 -15
- package/source/types/binary.js +4 -4
- package/source/types/dataurl.js +6 -6
- package/source/types/global.js +9 -7
- package/source/types/id.js +6 -3
- package/source/types/is.js +103 -85
- package/source/types/mediatype.js +4 -4
- package/source/types/node.js +179 -0
- package/source/types/nodelist.js +125 -0
- package/source/types/noderecursiveiterator.js +126 -0
- package/source/types/observer.js +3 -3
- package/source/types/observerlist.js +3 -3
- package/source/types/proxyobserver.js +24 -7
- package/source/types/queue.js +6 -6
- package/source/types/randomid.js +2 -2
- package/source/types/regex.js +49 -0
- package/source/types/stack.js +2 -2
- package/source/types/tokenlist.js +8 -9
- package/source/types/typeof.js +3 -3
- package/source/types/uniquequeue.js +4 -4
- package/source/types/uuid.js +102 -0
- package/source/types/validate.js +20 -20
- package/source/types/version.js +6 -6
- package/source/util/clone.js +4 -5
- package/source/util/comparator.js +5 -5
- package/source/util/freeze.js +5 -5
- package/source/util/processing.js +33 -36
- package/source/util/trimspaces.js +85 -0
- package/test/cases/data/buildtree.js +149 -0
- package/test/cases/data/datasource/restapi.js +1 -1
- package/test/cases/data/datasource.js +4 -4
- package/test/cases/data/diff.js +4 -4
- package/test/cases/data/pathfinder.js +18 -9
- package/test/cases/data/pipe.js +26 -2
- package/test/cases/data/transformer.js +41 -10
- package/test/cases/dom/attributes.js +18 -14
- package/test/cases/dom/customcontrol.js +6 -5
- package/test/cases/dom/customelement.js +14 -16
- package/test/cases/dom/focusmanager.js +111 -0
- package/test/cases/dom/locale.js +1 -4
- package/test/cases/dom/resource/data.js +129 -0
- package/test/cases/dom/resource/link/stylesheet.js +101 -0
- package/test/cases/dom/resource/link.js +101 -0
- package/test/cases/dom/resource/script.js +115 -0
- package/test/cases/dom/resourcemanager.js +118 -0
- package/test/cases/dom/updater.js +28 -4
- package/test/cases/dom/worker/factory.js +63 -0
- package/test/cases/i18n/formatter.js +66 -0
- package/test/cases/monster.js +1 -1
- package/test/cases/text/formatter.js +71 -8
- package/test/cases/types/node.js +196 -0
- package/test/cases/types/nodelist.js +64 -0
- package/test/cases/types/noderecursiveiterator.js +54 -0
- package/test/cases/types/proxyobserver.js +55 -11
- package/test/cases/types/regex.js +32 -0
- package/test/cases/types/uuid.js +42 -0
- package/test/cases/util/freeze.js +30 -4
- package/test/cases/util/trimspaces.js +24 -0
- package/test/util/cleanupdom.js +48 -0
- package/test/util/jsdom.js +22 -9
- package/test/web/import.js +15 -0
- package/test/web/monster-dev.html +3 -3
- package/test/web/monster.html +2 -2
- package/test/web/test.html +3 -3
- 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 {
|
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
|
-
|
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
|
-
|
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
|
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[
|
132
|
-
expect(Object.is(element[
|
131
|
+
const o = element[internalSymbol].realSubject;
|
132
|
+
expect(Object.is(element[internalSymbol].realSubject, o)).to.be.true;
|
133
133
|
|
134
|
-
expect(element[
|
135
|
-
expect(element[
|
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[
|
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[
|
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[
|
144
|
-
expect(Object.is(element[
|
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
|
+
});
|
package/test/cases/dom/locale.js
CHANGED
@@ -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
|
+
});
|