2015-08-21 04:13:44 +00:00
|
|
|
define( [
|
2016-04-06 15:59:16 +00:00
|
|
|
"qunit",
|
2020-05-16 07:16:24 +00:00
|
|
|
"jquery",
|
|
|
|
"lib/helper"
|
|
|
|
], function( QUnit, $, helper ) {
|
2021-06-06 22:58:12 +00:00
|
|
|
"use strict";
|
2015-04-03 19:21:16 +00:00
|
|
|
|
|
|
|
var exports = {};
|
|
|
|
|
|
|
|
function testWidgetDefaults( widget, defaults ) {
|
|
|
|
var pluginDefaults = $.ui[ widget ].prototype.options;
|
|
|
|
|
|
|
|
// Ensure that all defaults have the correct value
|
2016-04-06 15:59:16 +00:00
|
|
|
QUnit.test( "defined defaults", function( assert ) {
|
2015-04-03 19:21:16 +00:00
|
|
|
var count = 0;
|
|
|
|
$.each( defaults, function( key, val ) {
|
2016-04-06 15:59:16 +00:00
|
|
|
assert.expect( ++count );
|
2019-12-08 21:23:08 +00:00
|
|
|
if ( typeof val === "function" ) {
|
|
|
|
assert.ok( typeof pluginDefaults[ key ] === "function", key );
|
2015-04-03 19:21:16 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-04-06 15:59:16 +00:00
|
|
|
assert.deepEqual( pluginDefaults[ key ], val, key );
|
2015-08-21 04:13:44 +00:00
|
|
|
} );
|
|
|
|
} );
|
2015-04-03 19:21:16 +00:00
|
|
|
|
|
|
|
// Ensure that all defaults were tested
|
2016-04-06 15:59:16 +00:00
|
|
|
QUnit.test( "tested defaults", function( assert ) {
|
2015-04-03 19:21:16 +00:00
|
|
|
var count = 0;
|
|
|
|
$.each( pluginDefaults, function( key ) {
|
2016-04-06 15:59:16 +00:00
|
|
|
assert.expect( ++count );
|
|
|
|
assert.ok( key in defaults, key );
|
2015-08-21 04:13:44 +00:00
|
|
|
} );
|
|
|
|
} );
|
2015-04-03 19:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function testWidgetOverrides( widget ) {
|
|
|
|
if ( $.uiBackCompat === false ) {
|
2016-04-06 15:59:16 +00:00
|
|
|
QUnit.test( "$.widget overrides", function( assert ) {
|
|
|
|
assert.expect( 4 );
|
2015-08-21 04:13:44 +00:00
|
|
|
$.each( [
|
2015-04-03 19:21:16 +00:00
|
|
|
"_createWidget",
|
|
|
|
"destroy",
|
|
|
|
"option",
|
|
|
|
"_trigger"
|
|
|
|
], function( i, method ) {
|
2016-04-06 15:59:16 +00:00
|
|
|
assert.strictEqual( $.ui[ widget ].prototype[ method ],
|
2015-04-03 19:21:16 +00:00
|
|
|
$.Widget.prototype[ method ], "should not override " + method );
|
2015-08-21 04:13:44 +00:00
|
|
|
} );
|
|
|
|
} );
|
2015-04-03 19:21:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function testBasicUsage( widget ) {
|
2016-04-06 15:59:16 +00:00
|
|
|
QUnit.test( "basic usage", function( assert ) {
|
|
|
|
assert.expect( 3 );
|
2015-04-03 19:21:16 +00:00
|
|
|
|
|
|
|
var defaultElement = $.ui[ widget ].prototype.defaultElement;
|
|
|
|
$( defaultElement ).appendTo( "body" )[ widget ]().remove();
|
2016-04-06 15:59:16 +00:00
|
|
|
assert.ok( true, "initialized on element" );
|
2015-04-03 19:21:16 +00:00
|
|
|
|
|
|
|
$( defaultElement )[ widget ]().remove();
|
2016-04-06 15:59:16 +00:00
|
|
|
assert.ok( true, "initialized on disconnected DOMElement - never connected" );
|
2015-04-03 19:21:16 +00:00
|
|
|
|
|
|
|
// Ensure manipulating removed elements works (#3664)
|
|
|
|
$( defaultElement ).appendTo( "body" ).remove()[ widget ]().remove();
|
2016-04-06 15:59:16 +00:00
|
|
|
assert.ok( true, "initialized on disconnected DOMElement - removed" );
|
2015-08-21 04:13:44 +00:00
|
|
|
} );
|
2015-04-03 19:21:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
exports.testWidget = function( widget, settings ) {
|
2020-05-16 07:16:24 +00:00
|
|
|
QUnit.module( widget + ": common widget", { afterEach: helper.moduleAfterEach } );
|
2015-04-03 19:21:16 +00:00
|
|
|
|
|
|
|
testWidgetDefaults( widget, settings.defaults );
|
|
|
|
testWidgetOverrides( widget );
|
2015-04-21 16:45:02 +00:00
|
|
|
if ( !settings.noDefaultElement ) {
|
|
|
|
testBasicUsage( widget );
|
|
|
|
}
|
2016-04-06 15:59:16 +00:00
|
|
|
QUnit.test( "version", function( assert ) {
|
|
|
|
assert.expect( 1 );
|
|
|
|
assert.ok( "version" in $.ui[ widget ].prototype, "version property exists" );
|
2015-08-21 04:13:44 +00:00
|
|
|
} );
|
2015-04-03 19:21:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
return exports;
|
|
|
|
|
2015-08-21 04:13:44 +00:00
|
|
|
} );
|