Index: trunk/phase3/resources/mediawiki.util/mediawiki.util.test.js |
— | — | @@ -12,7 +12,12 @@ |
13 | 13 | |
14 | 14 | /* Variables */ |
15 | 15 | '$table' : null, |
| 16 | + // contains either a header or a test |
| 17 | + // test: [ code, result, contain ] see addTest |
| 18 | + // header: [ 'HEADER', escapedtitle, id ] see addHead |
16 | 19 | 'addedTests' : [], |
| 20 | + 'headResults' : [], |
| 21 | + 'numberOfHeader' : 0, |
17 | 22 | |
18 | 23 | /* Functions */ |
19 | 24 | |
— | — | @@ -29,7 +34,8 @@ |
30 | 35 | contain = result; |
31 | 36 | } |
32 | 37 | this.addedTests.push( [code, result, contain] ); |
33 | | - this.$table.append( '<tr><td>' + mw.html.escape( code ).replace( / /g, ' ' ) |
| 38 | + this.$table.append( '<tr class="mw-mwutiltest-test">' |
| 39 | + + '<td>' + mw.html.escape( code ).replace( / /g, ' ' ) |
34 | 40 | + '</td><td>' + mw.html.escape( result ).replace( / /g, ' ' ) |
35 | 41 | + '</td><td></td><td>?</td></tr>' ); |
36 | 42 | return true; |
— | — | @@ -44,7 +50,9 @@ |
45 | 51 | if ( !title ) { |
46 | 52 | return false; |
47 | 53 | } |
48 | | - this.$table.append( '<tr><th colspan="4">' + mw.html.escape( title ).replace( / /g, ' ' ) + '</th></tr>' ); |
| 54 | + escapedtitle = mw.html.escape( title ).replace( / /g, ' ' ); |
| 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>' ); |
49 | 57 | return true; |
50 | 58 | }, |
51 | 59 | |
— | — | @@ -75,10 +83,14 @@ |
76 | 84 | '<p>Below is a list of tests to confirm proper functionality of the mediaWiki JavaScript library</p>' |
77 | 85 | + '<p>' + skinLinksText + '</p>' |
78 | 86 | + '<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%;">' |
80 | 88 | + '<tr><th>Exec</th><th>Should return</th><th>Does return</th><th>Equal ?</th></tr>' |
81 | 89 | + '</table>' |
82 | 90 | ); |
| 91 | + |
| 92 | + // Override wikitable padding for <td> |
| 93 | + $('head').append('<style>#mw-mwutiltest-table tr td {padding:0 !important;}</style>'); |
| 94 | + |
83 | 95 | mw.test.$table = $( 'table#mw-mwutiltest-table' ); |
84 | 96 | |
85 | 97 | /* Populate tests */ |
— | — | @@ -299,6 +311,10 @@ |
300 | 312 | mw.test.addTest( 'typeof $.fn.makeCollapsible', |
301 | 313 | 'function (string)' ); |
302 | 314 | |
| 315 | + |
| 316 | + // End of tests. |
| 317 | + mw.test.addHead( '*** End of tests ***' ); |
| 318 | + |
303 | 319 | // Run tests and compare results |
304 | 320 | var exec, |
305 | 321 | result, |
— | — | @@ -307,30 +323,63 @@ |
308 | 324 | numberofpasseds = 0, |
309 | 325 | numberofpartials = 0, |
310 | 326 | numberoferrors = 0, |
| 327 | + headnumberoftests = 0, |
| 328 | + headnumberofpasseds = 0, |
| 329 | + headnumberofpartials = 0, |
| 330 | + headnumberoferrors = 0, |
| 331 | + numberofheaders = 0, |
311 | 332 | $testrows = mw.test.$table.find( 'tr:has(td)' ); |
312 | 333 | |
313 | 334 | $.each( mw.test.addedTests, function( i ) { |
314 | | - numberoftests++; |
315 | 335 | |
| 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 | + |
316 | 359 | exec = mw.test.addedTests[i][0]; |
317 | 360 | shouldreturn = mw.test.addedTests[i][1]; |
318 | 361 | shouldcontain = mw.test.addedTests[i][2]; |
| 362 | + |
| 363 | + numberoftests++; |
| 364 | + headnumberoftests++; |
319 | 365 | doesreturn = eval( exec ); |
320 | 366 | doesreturn = doesreturn + ' (' + typeof doesreturn + ')'; |
321 | | - $thisrow = $testrows.eq( i ); |
| 367 | + $thisrow = $testrows.eq( i - numberofheaders ); // since headers are rows as well |
322 | 368 | $thisrow.find( '> td' ).eq(2).html( mw.html.escape( doesreturn ).replace(/ /g, ' ' ) ); |
323 | 369 | |
324 | 370 | if ( doesreturn.indexOf( shouldcontain ) !== -1 ) { |
325 | 371 | if ( doesreturn == shouldreturn ) { |
326 | 372 | $thisrow.find( '> td' ).eq(3).css( 'background', '#AFA' ).text( 'OK' ); |
327 | 373 | numberofpasseds++; |
| 374 | + headnumberofpasseds++; |
328 | 375 | } else { |
329 | 376 | $thisrow.find( '> td' ).eq(3).css( 'background', '#FFA' ).html( '<small>PARTIALLY</small>' ); |
330 | 377 | numberofpartials++; |
| 378 | + headnumberofpartials++; |
331 | 379 | } |
332 | 380 | } else { |
333 | 381 | $thisrow.find( '> td' ).eq(3).css( 'background', '#FAA' ).text( 'ERROR' ); |
334 | 382 | numberoferrors++; |
| 383 | + headnumberoferrors++; |
335 | 384 | } |
336 | 385 | |
337 | 386 | } ); |
— | — | @@ -338,6 +387,12 @@ |
339 | 388 | numberofpasseds + ' passed test(s). ' + numberoferrors + ' error(s). ' + |
340 | 389 | numberofpartials + ' partially passed test(s). </p>' ); |
341 | 390 | |
| 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 | + }); |
342 | 397 | } |
343 | 398 | } ); |
344 | 399 | } |