2012-04-23 12:44:55 +00:00
|
|
|
|
(function( $ ) {
|
2011-01-25 00:20:09 +00:00
|
|
|
|
|
2012-04-19 15:37:33 +00:00
|
|
|
|
window.TestHelpers = {};
|
|
|
|
|
|
2012-04-23 14:43:01 +00:00
|
|
|
|
function includeStyle( url ) {
|
|
|
|
|
document.write( "<link rel='stylesheet' href='../../../" + url + "'>" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function includeScript( url ) {
|
|
|
|
|
document.write( "<script src='../../../" + url + "'></script>" );
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-23 14:47:43 +00:00
|
|
|
|
QUnit.config.urlConfig.push( "min" );
|
2012-04-23 14:43:01 +00:00
|
|
|
|
TestHelpers.loadResources = QUnit.urlParams.min ?
|
|
|
|
|
function() {
|
|
|
|
|
// TODO: proper include with theme images
|
|
|
|
|
includeStyle( "dist/jquery-ui.min.css" );
|
|
|
|
|
includeScript( "dist/jquery-ui.min.js" );
|
|
|
|
|
} :
|
|
|
|
|
function( resources ) {
|
|
|
|
|
$.each( resources.css || [], function( i, resource ) {
|
|
|
|
|
includeStyle( "themes/base/jquery." + resource + ".css" );
|
|
|
|
|
});
|
|
|
|
|
$.each( resources.js || [], function( i, resource ) {
|
|
|
|
|
includeScript( resource );
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2012-04-23 14:47:43 +00:00
|
|
|
|
QUnit.config.urlConfig.push( "nojshint" );
|
2012-04-30 00:22:31 +00:00
|
|
|
|
var jshintLoaded = false;
|
|
|
|
|
TestHelpers.testJshint = function( module ) {
|
2012-04-23 12:44:55 +00:00
|
|
|
|
if ( QUnit.urlParams.nojshint ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-30 00:22:31 +00:00
|
|
|
|
if ( !jshintLoaded ) {
|
|
|
|
|
includeScript( "external/jshint.js" );
|
|
|
|
|
jshintLoaded = true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-23 12:44:55 +00:00
|
|
|
|
asyncTest( "JSHint", function() {
|
|
|
|
|
expect( 1 );
|
|
|
|
|
|
|
|
|
|
$.when(
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: "../../../ui/.jshintrc",
|
|
|
|
|
dataType: "json"
|
|
|
|
|
}),
|
|
|
|
|
$.ajax({
|
2012-04-30 00:22:31 +00:00
|
|
|
|
url: "../../../ui/jquery." + module + ".js",
|
2012-04-23 12:44:55 +00:00
|
|
|
|
dataType: "text"
|
|
|
|
|
})
|
|
|
|
|
).done(function( hintArgs, srcArgs ) {
|
|
|
|
|
var passed = JSHINT( srcArgs[ 0 ], hintArgs[ 0 ] ),
|
|
|
|
|
errors = $.map( JSHINT.errors, function( error ) {
|
2012-04-24 11:43:26 +00:00
|
|
|
|
// JSHINT may report null if there are too many errors
|
|
|
|
|
if ( !error ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-23 12:44:55 +00:00
|
|
|
|
return "[L" + error.line + ":C" + error.character + "] " +
|
|
|
|
|
error.reason + "\n" + error.evidence + "\n";
|
|
|
|
|
}).join( "\n" );
|
|
|
|
|
ok( passed, errors );
|
|
|
|
|
start();
|
|
|
|
|
})
|
|
|
|
|
.fail(function() {
|
|
|
|
|
ok( false, "error loading source" );
|
|
|
|
|
start();
|
|
|
|
|
});
|
|
|
|
|
});
|
2012-04-30 05:19:26 +00:00
|
|
|
|
};
|
2012-04-23 12:44:55 +00:00
|
|
|
|
|
2011-01-25 00:20:09 +00:00
|
|
|
|
function testWidgetDefaults( widget, defaults ) {
|
|
|
|
|
var pluginDefaults = $.ui[ widget ].prototype.options;
|
|
|
|
|
|
2010-01-07 03:19:50 +00:00
|
|
|
|
// ensure that all defaults have the correct value
|
2011-01-25 00:20:09 +00:00
|
|
|
|
test( "defined defaults", function() {
|
|
|
|
|
$.each( defaults, function( key, val ) {
|
|
|
|
|
if ( $.isFunction( val ) ) {
|
|
|
|
|
ok( $.isFunction( pluginDefaults[ key ] ), key );
|
2009-09-15 08:26:59 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2012-02-28 14:56:32 +00:00
|
|
|
|
deepEqual( pluginDefaults[ key ], val, key );
|
2009-04-17 21:28:37 +00:00
|
|
|
|
});
|
|
|
|
|
});
|
2011-01-25 00:20:09 +00:00
|
|
|
|
|
2009-04-17 21:28:37 +00:00
|
|
|
|
// ensure that all defaults were tested
|
2011-01-25 00:20:09 +00:00
|
|
|
|
test( "tested defaults", function() {
|
|
|
|
|
$.each( pluginDefaults, function( key, val ) {
|
|
|
|
|
ok( key in defaults, key );
|
2009-04-17 21:28:37 +00:00
|
|
|
|
});
|
|
|
|
|
});
|
2009-02-02 06:46:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-25 00:20:09 +00:00
|
|
|
|
function testWidgetOverrides( widget ) {
|
2011-01-25 05:05:55 +00:00
|
|
|
|
if ( $.uiBackCompat === false ) {
|
|
|
|
|
test( "$.widget overrides", function() {
|
2012-04-23 14:43:01 +00:00
|
|
|
|
$.each([
|
|
|
|
|
"_createWidget",
|
|
|
|
|
"destroy",
|
|
|
|
|
"option",
|
|
|
|
|
"_trigger"
|
|
|
|
|
], function( i, method ) {
|
2011-01-25 05:05:55 +00:00
|
|
|
|
strictEqual( $.ui[ widget ].prototype[ method ],
|
|
|
|
|
$.Widget.prototype[ method ], "should not override " + method );
|
|
|
|
|
});
|
2009-04-17 21:28:37 +00:00
|
|
|
|
});
|
2011-01-25 05:05:55 +00:00
|
|
|
|
}
|
2009-02-02 06:46:56 +00:00
|
|
|
|
}
|
2010-01-07 03:19:50 +00:00
|
|
|
|
|
2011-01-25 00:20:09 +00:00
|
|
|
|
function testBasicUsage( widget ) {
|
|
|
|
|
test( "basic usage", function() {
|
|
|
|
|
var defaultElement = $.ui[ widget ].prototype.defaultElement;
|
|
|
|
|
$( defaultElement ).appendTo( "body" )[ widget ]().remove();
|
|
|
|
|
ok( true, "initialized on element" );
|
|
|
|
|
|
2011-01-25 03:37:57 +00:00
|
|
|
|
$( defaultElement )[ widget ]().remove();
|
2011-01-25 00:20:09 +00:00
|
|
|
|
ok( true, "initialized on disconnected DOMElement - never connected" );
|
2009-02-02 06:46:56 +00:00
|
|
|
|
|
2011-01-25 03:37:57 +00:00
|
|
|
|
$( defaultElement ).appendTo( "body" ).remove()[ widget ]().remove();
|
2011-01-25 00:20:09 +00:00
|
|
|
|
ok( true, "initialized on disconnected DOMElement - removed" );
|
|
|
|
|
});
|
2009-02-02 06:46:56 +00:00
|
|
|
|
}
|
2011-01-25 00:20:09 +00:00
|
|
|
|
|
2012-04-19 17:03:21 +00:00
|
|
|
|
TestHelpers.commonWidgetTests = function( widget, settings ) {
|
2011-01-25 00:20:09 +00:00
|
|
|
|
module( widget + ": common widget" );
|
|
|
|
|
|
2012-04-30 00:22:31 +00:00
|
|
|
|
TestHelpers.testJshint( "ui." + widget );
|
2011-01-25 00:20:09 +00:00
|
|
|
|
testWidgetDefaults( widget, settings.defaults );
|
|
|
|
|
testWidgetOverrides( widget );
|
|
|
|
|
testBasicUsage( widget );
|
2011-02-03 17:01:26 +00:00
|
|
|
|
test( "version", function() {
|
2011-05-28 19:42:55 +00:00
|
|
|
|
ok( "version" in $.ui[ widget ].prototype, "version property exists" );
|
2011-02-03 17:01:26 +00:00
|
|
|
|
});
|
2012-04-19 02:36:15 +00:00
|
|
|
|
};
|
2011-02-25 10:33:48 +00:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Experimental assertion for comparing DOM objects.
|
2012-02-28 14:56:32 +00:00
|
|
|
|
*
|
2012-05-25 20:51:51 +00:00
|
|
|
|
* Serializes an element and some properties and it's children if any, otherwise the text.
|
2011-02-25 10:33:48 +00:00
|
|
|
|
* Then compares the result using deepEqual.
|
|
|
|
|
*/
|
|
|
|
|
window.domEqual = function( selector, modifier, message ) {
|
2012-04-19 02:36:15 +00:00
|
|
|
|
var expected, actual,
|
2012-05-25 20:51:51 +00:00
|
|
|
|
properties = [
|
|
|
|
|
"autocomplete",
|
|
|
|
|
"aria-activedescendant",
|
|
|
|
|
"aria-controls",
|
|
|
|
|
"aria-describedby",
|
|
|
|
|
"aria-disabled",
|
|
|
|
|
"aria-expanded",
|
|
|
|
|
"aria-haspopup",
|
|
|
|
|
"aria-hidden",
|
|
|
|
|
"aria-labelledby",
|
|
|
|
|
"aria-pressed",
|
|
|
|
|
"aria-selected",
|
|
|
|
|
"aria-valuemax",
|
|
|
|
|
"aria-valuemin",
|
|
|
|
|
"aria-valuenow",
|
|
|
|
|
"class",
|
|
|
|
|
"disabled",
|
|
|
|
|
"href",
|
|
|
|
|
"id",
|
|
|
|
|
"nodeName",
|
|
|
|
|
"readOnly",
|
|
|
|
|
"role",
|
|
|
|
|
"tabIndex",
|
|
|
|
|
"title"
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
function extract( elem ) {
|
|
|
|
|
if ( !elem || !elem.length ) {
|
|
|
|
|
QUnit.push( false, actual, expected,
|
|
|
|
|
"domEqual failed, can't extract " + selector + ", message was: " + message );
|
2011-05-02 18:35:18 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2012-05-25 20:51:51 +00:00
|
|
|
|
|
2012-04-19 02:36:15 +00:00
|
|
|
|
var children,
|
|
|
|
|
result = {};
|
2012-05-25 20:51:51 +00:00
|
|
|
|
$.each( properties, function( index, attr ) {
|
|
|
|
|
result[ attr ] = elem.prop( attr );
|
2011-02-25 10:33:48 +00:00
|
|
|
|
});
|
2012-05-25 20:51:51 +00:00
|
|
|
|
children = elem.children();
|
|
|
|
|
if ( children.length ) {
|
|
|
|
|
result.children = elem.children().map(function( ind ) {
|
|
|
|
|
return extract( $( this ) );
|
2012-05-26 02:57:08 +00:00
|
|
|
|
}).get();
|
2011-02-25 10:33:48 +00:00
|
|
|
|
} else {
|
2012-05-25 20:51:51 +00:00
|
|
|
|
result.text = elem.text();
|
2011-02-25 10:33:48 +00:00
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2012-04-19 02:36:15 +00:00
|
|
|
|
expected = extract( $( selector ) );
|
|
|
|
|
modifier( $( selector ) );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
|
2012-04-19 02:36:15 +00:00
|
|
|
|
actual = extract( $( selector ) );
|
2011-03-20 14:56:48 +00:00
|
|
|
|
QUnit.push( QUnit.equiv(actual, expected), actual, expected, message );
|
2012-04-19 02:36:15 +00:00
|
|
|
|
};
|
2011-01-25 00:20:09 +00:00
|
|
|
|
|
2012-04-23 12:44:55 +00:00
|
|
|
|
}( jQuery ));
|