diff options
author | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
---|---|---|
committer | Yaco <franco@reevo.org> | 2020-06-04 11:01:00 -0300 |
commit | fc7369835258467bf97eb64f184b93691f9a9fd5 (patch) | |
tree | daabd60089d2dd76d9f5fb416b005fbe159c799d /www/wiki/tests/qunit/suites/resources/mediawiki/mediawiki.html.test.js |
first commit
Diffstat (limited to 'www/wiki/tests/qunit/suites/resources/mediawiki/mediawiki.html.test.js')
-rw-r--r-- | www/wiki/tests/qunit/suites/resources/mediawiki/mediawiki.html.test.js | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/www/wiki/tests/qunit/suites/resources/mediawiki/mediawiki.html.test.js b/www/wiki/tests/qunit/suites/resources/mediawiki/mediawiki.html.test.js new file mode 100644 index 00000000..16f8cf3b --- /dev/null +++ b/www/wiki/tests/qunit/suites/resources/mediawiki/mediawiki.html.test.js @@ -0,0 +1,105 @@ +( function ( mw ) { + QUnit.module( 'mediawiki.html' ); + + QUnit.test( 'escape', function ( assert ) { + assert.throws( + function () { + mw.html.escape(); + }, + TypeError, + 'throw a TypeError if argument is not a string' + ); + + assert.equal( + mw.html.escape( '<mw awesome="awesome" value=\'test\' />' ), + '<mw awesome="awesome" value='test' />', + 'Escape special characters to html entities' + ); + } ); + + QUnit.test( 'element()', function ( assert ) { + assert.equal( + mw.html.element(), + '<undefined/>', + 'return valid html even without arguments' + ); + } ); + + QUnit.test( 'element( tagName )', function ( assert ) { + assert.equal( mw.html.element( 'div' ), '<div/>', 'DIV' ); + } ); + + QUnit.test( 'element( tagName, attrs )', function ( assert ) { + assert.equal( mw.html.element( 'div', {} ), '<div/>', 'DIV' ); + + assert.equal( + mw.html.element( + 'div', { + id: 'foobar' + } + ), + '<div id="foobar"/>', + 'DIV with attribs' + ); + } ); + + QUnit.test( 'element( tagName, attrs, content )', function ( assert ) { + + assert.equal( mw.html.element( 'div', {}, '' ), '<div></div>', 'DIV with empty attributes and content' ); + + assert.equal( mw.html.element( 'p', {}, 12 ), '<p>12</p>', 'numbers as content cast to strings' ); + + assert.equal( mw.html.element( 'p', { title: 12 }, '' ), '<p title="12"></p>', 'number as attribute value' ); + + assert.equal( + mw.html.element( + 'div', + {}, + new mw.html.Raw( + mw.html.element( 'img', { src: '<' } ) + ) + ), + '<div><img src="<"/></div>', + 'unescaped content with mw.html.Raw' + ); + + assert.equal( + mw.html.element( + 'option', + { + selected: true + }, + 'Foo' + ), + '<option selected="selected">Foo</option>', + 'boolean true attribute value' + ); + + assert.equal( + mw.html.element( + 'option', + { + value: 'foo', + selected: false + }, + 'Foo' + ), + '<option value="foo">Foo</option>', + 'boolean false attribute value' + ); + + assert.equal( + mw.html.element( 'div', null, 'a' ), + '<div>a</div>', + 'Skip attributes with null' ); + + assert.equal( + mw.html.element( 'a', { + href: 'http://mediawiki.org/w/index.php?title=RL&action=history' + }, 'a' ), + '<a href="http://mediawiki.org/w/index.php?title=RL&action=history">a</a>', + 'Andhor tag with attributes and content' + ); + } ); + +}( mediaWiki ) ); |