Debian Codegraph @

tests/qunit/resources/mediawiki.base/html.test.js

raw symbols SCIP
1 QUnit.module( 'mediawiki.base/html', () => {
2
3 QUnit.test( 'escape', ( assert ) => {
4 assert.throws(
5 () => {
6 mw.html.escape();
7 },
8 TypeError,
9 'throw a TypeError if argument is not a string'
10 );
11
12 assert.strictEqual(
13 mw.html.escape( '<mw awesome="awesome" value=\'test\' />' ),
14 '&lt;mw awesome=&quot;awesome&quot; value=&#039;test&#039; /&gt;',
15 'Escape special characters to html entities'
16 );
17 } );
18
19 QUnit.test( 'element()', ( assert ) => {
20 assert.strictEqual(
21 mw.html.element(),
22 '<undefined/>',
23 'return valid html even without arguments'
24 );
25 } );
26
27 QUnit.test( 'element( tagName )', ( assert ) => {
28 assert.strictEqual( mw.html.element( 'div' ), '<div/>', 'DIV' );
29 } );
30
31 QUnit.test( 'element( tagName, attrs )', ( assert ) => {
32 assert.strictEqual( mw.html.element( 'div', {} ), '<div/>', 'DIV' );
33
34 assert.strictEqual(
35 mw.html.element(
36 'div', {
37 id: 'foobar'
38 }
39 ),
40 '<div id="foobar"/>',
41 'DIV with attribs'
42 );
43 } );
44
45 QUnit.test( 'element( tagName, attrs, content )', ( assert ) => {
46 assert.strictEqual( mw.html.element( 'div', {}, '' ), '<div></div>', 'DIV with empty attributes and content' );
47 assert.strictEqual( mw.html.element( 'p', {}, 12 ), '<p>12</p>', 'numbers as content cast to strings' );
48 assert.strictEqual( mw.html.element( 'p', { title: 12 }, '' ), '<p title="12"></p>', 'number as attribute value' );
49
50 assert.strictEqual(
51 mw.html.element(
52 'div',
53 {},
54 new mw.html.Raw(
55 mw.html.element( 'img', { src: '<' } )
56 )
57 ),
58 '<div><img src="&lt;"/></div>',
59 'unescaped content with mw.html.Raw'
60 );
61
62 assert.strictEqual(
63 mw.html.element(
64 'option',
65 {
66 selected: true
67 },
68 'Foo'
69 ),
70 '<option selected="selected">Foo</option>',
71 'boolean true attribute value'
72 );
73
74 assert.strictEqual(
75 mw.html.element(
76 'option',
77 {
78 value: 'foo',
79 selected: false
80 },
81 'Foo'
82 ),
83 '<option value="foo">Foo</option>',
84 'boolean false attribute value'
85 );
86
87 assert.strictEqual(
88 mw.html.element( 'div', null, 'a' ),
89 '<div>a</div>',
90 'Skip attributes with null' );
91
92 assert.strictEqual(
93 mw.html.element( 'a', {
94 href: 'http://mediawiki.org/w/index.php?title=RL&action=history'
95 }, 'a' ),
96 '<a href="http://mediawiki.org/w/index.php?title=RL&amp;action=history">a</a>',
97 'Andhor tag with attributes and content'
98 );
99 } );
100 } );