r110717 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r110716‎ | r110717 | r110718 >
Date:12:27, 5 February 2012
Author:krinkle
Status:ok
Tags:
Comment:
[tests] use core qunit-fixture properly
QUnit provides a <div id="qunit-fixture"> by default that is cleared out after each test.

* Switch tests to append to the provided #qunit-fixture instead of appending to the body.
* Remove redundant .remove() calls, which now happens automatically
* Fix jquery.textSelection.test to not cause dozens of elements to be appended to the body with duplicate IDs, which was causing WebFonts test suite to fail (since the DOM can't select multiple elements with the same DOM). (Fixes r92923, r100391)
Modified paths:
  • /trunk/phase3/tests/qunit/suites/resources/jquery/jquery.autoEllipsis.test.js (modified) (history)
  • /trunk/phase3/tests/qunit/suites/resources/jquery/jquery.byteLimit.test.js (modified) (history)
  • /trunk/phase3/tests/qunit/suites/resources/jquery/jquery.delayedBind.test.js (modified) (history)
  • /trunk/phase3/tests/qunit/suites/resources/jquery/jquery.tabIndex.test.js (modified) (history)
  • /trunk/phase3/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js (modified) (history)
  • /trunk/phase3/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js (modified) (history)
  • /trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js (modified) (history)

Diff [purge]

Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.textSelection.test.js
@@ -36,16 +36,14 @@
3737
3838 test( opt.description, function() {
3939 var tests = 1;
40 - if (opt.after.selected !== null) {
 40+ if ( opt.after.selected !== null ) {
4141 tests++;
4242 }
43 - expect(tests);
 43+ expect( tests );
4444
45 - var $fixture = $( '<div id="qunit-fixture"></div>' );
4645 var $textarea = $( '<textarea>' );
4746
48 - $fixture.append($textarea);
49 - $( 'body' ).append($fixture);
 47+ $( '#qunit-fixture' ).append( $textarea );
5048
5149 //$textarea.textSelection( 'setContents', opt.before.text); // this method is actually missing atm...
5250 $textarea.val( opt.before.text ); // won't work with the WikiEditor iframe?
@@ -228,11 +226,9 @@
229227 test(options.description, function() {
230228 expect(2);
231229
232 - var $fixture = $( '<div id="qunit-fixture"></div>' );
233230 var $textarea = $( '<textarea>' ).text(options.text);
234231
235 - $fixture.append($textarea);
236 - $( 'body' ).append($fixture);
 232+ $( '#qunit-fixture' ).append( $textarea );
237233
238234 if (options.mode == 'set') {
239235 $textarea.textSelection('setSelection', {
Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.autoEllipsis.test.js
@@ -6,8 +6,8 @@
77 });
88
99 function createWrappedDiv( text, width ) {
10 - var $wrapper = $( '<div />' ).css( 'width', width );
11 - var $div = $( '<div />' ).text( text );
 10+ var $wrapper = $( '<div>' ).css( 'width', width );
 11+ var $div = $( '<div>' ).text( text );
1212 $wrapper.append( $div );
1313 return $wrapper;
1414 }
@@ -26,7 +26,7 @@
2727 // We need this thing to be visible, so append it to the DOM
2828 var origText = 'This is a really long random string and there is no way it fits in 100 pixels.';
2929 var $wrapper = createWrappedDiv( origText, '100px' );
30 - $( 'body' ).append( $wrapper );
 30+ $( '#qunit-fixture' ).append( $wrapper );
3131 $wrapper.autoEllipsis( { position: 'right' } );
3232
3333 // Verify that, and only one, span element was created
@@ -47,12 +47,9 @@
4848 // Put this text in the span and verify it doesn't fit
4949 $span.text( spanTextNew );
5050 // In IE6 width works like min-width, allow IE6's width to be "equal to"
51 - if ( $.browser.msie && Number( $.browser.version ) == 6 ) {
 51+ if ( $.browser.msie && Number( $.browser.version ) === 6 ) {
5252 gtOrEq( $span.width(), $span.parent().width(), 'Fit is maximal (adding two characters makes it not fit any more) - IE6: Maybe equal to as well due to width behaving like min-width in IE6' );
5353 } else {
5454 gt( $span.width(), $span.parent().width(), 'Fit is maximal (adding two characters makes it not fit any more)' );
5555 }
56 -
57 - // Clean up
58 - $wrapper.remove();
5956 });
Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.tabIndex.test.js
@@ -18,14 +18,11 @@
1919 '<textarea tabindex="5">Foobar</textarea>' +
2020 '</form>';
2121
22 - var $testA = $( '<div>' ).html( testEnvironment ).appendTo( 'body' );
 22+ var $testA = $( '<div>' ).html( testEnvironment ).appendTo( '#qunit-fixture' );
2323 strictEqual( $testA.firstTabIndex(), 2, 'First tabindex should be 2 within this context.' );
2424
2525 var $testB = $( '<div>' );
2626 strictEqual( $testB.firstTabIndex(), null, 'Return null if none available.' );
27 -
28 - // Clean up
29 - $testA.add( $testB ).remove();
3027 });
3128
3229 test( 'lastTabIndex', function() {
@@ -39,12 +36,9 @@
4037 '<textarea tabindex="5">Foobar</textarea>' +
4138 '</form>';
4239
43 - var $testA = $( '<div>' ).html( testEnvironment ).appendTo( 'body' );
 40+ var $testA = $( '<div>' ).html( testEnvironment ).appendTo( '#qunit-fixture' );
4441 strictEqual( $testA.lastTabIndex(), 9, 'Last tabindex should be 9 within this context.' );
4542
4643 var $testB = $( '<div>' );
4744 strictEqual( $testB.lastTabIndex(), null, 'Return null if none available.' );
48 -
49 - // Clean up
50 - $testA.add( $testB ).remove();
5145 });
Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.byteLimit.test.js
@@ -46,7 +46,7 @@
4747
4848 test( opt.description, function() {
4949
50 - opt.$input.appendTo( 'body' );
 50+ opt.$input.appendTo( '#qunit-fixture' );
5151
5252 // Simulate pressing keys for each of the sample characters
5353 $.addChars( opt.$input, opt.sample );
@@ -66,8 +66,6 @@
6767 equal( newVal, opt.expected, 'New value matches the expected string' );
6868 equal( $.byteLength( newVal ), $.byteLength( opt.expected ), 'Unlimited scenarios are not affected, expected length reached' );
6969 }
70 -
71 - opt.$input.remove();
7270 } );
7371 };
7472
Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.delayedBind.test.js
@@ -1,5 +1,5 @@
22 test('jquery.delayedBind with data option', function() {
3 - var $fixture = $('<div>').appendTo('body'),
 3+ var $fixture = $('<div>').appendTo('#qunit-fixture'),
44 data = { magic: "beeswax" },
55 delay = 50;
66
@@ -20,7 +20,7 @@
2121 });
2222
2323 test('jquery.delayedBind without data option', function() {
24 - var $fixture = $('<div>').appendTo('body'),
 24+ var $fixture = $('<div>').appendTo('#qunit-fixture'),
2525 data = { magic: "beeswax" },
2626 delay = 50;
2727
Index: trunk/phase3/tests/qunit/suites/resources/jquery/jquery.tablesorter.test.js
@@ -79,7 +79,6 @@
8080 expect(1);
8181
8282 var $table = tableCreate( header, data );
83 - //$( 'body' ).append($table);
8483
8584 // Give caller a chance to set up sorting and manipulate the table.
8685 callback( $table );
Index: trunk/phase3/tests/qunit/suites/resources/mediawiki/mediawiki.util.test.js
@@ -52,7 +52,7 @@
5353 test( 'addCSS', function() {
5454 expect(3);
5555
56 - var $testEl = $( '<div>' ).attr( 'id', 'mw-addcsstest' ).appendTo( 'body' );
 56+ var $testEl = $( '<div>' ).attr( 'id', 'mw-addcsstest' ).appendTo( '#qunit-fixture' );
5757
5858 var style = mw.util.addCSS( '#mw-addcsstest { visibility: hidden; }' );
5959 equal( typeof style, 'object', 'addCSS returned an object' );
@@ -61,9 +61,7 @@
6262 equal( $testEl.css( 'visibility' ), 'hidden', 'Added style properties are in effect' );
6363
6464 // Clean up
65 - $( style.ownerNode )
66 - .add( $testEl )
67 - .remove();
 65+ $( style.ownerNode ).remove();
6866 });
6967
7068 test( 'toggleToc', function() {
@@ -79,7 +77,7 @@
8078 '</div>' +
8179 '<ul><li></li></ul>' +
8280 '</td></tr></table>',
83 - $toc = $(tocHtml).appendTo( 'body' ),
 81+ $toc = $(tocHtml).appendTo( '#qunit-fixture' ),
8482 $toggleLink = $( '#togglelink' );
8583
8684 strictEqual( $toggleLink.length, 1, 'Toggle link is appended to the page.' );
@@ -90,9 +88,6 @@
9189
9290 var actionC = function() {
9391 start();
94 -
95 - // Clean up
96 - $toc.remove();
9792 };
9893 var actionB = function() {
9994 start(); stop();
@@ -158,8 +153,8 @@
159154 <h5>Views</h5>\
160155 <ul></ul>\
161156 </div>',
162 - $mwPanel = $(mwPanel).appendTo( 'body' ),
163 - $vectorTabs = $(vectorTabs).appendTo( 'body' );
 157+ $mwPanel = $(mwPanel).appendTo( '#qunit-fixture' ),
 158+ $vectorTabs = $(vectorTabs).appendTo( '#qunit-fixture' );
164159
165160 var tbRL = mw.util.addPortletLink( 'p-test-tb', '//mediawiki.org/wiki/ResourceLoader',
166161 'ResourceLoader', 't-rl', 'More info about ResourceLoader on MediaWiki.org ', 'l' );
@@ -186,10 +181,7 @@
187182 strictEqual( $( caFoo ).find( 'span').length, 1, 'A <span> element should be added for porlets with vectorTabs class.' );
188183
189184 // Clean up
190 - $( [tbRL, tbMW, tbRLDM, caFoo] )
191 - .add( $mwPanel )
192 - .add( $vectorTabs )
193 - .remove();
 185+ $( [tbRL, tbMW, tbRLDM, caFoo] ).remove();
194186 });
195187
196188 test( 'jsMessage', function() {

Sign-offs

UserFlagDate
Santhosh.thottingalinspected04:27, 6 February 2012
Santhosh.thottingaltested04:27, 6 February 2012

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r92923Followup r86622: add initial QUnit test cases for jquery.textSelection module....brion00:44, 23 July 2011
r100391QUnit test cases for bug 31847: will trigger a fail on IE 6/7/8...brion22:50, 20 October 2011

Status & tagging log