mirror of https://github.com/go-gitea/gitea
Git with a cup of tea, painless self-hosted git service
Mirror for internal git.with.parts use
https://git.with.parts
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
1.2 KiB
27 lines
1.2 KiB
import {createElementFromAttrs, createElementFromHTML, querySingleVisibleElem} from './dom.ts';
|
|
|
|
test('createElementFromHTML', () => {
|
|
expect(createElementFromHTML('<a>foo<span>bar</span></a>').outerHTML).toEqual('<a>foo<span>bar</span></a>');
|
|
});
|
|
|
|
test('createElementFromAttrs', () => {
|
|
const el = createElementFromAttrs('button', {
|
|
id: 'the-id',
|
|
class: 'cls-1 cls-2',
|
|
disabled: true,
|
|
checked: false,
|
|
required: null,
|
|
tabindex: 0,
|
|
'data-foo': 'the-data',
|
|
}, 'txt', createElementFromHTML('<span>inner</span>'));
|
|
expect(el.outerHTML).toEqual('<button id="the-id" class="cls-1 cls-2" disabled="" tabindex="0" data-foo="the-data">txt<span>inner</span></button>');
|
|
});
|
|
|
|
test('querySingleVisibleElem', () => {
|
|
let el = createElementFromHTML('<div><span>foo</span></div>');
|
|
expect(querySingleVisibleElem(el, 'span').textContent).toEqual('foo');
|
|
el = createElementFromHTML('<div><span style="display: none;">foo</span><span>bar</span></div>');
|
|
expect(querySingleVisibleElem(el, 'span').textContent).toEqual('bar');
|
|
el = createElementFromHTML('<div><span>foo</span><span>bar</span></div>');
|
|
expect(() => querySingleVisibleElem(el, 'span')).toThrowError('Expected exactly one visible element');
|
|
});
|
|
|