Refactored most main.js logic into RecTest

master
Mike Gerwitz 2012-03-03 20:53:23 -05:00
parent 95f0a585f9
commit 38aefd223a
4 changed files with 137 additions and 66 deletions

126
scripts/RecTest.js 100644
View File

@ -0,0 +1,126 @@
/**
* Facade for the entire application
*/
rectest.RecTest = Class( 'RecTest',
{
/**
* jQuery instance
* @var {jQuery}
*/
'private _jQuery': null,
/**
* Supported test cases
* @var {Object}
*/
'private _cases': {},
/**
* Runs test configurations
* @var {TestRunner}
*/
'private _runner': null,
__construct: function( jquery, cases )
{
this._jQuery = jquery;
this._cases = cases;
this._runner = rectest.TestRunner( jquery, rectest.TestRun );
},
'public init': function()
{
// display js-dependent content
this._jQuery( '.hasjs' ).removeClass( 'hasjs' );
return this;
},
'public listCases': function( $select )
{
for ( var preset in this._cases )
{
var data = this._cases[ preset ];
$select.append( this._jQuery( '<option>' )
.attr( 'value', preset )
.text( data.title )
);
}
return this;
},
'public displayNotice': function( str )
{
this._jQuery( '.notice' )
.text( str )
.slideDown( 250, function()
{
$( this ).addClass( 'active' );
} );
return this;
},
'public hideNotice': function()
{
$( '.notice' ).slideUp( 250, function()
{
$( this ).removeClass( 'active' );
} );
return this;
},
'bindContinue': function( $element, callback )
{
var _self = this,
$body = this._jQuery( 'body' );
$element.click( function()
{
var options = _self._getOptions(),
testcase = _self._cases[ options['case'] ].testCase();
$body.addClass( 'testing' );
_self._runner.run( testcase, options, function( history )
{
$body.removeClass( 'testing' );
console.log( history );
console.log( 'done' );
} );
callback.call( _self.__inst );
} );
return this;
},
'private _getOptions': function()
{
var options = {},
values = [
'case', 'set', 'interval', 'blank', 'samples', 'delay'
],
i = values.length;
while ( i-- )
{
var id = values[ i ];
options[ id ] = this._jQuery( '#' + id ).val();
}
return options;
}
} );

View File

@ -83,6 +83,7 @@ rectest.TestRunner = Class( 'TestRunner',
// clear history from any previous runs
this._history = [];
this._callback = callback || function() {};
this._$dest.html( '' );
var _self = this,
run = _self._TestRun( test_case, options );

View File

@ -7,71 +7,14 @@ window.rectest = { cases: {} };
$( document ).ready( function()
{
// display js-dependent content
$( '.hasjs' ).removeClass( 'hasjs' );
listCases( rectest.cases, $( '#case' ) );
displayNotice( 'Please configure the test using the form below.' );
$( '#continue' ).click( function()
{
var runner = rectest.TestRunner( jQuery, rectest.TestRun );
var options = {},
values = [
'case', 'set', 'interval', 'blank', 'samples', 'delay'
],
i = values.length;
while ( i-- )
rectest.RecTest( jQuery, rectest.cases ).init()
.listCases( $( '#case' ) )
.displayNotice(
'Please configure the test using the form below.'
)
.bindContinue( $( '#continue' ), function()
{
var id = values[ i ];
options[ id ] = $( '#' + id ).val();
}
var testcase = rectest.cases[ options['case'] ].testCase();
hideNotice();
$( 'body' ).addClass( 'testing' );
runner.run( testcase, options, function( history )
{
$( 'body' ).removeClass( 'testing' );
console.log( history );
console.log( 'done' );
} );
} );
function displayNotice( str )
{
$( '.notice' )
.text( str )
.slideDown( 250, function()
{
$( this ).addClass( 'active' );
} );
}
function hideNotice()
{
$( '.notice' ).slideUp( 250, function()
{
$( this ).removeClass( 'active' );
} );
}
function listCases( presets, $select )
{
for ( var preset in presets )
{
var data = presets[ preset ];
$select.append( $( '<option>' )
.attr( 'value', preset )
.text( data.title )
);
}
}
this.hideNotice();
} )
;
} );

View File

@ -73,5 +73,6 @@
<script type="text/javascript" src="scripts/TestRun.js"></script>
<script type="text/javascript" src="scripts/TestRunner.js"></script>
<script type="text/javascript" src="scripts/ColorTestCase.js"></script>
<script type="text/javascript" src="scripts/RecTest.js"></script>
</body>
</html>