browser: true,
jquery: true
}, defaults ),
+ // TODO: don't create so many globals in tests
globals: {
+ accordion_state: true,
+ asyncTest: true,
+ commonWidgetTests: true,
+ deepEqual: true,
+ dlg: true,
+ domEqual: true,
+ drag: true,
+ el: true,
+ equal: true,
+ expect: true,
+ Globalize: true,
+ menu_click: true,
+ menu_log: true,
module: true,
- test: true,
ok: true,
- equal: true,
- deepEqual: true,
- QUnit: true
+ QUnit: true,
+ spinner_simulateKeyDownUp: true,
+ start: true,
+ strictEqual: true,
+ stop: true,
+ tabs_state: true,
+ tabs_disabled: true,
+ test: true
}
}
};
min: 0
}),
button = element.spinner( "widget" ).find( ".ui-spinner-down" );
-
+
button.trigger( "mousedown" ).trigger( "mouseup" );
equal( element.val(), 1 );
button.trigger( "mousedown" ).trigger( "mouseup" );
test( "precision", function() {
expect( 2 );
- var element = $( "#spin" ).val( .05 ).spinner({
- step: .0001
+ var element = $( "#spin" ).val( 0.05 ).spinner({
+ step: 0.0001
});
element.spinner( "stepUp" );
equal( element.val(), "0.0501", "precision from step" );
test( "enable", function() {
expect( 5 );
- var element = $( "#spin" ).val( 1 ).spinner({ disabled: true })
+ var element = $( "#spin" ).val( 1 ).spinner({ disabled: true }),
wrapper = element.spinner( "widget" );
ok( wrapper.hasClass( "ui-spinner-disabled" ), "before: wrapper has ui-spinner-disabled class" );
equal( element.spinner( "option", "min" ), -100, "option converted to number" );
element.spinner( "value", -1000 );
- equal( element.val(), "($100.00)", "min constrained in value method")
+ equal( element.val(), "($100.00)", "min constrained in value method" );
});
test( "step, 2", function() {
(function() {
-var versions = [ "1.6", "1.6.1", "1.6.2", "1.6.3", "1.6.4", "1.7", "1.7.1", "1.7.2", "git" ];
-
-var additionalTests = {
- accordion: [ "accordion_deprecated.html" ],
- position: [ "position_deprecated.html" ],
- tabs: [ "tabs_deprecated.html" ]
-};
+var versions = [ "1.6", "1.6.1", "1.6.2", "1.6.3", "1.6.4", "1.7", "1.7.1", "1.7.2", "git" ],
+ additionalTests = {
+ accordion: [ "accordion_deprecated.html" ],
+ position: [ "position_deprecated.html" ],
+ tabs: [ "tabs_deprecated.html" ]
+ };
window.testAllVersions = function( widget ) {
QUnit.testSuites( $.map(
QUnit.extend( QUnit, {
testSuites: function( suites ) {
+ function generateSuite( suite ) {
+ asyncTest( suite, function() {
+ QUnit.runSuite( suite );
+ });
+ }
+
for ( var i = 0; i < suites.length; i++ ) {
- (function( suite ) {
- asyncTest( suite, function() {
- QUnit.runSuite( suite );
- });
- }( suites[i] ) );
+ generateSuite( suites[ i ] );
}
+
QUnit.done = function() {
subsuiteFrame.style.display = "none";
};
testDone: function() {
var current = QUnit.id( this.config.current.id ),
- children = current.children;
+ children = current.children,
+ i = 0,
+ length = children.length;
// undo the auto-expansion of failed tests
- for ( var i = 0; i < children.length; i++ ) {
+ for ( ; i < length; i++ ) {
if ( children[i].nodeName === "OL" ) {
children[i].style.display = "none";
}
},
runSuite: function( suite ) {
- var body = document.getElementsByTagName( "body" )[0],
- iframe = subsuiteFrame = document.createElement( "iframe" ),
- iframeWin;
+ var iframeWin,
+ body = document.getElementsByTagName( "body" )[0],
+ iframe = document.createElement( "iframe" );
+ subsuiteFrame = iframe;
iframe.className = "qunit-subsuite";
body.appendChild( iframe );
if ( !url || url.indexOf("http") !== 0 ) {
return;
}
- document.write("<scr" + "ipt src='http://swarm.jquery.org/js/inject.js?" + (new Date).getTime() + "'></scr" + "ipt>");
+ document.write( "<scr" + "ipt src='http://swarm.jquery.org/js/inject.js?" + (new Date()).getTime() + "'></scr" + "ipt>" );
})();
// defaults are tested in the add method test
expect( 11 );
- var element = $( "#tabs2" ).tabs({
- tabTemplate: "<li class='customTab'><a href='http://example.com/#{href}'>#{label}</a></li>",
- panelTemplate: "<div class='customPanel'></div>"
- });
+ var tab, anchor,
+ element = $( "#tabs2" ).tabs({
+ tabTemplate: "<li class='customTab'><a href='http://example.com/#{href}'>#{label}</a></li>",
+ panelTemplate: "<div class='customPanel'></div>"
+ });
element.one( "tabsadd", function( event, ui ) {
var anchor = $( ui.tab );
equal( ui.index, 5, "ui.index" );
ok( $( ui.panel ).hasClass( "customPanel" ), "panel custom class" );
});
element.tabs( "add", "#new", "New" );
- var tab = element.find( ".ui-tabs-nav li" ).last(),
- anchor = tab.find( "a" );
+ tab = element.find( ".ui-tabs-nav li" ).last();
+ anchor = tab.find( "a" );
equal( tab.text(), "New", "label" );
ok( tab.hasClass( "customTab" ), "tab custom class" );
equal( anchor.attr( "href" ), "http://example.com/#new", "href" );
test( "add", function() {
expect( 27 );
- var element = $( "#tabs1" ).tabs();
+ var tab, anchor,
+ element = $( "#tabs1" ).tabs();
tabs_state( element, 1, 0, 0 );
// add without index
});
element.tabs( "add", "#new", "New" );
tabs_state( element, 1, 0, 0, 0 );
- var tab = element.find( ".ui-tabs-nav li" ).last(),
- anchor = tab.find( "a" );
+ tab = element.find( ".ui-tabs-nav li" ).last();
+ anchor = tab.find( "a" );
equal( tab.text(), "New", "label" );
equal( anchor.attr( "href" ), "#new", "href" );
equal( anchor.attr( "aria-controls" ), "new", "aria-controls" );
element.one( "tabsload", function( event, ui ) {
// TODO: remove wrapping in 2.0
var uiTab = $( ui.tab ),
- uiPanel = $( ui.panel );
-
- var tab = element.find( ".ui-tabs-nav a" ).eq( 3 ),
+ uiPanel = $( ui.panel ),
+ tab = element.find( ".ui-tabs-nav a" ).eq( 3 ),
panelId = tab.attr( "aria-controls" ),
panel = $( "#" + panelId );
element.one( "tabsload", function( event, ui ) {
// TODO: remove wrapping in 2.0
var uiTab = $( ui.tab ),
- uiPanel = $( ui.panel );
-
- var tab = element.find( ".ui-tabs-nav a" ).eq( 3 ),
+ uiPanel = $( ui.panel ),
+ tab = element.find( ".ui-tabs-nav a" ).eq( 3 ),
panelId = tab.attr( "aria-controls" ),
panel = $( "#" + panelId );
test( "version", function() {
ok( "version" in $.ui[ widget ].prototype, "version property exists" );
});
-}
+};
/*
* Experimental assertion for comparing DOM objects.
* Then compares the result using deepEqual.
*/
window.domEqual = function( selector, modifier, message ) {
- var attributes = ["class", "role", "id", "tabIndex", "aria-activedescendant"];
+ var expected, actual,
+ attributes = ["class", "role", "id", "tabIndex", "aria-activedescendant"];
function extract(value) {
if (!value || !value.length) {
QUnit.push( false, actual, expected, "domEqual failed, can't extract " + selector + ", message was: " + message );
return;
}
- var result = {};
+ var children,
+ result = {};
result.nodeName = value[0].nodeName;
$.each(attributes, function(index, attr) {
result[attr] = value.prop(attr);
});
result.children = [];
- var children = value.children();
+ children = value.children();
if (children.length) {
children.each(function() {
result.children.push(extract($(this)));
}
return result;
}
- var expected = extract($(selector));
- modifier($(selector));
+ expected = extract( $( selector ) );
+ modifier( $( selector ) );
- var actual = extract($(selector));
+ actual = extract( $( selector ) );
QUnit.push( QUnit.equiv(actual, expected), actual, expected, message );
-}
+};
}());
test( "open/close", function() {
expect( 3 );
$.fx.off = true;
- var element = $( "#tooltipped1" ).tooltip();
+ var tooltip,
+ element = $( "#tooltipped1" ).tooltip();
equal( $( ".ui-tooltip" ).length, 0, "no tooltip on init" );
element.tooltip( "open" );
- var tooltip = $( "#" + element.attr( "aria-describedby" ) );
+ tooltip = $( "#" + element.attr( "aria-describedby" ) );
ok( tooltip.is( ":visible" ) );
element.tooltip( "close" );
test( "enable/disable", function() {
expect( 7 );
$.fx.off = true;
- var element = $( "#tooltipped1" ).tooltip();
+ var tooltip,
+ element = $( "#tooltipped1" ).tooltip();
equal( $( ".ui-tooltip" ).length, 0, "no tooltip on init" );
element.tooltip( "open" );
- var tooltip = $( "#" + element.attr( "aria-describedby" ) );
+ tooltip = $( "#" + element.attr( "aria-describedby" ) );
ok( tooltip.is( ":visible" ) );
element.tooltip( "disable" );
test( "items", function() {
expect( 2 );
- var element = $( "#qunit-fixture" ).tooltip({
- items: "#fixture-span"
- });
+ var event,
+ element = $( "#qunit-fixture" ).tooltip({
+ items: "#fixture-span"
+ });
- var event = $.Event( "mouseenter" );
+ event = $.Event( "mouseenter" );
event.target = $( "#fixture-span" )[ 0 ];
element.tooltip( "open", event );
deepEqual( $( "#" + $( "#fixture-span" ).attr( "aria-describedby" ) ).text(), "title-text" );
});
test( "tooltipClass", function() {
- expect( 1 )
+ expect( 1 );
var element = $( "#tooltipped1" ).tooltip({
tooltipClass: "custom"
}).tooltip( "open" );
test( "jQuery usage", function() {
expect( 16 );
- var shouldCreate = false;
+ var elem, instance, ret, bcInstance,
+ shouldCreate = false;
$.widget( "ui.testWidget", {
getterSetterVal: 5,
});
shouldCreate = true;
- var elem = $( "<div>" )
+ elem = $( "<div>" )
.bind( "testwidgetcreate", function() {
ok( shouldCreate, "create event triggered on instantiation" );
})
.testWidget();
shouldCreate = false;
- var instance = elem.data( "ui-testWidget" );
+ instance = elem.data( "ui-testWidget" );
equal( typeof instance, "object", "instance stored in .data(pluginName)" );
equal( instance.element[0], elem[0], "element stored on widget" );
- var ret = elem.testWidget( "methodWithParams", "value1", "value2" );
+ ret = elem.testWidget( "methodWithParams", "value1", "value2" );
equal( ret, elem, "jQuery object returned from method call" );
// 1.9 BC for #7810
// TODO remove
- var bcInstance = elem.data("testWidget");
+ bcInstance = elem.data("testWidget");
equal( typeof bcInstance, "object", "instance stored in .data(pluginName)" );
equal( bcInstance.element[0], elem[0], "element stored on widget" );
test( "direct usage", function() {
expect( 9 );
- var shouldCreate = false;
+ var elem, instance, ret,
+ shouldCreate = false;
$.widget( "ui.testWidget", {
getterSetterVal: 5,
}
});
- var elem = $( "<div>" )[ 0 ];
+ elem = $( "<div>" )[ 0 ];
shouldCreate = true;
- var instance = new $.ui.testWidget( {}, elem );
+ instance = new $.ui.testWidget( {}, elem );
shouldCreate = false;
equal( $( elem ).data( "ui-testWidget" ), instance,
"instance stored in .data(pluginName)" );
equal( instance.element[ 0 ], elem, "element stored on widget" );
- var ret = instance.methodWithParams( "value1", "value2" );
+ ret = instance.methodWithParams( "value1", "value2" );
equal( ret, instance, "plugin returned from method call" );
ret = instance.getterSetterMethod();
_create: function() {}
});
- var div = $( "<div>" ).testWidget({
- foo: "bar",
- baz: 5,
- qux: [ "quux", "quuux" ]
- });
+ var options,
+ div = $( "<div>" ).testWidget({
+ foo: "bar",
+ baz: 5,
+ qux: [ "quux", "quuux" ]
+ });
deepEqual( div.testWidget( "option", "x" ), null, "non-existent option" );
deepEqual( div.testWidget( "option", "foo"), "bar", "single option - string" );
deepEqual( div.testWidget( "option", "qux"), [ "quux", "quuux" ],
"single option - array" );
- var options = div.testWidget( "option" );
+ options = div.testWidget( "option" );
deepEqual( options, {
create: null,
disabled: false,
});
test( ".option() - delegate to ._setOptions()", function() {
- var calls = [];
+ var div,
+ calls = [];
$.widget( "ui.testWidget", {
_create: function() {},
_setOptions: function( options ) {
calls.push( options );
}
});
- var div = $( "<div>" ).testWidget();
+ div = $( "<div>" ).testWidget();
calls = [];
div.testWidget( "option", "foo", "bar" );
});
test( ".option() - delegate to ._setOption()", function() {
- var calls = [];
+ var div,
+ calls = [];
$.widget( "ui.testWidget", {
_create: function() {},
_setOption: function( key, val ) {
});
}
});
- var div = $( "<div>" ).testWidget();
+ div = $( "<div>" ).testWidget();
calls = [];
div.testWidget( "option", "foo", "bar" );
test( "._bind() to element (default)", function() {
expect( 12 );
- var that;
+ var that, widget;
$.widget( "ui.testWidget", {
_create: function() {
that = this;
equal( "keydown", event.type );
}
});
- var widget = $( "<div></div>" )
+ widget = $( "<div></div>" )
.testWidget()
.trigger( "keyup" )
.trigger( "keydown" );
test( "._bind() to descendent", function() {
expect( 12 );
- var that;
+ var that, widget, descendant;
$.widget( "ui.testWidget", {
_create: function() {
that = this;
}
});
// trigger events on both widget and descendent to ensure that only descendent receives them
- var widget = $( "<div><p><strong>hello</strong> world</p></div>" )
+ widget = $( "<div><p><strong>hello</strong> world</p></div>" )
.testWidget()
.trigger( "keyup" )
.trigger( "keydown" );
- var descendent = widget.find( "strong" )
+ descendant = widget.find( "strong" )
.trigger( "keyup" )
.trigger( "keydown" );
widget
.testWidget( "disable" )
.trigger( "keyup" )
.trigger( "keydown" );
- descendent
+ descendant
.trigger( "keyup" )
.trigger( "keydown" );
widget
.testWidget( "enable" )
.trigger( "keyup" )
.trigger( "keydown" );
- descendent
+ descendant
.trigger( "keyup" )
.trigger( "keydown" );
- descendent
+ descendant
.addClass( "ui-state-disabled" )
.trigger( "keyup" )
.trigger( "keydown" );
.testWidget( "destroy" )
.trigger( "keyup" )
.trigger( "keydown" );
- descendent
+ descendant
.trigger( "keyup" )
.trigger( "keydown" );
});
qux: 5,
quux: 20
}
+ },
+ extra = {
+ bar: 5
};
- var extra = {
- bar: 5
- };
this._trigger( "foo", null, [ ui, extra ] );
}
});
$.widget( "ui.testWidget", {
defaultElement: null,
testEvent: function() {
- var ui = { foo: "bar" };
- this._trigger( "foo", null, ui );
+ this._trigger( "foo", null, { foo: "bar" } );
}
});
var instance = $.ui.testWidget({
test( "$.widget.extend()", function() {
expect( 26 );
- var settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
+ var ret, empty, optionsWithLength, optionsWithDate, myKlass, customObject, optionsWithCustomObject, nullUndef,
+ target, recursive, obj, input, output,
+ settings = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" },
options = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
optionsCopy = { xnumber2: 1, xstring2: "x", xxx: "newstring" },
merged = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "x", xxx: "newstring" },
deep2copy = { foo: { baz: true }, foo2: document },
deepmerged = { foo: { bar: true, baz: true }, foo2: document },
arr = [1, 2, 3],
- nestedarray = { arr: arr },
- ret;
+ nestedarray = { arr: arr };
$.widget.extend( settings, options );
deepEqual( settings, merged, "Check if extended: settings must be extended" );
strictEqual( $.widget.extend({}, nestedarray).arr, arr, "Don't clone arrays" );
ok( $.isPlainObject( $.widget.extend({ arr: arr }, { arr: {} }).arr ), "Cloned object heve to be an plain object" );
- var empty = {};
- var optionsWithLength = { foo: { length: -1 } };
+ empty = {};
+ optionsWithLength = { foo: { length: -1 } };
$.widget.extend( empty, optionsWithLength );
deepEqual( empty.foo, optionsWithLength.foo, "The length property must copy correctly" );
empty = {};
- var optionsWithDate = { foo: { date: new Date } };
+ optionsWithDate = { foo: { date: new Date() } };
$.widget.extend( empty, optionsWithDate );
deepEqual( empty.foo, optionsWithDate.foo, "Dates copy correctly" );
- var myKlass = function() {};
- var customObject = new myKlass();
- var optionsWithCustomObject = { foo: { date: customObject } };
+ myKlass = function() {};
+ customObject = new myKlass();
+ optionsWithCustomObject = { foo: { date: customObject } };
empty = {};
$.widget.extend( empty, optionsWithCustomObject );
strictEqual( empty.foo.date, customObject, "Custom objects copy correctly (no methods)" );
$.widget.extend( empty, optionsWithCustomObject );
strictEqual( empty.foo.date, customObject, "Custom objects copy correctly" );
- ret = $.widget.extend({ foo: 4 }, { foo: new Number(5) } );
+ ret = $.widget.extend({ foo: 4 }, { foo: Number(5) } );
equal( ret.foo, 5, "Wrapped numbers copy correctly" );
- var nullUndef;
nullUndef = $.widget.extend( {}, options, { xnumber2: null } );
strictEqual( nullUndef.xnumber2, null, "Check to make sure null values are copied");
nullUndef = $.widget.extend( {}, options, { xnumber0: null } );
strictEqual( nullUndef.xnumber0, null, "Check to make sure null values are inserted");
- var target = {};
- var recursive = { foo:target, bar:5 };
+ target = {};
+ recursive = { foo:target, bar:5 };
$.widget.extend( target, recursive );
deepEqual( target, { foo: {}, bar: 5 }, "Check to make sure a recursive obj doesn't go never-ending loop by not copying it over" );
ret = $.widget.extend( { foo:"bar" }, { foo:null } );
strictEqual( typeof ret.foo, "object", "Make sure a null value doesn't crash with deep extend, for #1908" );
- var obj = { foo:null };
+ obj = { foo:null };
$.widget.extend( obj, { foo:"notnull" } );
equal( obj.foo, "notnull", "Make sure a null value can be overwritten" );
options2Copy = { xstring2: "xx", xxx: "newstringx" },
merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" };
- var settings = $.widget.extend( {}, defaults, options1, options2 );
+ settings = $.widget.extend( {}, defaults, options1, options2 );
deepEqual( settings, merged2, "Check if extended: settings must be extended" );
deepEqual( defaults, defaultsCopy, "Check if not modified: options1 must not be modified" );
deepEqual( options1, options1Copy, "Check if not modified: options1 must not be modified" );
deepEqual( options2, options2Copy, "Check if not modified: options2 must not be modified" );
- var input = {
+ input = {
key: [ 1, 2, 3 ]
};
- var output = $.widget.extend( {}, input );
+ output = $.widget.extend( {}, input );
deepEqual( input, output, "don't clone arrays" );
input.key[0] = 10;
deepEqual( input, output, "don't clone arrays" );