2015-08-21 04:13:44 +00:00
|
|
|
define( [
|
2015-04-03 19:21:16 +00:00
|
|
|
"jquery"
|
|
|
|
], function( $ ) {
|
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
|
|
|
function testWidgetDefaults( widget, defaults ) {
|
|
|
|
var pluginDefaults = $.ui[ widget ].prototype.options;
|
|
|
|
|
|
|
|
// Ensure that all defaults have the correct value
|
|
|
|
test( "defined defaults", function() {
|
|
|
|
var count = 0;
|
|
|
|
$.each( defaults, function( key, val ) {
|
|
|
|
expect( ++count );
|
|
|
|
if ( $.isFunction( val ) ) {
|
|
|
|
ok( $.isFunction( pluginDefaults[ key ] ), key );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
deepEqual( pluginDefaults[ key ], val, key );
|
2015-08-21 04:13:44 +00:00
|
|
|
} );
|
|
|
|
} );
|
2015-04-03 19:21:16 +00:00
|
|
|
|
|
|
|
// Ensure that all defaults were tested
|
|
|
|
test( "tested defaults", function() {
|
|
|
|
var count = 0;
|
|
|
|
$.each( pluginDefaults, function( key ) {
|
|
|
|
expect( ++count );
|
|
|
|
ok( key in defaults, key );
|
2015-08-21 04:13:44 +00:00
|
|
|
} );
|
|
|
|
} );
|
2015-04-03 19:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testWidgetOverrides( widget ) {
|
|
|
|
if ( $.uiBackCompat === false ) {
|
|
|
|
test( "$.widget overrides", function() {
|
|
|
|
expect( 4 );
|
2015-08-21 04:13:44 +00:00
|
|
|
$.each( [
|
2015-04-03 19:21:16 +00:00
|
|
|
"_createWidget",
|
|
|
|
"destroy",
|
|
|
|
"option",
|
|
|
|
"_trigger"
|
|
|
|
], function( i, method ) {
|
|
|
|
strictEqual( $.ui[ widget ].prototype[ method ],
|
|
|
|
$.Widget.prototype[ method ], "should not override " + method );
|
2015-08-21 04:13:44 +00:00
|
|
|
} );
|
|
|
|
} );
|
2015-04-03 19:21:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function testBasicUsage( widget ) {
|
|
|
|
test( "basic usage", function() {
|
|
|
|
expect( 3 );
|
|
|
|
|
|
|
|
var defaultElement = $.ui[ widget ].prototype.defaultElement;
|
|
|
|
$( defaultElement ).appendTo( "body" )[ widget ]().remove();
|
|
|
|
ok( true, "initialized on element" );
|
|
|
|
|
|
|
|
$( defaultElement )[ widget ]().remove();
|
|
|
|
ok( true, "initialized on disconnected DOMElement - never connected" );
|
|
|
|
|
|
|
|
// Ensure manipulating removed elements works (#3664)
|
|
|
|
$( defaultElement ).appendTo( "body" ).remove()[ widget ]().remove();
|
|
|
|
ok( true, "initialized on disconnected DOMElement - removed" );
|
2015-08-21 04:13:44 +00:00
|
|
|
} );
|
2015-04-03 19:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.testWidget = function( widget, settings ) {
|
|
|
|
module( widget + ": common widget" );
|
|
|
|
|
2015-07-15 02:22:43 +00:00
|
|
|
exports.testJshint( "/widgets/" + widget );
|
2015-04-03 19:21:16 +00:00
|
|
|
testWidgetDefaults( widget, settings.defaults );
|
|
|
|
testWidgetOverrides( widget );
|
2015-04-21 16:45:02 +00:00
|
|
|
if ( !settings.noDefaultElement ) {
|
|
|
|
testBasicUsage( widget );
|
|
|
|
}
|
2015-04-03 19:21:16 +00:00
|
|
|
test( "version", function() {
|
|
|
|
expect( 1 );
|
|
|
|
ok( "version" in $.ui[ widget ].prototype, "version property exists" );
|
2015-08-21 04:13:44 +00:00
|
|
|
} );
|
2015-04-03 19:21:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
exports.testJshint = function( module ) {
|
|
|
|
|
|
|
|
// Function.prototype.bind check is needed because JSHint doesn't work in ES3 browsers anymore
|
|
|
|
// https://github.com/jshint/jshint/issues/1384
|
|
|
|
if ( QUnit.urlParams.nojshint || !Function.prototype.bind ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
asyncTest( "JSHint", function() {
|
|
|
|
require( [ "jshint" ], function() {
|
|
|
|
expect( 1 );
|
|
|
|
|
|
|
|
$.when(
|
|
|
|
$.ajax( {
|
|
|
|
url: "../../../ui/.jshintrc",
|
|
|
|
dataType: "json"
|
|
|
|
} ),
|
|
|
|
$.ajax( {
|
|
|
|
url: "../../../ui/" + module + ".js",
|
|
|
|
dataType: "text"
|
|
|
|
} )
|
|
|
|
)
|
|
|
|
.done( function( hintArgs, srcArgs ) {
|
|
|
|
var globals, passed, errors,
|
|
|
|
jshintrc = hintArgs[ 0 ],
|
|
|
|
source = srcArgs[ 0 ];
|
|
|
|
|
|
|
|
globals = jshintrc.globals || {};
|
|
|
|
delete jshintrc.globals;
|
|
|
|
passed = JSHINT( source, jshintrc, globals );
|
|
|
|
errors = $.map( JSHINT.errors, function( error ) {
|
|
|
|
|
|
|
|
// JSHINT may report null if there are too many errors
|
|
|
|
if ( !error ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
return "[L" + error.line + ":C" + error.character + "] " +
|
|
|
|
error.reason + "\n" + error.evidence + "\n";
|
|
|
|
} ).join( "\n" );
|
|
|
|
ok( passed, errors );
|
|
|
|
start();
|
|
|
|
} )
|
2015-08-21 04:13:44 +00:00
|
|
|
.fail( function( hintError, srcError ) {
|
2015-04-03 19:21:16 +00:00
|
|
|
ok( false, "error loading source: " + ( hintError || srcError ).statusText );
|
|
|
|
start();
|
|
|
|
} );
|
2015-08-21 04:13:44 +00:00
|
|
|
} );
|
|
|
|
} );
|
2015-04-03 19:21:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
|
2015-08-21 04:13:44 +00:00
|
|
|
} );
|