From 39b0bbc9ca4c5ecb1fb21e494f5c84840b1e2078 Mon Sep 17 00:00:00 2001 From: Richard Worth Date: Mon, 2 Feb 2009 06:46:56 +0000 Subject: [PATCH] unit tests: added common widget tests. Thanks Scott G. --- tests/unit/testsuite.js | 83 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) diff --git a/tests/unit/testsuite.js b/tests/unit/testsuite.js index 2ad60cbab..e1a93ce89 100644 --- a/tests/unit/testsuite.js +++ b/tests/unit/testsuite.js @@ -1,3 +1,4 @@ + $(function() { $('body').prepend( @@ -8,3 +9,85 @@ $('body').prepend( ); }); + +function testWidgetDefaults(widget, defaults) { + 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) { + same(pluginDefaults[key], val, key); + }); + }); + + // ensure that all defaults were tested + test('tested defaults', function() { + $.each(pluginDefaults, function(key) { + ok(key in defaults, key); + }); + }); + + // defaults after init + test('defaults on init', function() { + var el = $('
')[widget](), + instance = el.data(widget); + + $.each(defaults, function(key, val) { + same(instance.options[key], val, key); + }); + el.remove(); + }); +} + +function testSettingOptions(widget, options) { + test('option values', function() { + var el = $('
')[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); + }); + }); + }); +} + +function testWidgetOverrides(widget) { + test('$.widget overrides', function() { + $.each(['option', '_getData', '_trigger'], function(i, method) { + ok($.widget.prototype[method] == $.ui[widget].prototype[method], + 'should not override ' + method); + }); + }); +} +function commonWidgetTests(widget, settings) { + var options = []; + $.each(settings.defaults, function(option) { + options.push(option); + }); + + module(widget + ": common widget"); + + testWidgetDefaults(widget, settings.defaults); +// testSettingOptions(widget, options); + testWidgetOverrides(widget); +} -- 2.39.5