@schukai/monster 1.24.0 → 1.27.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG +47 -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 +1 -1
- package/dist/modules/data/datasource/restapi.js +1 -1
- package/dist/modules/data/datasource/storage/localstorage.js +1 -1
- package/dist/modules/data/datasource/storage/namespace.js +1 -1
- package/dist/modules/data/datasource/storage/sessionstorage.js +1 -1
- package/dist/modules/data/datasource/storage.js +1 -1
- package/dist/modules/data/datasource.js +1 -1
- package/dist/modules/data/diff.js +1 -1
- package/dist/modules/data/extend.js +1 -1
- package/dist/modules/data/namespace.js +1 -1
- package/dist/modules/data/pathfinder.js +1 -1
- 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 +2 -2
- package/dist/modules/dom/constants.js +2 -2
- package/dist/modules/dom/customcontrol.js +1 -1
- package/dist/modules/dom/customelement.js +1 -1
- 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 +1 -1
- 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 +1 -1
- 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 +1 -1
- package/dist/modules/types/proxyobserver.js +1 -1
- 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 +1 -1
- 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 +1 -1
- package/dist/modules/util/freeze.js +1 -1
- package/dist/modules/util/namespace.js +1 -1
- package/dist/modules/util/processing.js +1 -1
- package/dist/modules/util/trimspaces.js +1 -1
- package/dist/monster.dev.js +1528 -770
- package/dist/monster.dev.js.map +1 -1
- package/dist/monster.js +2 -2
- package/package.json +13 -2
- package/source/constants.js +11 -2
- 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 +25 -9
- package/source/data/buildtree.js +95 -0
- package/source/data/datasource/restapi.js +3 -3
- package/source/data/datasource/storage/localstorage.js +2 -2
- package/source/data/datasource/storage/sessionstorage.js +2 -2
- package/source/data/datasource/storage.js +3 -3
- package/source/data/datasource.js +3 -3
- package/source/data/diff.js +3 -3
- package/source/data/extend.js +2 -2
- package/source/data/pathfinder.js +4 -4
- package/source/data/pipe.js +3 -3
- package/source/data/transformer.js +7 -5
- package/source/dom/assembler.js +2 -2
- package/source/dom/attributes.js +111 -28
- package/source/dom/constants.js +287 -10
- package/source/dom/customcontrol.js +1 -1
- package/source/dom/customelement.js +1 -1
- package/source/dom/events.js +6 -7
- 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 +86 -16
- package/source/dom/theme.js +3 -3
- package/source/dom/updater.js +138 -90
- 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 +6 -4
- package/source/i18n/provider.js +2 -2
- package/source/i18n/providers/fetch.js +18 -3
- package/source/i18n/translations.js +18 -9
- 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 +2 -2
- package/source/math/random.js +9 -5
- package/source/namespace.js +1 -1
- package/source/text/formatter.js +190 -48
- package/source/types/base.js +4 -4
- package/source/types/basewithoptions.js +2 -2
- package/source/types/binary.js +4 -4
- package/source/types/dataurl.js +4 -4
- package/source/types/global.js +4 -4
- 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 +2 -2
- package/source/types/proxyobserver.js +5 -5
- package/source/types/queue.js +4 -4
- 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 +2 -2
- package/source/types/typeof.js +3 -3
- package/source/types/uniquequeue.js +2 -2
- 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 +2 -2
- package/source/util/comparator.js +4 -4
- package/source/util/freeze.js +5 -5
- package/source/util/processing.js +3 -3
- package/source/util/trimspaces.js +3 -3
- package/test/cases/data/buildtree.js +149 -0
- package/test/cases/data/datasource/restapi.js +1 -1
- package/test/cases/data/transformer.js +2 -0
- package/test/cases/dom/attributes.js +46 -19
- package/test/cases/dom/customelement.js +0 -3
- 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/template.js +72 -14
- package/test/cases/dom/updater.js +102 -75
- 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 +36 -5
- 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/regex.js +32 -0
- package/test/cases/types/uuid.js +42 -0
- package/test/cases/util/freeze.js +30 -4
- package/test/util/cleanupdom.js +48 -0
- package/test/util/jsdom.js +22 -9
- package/test/web/import.js +14 -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
@@ -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
|
+
});
|
@@ -0,0 +1,118 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
import {expect} from "chai"
|
4
|
+
|
5
|
+
import {ResourceManager} from "../../../source/dom/resourcemanager.js";
|
6
|
+
import {cleanupDOMFromTesting, initMutationObserverForTesting} from "../../util/cleanupdom.js";
|
7
|
+
import {initJSDOM} from "../../util/jsdom.js";
|
8
|
+
|
9
|
+
describe('ResourceManager', function () {
|
10
|
+
|
11
|
+
let fetchReference, returnStatus;
|
12
|
+
|
13
|
+
before(function (done) {
|
14
|
+
initJSDOM().then(() => {
|
15
|
+
done()
|
16
|
+
}).catch(e => done(e));
|
17
|
+
});
|
18
|
+
|
19
|
+
afterEach(() => {
|
20
|
+
global['fetch'] = fetchReference;
|
21
|
+
cleanupDOMFromTesting();
|
22
|
+
})
|
23
|
+
|
24
|
+
beforeEach(() => {
|
25
|
+
|
26
|
+
initMutationObserverForTesting()
|
27
|
+
|
28
|
+
returnStatus = 200;
|
29
|
+
fetchReference = global['fetch'];
|
30
|
+
global['fetch'] = function (url, options) {
|
31
|
+
|
32
|
+
if (!url) throw new Error('missing url')
|
33
|
+
|
34
|
+
return new Promise((resolve, reject) => {
|
35
|
+
resolve({
|
36
|
+
text: function () {
|
37
|
+
return JSON.stringify({
|
38
|
+
a: "test"
|
39
|
+
})
|
40
|
+
},
|
41
|
+
status: returnStatus
|
42
|
+
});
|
43
|
+
})
|
44
|
+
|
45
|
+
};
|
46
|
+
|
47
|
+
})
|
48
|
+
|
49
|
+
describe('new', function () {
|
50
|
+
it('new ResourceManager() should return ResourceManager object', function () {
|
51
|
+
let d = new ResourceManager();
|
52
|
+
expect(d).to.be.instanceOf(ResourceManager);
|
53
|
+
});
|
54
|
+
});
|
55
|
+
|
56
|
+
describe('load resources', function () {
|
57
|
+
|
58
|
+
let manager;
|
59
|
+
|
60
|
+
beforeEach(() => {
|
61
|
+
manager = new ResourceManager();
|
62
|
+
})
|
63
|
+
|
64
|
+
it('add script should instance of ResourceManager', function () {
|
65
|
+
expect(manager.addScript('/example.js')).to.be.instanceOf(ResourceManager);
|
66
|
+
});
|
67
|
+
|
68
|
+
it('add style should instance of ResourceManager', function () {
|
69
|
+
expect(manager.addStylesheet('/style.js')).to.be.instanceOf(ResourceManager);
|
70
|
+
});
|
71
|
+
|
72
|
+
it('add data should instance of ResourceManager', function () {
|
73
|
+
expect(manager.addData('/data.json')).to.be.instanceOf(ResourceManager);
|
74
|
+
});
|
75
|
+
|
76
|
+
describe('connect resources', function () {
|
77
|
+
it('add script and connect should instance of ResourceManager', function () {
|
78
|
+
expect(manager.addScript('/example.js').connect()).to.be.instanceOf(ResourceManager);
|
79
|
+
});
|
80
|
+
|
81
|
+
it('add style and connect should instance of ResourceManager', function () {
|
82
|
+
expect(manager.addStylesheet('/style.js').connect()).to.be.instanceOf(ResourceManager);
|
83
|
+
});
|
84
|
+
|
85
|
+
it('add data and connect should instance of ResourceManager', function () {
|
86
|
+
expect(manager.addData('/data.json').connect()).to.be.instanceOf(ResourceManager);
|
87
|
+
});
|
88
|
+
})
|
89
|
+
|
90
|
+
|
91
|
+
describe('check availability resources', function () {
|
92
|
+
it('add script and check availability should return Promise', function () {
|
93
|
+
expect(manager.addScript('/example.js').available()).to.be.instanceOf(Promise);
|
94
|
+
});
|
95
|
+
|
96
|
+
it('add style and check availability should should return Promise', function () {
|
97
|
+
expect(manager.addStylesheet('/style.js').available()).to.be.instanceOf(Promise);
|
98
|
+
});
|
99
|
+
|
100
|
+
it('add data and check availability should should return Promise', function () {
|
101
|
+
expect(manager.addData('/data.json').available()).to.be.instanceOf(Promise);
|
102
|
+
});
|
103
|
+
})
|
104
|
+
|
105
|
+
describe('check availability example.json', function () {
|
106
|
+
it('add data and check content', function (done) {
|
107
|
+
manager.addData('https://example.com/example.json').connect().available().then(r => {
|
108
|
+
expect(document.querySelector('html').outerHTML).contains('>{"a":"test"}</script></head>');
|
109
|
+
done();
|
110
|
+
}).catch(e => done(e));
|
111
|
+
});
|
112
|
+
|
113
|
+
})
|
114
|
+
|
115
|
+
});
|
116
|
+
|
117
|
+
|
118
|
+
});
|