@schukai/monster 3.56.1 → 3.57.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/example/components/form/toggle-switch.mjs +7 -0
- package/package.json +1 -1
- package/source/components/form/button.mjs +3 -3
- package/source/components/form/select.mjs +1773 -1745
- package/source/components/form/style/select.pcss +1 -1
- package/source/components/form/style/toggle-switch.pcss +74 -0
- package/source/components/form/stylesheet/select.mjs +1 -1
- package/source/components/form/stylesheet/toggle-switch.mjs +27 -0
- package/source/components/form/toggle-switch.mjs +427 -0
- package/source/data/transformer.mjs +33 -1
- package/source/dom/attributes.mjs +1 -1
- package/source/dom/customcontrol.mjs +6 -2
- package/source/dom/customelement.mjs +909 -864
- package/source/dom/updater.mjs +754 -732
- package/source/dom/util/set-option-from-attribute.mjs +2 -1
- package/source/monster.mjs +5 -0
- package/source/types/version.mjs +1 -1
- package/test/cases/components/form/select.mjs +1 -1
- package/test/cases/components/form/toggle-switch.mjs +310 -0
- package/test/cases/components/form/tree-select.mjs +1 -8
- package/test/cases/data/transformer.mjs +16 -0
- package/test/cases/dom/customcontrol.mjs +53 -8
- package/test/cases/dom/customelement-initfromscripthost.mjs +0 -4
- package/test/cases/dom/customelement.mjs +30 -26
- package/test/cases/dom/updater.mjs +14 -3
- package/test/cases/monster.mjs +1 -1
- package/test/util/jsdom.mjs +9 -10
- package/test/web/test.html +2 -2
- package/test/web/tests.js +3044 -1023
@@ -49,6 +49,7 @@ function setOptionFromAttribute(
|
|
49
49
|
mapping = {},
|
50
50
|
prefix = "data-monster-option-",
|
51
51
|
) {
|
52
|
+
|
52
53
|
if (!(element instanceof HTMLElement)) return options;
|
53
54
|
if (!element.hasAttributes()) return options;
|
54
55
|
|
@@ -84,4 +85,4 @@ function setOptionFromAttribute(
|
|
84
85
|
finder.setVia(optionName, value);
|
85
86
|
|
86
87
|
return options;
|
87
|
-
}
|
88
|
+
}
|
package/source/monster.mjs
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
|
1
2
|
/**
|
2
3
|
* Copyright schukai GmbH and contributors 2023. All Rights Reserved.
|
3
4
|
* Node module: @schukai/monster
|
@@ -93,9 +94,11 @@ export * from "./components/datatable/datatable/header.mjs";
|
|
93
94
|
export * from "./components/datatable/pagination.mjs";
|
94
95
|
export * from "./components/datatable/util.mjs";
|
95
96
|
export * from "./components/datatable/filter.mjs";
|
97
|
+
export * from "./components/datatable/save-button.mjs";
|
96
98
|
export * from "./components/datatable/dataset.mjs";
|
97
99
|
export * from "./components/datatable/embedded-pagination.mjs";
|
98
100
|
export * from "./components/datatable/status.mjs";
|
101
|
+
export * from "./components/datatable/change-button.mjs";
|
99
102
|
export * from "./components/datatable/constants.mjs";
|
100
103
|
export * from "./components/datatable/stylesheet/select-filter.mjs";
|
101
104
|
export * from "./components/datatable/stylesheet/datasource.mjs";
|
@@ -105,10 +108,12 @@ export * from "./components/datatable/stylesheet/filter-date-range.mjs";
|
|
105
108
|
export * from "./components/datatable/stylesheet/datatable.mjs";
|
106
109
|
export * from "./components/datatable/stylesheet/pagination.mjs";
|
107
110
|
export * from "./components/datatable/stylesheet/filter.mjs";
|
111
|
+
export * from "./components/datatable/stylesheet/save-button.mjs";
|
108
112
|
export * from "./components/datatable/stylesheet/dataset.mjs";
|
109
113
|
export * from "./components/datatable/stylesheet/embedded-pagination.mjs";
|
110
114
|
export * from "./components/datatable/stylesheet/filter-controls-defaults.mjs";
|
111
115
|
export * from "./components/datatable/stylesheet/status.mjs";
|
116
|
+
export * from "./components/datatable/stylesheet/change-button.mjs";
|
112
117
|
export * from "./components/datatable/stylesheet/filter-range.mjs";
|
113
118
|
export * from "./components/state/log/entry.mjs";
|
114
119
|
export * from "./components/state/state.mjs";
|
package/source/types/version.mjs
CHANGED
@@ -0,0 +1,310 @@
|
|
1
|
+
import { getGlobal } from "../../../../source/types/global.mjs";
|
2
|
+
import chai from "chai"
|
3
|
+
import { chaiDom } from "../../../util/chai-dom.mjs";
|
4
|
+
import { initJSDOM } from "../../../util/jsdom.mjs";
|
5
|
+
|
6
|
+
let expect = chai.expect;
|
7
|
+
chai.use(chaiDom);
|
8
|
+
|
9
|
+
const global = getGlobal();
|
10
|
+
|
11
|
+
let html1 = `
|
12
|
+
<div id="test1">
|
13
|
+
</div>
|
14
|
+
`;
|
15
|
+
|
16
|
+
let html2 = `
|
17
|
+
<div id="test2">
|
18
|
+
<monster-toggle-switch></monster-toggle-switch>
|
19
|
+
</div>
|
20
|
+
`;
|
21
|
+
|
22
|
+
let ToggleSwitch;
|
23
|
+
|
24
|
+
describe('ToggleSwitch', function () {
|
25
|
+
|
26
|
+
before(function (done) {
|
27
|
+
initJSDOM().then(() => {
|
28
|
+
|
29
|
+
import("element-internals-polyfill").catch(e => done(e));
|
30
|
+
|
31
|
+
import("../../../../source/components/form/toggle-switch.mjs").then((m) => {
|
32
|
+
ToggleSwitch = m['ToggleSwitch'];
|
33
|
+
done()
|
34
|
+
}).catch(e => done(e))
|
35
|
+
|
36
|
+
|
37
|
+
});
|
38
|
+
})
|
39
|
+
|
40
|
+
describe('new ToggleSwitch', function () {
|
41
|
+
|
42
|
+
beforeEach(() => {
|
43
|
+
let mocks = document.getElementById('mocks');
|
44
|
+
mocks.innerHTML = html1;
|
45
|
+
})
|
46
|
+
|
47
|
+
afterEach(() => {
|
48
|
+
let mocks = document.getElementById('mocks');
|
49
|
+
mocks.innerHTML = "";
|
50
|
+
})
|
51
|
+
|
52
|
+
describe('create from template', function () {
|
53
|
+
beforeEach(() => {
|
54
|
+
let mocks = document.getElementById('mocks');
|
55
|
+
mocks.innerHTML = html2;
|
56
|
+
});
|
57
|
+
|
58
|
+
afterEach(() => {
|
59
|
+
let mocks = document.getElementById('mocks');
|
60
|
+
mocks.innerHTML = "";
|
61
|
+
|
62
|
+
})
|
63
|
+
|
64
|
+
describe('create from template', function () {
|
65
|
+
it('should contains monster-toggle-switch', function () {
|
66
|
+
expect(document.getElementById('test2')).contain.html('<monster-toggle-switch');
|
67
|
+
});
|
68
|
+
});
|
69
|
+
|
70
|
+
});
|
71
|
+
|
72
|
+
describe('document.createElement', function () {
|
73
|
+
it('should instance of monster-toggle-switch', function () {
|
74
|
+
expect(document.createElement('monster-toggle-switch')).is.instanceof(ToggleSwitch);
|
75
|
+
});
|
76
|
+
});
|
77
|
+
|
78
|
+
});
|
79
|
+
|
80
|
+
describe('toggle', function () {
|
81
|
+
beforeEach(() => {
|
82
|
+
let mocks = document.getElementById('mocks');
|
83
|
+
mocks.innerHTML = html1;
|
84
|
+
});
|
85
|
+
|
86
|
+
afterEach(() => {
|
87
|
+
let mocks = document.getElementById('mocks');
|
88
|
+
mocks.innerHTML = "";
|
89
|
+
})
|
90
|
+
|
91
|
+
it('toggle to on', function () {
|
92
|
+
|
93
|
+
const toggleSwitch = document.createElement('monster-toggle-switch');
|
94
|
+
|
95
|
+
expect(toggleSwitch.value).is.equal('off');
|
96
|
+
expect(toggleSwitch.state).is.equal('off');
|
97
|
+
|
98
|
+
toggleSwitch.toggle();
|
99
|
+
|
100
|
+
expect(toggleSwitch.value).is.equal('on');
|
101
|
+
expect(toggleSwitch.state).is.equal('on');
|
102
|
+
|
103
|
+
toggleSwitch.toggle();
|
104
|
+
|
105
|
+
expect(toggleSwitch.value).is.equal('off');
|
106
|
+
expect(toggleSwitch.state).is.equal('off');
|
107
|
+
});
|
108
|
+
|
109
|
+
it('toggle on to off', function () {
|
110
|
+
|
111
|
+
const toggleSwitch = document.createElement('monster-toggle-switch');
|
112
|
+
|
113
|
+
toggleSwitch.toggleOn();
|
114
|
+
|
115
|
+
expect(toggleSwitch.value).is.equal('on');
|
116
|
+
expect(toggleSwitch.state).is.equal('on');
|
117
|
+
|
118
|
+
toggleSwitch.toggleOff();
|
119
|
+
|
120
|
+
expect(toggleSwitch.value).is.equal('off');
|
121
|
+
expect(toggleSwitch.state).is.equal('off');
|
122
|
+
|
123
|
+
});
|
124
|
+
|
125
|
+
|
126
|
+
});
|
127
|
+
|
128
|
+
describe('describe css', function () {
|
129
|
+
|
130
|
+
beforeEach(() => {
|
131
|
+
let mocks = document.getElementById('mocks');
|
132
|
+
mocks.innerHTML = html1;
|
133
|
+
});
|
134
|
+
|
135
|
+
afterEach(() => {
|
136
|
+
let mocks = document.getElementById('mocks');
|
137
|
+
mocks.innerHTML = "";
|
138
|
+
})
|
139
|
+
|
140
|
+
it('css toggle', function (done) {
|
141
|
+
|
142
|
+
/**
|
143
|
+
* new Control
|
144
|
+
*/
|
145
|
+
const toggleSwitch = document.createElement('monster-toggle-switch');
|
146
|
+
|
147
|
+
/**
|
148
|
+
* set init value to on
|
149
|
+
*/
|
150
|
+
toggleSwitch.value = "on";
|
151
|
+
|
152
|
+
/**
|
153
|
+
* insert DOM
|
154
|
+
*/
|
155
|
+
document.getElementById('mocks').appendChild(toggleSwitch);
|
156
|
+
|
157
|
+
/**
|
158
|
+
* expect that classes.on is set to Element Switch
|
159
|
+
*/
|
160
|
+
let hasClassA = toggleSwitch.shadowRoot.querySelectorAll('[data-monster-role="switch"]')[0].classList.contains(toggleSwitch.getOption('classes.on'));
|
161
|
+
expect(hasClassA).is.true;
|
162
|
+
|
163
|
+
/**
|
164
|
+
* switch off
|
165
|
+
*/
|
166
|
+
toggleSwitch.value = "off";
|
167
|
+
|
168
|
+
/**
|
169
|
+
* Updater prozess runs in setTimeout
|
170
|
+
* self[internalSymbol].attachObserver();
|
171
|
+
*/
|
172
|
+
setTimeout(() => {
|
173
|
+
|
174
|
+
/**
|
175
|
+
* expect that classes.on is removed from Element Switch
|
176
|
+
*/
|
177
|
+
let hasClassB = toggleSwitch.shadowRoot.querySelectorAll('[data-monster-role="switch"]')[0].classList.contains(toggleSwitch.getOption('classes.on'));
|
178
|
+
expect(hasClassB).is.false;
|
179
|
+
|
180
|
+
/**
|
181
|
+
* expect that classes.off is set to Element Switch
|
182
|
+
*/
|
183
|
+
let hasClassC = toggleSwitch.shadowRoot.querySelectorAll('[data-monster-role="switch"]')[0].classList.contains(toggleSwitch.getOption('classes.off'));
|
184
|
+
expect(hasClassC).is.true;
|
185
|
+
|
186
|
+
|
187
|
+
done();
|
188
|
+
}, 0);
|
189
|
+
|
190
|
+
})
|
191
|
+
|
192
|
+
});
|
193
|
+
|
194
|
+
describe('describe value', function () {
|
195
|
+
|
196
|
+
beforeEach(() => {
|
197
|
+
let mocks = document.getElementById('mocks');
|
198
|
+
mocks.innerHTML = html1;
|
199
|
+
});
|
200
|
+
|
201
|
+
afterEach(() => {
|
202
|
+
let mocks = document.getElementById('mocks');
|
203
|
+
mocks.innerHTML = "";
|
204
|
+
|
205
|
+
})
|
206
|
+
|
207
|
+
it('the default value is off', function () {
|
208
|
+
|
209
|
+
/**
|
210
|
+
* new Control
|
211
|
+
*/
|
212
|
+
let toggleSwitch = document.createElement('monster-toggle-switch');
|
213
|
+
|
214
|
+
/**
|
215
|
+
* the switch is off and provides the value for off
|
216
|
+
*/
|
217
|
+
expect(toggleSwitch.value).is.equal('off');
|
218
|
+
|
219
|
+
/**
|
220
|
+
* the switch is off
|
221
|
+
*/
|
222
|
+
expect(toggleSwitch.state).is.equal('off');
|
223
|
+
|
224
|
+
});
|
225
|
+
|
226
|
+
it('incorrect values are not accepted', function () {
|
227
|
+
|
228
|
+
let toggleSwitch = document.createElement('monster-toggle-switch');
|
229
|
+
|
230
|
+
/**
|
231
|
+
* define the values for on and off
|
232
|
+
*/
|
233
|
+
toggleSwitch.setOption('values.on', 'true');
|
234
|
+
toggleSwitch.setOption('values.off', 'false');
|
235
|
+
|
236
|
+
/**
|
237
|
+
* This value is not "true" and not "false"
|
238
|
+
*/
|
239
|
+
toggleSwitch.value = "test";
|
240
|
+
|
241
|
+
/**
|
242
|
+
* the switch is off and provides the value for off
|
243
|
+
*/
|
244
|
+
expect(toggleSwitch.value).is.equal('false');
|
245
|
+
|
246
|
+
/**
|
247
|
+
* the switch is off
|
248
|
+
*/
|
249
|
+
expect(toggleSwitch.state).is.equal('off');
|
250
|
+
|
251
|
+
/**
|
252
|
+
* disabled attribute is only set when the element has been mounted in the DOM
|
253
|
+
*/
|
254
|
+
expect(toggleSwitch.hasAttribute('disabled')).is.false;
|
255
|
+
|
256
|
+
/**
|
257
|
+
* insert DOM
|
258
|
+
*/
|
259
|
+
document.getElementById('mocks').appendChild(toggleSwitch);
|
260
|
+
|
261
|
+
/**
|
262
|
+
* now the element is disabled
|
263
|
+
*/
|
264
|
+
expect(toggleSwitch.hasAttribute('disabled')).is.true;
|
265
|
+
|
266
|
+
|
267
|
+
});
|
268
|
+
|
269
|
+
it('correct values are accepted', function () {
|
270
|
+
|
271
|
+
const toggleSwitch = document.createElement('monster-toggle-switch');
|
272
|
+
|
273
|
+
/**
|
274
|
+
* define the values for on and off
|
275
|
+
*/
|
276
|
+
toggleSwitch.setOption('values.on', 'true');
|
277
|
+
toggleSwitch.setOption('values.off', 'false');
|
278
|
+
|
279
|
+
/**
|
280
|
+
* This value is correct
|
281
|
+
*/
|
282
|
+
toggleSwitch.value = "true";
|
283
|
+
|
284
|
+
/**
|
285
|
+
* the switch is on and provides the value for on
|
286
|
+
*/
|
287
|
+
expect(toggleSwitch.value).is.equal('true');
|
288
|
+
|
289
|
+
/**
|
290
|
+
* the switch is on
|
291
|
+
*/
|
292
|
+
expect(toggleSwitch.state).is.equal('on');
|
293
|
+
|
294
|
+
/**
|
295
|
+
* insert DOM
|
296
|
+
*/
|
297
|
+
document.getElementById('mocks').appendChild(toggleSwitch);
|
298
|
+
|
299
|
+
/**
|
300
|
+
* disabled attribute is not set
|
301
|
+
*/
|
302
|
+
expect(toggleSwitch.hasAttribute('disabled')).is.false;
|
303
|
+
|
304
|
+
});
|
305
|
+
|
306
|
+
});
|
307
|
+
|
308
|
+
|
309
|
+
|
310
|
+
});
|
@@ -96,18 +96,11 @@ describe('Treeselect', function () {
|
|
96
96
|
} ]`);
|
97
97
|
|
98
98
|
resolve2(JSON.stringify(json))
|
99
|
-
|
100
|
-
|
101
99
|
})
|
102
|
-
|
103
|
-
|
104
100
|
}
|
105
101
|
});
|
106
102
|
})
|
107
|
-
|
108
103
|
};
|
109
|
-
|
110
|
-
|
111
104
|
})
|
112
105
|
|
113
106
|
afterEach(() => {
|
@@ -174,7 +167,7 @@ describe('Treeselect', function () {
|
|
174
167
|
|
175
168
|
done();
|
176
169
|
|
177
|
-
},
|
170
|
+
}, 100)
|
178
171
|
})
|
179
172
|
|
180
173
|
|
@@ -175,6 +175,22 @@ describe('Transformer', function () {
|
|
175
175
|
['index:a', new Map().set('a', 5), 5],
|
176
176
|
['substring:2:4', 'abcdefghijklmnop', 'cdef'],
|
177
177
|
['nop', 'abcdefghijklmnop', 'abcdefghijklmnop'],
|
178
|
+
['set-toggle:c', 'a b c', 'a b'],
|
179
|
+
['set-toggle:c', 'a b', 'a b c'],
|
180
|
+
['set-set:c', 'a b', 'a b c'],
|
181
|
+
['set-set:c', 'a b c', 'a b c'],
|
182
|
+
['set-remove:c', 'a b c', 'a b'],
|
183
|
+
['set-toggle:c:,', 'a,b,c', 'a,b'],
|
184
|
+
['set-toggle:c:,', 'a,b', 'a,b,c'],
|
185
|
+
['set-set:c:,', 'a,b', 'a,b,c'],
|
186
|
+
['set-set:c:,', 'a,b,c', 'a,b,c'],
|
187
|
+
['set-remove:c:,', 'a,b,c', 'a,b'],
|
188
|
+
['set-toggle:c,d:,', 'a,b,c', 'a,b,d'],
|
189
|
+
['set-toggle:c,d:,', 'a,b,c,d', 'a,b'],
|
190
|
+
['set-toggle:c,d:,', 'a,b', 'a,b,c,d'],
|
191
|
+
['set-set:c,d:,', 'a,b', 'a,b,c,d'],
|
192
|
+
['set-set:c,d:,', 'a,b,c', 'a,b,c,d'],
|
193
|
+
['set-remove:c:,', 'a,b,c', 'a,b'],
|
178
194
|
|
179
195
|
].forEach(function (data) {
|
180
196
|
|
@@ -19,7 +19,7 @@ describe('DOM', function () {
|
|
19
19
|
let CustomControl, registerCustomElement, TestComponent, document, jsdomFlag;
|
20
20
|
|
21
21
|
before(function (done) {
|
22
|
-
initJSDOM().then(() => {
|
22
|
+
initJSDOM({}).then(() => {
|
23
23
|
|
24
24
|
import("element-internals-polyfill").then((m) => {
|
25
25
|
m.polyfill();
|
@@ -29,7 +29,7 @@ describe('DOM', function () {
|
|
29
29
|
jsdomFlag = navigator.userAgent.includes("jsdom");
|
30
30
|
|
31
31
|
import("../../../source/dom/customelement.mjs").then((m) => {
|
32
|
-
|
32
|
+
|
33
33
|
registerCustomElement = m['registerCustomElement'];
|
34
34
|
|
35
35
|
|
@@ -55,10 +55,52 @@ describe('DOM', function () {
|
|
55
55
|
});
|
56
56
|
}).catch((e) => {
|
57
57
|
done(e);
|
58
|
-
}
|
58
|
+
});
|
59
59
|
});
|
60
60
|
})
|
61
61
|
|
62
|
+
describe('formDisabledCallback()', function () {
|
63
|
+
|
64
|
+
let element
|
65
|
+
|
66
|
+
beforeEach(() => {
|
67
|
+
try {
|
68
|
+
const TestComponent2 = class extends CustomControl {
|
69
|
+
/**
|
70
|
+
* A description of the entire function.
|
71
|
+
*
|
72
|
+
* @return {string} description of return value
|
73
|
+
*/
|
74
|
+
static getTag() {
|
75
|
+
return "monster-customcontrol2"
|
76
|
+
}
|
77
|
+
}
|
78
|
+
registerCustomElement(TestComponent2)
|
79
|
+
} catch (e) {
|
80
|
+
expect(e).to.be.not.null;
|
81
|
+
}
|
82
|
+
|
83
|
+
element = document.createElement('monster-customcontrol2');
|
84
|
+
|
85
|
+
})
|
86
|
+
|
87
|
+
afterEach(() => {
|
88
|
+
|
89
|
+
})
|
90
|
+
|
91
|
+
it('should return undefined', function () {
|
92
|
+
expect(element.formDisabledCallback()).to.be.undefined;
|
93
|
+
expect(element.hasAttribute('disabled')).to.be.false;
|
94
|
+
expect(element.formDisabledCallback(true)).to.be.undefined;
|
95
|
+
expect(element.hasAttribute('disabled')).to.be.true;
|
96
|
+
const d = element.getAttribute('disabled');
|
97
|
+
expect(d).to.not.be.null;
|
98
|
+
|
99
|
+
});
|
100
|
+
|
101
|
+
})
|
102
|
+
|
103
|
+
|
62
104
|
describe('CustomControl()', function () {
|
63
105
|
|
64
106
|
beforeEach(() => {
|
@@ -76,13 +118,16 @@ describe('DOM', function () {
|
|
76
118
|
|
77
119
|
describe('create', function () {
|
78
120
|
it('should return custom-element object', function () {
|
121
|
+
let d
|
79
122
|
try {
|
80
|
-
|
123
|
+
d = new TestComponent();
|
81
124
|
} catch (e) {
|
82
|
-
expect(e).to.be.
|
125
|
+
expect(e).to.be.null;
|
83
126
|
}
|
84
127
|
|
85
|
-
|
128
|
+
console.log(typeof d,"ssss");
|
129
|
+
expect(typeof d).is.equal('object');
|
130
|
+
|
86
131
|
});
|
87
132
|
});
|
88
133
|
|
@@ -91,7 +136,7 @@ describe('DOM', function () {
|
|
91
136
|
|
92
137
|
let d = document.createElement('monster-customcontrol');
|
93
138
|
document.getElementById('test1').appendChild(d);
|
94
|
-
|
139
|
+
|
95
140
|
expect(document.getElementsByTagName('monster-customcontrol').length).is.equal(1);
|
96
141
|
// no data-monster-objectlink="Symbol(monsterUpdater)" because it has nothing to update
|
97
142
|
expect(document.getElementById('test1')).contain.html('<monster-customcontrol data-monster-error="Error: html is not set."></monster-customcontrol>')
|
@@ -172,7 +217,7 @@ describe('DOM', function () {
|
|
172
217
|
|
173
218
|
let d = document.createElement('monster-customcontrol');
|
174
219
|
form.appendChild(d);
|
175
|
-
|
220
|
+
|
176
221
|
});
|
177
222
|
|
178
223
|
it('name getter', function () {
|
@@ -1,11 +1,7 @@
|
|
1
1
|
'use strict';
|
2
2
|
|
3
3
|
import chai from "chai"
|
4
|
-
// import {internalSymbol} from "../../../source/constants.mjs";
|
5
|
-
// import {ATTRIBUTE_OPTIONS} from "../../../source/dom/constants.mjs";
|
6
4
|
import {getDocument} from "../../../source/dom/util.mjs";
|
7
|
-
// import {ProxyObserver} from "../../../source/types/proxyobserver.mjs";
|
8
|
-
// import {addObjectWithUpdaterToElement} from "../../../source/dom/updater.mjs";
|
9
5
|
import {chaiDom} from "../../util/chai-dom.mjs";
|
10
6
|
import {initJSDOM} from "../../util/jsdom.mjs";
|
11
7
|
|
@@ -2,10 +2,8 @@
|
|
2
2
|
|
3
3
|
import chai from "chai"
|
4
4
|
import {internalSymbol} from "../../../source/constants.mjs";
|
5
|
-
import {ATTRIBUTE_OPTIONS} from "../../../source/dom/constants.mjs";
|
6
5
|
import {getDocument} from "../../../source/dom/util.mjs";
|
7
6
|
import {ProxyObserver} from "../../../source/types/proxyobserver.mjs";
|
8
|
-
import {addObjectWithUpdaterToElement} from "../../../source/dom/updater.mjs";
|
9
7
|
import {chaiDom} from "../../util/chai-dom.mjs";
|
10
8
|
import {initJSDOM} from "../../util/jsdom.mjs";
|
11
9
|
|
@@ -27,34 +25,41 @@ const updaterSymbolKey = "@schukai/monster/dom/custom-element@@options-updater-l
|
|
27
25
|
const updaterSymbolSymbol = Symbol.for(updaterSymbolKey);
|
28
26
|
|
29
27
|
|
30
|
-
|
31
28
|
describe('DOM', function () {
|
32
29
|
|
33
|
-
let CustomElement, registerCustomElement, TestComponent, document, TestComponent2,assignUpdaterToElement
|
34
|
-
|
30
|
+
let CustomElement, registerCustomElement, TestComponent, document, TestComponent2, assignUpdaterToElement,
|
31
|
+
addObjectWithUpdaterToElement;
|
35
32
|
|
36
33
|
describe("assignUpdaterToElement", function () {
|
37
34
|
|
38
35
|
before(function (done) {
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
36
|
+
const options = {};
|
37
|
+
initJSDOM(options).then(() => {
|
38
|
+
import("../../../source/dom/updater.mjs").then((yy) => {
|
39
|
+
addObjectWithUpdaterToElement = yy['addObjectWithUpdaterToElement'];
|
40
|
+
import("../../../source/dom/customelement.mjs").then((m) => {
|
41
|
+
try {
|
42
|
+
CustomElement = m['CustomElement'];
|
43
|
+
assignUpdaterToElement = function (elements, object) {
|
44
|
+
return addObjectWithUpdaterToElement.call(this, elements, updaterSymbolSymbol, object);
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
document = getDocument();
|
49
|
+
|
50
|
+
done()
|
51
|
+
} catch (e) {
|
52
|
+
done(e);
|
45
53
|
}
|
46
|
-
|
47
|
-
|
48
|
-
document = getDocument();
|
49
54
|
|
50
|
-
done()
|
51
|
-
} catch (e) {
|
52
|
-
done(e);
|
53
|
-
}
|
54
55
|
|
56
|
+
}).catch((e) => {
|
57
|
+
done(e);
|
58
|
+
});
|
55
59
|
|
60
|
+
}).catch((e) => {
|
61
|
+
done(e);
|
56
62
|
});
|
57
|
-
|
58
63
|
});
|
59
64
|
})
|
60
65
|
|
@@ -71,7 +76,7 @@ describe('DOM', function () {
|
|
71
76
|
/**
|
72
77
|
* this test try to simulate the bug that was found in the assignUpdaterToElement function.
|
73
78
|
* The bug was that the updater was not assigned to the element when the element was created.
|
74
|
-
*
|
79
|
+
*
|
75
80
|
* unfortunately, this test does not reproduce the bug.
|
76
81
|
*/
|
77
82
|
it("should assign an updater to an element", function (done) {
|
@@ -98,9 +103,9 @@ describe('DOM', function () {
|
|
98
103
|
expect(JSON.stringify(y)).to.equal('{"b":2}');
|
99
104
|
|
100
105
|
const sy = updaterSymbolSymbol;
|
101
|
-
|
106
|
+
|
102
107
|
let v = element.getAttribute("data-monster-objectlink");
|
103
|
-
expect(v).to.equal('Symbol('+updaterSymbolKey+')');
|
108
|
+
expect(v).to.equal('Symbol(' + updaterSymbolKey + ')');
|
104
109
|
|
105
110
|
const updater = element[sy];
|
106
111
|
|
@@ -126,7 +131,7 @@ describe('DOM', function () {
|
|
126
131
|
// <input data-monster-bind="path:a" id="test2" data-monster-attributes="value path:a" data-monster-objectlink="Symbol(@schukai/monster/dom/@@object-updater-link)" value="3">
|
127
132
|
|
128
133
|
expect(mockHTML.querySelector("#test2")).to.have.value('3')
|
129
|
-
expect(mockHTML.querySelector("#test2")).to.have.attribute('data-monster-objectlink', 'Symbol('+updaterSymbolKey+')')
|
134
|
+
expect(mockHTML.querySelector("#test2")).to.have.attribute('data-monster-objectlink', 'Symbol(' + updaterSymbolKey + ')')
|
130
135
|
//expect(mockHTML).to.have.html(resultHTML);
|
131
136
|
|
132
137
|
expect(element.value).to.equal("3");
|
@@ -140,11 +145,10 @@ describe('DOM', function () {
|
|
140
145
|
|
141
146
|
})
|
142
147
|
|
143
|
-
|
144
148
|
describe('CustomElement()', function () {
|
145
149
|
|
146
150
|
before(function (done) {
|
147
|
-
initJSDOM().then(() => {
|
151
|
+
initJSDOM({}).then(() => {
|
148
152
|
|
149
153
|
import("../../../source/dom/customelement.mjs").then((m) => {
|
150
154
|
|
@@ -254,7 +258,7 @@ describe('DOM', function () {
|
|
254
258
|
try {
|
255
259
|
expect(document.getElementsByTagName('monster-testclass2').length).is.equal(1);
|
256
260
|
expect(document.getElementsByTagName('monster-testclass2').item(0).shadowRoot.innerHTML).is.equal('<h1></h1><article><p>test</p><div id="container"></div></article>');
|
257
|
-
expect(document.getElementById('test1')).contain.html('<monster-testclass2 data-monster-objectlink="Symbol('+updaterSymbolKey+')"></monster-testclass2>');
|
261
|
+
expect(document.getElementById('test1')).contain.html('<monster-testclass2 data-monster-objectlink="Symbol(' + updaterSymbolKey + ')"></monster-testclass2>');
|
258
262
|
return done();
|
259
263
|
} catch (e) {
|
260
264
|
done(e);
|