* Tests: avoid creating real editors (fix #115230) * tests - bring back file editor input factory test * tests cleanup * more cleanup
133 lines
4.3 KiB
TypeScript
133 lines
4.3 KiB
TypeScript
/*---------------------------------------------------------------------------------------------
|
|
* 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', () => {
|
|
|
|
let 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 () {
|
|
let 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' }));
|
|
let 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', () => {
|
|
let div = $('div', undefined, 'foobar');
|
|
let firstChild = div.firstChild as HTMLElement;
|
|
assert.strictEqual(firstChild.tagName, undefined);
|
|
assert.strictEqual(firstChild.textContent, 'foobar');
|
|
});
|
|
});
|
|
});
|