r81126 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r81125‎ | r81126 | r81127 >
Date:12:13, 28 January 2011
Author:hashar
Status:resolved (Comments)
Tags:
Comment:
JS tests: fold headers, adapt style

Update the style by removing padding inherited from .wikitable and make
the font smaller (0.8em). Make easier to see the tests on a small screen.

I have folded out the tests by section (using headers as reference), added
some classes and id around to help selection.

TODO: we probably only want to hide tests which are OK
Modified paths:
  • /trunk/phase3/resources/mediawiki.util/mediawiki.util.test.js (modified) (history)

Diff [purge]

Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.test.js
@@ -12,7 +12,12 @@
1313
1414 /* Variables */
1515 '$table' : null,
 16+ // contains either a header or a test
 17+ // test: [ code, result, contain ] see addTest
 18+ // header: [ 'HEADER', escapedtitle, id ] see addHead
1619 'addedTests' : [],
 20+ 'headResults' : [],
 21+ 'numberOfHeader' : 0,
1722
1823 /* Functions */
1924
@@ -29,7 +34,8 @@
3035 contain = result;
3136 }
3237 this.addedTests.push( [code, result, contain] );
33 - this.$table.append( '<tr><td>' + mw.html.escape( code ).replace( / /g, '&nbsp;&nbsp;' )
 38+ this.$table.append( '<tr class="mw-mwutiltest-test">'
 39+ + '<td>' + mw.html.escape( code ).replace( / /g, '&nbsp;&nbsp;' )
3440 + '</td><td>' + mw.html.escape( result ).replace( / /g, '&nbsp;&nbsp;' )
3541 + '</td><td></td><td>?</td></tr>' );
3642 return true;
@@ -44,7 +50,9 @@
4551 if ( !title ) {
4652 return false;
4753 }
48 - this.$table.append( '<tr><th colspan="4">' + mw.html.escape( title ).replace( / /g, '&nbsp;&nbsp;' ) + '</th></tr>' );
 54+ escapedtitle = mw.html.escape( title ).replace( / /g, '&nbsp;&nbsp;' );
 55+ this.addedTests.push( [ 'HEADER', escapedtitle, mw.test.numberOfHeader++ ] );
 56+ this.$table.append( '<tr class="mw-mwutiltest-head" id="mw-mwutiltest-head'+mw.test.numberOfHeader+'"><th colspan="4">' + escapedtitle + '</th></tr>' );
4957 return true;
5058 },
5159
@@ -75,10 +83,14 @@
7684 '<p>Below is a list of tests to confirm proper functionality of the mediaWiki JavaScript library</p>'
7785 + '<p>' + skinLinksText + '</p>'
7886 + '<hr />'
79 - + '<table id="mw-mwutiltest-table" class="wikitable sortable" style="white-space:break; font-family:monospace,\'Courier New\'">'
 87+ + '<table id="mw-mwutiltest-table" class="wikitable sortable" style="white-space:break; font-family:monospace,\'Courier New\';font-size:0.8em; width:100%;">'
8088 + '<tr><th>Exec</th><th>Should return</th><th>Does return</th><th>Equal ?</th></tr>'
8189 + '</table>'
8290 );
 91+
 92+ // Override wikitable padding for <td>
 93+ $('head').append('<style>#mw-mwutiltest-table tr td {padding:0 !important;}</style>');
 94+
8395 mw.test.$table = $( 'table#mw-mwutiltest-table' );
8496
8597 /* Populate tests */
@@ -299,6 +311,10 @@
300312 mw.test.addTest( 'typeof $.fn.makeCollapsible',
301313 'function (string)' );
302314
 315+
 316+ // End of tests.
 317+ mw.test.addHead( '*** End of tests ***' );
 318+
303319 // Run tests and compare results
304320 var exec,
305321 result,
@@ -307,30 +323,63 @@
308324 numberofpasseds = 0,
309325 numberofpartials = 0,
310326 numberoferrors = 0,
 327+ headnumberoftests = 0,
 328+ headnumberofpasseds = 0,
 329+ headnumberofpartials = 0,
 330+ headnumberoferrors = 0,
 331+ numberofheaders = 0,
