2012-04-23 12:44:55 +00:00
|
|
|
|
(function( $ ) {
|
2011-01-25 00:20:09 +00:00
|
|
|
|
|
2012-08-30 13:20:36 +00:00
|
|
|
|
var reset, jshintLoaded;
|
|
|
|
|
|
2012-04-19 15:37:33 +00:00
|
|
|
|
window.TestHelpers = {};
|
|
|
|
|
|
2012-04-23 14:43:01 +00:00
|
|
|
|
function includeStyle( url ) {
|
|
|
|
|
document.write( "<link rel='stylesheet' href='../../../" + url + "'>" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function includeScript( url ) {
|
|
|
|
|
document.write( "<script src='../../../" + url + "'></script>" );
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-22 21:41:54 +00:00
|
|
|
|
function url( value ) {
|
2014-09-03 12:37:51 +00:00
|
|
|
|
return value + ( /\?/.test( value ) ? "&" : "?" ) + new Date().getTime() + "" +
|
|
|
|
|
parseInt( Math.random() * 100000, 10 );
|
2012-10-22 21:41:54 +00:00
|
|
|
|
}
|
|
|
|
|
|
2012-08-30 13:20:36 +00:00
|
|
|
|
reset = QUnit.reset;
|
|
|
|
|
QUnit.reset = function() {
|
2014-09-03 12:37:51 +00:00
|
|
|
|
|
2012-08-30 13:20:36 +00:00
|
|
|
|
// Ensure jQuery events and data on the fixture are properly removed
|
2014-09-03 12:37:51 +00:00
|
|
|
|
jQuery( "#qunit-fixture" ).empty();
|
|
|
|
|
|
2012-08-30 13:20:36 +00:00
|
|
|
|
// Let QUnit reset the fixture
|
|
|
|
|
reset.apply( this, arguments );
|
|
|
|
|
};
|
|
|
|
|
|
2012-06-27 15:32:48 +00:00
|
|
|
|
QUnit.config.requireExpects = true;
|
|
|
|
|
|
2013-09-20 16:15:55 +00:00
|
|
|
|
/*
|
|
|
|
|
// TODO: Add back the ability to test against minified files
|
|
|
|
|
// see QUnit.urlParams.min usage below
|
2012-07-10 01:45:49 +00:00
|
|
|
|
QUnit.config.urlConfig.push({
|
2013-01-16 18:45:54 +00:00
|
|
|
|
id: "min",
|
|
|
|
|
label: "Minified source",
|
|
|
|
|
tooltip: "Load minified source files instead of the regular unminified ones."
|
2012-07-10 01:45:49 +00:00
|
|
|
|
});
|
2013-09-20 16:15:55 +00:00
|
|
|
|
*/
|
2012-07-10 01:45:49 +00:00
|
|
|
|
|
2012-04-23 14:43:01 +00:00
|
|
|
|
TestHelpers.loadResources = QUnit.urlParams.min ?
|
|
|
|
|
function() {
|
|
|
|
|
includeStyle( "dist/jquery-ui.min.css" );
|
|
|
|
|
includeScript( "dist/jquery-ui.min.js" );
|
|
|
|
|
} :
|
|
|
|
|
function( resources ) {
|
|
|
|
|
$.each( resources.css || [], function( i, resource ) {
|
2013-12-02 18:36:12 +00:00
|
|
|
|
includeStyle( "themes/base/" + resource + ".css" );
|
2012-04-23 14:43:01 +00:00
|
|
|
|
});
|
|
|
|
|
$.each( resources.js || [], function( i, resource ) {
|
|
|
|
|
includeScript( resource );
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2012-07-10 01:45:49 +00:00
|
|
|
|
QUnit.config.urlConfig.push({
|
|
|
|
|
id: "nojshint",
|
|
|
|
|
label: "Skip JSHint",
|
2014-09-03 12:37:51 +00:00
|
|
|
|
tooltip: "Skip running JSHint, e.g., within TestSwarm, where Jenkins runs it already"
|
2012-07-10 01:45:49 +00:00
|
|
|
|
});
|
|
|
|
|
|
2014-02-21 17:42:43 +00:00
|
|
|
|
QUnit.config.urlConfig.push({
|
|
|
|
|
id: "jquery",
|
|
|
|
|
label: "jQuery version",
|
|
|
|
|
value: [
|
2015-01-12 16:19:46 +00:00
|
|
|
|
"1.7.0", "1.7.1", "1.7.2", "1.8.0", "1.8.1", "1.8.2", "1.8.3",
|
|
|
|
|
"1.9.0", "1.9.1", "1.10.0", "1.10.1", "1.10.2", "2.0.0",
|
|
|
|
|
"2.0.1", "2.0.2", "2.0.3", "git"
|
2014-02-21 17:42:43 +00:00
|
|
|
|
],
|
|
|
|
|
tooltip: "Which jQuery Core version to test against"
|
|
|
|
|
});
|
|
|
|
|
|
2012-08-30 13:20:36 +00:00
|
|
|
|
jshintLoaded = false;
|
2012-04-30 00:22:31 +00:00
|
|
|
|
TestHelpers.testJshint = function( module ) {
|
2014-09-03 12:37:51 +00:00
|
|
|
|
|
2013-11-22 16:43:55 +00:00
|
|
|
|
// Function.prototype.bind check is needed because JSHint doesn't work in ES3 browsers anymore
|
|
|
|
|
// https://github.com/jshint/jshint/issues/1384
|
|
|
|
|
if ( QUnit.urlParams.nojshint || !Function.prototype.bind ) {
|
2012-04-23 12:44:55 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-30 00:22:31 +00:00
|
|
|
|
if ( !jshintLoaded ) {
|
2014-06-10 11:55:45 +00:00
|
|
|
|
includeScript( "external/jshint/jshint.js" );
|
2012-04-30 00:22:31 +00:00
|
|
|
|
jshintLoaded = true;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-23 12:44:55 +00:00
|
|
|
|
asyncTest( "JSHint", function() {
|
|
|
|
|
expect( 1 );
|
|
|
|
|
|
|
|
|
|
$.when(
|
|
|
|
|
$.ajax({
|
2014-09-03 12:37:51 +00:00
|
|
|
|
url: url( "../../../ui/.jshintrc" ),
|
2012-04-23 12:44:55 +00:00
|
|
|
|
dataType: "json"
|
|
|
|
|
}),
|
|
|
|
|
$.ajax({
|
2014-09-03 12:37:51 +00:00
|
|
|
|
url: url( "../../../ui/" + module + ".js" ),
|
2012-04-23 12:44:55 +00:00
|
|
|
|
dataType: "text"
|
|
|
|
|
})
|
|
|
|
|
).done(function( hintArgs, srcArgs ) {
|
2013-03-27 13:40:53 +00:00
|
|
|
|
var globals, passed, errors,
|
|
|
|
|
jshintrc = hintArgs[ 0 ],
|
|
|
|
|
source = srcArgs[ 0 ];
|
|
|
|
|
|
|
|
|
|
globals = jshintrc.globals || {};
|
|
|
|
|
delete jshintrc.globals;
|
2013-08-21 13:37:03 +00:00
|
|
|
|
passed = JSHINT( source, jshintrc, globals );
|
2013-03-27 13:40:53 +00:00
|
|
|
|
errors = $.map( JSHINT.errors, function( error ) {
|
2014-09-03 12:37:51 +00:00
|
|
|
|
|
2013-03-27 13:40:53 +00:00
|
|
|
|
// JSHINT may report null if there are too many errors
|
|
|
|
|
if ( !error ) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return "[L" + error.line + ":C" + error.character + "] " +
|
|
|
|
|
error.reason + "\n" + error.evidence + "\n";
|
|
|
|
|
}).join( "\n" );
|
2012-04-23 12:44:55 +00:00
|
|
|
|
ok( passed, errors );
|
|
|
|
|
start();
|
|
|
|
|
})
|
|
|
|
|
.fail(function() {
|
|
|
|
|
ok( false, "error loading source" );
|
|
|
|
|
start();
|
|
|
|
|
});
|
|
|
|
|
});
|
2012-04-30 05:19:26 +00:00
|
|
|
|
};
|
2012-04-23 12:44:55 +00:00
|
|
|
|
|
2011-01-25 00:20:09 +00:00
|
|
|
|
function testWidgetDefaults( widget, defaults ) {
|
|
|
|
|
var pluginDefaults = $.ui[ widget ].prototype.options;
|
|
|
|
|
|
2014-09-03 12:37:51 +00:00
|
|
|
|
// Ensure that all defaults have the correct value
|
2011-01-25 00:20:09 +00:00
|
|
|
|
test( "defined defaults", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
|
var count = 0;
|
2011-01-25 00:20:09 +00:00
|
|
|
|
$.each( defaults, function( key, val ) {
|
2012-06-27 15:32:48 +00:00
|
|
|
|
expect( ++count );
|
2011-01-25 00:20:09 +00:00
|
|
|
|
if ( $.isFunction( val ) ) {
|
|
|
|
|
ok( $.isFunction( pluginDefaults[ key ] ), key );
|
2009-09-15 08:26:59 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2012-02-28 14:56:32 +00:00
|
|
|
|
deepEqual( pluginDefaults[ key ], val, key );
|
2009-04-17 21:28:37 +00:00
|
|
|
|
});
|
|
|
|
|
});
|
2011-01-25 00:20:09 +00:00
|
|
|
|
|
2014-09-03 12:37:51 +00:00
|
|
|
|
// Ensure that all defaults were tested
|
2011-01-25 00:20:09 +00:00
|
|
|
|
test( "tested defaults", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
|
var count = 0;
|
2012-10-23 14:36:42 +00:00
|
|
|
|
$.each( pluginDefaults, function( key ) {
|
2012-06-27 15:32:48 +00:00
|
|
|
|
expect( ++count );
|
2011-01-25 00:20:09 +00:00
|
|
|
|
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
|
|
|
|
function testWidgetOverrides( widget ) {
|
2011-01-25 05:05:55 +00:00
|
|
|
|
if ( $.uiBackCompat === false ) {
|
|
|
|
|
test( "$.widget overrides", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
|
expect( 4 );
|
2012-04-23 14:43:01 +00:00
|
|
|
|
$.each([
|
|
|
|
|
"_createWidget",
|
|
|
|
|
"destroy",
|
|
|
|
|
"option",
|
|
|
|
|
"_trigger"
|
|
|
|
|
], function( i, method ) {
|
2011-01-25 05:05:55 +00:00
|
|
|
|
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() {
|
2012-06-27 15:32:48 +00:00
|
|
|
|
expect( 3 );
|
|
|
|
|
|
2011-01-25 00:20:09 +00:00
|
|
|
|
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
|
|
|
|
|
2014-09-03 12:37:51 +00:00
|
|
|
|
// Ensure manipulating removed elements works (#3664)
|
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
|
|
|
|
|
2012-04-19 17:03:21 +00:00
|
|
|
|
TestHelpers.commonWidgetTests = function( widget, settings ) {
|
2011-01-25 00:20:09 +00:00
|
|
|
|
module( widget + ": common widget" );
|
|
|
|
|
|
2012-06-15 17:42:00 +00:00
|
|
|
|
TestHelpers.testJshint( widget );
|
2011-01-25 00:20:09 +00:00
|
|
|
|
testWidgetDefaults( widget, settings.defaults );
|
|
|
|
|
testWidgetOverrides( widget );
|
|
|
|
|
testBasicUsage( widget );
|
2011-02-03 17:01:26 +00:00
|
|
|
|
test( "version", function() {
|
2012-06-27 15:32:48 +00:00
|
|
|
|
expect( 1 );
|
2011-05-28 19:42:55 +00:00
|
|
|
|
ok( "version" in $.ui[ widget ].prototype, "version property exists" );
|
2011-02-03 17:01:26 +00:00
|
|
|
|
});
|
2012-04-19 02:36:15 +00:00
|
|
|
|
};
|
2011-02-25 10:33:48 +00:00
|
|
|
|
|
2014-09-03 12:37:51 +00:00
|
|
|
|
TestHelpers.onFocus = function( element, onFocus ) {
|
|
|
|
|
var fn = function( event ) {
|
|
|
|
|
if ( !event.originalEvent ) {
|
2013-05-01 22:01:32 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
element.unbind( "focus", fn );
|
|
|
|
|
onFocus();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
element.bind( "focus", fn )[ 0 ].focus();
|
|
|
|
|
};
|
|
|
|
|
|
2013-10-19 15:12:35 +00:00
|
|
|
|
TestHelpers.forceScrollableWindow = function( appendTo ) {
|
2014-09-03 12:37:51 +00:00
|
|
|
|
|
2014-08-22 15:51:15 +00:00
|
|
|
|
// The main testable area is 10000x10000 so to enforce scrolling,
|
|
|
|
|
// this DIV must be greater than 10000 to work
|
2013-10-19 15:12:35 +00:00
|
|
|
|
return $( "<div>" ).css({
|
2014-08-22 15:51:15 +00:00
|
|
|
|
height: "11000px",
|
|
|
|
|
width: "11000px"
|
2013-10-19 15:12:35 +00:00
|
|
|
|
}).appendTo( appendTo || "#qunit-fixture" );
|
|
|
|
|
};
|
|
|
|
|
|
2014-09-03 12:37:51 +00:00
|
|
|
|
// Taken from https://github.com/jquery/qunit/tree/master/addons/close-enough
|
2012-11-09 20:02:12 +00:00
|
|
|
|
window.closeEnough = function( actual, expected, maxDifference, message ) {
|
2014-09-03 12:37:51 +00:00
|
|
|
|
var passes = ( actual === expected ) || Math.abs( actual - expected ) <= maxDifference;
|
|
|
|
|
QUnit.push( passes, actual, expected, message );
|
2012-11-09 20:02:12 +00:00
|
|
|
|
};
|
|
|
|
|
|
2011-02-25 10:33:48 +00:00
|
|
|
|
/*
|
|
|
|
|
* Experimental assertion for comparing DOM objects.
|
2012-02-28 14:56:32 +00:00
|
|
|
|
*
|
2014-09-03 12:37:51 +00:00
|
|
|
|
* Serializes an element and some properties and attributes and its children if any,
|
|
|
|
|
* otherwise the text. Then compares the result using deepEqual().
|
2011-02-25 10:33:48 +00:00
|
|
|
|
*/
|
|
|
|
|
window.domEqual = function( selector, modifier, message ) {
|
2012-04-19 02:36:15 +00:00
|
|
|
|
var expected, actual,
|
2012-05-25 20:51:51 +00:00
|
|
|
|
properties = [
|
2012-05-29 19:14:35 +00:00
|
|
|
|
"disabled",
|
|
|
|
|
"readOnly"
|
|
|
|
|
],
|
|
|
|
|
attributes = [
|
2012-05-25 20:51:51 +00:00
|
|
|
|
"autocomplete",
|
|
|
|
|
"aria-activedescendant",
|
|
|
|
|
"aria-controls",
|
|
|
|
|
"aria-describedby",
|
|
|
|
|
"aria-disabled",
|
|
|
|
|
"aria-expanded",
|
|
|
|
|
"aria-haspopup",
|
|
|
|
|
"aria-hidden",
|
|
|
|
|
"aria-labelledby",
|
|
|
|
|
"aria-pressed",
|
|
|
|
|
"aria-selected",
|
|
|
|
|
"aria-valuemax",
|
|
|
|
|
"aria-valuemin",
|
|
|
|
|
"aria-valuenow",
|
|
|
|
|
"class",
|
|
|
|
|
"href",
|
|
|
|
|
"id",
|
|
|
|
|
"nodeName",
|
|
|
|
|
"role",
|
|
|
|
|
"tabIndex",
|
2012-12-04 14:21:33 +00:00
|
|
|
|
"title"
|
2012-05-25 20:51:51 +00:00
|
|
|
|
];
|
2012-12-04 15:03:05 +00:00
|
|
|
|
|
2012-12-04 14:21:33 +00:00
|
|
|
|
function getElementStyles( elem ) {
|
|
|
|
|
var key, len,
|
|
|
|
|
style = elem.ownerDocument.defaultView ?
|
|
|
|
|
elem.ownerDocument.defaultView.getComputedStyle( elem, null ) :
|
|
|
|
|
elem.currentStyle,
|
|
|
|
|
styles = {};
|
|
|
|
|
|
|
|
|
|
if ( style && style.length && style[ 0 ] && style[ style[ 0 ] ] ) {
|
|
|
|
|
len = style.length;
|
|
|
|
|
while ( len-- ) {
|
|
|
|
|
key = style[ len ];
|
|
|
|
|
if ( typeof style[ key ] === "string" ) {
|
|
|
|
|
styles[ $.camelCase( key ) ] = style[ key ];
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-09-03 12:37:51 +00:00
|
|
|
|
|
2012-12-04 14:21:33 +00:00
|
|
|
|
// support: Opera, IE <9
|
|
|
|
|
} else {
|
|
|
|
|
for ( key in style ) {
|
|
|
|
|
if ( typeof style[ key ] === "string" ) {
|
|
|
|
|
styles[ key ] = style[ key ];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-11-09 19:52:57 +00:00
|
|
|
|
|
2012-12-04 14:21:33 +00:00
|
|
|
|
return styles;
|
|
|
|
|
}
|
2012-12-04 15:03:05 +00:00
|
|
|
|
|
2012-05-25 20:51:51 +00:00
|
|
|
|
function extract( elem ) {
|
|
|
|
|
if ( !elem || !elem.length ) {
|
|
|
|
|
QUnit.push( false, actual, expected,
|
|
|
|
|
"domEqual failed, can't extract " + selector + ", message was: " + message );
|
2011-05-02 18:35:18 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
2012-05-25 20:51:51 +00:00
|
|
|
|
|
2012-04-19 02:36:15 +00:00
|
|
|
|
var children,
|
|
|
|
|
result = {};
|
2012-05-25 20:51:51 +00:00
|
|
|
|
$.each( properties, function( index, attr ) {
|
2012-05-29 19:14:35 +00:00
|
|
|
|
var value = elem.prop( attr );
|
|
|
|
|
result[ attr ] = value !== undefined ? value : "";
|
|
|
|
|
});
|
|
|
|
|
$.each( attributes, function( index, attr ) {
|
|
|
|
|
var value = elem.attr( attr );
|
|
|
|
|
result[ attr ] = value !== undefined ? value : "";
|
2011-02-25 10:33:48 +00:00
|
|
|
|
});
|
2012-12-04 15:03:05 +00:00
|
|
|
|
result.style = getElementStyles( elem[ 0 ] );
|
2012-06-10 00:12:03 +00:00
|
|
|
|
result.events = $._data( elem[ 0 ], "events" );
|
|
|
|
|
result.data = $.extend( {}, elem.data() );
|
|
|
|
|
delete result.data[ $.expando ];
|
2012-05-25 20:51:51 +00:00
|
|
|
|
children = elem.children();
|
|
|
|
|
if ( children.length ) {
|
2012-10-23 14:36:42 +00:00
|
|
|
|
result.children = elem.children().map(function() {
|
2012-05-25 20:51:51 +00:00
|
|
|
|
return extract( $( this ) );
|
2012-05-26 02:57:08 +00:00
|
|
|
|
}).get();
|
2011-02-25 10:33:48 +00:00
|
|
|
|
} else {
|
2012-05-25 20:51:51 +00:00
|
|
|
|
result.text = elem.text();
|
2011-02-25 10:33:48 +00:00
|
|
|
|
}
|
|
|
|
|
return result;
|
|
|
|
|
}
|
2012-11-12 16:19:20 +00:00
|
|
|
|
|
|
|
|
|
function done() {
|
|
|
|
|
actual = extract( $( selector ) );
|
|
|
|
|
QUnit.push( QUnit.equiv(actual, expected), actual, expected, message );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Get current state prior to modifier
|
2012-04-19 02:36:15 +00:00
|
|
|
|
expected = extract( $( selector ) );
|
2012-02-28 14:56:32 +00:00
|
|
|
|
|
2012-11-12 16:19:20 +00:00
|
|
|
|
// Run modifier (async or sync), then compare state via done()
|
|
|
|
|
if ( modifier.length ) {
|
|
|
|
|
modifier( done );
|
|
|
|
|
} else {
|
|
|
|
|
modifier();
|
|
|
|
|
done();
|
|
|
|
|
}
|
2012-04-19 02:36:15 +00:00
|
|
|
|
};
|
2011-01-25 00:20:09 +00:00
|
|
|
|
|
2012-04-23 12:44:55 +00:00
|
|
|
|
}( jQuery ));
|