forked from DevExpress/DevExtreme
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.shadow_dom.tests.js
More file actions
56 lines (44 loc) · 2.23 KB
/
utils.shadow_dom.tests.js
File metadata and controls
56 lines (44 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import { computeStyleSheetsHash, addShadowDomStyles } from '__internal/core/utils/m_shadow_dom';
QUnit.module('computeStyleSheetsHash', () => {
QUnit.test('Returns consistent hash for same content', function(assert) {
const mockStyles = '.a { color: red; }';
const styleSheet1 = new CSSStyleSheet();
const styleSheet2 = new CSSStyleSheet();
styleSheet1.replaceSync(mockStyles);
styleSheet2.replaceSync(mockStyles);
const hash1 = computeStyleSheetsHash([styleSheet1]);
const hash2 = computeStyleSheetsHash([styleSheet2]);
assert.equal(hash1, hash2, 'Hashes are equal for identical stylesheets');
});
QUnit.test('Returns different hash for different content', function(assert) {
const styleSheet1 = new CSSStyleSheet();
const styleSheet2 = new CSSStyleSheet();
styleSheet1.replaceSync('.a { color: red; }');
styleSheet2.replaceSync('.a { color: blue; }');
const hash1 = computeStyleSheetsHash([styleSheet1]);
const hash2 = computeStyleSheetsHash([styleSheet2]);
assert.notEqual(hash1, hash2, 'Hashes differ for different stylesheets');
});
});
QUnit.module('addShadowDomStyles', () => {
QUnit.test('Does not duplicate stylesheets on repeated calls', async function(assert) {
const done = assert.async();
const container = document.createElement('div');
document.body.appendChild(container);
const shadow = container.attachShadow({ mode: 'open' });
const div = document.createElement('div');
shadow.appendChild(div);
const $div = $(div);
addShadowDomStyles($div);
const firstSheets = [...shadow.adoptedStyleSheets];
const firstRules = firstSheets.map(sheet => sheet.cssRules.length);
addShadowDomStyles($div);
const secondSheets = [...shadow.adoptedStyleSheets];
const secondRules = secondSheets.map(sheet => sheet.cssRules.length);
assert.equal(firstSheets.length, secondSheets.length, 'Stylesheets count unchanged after repeated call');
for(let i = 0; i < firstRules.length; i++) {
assert.equal(firstRules[i], secondRules[i], `Sheet[${i}] cssRules count unchanged`);
}
done();
});
});