2009-09-15 21:20:51 +00:00
|
|
|
// FIXME remove this once updated to jQuery core 1.3.3
|
|
|
|
var hasDuplicate = false;
|
2009-02-02 06:46:56 +00:00
|
|
|
|
|
|
|
function testWidgetDefaults(widget, defaults) {
|
2009-04-17 21:28:37 +00:00
|
|
|
var pluginDefaults = $.extend({},
|
|
|
|
$.widget.defaults,
|
|
|
|
$.ui[widget].defaults
|
|
|
|
);
|
|
|
|
|
|
|
|
// ensure that all defualts have the correct value
|
|
|
|
test('defined defaults', function() {
|
|
|
|
$.each(defaults, function(key, val) {
|
2009-09-15 08:26:59 +00:00
|
|
|
if ($.isFunction(val)) {
|
|
|
|
ok(val !== undefined);
|
|
|
|
return;
|
|
|
|
}
|
2009-04-17 21:28:37 +00:00
|
|
|
same(pluginDefaults[key], val, key);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// ensure that all defaults were tested
|
|
|
|
test('tested defaults', function() {
|
2009-09-15 08:26:59 +00:00
|
|
|
$.each(pluginDefaults, function(key, val) {
|
2009-04-17 21:28:37 +00:00
|
|
|
ok(key in defaults, key);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// defaults after init
|
|
|
|
test('defaults on init', function() {
|
|
|
|
var el = $('<div/>')[widget](),
|
|
|
|
instance = el.data(widget);
|
|
|
|
|
|
|
|
$.each(defaults, function(key, val) {
|
2009-09-15 08:26:59 +00:00
|
|
|
if ($.isFunction(val)) {
|
|
|
|
ok(val !== undefined);
|
|
|
|
return;
|
|
|
|
}
|
2009-04-17 21:28:37 +00:00
|
|
|
same(instance.options[key], val, key);
|
|
|
|
});
|
|
|
|
el.remove();
|
|
|
|
});
|
2009-02-02 06:46:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testSettingOptions(widget, options) {
|
2009-04-17 21:28:37 +00:00
|
|
|
test('option values', function() {
|
|
|
|
var el = $('<div/>')[widget](),
|
|
|
|
instance = el.data(widget);
|
|
|
|
|
|
|
|
$.each(options, function(i, option) {
|
|
|
|
$.each({
|
|
|
|
'null': null,
|
|
|
|
'false': false,
|
|
|
|
'true': true,
|
|
|
|
zero: 0,
|
|
|
|
number: 1,
|
|
|
|
'empty string': '',
|
|
|
|
string: 'string',
|
|
|
|
'empty array': [],
|
|
|
|
array: ['array'],
|
|
|
|
'empty object': {},
|
|
|
|
object: {obj: 'ect'},
|
|
|
|
date: new Date(),
|
|
|
|
regexp: /regexp/,
|
|
|
|
'function': function() {}
|
|
|
|
}, function(type, val) {
|
|
|
|
el[widget]('option', option, val);
|
|
|
|
same(instance.options[option], val, option + ': ' + type);
|
|
|
|
});
|
|
|
|
});
|
2009-09-17 14:55:35 +00:00
|
|
|
|
|
|
|
el.remove();
|
2009-04-17 21:28:37 +00:00
|
|
|
});
|
2009-02-02 06:46:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testWidgetOverrides(widget) {
|
2009-04-17 21:28:37 +00:00
|
|
|
test('$.widget overrides', function() {
|
|
|
|
$.each(['option', '_getData', '_trigger'], function(i, method) {
|
|
|
|
ok($.widget.prototype[method] == $.ui[widget].prototype[method],
|
|
|
|
'should not override ' + method);
|
|
|
|
});
|
|
|
|
});
|
2009-02-02 06:46:56 +00:00
|
|
|
}
|
|
|
|
function commonWidgetTests(widget, settings) {
|
2009-04-17 21:28:37 +00:00
|
|
|
var options = [];
|
|
|
|
$.each(settings.defaults, function(option) {
|
|
|
|
options.push(option);
|
|
|
|
});
|
|
|
|
|
2009-02-02 06:46:56 +00:00
|
|
|
module(widget + ": common widget");
|
|
|
|
|
2009-04-17 21:28:37 +00:00
|
|
|
testWidgetDefaults(widget, settings.defaults);
|
|
|
|
testSettingOptions(widget, options);
|
|
|
|
testWidgetOverrides(widget);
|
2009-02-02 06:46:56 +00:00
|
|
|
}
|
2009-09-11 18:22:52 +00:00
|
|
|
|
|
|
|
// load testswarm agent
|
|
|
|
(function() {
|
|
|
|
var url = window.location.search;
|
|
|
|
url = decodeURIComponent( url.slice( url.indexOf("swarmURL=") + 9 ) );
|
|
|
|
if ( !url || url.indexOf("http") !== 0 ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
document.write("<scr" + "ipt src='http://testswarm.com/js/inject.js?" + (new Date).getTime() + "'></scr" + "ipt>");
|
|
|
|
})();
|