@schukai/monster 1.13.0 → 1.15.2
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG +46 -1
- package/README.md +5 -5
- package/dist/modules/constants.js +2 -2
- package/dist/modules/constraints/abstract.js +2 -2
- package/dist/modules/constraints/abstractoperator.js +2 -2
- package/dist/modules/constraints/andoperator.js +2 -2
- package/dist/modules/constraints/invalid.js +2 -2
- package/dist/modules/constraints/isarray.js +2 -2
- package/dist/modules/constraints/isobject.js +2 -2
- package/dist/modules/constraints/namespace.js +1 -1
- package/dist/modules/constraints/oroperator.js +2 -2
- package/dist/modules/constraints/valid.js +2 -2
- package/dist/modules/data/buildmap.js +2 -2
- package/dist/modules/data/diff.js +2 -2
- package/dist/modules/data/extend.js +2 -2
- package/dist/modules/data/namespace.js +1 -1
- package/dist/modules/data/pathfinder.js +2 -2
- package/dist/modules/data/pipe.js +2 -2
- package/dist/modules/data/transformer.js +2 -2
- package/dist/modules/dom/assembler.js +2 -2
- package/dist/modules/dom/attributes.js +2 -2
- package/dist/modules/dom/constants.js +2 -2
- package/dist/modules/dom/customcontrol.js +2 -0
- package/dist/modules/dom/customelement.js +2 -2
- package/dist/modules/dom/events.js +2 -2
- package/dist/modules/dom/locale.js +2 -2
- package/dist/modules/dom/namespace.js +1 -1
- package/dist/modules/dom/template.js +2 -2
- package/dist/modules/dom/theme.js +2 -2
- package/dist/modules/dom/updater.js +2 -2
- package/dist/modules/dom/util.js +2 -2
- package/dist/modules/i18n/locale.js +2 -2
- package/dist/modules/i18n/namespace.js +1 -1
- package/dist/modules/i18n/provider.js +2 -2
- package/dist/modules/i18n/providers/fetch.js +2 -2
- package/dist/modules/i18n/providers/namespace.js +1 -1
- package/dist/modules/i18n/translations.js +2 -2
- package/dist/modules/logging/handler/console.js +2 -2
- package/dist/modules/logging/handler/namespace.js +1 -1
- package/dist/modules/logging/handler.js +2 -2
- package/dist/modules/logging/logentry.js +2 -2
- package/dist/modules/logging/logger.js +2 -2
- 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 +2 -2
- package/dist/modules/namespace.js +2 -2
- package/dist/modules/text/formatter.js +2 -2
- package/dist/modules/text/namespace.js +1 -1
- package/dist/modules/types/base.js +2 -2
- package/dist/modules/types/basewithoptions.js +2 -2
- package/dist/modules/types/global.js +2 -2
- package/dist/modules/types/id.js +2 -2
- package/dist/modules/types/is.js +2 -2
- package/dist/modules/types/namespace.js +1 -1
- package/dist/modules/types/observer.js +2 -2
- package/dist/modules/types/observerlist.js +2 -2
- package/dist/modules/types/proxyobserver.js +2 -2
- package/dist/modules/types/queue.js +2 -2
- package/dist/modules/types/randomid.js +2 -2
- package/dist/modules/types/stack.js +2 -2
- package/dist/modules/types/tokenlist.js +2 -2
- package/dist/modules/types/typeof.js +2 -2
- package/dist/modules/types/uniquequeue.js +2 -2
- package/dist/modules/types/validate.js +2 -2
- package/dist/modules/types/version.js +2 -2
- package/dist/modules/util/clone.js +2 -2
- package/dist/modules/util/comparator.js +2 -2
- package/dist/modules/util/freeze.js +2 -2
- package/dist/modules/util/namespace.js +1 -1
- package/dist/monster.dev.js +8622 -7709
- package/dist/monster.dev.js.map +1 -1
- package/dist/monster.js +2 -9
- package/package.json +1 -1
- package/source/constants.js +7 -6
- package/source/constraints/abstract.js +2 -2
- package/source/constraints/abstractoperator.js +4 -4
- package/source/constraints/andoperator.js +8 -8
- package/source/constraints/invalid.js +6 -6
- package/source/constraints/isarray.js +7 -7
- package/source/constraints/isobject.js +7 -7
- package/source/constraints/namespace.js +2 -2
- package/source/constraints/oroperator.js +8 -8
- package/source/constraints/valid.js +7 -7
- package/source/data/buildmap.js +15 -15
- package/source/data/diff.js +9 -9
- package/source/data/extend.js +55 -13
- package/source/data/namespace.js +2 -2
- package/source/data/pathfinder.js +13 -14
- package/source/data/pipe.js +8 -8
- package/source/data/transformer.js +11 -11
- package/source/dom/assembler.js +7 -7
- package/source/dom/attributes.js +89 -46
- package/source/dom/constants.js +9 -2
- package/source/dom/customcontrol.js +299 -0
- package/source/dom/customelement.js +181 -66
- package/source/dom/events.js +58 -8
- package/source/dom/locale.js +5 -5
- package/source/dom/namespace.js +2 -2
- package/source/dom/template.js +24 -19
- package/source/dom/theme.js +8 -9
- package/source/dom/updater.js +46 -24
- package/source/dom/util.js +10 -10
- package/source/i18n/locale.js +7 -7
- package/source/i18n/namespace.js +1 -1
- package/source/i18n/provider.js +6 -6
- package/source/i18n/providers/fetch.js +10 -10
- package/source/i18n/translations.js +5 -5
- package/source/logging/handler/console.js +5 -5
- package/source/logging/handler/namespace.js +1 -1
- package/source/logging/handler.js +8 -8
- package/source/logging/logentry.js +5 -5
- package/source/logging/logger.js +5 -5
- package/source/logging/namespace.js +2 -2
- package/source/math/namespace.js +2 -2
- package/source/math/random.js +5 -5
- package/source/monster.js +48 -44
- package/source/namespace.js +2 -2
- package/source/text/formatter.js +6 -7
- package/source/text/namespace.js +1 -1
- package/source/types/base.js +4 -5
- package/source/types/basewithoptions.js +10 -9
- package/source/types/global.js +7 -7
- package/source/types/id.js +7 -7
- package/source/types/is.js +22 -22
- package/source/types/namespace.js +2 -2
- package/source/types/observer.js +7 -7
- package/source/types/observerlist.js +4 -4
- package/source/types/proxyobserver.js +32 -26
- package/source/types/queue.js +13 -7
- package/source/types/randomid.js +6 -6
- package/source/types/stack.js +11 -4
- package/source/types/tokenlist.js +9 -9
- package/source/types/typeof.js +5 -5
- package/source/types/uniquequeue.js +14 -7
- package/source/types/validate.js +27 -27
- package/source/types/version.js +9 -9
- package/source/util/clone.js +6 -6
- package/source/util/comparator.js +7 -7
- package/source/util/freeze.js +7 -7
- package/source/util/namespace.js +2 -2
- package/test/cases/data/extend.js +66 -13
- package/test/cases/dom/attributes.js +56 -1
- package/test/cases/dom/customcontrol.js +264 -0
- package/test/cases/dom/customelement.js +112 -51
- package/test/cases/dom/events.js +32 -14
- package/test/cases/dom/template.js +40 -1
- package/test/cases/monster.js +1 -1
- package/test/cases/types/proxyobserver.js +9 -0
- package/test/util/jsdom.js +3 -0
- package/test/web/import.js +1 -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 +3 -3
@@ -7,6 +7,23 @@ describe('extend', function () {
|
|
7
7
|
|
8
8
|
[
|
9
9
|
[
|
10
|
+
'{"a":{"b":["1","2","3"]}}',
|
11
|
+
{
|
12
|
+
a: {
|
13
|
+
b: [
|
14
|
+
"1",
|
15
|
+
"2",
|
16
|
+
"3"
|
17
|
+
]
|
18
|
+
}
|
19
|
+
},
|
20
|
+
{
|
21
|
+
a: {
|
22
|
+
b: []
|
23
|
+
}
|
24
|
+
},
|
25
|
+
], [
|
26
|
+
'{"a":{"b":1,"d":1}}',
|
10
27
|
{
|
11
28
|
a: {
|
12
29
|
b: 1
|
@@ -17,43 +34,79 @@ describe('extend', function () {
|
|
17
34
|
d: 1
|
18
35
|
}
|
19
36
|
},
|
20
|
-
undefined,
|
21
|
-
'{"a":{"b":1,"d":1}}'
|
22
37
|
],
|
23
38
|
|
24
39
|
[
|
40
|
+
'{"a":{"b":1,"d":{"x":["car"],"f":true,"g":[]}}}',
|
41
|
+
{},
|
25
42
|
{
|
26
43
|
a: {
|
27
44
|
b: 1,
|
28
|
-
d:["car"]
|
45
|
+
d: {x: ["car"]}
|
29
46
|
}
|
30
47
|
},
|
31
48
|
{
|
32
49
|
a: {
|
33
50
|
d: {
|
34
|
-
f:true,
|
51
|
+
f: true,
|
35
52
|
g: []
|
36
53
|
}
|
37
54
|
}
|
38
55
|
},
|
39
|
-
undefined,
|
40
|
-
'{"a":{"b":1,"d":{"0":"car","f":true,"g":[]}}}'
|
41
56
|
]
|
42
|
-
|
57
|
+
|
43
58
|
].forEach(function (data) {
|
44
59
|
|
45
|
-
let a = data.shift()
|
46
|
-
let b = data.shift()
|
47
|
-
let c = data.shift()
|
48
60
|
let d = data.shift()
|
61
|
+
let a = data
|
49
62
|
|
50
|
-
|
51
|
-
|
52
|
-
let x = extend(a, b, c);
|
63
|
+
it('.extend(' + JSON.stringify(a) + ') should result in ' + d, function () {
|
64
|
+
let x = extend.apply(this, a);
|
53
65
|
expect(JSON.stringify(x)).is.equal(d);
|
54
66
|
});
|
55
67
|
|
56
68
|
|
57
69
|
});
|
58
70
|
|
71
|
+
|
72
|
+
[
|
73
|
+
|
74
|
+
|
75
|
+
[
|
76
|
+
{},
|
77
|
+
{
|
78
|
+
a: {
|
79
|
+
b: 1,
|
80
|
+
d: ["car"]
|
81
|
+
}
|
82
|
+
},
|
83
|
+
{
|
84
|
+
a: {
|
85
|
+
d: {
|
86
|
+
f: true,
|
87
|
+
g: []
|
88
|
+
}
|
89
|
+
}
|
90
|
+
},
|
91
|
+
],
|
92
|
+
[
|
93
|
+
{
|
94
|
+
a: {}
|
95
|
+
},
|
96
|
+
{
|
97
|
+
a: []
|
98
|
+
}
|
99
|
+
]
|
100
|
+
|
101
|
+
].forEach(function (data) {
|
102
|
+
|
103
|
+
let a = data
|
104
|
+
|
105
|
+
it('.extend(' + JSON.stringify(a) + ') should throw Error ', function () {
|
106
|
+
expect(() => extend.apply(this, a)).to.throw(Error);
|
107
|
+
});
|
108
|
+
|
109
|
+
|
110
|
+
});
|
111
|
+
|
59
112
|
})
|
@@ -8,7 +8,13 @@ import {
|
|
8
8
|
containsAttributeToken,
|
9
9
|
replaceAttributeToken,
|
10
10
|
clearAttributeTokens,
|
11
|
-
removeAttributeToken,
|
11
|
+
removeAttributeToken,
|
12
|
+
hasObjectLink,
|
13
|
+
addToObjectLink,
|
14
|
+
removeObjectLink,
|
15
|
+
getLinkedObjects,
|
16
|
+
findClosestObjectLink,
|
17
|
+
findClosestByAttribute
|
12
18
|
} from "../../../source/dom/attributes.js";
|
13
19
|
|
14
20
|
import {initJSDOM} from "../../util/jsdom.js";
|
@@ -26,6 +32,18 @@ let html2 = `<div id="test1">
|
|
26
32
|
</div>
|
27
33
|
</div>
|
28
34
|
`;
|
35
|
+
let html3 = `<div data-monster-role="test1">
|
36
|
+
<div data-monster-role="sub1" id="a1">
|
37
|
+
<div data-monster-role="sub2" id="a2">
|
38
|
+
<div data-monster-role="sub3" id="a3">
|
39
|
+
<div data-monster-role="sub4" id="a4">
|
40
|
+
<div data-monster-role="sub5" id="a5"></div>
|
41
|
+
</div>
|
42
|
+
</div>
|
43
|
+
</div>
|
44
|
+
</div>
|
45
|
+
</div>
|
46
|
+
`;
|
29
47
|
|
30
48
|
describe('Attributes', function () {
|
31
49
|
before(function (done) {
|
@@ -99,6 +117,43 @@ describe('Attributes', function () {
|
|
99
117
|
|
100
118
|
});
|
101
119
|
|
120
|
+
describe('Attributes', function () {
|
121
|
+
beforeEach(() => {
|
122
|
+
let mocks = document.getElementById('mocks');
|
123
|
+
mocks.innerHTML = html3;
|
124
|
+
})
|
125
|
+
|
126
|
+
afterEach(() => {
|
127
|
+
let mocks = document.getElementById('mocks');
|
128
|
+
mocks.innerHTML = "";
|
129
|
+
})
|
130
|
+
|
131
|
+
describe('find closest Attributes', function () {
|
132
|
+
|
133
|
+
[
|
134
|
+
['a5', 'data-monster-role', undefined, 'sub5'],
|
135
|
+
['a5', 'data-monster-role', 'sub3', 'sub3'],
|
136
|
+
['a5', 'data-monster-role', 'sub1', 'sub1'],
|
137
|
+
['a4', 'data-monster-role', 'sub1', 'sub1'],
|
138
|
+
['a3', 'data-monster-role', 'sub1', 'sub1'],
|
139
|
+
['a2', 'data-monster-role', undefined, 'sub2'],
|
140
|
+
['a5', 'data-monster-role', 'sub5', 'sub5']
|
141
|
+
].forEach(function (data) {
|
142
|
+
|
143
|
+
let a = data.shift()
|
144
|
+
let b = data.shift()
|
145
|
+
let c = data.shift()
|
146
|
+
let d = data.shift()
|
147
|
+
|
148
|
+
it('findClosestByAttribute(' + a + ', ' + b + ',' + c + ') should return ' + d, function () {
|
149
|
+
expect(findClosestByAttribute(document.getElementById(a), b, c).getAttribute('data-monster-role')).to.be.equal(d);
|
150
|
+
})
|
151
|
+
|
152
|
+
|
153
|
+
});
|
154
|
+
});
|
155
|
+
});
|
156
|
+
|
102
157
|
describe('Attributes', function () {
|
103
158
|
|
104
159
|
beforeEach(() => {
|
@@ -0,0 +1,264 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
import {ATTRIBUTE_OPTIONS} from "../../../source/dom/constants.js";
|
4
|
+
import {getDocument} from "../../../source/dom/util.js";
|
5
|
+
import {ID} from "../../../source/types/id.js";
|
6
|
+
import {initJSDOM} from "../../util/jsdom.js";
|
7
|
+
import chai from "chai"
|
8
|
+
import {chaiDom} from "../../util/chai-dom.js";
|
9
|
+
|
10
|
+
|
11
|
+
let expect = chai.expect;
|
12
|
+
chai.use(chaiDom);
|
13
|
+
|
14
|
+
let html1 = `
|
15
|
+
<div id="test1">
|
16
|
+
</div>
|
17
|
+
`;
|
18
|
+
|
19
|
+
describe('DOM', function () {
|
20
|
+
|
21
|
+
let CustomControl, registerCustomElement, TestComponent, document, jsdomFlag;
|
22
|
+
|
23
|
+
describe('CustomControl()', function () {
|
24
|
+
|
25
|
+
before(function (done) {
|
26
|
+
initJSDOM().then(() => {
|
27
|
+
|
28
|
+
// jsdom does not support ElementInternals
|
29
|
+
jsdomFlag = navigator.userAgent.includes("jsdom");
|
30
|
+
|
31
|
+
import("../../../source/dom/customelement.js").then((m) => {
|
32
|
+
registerCustomElement = m['registerCustomElement'];
|
33
|
+
|
34
|
+
|
35
|
+
import("../../../source/dom/customcontrol.js").then((m) => {
|
36
|
+
|
37
|
+
document = getDocument();
|
38
|
+
|
39
|
+
try {
|
40
|
+
CustomControl = m['CustomControl'];
|
41
|
+
|
42
|
+
TestComponent = class extends CustomControl {
|
43
|
+
static getTag() {
|
44
|
+
return "monster-customcontrol"
|
45
|
+
}
|
46
|
+
}
|
47
|
+
registerCustomElement(TestComponent)
|
48
|
+
|
49
|
+
|
50
|
+
done()
|
51
|
+
} catch (e) {
|
52
|
+
done(e);
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
});
|
57
|
+
});
|
58
|
+
});
|
59
|
+
})
|
60
|
+
|
61
|
+
beforeEach(() => {
|
62
|
+
let mocks = document.getElementById('mocks');
|
63
|
+
mocks.innerHTML = html1;
|
64
|
+
})
|
65
|
+
|
66
|
+
afterEach(() => {
|
67
|
+
let mocks = document.getElementById('mocks');
|
68
|
+
mocks.innerHTML = "";
|
69
|
+
})
|
70
|
+
|
71
|
+
describe('create', function () {
|
72
|
+
it('should return custom-element object', function () {
|
73
|
+
let d = new TestComponent();
|
74
|
+
expect(typeof d).is.equal('object');
|
75
|
+
});
|
76
|
+
});
|
77
|
+
|
78
|
+
describe('connect empty element', function () {
|
79
|
+
it('document should contain monster-customcontrol', function () {
|
80
|
+
let d = document.createElement('monster-customcontrol');
|
81
|
+
document.getElementById('test1').appendChild(d);
|
82
|
+
expect(document.getElementsByTagName('monster-customcontrol').length).is.equal(1);
|
83
|
+
expect(document.getElementById('test1')).contain.html('<monster-customcontrol></monster-customcontrol>');
|
84
|
+
});
|
85
|
+
});
|
86
|
+
|
87
|
+
describe('Options change', function () {
|
88
|
+
|
89
|
+
it('delegatesFocus should change from true to false', function () {
|
90
|
+
let element = document.createElement('monster-customcontrol')
|
91
|
+
|
92
|
+
expect(element.getOption('delegatesFocus')).to.be.true;
|
93
|
+
element.setAttribute(ATTRIBUTE_OPTIONS, JSON.stringify({delegatesFocus: false}));
|
94
|
+
expect(element.getOption('delegatesFocus')).to.be.false;
|
95
|
+
|
96
|
+
})
|
97
|
+
|
98
|
+
|
99
|
+
})
|
100
|
+
|
101
|
+
describe('Test ElementInternals', function () {
|
102
|
+
|
103
|
+
let form;
|
104
|
+
|
105
|
+
beforeEach(() => {
|
106
|
+
form = document.createElement('form');
|
107
|
+
})
|
108
|
+
|
109
|
+
it('formAssociated', function () {
|
110
|
+
|
111
|
+
let d = document.createElement('monster-customcontrol');
|
112
|
+
form.appendChild(d);
|
113
|
+
|
114
|
+
expect(d.constructor.formAssociated).to.be.true;
|
115
|
+
|
116
|
+
});
|
117
|
+
it('form', function () {
|
118
|
+
|
119
|
+
let d = document.createElement('monster-customcontrol');
|
120
|
+
form.appendChild(d);
|
121
|
+
|
122
|
+
if (jsdomFlag) {
|
123
|
+
expect(() => d.form).to.throw(Error);
|
124
|
+
} else {
|
125
|
+
expect(d.form).to.be.instanceof(HTMLFormElement)
|
126
|
+
}
|
127
|
+
|
128
|
+
|
129
|
+
});
|
130
|
+
|
131
|
+
it('value getter', function () {
|
132
|
+
|
133
|
+
let d = document.createElement('monster-customcontrol');
|
134
|
+
form.appendChild(d);
|
135
|
+
|
136
|
+
expect(() => d.value).to.throw(Error);
|
137
|
+
|
138
|
+
});
|
139
|
+
|
140
|
+
it('value setter', function () {
|
141
|
+
|
142
|
+
let d = document.createElement('monster-customcontrol');
|
143
|
+
form.appendChild(d);
|
144
|
+
|
145
|
+
expect(() => d.value = 4).to.throw(Error);
|
146
|
+
|
147
|
+
});
|
148
|
+
|
149
|
+
|
150
|
+
it('setFormValue', function () {
|
151
|
+
|
152
|
+
let d = document.createElement('monster-customcontrol');
|
153
|
+
form.appendChild(d);
|
154
|
+
|
155
|
+
if (jsdomFlag) {
|
156
|
+
expect(() => d.setFormValue()).to.throw(Error);
|
157
|
+
} else {
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
});
|
162
|
+
|
163
|
+
|
164
|
+
it('name getter', function () {
|
165
|
+
|
166
|
+
let d = document.createElement('monster-customcontrol');
|
167
|
+
form.appendChild(d);
|
168
|
+
|
169
|
+
expect(d.name).to.be.null;
|
170
|
+
|
171
|
+
});
|
172
|
+
|
173
|
+
it('type getter', function () {
|
174
|
+
|
175
|
+
let d = document.createElement('monster-customcontrol');
|
176
|
+
form.appendChild(d);
|
177
|
+
|
178
|
+
expect(d.type).to.be.equal('monster-customcontrol');
|
179
|
+
|
180
|
+
});
|
181
|
+
|
182
|
+
it('validity getter', function () {
|
183
|
+
|
184
|
+
let d = document.createElement('monster-customcontrol');
|
185
|
+
form.appendChild(d);
|
186
|
+
if (jsdomFlag) {
|
187
|
+
expect(() => d.validity).to.throw(Error);
|
188
|
+
} else {
|
189
|
+
|
190
|
+
}
|
191
|
+
|
192
|
+
});
|
193
|
+
|
194
|
+
it('validationMessage getter', function () {
|
195
|
+
|
196
|
+
let d = document.createElement('monster-customcontrol');
|
197
|
+
form.appendChild(d);
|
198
|
+
|
199
|
+
if (jsdomFlag) {
|
200
|
+
expect(() => d.validity).to.throw(Error);
|
201
|
+
} else {
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
});
|
206
|
+
|
207
|
+
it('willValidate getter', function () {
|
208
|
+
|
209
|
+
let d = document.createElement('monster-customcontrol');
|
210
|
+
form.appendChild(d);
|
211
|
+
|
212
|
+
if (jsdomFlag) {
|
213
|
+
expect(() => d.willValidate).to.throw(Error);
|
214
|
+
} else {
|
215
|
+
|
216
|
+
}
|
217
|
+
|
218
|
+
});
|
219
|
+
it('checkValidity()', function () {
|
220
|
+
|
221
|
+
let d = document.createElement('monster-customcontrol');
|
222
|
+
form.appendChild(d);
|
223
|
+
|
224
|
+
if (jsdomFlag) {
|
225
|
+
expect(() => d.checkValidity()).to.throw(Error);
|
226
|
+
} else {
|
227
|
+
|
228
|
+
}
|
229
|
+
|
230
|
+
});
|
231
|
+
|
232
|
+
it('reportValidity()', function () {
|
233
|
+
|
234
|
+
let d = document.createElement('monster-customcontrol');
|
235
|
+
form.appendChild(d);
|
236
|
+
|
237
|
+
if (jsdomFlag) {
|
238
|
+
expect(() => d.reportValidity()).to.throw(Error);
|
239
|
+
} else {
|
240
|
+
|
241
|
+
}
|
242
|
+
|
243
|
+
});
|
244
|
+
|
245
|
+
|
246
|
+
it('setValidity()', function () {
|
247
|
+
|
248
|
+
let d = document.createElement('monster-customcontrol');
|
249
|
+
form.appendChild(d);
|
250
|
+
if (jsdomFlag) {
|
251
|
+
expect(() => d.setValidity()).to.throw(Error);
|
252
|
+
} else {
|
253
|
+
expect(d.setValidity({'valueMissing': true}, "my message")).to.be.undefined;
|
254
|
+
}
|
255
|
+
|
256
|
+
});
|
257
|
+
|
258
|
+
|
259
|
+
});
|
260
|
+
});
|
261
|
+
|
262
|
+
});
|
263
|
+
|
264
|
+
|
@@ -1,5 +1,7 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
|
+
import {PROPERTY_KEY_INTERNALDATA} from "../../../source/constants.js";
|
4
|
+
import {ATTRIBUTE_OPTIONS} from "../../../source/dom/constants.js";
|
3
5
|
import {getDocument} from "../../../source/dom/util.js";
|
4
6
|
import {initJSDOM} from "../../util/jsdom.js";
|
5
7
|
import chai from "chai"
|
@@ -14,70 +16,75 @@ let html1 = `
|
|
14
16
|
</div>
|
15
17
|
`;
|
16
18
|
|
19
|
+
const internalDataSymbol = Symbol.for(PROPERTY_KEY_INTERNALDATA);
|
20
|
+
|
17
21
|
describe('DOM', function () {
|
18
22
|
|
19
23
|
let CustomElement, registerCustomElement, TestComponent, document, TestComponent2;
|
20
24
|
|
21
|
-
before(function (done) {
|
22
|
-
initJSDOM().then(() => {
|
23
25
|
|
24
|
-
|
26
|
+
describe('CustomElement()', function () {
|
25
27
|
|
26
|
-
try {
|
27
|
-
CustomElement = m['CustomElement'];
|
28
|
-
registerCustomElement = m['registerCustomElement'];
|
29
|
-
TestComponent = class extends CustomElement {
|
30
|
-
static getTag() {
|
31
|
-
return "monster-testclass"
|
32
|
-
}
|
33
|
-
}
|
34
|
-
registerCustomElement(TestComponent)
|
35
28
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
29
|
+
before(function (done) {
|
30
|
+
initJSDOM().then(() => {
|
31
|
+
|
32
|
+
import("../../../source/dom/customelement.js").then((m) => {
|
40
33
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
templates: {
|
49
|
-
main: '<h1></h1><article><p>test</p></article>'
|
50
|
-
},
|
51
|
-
})
|
34
|
+
try {
|
35
|
+
CustomElement = m['CustomElement'];
|
36
|
+
registerCustomElement = m['registerCustomElement'];
|
37
|
+
TestComponent = class extends CustomElement {
|
38
|
+
static getTag() {
|
39
|
+
return "monster-testclass"
|
40
|
+
}
|
52
41
|
}
|
53
42
|
|
54
|
-
|
43
|
+
registerCustomElement(TestComponent)
|
55
44
|
|
56
|
-
|
45
|
+
TestComponent2 = class extends CustomElement {
|
46
|
+
static getTag() {
|
47
|
+
return "monster-testclass2"
|
48
|
+
}
|
57
49
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
50
|
+
/**
|
51
|
+
*
|
52
|
+
* @return {Object}
|
53
|
+
*/
|
54
|
+
get defaults() {
|
63
55
|
|
56
|
+
return Object.assign({}, super.defaults, {
|
57
|
+
templates: {
|
58
|
+
main: '<h1></h1><article><p>test</p></article>'
|
59
|
+
},
|
60
|
+
})
|
61
|
+
}
|
64
62
|
|
65
|
-
|
63
|
+
}
|
66
64
|
|
67
|
-
|
68
|
-
})
|
65
|
+
registerCustomElement(TestComponent2)
|
69
66
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
67
|
+
document = getDocument();
|
68
|
+
done()
|
69
|
+
} catch (e) {
|
70
|
+
done(e);
|
71
|
+
}
|
74
72
|
|
75
|
-
afterEach(() => {
|
76
|
-
let mocks = document.getElementById('mocks');
|
77
|
-
mocks.innerHTML = "";
|
78
|
-
})
|
79
73
|
|
80
|
-
|
74
|
+
});
|
75
|
+
|
76
|
+
});
|
77
|
+
})
|
78
|
+
|
79
|
+
beforeEach(() => {
|
80
|
+
let mocks = document.getElementById('mocks');
|
81
|
+
mocks.innerHTML = html1;
|
82
|
+
})
|
83
|
+
|
84
|
+
afterEach(() => {
|
85
|
+
let mocks = document.getElementById('mocks');
|
86
|
+
mocks.innerHTML = "";
|
87
|
+
})
|
81
88
|
|
82
89
|
describe('create', function () {
|
83
90
|
it('should return custom-element object', function () {
|
@@ -99,22 +106,76 @@ describe('DOM', function () {
|
|
99
106
|
it('document should contain monster-testclass2', function (done) {
|
100
107
|
let d = document.createElement('monster-testclass2');
|
101
108
|
document.getElementById('test1').appendChild(d);
|
102
|
-
|
109
|
+
|
103
110
|
// insert DOM run in extra process via setTimeout!
|
104
|
-
setTimeout(function(){
|
111
|
+
setTimeout(function () {
|
105
112
|
try {
|
106
113
|
expect(document.getElementsByTagName('monster-testclass2').length).is.equal(1);
|
107
114
|
expect(document.getElementsByTagName('monster-testclass2').item(0).shadowRoot.innerHTML).is.equal('<h1></h1><article><p>test</p></article>');
|
108
115
|
expect(document.getElementById('test1')).contain.html('<monster-testclass2 data-monster-objectlink="Symbol(monsterUpdater)"></monster-testclass2>');
|
109
|
-
} catch(e) {
|
116
|
+
} catch (e) {
|
110
117
|
done(e);
|
111
118
|
}
|
112
119
|
done();
|
113
|
-
},100);
|
114
|
-
|
120
|
+
}, 100);
|
121
|
+
|
115
122
|
});
|
116
123
|
});
|
117
124
|
|
125
|
+
describe('Options change', function () {
|
126
|
+
|
127
|
+
it('delegatesFocus should change from true to false', function () {
|
128
|
+
let element = document.createElement('monster-testclass')
|
129
|
+
|
130
|
+
const o = element[internalDataSymbol].realSubject;
|
131
|
+
expect(Object.is(element[internalDataSymbol].realSubject, o)).to.be.true;
|
132
|
+
|
133
|
+
expect(element[internalDataSymbol].realSubject.options.delegatesFocus).to.be.true;
|
134
|
+
expect(element[internalDataSymbol].subject.options.delegatesFocus).to.be.true;
|
135
|
+
expect(element.getOption('delegatesFocus')).to.be.true;
|
136
|
+
expect(Object.is(element[internalDataSymbol].realSubject, o)).to.be.true;
|
137
|
+
|
138
|
+
element.setAttribute(ATTRIBUTE_OPTIONS, JSON.stringify({delegatesFocus: false}));
|
139
|
+
expect(Object.is(element[internalDataSymbol].realSubject, o)).to.be.true;
|
140
|
+
|
141
|
+
expect(element.getOption('delegatesFocus')).to.be.false;
|
142
|
+
expect(element[internalDataSymbol].realSubject.options.delegatesFocus).to.be.false;
|
143
|
+
expect(Object.is(element[internalDataSymbol].realSubject, o)).to.be.true;
|
144
|
+
|
145
|
+
})
|
146
|
+
|
147
|
+
|
148
|
+
})
|
149
|
+
|
150
|
+
describe('setOptions()', function () {
|
151
|
+
[
|
152
|
+
['shadowMode', 'x1'],
|
153
|
+
['templates.main', 'x2'], // is explicitly set to undefined
|
154
|
+
['delegatesFocus', 'x4'],
|
155
|
+
].forEach(function (data) {
|
156
|
+
|
157
|
+
|
158
|
+
let key = data.shift()
|
159
|
+
let newValue = data.shift()
|
160
|
+
|
161
|
+
let text = key + ' should return ' + newValue;
|
162
|
+
if (newValue !== undefined) {
|
163
|
+
text = key + ' was not set, therefore default ' + newValue;
|
164
|
+
}
|
165
|
+
|
166
|
+
|
167
|
+
it(text, function () {
|
168
|
+
|
169
|
+
let d = document.createElement('monster-testclass');
|
170
|
+
expect(d.getOption(key)).to.be.not.equal(newValue);
|
171
|
+
let x = d.setOption(key, newValue);
|
172
|
+
expect(d.getOption(key)).to.be.equal(newValue);
|
173
|
+
})
|
174
|
+
|
175
|
+
|
176
|
+
})
|
177
|
+
});
|
178
|
+
|
118
179
|
describe('getOptions()', function () {
|
119
180
|
|
120
181
|
[
|