2011-01-25 00:20:09 +00:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2011-01-25 00:20:09 +00:00
|
|
|
same( 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
|
|
|
var privateMethods = [
|
|
|
|
"_createWidget",
|
|
|
|
"destroy",
|
|
|
|
"option",
|
|
|
|
"_trigger"
|
|
|
|
];
|
|
|
|
|
|
|
|
function testWidgetOverrides( widget ) {
|
2011-01-25 05:05:55 +00:00
|
|
|
if ( $.uiBackCompat === false ) {
|
|
|
|
test( "$.widget overrides", function() {
|
|
|
|
$.each( privateMethods, function( i, method ) {
|
|
|
|
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
|
|
|
|
|
|
|
window.commonWidgetTests = function( widget, settings ) {
|
|
|
|
module( widget + ": common widget" );
|
|
|
|
|
|
|
|
testWidgetDefaults( widget, settings.defaults );
|
|
|
|
testWidgetOverrides( widget );
|
|
|
|
testBasicUsage( widget );
|
2011-02-03 17:01:26 +00:00
|
|
|
test( "version", function() {
|
|
|
|
ok( "version" in $.ui[ widget ], "version property exists" );
|
|
|
|
});
|
2011-02-25 10:33:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Experimental assertion for comparing DOM objects.
|
|
|
|
*
|
|
|
|
* Serializes an element and some attributes and it's children if any, otherwise the text.
|
|
|
|
* Then compares the result using deepEqual.
|
|
|
|
*/
|
|
|
|
window.domEqual = function( selector, modifier, message ) {
|
|
|
|
var attributes = ["class", "role", "id", "tabIndex", "aria-activedescendant"];
|
|
|
|
|
|
|
|
function extract(value) {
|
2011-05-02 18:35:18 +00:00
|
|
|
if (!value || !value.length) {
|
|
|
|
QUnit.push( false, actual, expected, "domEqual failed, can't extract " + selector + ", message was: " + message );
|
|
|
|
return;
|
|
|
|
}
|
2011-02-25 10:33:48 +00:00
|
|
|
var result = {};
|
|
|
|
result.nodeName = value[0].nodeName;
|
|
|
|
$.each(attributes, function(index, attr) {
|
|
|
|
result[attr] = value.attr(attr);
|
|
|
|
});
|
|
|
|
result.children = [];
|
|
|
|
var children = value.children();
|
|
|
|
if (children.length) {
|
|
|
|
children.each(function() {
|
|
|
|
result.children.push(extract($(this)));
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
result.text = value.text();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
var expected = extract($(selector));
|
|
|
|
modifier($(selector));
|
|
|
|
|
2011-03-20 14:56:48 +00:00
|
|
|
var actual = extract($(selector));
|
|
|
|
QUnit.push( QUnit.equiv(actual, expected), actual, expected, message );
|
2011-02-25 10:33:48 +00:00
|
|
|
}
|
2011-01-25 00:20:09 +00:00
|
|
|
|
|
|
|
}());
|