/* Variables */
'$table' : null,
+ // contains either a header or a test
+ // test: [ code, result, contain ] see addTest
+ // header: [ 'HEADER', escapedtitle, id ] see addHead
'addedTests' : [],
+ 'headResults' : [],
+ 'numberOfHeader' : 0,
/* Functions */
contain = result;
}
this.addedTests.push( [code, result, contain] );
- this.$table.append( '<tr><td>' + mw.html.escape( code ).replace( / /g, ' ' )
+ this.$table.append( '<tr class="mw-mwutiltest-test">'
+ + '<td>' + mw.html.escape( code ).replace( / /g, ' ' )
+ '</td><td>' + mw.html.escape( result ).replace( / /g, ' ' )
+ '</td><td></td><td>?</td></tr>' );
return true;
if ( !title ) {
return false;
}
- this.$table.append( '<tr><th colspan="4">' + mw.html.escape( title ).replace( / /g, ' ' ) + '</th></tr>' );
+ escapedtitle = mw.html.escape( title ).replace( / /g, ' ' );
+ this.addedTests.push( [ 'HEADER', escapedtitle, mw.test.numberOfHeader++ ] );
+ this.$table.append( '<tr class="mw-mwutiltest-head" id="mw-mwutiltest-head'+mw.test.numberOfHeader+'"><th colspan="4">' + escapedtitle + '</th></tr>' );
return true;
},
'<p>Below is a list of tests to confirm proper functionality of the mediaWiki JavaScript library</p>'
+ '<p>' + skinLinksText + '</p>'
+ '<hr />'
- + '<table id="mw-mwutiltest-table" class="wikitable sortable" style="white-space:break; font-family:monospace,\'Courier New\'">'
+ + '<table id="mw-mwutiltest-table" class="wikitable sortable" style="white-space:break; font-family:monospace,\'Courier New\';font-size:0.8em; width:100%;">'
+ '<tr><th>Exec</th><th>Should return</th><th>Does return</th><th>Equal ?</th></tr>'
+ '</table>'
);
+
+ // Override wikitable padding for <td>
+ $('head').append('<style>#mw-mwutiltest-table tr td {padding:0 !important;}</style>');
+
mw.test.$table = $( 'table#mw-mwutiltest-table' );
/* Populate tests */
mw.test.addTest( 'typeof $.fn.makeCollapsible',
'function (string)' );
+
+ // End of tests.
+ mw.test.addHead( '*** End of tests ***' );
+
// Run tests and compare results
var exec,
result,
numberofpasseds = 0,
numberofpartials = 0,
numberoferrors = 0,
+ headnumberoftests = 0,
+ headnumberofpasseds = 0,
+ headnumberofpartials = 0,
+ headnumberoferrors = 0,
+ numberofheaders = 0,
$testrows = mw.test.$table.find( 'tr:has(td)' );
$.each( mw.test.addedTests, function( i ) {
- numberoftests++;
+
+ // New header
+ if( mw.test.addedTests[i][0] == 'HEADER' ) {
+ headertitle = mw.test.addedTests[i][1];
+
+ // update current header with its tests results
+ mw.test.$table.find( 'tr#mw-mwutiltest-head'+numberofheaders+' > th' )
+ .text( headertitle + ' ('
+ + 'T: ' + headnumberoftests
+ + ' ok: ' + headnumberofpasseds
+ + ' partial: ' + headnumberofpartials
+ + ' err: ' + headnumberoferrors
+ + ')' );
+
+ numberofheaders++;
+ // Reset values for the new header;
+ headnumberoftests = 0;
+ headnumberofpasseds = 0;
+ headnumberofpartials = 0;
+ headnumberoferrors = 0;
+
+ return true;
+ }
exec = mw.test.addedTests[i][0];
shouldreturn = mw.test.addedTests[i][1];
shouldcontain = mw.test.addedTests[i][2];
+
+ numberoftests++;
+ headnumberoftests++;
doesreturn = eval( exec );
doesreturn = doesreturn + ' (' + typeof doesreturn + ')';
- $thisrow = $testrows.eq( i );
+ $thisrow = $testrows.eq( i - numberofheaders ); // since headers are rows as well
$thisrow.find( '> td' ).eq(2).html( mw.html.escape( doesreturn ).replace(/ /g, ' ' ) );
if ( doesreturn.indexOf( shouldcontain ) !== -1 ) {
if ( doesreturn == shouldreturn ) {
$thisrow.find( '> td' ).eq(3).css( 'background', '#AFA' ).text( 'OK' );
numberofpasseds++;
+ headnumberofpasseds++;
} else {
$thisrow.find( '> td' ).eq(3).css( 'background', '#FFA' ).html( '<small>PARTIALLY</small>' );
numberofpartials++;
+ headnumberofpartials++;
}
} else {
$thisrow.find( '> td' ).eq(3).css( 'background', '#FAA' ).text( 'ERROR' );
numberoferrors++;
+ headnumberoferrors++;
}
} );
numberofpasseds + ' passed test(s). ' + numberoferrors + ' error(s). ' +
numberofpartials + ' partially passed test(s). </p>' );
+ // hide all tests. TODO hide only OK?
+ mw.test.$table.find( '.mw-mwutiltest-test' ).hide();
+ // clickable header to show/hide the tests
+ mw.test.$table.find( '.mw-mwutiltest-head' ).click(function() {
+ $(this).nextUntil( '.mw-mwutiltest-head' ).toggle();
+ });
}
} );
}