311332 $testrows = mw.test.$table.find( 'tr:has(td)' );
312333
313334 $.each( mw.test.addedTests, function( i ) {
314 - numberoftests++;
315335
 336+ // New header
 337+ if( mw.test.addedTests[i][0] == 'HEADER' ) {
 338+ headertitle = mw.test.addedTests[i][1];
 339+
 340+ // update current header with its tests results
 341+ mw.test.$table.find( 'tr#mw-mwutiltest-head'+numberofheaders+' > th' )
 342+ .text( headertitle + ' ('
 343+ + 'T: ' + headnumberoftests
 344+ + ' ok: ' + headnumberofpasseds
 345+ + ' partial: ' + headnumberofpartials
 346+ + ' err: ' + headnumberoferrors
 347+ + ')' );
 348+
 349+ numberofheaders++;
 350+ // Reset values for the new header;
 351+ headnumberoftests = 0;
 352+ headnumberofpasseds = 0;
 353+ headnumberofpartials = 0;
 354+ headnumberoferrors = 0;
 355+
 356+ return true;
 357+ }
 358+
316359 exec = mw.test.addedTests[i][0];
317360 shouldreturn = mw.test.addedTests[i][1];
318361 shouldcontain = mw.test.addedTests[i][2];
 362+
 363+ numberoftests++;
 364+ headnumberoftests++;
319365 doesreturn = eval( exec );
320366 doesreturn = doesreturn + ' (' + typeof doesreturn + ')';
321 - $thisrow = $testrows.eq( i );
 367+ $thisrow = $testrows.eq( i - numberofheaders ); // since headers are rows as well
322368 $thisrow.find( '> td' ).eq(2).html( mw.html.escape( doesreturn ).replace(/ /g, '&nbsp;&nbsp;' ) );
323369
324370 if ( doesreturn.indexOf( shouldcontain ) !== -1 ) {
325371 if ( doesreturn == shouldreturn ) {
326372 $thisrow.find( '> td' ).eq(3).css( 'background', '#AFA' ).text( 'OK' );
327373 numberofpasseds++;
 374+ headnumberofpasseds++;
328375 } else {
329376 $thisrow.find( '> td' ).eq(3).css( 'background', '#FFA' ).html( '<small>PARTIALLY</small>' );
330377 numberofpartials++;
 378+ headnumberofpartials++;
331379 }
332380 } else {
333381 $thisrow.find( '> td' ).eq(3).css( 'background', '#FAA' ).text( 'ERROR' );
334382 numberoferrors++;
 383+ headnumberoferrors++;
335384 }
336385
337386 } );
@@ -338,6 +387,12 @@
339388 numberofpasseds + ' passed test(s). ' + numberoferrors + ' error(s). ' +
340389 numberofpartials + ' partially passed test(s). </p>' );
341390
 391+ // hide all tests. TODO hide only OK?
 392+ mw.test.$table.find( '.mw-mwutiltest-test' ).hide();
 393+ // clickable header to show/hide the tests
 394+ mw.test.$table.find( '.mw-mwutiltest-head' ).click(function() {
 395+ $(this).nextUntil( '.mw-mwutiltest-head' ).toggle();
 396+ });
342397 }
343398 } );
344399 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r81152Made mediaWiki JS test suite table no longer sortable. This functionality bro...krinkle19:32, 28 January 2011
r81154* Adding cursor:pointer when hovering the headers (which hide/show stuff)...krinkle19:38, 28 January 2011

Comments

#Comment by Hashar (talk | contribs)   12:14, 28 January 2011

Note: click on a header to show the tests.

#Comment by Reach Out to the Truth (talk | contribs)   19:21, 28 January 2011

A note on the generated page indicating that would be useful. Right now the only hint that there's more information is the presence of a sortable table header.

And the section headers mess up the sorting, so the table probably needs to be unsortable.

#Comment by Krinkle (talk | contribs)   19:29, 28 January 2011

The headings are overwritten and the first one is removed. (arrays start at 0, first count is 1, +1 difference)

#Comment by Krinkle (talk | contribs)   19:29, 28 January 2011

Fixed in r81151.

Status & tagging log