Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.test.js |
— | — | @@ -83,13 +83,13 @@ |
84 | 84 | '<p>Below is a list of tests to confirm proper functionality of the mediaWiki JavaScript library</p>' |
85 | 85 | + '<p>' + skinLinksText + '</p>' |
86 | 86 | + '<hr />' |
87 | | - + '<table id="mw-mwutiltest-table" class="wikitable sortable" style="white-space:break; font-family:monospace,\'Courier New\';font-size:0.8em; width:100%;">' |
| 87 | + + '<table id="mw-mwutiltest-table" class="wikitable sortable" style="white-space:break; font-family:monospace,\'Courier New\'; width:100%;">' |
88 | 88 | + '<tr><th>Exec</th><th>Should return</th><th>Does return</th><th>Equal ?</th></tr>' |
89 | 89 | + '</table>' |
90 | 90 | ); |
91 | 91 | |
92 | 92 | // Override wikitable padding for <td> |
93 | | - $('head').append('<style>#mw-mwutiltest-table tr td {padding:0 !important;}</style>'); |
| 93 | + mw.util.addCSS( '#mw-mwutiltest-table tr td { padding:0 !important; }' ); |
94 | 94 | |
95 | 95 | mw.test.$table = $( 'table#mw-mwutiltest-table' ); |
96 | 96 | |
— | — | @@ -319,73 +319,75 @@ |
320 | 320 | var exec, |
321 | 321 | result, |
322 | 322 | resulttype, |
323 | | - numberoftests = 0, |
324 | | - numberofpasseds = 0, |
325 | | - numberofpartials = 0, |
326 | | - numberoferrors = 0, |
327 | | - headnumberoftests = 0, |
328 | | - headnumberofpasseds = 0, |
329 | | - headnumberofpartials = 0, |
330 | | - headnumberoferrors = 0, |
331 | | - numberofheaders = 0, |
| 323 | + numberOfTests = 0, |
| 324 | + numberOfPasseds = 0, |
| 325 | + numberOfPartials = 0, |
| 326 | + numberOfErrors = 0, |
| 327 | + headNumberOfTests = 0, |
| 328 | + headNumberOfPasseds = 0, |
| 329 | + headNumberOfPartials = 0, |
| 330 | + headNumberOfErrors = 0, |
| 331 | + numberOfHeaders = 0, |
| 332 | + previousHeadTitle = '', |
332 | 333 | $testrows = mw.test.$table.find( 'tr:has(td)' ); |
333 | 334 | |
334 | | - $.each( mw.test.addedTests, function( i ) { |
| 335 | + $.each( mw.test.addedTests, function( i, item ) { |
335 | 336 | |
336 | 337 | // New header |
337 | | - if( mw.test.addedTests[i][0] == 'HEADER' ) { |
338 | | - headertitle = mw.test.addedTests[i][1]; |
| 338 | + if( item[0] == 'HEADER' ) { |
339 | 339 | |
340 | 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 | | - + ')' ); |
| 341 | + mw.test.$table.find( 'tr#mw-mwutiltest-head' + ( numberOfHeaders ) +' > th' ) |
| 342 | + .html( previousHeadTitle + ' <span style="float:right">(' |
| 343 | + + 'T: ' + headNumberOfTests |
| 344 | + + ' ok: ' + headNumberOfPasseds |
| 345 | + + ' partial: ' + headNumberOfPartials |
| 346 | + + ' err: ' + headNumberOfErrors |
| 347 | + + ')</span>' ); |
348 | 348 | |
349 | | - numberofheaders++; |
| 349 | + numberOfHeaders++; |
350 | 350 | // Reset values for the new header; |
351 | | - headnumberoftests = 0; |
352 | | - headnumberofpasseds = 0; |
353 | | - headnumberofpartials = 0; |
354 | | - headnumberoferrors = 0; |
| 351 | + headNumberOfTests = 0; |
| 352 | + headNumberOfPasseds = 0; |
| 353 | + headNumberOfPartials = 0; |
| 354 | + headNumberOfErrors = 0; |
355 | 355 | |
| 356 | + previousHeadTitle = mw.test.addedTests[i][1]; |
| 357 | + |
356 | 358 | return true; |
357 | 359 | } |
358 | 360 | |
359 | | - exec = mw.test.addedTests[i][0]; |
360 | | - shouldreturn = mw.test.addedTests[i][1]; |
361 | | - shouldcontain = mw.test.addedTests[i][2]; |
| 361 | + exec = item[0]; |
| 362 | + shouldreturn = item[1]; |
| 363 | + shouldcontain = item[2]; |
362 | 364 | |
363 | | - numberoftests++; |
364 | | - headnumberoftests++; |
365 | | - doesreturn = eval( exec ); |
366 | | - doesreturn = doesreturn + ' (' + typeof doesreturn + ')'; |
367 | | - $thisrow = $testrows.eq( i - numberofheaders ); // since headers are rows as well |
368 | | - $thisrow.find( '> td' ).eq(2).html( mw.html.escape( doesreturn ).replace(/ /g, ' ' ) ); |
| 365 | + numberOfTests++; |
| 366 | + headNumberOfTests++; |
| 367 | + doesReturn = eval( exec ); |
| 368 | + doesReturn = doesReturn + ' (' + typeof doesReturn + ')'; |
| 369 | + $thisrow = $testrows.eq( i - numberOfHeaders ); // since headers are rows as well |
| 370 | + $thisrow.find( '> td' ).eq(2).html( mw.html.escape( doesReturn ).replace(/ /g, ' ' ) ); |
369 | 371 | |
370 | | - if ( doesreturn.indexOf( shouldcontain ) !== -1 ) { |
371 | | - if ( doesreturn == shouldreturn ) { |
| 372 | + if ( doesReturn.indexOf( shouldcontain ) !== -1 ) { |
| 373 | + if ( doesReturn == shouldreturn ) { |
372 | 374 | $thisrow.find( '> td' ).eq(3).css( 'background', '#AFA' ).text( 'OK' ); |
373 | | - numberofpasseds++; |
374 | | - headnumberofpasseds++; |
| 375 | + numberOfPasseds++; |
| 376 | + headNumberOfPasseds++; |
375 | 377 | } else { |
376 | 378 | $thisrow.find( '> td' ).eq(3).css( 'background', '#FFA' ).html( '<small>PARTIALLY</small>' ); |
377 | | - numberofpartials++; |
378 | | - headnumberofpartials++; |
| 379 | + numberOfPartials++; |
| 380 | + headNumberOfPartials++; |
379 | 381 | } |
380 | 382 | } else { |
381 | 383 | $thisrow.find( '> td' ).eq(3).css( 'background', '#FAA' ).text( 'ERROR' ); |
382 | | - numberoferrors++; |
383 | | - headnumberoferrors++; |
| 384 | + numberOfErrors++; |
| 385 | + headNumberOfErrors++; |
384 | 386 | } |
385 | 387 | |
386 | 388 | } ); |
387 | | - mw.test.$table.before( '<p><strong>Ran ' + numberoftests + ' tests. ' + |
388 | | - numberofpasseds + ' passed test(s). ' + numberoferrors + ' error(s). ' + |
389 | | - numberofpartials + ' partially passed test(s). </p>' ); |
| 389 | + mw.test.$table.before( '<p><strong>Ran ' + numberOfTests + ' tests. ' + |
| 390 | + numberOfPasseds + ' passed test(s). ' + numberOfErrors + ' error(s). ' + |
| 391 | + numberOfPartials + ' partially passed test(s). </p>' ); |
390 | 392 | |
391 | 393 | // hide all tests. TODO hide only OK? |
392 | 394 | mw.test.$table.find( '.mw-mwutiltest-test' ).hide(); |