aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/testsuite.js
blob: 23819d0e43bd06ddf8a4f9d55a062f14945e02cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
(function() {

function testWidgetDefaults( widget, defaults ) {
	var pluginDefaults = $.ui[ widget ].prototype.options;

	// ensure that all defaults have the correct value
	test( "defined defaults", function() {
		$.each( defaults, function( key, val ) {
			if ( $.isFunction( val ) ) {
				ok( $.isFunction( pluginDefaults[ key ] ), key );
				return;
			}
			same( pluginDefaults[ key ], val, key );
		});
	});

	// ensure that all defaults were tested
	test( "tested defaults", function() {
		$.each( pluginDefaults, function( key, val ) {
			ok( key in defaults, key );
		});
	});
}

var privateMethods = [
	"_createWidget",
	"_super",
	"_superApply",
	"destroy",
	"option",
	"enable",
	"disable",
	"_trigger"
];

function testWidgetOverrides( widget ) {
	test( "$.widget overrides", function() {
		$.each( privateMethods, function( i, method ) {
			strictEqual( $.ui[ widget ].prototype[ method ],
				$.Widget.prototype[ method ], "should not override " + method );
		});
	});
}

function testBasicUsage( widget ) {
	test( "basic usage", function() {
		var defaultElement = $.ui[ widget ].prototype.defaultElement;
		$( defaultElement ).appendTo( "body" )[ widget ]().remove();
		ok( true, "initialized on element" );

		$( defaultElement ).accordion().remove();
		ok( true, "initialized on disconnected DOMElement - never connected" );

		$( defaultElement ).appendTo( "body" ).remove().accordion().remove();
		ok( true, "initialized on disconnected DOMElement - removed" );
	});
}

window.commonWidgetTests = function( widget, settings ) {
	module( widget + ": common widget" );

	testWidgetDefaults( widget, settings.defaults );
	testWidgetOverrides( widget );
	testBasicUsage( widget );
};

}());