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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
|
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import * as assert from 'assert';
import * as dom from 'vs/base/browser/dom';
const $ = dom.$;
suite('dom', () => {
test('hasClass', () => {
const element = document.createElement('div');
element.className = 'foobar boo far';
assert(element.classList.contains('foobar'));
assert(element.classList.contains('boo'));
assert(element.classList.contains('far'));
assert(!element.classList.contains('bar'));
assert(!element.classList.contains('foo'));
assert(!element.classList.contains(''));
});
test('removeClass', () => {
let element = document.createElement('div');
element.className = 'foobar boo far';
element.classList.remove('boo');
assert(element.classList.contains('far'));
assert(!element.classList.contains('boo'));
assert(element.classList.contains('foobar'));
assert.strictEqual(element.className, 'foobar far');
element = document.createElement('div');
element.className = 'foobar boo far';
element.classList.remove('far');
assert(!element.classList.contains('far'));
assert(element.classList.contains('boo'));
assert(element.classList.contains('foobar'));
assert.strictEqual(element.className, 'foobar boo');
element.classList.remove('boo');
assert(!element.classList.contains('far'));
assert(!element.classList.contains('boo'));
assert(element.classList.contains('foobar'));
assert.strictEqual(element.className, 'foobar');
element.classList.remove('foobar');
assert(!element.classList.contains('far'));
assert(!element.classList.contains('boo'));
assert(!element.classList.contains('foobar'));
assert.strictEqual(element.className, '');
});
test('removeClass should consider hyphens', function () {
const element = document.createElement('div');
element.classList.add('foo-bar');
element.classList.add('bar');
assert(element.classList.contains('foo-bar'));
assert(element.classList.contains('bar'));
element.classList.remove('bar');
assert(element.classList.contains('foo-bar'));
assert(!element.classList.contains('bar'));
element.classList.remove('foo-bar');
assert(!element.classList.contains('foo-bar'));
assert(!element.classList.contains('bar'));
});
test('multibyteAwareBtoa', () => {
assert.ok(dom.multibyteAwareBtoa('hello world').length > 0);
assert.ok(dom.multibyteAwareBtoa('平仮名').length > 0);
assert.ok(dom.multibyteAwareBtoa(new Array(100000).fill('vs').join('')).length > 0); // https://github.com/microsoft/vscode/issues/112013
});
suite('$', () => {
test('should build simple nodes', () => {
const div = $('div');
assert(div);
assert(div instanceof HTMLElement);
assert.strictEqual(div.tagName, 'DIV');
assert(!div.firstChild);
});
test('should buld nodes with id', () => {
const div = $('div#foo');
assert(div);
assert(div instanceof HTMLElement);
assert.strictEqual(div.tagName, 'DIV');
assert.strictEqual(div.id, 'foo');
});
test('should buld nodes with class-name', () => {
const div = $('div.foo');
assert(div);
assert(div instanceof HTMLElement);
assert.strictEqual(div.tagName, 'DIV');
assert.strictEqual(div.className, 'foo');
});
test('should build nodes with attributes', () => {
let div = $('div', { class: 'test' });
assert.strictEqual(div.className, 'test');
div = $('div', undefined);
assert.strictEqual(div.className, '');
});
test('should build nodes with children', () => {
let div = $('div', undefined, $('span', { id: 'demospan' }));
const firstChild = div.firstChild as HTMLElement;
assert.strictEqual(firstChild.tagName, 'SPAN');
assert.strictEqual(firstChild.id, 'demospan');
div = $('div', undefined, 'hello');
assert.strictEqual(div.firstChild && div.firstChild.textContent, 'hello');
});
test('should build nodes with text children', () => {
const div = $('div', undefined, 'foobar');
const firstChild = div.firstChild as HTMLElement;
assert.strictEqual(firstChild.tagName, undefined);
assert.strictEqual(firstChild.textContent, 'foobar');
});
});
});
|