Refactored most main.js logic into RecTest
parent
95f0a585f9
commit
38aefd223a
|
@ -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;
|
||||||
|
}
|
||||||
|
} );
|
|
@ -83,6 +83,7 @@ rectest.TestRunner = Class( 'TestRunner',
|
||||||
// clear history from any previous runs
|
// clear history from any previous runs
|
||||||
this._history = [];
|
this._history = [];
|
||||||
this._callback = callback || function() {};
|
this._callback = callback || function() {};
|
||||||
|
this._$dest.html( '' );
|
||||||
|
|
||||||
var _self = this,
|
var _self = this,
|
||||||
run = _self._TestRun( test_case, options );
|
run = _self._TestRun( test_case, options );
|
||||||
|
|
|
@ -7,71 +7,14 @@ window.rectest = { cases: {} };
|
||||||
|
|
||||||
$( document ).ready( function()
|
$( document ).ready( function()
|
||||||
{
|
{
|
||||||
// display js-dependent content
|
rectest.RecTest( jQuery, rectest.cases ).init()
|
||||||
$( '.hasjs' ).removeClass( 'hasjs' );
|
.listCases( $( '#case' ) )
|
||||||
|
.displayNotice(
|
||||||
listCases( rectest.cases, $( '#case' ) );
|
'Please configure the test using the form below.'
|
||||||
|
)
|
||||||
displayNotice( 'Please configure the test using the form below.' );
|
.bindContinue( $( '#continue' ), function()
|
||||||
|
|
||||||
$( '#continue' ).click( function()
|
|
||||||
{
|
{
|
||||||
var runner = rectest.TestRunner( jQuery, rectest.TestRun );
|
this.hideNotice();
|
||||||
|
} )
|
||||||
var options = {},
|
;
|
||||||
values = [
|
|
||||||
'case', 'set', 'interval', 'blank', 'samples', 'delay'
|
|
||||||
],
|
|
||||||
i = values.length;
|
|
||||||
|
|
||||||
while ( i-- )
|
|
||||||
{
|
|
||||||
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 )
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} );
|
} );
|
||||||
|
|
|
@ -73,5 +73,6 @@
|
||||||
<script type="text/javascript" src="scripts/TestRun.js"></script>
|
<script type="text/javascript" src="scripts/TestRun.js"></script>
|
||||||
<script type="text/javascript" src="scripts/TestRunner.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/ColorTestCase.js"></script>
|
||||||
|
<script type="text/javascript" src="scripts/RecTest.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in New Issue