diff options
author | Leif Johansson <leifj@sunet.se> | 2011-11-25 21:18:19 +0100 |
---|---|---|
committer | Leif Johansson <leifj@sunet.se> | 2011-11-25 21:18:19 +0100 |
commit | 3909e6d89e01e4cd8777377c63037896bb95aa2f (patch) | |
tree | 59679df287c2bee55087fb5afb8d42e7f93a44fb /src/main/webapp/jquery-ui-1.9pre/tests/unit | |
parent | e5f94e9be5017f627c1ccd8c6306c5cc2e200432 (diff) |
new jq layout
Diffstat (limited to 'src/main/webapp/jquery-ui-1.9pre/tests/unit')
157 files changed, 17308 insertions, 0 deletions
diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion.html new file mode 100644 index 0000000..ed9b1aa --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion.html @@ -0,0 +1,144 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Accordion Test Suite</title> + + <script src="../../jquery.js"></script> + <script> + $.uiBackCompat = false; + </script> + <script src="../../resource_loader.js"></script> + <script> + loadResources({ + css: [ "ui.core", "ui.accordion" ], + js: [ + "ui/jquery.ui.core.js", + "ui/jquery.ui.widget.js", + "ui/jquery.ui.accordion.js" + ] + }); + </script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <script src="../../../external/qunit.js"></script> + <script src="../../jquery.simulate.js"></script> + <script src="../testsuite.js"></script> + + <script src="accordion_test_helpers.js"></script> + <script src="accordion_defaults.js"></script> + <script src="accordion_core.js"></script> + <script src="accordion_events.js"></script> + <script src="accordion_methods.js"></script> + <script src="accordion_options.js"></script> + + <script src="../swarminject.js"></script> + <style> + #list, #list1 *, #navigation, #navigation * { + margin: 0; + padding: 0; + font-size: 12px; + line-height: 15px; + } + </style> +</head> +<body> +<h1 id="qunit-header">jQuery UI Accordion Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +<div id="list1" class="foo"> + <h3 class="bar"><a class="anchor">There is one obvious advantage:</a></h3> + <div class="foo"> + <p> + You've seen it coming! + <br> + Buy now and get nothing for free! + <br> + Well, at least no free beer. Perhaps a bear, if you can afford it. + </p> + </div> + <h3 class="bar"><a class="anchor">Now that you've got...</a></h3> + <div class="foo"> + <p> + your bear, you have to admit it! + <br> + No, we aren't selling bears. + </p> + <p> + We could talk about renting one. + </p> + </div> + <h3 class="bar"><a class="anchor">Rent one bear, ...</a></h3> + <div class="foo"> + <p> + get two for three beer. + </p> + <p> + And now, for something completely different. + </p> + </div> +</div> + +<div id="navigationWrapper"> + <ul id="navigation"> + <li> + <h2><a href="?p=1.1.1">Guitar</a></h2> + <ul> + <li><a href="?p=1.1.1.1">Electric</a></li> + <li><a href="?p=1.1.1.2">Acoustic</a></li> + <li><a href="?p=1.1.1.3">Amps</a></li> + <li><a href="?p=1.1.1.4">Effects</a></li> + <li><a href="?p=1.1.1.5">Accessories</a></li> + </ul> + </li> + <li> + <h2><a href="?p=1.1.2"><span>Bass</span></a></h2> + <ul> + <li><a href="?p=1.1.2.1">Electric</a></li> + <li><a href="?p=1.1.2.2">Acoustic</a></li> + <li><a href="?p=1.1.2.3">Amps</a></li> + <li><a href="?p=1.1.2.4">Effects</a></li> + <li><a href="?p=1.1.2.5">Accessories</a></li> + <li><a href="?p=1.1.2.5">Accessories</a></li> + <li><a href="?p=1.1.2.5">Accessories</a></li> + </ul> + </li> + <li> + <h2><a href="?p=1.1.3">Drums</a></h2> + <ul> + <li><a href="?p=1.1.3.2">Acoustic</a></li> + <li><a href="?p=1.1.3.3">Electronic</a></li> + <li><a href="?p=1.1.3.6">Accessories</a></li> + </ul> + </li> + </ul> +</div> + +<dl id="accordion-dl"> + <dt> + <a href="#">Accordion Header 1</a> + </dt> + <dd> + Accordion Content 1 + </dd> + <dt> + <a href="#">Accordion Header 2</a> + </dt> + <dd> + Accordion Content 2 + </dd> + <dt> + <a href="#">Accordion Header 3</a> + </dt> + <dd> + Accordion Content 3 + </dd> +</dl> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion_core.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion_core.js new file mode 100644 index 0000000..3442cad --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion_core.js @@ -0,0 +1,55 @@ +(function( $ ) { + +module( "accordion: core", accordion_setupTeardown() ); + +$.each( { div: "#list1", ul: "#navigation", dl: "#accordion-dl" }, function( type, selector ) { + test( "markup structure: " + type, function() { + expect( 4 ); + var element = $( selector ).accordion(); + ok( element.hasClass( "ui-accordion" ), "main element is .ui-accordion" ); + equal( element.find( ".ui-accordion-header" ).length, 3, + ".ui-accordion-header elements exist, correct number" ); + equal( element.find( ".ui-accordion-content" ).length, 3, + ".ui-accordion-content elements exist, correct number" ); + deepEqual( element.find( ".ui-accordion-header" ).next().get(), + element.find( ".ui-accordion-content" ).get(), + "content panels come immediately after headers" ); + }); +}); + +test( "handle click on header-descendant", function() { + expect( 1 ); + var element = $( "#navigation" ).accordion(); + $( "#navigation h2:eq(1) a" ).click(); + accordion_state( element, 0, 1, 0 ); +}); + +test( "ui-accordion-heading class added to headers anchor", function() { + expect( 1 ); + var element = $( "#list1" ).accordion(); + var anchors = element.find( ".ui-accordion-heading" ); + equal( anchors.length, 3 ); +}); + +test( "accessibility", function () { + expect( 13 ); + var element = $( "#list1" ).accordion().accordion( "option", "active", 1 ); + var headers = element.find( ".ui-accordion-header" ); + + equal( headers.eq( 1 ).attr( "tabindex" ), 0, "active header should have tabindex=0" ); + equal( headers.eq( 0 ).attr( "tabindex" ), -1, "inactive header should have tabindex=-1" ); + equal( element.attr( "role" ), "tablist", "main role" ); + equal( headers.attr( "role" ), "tab", "tab roles" ); + equal( headers.next().attr( "role" ), "tabpanel", "tabpanel roles" ); + equal( headers.eq( 1 ).attr( "aria-expanded" ), "true", "active tab has aria-expanded" ); + equal( headers.eq( 0 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded" ); + equal( headers.eq( 1 ).attr( "aria-selected" ), "true", "active tab has aria-selected" ); + equal( headers.eq( 0 ).attr( "aria-selected" ), "false", "inactive tab has aria-selected" ); + element.accordion( "option", "active", 0 ); + equal( headers.eq( 0 ).attr( "aria-expanded" ), "true", "newly active tab has aria-expanded" ); + equal( headers.eq( 1 ).attr( "aria-expanded" ), "false", "newly inactive tab has aria-expanded" ); + equal( headers.eq( 0 ).attr( "aria-selected" ), "true", "active tab has aria-selected" ); + equal( headers.eq( 1 ).attr( "aria-selected" ), "false", "inactive tab has aria-selected" ); +}); + +}( jQuery ) ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion_defaults.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion_defaults.js new file mode 100644 index 0000000..9aa58e6 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion_defaults.js @@ -0,0 +1,20 @@ +commonWidgetTests( "accordion", { + defaults: { + active: 0, + animated: "slide", + collapsible: false, + disabled: false, + event: "click", + header: "> li > :first-child,> :not(li):even", + heightStyle: "auto", + icons: { + "activeHeader": "ui-icon-triangle-1-s", + "header": "ui-icon-triangle-1-e" + }, + + // callbacks + activate: null, + beforeActivate: null, + create: null + } +}); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion_defaults_deprecated.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion_defaults_deprecated.js new file mode 100644 index 0000000..3f45a1f --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion_defaults_deprecated.js @@ -0,0 +1,28 @@ +commonWidgetTests( "accordion", { + defaults: { + active: 0, + animated: "slide", + autoHeight: true, + clearStyle: false, + collapsible: false, + disabled: false, + event: "click", + fillSpace: false, + header: "> li > :first-child,> :not(li):even", + heightStyle: null, + icons: { + "activeHeader": null, + "header": "ui-icon-triangle-1-e", + "headerSelected": "ui-icon-triangle-1-s" + }, + navigation: false, + navigationFilter: function() {}, + + // callbacks + activate: null, + beforeActivate: null, + change: null, + changestart: null, + create: null + } +}); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion_deprecated.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion_deprecated.html new file mode 100644 index 0000000..f730d80 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion_deprecated.html @@ -0,0 +1,142 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Accordion Test Suite</title> + + <script src="../../jquery.js"></script> + <script src="../../resource_loader.js"></script> + <script> + loadResources({ + css: [ "ui.core", "ui.accordion" ], + js: [ + "ui/jquery.ui.core.js", + "ui/jquery.ui.widget.js", + "ui/jquery.ui.accordion.js" + ] + }); + </script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <script src="../../../external/qunit.js"></script> + <script src="../../jquery.simulate.js"></script> + <script src="../testsuite.js"></script> + + <script src="accordion_test_helpers.js"></script> + <script src="accordion_defaults_deprecated.js"></script> + <script src="accordion_core.js"></script> + <script src="accordion_events.js"></script> + <script src="accordion_methods.js"></script> + <script src="accordion_options.js"></script> + <script src="accordion_deprecated.js"></script> + + <script src="../swarminject.js"></script> + <style> + #list, #list1 *, #navigation, #navigation * { + margin: 0; + padding: 0; + font-size: 12px; + line-height: 15px; + } + </style> +</head> +<body> +<h1 id="qunit-header">jQuery UI Accordion Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +<div id="list1" class="foo"> + <h3 class="bar"><a class="anchor">There is one obvious advantage:</a></h3> + <div class="foo"> + <p> + You've seen it coming! + <br> + Buy now and get nothing for free! + <br> + Well, at least no free beer. Perhaps a bear, if you can afford it. + </p> + </div> + <h3 class="bar"><a class="anchor">Now that you've got...</a></h3> + <div class="foo"> + <p> + your bear, you have to admit it! + <br> + No, we aren't selling bears. + </p> + <p> + We could talk about renting one. + </p> + </div> + <h3 class="bar"><a class="anchor">Rent one bear, ...</a></h3> + <div class="foo"> + <p> + get two for three beer. + </p> + <p> + And now, for something completely different. + </p> + </div> +</div> + +<div id="navigationWrapper"> + <ul id="navigation"> + <li> + <h2><a href="?p=1.1.1">Guitar</a></h2> + <ul> + <li><a href="?p=1.1.1.1">Electric</a></li> + <li><a href="?p=1.1.1.2">Acoustic</a></li> + <li><a href="?p=1.1.1.3">Amps</a></li> + <li><a href="?p=1.1.1.4">Effects</a></li> + <li><a href="?p=1.1.1.5">Accessories</a></li> + </ul> + </li> + <li> + <h2><a href="?p=1.1.2"><span>Bass</span></a></h2> + <ul> + <li><a href="?p=1.1.2.1">Electric</a></li> + <li><a href="?p=1.1.2.2">Acoustic</a></li> + <li><a href="?p=1.1.2.3">Amps</a></li> + <li><a href="?p=1.1.2.4">Effects</a></li> + <li><a href="?p=1.1.2.5">Accessories</a></li> + <li><a href="?p=1.1.2.5">Accessories</a></li> + <li><a href="?p=1.1.2.5">Accessories</a></li> + </ul> + </li> + <li> + <h2><a href="?p=1.1.3">Drums</a></h2> + <ul> + <li><a href="?p=1.1.3.2">Acoustic</a></li> + <li><a href="?p=1.1.3.3">Electronic</a></li> + <li><a href="?p=1.1.3.6">Accessories</a></li> + </ul> + </li> + </ul> +</div> + +<dl id="accordion-dl"> + <dt> + <a href="#">Accordion Header 1</a> + </dt> + <dd> + Accordion Content 1 + </dd> + <dt> + <a href="#">Accordion Header 2</a> + </dt> + <dd> + Accordion Content 2 + </dd> + <dt> + <a href="#">Accordion Header 3</a> + </dt> + <dd> + Accordion Content 3 + </dd> +</dl> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion_deprecated.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion_deprecated.js new file mode 100644 index 0000000..eec034e --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion_deprecated.js @@ -0,0 +1,338 @@ +(function( $ ) { + +module( "accordion (deprecated): expanded active option, activate method", accordion_setupTeardown() ); + +test( "activate, numeric", function() { + expect( 5 ); + var element = $( "#list1" ).accordion({ active: 1 }); + accordion_state( element, 0, 1, 0 ); + element.accordion( "activate", 2 ); + accordion_state( element, 0, 0, 1 ); + element.accordion( "activate", 0 ); + accordion_state( element, 1, 0, 0 ); + element.accordion( "activate", 1 ); + accordion_state( element, 0, 1, 0 ); + element.accordion( "activate", 2 ); + accordion_state( element, 0, 0, 1 ); +}); + +test( "activate, numeric, collapsible:true", function() { + expect( 3 ); + var element = $( "#list1" ).accordion({ collapsible: true }); + element.accordion( "activate", 2 ); + accordion_state( element, 0, 0, 1 ); + element.accordion( "activate", 0 ); + accordion_state( element, 1, 0, 0 ); + element.accordion( "activate", -1 ); + accordion_state( element, 0, 0, 0 ); +}); + +test( "activate, boolean, collapsible: true", function() { + expect( 2 ); + var element = $( "#list1" ).accordion({ collapsible: true }); + element.accordion( "activate", 2 ); + accordion_state( element, 0, 0, 1 ); + element.accordion( "activate", false ); + accordion_state( element, 0, 0, 0 ); +}); + +test( "activate, boolean, collapsible: false", function() { + expect( 2 ); + var element = $( "#list1" ).accordion(); + element.accordion( "activate", 2 ); + accordion_state( element, 0, 0, 1 ); + element.accordion( "activate", false ); + accordion_state( element, 0, 0, 1 ); +}); + +test( "activate, string expression", function() { + expect( 4 ); + var element = $( "#list1" ).accordion({ active: "h3:last" }); + accordion_state( element, 0, 0, 1 ); + element.accordion( "activate", ":first" ); + accordion_state( element, 1, 0, 0 ); + element.accordion( "activate", ":eq(1)" ); + accordion_state( element, 0, 1, 0 ); + element.accordion( "activate", ":last" ); + accordion_state( element, 0, 0, 1 ); +}); + +test( "activate, jQuery or DOM element", function() { + expect( 3 ); + var element = $( "#list1" ).accordion({ active: $( "#list1 h3:last" ) }); + accordion_state( element, 0, 0, 1 ); + element.accordion( "activate", $( "#list1 h3:first" ) ); + accordion_state( element, 1, 0, 0 ); + element.accordion( "activate", $( "#list1 h3" )[ 1 ] ); + accordion_state( element, 0, 1, 0 ); +}); + +test( "{ active: Selector }", function() { + expect( 2 ); + var element = $("#list1").accordion({ + active: "h3:last" + }); + accordion_state( element, 0, 0, 1 ); + element.accordion( "option", "active", "h3:eq(1)" ); + accordion_state( element, 0, 1, 0 ); +}); + +test( "{ active: Element }", function() { + expect( 2 ); + var element = $( "#list1" ).accordion({ + active: $( "#list1 h3:last" )[ 0 ] + }); + accordion_state( element, 0, 0, 1 ); + element.accordion( "option", "active", $( "#list1 h3:eq(1)" )[ 0 ] ); + accordion_state( element, 0, 1, 0 ); +}); + +test( "{ active: jQuery Object }", function() { + expect( 2 ); + var element = $( "#list1" ).accordion({ + active: $( "#list1 h3:last" ) + }); + accordion_state( element, 0, 0, 1 ); + element.accordion( "option", "active", $( "#list1 h3:eq(1)" ) ); + accordion_state( element, 0, 1, 0 ); +}); + + + + + +module( "accordion (deprecated) - height options", accordion_setupTeardown() ); + +test( "{ autoHeight: true }, default", function() { + expect( 3 ); + accordion_equalHeights( $( "#navigation" ).accordion({ autoHeight: true }), 95, 130 ); +}); + +test( "{ autoHeight: false }", function() { + expect( 3 ); + var element = $( "#navigation" ).accordion({ autoHeight: false }); + var sizes = []; + element.find( ".ui-accordion-content" ).each(function() { + sizes.push( $(this).height() ); + }); + ok( sizes[0] >= 70 && sizes[0] <= 105, "was " + sizes[0] ); + ok( sizes[1] >= 98 && sizes[1] <= 126, "was " + sizes[1] ); + ok( sizes[2] >= 42 && sizes[2] <= 54, "was " + sizes[2] ); +}); + +test( "{ fillSpace: true }", function() { + expect( 3 ); + $( "#navigationWrapper" ).height( 500 ); + var element = $( "#navigation" ).accordion({ fillSpace: true }); + accordion_equalHeights( element, 446, 458 ); +}); + +test( "{ fillSapce: true } with sibling", function() { + expect( 3 ); + $( "#navigationWrapper" ).height( 500 ); + $( "<p>Lorem Ipsum</p>" ) + .css({ + height: 50, + marginTop: 20, + marginBottom: 30 + }) + .prependTo( "#navigationWrapper" ); + var element = $( "#navigation" ).accordion({ fillSpace: true }); + accordion_equalHeights( element , 346, 358); +}); + +test( "{ fillSpace: true } with multiple siblings", function() { + expect( 3 ); + $( "#navigationWrapper" ).height( 500 ); + $( "<p>Lorem Ipsum</p>" ) + .css({ + height: 50, + marginTop: 20, + marginBottom: 30 + }) + .prependTo( "#navigationWrapper" ); + $( "<p>Lorem Ipsum</p>" ) + .css({ + height: 50, + marginTop: 20, + marginBottom: 30, + position: "absolute" + }) + .prependTo( "#navigationWrapper" ); + $( "<p>Lorem Ipsum</p>" ) + .css({ + height: 25, + marginTop: 10, + marginBottom: 15 + }) + .prependTo( "#navigationWrapper" ); + var element = $( "#navigation" ).accordion({ fillSpace: true }); + accordion_equalHeights( element, 296, 308 ); +}); + + + + + +module( "accordion (deprecated) - icons", accordion_setupTeardown() ); + +test( "icons, headerSelected", function() { + expect( 3 ); + var element = $( "#list1" ).accordion({ + icons: { headerSelected: "a1", header: "h1" } + }); + ok( element.find( ".ui-accordion-header.ui-state-active span.ui-icon" ).hasClass( "a1" ) ); + element.accordion( "option", "icons", { headerSelected: "a2", header: "h2" } ); + ok( !element.find( ".ui-accordion-header.ui-state-active span.ui-icon" ).hasClass( "a1" ) ); + ok( element.find( ".ui-accordion-header.ui-state-active span.ui-icon" ).hasClass( "a2" ) ); +}); + + + + + +module( "accordion (deprecated) - resize", accordion_setupTeardown() ); + +test( "resize", function() { + expect( 6 ); + var element = $( "#navigation" ) + .parent() + .height( 300 ) + .end() + .accordion({ + heightStyle: "fill" + }); + accordion_equalHeights( element, 246, 258 ); + + element.parent().height( 500 ); + element.accordion( "resize" ); + accordion_equalHeights( element, 446, 458 ); +}); + + + + + +module( "accordion (deprecated) - navigation", accordion_setupTeardown() ); + +test( "{ navigation: true, navigationFilter: header }", function() { + expect( 2 ); + var element = $( "#navigation" ).accordion({ + navigation: true, + navigationFilter: function() { + return /\?p=1\.1\.3$/.test( this.href ); + } + }); + equal( element.accordion( "option", "active" ), 2 ); + accordion_state( element, 0, 0, 1 ); +}); + +test( "{ navigation: true, navigationFilter: content }", function() { + expect( 2 ); + var element = $( "#navigation" ).accordion({ + navigation: true, + navigationFilter: function() { + return /\?p=1\.1\.3\.2$/.test( this.href ); + } + }); + equal( element.accordion( "option", "active" ), 2 ); + accordion_state( element, 0, 0, 1 ); +}); + + + + + +module( "accordion (deprecated) - changestart/change events", accordion_setupTeardown() ); + +test( "changestart", function() { + expect( 26 ); + var element = $( "#list1" ).accordion({ + active: false, + collapsible: true + }); + var headers = element.find( ".ui-accordion-header" ); + var content = element.find( ".ui-accordion-content" ); + + element.one( "accordionchangestart", function( event, ui ) { + equal( ui.oldHeader.size(), 0 ); + equal( ui.oldContent.size(), 0 ); + equal( ui.newHeader.size(), 1 ); + strictEqual( ui.newHeader[ 0 ], headers[ 0 ] ); + equal( ui.newContent.size(), 1 ); + strictEqual( ui.newContent[ 0 ], content[ 0 ] ); + accordion_state( element, 0, 0, 0 ); + }); + element.accordion( "option", "active", 0 ); + accordion_state( element, 1, 0, 0 ); + + element.one( "accordionchangestart", function( event, ui ) { + equal( ui.oldHeader.size(), 1 ); + strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] ); + equal( ui.oldContent.size(), 1 ); + strictEqual( ui.oldContent[ 0 ], content[ 0 ] ); + equal( ui.newHeader.size(), 1 ); + strictEqual( ui.newHeader[ 0 ], headers[ 1 ] ); + equal( ui.newContent.size(), 1 ); + strictEqual( ui.newContent[ 0 ], content[ 1 ] ); + accordion_state( element, 1, 0, 0 ); + }); + headers.eq( 1 ).click(); + accordion_state( element, 0, 1, 0 ); + + element.one( "accordionchangestart", function( event, ui ) { + equal( ui.oldHeader.size(), 1 ); + strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] ); + equal( ui.oldContent.size(), 1 ); + strictEqual( ui.oldContent[ 0 ], content[ 1 ] ); + equal( ui.newHeader.size(), 0 ); + equal( ui.newContent.size(), 0 ); + accordion_state( element, 0, 1, 0 ); + }); + element.accordion( "option", "active", false ); + accordion_state( element, 0, 0, 0 ); +}); + +test( "change", function() { + expect( 20 ); + var element = $( "#list1" ).accordion({ + active: false, + collapsible: true + }); + var headers = element.find( ".ui-accordion-header" ); + var content = element.find( ".ui-accordion-content" ); + + element.one( "accordionchange", function( event, ui ) { + equal( ui.oldHeader.size(), 0 ); + equal( ui.oldContent.size(), 0 ); + equal( ui.newHeader.size(), 1 ); + strictEqual( ui.newHeader[ 0 ], headers[ 0 ] ); + equal( ui.newContent.size(), 1 ); + strictEqual( ui.newContent[ 0 ], content[ 0 ] ); + }); + element.accordion( "option", "active", 0 ); + + element.one( "accordionchange", function( event, ui ) { + equal( ui.oldHeader.size(), 1 ); + strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] ); + equal( ui.oldContent.size(), 1 ); + strictEqual( ui.oldContent[ 0 ], content[ 0 ] ); + equal( ui.newHeader.size(), 1 ); + strictEqual( ui.newHeader[ 0 ], headers[ 1 ] ); + equal( ui.newContent.size(), 1 ); + strictEqual( ui.newContent[ 0 ], content[ 1 ] ); + }); + headers.eq( 1 ).click(); + + element.one( "accordionchange", function( event, ui ) { + equal( ui.oldHeader.size(), 1 ); + strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] ); + equal( ui.oldContent.size(), 1 ); + strictEqual( ui.oldContent[ 0 ], content[ 1 ] ); + equal( ui.newHeader.size(), 0 ); + equal( ui.newContent.size(), 0 ); + }); + element.accordion( "option", "active", false ); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion_events.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion_events.js new file mode 100644 index 0000000..12acf2a --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion_events.js @@ -0,0 +1,122 @@ +(function( $ ) { + +module( "accordion: events", accordion_setupTeardown() ); + +test( "beforeActivate", function() { + expect( 38 ); + var element = $( "#list1" ).accordion({ + active: false, + collapsible: true + }); + var headers = element.find( ".ui-accordion-header" ); + var content = element.find( ".ui-accordion-content" ); + + element.one( "accordionbeforeactivate", function( event, ui ) { + ok( !( "originalEvent" in event ) ); + equal( ui.oldHeader.size(), 0 ); + equal( ui.oldContent.size(), 0 ); + equal( ui.newHeader.size(), 1 ); + strictEqual( ui.newHeader[ 0 ], headers[ 0 ] ); + equal( ui.newContent.size(), 1 ); + strictEqual( ui.newContent[ 0 ], content[ 0 ] ); + accordion_state( element, 0, 0, 0 ); + }); + element.accordion( "option", "active", 0 ); + accordion_state( element, 1, 0, 0 ); + + element.one( "accordionbeforeactivate", function( event, ui ) { + equal( event.originalEvent.type, "click" ); + equal( ui.oldHeader.size(), 1 ); + strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] ); + equal( ui.oldContent.size(), 1 ); + strictEqual( ui.oldContent[ 0 ], content[ 0 ] ); + equal( ui.newHeader.size(), 1 ); + strictEqual( ui.newHeader[ 0 ], headers[ 1 ] ); + equal( ui.newContent.size(), 1 ); + strictEqual( ui.newContent[ 0 ], content[ 1 ] ); + accordion_state( element, 1, 0, 0 ); + }); + headers.eq( 1 ).click(); + accordion_state( element, 0, 1, 0 ); + + element.one( "accordionbeforeactivate", function( event, ui ) { + ok( !( "originalEvent" in event ) ); + equal( ui.oldHeader.size(), 1 ); + strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] ); + equal( ui.oldContent.size(), 1 ); + strictEqual( ui.oldContent[ 0 ], content[ 1 ] ); + equal( ui.newHeader.size(), 0 ); + equal( ui.newContent.size(), 0 ); + accordion_state( element, 0, 1, 0 ); + }); + element.accordion( "option", "active", false ); + accordion_state( element, 0, 0, 0 ); + + element.one( "accordionbeforeactivate", function( event, ui ) { + ok( !( "originalEvent" in event ) ); + equal( ui.oldHeader.size(), 0 ); + equal( ui.oldContent.size(), 0 ); + equal( ui.newHeader.size(), 1 ); + strictEqual( ui.newHeader[ 0 ], headers[ 2 ] ); + equal( ui.newContent.size(), 1 ); + strictEqual( ui.newContent[ 0 ], content[ 2 ] ); + event.preventDefault(); + accordion_state( element, 0, 0, 0 ); + }); + element.accordion( "option", "active", 2 ); + accordion_state( element, 0, 0, 0 ); +}); + +test( "activate", function() { + expect( 21 ); + var element = $( "#list1" ).accordion({ + active: false, + collapsible: true + }); + var headers = element.find( ".ui-accordion-header" ); + var content = element.find( ".ui-accordion-content" ); + + element.one( "accordionactivate", function( event, ui ) { + equal( ui.oldHeader.size(), 0 ); + equal( ui.oldContent.size(), 0 ); + equal( ui.newHeader.size(), 1 ); + strictEqual( ui.newHeader[ 0 ], headers[ 0 ] ); + equal( ui.newContent.size(), 1 ); + strictEqual( ui.newContent[ 0 ], content[ 0 ] ); + }); + element.accordion( "option", "active", 0 ); + + element.one( "accordionactivate", function( event, ui ) { + equal( ui.oldHeader.size(), 1 ); + strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] ); + equal( ui.oldContent.size(), 1 ); + strictEqual( ui.oldContent[ 0 ], content[ 0 ] ); + equal( ui.newHeader.size(), 1 ); + strictEqual( ui.newHeader[ 0 ], headers[ 1 ] ); + equal( ui.newContent.size(), 1 ); + strictEqual( ui.newContent[ 0 ], content[ 1 ] ); + }); + headers.eq( 1 ).click(); + + element.one( "accordionactivate", function( event, ui ) { + equal( ui.oldHeader.size(), 1 ); + strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] ); + equal( ui.oldContent.size(), 1 ); + strictEqual( ui.oldContent[ 0 ], content[ 1 ] ); + equal( ui.newHeader.size(), 0 ); + equal( ui.newContent.size(), 0 ); + }); + element.accordion( "option", "active", false ); + + // prevent activation + element.one( "accordionbeforeactivate", function( event ) { + ok( true ); + event.preventDefault(); + }); + element.one( "accordionactivate", function() { + ok( false ); + }); + element.accordion( "option", "active", 1 ); +}); + +}( jQuery ) ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion_methods.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion_methods.js new file mode 100644 index 0000000..9f61647 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion_methods.js @@ -0,0 +1,40 @@ +(function( $ ) { + +module( "accordion: methods", accordion_setupTeardown() ); + +test( "destroy", function() { + expect( 1 ); + domEqual( "#list1", function() { + $( "#list1" ).accordion().accordion( "destroy" ); + }); +}); + +test( "enable/disable", function() { + expect( 3 ); + var element = $( "#list1" ).accordion(); + accordion_state( element, 1, 0, 0 ); + element.accordion( "disable" ); + element.accordion( "option", "active", 1 ); + accordion_state( element, 1, 0, 0 ); + element.accordion( "enable" ); + element.accordion( "option", "active", 1 ); + accordion_state( element, 0, 1, 0 ); +}); + +test( "refresh", function() { + expect( 6 ); + var element = $( "#navigation" ) + .parent() + .height( 300 ) + .end() + .accordion({ + heightStyle: "fill" + }); + accordion_equalHeights( element, 246, 258 ); + + element.parent().height( 500 ); + element.accordion( "refresh" ); + accordion_equalHeights( element, 446, 458 ); +}); + +}( jQuery ) ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion_options.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion_options.js new file mode 100644 index 0000000..a60bb27 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion_options.js @@ -0,0 +1,283 @@ +(function( $ ) { + +module( "accordion: options", accordion_setupTeardown() ); + +test( "{ active: default }", function() { + expect( 2 ); + var element = $( "#list1" ).accordion(); + equal( element.accordion( "option", "active" ), 0 ); + accordion_state( element, 1, 0, 0 ); +}); + +test( "{ active: false }", function() { + expect( 7 ); + var element = $( "#list1" ).accordion({ + active: false, + collapsible: true + }); + accordion_state( element, 0, 0, 0 ); + equal( element.find( ".ui-accordion-header.ui-state-active" ).size(), 0, "no headers selected" ); + equal( element.accordion( "option", "active" ), false ); + + element.accordion( "option", "collapsible", false ); + accordion_state( element, 1, 0, 0 ); + equal( element.accordion( "option", "active" ), 0 ); + + element.accordion( "destroy" ); + element.accordion({ + active: false + }); + accordion_state( element, 1, 0, 0 ); + strictEqual( element.accordion( "option", "active" ), 0 ); +}); + +test( "{ active: Number }", function() { + expect( 8 ); + var element = $( "#list1" ).accordion({ + active: 2 + }); + equal( element.accordion( "option", "active" ), 2 ); + accordion_state( element, 0, 0, 1 ); + + element.accordion( "option", "active", 0 ); + equal( element.accordion( "option", "active" ), 0 ); + accordion_state( element, 1, 0, 0 ); + + element.find( ".ui-accordion-header" ).eq( 1 ).click(); + equal( element.accordion( "option", "active" ), 1 ); + accordion_state( element, 0, 1, 0 ); + + element.accordion( "option", "active", 10 ); + equal( element.accordion( "option", "active" ), 1 ); + accordion_state( element, 0, 1, 0 ); +}); + +if ( $.uiBackCompat === false ) { + test( "{ active: -Number }", function() { + expect( 8 ); + var element = $( "#list1" ).accordion({ + active: -1 + }); + equal( element.accordion( "option", "active" ), 2 ); + accordion_state( element, 0, 0, 1 ); + + element.accordion( "option", "active", -2 ); + equal( element.accordion( "option", "active" ), 1 ); + accordion_state( element, 0, 1, 0 ); + + element.accordion( "option", "active", -10 ); + equal( element.accordion( "option", "active" ), 1 ); + accordion_state( element, 0, 1, 0 ); + + element.accordion( "option", "active", -3 ); + equal( element.accordion( "option", "active" ), 0 ); + accordion_state( element, 1, 0, 0 ); + }); +} + +// TODO: add animation tests + +test( "{ collapsible: false }", function() { + expect( 4 ); + var element = $( "#list1" ).accordion({ + active: 1 + }); + element.accordion( "option", "active", false ); + equal( element.accordion( "option", "active" ), 1 ); + accordion_state( element, 0, 1, 0 ); + + element.find( ".ui-accordion-header" ).eq( 1 ).click(); + equal( element.accordion( "option", "active" ), 1 ); + accordion_state( element, 0, 1, 0 ); +}); + +test( "{ collapsible: true }", function() { + expect( 6 ); + var element = $( "#list1" ).accordion({ + active: 1, + collapsible: true + }); + + element.accordion( "option", "active", false ); + equal( element.accordion( "option", "active" ), false ); + accordion_state( element, 0, 0, 0 ); + + element.accordion( "option", "active", 1 ); + equal( element.accordion( "option", "active" ), 1 ); + accordion_state( element, 0, 1, 0 ); + + element.find( ".ui-accordion-header" ).eq( 1 ).click(); + equal( element.accordion( "option", "active" ), false ); + accordion_state( element, 0, 0, 0 ); +}); + +test( "{ event: null }", function() { + expect( 5 ); + var element = $( "#list1" ).accordion({ + event: null + }); + accordion_state( element, 1, 0, 0 ); + + element.accordion( "option", "active", 1 ); + equal( element.accordion( "option", "active" ), 1 ); + accordion_state( element, 0, 1, 0 ); + + // ensure default click handler isn't bound + element.find( ".ui-accordion-header" ).eq( 2 ).click(); + equal( element.accordion( "option", "active" ), 1 ); + accordion_state( element, 0, 1, 0 ); +}); + +test( "{ event: custom }", function() { + expect( 11 ); + var element = $( "#list1" ).accordion({ + event: "custom1 custom2" + }); + accordion_state( element, 1, 0, 0 ); + + element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "custom1" ); + equal( element.accordion( "option", "active" ), 1 ); + accordion_state( element, 0, 1, 0 ); + + // ensure default click handler isn't bound + element.find( ".ui-accordion-header" ).eq( 2 ).trigger( "click" ); + equal( element.accordion( "option", "active" ), 1 ); + accordion_state( element, 0, 1, 0 ); + + element.find( ".ui-accordion-header" ).eq( 2 ).trigger( "custom2" ); + equal( element.accordion( "option", "active" ), 2 ); + accordion_state( element, 0, 0, 1 ); + + element.accordion( "option", "event", "custom3" ); + + // ensure old event handlers are unbound + element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "custom1" ); + equal( element.accordion( "option", "active" ), 2 ); + accordion_state( element, 0, 0, 1 ); + + element.find( ".ui-accordion-header" ).eq( 1 ).trigger( "custom3" ); + equal( element.accordion( "option", "active" ), 1 ); + accordion_state( element, 0, 1, 0 ); +}); + +test( "{ header: default }", function() { + expect( 2 ); + // default: > li > :first-child,> :not(li):even + // > :not(li):even + accordion_state( $( "#list1" ).accordion(), 1, 0, 0); + // > li > :first-child + accordion_state( $( "#navigation" ).accordion(), 1, 0, 0); +}); + +test( "{ header: custom }", function() { + expect( 6 ); + var element = $( "#navigationWrapper" ).accordion({ + header: "h2" + }); + element.find( "h2" ).each(function() { + ok( $( this ).hasClass( "ui-accordion-header" ) ); + }); + equal( element.find( ".ui-accordion-header" ).length, 3 ); + accordion_state( element, 1, 0, 0 ); + element.accordion( "option", "active", 2 ); + accordion_state( element, 0, 0, 1 ); +}); + +test( "{ heightStyle: 'auto' }", function() { + expect( 3 ); + var element = $( "#navigation" ).accordion({ heightStyle: "auto" }); + accordion_equalHeights( element, 95, 130 ); +}); + +test( "{ heightStyle: 'content' }", function() { + expect( 3 ); + var element = $( "#navigation" ).accordion({ heightStyle: "content" }); + var sizes = element.find( ".ui-accordion-content" ).map(function() { + return $( this ).height(); + }).get(); + ok( sizes[ 0 ] >= 70 && sizes[ 0 ] <= 105, "was " + sizes[ 0 ] ); + ok( sizes[ 1 ] >= 98 && sizes[ 1 ] <= 126, "was " + sizes[ 1 ] ); + ok( sizes[ 2 ] >= 42 && sizes[ 2 ] <= 54, "was " + sizes[ 2 ] ); +}); + +test( "{ heightStyle: 'fill' }", function() { + expect( 3 ); + $( "#navigationWrapper" ).height( 500 ); + var element = $( "#navigation" ).accordion({ heightStyle: "fill" }); + accordion_equalHeights( element, 446, 458 ); +}); + +test( "{ heightStyle: 'fill' } with sibling", function() { + expect( 3 ); + $( "#navigationWrapper" ).height( 500 ); + $( "<p>Lorem Ipsum</p>" ) + .css({ + height: 50, + marginTop: 20, + marginBottom: 30 + }) + .prependTo( "#navigationWrapper" ); + var element = $( "#navigation" ).accordion({ heightStyle: "fill" }); + accordion_equalHeights( element , 346, 358); +}); + +test( "{ heightStyle: 'fill' } with multiple siblings", function() { + expect( 3 ); + $( "#navigationWrapper" ).height( 500 ); + $( "<p>Lorem Ipsum</p>" ) + .css({ + height: 50, + marginTop: 20, + marginBottom: 30 + }) + .prependTo( "#navigationWrapper" ); + $( "<p>Lorem Ipsum</p>" ) + .css({ + height: 50, + marginTop: 20, + marginBottom: 30, + position: "absolute" + }) + .prependTo( "#navigationWrapper" ); + $( "<p>Lorem Ipsum</p>" ) + .css({ + height: 25, + marginTop: 10, + marginBottom: 15 + }) + .prependTo( "#navigationWrapper" ); + var element = $( "#navigation" ).accordion({ heightStyle: "fill" }); + accordion_equalHeights( element, 296, 308 ); +}); + +test( "{ icons: false }", function() { + expect( 8 ); + var element = $( "#list1" ); + function icons( on ) { + deepEqual( element.find( "span.ui-icon").length, on ? 3 : 0 ); + deepEqual( element.hasClass( "ui-accordion-icons" ), on ); + } + element.accordion(); + icons( true ); + element.accordion( "destroy" ).accordion({ + icons: false + }); + icons( false ); + element.accordion( "option", "icons", { header: "foo", activeHeader: "bar" } ); + icons( true ); + element.accordion( "option", "icons", false ); + icons( false ); +}); + +test( "{ icons: hash }", function() { + expect( 3 ); + var element = $( "#list1" ).accordion({ + icons: { activeHeader: "a1", header: "h1" } + }); + ok( element.find( ".ui-accordion-header.ui-state-active span.ui-icon" ).hasClass( "a1" ) ); + element.accordion( "option", "icons", { activeHeader: "a2", header: "h2" } ); + ok( !element.find( ".ui-accordion-header.ui-state-active span.ui-icon" ).hasClass( "a1" ) ); + ok( element.find( ".ui-accordion-header.ui-state-active span.ui-icon" ).hasClass( "a2" ) ); +}); + +}( jQuery ) ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion_test_helpers.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion_test_helpers.js new file mode 100644 index 0000000..66d60a4 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/accordion_test_helpers.js @@ -0,0 +1,30 @@ +function accordion_state( accordion ) { + var expected = $.makeArray( arguments ).slice( 1 ); + var actual = accordion.find( ".ui-accordion-content" ).map(function() { + return $( this ).css( "display" ) === "none" ? 0 : 1; + }).get(); + deepEqual( actual, expected ); +} + +function accordion_equalHeights( accordion, min, max ) { + var sizes = []; + accordion.find( ".ui-accordion-content" ).each(function() { + sizes.push( $( this ).outerHeight() ); + }); + ok( sizes[ 0 ] >= min && sizes[ 0 ] <= max, + "must be within " + min + " and " + max + ", was " + sizes[ 0 ] ); + deepEqual( sizes[ 0 ], sizes[ 1 ] ); + deepEqual( sizes[ 0 ], sizes[ 2 ] ); +} + +function accordion_setupTeardown() { + var animated = $.ui.accordion.prototype.options.animated; + return { + setup: function() { + $.ui.accordion.prototype.options.animated = false; + }, + teardown: function() { + $.ui.accordion.prototype.options.animated = animated; + } + }; +} diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/all.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/all.html new file mode 100644 index 0000000..0d600e1 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/accordion/all.html @@ -0,0 +1,30 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Accordion Test Suite</title> + + <script src="../../../jquery-1.7.1.js"></script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <link rel="stylesheet" href="../subsuiteRunner.css"> + <script src="../../../external/qunit.js"></script> + <script src="../subsuiteRunner.js"></script> + <script src="../subsuite.js"></script> + + <script> + testAllVersions( "accordion" ); + </script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Accordion Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/all.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/all.html new file mode 100644 index 0000000..d5152bb --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/all.html @@ -0,0 +1,72 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Test Suite</title> + + <script src="../../jquery-1.7.1.js"></script> + + <link rel="stylesheet" href="../../external/qunit.css"> + <link rel="stylesheet" href="subsuiteRunner.css"> + <script src="../../external/qunit.js"></script> + <script src="subsuiteRunner.js"></script> + + <script> + (function() { + + var params = [], + suites = [ + "accordion/accordion.html", + "accordion/accordion_deprecated.html", + "autocomplete/autocomplete.html", + "button/button.html", + "core/core.html", + "datepicker/datepicker.html", + "dialog/dialog.html", + //"draggable/draggable.html", + //"droppable/droppable.html", + "effects/effects.html", + "menu/menu.html", + "position/position.html", + "position/position_deprecated.html", + "progressbar/progressbar.html", + //"resizable/resizable.html", + //"selectable/selectable.html", + "slider/slider.html", + //"sortable/sortable.html", + "spinner/spinner.html", + "tabs/tabs.html", + "tabs/tabs_deprecated.html", + "tooltip/tooltip.html", + "widget/widget.html" + ]; + + $.each( QUnit.urlParams, function( key, value ) { + if ( key === "filter" ) { + return; + } + params.push( encodeURIComponent( key ) + "=" + encodeURIComponent( value ) ); + }); + if ( params.length ) { + params = "?" + params.join( "&" ); + suites = $.map( suites, function( suite ) { + return suite + params; + }); + } + QUnit.testSuites( suites ); + + }()); + </script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/all.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/all.html new file mode 100644 index 0000000..c644e27 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/all.html @@ -0,0 +1,30 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Autocomplete Test Suite</title> + + <script src="../../../jquery-1.7.1.js"></script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <link rel="stylesheet" href="../subsuiteRunner.css"> + <script src="../../../external/qunit.js"></script> + <script src="../subsuiteRunner.js"></script> + <script src="../subsuite.js"></script> + + <script> + testAllVersions( "autocomplete" ); + </script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Autocomplete Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/autocomplete.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/autocomplete.html new file mode 100644 index 0000000..70d2ecf --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/autocomplete.html @@ -0,0 +1,51 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Autocomplete Test Suite</title> + + <script src="../../jquery.js"></script> + <script src="../../resource_loader.js"></script> + <script> + loadResources({ + css: [ "ui.core", "ui.menu", "ui.autocomplete" ], + js: [ + "ui/jquery.ui.core.js", + "ui/jquery.ui.widget.js", + "ui/jquery.ui.position.js", + "ui/jquery.ui.menu.js", + "ui/jquery.ui.autocomplete.js" + ] + }); + </script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <script src="../../../external/qunit.js"></script> + <script src="../../jquery.simulate.js"></script> + <script src="../testsuite.js"></script> + + <script src="autocomplete_defaults.js"></script> + <script src="autocomplete_core.js"></script> + <script src="autocomplete_events.js"></script> + <script src="autocomplete_methods.js"></script> + <script src="autocomplete_options.js"></script> + + <script src="../swarminject.js"></script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Autocomplete Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +<div id="ac-wrap1" class="ac-wrap"></div> +<div id="ac-wrap2" class="ac-wrap"><input id="autocomplete" class="foo"></div> +<div id="autocomplete-contenteditable" contenteditable="" tabindex=0></div> +<textarea id="autocomplete-textarea"></textarea> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/autocomplete_core.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/autocomplete_core.js new file mode 100644 index 0000000..3f92aa0 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/autocomplete_core.js @@ -0,0 +1,83 @@ +(function( $ ) { + +module( "autocomplete: core" ); + +asyncTest( "close-on-blur is properly delayed", function() { + expect( 3 ); + var element = $( "#autocomplete" ) + .autocomplete({ + source: [ "java", "javascript" ] + }) + .val( "ja" ) + .autocomplete( "search" ), + menu = element.autocomplete( "widget" ); + + ok( menu.is( ":visible" ) ); + element.blur(); + ok( menu.is( ":visible" ) ); + setTimeout(function() { + ok( menu.is( ":hidden") ); + start(); + }, 200 ); +}); + +asyncTest( "close-on-blur is cancelled when starting a search", function() { + expect( 3 ); + var element = $( "#autocomplete" ) + .autocomplete({ + source: [ "java", "javascript" ] + }) + .val( "ja" ) + .autocomplete( "search" ), + menu = element.autocomplete( "widget" ); + + ok( menu.is( ":visible" ) ); + element.blur(); + ok( menu.is( ":visible" ) ); + element.autocomplete( "search" ); + setTimeout(function() { + ok( menu.is( ":visible" ) ); + start(); + }, 200 ); +}); + +test( "prevent form submit on enter when menu is active", function() { + expect( 2 ); + var event, + element = $( "#autocomplete" ) + .autocomplete({ + source: [ "java", "javascript" ] + }) + .val( "ja" ) + .autocomplete( "search" ), + menu = element.autocomplete( "widget" ); + + event = $.Event( "keydown" ); + event.keyCode = $.ui.keyCode.DOWN; + element.trigger( event ); + deepEqual( menu.find( ".ui-menu-item:has(.ui-state-focus)" ).length, 1, "menu item is active" ); + + event = $.Event( "keydown" ); + event.keyCode = $.ui.keyCode.ENTER; + element.trigger( event ); + ok( event.isDefaultPrevented(), "default action is prevented" ); +}); + +test( "allow form submit on enter when menu is not active", function() { + expect( 1 ); + var event, + element = $( "#autocomplete" ) + .autocomplete({ + autoFocus: false, + source: [ "java", "javascript" ] + }) + .val( "ja" ) + .autocomplete( "search" ); + + event = $.Event( "keydown" ); + event.keyCode = $.ui.keyCode.ENTER; + element.trigger( event ); + ok( !event.isDefaultPrevented(), "default action is prevented" ); +}); + +}( jQuery ) ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/autocomplete_defaults.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/autocomplete_defaults.js new file mode 100644 index 0000000..ac83eae --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/autocomplete_defaults.js @@ -0,0 +1,25 @@ +commonWidgetTests( "autocomplete", { + defaults: { + appendTo: "body", + autoFocus: false, + delay: 300, + disabled: false, + minLength: 1, + position: { + my: "left top", + at: "left bottom", + collision: "none" + }, + source: null, + + // callbacks + change: null, + close: null, + create: null, + focus: null, + open: null, + response: null, + search: null, + select: null + } +}); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/autocomplete_events.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/autocomplete_events.js new file mode 100644 index 0000000..7b51ec4 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/autocomplete_events.js @@ -0,0 +1,179 @@ +(function( $ ) { + +module( "autocomplete: events" ); + +var data = [ "Clojure", "COBOL", "ColdFusion", "Java", "JavaScript", "Scala", "Scheme" ]; + +$.each([ + { + type: "input", + selector: "#autocomplete", + valueMethod: "val" + }, + { + type: "textarea", + selector: "#autocomplete-textarea", + valueMethod: "val" + }, + { + type: "contenteditable", + selector: "#autocomplete-contenteditable", + valueMethod: "text" + } +], function( i, settings ) { + asyncTest( "all events - " + settings.type, function() { + expect( 13 ); + var element = $( settings.selector ) + .autocomplete({ + autoFocus: false, + delay: 0, + source: data, + search: function( event ) { + equal( event.originalEvent.type, "keydown", "search originalEvent" ); + }, + response: function( event, ui ) { + deepEqual( ui.content, [ + { label: "Clojure", value: "Clojure" }, + { label: "Java", value: "Java" }, + { label: "JavaScript", value: "JavaScript" } + ], "response ui.content" ); + ui.content.splice( 0, 1 ); + }, + open: function( event ) { + ok( menu.is( ":visible" ), "menu open on open" ); + }, + focus: function( event, ui ) { + equal( event.originalEvent.type, "menufocus", "focus originalEvent" ); + deepEqual( ui.item, { label: "Java", value: "Java" }, "focus ui.item" ); + }, + close: function( event ) { + equal( event.originalEvent.type, "menuselect", "close originalEvent" ); + ok( menu.is( ":hidden" ), "menu closed on close" ); + }, + select: function( event, ui ) { + equal( event.originalEvent.type, "menuselect", "select originalEvent" ); + deepEqual( ui.item, { label: "Java", value: "Java" }, "select ui.item" ); + }, + change: function( event, ui ) { + equal( event.originalEvent.type, "blur", "change originalEvent" ); + deepEqual( ui.item, { label: "Java", value: "Java" }, "change ui.item" ); + ok( menu.is( ":hidden" ), "menu closed on change" ); + start(); + } + }), + menu = element.autocomplete( "widget" ); + + element.simulate( "focus" )[ settings.valueMethod ]( "j" ).keydown(); + setTimeout(function() { + ok( menu.is( ":visible" ), "menu is visible after delay" ); + element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); + element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); + element.simulate( "blur" ); + }, 50 ); + }); +}); + +asyncTest( "change without selection", function() { + expect( 1 ); + var element = $( "#autocomplete" ).autocomplete({ + delay: 0, + source: data, + change: function( event, ui ) { + strictEqual( ui.item, null ); + start(); + } + }); + element.triggerHandler( "focus" ); + element.val( "ja" ).triggerHandler( "blur" ); +}); + +asyncTest( "cancel search", function() { + expect( 6 ); + var first = true, + element = $( "#autocomplete" ).autocomplete({ + delay: 0, + source: data, + search: function() { + if ( first ) { + equal( element.val(), "ja", "val on first search" ); + first = false; + return false; + } + equal( element.val(), "java", "val on second search" ); + }, + open: function() { + ok( true, "menu opened" ); + } + }), + menu = element.autocomplete( "widget" ); + element.val( "ja" ).keydown(); + setTimeout(function() { + ok( menu.is( ":hidden" ), "menu is hidden after first search" ); + element.val( "java" ).keydown(); + setTimeout(function() { + ok( menu.is( ":visible" ), "menu is visible after second search" ); + equal( menu.find( ".ui-menu-item" ).length, 2, "# of menu items" ); + start(); + }, 50 ); + }, 50 ); +}); + +asyncTest( "cancel focus", function() { + expect( 1 ); + var customVal = "custom value"; + element = $( "#autocomplete" ).autocomplete({ + delay: 0, + source: data, + focus: function( event, ui ) { + $( this ).val( customVal ); + return false; + } + }); + element.val( "ja" ).keydown(); + setTimeout(function() { + element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); + equal( element.val(), customVal ); + start(); + }, 50 ); +}); + +asyncTest( "cancel select", function() { + expect( 1 ); + var customVal = "custom value", + element = $( "#autocomplete" ).autocomplete({ + delay: 0, + source: data, + select: function( event, ui ) { + $( this ).val( customVal ); + return false; + } + }); + element.val( "ja" ).keydown(); + setTimeout(function() { + element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); + element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); + equal( element.val(), customVal ); + start(); + }, 50 ); +}); + +asyncTest( "blur during remote search", function() { + expect( 1 ); + var ac = $( "#autocomplete" ).autocomplete({ + delay: 0, + source: function( request, response ) { + ok( true, "trigger request" ); + ac.simulate( "blur" ); + setTimeout(function() { + response([ "result" ]); + start(); + }, 100 ); + }, + open: function() { + ok( false, "opened after a blur" ); + } + }); + ac.val( "ro" ).keydown(); +}); + +}( jQuery ) ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/autocomplete_methods.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/autocomplete_methods.js new file mode 100644 index 0000000..3fe035d --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/autocomplete_methods.js @@ -0,0 +1,30 @@ +(function( $ ) { + +module( "autocomplete: methods" ); + +test( "destroy", function() { + expect( 1 ); + domEqual( "#autocomplete", function() { + $( "#autocomplete" ).autocomplete().autocomplete( "destroy" ); + }); +}); + +test( "search", function() { + expect( 3 ); + var data = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl" ], + element = $( "#autocomplete" ).autocomplete({ + source: data, + minLength: 0 + }), + menu = element.autocomplete( "widget" ); + element.autocomplete( "search" ); + equal( menu.find( ".ui-menu-item" ).length, data.length, "all items for a blank search" ); + + element.val( "has" ).autocomplete( "search" ); + equal( menu.find( ".ui-menu-item" ).text(), "haskell", "only one item for set input value" ); + + element.autocomplete( "search", "ja" ); + equal( menu.find( ".ui-menu-item" ).length, 2, "only java and javascript for 'ja'" ); +}); + +}( jQuery ) ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/autocomplete_options.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/autocomplete_options.js new file mode 100644 index 0000000..114e9a4 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/autocomplete_options.js @@ -0,0 +1,193 @@ +(function( $ ) { + +module( "autocomplete: options" ); + +var data = [ "c++", "java", "php", "coldfusion", "javascript", "asp", "ruby", "python", "c", "scala", "groovy", "haskell", "perl" ]; + +test( "appendTo", function() { + expect( 5 ); + var element = $( "#autocomplete" ).autocomplete(); + equal( element.autocomplete( "widget" ).parent()[0], document.body, "defaults to body" ); + element.autocomplete( "destroy" ); + + element.autocomplete({ + appendTo: ".ac-wrap" + }); + equal( element.autocomplete( "widget" ).parent()[0], $( "#ac-wrap1" )[0], "first found element" ); + equal( $( "#ac-wrap2 .ui-autocomplete" ).length, 0, "only appends to one element" ); + element.autocomplete( "destroy" ); + + element.autocomplete({ + appendTo: null + }); + equal( element.autocomplete( "widget" ).parent()[0], document.body, "null" ); + element.autocomplete( "destroy" ); + + element.autocomplete().autocomplete( "option", "appendTo", "#ac-wrap1" ); + equal( element.autocomplete( "widget" ).parent()[0], $( "#ac-wrap1" )[0], "modified after init" ); + element.autocomplete( "destroy" ); +}); + +function autoFocusTest( afValue, focusedLength ) { + var element = $( "#autocomplete" ).autocomplete({ + autoFocus: afValue, + delay: 0, + source: data, + open: function( event, ui ) { + equal( element.autocomplete( "widget" ).children( ".ui-menu-item:first" ).find( ".ui-state-focus" ).length, + focusedLength, "first item is " + (afValue ? "" : "not") + " auto focused" ); + start(); + } + }); + element.val( "ja" ).keydown(); + stop(); +} + +test( "autoFocus: false", function() { + expect( 1 ); + autoFocusTest( false, 0 ); +}); + +test( "autoFocus: true", function() { + expect( 1 ); + autoFocusTest( true, 1 ); +}); + +asyncTest( "delay", function() { + expect( 2 ); + var element = $( "#autocomplete" ).autocomplete({ + source: data, + delay: 50 + }), + menu = element.autocomplete( "widget" ); + element.val( "ja" ).keydown(); + + ok( menu.is( ":hidden" ), "menu is closed immediately after search" ); + + setTimeout(function() { + ok( menu.is( ":visible" ), "menu is open after delay" ); + start(); + }, 100 ); +}); + +asyncTest( "disabled", function() { + expect( 2 ); + var element = $( "#autocomplete" ).autocomplete({ + source: data, + delay: 0, + disabled: true + }), + menu = element.autocomplete( "widget" ); + element.val( "ja" ).keydown(); + + ok( menu.is( ":hidden" ) ); + + setTimeout(function() { + ok( menu.is( ":hidden" ) ); + start(); + }, 50 ); +}); + +test( "minLength", function() { + expect( 2 ); + var element = $( "#autocomplete" ).autocomplete({ + source: data + }), + menu = element.autocomplete( "widget" ); + element.autocomplete( "search", "" ); + ok( menu.is( ":hidden" ), "blank not enough for minLength: 1" ); + + element.autocomplete( "option", "minLength", 0 ); + element.autocomplete( "search", "" ); + ok( menu.is( ":visible" ), "blank enough for minLength: 0" ); +}); + +test( "source, local string array", function() { + expect( 1 ); + var element = $( "#autocomplete" ).autocomplete({ + source: data + }), + menu = element.autocomplete( "widget" ); + element.val( "ja" ).autocomplete( "search" ); + equal( menu.find( ".ui-menu-item" ).text(), "javajavascript" ); +}); + +function sourceTest( source, async ) { + var element = $( "#autocomplete" ).autocomplete({ + source: source + }), + menu = element.autocomplete( "widget" ); + function result() { + equal( menu.find( ".ui-menu-item" ).text(), "javajavascript" ); + element.autocomplete( "destroy" ); + if ( async ) { + start(); + } + } + if ( async ) { + stop(); + $( document ).one( "ajaxStop", result ); + } + element.val( "ja" ).autocomplete( "search" ); + if ( !async ) { + result(); + } +} + +test( "source, local object array, only label property", function() { + expect( 1 ); + sourceTest([ + { label: "java" }, + { label: "php" }, + { label: "coldfusion" }, + { label: "javascript" } + ]); +}); + +test( "source, local object array, only value property", function() { + expect( 1 ); + sourceTest([ + { value: "java" }, + { value: "php" }, + { value: "coldfusion" }, + { value: "javascript" } + ]); +}); + +test( "source, url string with remote json string array", function() { + expect( 1 ); + sourceTest( "remote_string_array.txt", true ); +}); + +test( "source, url string with remote json object array, only value properties", function() { + expect( 1 ); + sourceTest( "remote_object_array_values.txt", true ); +}); + +test( "source, url string with remote json object array, only label properties", function() { + expect( 1 ); + sourceTest( "remote_object_array_labels.txt", true ); +}); + +test( "source, custom", function() { + expect( 2 ); + sourceTest(function( request, response ) { + equal( request.term, "ja" ); + response( ["java", "javascript"] ); + }); +}); + +test( "source, update after init", function() { + expect( 2 ); + var element = $( "#autocomplete" ).autocomplete({ + source: [ "java", "javascript", "haskell" ] + }), + menu = element.autocomplete( "widget" ); + element.val( "ja" ).autocomplete( "search" ); + equal( menu.find( ".ui-menu-item" ).text(), "javajavascript" ); + element.autocomplete( "option", "source", [ "php", "asp" ] ); + element.val( "ph" ).autocomplete( "search" ); + equal( menu.find( ".ui-menu-item" ).text(), "php" ); +}); + +}( jQuery ) ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/remote_object_array_labels.txt b/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/remote_object_array_labels.txt new file mode 100644 index 0000000..502496c --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/remote_object_array_labels.txt @@ -0,0 +1 @@ +[{"label":"java"},{"label":"javascript"}]
\ No newline at end of file diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/remote_object_array_values.txt b/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/remote_object_array_values.txt new file mode 100644 index 0000000..029cbb9 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/remote_object_array_values.txt @@ -0,0 +1 @@ +[{"value":"java"},{"value":"javascript"}]
\ No newline at end of file diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/remote_string_array.txt b/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/remote_string_array.txt new file mode 100644 index 0000000..3b24c8e --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/autocomplete/remote_string_array.txt @@ -0,0 +1 @@ +["java", "javascript"]
\ No newline at end of file diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/button/all.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/button/all.html new file mode 100644 index 0000000..fa9e224 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/button/all.html @@ -0,0 +1,30 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Button Test Suite</title> + + <script src="../../../jquery-1.7.1.js"></script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <link rel="stylesheet" href="../subsuiteRunner.css"> + <script src="../../../external/qunit.js"></script> + <script src="../subsuiteRunner.js"></script> + <script src="../subsuite.js"></script> + + <script> + testAllVersions( "button" ); + </script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Button Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/button/button.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/button/button.html new file mode 100644 index 0000000..5ec7e31 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/button/button.html @@ -0,0 +1,71 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Button Test Suite</title> + + <script src="../../jquery.js"></script> + <script src="../../resource_loader.js"></script> + <script> + loadResources({ + css: [ "ui.core", "ui.button" ], + js: [ + "ui/jquery.ui.core.js", + "ui/jquery.ui.widget.js", + "ui/jquery.ui.button.js" + ] + }); + </script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <script src="../../../external/qunit.js"></script> + <script src="../../jquery.simulate.js"></script> + <script src="../testsuite.js"></script> + + <script src="button_core.js"></script> + <script src="button_defaults.js"></script> + <script src="button_events.js"></script> + <script src="button_methods.js"></script> + <script src="button_options.js"></script> + <script src="button_tickets.js"></script> + + <script src="../swarminject.js"></script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Button Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +<div><button id="button" class="foo">Label</button></div> + +<div id="radio0" style="margin-top: 2em;"> + <input type="radio" id="radio01" name="radio" checked="checked"><label for="radio01">Choice 1</label> + <input type="radio" id="radio02" name="radio"><label for="radio02">Choice 2</label> + <input type="radio" id="radio03" name="radio"><label for="radio03">Choice 3</label> +</div> +<form> + <div id="radio1" style="margin-top: 2em;"> + <input type="radio" id="radio11" name="radio"><label for="radio11">Choice 1</label> + <input type="radio" id="radio12" name="radio" checked="checked"><label for="radio12">Choice 2</label> + <input type="radio" id="radio13" name="radio"><label for="radio13">Choice 3</label> + </div> +</form> +<form> + <div id="radio2" style="margin-top: 2em;"> + <input type="radio" id="radio21" name="radio"><label for="radio21">Choice 1</label> + <input type="radio" id="radio22" name="radio"><label for="radio22">Choice 2</label> + <input type="radio" id="radio23" name="radio" checked="checked"><label for="radio23">Choice 3</label> + </div> +</form> + +<input type="checkbox" id="check"><label for="check">Toggle</label> + +<div><input id="submit" type="submit" value="Label"></div> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/button/button_core.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/button/button_core.js new file mode 100644 index 0000000..692c403 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/button/button_core.js @@ -0,0 +1,84 @@ +/* + * button_core.js + */ + + +(function($) { + +module("button: core"); + +test("checkbox", function() { + var input = $("#check"); + label = $("label[for=check]"); + ok( input.is(":visible") ); + ok( label.is(":not(.ui-button)") ); + input.button(); + ok( input.is(".ui-helper-hidden-accessible") ); + ok( label.is(".ui-button") ); +}); + +test("radios", function() { + var inputs = $("#radio0 input"); + labels = $("#radio0 label"); + ok( inputs.is(":visible") ); + ok( labels.is(":not(.ui-button)") ); + inputs.button(); + ok( inputs.is(".ui-helper-hidden-accessible") ); + ok( labels.is(".ui-button") ); +}); + +function assert(noForm, form1, form2) { + ok( $("#radio0 .ui-button" + noForm).is(".ui-state-active") ); + ok( $("#radio1 .ui-button" + form1).is(".ui-state-active") ); + ok( $("#radio2 .ui-button" + form2).is(".ui-state-active") ); +} + +test("radio groups", function() { + $(":radio").button(); + assert(":eq(0)", ":eq(1)", ":eq(2)"); + + // click outside of forms + $("#radio0 .ui-button:eq(1)").click(); + assert(":eq(1)", ":eq(1)", ":eq(2)"); + + // click in first form + $("#radio1 .ui-button:eq(0)").click(); + assert(":eq(1)", ":eq(0)", ":eq(2)"); + + // click in second form + $("#radio2 .ui-button:eq(0)").click(); + assert(":eq(1)", ":eq(0)", ":eq(0)"); +}); + +test("input type submit, don't create child elements", function() { + var input = $("#submit") + same( input.children().length, 0 ); + input.button(); + same( input.children().length, 0 ); +}); + +test("buttonset", function() { + var set = $("#radio1").buttonset(); + ok( set.is(".ui-buttonset") ); + same( set.children(".ui-button").length, 3 ); + same( set.children("input:radio.ui-helper-hidden-accessible").length, 3 ); + ok( set.children("label:eq(0)").is(".ui-button.ui-corner-left:not(.ui-corner-all)") ); + ok( set.children("label:eq(1)").is(".ui-button:not(.ui-corner-all)") ); + ok( set.children("label:eq(2)").is(".ui-button.ui-corner-right:not(.ui-corner-all)") ); +}); + +test("buttonset (rtl)", function() { + var parent = $("#radio1").parent(); + // Set to rtl + parent.attr("dir", "rtl"); + + var set = $("#radio1").buttonset(); + ok( set.is(".ui-buttonset") ); + same( set.children(".ui-button").length, 3 ); + same( set.children("input:radio.ui-helper-hidden-accessible").length, 3 ); + ok( set.children("label:eq(0)").is(".ui-button.ui-corner-right:not(.ui-corner-all)") ); + ok( set.children("label:eq(1)").is(".ui-button:not(.ui-corner-all)") ); + ok( set.children("label:eq(2)").is(".ui-button.ui-corner-left:not(.ui-corner-all)") ); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/button/button_defaults.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/button/button_defaults.js new file mode 100644 index 0000000..96c7e5b --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/button/button_defaults.js @@ -0,0 +1,14 @@ +commonWidgetTests( "button", { + defaults: { + disabled: null, + icons: { + primary: null, + secondary: null + }, + label: null, + text: true, + + // callbacks + create: null + } +}); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/button/button_events.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/button/button_events.js new file mode 100644 index 0000000..a215402 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/button/button_events.js @@ -0,0 +1,8 @@ +/* + * button_events.js + */ +(function($) { + +module("button: events"); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/button/button_methods.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/button/button_methods.js new file mode 100644 index 0000000..a83a73b --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/button/button_methods.js @@ -0,0 +1,19 @@ +/* + * button_methods.js + */ +(function($) { + + +module("button: methods"); + +test("destroy", function() { + var beforeHtml = $("#button").parent().html(); + var afterHtml = $("#button").button().button("destroy").parent().html(); + // Opera 9 outputs role="" instead of removing the attribute like everyone else + if ($.browser.opera) { + afterHtml = afterHtml.replace(/ role=""/g, ""); + } + equal( afterHtml, beforeHtml ); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/button/button_options.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/button/button_options.js new file mode 100644 index 0000000..a3ab5ae --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/button/button_options.js @@ -0,0 +1,93 @@ +/* + * button_options.js + */ +(function($) { + +module("button: options"); + +test("disabled, explicit value", function() { + $("#radio01").button({ disabled: false }); + same(false, $("#radio01").button("option", "disabled"), + "disabled option set to false"); + same(false, $("#radio01").prop("disabled"), "element is disabled"); + + $("#radio02").button({ disabled: true }); + same(true, $("#radio02").button("option", "disabled"), + "disabled option set to true"); + same(true, $("#radio02").prop("disabled"), "element is not disabled"); +}); + +test("disabled, null", function() { + $("#radio01").button({ disabled: null }); + same(false, $("#radio01").button("option", "disabled"), + "disabled option set to false"); + same(false, $("#radio01").prop("disabled"), "element is disabled"); + + $("#radio02").prop("disabled", true).button({ disabled: null }); + same(true, $("#radio02").button("option", "disabled"), + "disabled option set to true"); + same(true, $("#radio02").prop("disabled"), "element is not disabled"); +}); + +test("text false without icon", function() { + $("#button").button({ + text: false + }); + ok( $("#button").is(".ui-button-text-only:not(.ui-button-icon-only)") ); + + $("#button").button("destroy"); +}); + +test("text false with icon", function() { + $("#button").button({ + text: false, + icons: { + primary: "iconclass" + } + }); + ok( $("#button").is(".ui-button-icon-only:not(.ui-button-text):has(span.ui-icon.iconclass)") ); + + $("#button").button("destroy"); +}); + +test("label, default", function() { + $("#button").button(); + same( $("#button").text(), "Label" ); + + $("#button").button("destroy"); +}); + +test("label", function() { + $("#button").button({ + label: "xxx" + }); + same( $("#button").text(), "xxx" ); + + $("#button").button("destroy"); +}); + +test("label default with input type submit", function() { + same( $("#submit").button().val(), "Label" ); +}); + +test("label with input type submit", function() { + var label = $("#submit").button({ + label: "xxx" + }).val(); + same( label, "xxx" ); +}); + +test("icons", function() { + $("#button").button({ + text: false, + icons: { + primary: "iconclass", + secondary: "iconclass2" + } + }); + ok( $("#button").is(":has(span.ui-icon.ui-button-icon-primary.iconclass):has(span.ui-icon.ui-button-icon-secondary.iconclass2)") ); + + $("#button").button("destroy"); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/button/button_tickets.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/button/button_tickets.js new file mode 100644 index 0000000..624d167 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/button/button_tickets.js @@ -0,0 +1,59 @@ +/* + * button_tickets.js + */ +(function( $ ) { + +module( "button: tickets" ); + +test( "#5946 - buttonset should ignore buttons that are not :visible", function() { + $( "#radio01" ).next().andSelf().hide(); + var set = $( "#radio0" ).buttonset({ items: ":radio:visible" }); + ok( set.find( "label:eq(0)" ).is( ":not(.ui-button):not(.ui-corner-left)" ) ); + ok( set.find( "label:eq(1)" ).is( ".ui-button.ui-corner-left" ) ); +}); + +test( "#6262 - buttonset not applying ui-corner to invisible elements", function() { + $( "#radio0" ).hide(); + var set = $( "#radio0" ).buttonset(); + ok( set.find( "label:eq(0)" ).is( ".ui-button.ui-corner-left" ) ); + ok( set.find( "label:eq(1)" ).is( ".ui-button" ) ); + ok( set.find( "label:eq(2)" ).is( ".ui-button.ui-corner-right" ) ); +}); + +test( "#6711 Checkbox/Radiobutton do not Show Focused State when using Keyboard Navigation", function() { + var check = $( "#check" ).button(), + label = $( "label[for='check']" ); + ok( !label.is( ".ui-state-focus" ) ); + check.focus(); + ok( label.is( ".ui-state-focus" ) ); +}); + +test( "#7092 - button creation that requires a matching label does not find label in all cases", function() { + var group = $( "<span><label for='t7092a'></label><input type='checkbox' id='t7092a'></span>" ); + group.find( "input:checkbox" ).button(); + ok( group.find( "label" ).is( ".ui-button" ) ); + + group = $( "<input type='checkbox' id='t7092b'><label for='t7092b'></label>" ); + group.filter( "input:checkbox" ).button(); + ok( group.filter( "label" ).is( ".ui-button" ) ); + + group = $( "<span><input type='checkbox' id='t7092c'></span><label for='t7092c'></label>" ); + group.find( "input:checkbox" ).button(); + ok( group.filter( "label" ).is( ".ui-button" ) ); + + group = $( "<span><input type='checkbox' id='t7092d'></span><span><label for='t7092d'></label></span>" ); + group.find( "input:checkbox" ).button(); + ok( group.find( "label" ).is( ".ui-button" ) ); + + group = $( "<input type='checkbox' id='t7092e'><span><label for='t7092e'></label></span>" ); + group.filter( "input:checkbox" ).button(); + ok( group.find( "label" ).is( ".ui-button" ) ); +}); + +test( "#7534 - Button label selector works for ids with \":\"", function() { + var group = $( "<span><input type='checkbox' id='check:7534'><label for='check:7534'>Label</label></span>" ); + group.find( "input" ).button(); + ok( group.find( "label" ).is( ".ui-button" ), "Found an id with a :" ); +}); + +})( jQuery ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/core/all.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/core/all.html new file mode 100644 index 0000000..e8d84e1 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/core/all.html @@ -0,0 +1,30 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Core Test Suite</title> + + <script src="../../../jquery-1.7.1.js"></script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <link rel="stylesheet" href="../subsuiteRunner.css"> + <script src="../../../external/qunit.js"></script> + <script src="../subsuiteRunner.js"></script> + <script src="../subsuite.js"></script> + + <script> + testAllVersions( "core" ); + </script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Core Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/core/core.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/core/core.html new file mode 100644 index 0000000..3b1dc1f --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/core/core.html @@ -0,0 +1,134 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Core Test Suite</title> + + <script src="../../jquery.js"></script> + <script src="../../resource_loader.js"></script> + <script> + loadResources({ + js: [ "ui/jquery.ui.core.js" ] + }); + </script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <script src="../../../external/qunit.js"></script> + <script src="../../jquery.simulate.js"></script> + <script src="../testsuite.js"></script> + + <script src="core.js"></script> + <script src="selector.js"></script> + + <script src="../swarminject.js"></script> + <style> + .zindex { + z-index: 100; + } + .absolute { + position: absolute; + } + </style> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Core Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +<img src="../images/jqueryui_32x32.png" usemap="#mymap" width="10", height="10"> +<map name="mymap"> + <area shape="rect" coords="0,0,1,1" id="areaCoordsNoHref"> + <area shape="rect" coords="1,1,2,2" href="foo.html" id="areaCoordsHref"> + <area shape="rect" coords="0,0,0,0" href="foo.html" id="areaCoordsNoSizeHref"> + <area href="foo.html" id="areaNoCoordsHref"> +</map> +<map name="mymap2"> + <area shape="rect" coords="1,1,2,2" href="foo.html" id="areaNoImg"> +</map> + +<form id="formNoTabindex"></form> +<form id="formTabindex" tabindex="1"></form> + +<div> + <input id="visibleAncestor-inputTypeNone"> + <input type="text" id="visibleAncestor-inputTypeText"> + <input type="checkbox" id="visibleAncestor-inputTypeCheckbox"> + <input type="radio" id="visibleAncestor-inputTypeRadio"> + <input type="button" id="visibleAncestor-inputTypeButton"> + <input type="hidden" id="visibleAncestor-inputTypeHidden"> + <button id="visibleAncestor-button">x</button> + <select id="visibleAncestor-select"> + <option>option</option> + </select> + <textarea id="visibleAncestor-textarea">x</textarea> + <object id="visibleAncestor-object" codebase="about:blank">xxx</object> + <a href="#" id="visibleAncestor-anchorWithHref">anchor</a> + <a id="visibleAncestor-anchorWithoutHref">anchor</a> + <span id="visibleAncestor-span">x</span> + <div id="visibleAncestor-div">x</div> + <span id="visibleAncestor-spanWithTabindex" tabindex="1">x</span> + <div id="visibleAncestor-divWithNegativeTabindex" tabindex="-1">x</div> +</div> + +<div> + <input id="disabledElement-inputTypeNone" disabled="disabled"> + <input type="text" id="disabledElement-inputTypeText" disabled="disabled"> + <input type="checkbox" id="disabledElement-inputTypeCheckbox" disabled="disabled"> + <input type="radio" id="disabledElement-inputTypeRadio" disabled="disabled"> + <input type="button" id="disabledElement-inputTypeButton" disabled="disabled"> + <input type="hidden" id="disabledElement-inputTypeHidden" disabled="disabled"> + <button id="disabledElement-button" disabled="disabled"></button> + <select id="disabledElement-select" disabled="disabled"></select> + <textarea id="disabledElement-textarea" disabled="disabled"></textarea> +</div> + +<div> + <div id="displayNoneAncestor" style="display: none;"> + <input id="displayNoneAncestor-input"> + <span tabindex="1" id="displayNoneAncestor-span">.</span> + </div> + + <div id="visibilityHiddenAncestor" style="visibility: hidden;"> + <input id="visibilityHiddenAncestor-input"> + <span tabindex="1" id="visibilityHiddenAncestor-span">.</span> + </div> + + <span tabindex="1" id="displayNone-span" style="display: none;">.</span> + <span tabindex="1" id="visibilityHidden-span" style="visibility: hidden;">.</span> + + <input id="displayNone-input" style="display: none;"> + <input id="visibilityHidden-input" style="visibility: hidden;"> +</div> + +<div> + <input id="inputTabindex0" tabindex="0"> + <input id="inputTabindex10" tabindex="10"> + <input id="inputTabindex-1" tabindex="-1"> + <input id="inputTabindex-50" tabindex="-50"> + + <span id="spanTabindex0" tabindex="0">.</span> + <span id="spanTabindex10" tabindex="10">.</span> + <span id="spanTabindex-1" tabindex="-1">.</span> + <span id="spanTabindex-50" tabindex="-50">.</span> +</div> + +<div id="zIndex100" style="z-index: 100; position: absolute"> + <div id="zIndexAutoWithParent">.</div> +</div> +<div id="zIndex100ViaCSS" class="zindex"> + <div id="zIndexAutoWithParentViaCSS">.</div> +</div> +<div id="zIndex100ViaCSSPositioned" class="zindex absolute"> + <div id="zIndexAutoWithParentViaCSSPositioned">.</div> +</div> +<div id="zIndexAutoNoParent"></div> + +<div id="dimensions" style="float: left; height: 50px; width: 100px; margin: 1px 12px 11px 2px; border-style: solid; border-width: 3px 14px 13px 4px; padding: 5px 16px 15px 6px;"></div> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/core/core.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/core/core.js new file mode 100644 index 0000000..03a7ab8 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/core/core.js @@ -0,0 +1,157 @@ +/* + * core unit tests + */ +(function($) { + +module('core - jQuery extensions'); + +test('focus - original functionality', function() { + expect(1); + + $('#inputTabindex0') + .focus(function() { + ok(true, 'event triggered'); + }) + .focus(); +}); + +asyncTest('focus', function() { + expect(2); + $('#inputTabindex0') + .focus(function() { + ok(true, 'event triggered'); + }) + .focus(500, function() { + ok(true, 'callback triggered'); + $(this).unbind('focus'); + start(); + }); +}); + +test('zIndex', function() { + var el = $('#zIndexAutoWithParent'), + parent = el.parent(); + equals(el.zIndex(), 100, 'zIndex traverses up to find value'); + equals(parent.zIndex(200), parent, 'zIndex setter is chainable'); + equals(el.zIndex(), 200, 'zIndex setter changed zIndex'); + + el = $('#zIndexAutoWithParentViaCSS'); + equals(el.zIndex(), 0, 'zIndex traverses up to find CSS value, not found because not positioned'); + + el = $('#zIndexAutoWithParentViaCSSPositioned'); + equals(el.zIndex(), 100, 'zIndex traverses up to find CSS value'); + el.parent().zIndex(200); + equals(el.zIndex(), 200, 'zIndex setter changed zIndex, overriding CSS'); + + equals($('#zIndexAutoNoParent').zIndex(), 0, 'zIndex never explicitly set in hierarchy'); +}); + +test( "innerWidth - getter", function() { + var el = $( "#dimensions" ); + + equals( el.innerWidth(), 122, "getter passthru" ); + el.hide(); + equals( el.innerWidth(), 122, "getter passthru when hidden" ); +}); + +test( "innerWidth - setter", function() { + var el = $( "#dimensions" ); + + el.innerWidth( 120 ); + equals( el.width(), 98, "width set properly" ); + el.hide(); + el.innerWidth( 100 ); + equals( el.width(), 78, "width set properly when hidden" ); +}); + +test( "innerHeight - getter", function() { + var el = $( "#dimensions" ); + + equals( el.innerHeight(), 70, "getter passthru" ); + el.hide(); + equals( el.innerHeight(), 70, "getter passthru when hidden" ); +}); + +test( "innerHeight - setter", function() { + var el = $( "#dimensions" ); + + el.innerHeight( 60 ); + equals( el.height(), 40, "height set properly" ); + el.hide(); + el.innerHeight( 50 ); + equals( el.height(), 30, "height set properly when hidden" ); +}); + +test( "outerWidth - getter", function() { + var el = $( "#dimensions" ); + + equals( el.outerWidth(), 140, "getter passthru" ); + el.hide(); + equals( el.outerWidth(), 140, "getter passthru when hidden" ); +}); + +test( "outerWidth - setter", function() { + var el = $( "#dimensions" ); + + el.outerWidth( 130 ); + equals( el.width(), 90, "width set properly" ); + el.hide(); + el.outerWidth( 120 ); + equals( el.width(), 80, "width set properly when hidden" ); +}); + +test( "outerWidth(true) - getter", function() { + var el = $( "#dimensions" ); + + equals( el.outerWidth(true), 154, "getter passthru w/ margin" ); + el.hide(); + equals( el.outerWidth(true), 154, "getter passthru w/ margin when hidden" ); +}); + +test( "outerWidth(true) - setter", function() { + var el = $( "#dimensions" ); + + el.outerWidth( 130, true ); + equals( el.width(), 76, "width set properly" ); + el.hide(); + el.outerWidth( 120, true ); + equals( el.width(), 66, "width set properly when hidden" ); +}); + +test( "outerHeight - getter", function() { + var el = $( "#dimensions" ); + + equals( el.outerHeight(), 86, "getter passthru" ); + el.hide(); + equals( el.outerHeight(), 86, "getter passthru when hidden" ); +}); + +test( "outerHeight - setter", function() { + var el = $( "#dimensions" ); + + el.outerHeight( 80 ); + equals( el.height(), 44, "height set properly" ); + el.hide(); + el.outerHeight( 70 ); + equals( el.height(), 34, "height set properly when hidden" ); +}); + +test( "outerHeight(true) - getter", function() { + var el = $( "#dimensions" ); + + equals( el.outerHeight(true), 98, "getter passthru w/ margin" ); + el.hide(); + equals( el.outerHeight(true), 98, "getter passthru w/ margin when hidden" ); +}); + +test( "outerHeight(true) - setter", function() { + var el = $( "#dimensions" ); + + el.outerHeight( 90, true ); + equals( el.height(), 42, "height set properly" ); + el.hide(); + el.outerHeight( 80, true ); + equals( el.height(), 32, "height set properly when hidden" ); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/core/selector.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/core/selector.js new file mode 100644 index 0000000..2fb7802 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/core/selector.js @@ -0,0 +1,239 @@ +/* + * selector unit tests + */ +(function($) { + +module("core - selectors"); + +function isFocusable(selector, msg) { + ok($(selector).is(':focusable'), msg + " - selector " + selector + " is focusable"); +} + +function isNotFocusable(selector, msg) { + ok($(selector).length && !$(selector).is(':focusable'), msg + " - selector " + selector + " is not focusable"); +} + +function isTabbable(selector, msg) { + ok($(selector).is(':tabbable'), msg + " - selector " + selector + " is tabbable"); +} + +function isNotTabbable(selector, msg) { + ok($(selector).length && !$(selector).is(':tabbable'), msg + " - selector " + selector + " is not tabbable"); +} + +test("data", function() { + expect(15); + + var el; + function shouldHaveData(msg) { + ok(el.is(':data(test)'), msg); + } + function shouldNotHaveData(msg) { + ok(!el.is(':data(test)'), msg); + } + + el = $('<div>'); + shouldNotHaveData('data never set'); + + el = $('<div>').data('test', null); + shouldNotHaveData('data is null'); + + el = $('<div>').data('test', true); + shouldHaveData('data set to true'); + + el = $('<div>').data('test', false); + shouldNotHaveData('data set to false'); + + el = $('<div>').data('test', 0); + shouldNotHaveData('data set to 0'); + + el = $('<div>').data('test', 1); + shouldHaveData('data set to 1'); + + el = $('<div>').data('test', ''); + shouldNotHaveData('data set to empty string'); + + el = $('<div>').data('test', 'foo'); + shouldHaveData('data set to string'); + + el = $('<div>').data('test', []); + shouldHaveData('data set to empty array'); + + el = $('<div>').data('test', [1]); + shouldHaveData('data set to array'); + + el = $('<div>').data('test', {}); + shouldHaveData('data set to empty object'); + + el = $('<div>').data('test', {foo: 'bar'}); + shouldHaveData('data set to object'); + + el = $('<div>').data('test', new Date()); + shouldHaveData('data set to date'); + + el = $('<div>').data('test', /test/); + shouldHaveData('data set to regexp'); + + el = $('<div>').data('test', function() {}); + shouldHaveData('data set to function'); +}); + +test("focusable - visible, enabled elements", function() { + expect(18); + + isNotFocusable('#formNoTabindex', 'form'); + isFocusable('#formTabindex', 'form with tabindex'); + isFocusable('#visibleAncestor-inputTypeNone', 'input, no type'); + isFocusable('#visibleAncestor-inputTypeText', 'input, type text'); + isFocusable('#visibleAncestor-inputTypeCheckbox', 'input, type checkbox'); + isFocusable('#visibleAncestor-inputTypeRadio', 'input, type radio'); + isFocusable('#visibleAncestor-inputTypeButton', 'input, type button'); + isNotFocusable('#visibleAncestor-inputTypeHidden', 'input, type hidden'); + isFocusable('#visibleAncestor-button', 'button'); + isFocusable('#visibleAncestor-select', 'select'); + isFocusable('#visibleAncestor-textarea', 'textarea'); + isFocusable('#visibleAncestor-object', 'object'); + isFocusable('#visibleAncestor-anchorWithHref', 'anchor with href'); + isNotFocusable('#visibleAncestor-anchorWithoutHref', 'anchor without href'); + isNotFocusable('#visibleAncestor-span', 'span'); + isNotFocusable('#visibleAncestor-div', 'div'); + isFocusable("#visibleAncestor-spanWithTabindex", 'span with tabindex'); + isFocusable("#visibleAncestor-divWithNegativeTabindex", 'div with tabindex'); +}); + +test("focusable - disabled elements", function() { + expect(9); + + isNotFocusable('#disabledElement-inputTypeNone', 'input, no type'); + isNotFocusable('#disabledElement-inputTypeText', 'input, type text'); + isNotFocusable('#disabledElement-inputTypeCheckbox', 'input, type checkbox'); + isNotFocusable('#disabledElement-inputTypeRadio', 'input, type radio'); + isNotFocusable('#disabledElement-inputTypeButton', 'input, type button'); + isNotFocusable('#disabledElement-inputTypeHidden', 'input, type hidden'); + isNotFocusable('#disabledElement-button', 'button'); + isNotFocusable('#disabledElement-select', 'select'); + isNotFocusable('#disabledElement-textarea', 'textarea'); +}); + +test("focusable - hidden styles", function() { + expect(8); + + isNotFocusable('#displayNoneAncestor-input', 'input, display: none parent'); + isNotFocusable('#displayNoneAncestor-span', 'span with tabindex, display: none parent'); + + isNotFocusable('#visibilityHiddenAncestor-input', 'input, visibility: hidden parent'); + isNotFocusable('#visibilityHiddenAncestor-span', 'span with tabindex, visibility: hidden parent'); + + isNotFocusable('#displayNone-input', 'input, display: none'); + isNotFocusable('#visibilityHidden-input', 'input, visibility: hidden'); + + isNotFocusable('#displayNone-span', 'span with tabindex, display: none'); + isNotFocusable('#visibilityHidden-span', 'span with tabindex, visibility: hidden'); +}); + +test("focusable - natively focusable with various tabindex", function() { + expect(4); + + isFocusable('#inputTabindex0', 'input, tabindex 0'); + isFocusable('#inputTabindex10', 'input, tabindex 10'); + isFocusable('#inputTabindex-1', 'input, tabindex -1'); + isFocusable('#inputTabindex-50', 'input, tabindex -50'); +}); + +test("focusable - not natively focusable with various tabindex", function() { + expect(4); + + isFocusable('#spanTabindex0', 'span, tabindex 0'); + isFocusable('#spanTabindex10', 'span, tabindex 10'); + isFocusable('#spanTabindex-1', 'span, tabindex -1'); + isFocusable('#spanTabindex-50', 'span, tabindex -50'); +}); + +test("focusable - area elements", function() { + isNotFocusable('#areaCoordsNoHref', 'coords but no href'); + isFocusable('#areaCoordsHref', 'coords and href'); + isFocusable('#areaCoordsNoSizeHref', 'coords of zero px and href'); + isFocusable('#areaNoCoordsHref', 'href but no coords'); + isNotFocusable('#areaNoImg', 'not associated with an image'); +}); + +test("tabbable - visible, enabled elements", function() { + expect(18); + + isNotTabbable('#formNoTabindex', 'form'); + isTabbable('#formTabindex', 'form with tabindex'); + isTabbable('#visibleAncestor-inputTypeNone', 'input, no type'); + isTabbable('#visibleAncestor-inputTypeText', 'input, type text'); + isTabbable('#visibleAncestor-inputTypeCheckbox', 'input, type checkbox'); + isTabbable('#visibleAncestor-inputTypeRadio', 'input, type radio'); + isTabbable('#visibleAncestor-inputTypeButton', 'input, type button'); + isNotTabbable('#visibleAncestor-inputTypeHidden', 'input, type hidden'); + isTabbable('#visibleAncestor-button', 'button'); + isTabbable('#visibleAncestor-select', 'select'); + isTabbable('#visibleAncestor-textarea', 'textarea'); + isTabbable('#visibleAncestor-object', 'object'); + isTabbable('#visibleAncestor-anchorWithHref', 'anchor with href'); + isNotTabbable('#visibleAncestor-anchorWithoutHref', 'anchor without href'); + isNotTabbable('#visibleAncestor-span', 'span'); + isNotTabbable('#visibleAncestor-div', 'div'); + isTabbable("#visibleAncestor-spanWithTabindex", 'span with tabindex'); + isNotTabbable("#visibleAncestor-divWithNegativeTabindex", 'div with tabindex'); +}); + +test("tabbable - disabled elements", function() { + expect(9); + + isNotTabbable('#disabledElement-inputTypeNone', 'input, no type'); + isNotTabbable('#disabledElement-inputTypeText', 'input, type text'); + isNotTabbable('#disabledElement-inputTypeCheckbox', 'input, type checkbox'); + isNotTabbable('#disabledElement-inputTypeRadio', 'input, type radio'); + isNotTabbable('#disabledElement-inputTypeButton', 'input, type button'); + isNotTabbable('#disabledElement-inputTypeHidden', 'input, type hidden'); + isNotTabbable('#disabledElement-button', 'button'); + isNotTabbable('#disabledElement-select', 'select'); + isNotTabbable('#disabledElement-textarea', 'textarea'); +}); + +test("tabbable - hidden styles", function() { + expect(8); + + isNotTabbable('#displayNoneAncestor-input', 'input, display: none parent'); + isNotTabbable('#displayNoneAncestor-span', 'span with tabindex, display: none parent'); + + isNotTabbable('#visibilityHiddenAncestor-input', 'input, visibility: hidden parent'); + isNotTabbable('#visibilityHiddenAncestor-span', 'span with tabindex, visibility: hidden parent'); + + isNotTabbable('#displayNone-input', 'input, display: none'); + isNotTabbable('#visibilityHidden-input', 'input, visibility: hidden'); + + isNotTabbable('#displayNone-span', 'span with tabindex, display: none'); + isNotTabbable('#visibilityHidden-span', 'span with tabindex, visibility: hidden'); +}); + +test("tabbable - natively tabbable with various tabindex", function() { + expect(4); + + isTabbable('#inputTabindex0', 'input, tabindex 0'); + isTabbable('#inputTabindex10', 'input, tabindex 10'); + isNotTabbable('#inputTabindex-1', 'input, tabindex -1'); + isNotTabbable('#inputTabindex-50', 'input, tabindex -50'); +}); + +test("tabbable - not natively tabbable with various tabindex", function() { + expect(4); + + isTabbable('#spanTabindex0', 'span, tabindex 0'); + isTabbable('#spanTabindex10', 'span, tabindex 10'); + isNotTabbable('#spanTabindex-1', 'span, tabindex -1'); + isNotTabbable('#spanTabindex-50', 'span, tabindex -50'); +}); + +test("tabbable - area elements", function() { + isNotTabbable('#areaCoordsNoHref', 'coords but no href'); + isTabbable('#areaCoordsHref', 'coords and href'); + isTabbable('#areaCoordsNoSizeHref', 'coords of zero px and href'); + isTabbable('#areaNoCoordsHref', 'href but no coords'); + isNotTabbable('#areaNoImg', 'not associated with an image'); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/datepicker/all.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/datepicker/all.html new file mode 100644 index 0000000..67d5cb2 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/datepicker/all.html @@ -0,0 +1,30 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Datepicker Test Suite</title> + + <script src="../../../jquery-1.7.1.js"></script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <link rel="stylesheet" href="../subsuiteRunner.css"> + <script src="../../../external/qunit.js"></script> + <script src="../subsuiteRunner.js"></script> + <script src="../subsuite.js"></script> + + <script> + testAllVersions( "datepicker" ); + </script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Datepicker Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/datepicker/datepicker.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/datepicker/datepicker.html new file mode 100644 index 0000000..592db53 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/datepicker/datepicker.html @@ -0,0 +1,60 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Datepicker Test Suite</title> + + <script src="../../jquery.js"></script> + <script src="../../resource_loader.js"></script> + <script> + loadResources({ + css: [ "ui.core", "ui.datepicker" ], + js: [ + "ui/jquery.ui.core.js", + "ui/jquery.ui.datepicker.js", + "ui/i18n/jquery.ui.datepicker-fr.js", + "ui/i18n/jquery.ui.datepicker-he.js", + "ui/i18n/jquery.ui.datepicker-zh-CN.js" + ] + }); + </script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <script src="../../../external/qunit.js"></script> + <script src="../../jquery.simulate.js"></script> + <script src="../testsuite.js"></script> + + <script src="datepicker_core.js"></script> + <script src="datepicker_defaults.js"></script> + <script src="datepicker_events.js"></script> + <script src="datepicker_methods.js"></script> + <script src="datepicker_options.js"></script> + <script src="datepicker_tickets.js"></script> + + <script> + // disable this stale testsuite for testswarm only + var url = window.location.search; + url = decodeURIComponent( url.slice( url.indexOf("swarmURL=") + 9 ) ); + if ( url && url.indexOf("http") == 0 ) { + // reset config to kill previous tests; make sure testsuite.js is loaded afterwards to init the testswarm script + QUnit.init(); + test("datepicker", function() { ok(true, "disabled datepicker testsuite"); }); + } + </script> + <script src="../swarminject.js"></script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Datepicker Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +<div><input type="text" id="inp"><input type="text" id="alt"><div id="inl"></div></div> +<p><input type="text" id="inp2"></p> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/datepicker/datepicker_core.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/datepicker/datepicker_core.js new file mode 100644 index 0000000..badb837 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/datepicker/datepicker_core.js @@ -0,0 +1,449 @@ +/* + * datepicker_core.js + */ + +function equalsDate(d1, d2, message) { + if (!d1 || !d2) { + ok(false, message + ' - missing date'); + return; + } + d1 = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate()); + d2 = new Date(d2.getFullYear(), d2.getMonth(), d2.getDate()); + equals(d1.toString(), d2.toString(), message); +} + +function equalsDateArray(a1, a2, message) { + if (!a1 || !a2) { + ok(false, message + ' - missing dates'); + return; + } + a1[0] = (a1[0] ? new Date(a1[0].getFullYear(), a1[0].getMonth(), a1[0].getDate()) : ''); + a1[1] = (a1[1] ? new Date(a1[1].getFullYear(), a1[1].getMonth(), a1[1].getDate()) : ''); + a2[0] = (a2[0] ? new Date(a2[0].getFullYear(), a2[0].getMonth(), a2[0].getDate()) : ''); + a2[1] = (a2[1] ? new Date(a2[1].getFullYear(), a2[1].getMonth(), a2[1].getDate()) : ''); + same(a1, a2, message); +} + +function addMonths(date, offset) { + var maxDay = 32 - new Date(date.getFullYear(), date.getMonth() + offset, 32).getDate(); + date.setDate(Math.min(date.getDate(), maxDay)); + date.setMonth(date.getMonth() + offset); + return date; +} + +function init(id, options) { + $.datepicker.setDefaults($.datepicker.regional['']); + return $(id).datepicker($.extend({showAnim: ''}, options || {})); +} + +var PROP_NAME = 'datepicker'; + +(function($) { + +module("datepicker: core"); + +test( "widget method - empty collection", function() { + $( "#nonExist" ).datepicker(); // should create nothing + ok( !$( "#ui-datepicker-div" ).length, "Non init on empty collection" ); +}); + +test("widget method", function() { + var actual = $("#inp").datepicker().datepicker("widget")[0]; + same($("body > #ui-datepicker-div:last-child")[0], actual); +}); + +test('baseStructure', function() { + var inp = init('#inp'); + inp.focus(); + var dp = $('#ui-datepicker-div'); + var iframe = ($.browser.msie && parseInt($.browser.version) < 7); + ok(dp.is(':visible'), 'Structure - datepicker visible'); + ok(!dp.is('.ui-datepicker-rtl'), 'Structure - not right-to-left'); + ok(!dp.is('.ui-datepicker-multi'), 'Structure - not multi-month'); + equals(dp.children().length, 2 + (iframe ? 1 : 0), 'Structure - child count'); + + var header = dp.children(':first'); + ok(header.is('div.ui-datepicker-header'), 'Structure - header division'); + equals(header.children().length, 3, 'Structure - header child count'); + ok(header.children(':first').is('a.ui-datepicker-prev') && header.children(':first').html() != '', 'Structure - prev link'); + ok(header.children(':eq(1)').is('a.ui-datepicker-next') && header.children(':eq(1)').html() != '', 'Structure - next link'); + + var title = header.children(':last'); + ok(title.is('div.ui-datepicker-title') && title.html() != '','Structure - title division'); + equals(title.children().length, 2, 'Structure - title child count'); + ok(title.children(':first').is('span.ui-datepicker-month') && title.children(':first').text() != '', 'Structure - month text') + ok(title.children(':last').is('span.ui-datepicker-year') && title.children(':last').text() != '', 'Structure - year text') + + var table = dp.children(':eq(1)'); + ok(table.is('table.ui-datepicker-calendar'), 'Structure - month table'); + ok(table.children(':first').is('thead'), 'Structure - month table thead'); + var thead = table.children(':first').children(':first'); + ok(thead.is('tr'), 'Structure - month table title row'); + equals(thead.find('th').length, 7, 'Structure - month table title cells'); + ok(table.children(':eq(1)').is('tbody'), 'Structure - month table body'); + ok(table.children(':eq(1)').children('tr').length >= 4, 'Structure - month table week count'); + var week = table.children(':eq(1)').children(':first'); + ok(week.is('tr'), 'Structure - month table week row'); + equals(week.children().length, 7, 'Structure - week child count'); + ok(week.children(':first').is('td.ui-datepicker-week-end'), 'Structure - month table first day cell'); + ok(week.children(':last').is('td.ui-datepicker-week-end'), 'Structure - month table second day cell'); + ok(dp.children('iframe').length == (iframe ? 1 : 0), 'Structure - iframe'); + inp.datepicker('hide').datepicker('destroy'); + + // Editable month/year and button panel + inp = init('#inp', {changeMonth: true, changeYear: true, showButtonPanel: true}); + inp.focus(); + + var title = dp.find('div.ui-datepicker-title'); + ok(title.children(':first').is('select.ui-datepicker-month'), 'Structure - month selector'); + ok(title.children(':last').is('select.ui-datepicker-year'), 'Structure - year selector'); + + var panel = dp.children(':last'); + ok(panel.is('div.ui-datepicker-buttonpane'), 'Structure - button panel division'); + equals(panel.children().length, 2, 'Structure - button panel child count'); + ok(panel.children(':first').is('button.ui-datepicker-current'), 'Structure - today button'); + ok(panel.children(':last').is('button.ui-datepicker-close'), 'Structure - close button'); + inp.datepicker('hide').datepicker('destroy'); + + // Multi-month 2 + inp = init('#inp', {numberOfMonths: 2}); + inp.focus(); + ok(dp.is('.ui-datepicker-multi'), 'Structure multi [2] - multi-month'); + equals(dp.children().length, 3 + (iframe ? 1 : 0), 'Structure multi [2] - child count'); + var child = dp.children(':first'); + ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-first'), 'Structure multi [2] - first month division'); + child = dp.children(':eq(1)'); + ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-last'), 'Structure multi [2] - second month division'); + child = dp.children(':eq(2)'); + ok(child.is('div.ui-datepicker-row-break'), 'Structure multi [2] - row break'); + ok(dp.is('.ui-datepicker-multi-2'), 'Structure multi [2] - multi-2'); + inp.datepicker('hide').datepicker('destroy'); + + // Multi-month 3 + inp = init('#inp', {numberOfMonths: 3}); + inp.focus(); + ok(dp.is('.ui-datepicker-multi-3'), 'Structure multi [3] - multi-3'); + ok(! dp.is('.ui-datepicker-multi-2'), 'Structure multi [3] - Trac #6704'); + inp.datepicker('hide').datepicker('destroy'); + + // Multi-month [2, 2] + inp = init('#inp', {numberOfMonths: [2, 2]}); + inp.focus(); + ok(dp.is('.ui-datepicker-multi'), 'Structure multi - multi-month'); + equals(dp.children().length, 6 + (iframe ? 1 : 0), 'Structure multi [2,2] - child count'); + child = dp.children(':first'); + ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-first'), 'Structure multi [2,2] - first month division'); + child = dp.children(':eq(1)'); + ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-last'), 'Structure multi [2,2] - second month division'); + child = dp.children(':eq(2)'); + ok(child.is('div.ui-datepicker-row-break'), 'Structure multi [2,2] - row break'); + child = dp.children(':eq(3)'); + ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-first'), 'Structure multi [2,2] - third month division'); + child = dp.children(':eq(4)'); + ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-last'), 'Structure multi [2,2] - fourth month division'); + child = dp.children(':eq(5)'); + ok(child.is('div.ui-datepicker-row-break'), 'Structure multi [2,2] - row break'); + inp.datepicker('hide').datepicker('destroy'); + + // Inline + var inl = init('#inl'); + dp = inl.children(); + ok(dp.is('.ui-datepicker-inline'), 'Structure inline - main div'); + ok(!dp.is('.ui-datepicker-rtl'), 'Structure inline - not right-to-left'); + ok(!dp.is('.ui-datepicker-multi'), 'Structure inline - not multi-month'); + equals(dp.children().length, 2, 'Structure inline - child count'); + var header = dp.children(':first'); + ok(header.is('div.ui-datepicker-header'), 'Structure inline - header division'); + equals(header.children().length, 3, 'Structure inline - header child count'); + var table = dp.children(':eq(1)'); + ok(table.is('table.ui-datepicker-calendar'), 'Structure inline - month table'); + ok(table.children(':first').is('thead'), 'Structure inline - month table thead'); + ok(table.children(':eq(1)').is('tbody'), 'Structure inline - month table body'); + inl.datepicker('destroy'); + + // Inline multi-month + inl = init('#inl', {numberOfMonths: 2}); + dp = inl.children(); + ok(dp.is('.ui-datepicker-inline') && dp.is('.ui-datepicker-multi'), 'Structure inline multi - main div'); + equals(dp.children().length, 3 + (iframe ? 1 : 0), 'Structure inline multi - child count'); + child = dp.children(':first'); + ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-first'), 'Structure inline multi - first month division'); + child = dp.children(':eq(1)'); + ok(child.is('div.ui-datepicker-group') && child.is('div.ui-datepicker-group-last'), 'Structure inline multi - second month division'); + child = dp.children(':eq(2)'); + ok(child.is('div.ui-datepicker-row-break'), 'Structure inline multi - row break'); + inl.datepicker('destroy'); +}); + +test('customStructure', function() { + var dp = $('#ui-datepicker-div'); + // Check right-to-left localisation + var inp = init('#inp', $.datepicker.regional['he']); + inp.data('showButtonPanel.datepicker',true); + inp.focus(); + var iframe = ($.browser.msie && parseInt($.browser.version) < 7); + ok(dp.is('.ui-datepicker-rtl'), 'Structure RTL - right-to-left'); + var header = dp.children(':first'); + ok(header.is('div.ui-datepicker-header'), 'Structure RTL - header division'); + equals(header.children().length, 3, 'Structure RTL - header child count'); + ok(header.children(':first').is('a.ui-datepicker-next'), 'Structure RTL - prev link'); + ok(header.children(':eq(1)').is('a.ui-datepicker-prev'), 'Structure RTL - next link'); + var panel = dp.children(':last'); + ok(panel.is('div.ui-datepicker-buttonpane'), 'Structure RTL - button division'); + equals(panel.children().length, 2, 'Structure RTL - button panel child count'); + ok(panel.children(':first').is('button.ui-datepicker-close'), 'Structure RTL - close button'); + ok(panel.children(':last').is('button.ui-datepicker-current'), 'Structure RTL - today button'); + inp.datepicker('hide').datepicker('destroy'); + + // Hide prev/next + inp = init('#inp', {hideIfNoPrevNext: true, minDate: new Date(2008, 2 - 1, 4), maxDate: new Date(2008, 2 - 1, 14)}); + inp.val('02/10/2008').focus(); + var header = dp.children(':first'); + ok(header.is('div.ui-datepicker-header'), 'Structure hide prev/next - header division'); + equals(header.children().length, 1, 'Structure hide prev/next - links child count'); + ok(header.children(':first').is('div.ui-datepicker-title'), 'Structure hide prev/next - title division'); + inp.datepicker('hide').datepicker('destroy'); + + // Changeable Month with read-only year + inp = init('#inp', {changeMonth: true}); + inp.focus(); + var title = dp.children(':first').children(':last'); + equals(title.children().length, 2, 'Structure changeable month - title child count'); + ok(title.children(':first').is('select.ui-datepicker-month'), 'Structure changeable month - month selector'); + ok(title.children(':last').is('span.ui-datepicker-year'), 'Structure changeable month - read-only year'); + inp.datepicker('hide').datepicker('destroy'); + + // Changeable year with read-only month + inp = init('#inp', {changeYear: true}); + inp.focus(); + var title = dp.children(':first').children(':last'); + equals(title.children().length, 2, 'Structure changeable year - title child count'); + ok(title.children(':first').is('span.ui-datepicker-month'), 'Structure changeable year - read-only month'); + ok(title.children(':last').is('select.ui-datepicker-year'), 'Structure changeable year - year selector'); + inp.datepicker('hide').datepicker('destroy'); + + // Read-only first day of week + inp = init('#inp', {changeFirstDay: false}); + inp.focus(); + var thead = dp.find('.ui-datepicker-calendar thead tr'); + equals(thead.children().length, 7, 'Structure read-only first day - thead child count'); + equals(thead.find('a').length, 0, 'Structure read-only first day - thead links count'); + inp.datepicker('hide').datepicker('destroy'); +}); + +test('keystrokes', function() { + var inp = init('#inp'); + var date = new Date(); + inp.val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), date, 'Keystroke enter'); + inp.val('02/04/2008').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4), + 'Keystroke enter - preset'); + inp.val('02/04/2008').datepicker('show'). + simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_HOME}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+home'); + inp.val('02/04/2008').datepicker('show'). + simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_END}); + ok(inp.datepicker('getDate') == null, 'Keystroke ctrl+end'); + inp.val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ESC}); + ok(inp.datepicker('getDate') == null, 'Keystroke esc'); + inp.val('02/04/2008').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ESC}); + equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4), + 'Keystroke esc - preset'); + inp.val('02/04/2008').datepicker('show'). + simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}). + simulate('keydown', {keyCode: $.simulate.VK_ESC}); + equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4), + 'Keystroke esc - abandoned'); + // Moving by day or week + inp.val('').datepicker('show'). + simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_LEFT}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() - 1); + equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+left'); + inp.val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_LEFT}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() + 1); + equalsDate(inp.datepicker('getDate'), date, 'Keystroke left'); + inp.val('').datepicker('show'). + simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_RIGHT}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() + 1); + equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+right'); + inp.val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_RIGHT}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() - 1); + equalsDate(inp.datepicker('getDate'), date, 'Keystroke right'); + inp.val('').datepicker('show'). + simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_UP}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() - 7); + equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+up'); + inp.val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_UP}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() + 7); + equalsDate(inp.datepicker('getDate'), date, 'Keystroke up'); + inp.val('').datepicker('show'). + simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_DOWN}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() + 7); + equalsDate(inp.datepicker('getDate'), date, 'Keystroke ctrl+down'); + inp.val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_DOWN}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() - 7); + equalsDate(inp.datepicker('getDate'), date, 'Keystroke down'); + // Moving by month or year + inp.val('02/04/2008').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_PGUP}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), new Date(2008, 1 - 1, 4), + 'Keystroke pgup'); + inp.val('02/04/2008').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_PGDN}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), new Date(2008, 3 - 1, 4), + 'Keystroke pgdn'); + inp.val('02/04/2008').datepicker('show'). + simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), new Date(2007, 2 - 1, 4), + 'Keystroke ctrl+pgup'); + inp.val('02/04/2008').datepicker('show'). + simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), new Date(2009, 2 - 1, 4), + 'Keystroke ctrl+pgdn'); + // Check for moving to short months + inp.val('03/31/2008').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_PGUP}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 29), + 'Keystroke pgup - Feb'); + inp.val('01/30/2008').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_PGDN}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 29), + 'Keystroke pgdn - Feb'); + inp.val('02/29/2008').datepicker('show'). + simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), new Date(2007, 2 - 1, 28), + 'Keystroke ctrl+pgup - Feb'); + inp.val('02/29/2008').datepicker('show'). + simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), new Date(2009, 2 - 1, 28), + 'Keystroke ctrl+pgdn - Feb'); + // Goto current + inp.datepicker('option', {gotoCurrent: true}). + datepicker('hide').val('02/04/2008').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_PGDN}). + simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_HOME}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4), + 'Keystroke ctrl+home'); + // Change steps + inp.datepicker('option', {stepMonths: 2, gotoCurrent: false}). + datepicker('hide').val('02/04/2008').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_PGUP}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), new Date(2007, 12 - 1, 4), + 'Keystroke pgup step 2'); + inp.val('02/04/2008').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_PGDN}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), new Date(2008, 4 - 1, 4), + 'Keystroke pgdn step 2'); +}); + +test('mouse', function() { + var inp = init('#inp'); + var dp = $('#ui-datepicker-div'); + var date = new Date(); + inp.val('').datepicker('show'); + $('.ui-datepicker-calendar tbody a:contains(10)', dp).simulate('click', {}); + date.setDate(10); + equalsDate(inp.datepicker('getDate'), date, 'Mouse click'); + inp.val('02/04/2008').datepicker('show'); + $('.ui-datepicker-calendar tbody a:contains(12)', dp).simulate('click', {}); + equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 12), + 'Mouse click - preset'); + inp.val('02/04/2008').datepicker('show'); + inp.val('').datepicker('show'); + $('button.ui-datepicker-close', dp).simulate('click', {}); + ok(inp.datepicker('getDate') == null, 'Mouse click - close'); + inp.val('02/04/2008').datepicker('show'); + $('button.ui-datepicker-close', dp).simulate('click', {}); + equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4), + 'Mouse click - close + preset'); + inp.val('02/04/2008').datepicker('show'); + $('a.ui-datepicker-prev', dp).simulate('click', {}); + $('button.ui-datepicker-close', dp).simulate('click', {}); + equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 4), + 'Mouse click - abandoned'); + // Current/previous/next + inp.val('02/04/2008').datepicker('option', {showButtonPanel: true}).datepicker('show'); + $('.ui-datepicker-current', dp).simulate('click', {}); + $('.ui-datepicker-calendar tbody a:contains(14)', dp).simulate('click', {}); + date.setDate(14); + equalsDate(inp.datepicker('getDate'), date, 'Mouse click - current'); + inp.val('02/04/2008').datepicker('show'); + $('.ui-datepicker-prev', dp).simulate('click'); + $('.ui-datepicker-calendar tbody a:contains(16)', dp).simulate('click'); + equalsDate(inp.datepicker('getDate'), new Date(2008, 1 - 1, 16), + 'Mouse click - previous'); + inp.val('02/04/2008').datepicker('show'); + $('.ui-datepicker-next', dp).simulate('click'); + $('.ui-datepicker-calendar tbody a:contains(18)', dp).simulate('click'); + equalsDate(inp.datepicker('getDate'), new Date(2008, 3 - 1, 18), + 'Mouse click - next'); + // Previous/next with minimum/maximum + inp.datepicker('option', {minDate: new Date(2008, 2 - 1, 2), + maxDate: new Date(2008, 2 - 1, 26)}).val('02/04/2008').datepicker('show'); + $('.ui-datepicker-prev', dp).simulate('click'); + $('.ui-datepicker-calendar tbody a:contains(16)', dp).simulate('click'); + equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 16), + 'Mouse click - previous + min/max'); + inp.val('02/04/2008').datepicker('show'); + $('.ui-datepicker-next', dp).simulate('click'); + $('.ui-datepicker-calendar tbody a:contains(18)', dp).simulate('click'); + equalsDate(inp.datepicker('getDate'), new Date(2008, 2 - 1, 18), + 'Mouse click - next + min/max'); + // Inline + var inl = init('#inl'); + var dp = $('.ui-datepicker-inline', inl); + var date = new Date(); + inl.datepicker('setDate', date); + $('.ui-datepicker-calendar tbody a:contains(10)', dp).simulate('click', {}); + date.setDate(10); + equalsDate(inl.datepicker('getDate'), date, 'Mouse click inline'); + inl.datepicker('option', {showButtonPanel: true}).datepicker('setDate', new Date(2008, 2 - 1, 4)); + $('.ui-datepicker-calendar tbody a:contains(12)', dp).simulate('click', {}); + equalsDate(inl.datepicker('getDate'), new Date(2008, 2 - 1, 12), 'Mouse click inline - preset'); + inl.datepicker('option', {showButtonPanel: true}); + $('.ui-datepicker-current', dp).simulate('click', {}); + $('.ui-datepicker-calendar tbody a:contains(14)', dp).simulate('click', {}); + date.setDate(14); + equalsDate(inl.datepicker('getDate'), date, 'Mouse click inline - current'); + inl.datepicker('setDate', new Date(2008, 2 - 1, 4)); + $('.ui-datepicker-prev', dp).simulate('click'); + $('.ui-datepicker-calendar tbody a:contains(16)', dp).simulate('click'); + equalsDate(inl.datepicker('getDate'), new Date(2008, 1 - 1, 16), + 'Mouse click inline - previous'); + inl.datepicker('setDate', new Date(2008, 2 - 1, 4)); + $('.ui-datepicker-next', dp).simulate('click'); + $('.ui-datepicker-calendar tbody a:contains(18)', dp).simulate('click'); + equalsDate(inl.datepicker('getDate'), new Date(2008, 3 - 1, 18), + 'Mouse click inline - next'); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/datepicker/datepicker_defaults.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/datepicker/datepicker_defaults.js new file mode 100644 index 0000000..4243cf1 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/datepicker/datepicker_defaults.js @@ -0,0 +1,9 @@ +/* + * datepicker_defaults.js + */ + +var datepicker_defaults = { + disabled: false +}; + +//commonWidgetTests('datepicker', { defaults: datepicker_defaults }); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/datepicker/datepicker_events.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/datepicker/datepicker_events.js new file mode 100644 index 0000000..c7c16b6 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/datepicker/datepicker_events.js @@ -0,0 +1,127 @@ +/* + * datepicker_events.js + */ +(function($) { + +module("datepicker: events"); + +var selectedThis = null; +var selectedDate = null; +var selectedInst = null; + +function callback(date, inst) { + selectedThis = this; + selectedDate = date; + selectedInst = inst; +} + +function callback2(year, month, inst) { + selectedThis = this; + selectedDate = year + '/' + month; + selectedInst = inst; +} + +test('events', function() { + var inp = init('#inp', {onSelect: callback}); + var date = new Date(); + // onSelect + inp.val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equals(selectedThis, inp[0], 'Callback selected this'); + equals(selectedInst, $.data(inp[0], PROP_NAME), 'Callback selected inst'); + equals(selectedDate, $.datepicker.formatDate('mm/dd/yy', date), + 'Callback selected date'); + inp.val('').datepicker('show'). + simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_DOWN}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() + 7); + equals(selectedDate, $.datepicker.formatDate('mm/dd/yy', date), + 'Callback selected date - ctrl+down'); + inp.val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ESC}); + equals(selectedDate, $.datepicker.formatDate('mm/dd/yy', date), + 'Callback selected date - esc'); + var dateStr = '02/04/2008'; + inp.val(dateStr).datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equals(dateStr, selectedDate, + 'onSelect is called after enter keydown'); + // onChangeMonthYear + inp.datepicker('option', {onChangeMonthYear: callback2, onSelect: null}). + val('').datepicker('show'); + var newMonthYear = function(date) { + return date.getFullYear() + '/' + (date.getMonth() + 1); + }; + date = new Date(); + date.setDate(1); + inp.simulate('keydown', {keyCode: $.simulate.VK_PGUP}); + date.setMonth(date.getMonth() - 1); + equals(selectedThis, inp[0], 'Callback change month/year this'); + equals(selectedInst, $.data(inp[0], PROP_NAME), 'Callback change month/year inst'); + equals(selectedDate, newMonthYear(date), + 'Callback change month/year date - pgup'); + inp.simulate('keydown', {keyCode: $.simulate.VK_PGDN}); + date.setMonth(date.getMonth() + 1); + equals(selectedDate, newMonthYear(date), + 'Callback change month/year date - pgdn'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}); + date.setFullYear(date.getFullYear() - 1); + equals(selectedDate, newMonthYear(date), + 'Callback change month/year date - ctrl+pgup'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_HOME}); + date.setFullYear(date.getFullYear() + 1); + equals(selectedDate, newMonthYear(date), + 'Callback change month/year date - ctrl+home'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}); + date.setFullYear(date.getFullYear() + 1); + equals(selectedDate, newMonthYear(date), + 'Callback change month/year date - ctrl+pgdn'); + inp.datepicker('setDate', new Date(2007, 1 - 1, 26)); + equals(selectedDate, '2007/1', 'Callback change month/year date - setDate'); + selectedDate = null; + inp.datepicker('setDate', new Date(2007, 1 - 1, 12)); + ok(selectedDate == null, 'Callback change month/year date - setDate no change'); + // onChangeMonthYear step by 2 + inp.datepicker('option', {stepMonths: 2}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_PGUP}); + date.setMonth(date.getMonth() - 14); + equals(selectedDate, newMonthYear(date), + 'Callback change month/year by 2 date - pgup'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}); + date.setMonth(date.getMonth() - 12); + equals(selectedDate, newMonthYear(date), + 'Callback change month/year by 2 date - ctrl+pgup'); + inp.simulate('keydown', {keyCode: $.simulate.VK_PGDN}); + date.setMonth(date.getMonth() + 2); + equals(selectedDate, newMonthYear(date), + 'Callback change month/year by 2 date - pgdn'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}); + date.setMonth(date.getMonth() + 12); + equals(selectedDate, newMonthYear(date), + 'Callback change month/year by 2 date - ctrl+pgdn'); + // onClose + inp.datepicker('option', {onClose: callback, onChangeMonthYear: null, stepMonths: 1}). + val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ESC}); + equals(selectedThis, inp[0], 'Callback close this'); + equals(selectedInst, $.data(inp[0], PROP_NAME), 'Callback close inst'); + equals(selectedDate, '', 'Callback close date - esc'); + inp.val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equals(selectedDate, $.datepicker.formatDate('mm/dd/yy', new Date()), + 'Callback close date - enter'); + inp.val('02/04/2008').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ESC}); + equals(selectedDate, '02/04/2008', 'Callback close date - preset'); + inp.val('02/04/2008').datepicker('show'). + simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_END}); + equals(selectedDate, '', 'Callback close date - ctrl+end'); + + var inp2 = init('#inp2'); + inp2.datepicker().datepicker('option', {onClose: callback}).datepicker('show'); + inp.datepicker('show'); + equals(selectedThis, inp2[0], 'Callback close this'); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/datepicker/datepicker_methods.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/datepicker/datepicker_methods.js new file mode 100644 index 0000000..c8f1b75 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/datepicker/datepicker_methods.js @@ -0,0 +1,121 @@ +/* + * datepicker_methods.js + */ +(function($) { + +module("datepicker: methods"); + +test('destroy', function() { + var inp = init('#inp'); + ok(inp.is('.hasDatepicker'), 'Default - marker class set'); + ok($.data(inp[0], PROP_NAME), 'Default - instance present'); + ok(inp.next().is('#alt'), 'Default - button absent'); + inp.datepicker('destroy'); + inp = $('#inp'); + ok(!inp.is('.hasDatepicker'), 'Default - marker class cleared'); + ok(!$.data(inp[0], PROP_NAME), 'Default - instance absent'); + ok(inp.next().is('#alt'), 'Default - button absent'); + // With button + inp= init('#inp', {showOn: 'both'}); + ok(inp.is('.hasDatepicker'), 'Button - marker class set'); + ok($.data(inp[0], PROP_NAME), 'Button - instance present'); + ok(inp.next().text() == '...', 'Button - button added'); + inp.datepicker('destroy'); + inp = $('#inp'); + ok(!inp.is('.hasDatepicker'), 'Button - marker class cleared'); + ok(!$.data(inp[0], PROP_NAME), 'Button - instance absent'); + ok(inp.next().is('#alt'), 'Button - button removed'); + // With append text + inp = init('#inp', {appendText: 'Testing'}); + ok(inp.is('.hasDatepicker'), 'Append - marker class set'); + ok($.data(inp[0], PROP_NAME), 'Append - instance present'); + ok(inp.next().text() == 'Testing', 'Append - append text added'); + inp.datepicker('destroy'); + inp = $('#inp'); + ok(!inp.is('.hasDatepicker'), 'Append - marker class cleared'); + ok(!$.data(inp[0], PROP_NAME), 'Append - instance absent'); + ok(inp.next().is('#alt'), 'Append - append text removed'); + // With both + inp= init('#inp', {showOn: 'both', buttonImageOnly: true, + buttonImage: 'img/calendar.gif', appendText: 'Testing'}); + ok(inp.is('.hasDatepicker'), 'Both - marker class set'); + ok($.data(inp[0], PROP_NAME), 'Both - instance present'); + ok(inp.next()[0].nodeName.toLowerCase() == 'img', 'Both - button added'); + ok(inp.next().next().text() == 'Testing', 'Both - append text added'); + inp.datepicker('destroy'); + inp = $('#inp'); + ok(!inp.is('.hasDatepicker'), 'Both - marker class cleared'); + ok(!$.data(inp[0], PROP_NAME), 'Both - instance absent'); + ok(inp.next().is('#alt'), 'Both - button and append text absent'); + // Inline + var inl = init('#inl'); + ok(inl.is('.hasDatepicker'), 'Inline - marker class set'); + ok(inl.html() != '', 'Inline - datepicker present'); + ok($.data(inl[0], PROP_NAME), 'Inline - instance present'); + ok(inl.next().length == 0 || inl.next().is('p'), 'Inline - button absent'); + inl.datepicker('destroy'); + inl = $('#inl'); + ok(!inl.is('.hasDatepicker'), 'Inline - marker class cleared'); + ok(inl.html() == '', 'Inline - datepicker absent'); + ok(!$.data(inl[0], PROP_NAME), 'Inline - instance absent'); + ok(inl.next().length == 0 || inl.next().is('p'), 'Inline - button absent'); +}); + +test('enableDisable', function() { + var inp = init('#inp'); + ok(!inp.datepicker('isDisabled'), 'Enable/disable - initially marked as enabled'); + ok(!inp[0].disabled, 'Enable/disable - field initially enabled'); + inp.datepicker('disable'); + ok(inp.datepicker('isDisabled'), 'Enable/disable - now marked as disabled'); + ok(inp[0].disabled, 'Enable/disable - field now disabled'); + inp.datepicker('enable'); + ok(!inp.datepicker('isDisabled'), 'Enable/disable - now marked as enabled'); + ok(!inp[0].disabled, 'Enable/disable - field now enabled'); + inp.datepicker('destroy'); + // With a button + inp = init('#inp', {showOn: 'button'}); + ok(!inp.datepicker('isDisabled'), 'Enable/disable button - initially marked as enabled'); + ok(!inp[0].disabled, 'Enable/disable button - field initially enabled'); + ok(!inp.next('button')[0].disabled, 'Enable/disable button - button initially enabled'); + inp.datepicker('disable'); + ok(inp.datepicker('isDisabled'), 'Enable/disable button - now marked as disabled'); + ok(inp[0].disabled, 'Enable/disable button - field now disabled'); + ok(inp.next('button')[0].disabled, 'Enable/disable button - button now disabled'); + inp.datepicker('enable'); + ok(!inp.datepicker('isDisabled'), 'Enable/disable button - now marked as enabled'); + ok(!inp[0].disabled, 'Enable/disable button - field now enabled'); + ok(!inp.next('button')[0].disabled, 'Enable/disable button - button now enabled'); + inp.datepicker('destroy'); + // With an image button + inp = init('#inp', {showOn: 'button', buttonImageOnly: true, + buttonImage: 'img/calendar.gif'}); + ok(!inp.datepicker('isDisabled'), 'Enable/disable image - initially marked as enabled'); + ok(!inp[0].disabled, 'Enable/disable image - field initially enabled'); + ok(inp.next('img').css('opacity') == 1, 'Enable/disable image - image initially enabled'); + inp.datepicker('disable'); + ok(inp.datepicker('isDisabled'), 'Enable/disable image - now marked as disabled'); + ok(inp[0].disabled, 'Enable/disable image - field now disabled'); + ok(inp.next('img').css('opacity') != 1, 'Enable/disable image - image now disabled'); + inp.datepicker('enable'); + ok(!inp.datepicker('isDisabled'), 'Enable/disable image - now marked as enabled'); + ok(!inp[0].disabled, 'Enable/disable image - field now enabled'); + ok(inp.next('img').css('opacity') == 1, 'Enable/disable image - image now enabled'); + inp.datepicker('destroy'); + // Inline + var inl = init('#inl', {changeYear: true}); + var dp = $('.ui-datepicker-inline', inl); + ok(!inl.datepicker('isDisabled'), 'Enable/disable inline - initially marked as enabled'); + ok(!dp.children().is('.ui-state-disabled'), 'Enable/disable inline - not visually disabled initially'); + ok(!dp.find('select').prop('disabled'), 'Enable/disable inline - form element enabled initially'); + inl.datepicker('disable'); + ok(inl.datepicker('isDisabled'), 'Enable/disable inline - now marked as disabled'); + ok(dp.children().is('.ui-state-disabled'), 'Enable/disable inline - visually disabled'); + ok(dp.find('select').prop('disabled'), 'Enable/disable inline - form element disabled'); + inl.datepicker('enable'); + ok(!inl.datepicker('isDisabled'), 'Enable/disable inline - now marked as enabled'); + ok(!dp.children().is('.ui-state-disabled'), 'Enable/disable inline - not visiually disabled'); + ok(!dp.find('select').prop('disabled'), 'Enable/disable inline - form element enabled'); + inl.datepicker('destroy'); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/datepicker/datepicker_options.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/datepicker/datepicker_options.js new file mode 100644 index 0000000..272af9d --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/datepicker/datepicker_options.js @@ -0,0 +1,925 @@ +/* + * datepicker_options.js + */ + +(function($) { + +module("datepicker: options"); + +test('setDefaults', function() { + var inp = init('#inp'); + equals($.datepicker._defaults.showOn, 'focus', 'Initial showOn'); + $.datepicker.setDefaults({showOn: 'button'}); + equals($.datepicker._defaults.showOn, 'button', 'Change default showOn'); + $.datepicker.setDefaults({showOn: 'focus'}); + equals($.datepicker._defaults.showOn, 'focus', 'Restore showOn'); +}); + +test('option', function() { + var inp = init('#inp'); + var inst = $.data(inp[0], PROP_NAME); + // Set option + equals(inst.settings.showOn, null, 'Initial setting showOn'); + equals($.datepicker._get(inst, 'showOn'), 'focus', 'Initial instance showOn'); + equals($.datepicker._defaults.showOn, 'focus', 'Initial default showOn'); + inp.datepicker('option', 'showOn', 'button'); + equals(inst.settings.showOn, 'button', 'Change setting showOn'); + equals($.datepicker._get(inst, 'showOn'), 'button', 'Change instance showOn'); + equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn'); + inp.datepicker('option', {showOn: 'both'}); + equals(inst.settings.showOn, 'both', 'Change setting showOn'); + equals($.datepicker._get(inst, 'showOn'), 'both', 'Change instance showOn'); + equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn'); + inp.datepicker('option', 'showOn', undefined); + equals(inst.settings.showOn, null, 'Clear setting showOn'); + equals($.datepicker._get(inst, 'showOn'), 'focus', 'Restore instance showOn'); + equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn'); + // Get option + inp = init('#inp'); + equals(inp.datepicker('option', 'showOn'), 'focus', 'Initial setting showOn'); + inp.datepicker('option', 'showOn', 'button'); + equals(inp.datepicker('option', 'showOn'), 'button', 'Change instance showOn'); + inp.datepicker('option', 'showOn', undefined); + equals(inp.datepicker('option', 'showOn'), 'focus', 'Reset instance showOn'); + same(inp.datepicker('option', 'all'), {showAnim: ''}, 'Get instance settings'); + same(inp.datepicker('option', 'defaults'), $.datepicker._defaults, + 'Get default settings'); +}); + +test('change', function() { + var inp = init('#inp'); + var inst = $.data(inp[0], PROP_NAME); + equals(inst.settings.showOn, null, 'Initial setting showOn'); + equals($.datepicker._get(inst, 'showOn'), 'focus', 'Initial instance showOn'); + equals($.datepicker._defaults.showOn, 'focus', 'Initial default showOn'); + inp.datepicker('change', 'showOn', 'button'); + equals(inst.settings.showOn, 'button', 'Change setting showOn'); + equals($.datepicker._get(inst, 'showOn'), 'button', 'Change instance showOn'); + equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn'); + inp.datepicker('change', {showOn: 'both'}); + equals(inst.settings.showOn, 'both', 'Change setting showOn'); + equals($.datepicker._get(inst, 'showOn'), 'both', 'Change instance showOn'); + equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn'); + inp.datepicker('change', 'showOn', undefined); + equals(inst.settings.showOn, null, 'Clear setting showOn'); + equals($.datepicker._get(inst, 'showOn'), 'focus', 'Restore instance showOn'); + equals($.datepicker._defaults.showOn, 'focus', 'Retain default showOn'); +}); + +test('invocation', function() { + var inp = init('#inp'); + var dp = $('#ui-datepicker-div'); + var body = $('body'); + // On focus + var button = inp.siblings('button'); + ok(button.length == 0, 'Focus - button absent'); + var image = inp.siblings('img'); + ok(image.length == 0, 'Focus - image absent'); + inp.focus(); + ok(dp.is(':visible'), 'Focus - rendered on focus'); + inp.simulate('keydown', {keyCode: $.simulate.VK_ESC}); + ok(!dp.is(':visible'), 'Focus - hidden on exit'); + inp.focus(); + ok(dp.is(':visible'), 'Focus - rendered on focus'); + body.simulate('mousedown', {}); + ok(!dp.is(':visible'), 'Focus - hidden on external click'); + inp.datepicker('hide').datepicker('destroy'); + // On button + inp = init('#inp', {showOn: 'button', buttonText: 'Popup'}); + ok(!dp.is(':visible'), 'Button - initially hidden'); + button = inp.siblings('button'); + image = inp.siblings('img'); + ok(button.length == 1, 'Button - button present'); + ok(image.length == 0, 'Button - image absent'); + equals(button.text(), 'Popup', 'Button - button text'); + inp.focus(); + ok(!dp.is(':visible'), 'Button - not rendered on focus'); + button.click(); + ok(dp.is(':visible'), 'Button - rendered on button click'); + button.click(); + ok(!dp.is(':visible'), 'Button - hidden on second button click'); + inp.datepicker('hide').datepicker('destroy'); + // On image button + inp = init('#inp', {showOn: 'button', buttonImageOnly: true, + buttonImage: 'img/calendar.gif', buttonText: 'Cal'}); + ok(!dp.is(':visible'), 'Image button - initially hidden'); + button = inp.siblings('button'); + ok(button.length == 0, 'Image button - button absent'); + image = inp.siblings('img'); + ok(image.length == 1, 'Image button - image present'); + equals(image.attr('src'), 'img/calendar.gif', 'Image button - image source'); + equals(image.attr('title'), 'Cal', 'Image button - image text'); + inp.focus(); + ok(!dp.is(':visible'), 'Image button - not rendered on focus'); + image.click(); + ok(dp.is(':visible'), 'Image button - rendered on image click'); + image.click(); + ok(!dp.is(':visible'), 'Image button - hidden on second image click'); + inp.datepicker('hide').datepicker('destroy'); + // On both + inp = init('#inp', {showOn: 'both', buttonImage: 'img/calendar.gif'}); + ok(!dp.is(':visible'), 'Both - initially hidden'); + button = inp.siblings('button'); + ok(button.length == 1, 'Both - button present'); + image = inp.siblings('img'); + ok(image.length == 0, 'Both - image absent'); + image = button.children('img'); + ok(image.length == 1, 'Both - button image present'); + inp.focus(); + ok(dp.is(':visible'), 'Both - rendered on focus'); + body.simulate('mousedown', {}); + ok(!dp.is(':visible'), 'Both - hidden on external click'); + button.click(); + ok(dp.is(':visible'), 'Both - rendered on button click'); + button.click(); + ok(!dp.is(':visible'), 'Both - hidden on second button click'); + inp.datepicker('hide').datepicker('destroy'); +}); + +test('otherMonths', function() { + var inp = init('#inp'); + var pop = $('#ui-datepicker-div'); + inp.val('06/01/2009').datepicker('show'); + equals(pop.find('tbody').text(), '\u00a0123456789101112131415161718192021222324252627282930\u00a0\u00a0\u00a0\u00a0', + 'Other months - none'); + ok(pop.find('td:last *').length == 0, 'Other months - no content'); + inp.datepicker('hide').datepicker('option', 'showOtherMonths', true).datepicker('show'); + equals(pop.find('tbody').text(), '311234567891011121314151617181920212223242526272829301234', + 'Other months - show'); + ok(pop.find('td:last span').length == 1, 'Other months - span content'); + inp.datepicker('hide').datepicker('option', 'selectOtherMonths', true).datepicker('show'); + equals(pop.find('tbody').text(), '311234567891011121314151617181920212223242526272829301234', + 'Other months - select'); + ok(pop.find('td:last a').length == 1, 'Other months - link content'); + inp.datepicker('hide').datepicker('option', 'showOtherMonths', false).datepicker('show'); + equals(pop.find('tbody').text(), '\u00a0123456789101112131415161718192021222324252627282930\u00a0\u00a0\u00a0\u00a0', + 'Other months - none'); + ok(pop.find('td:last *').length == 0, 'Other months - no content'); +}); + +test('defaultDate', function() { + var inp = init('#inp'); + var date = new Date(); + inp.val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), date, 'Default date null'); + // Numeric values + inp.datepicker('option', {defaultDate: -2}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() - 2); + equalsDate(inp.datepicker('getDate'), date, 'Default date -2'); + inp.datepicker('option', {defaultDate: 3}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() + 5); + equalsDate(inp.datepicker('getDate'), date, 'Default date 3'); + inp.datepicker('option', {defaultDate: 1 / 0}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() - 3); + equalsDate(inp.datepicker('getDate'), date, 'Default date Infinity'); + inp.datepicker('option', {defaultDate: 1 / 'a'}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), date, 'Default date NaN'); + // String offset values + inp.datepicker('option', {defaultDate: '-1d'}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() - 1); + equalsDate(inp.datepicker('getDate'), date, 'Default date -1d'); + inp.datepicker('option', {defaultDate: '+3D'}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() + 4); + equalsDate(inp.datepicker('getDate'), date, 'Default date +3D'); + inp.datepicker('option', {defaultDate: ' -2 w '}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date = new Date(); + date.setDate(date.getDate() - 14); + equalsDate(inp.datepicker('getDate'), date, 'Default date -2 w'); + inp.datepicker('option', {defaultDate: '+1 W'}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setDate(date.getDate() + 21); + equalsDate(inp.datepicker('getDate'), date, 'Default date +1 W'); + inp.datepicker('option', {defaultDate: ' -1 m '}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date = addMonths(new Date(), -1); + equalsDate(inp.datepicker('getDate'), date, 'Default date -1 m'); + inp.datepicker('option', {defaultDate: '+2M'}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date = addMonths(new Date(), 2); + equalsDate(inp.datepicker('getDate'), date, 'Default date +2M'); + inp.datepicker('option', {defaultDate: '-2y'}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date = new Date(); + date.setFullYear(date.getFullYear() - 2); + equalsDate(inp.datepicker('getDate'), date, 'Default date -2y'); + inp.datepicker('option', {defaultDate: '+1 Y '}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date.setFullYear(date.getFullYear() + 3); + equalsDate(inp.datepicker('getDate'), date, 'Default date +1 Y'); + inp.datepicker('option', {defaultDate: '+1M +10d'}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date = addMonths(new Date(), 1); + date.setDate(date.getDate() + 10); + equalsDate(inp.datepicker('getDate'), date, 'Default date +1M +10d'); + // String date values + inp.datepicker('option', {defaultDate: '07/04/2007'}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date = new Date(2007, 7 - 1, 4); + equalsDate(inp.datepicker('getDate'), date, 'Default date 07/04/2007'); + inp.datepicker('option', {dateFormat: 'yy-mm-dd', defaultDate: '2007-04-02'}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + date = new Date(2007, 4 - 1, 2); + equalsDate(inp.datepicker('getDate'), date, 'Default date 2007-04-02'); + // Date value + date = new Date(2007, 1 - 1, 26); + inp.datepicker('option', {dateFormat: 'mm/dd/yy', defaultDate: date}). + datepicker('hide').val('').datepicker('show'). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), date, 'Default date 01/26/2007'); +}); + +test('miscellaneous', function() { + var dp = $('#ui-datepicker-div'); + var inp = init('#inp'); + // Year range + var genRange = function(start, offset) { + var range = ''; + for (var i = start; i < start + offset; i++) { + range += i; + } + return range; + }; + var curYear = new Date().getFullYear(); + inp.val('02/04/2008').datepicker('show'); + equals(dp.find('.ui-datepicker-year').text(), '2008', 'Year range - read-only default'); + inp.datepicker('hide').datepicker('option', {changeYear: true}).datepicker('show'); + equals(dp.find('.ui-datepicker-year').text(), genRange(2008 - 10, 21), 'Year range - changeable default'); + inp.datepicker('hide').datepicker('option', {yearRange: 'c-6:c+2', changeYear: true}).datepicker('show'); + equals(dp.find('.ui-datepicker-year').text(), genRange(2008 - 6, 9), 'Year range - c-6:c+2'); + inp.datepicker('hide').datepicker('option', {yearRange: '2000:2010', changeYear: true}).datepicker('show'); + equals(dp.find('.ui-datepicker-year').text(), genRange(2000, 11), 'Year range - 2000:2010'); + inp.datepicker('hide').datepicker('option', {yearRange: '-5:+3', changeYear: true}).datepicker('show'); + equals(dp.find('.ui-datepicker-year').text(), genRange(curYear - 5, 9), 'Year range - -5:+3'); + inp.datepicker('hide').datepicker('option', {yearRange: '2000:-5', changeYear: true}).datepicker('show'); + equals(dp.find('.ui-datepicker-year').text(), genRange(2000, curYear - 2004), 'Year range - 2000:-5'); + inp.datepicker('hide').datepicker('option', {yearRange: '', changeYear: true}).datepicker('show'); + equals(dp.find('.ui-datepicker-year').text(), genRange(curYear, 1), 'Year range - -6:+2'); + + // Navigation as date format + inp.datepicker('option', {showButtonPanel: true}); + equals(dp.find('.ui-datepicker-prev').text(), 'Prev', 'Navigation prev - default'); + equals(dp.find('.ui-datepicker-current').text(), 'Today', 'Navigation current - default'); + equals(dp.find('.ui-datepicker-next').text(), 'Next', 'Navigation next - default'); + inp.datepicker('hide').datepicker('option', {navigationAsDateFormat: true, prevText: '< M', currentText: 'MM', nextText: 'M >'}). + val('02/04/2008').datepicker('show'); + var longNames = $.datepicker.regional[''].monthNames; + var shortNames = $.datepicker.regional[''].monthNamesShort; + var date = new Date(); + equals(dp.find('.ui-datepicker-prev').text(), '< ' + shortNames[0], 'Navigation prev - as date format'); + equals(dp.find('.ui-datepicker-current').text(), + longNames[date.getMonth()], 'Navigation current - as date format'); + equals(dp.find('.ui-datepicker-next').text(), + shortNames[2] + ' >', 'Navigation next - as date format'); + inp.simulate('keydown', {keyCode: $.simulate.VK_PGDN}); + equals(dp.find('.ui-datepicker-prev').text(), + '< ' + shortNames[1], 'Navigation prev - as date format + pgdn'); + equals(dp.find('.ui-datepicker-current').text(), + longNames[date.getMonth()], 'Navigation current - as date format + pgdn'); + equals(dp.find('.ui-datepicker-next').text(), + shortNames[3] + ' >', 'Navigation next - as date format + pgdn'); + inp.datepicker('hide').datepicker('option', {gotoCurrent: true}). + val('02/04/2008').datepicker('show'); + equals(dp.find('.ui-datepicker-prev').text(), + '< ' + shortNames[0], 'Navigation prev - as date format + goto current'); + equals(dp.find('.ui-datepicker-current').text(), + longNames[1], 'Navigation current - as date format + goto current'); + equals(dp.find('.ui-datepicker-next').text(), + shortNames[2] + ' >', 'Navigation next - as date format + goto current'); +}); + +test('minMax', function() { + var inp = init('#inp'); + var lastYear = new Date(2007, 6 - 1, 4); + var nextYear = new Date(2009, 6 - 1, 4); + var minDate = new Date(2008, 2 - 1, 29); + var maxDate = new Date(2008, 12 - 1, 7); + inp.val('06/04/2008').datepicker('show'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), lastYear, + 'Min/max - null, null - ctrl+pgup'); + inp.val('06/04/2008').datepicker('show'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), nextYear, + 'Min/max - null, null - ctrl+pgdn'); + inp.datepicker('option', {minDate: minDate}). + datepicker('hide').val('06/04/2008').datepicker('show'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), minDate, + 'Min/max - 02/29/2008, null - ctrl+pgup'); + inp.val('06/04/2008').datepicker('show'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), nextYear, + 'Min/max - 02/29/2008, null - ctrl+pgdn'); + inp.datepicker('option', {maxDate: maxDate}). + datepicker('hide').val('06/04/2008').datepicker('show'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), minDate, + 'Min/max - 02/29/2008, 12/07/2008 - ctrl+pgup'); + inp.val('06/04/2008').datepicker('show'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), maxDate, + 'Min/max - 02/29/2008, 12/07/2008 - ctrl+pgdn'); + inp.datepicker('option', {minDate: null}). + datepicker('hide').val('06/04/2008').datepicker('show'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), lastYear, + 'Min/max - null, 12/07/2008 - ctrl+pgup'); + inp.val('06/04/2008').datepicker('show'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), maxDate, + 'Min/max - null, 12/07/2008 - ctrl+pgdn'); + // Relative dates + var date = new Date(); + date.setDate(date.getDate() - 7); + inp.datepicker('option', {minDate: '-1w', maxDate: '+1 M +10 D '}). + datepicker('hide').val('').datepicker('show'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGUP}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), date, + 'Min/max - -1w, +1 M +10 D - ctrl+pgup'); + date = addMonths(new Date(), 1); + date.setDate(date.getDate() + 10); + inp.val('').datepicker('show'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_PGDN}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equalsDate(inp.datepicker('getDate'), date, + 'Min/max - -1w, +1 M +10 D - ctrl+pgdn'); + // With existing date + inp = init('#inp'); + inp.val('06/04/2008').datepicker('option', {minDate: minDate}); + equalsDate(inp.datepicker('getDate'), new Date(2008, 6 - 1, 4), 'Min/max - setDate > min'); + inp.datepicker('option', {minDate: null}).val('01/04/2008').datepicker('option', {minDate: minDate}); + equalsDate(inp.datepicker('getDate'), minDate, 'Min/max - setDate < min'); + inp.datepicker('option', {minDate: null}).val('06/04/2008').datepicker('option', {maxDate: maxDate}); + equalsDate(inp.datepicker('getDate'), new Date(2008, 6 - 1, 4), 'Min/max - setDate < max'); + inp.datepicker('option', {maxDate: null}).val('01/04/2009').datepicker('option', {maxDate: maxDate}); + equalsDate(inp.datepicker('getDate'), maxDate, 'Min/max - setDate > max'); + inp.datepicker('option', {maxDate: null}).val('01/04/2008').datepicker('option', {minDate: minDate, maxDate: maxDate}); + equalsDate(inp.datepicker('getDate'), minDate, 'Min/max - setDate < min'); + inp.datepicker('option', {maxDate: null}).val('06/04/2008').datepicker('option', {minDate: minDate, maxDate: maxDate}); + equalsDate(inp.datepicker('getDate'), new Date(2008, 6 - 1, 4), 'Min/max - setDate > min, < max'); + inp.datepicker('option', {maxDate: null}).val('01/04/2009').datepicker('option', {minDate: minDate, maxDate: maxDate}); + equalsDate(inp.datepicker('getDate'), maxDate, 'Min/max - setDate > max'); +}); + +test('setDate', function() { + var inp = init('#inp'); + var date1 = new Date(2008, 6 - 1, 4); + var date2 = new Date(); + ok(inp.datepicker('getDate') == null, 'Set date - default'); + inp.datepicker('setDate', date1); + equalsDate(inp.datepicker('getDate'), date1, 'Set date - 2008-06-04'); + date1 = new Date(); + date1.setDate(date1.getDate() + 7); + inp.datepicker('setDate', +7); + equalsDate(inp.datepicker('getDate'), date1, 'Set date - +7'); + date2.setFullYear(date2.getFullYear() + 2); + inp.datepicker('setDate', '+2y'); + equalsDate(inp.datepicker('getDate'), date2, 'Set date - +2y'); + inp.datepicker('setDate', date1, date2); + equalsDate(inp.datepicker('getDate'), date1, 'Set date - two dates'); + inp.datepicker('setDate'); + ok(inp.datepicker('getDate') == null, 'Set date - null'); + // Relative to current date + date1 = new Date(); + date1.setDate(date1.getDate() + 7); + inp.datepicker('setDate', 'c +7'); + equalsDate(inp.datepicker('getDate'), date1, 'Set date - c +7'); + date1.setDate(date1.getDate() + 7); + inp.datepicker('setDate', 'c+7'); + equalsDate(inp.datepicker('getDate'), date1, 'Set date - c+7'); + date1.setDate(date1.getDate() - 21); + inp.datepicker('setDate', 'c -3 w'); + equalsDate(inp.datepicker('getDate'), date1, 'Set date - c -3 w'); + // Inline + var inl = init('#inl'); + date1 = new Date(2008, 6 - 1, 4); + date2 = new Date(); + equalsDate(inl.datepicker('getDate'), date2, 'Set date inline - default'); + inl.datepicker('setDate', date1); + equalsDate(inl.datepicker('getDate'), date1, 'Set date inline - 2008-06-04'); + date1 = new Date(); + date1.setDate(date1.getDate() + 7); + inl.datepicker('setDate', +7); + equalsDate(inl.datepicker('getDate'), date1, 'Set date inline - +7'); + date2.setFullYear(date2.getFullYear() + 2); + inl.datepicker('setDate', '+2y'); + equalsDate(inl.datepicker('getDate'), date2, 'Set date inline - +2y'); + inl.datepicker('setDate', date1, date2); + equalsDate(inl.datepicker('getDate'), date1, 'Set date inline - two dates'); + inl.datepicker('setDate'); + ok(inl.datepicker('getDate') == null, 'Set date inline - null'); + // Alternate field + var alt = $('#alt'); + inp.datepicker('option', {altField: '#alt', altFormat: 'yy-mm-dd'}); + date1 = new Date(2008, 6 - 1, 4); + inp.datepicker('setDate', date1); + equals(inp.val(), '06/04/2008', 'Set date alternate - 06/04/2008'); + equals(alt.val(), '2008-06-04', 'Set date alternate - 2008-06-04'); + // With minimum/maximum + inp = init('#inp'); + date1 = new Date(2008, 1 - 1, 4); + date2 = new Date(2008, 6 - 1, 4); + var minDate = new Date(2008, 2 - 1, 29); + var maxDate = new Date(2008, 3 - 1, 28); + inp.val('').datepicker('option', {minDate: minDate}).datepicker('setDate', date2); + equalsDate(inp.datepicker('getDate'), date2, 'Set date min/max - setDate > min'); + inp.datepicker('setDate', date1); + equalsDate(inp.datepicker('getDate'), minDate, 'Set date min/max - setDate < min'); + inp.val('').datepicker('option', {maxDate: maxDate, minDate: null}).datepicker('setDate', date1); + equalsDate(inp.datepicker('getDate'), date1, 'Set date min/max - setDate < max'); + inp.datepicker('setDate', date2); + equalsDate(inp.datepicker('getDate'), maxDate, 'Set date min/max - setDate > max'); + inp.val('').datepicker('option', {minDate: minDate}).datepicker('setDate', date1); + equalsDate(inp.datepicker('getDate'), minDate, 'Set date min/max - setDate < min'); + inp.datepicker('setDate', date2); + equalsDate(inp.datepicker('getDate'), maxDate, 'Set date min/max - setDate > max'); + var dateAndTimeToSet = new Date(2008, 3 - 1, 28, 1, 11, 0); + var dateAndTimeClone = new Date(2008, 3 - 1, 28, 1, 11, 0); + inp.datepicker('setDate', dateAndTimeToSet); + equals(dateAndTimeToSet.getTime(), dateAndTimeClone.getTime(), 'Date object passed should not be changed by setDate'); +}); + +test('altField', function() { + var inp = init('#inp'); + var alt = $('#alt'); + // No alternate field set + alt.val(''); + inp.val('06/04/2008').datepicker('show'); + inp.simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equals(inp.val(), '06/04/2008', 'Alt field - dp - enter'); + equals(alt.val(), '', 'Alt field - alt not set'); + // Alternate field set + alt.val(''); + inp.datepicker('option', {altField: '#alt', altFormat: 'yy-mm-dd'}). + val('06/04/2008').datepicker('show'); + inp.simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equals(inp.val(), '06/04/2008', 'Alt field - dp - enter'); + equals(alt.val(), '2008-06-04', 'Alt field - alt - enter'); + // Move from initial date + alt.val(''); + inp.val('06/04/2008').datepicker('show'); + inp.simulate('keydown', {keyCode: $.simulate.VK_PGDN}). + simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + equals(inp.val(), '07/04/2008', 'Alt field - dp - pgdn'); + equals(alt.val(), '2008-07-04', 'Alt field - alt - pgdn'); + // Alternate field set - closed + alt.val(''); + inp.val('06/04/2008').datepicker('show'); + inp.simulate('keydown', {keyCode: $.simulate.VK_PGDN}). + simulate('keydown', {keyCode: $.simulate.VK_ESC}); + equals(inp.val(), '06/04/2008', 'Alt field - dp - pgdn/esc'); + equals(alt.val(), '', 'Alt field - alt - pgdn/esc'); + // Clear date and alternate + alt.val(''); + inp.val('06/04/2008').datepicker('show'); + inp.simulate('keydown', {ctrlKey: true, keyCode: $.simulate.VK_END}); + equals(inp.val(), '', 'Alt field - dp - ctrl+end'); + equals(alt.val(), '', 'Alt field - alt - ctrl+end'); + + return + // TODO manual entry impl works (see altField demo) but this test doesn't + // probably something the rewrite won't cover anymore anyway + + // Verify alt field is updated on keyup + alt.val(''); + inp.val('06/04/200').datepicker('show'); + inp.simulate('keydown', {charCode: '8'.charCodeAt(0)}); + inp.simulate('keypress', {charCode: '8'.charCodeAt(0)}); + inp.simulate('keyup', {charCode: '8'.charCodeAt(0)}); + equals(inp.val(), '06/04/2008', 'Alt field - dp - manual entry'); + equals(alt.val(), '2008-06-04', 'Alt field - manual entry'); + // Verify alt field is not updated on keyup if date is invalid + inp.val('12/04'); + inp.simulate('keydown', {charCode: '/'.charCodeAt(0)}); + inp.simulate('keypress', {charCode: '/'.charCodeAt(0)}); + inp.simulate('keyup', {charCode: '/'.charCodeAt(0)}); + equals(inp.val(), '12/04/', 'Alt field - dp - manual entry incomplete'); + equals(alt.val(), '2008-06-04', 'Alt field - manual entry - not updated'); +}); + +test('autoSize', function() { + var inp = init('#inp'); + equals(inp.prop('size'), 20, 'Auto size - default'); + inp.datepicker('option', 'autoSize', true); + equals(inp.prop('size'), 10, 'Auto size - mm/dd/yy'); + inp.datepicker('option', 'dateFormat', 'm/d/yy'); + equals(inp.prop('size'), 10, 'Auto size - m/d/yy'); + inp.datepicker('option', 'dateFormat', 'D M d yy'); + equals(inp.prop('size'), 15, 'Auto size - D M d yy'); + inp.datepicker('option', 'dateFormat', 'DD, MM dd, yy'); + equals(inp.prop('size'), 29, 'Auto size - DD, MM dd, yy'); + // French + inp.datepicker('option', $.extend({autoSize: false}, $.datepicker.regional['fr'])); + equals(inp.prop('size'), 29, 'Auto size - fr - default'); + inp.datepicker('option', 'autoSize', true); + equals(inp.prop('size'), 10, 'Auto size - fr - dd/mm/yy'); + inp.datepicker('option', 'dateFormat', 'm/d/yy'); + equals(inp.prop('size'), 10, 'Auto size - fr - m/d/yy'); + inp.datepicker('option', 'dateFormat', 'D M d yy'); + equals(inp.prop('size'), 18, 'Auto size - fr - D M d yy'); + inp.datepicker('option', 'dateFormat', 'DD, MM dd, yy'); + equals(inp.prop('size'), 28, 'Auto size - fr - DD, MM dd, yy'); + // Hebrew + inp.datepicker('option', $.extend({autoSize: false}, $.datepicker.regional['he'])); + equals(inp.prop('size'), 28, 'Auto size - he - default'); + inp.datepicker('option', 'autoSize', true); + equals(inp.prop('size'), 10, 'Auto size - he - dd/mm/yy'); + inp.datepicker('option', 'dateFormat', 'm/d/yy'); + equals(inp.prop('size'), 10, 'Auto size - he - m/d/yy'); + inp.datepicker('option', 'dateFormat', 'D M d yy'); + equals(inp.prop('size'), 14, 'Auto size - he - D M d yy'); + inp.datepicker('option', 'dateFormat', 'DD, MM dd, yy'); + equals(inp.prop('size'), 23, 'Auto size - he - DD, MM dd, yy'); +}); + +test('daylightSaving', function() { + var inp = init('#inp'); + var dp = $('#ui-datepicker-div'); + ok(true, 'Daylight saving - ' + new Date()); + // Australia, Sydney - AM change, southern hemisphere + inp.val('04/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(6) a', dp).simulate('click'); + equals(inp.val(), '04/05/2008', 'Daylight saving - Australia 04/05/2008'); + inp.val('04/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(7) a', dp).simulate('click'); + equals(inp.val(), '04/06/2008', 'Daylight saving - Australia 04/06/2008'); + inp.val('04/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(8) a', dp).simulate('click'); + equals(inp.val(), '04/07/2008', 'Daylight saving - Australia 04/07/2008'); + inp.val('10/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(6) a', dp).simulate('click'); + equals(inp.val(), '10/04/2008', 'Daylight saving - Australia 10/04/2008'); + inp.val('10/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(7) a', dp).simulate('click'); + equals(inp.val(), '10/05/2008', 'Daylight saving - Australia 10/05/2008'); + inp.val('10/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(8) a', dp).simulate('click'); + equals(inp.val(), '10/06/2008', 'Daylight saving - Australia 10/06/2008'); + // Brasil, Brasilia - midnight change, southern hemisphere + inp.val('02/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(20) a', dp).simulate('click'); + equals(inp.val(), '02/16/2008', 'Daylight saving - Brasil 02/16/2008'); + inp.val('02/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(21) a', dp).simulate('click'); + equals(inp.val(), '02/17/2008', 'Daylight saving - Brasil 02/17/2008'); + inp.val('02/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(22) a', dp).simulate('click'); + equals(inp.val(), '02/18/2008', 'Daylight saving - Brasil 02/18/2008'); + inp.val('10/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(13) a', dp).simulate('click'); + equals(inp.val(), '10/11/2008', 'Daylight saving - Brasil 10/11/2008'); + inp.val('10/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(14) a', dp).simulate('click'); + equals(inp.val(), '10/12/2008', 'Daylight saving - Brasil 10/12/2008'); + inp.val('10/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(15) a', dp).simulate('click'); + equals(inp.val(), '10/13/2008', 'Daylight saving - Brasil 10/13/2008'); + // Lebanon, Beirut - midnight change, northern hemisphere + inp.val('03/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(34) a', dp).simulate('click'); + equals(inp.val(), '03/29/2008', 'Daylight saving - Lebanon 03/29/2008'); + inp.val('03/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(35) a', dp).simulate('click'); + equals(inp.val(), '03/30/2008', 'Daylight saving - Lebanon 03/30/2008'); + inp.val('03/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(36) a', dp).simulate('click'); + equals(inp.val(), '03/31/2008', 'Daylight saving - Lebanon 03/31/2008'); + inp.val('10/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(27) a', dp).simulate('click'); + equals(inp.val(), '10/25/2008', 'Daylight saving - Lebanon 10/25/2008'); + inp.val('10/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(28) a', dp).simulate('click'); + equals(inp.val(), '10/26/2008', 'Daylight saving - Lebanon 10/26/2008'); + inp.val('10/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(29) a', dp).simulate('click'); + equals(inp.val(), '10/27/2008', 'Daylight saving - Lebanon 10/27/2008'); + // US, Eastern - AM change, northern hemisphere + inp.val('03/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(13) a', dp).simulate('click'); + equals(inp.val(), '03/08/2008', 'Daylight saving - US 03/08/2008'); + inp.val('03/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(14) a', dp).simulate('click'); + equals(inp.val(), '03/09/2008', 'Daylight saving - US 03/09/2008'); + inp.val('03/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(15) a', dp).simulate('click'); + equals(inp.val(), '03/10/2008', 'Daylight saving - US 03/10/2008'); + inp.val('11/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(6) a', dp).simulate('click'); + equals(inp.val(), '11/01/2008', 'Daylight saving - US 11/01/2008'); + inp.val('11/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(7) a', dp).simulate('click'); + equals(inp.val(), '11/02/2008', 'Daylight saving - US 11/02/2008'); + inp.val('11/01/2008').datepicker('show'); + $('.ui-datepicker-calendar td:eq(8) a', dp).simulate('click'); + equals(inp.val(), '11/03/2008', 'Daylight saving - US 11/03/2008'); +}); + +var beforeShowThis = null; +var beforeShowInput = null; +var beforeShowInst = null; + +function beforeAll(input, inst) { + beforeShowThis = this; + beforeShowInput = input; + beforeShowInst = inst; + return {currentText: 'Current'}; +} + +var beforeShowDayThis = null; +var beforeShowDayOK = true; + +function beforeDay(date) { + beforeShowDayThis = this; + beforeShowDayOK &= (date > new Date(2008, 1 - 1, 26) && + date < new Date(2008, 3 - 1, 6)); + return [(date.getDate() % 2 == 0), (date.getDate() % 10 == 0 ? 'day10' : ''), + (date.getDate() % 3 == 0 ? 'Divisble by 3' : '')]; +} + +function calcWeek(date) { + var doy = date.getDate() + 6; + for (var m = date.getMonth() - 1; m >= 0; m--) + doy += $.datepicker._getDaysInMonth(date.getFullYear(), m); + // Simple count from 01/01 starting at week 1 + return Math.floor(doy / 7); +} + +test('callbacks', function() { + // Before show + var inp = init('#inp', {beforeShow: beforeAll}); + var inst = $.data(inp[0], 'datepicker'); + equals($.datepicker._get(inst, 'currentText'), 'Today', 'Before show - initial'); + inp.val('02/04/2008').datepicker('show'); + equals($.datepicker._get(inst, 'currentText'), 'Current', 'Before show - changed'); + ok(beforeShowThis.id == inp[0].id, 'Before show - this OK'); + ok(beforeShowInput.id == inp[0].id, 'Before show - input OK'); + deepEqual(beforeShowInst, inst, 'Before show - inst OK'); + inp.datepicker('hide').datepicker('destroy'); + // Before show day + inp = init('#inp', {beforeShowDay: beforeDay}); + var dp = $('#ui-datepicker-div'); + inp.val('02/04/2008').datepicker('show'); + ok(beforeShowDayThis.id == inp[0].id, 'Before show day - this OK'); + ok(beforeShowDayOK, 'Before show day - dates OK'); + var day20 = dp.find('.ui-datepicker-calendar td:contains("20")'); + var day21 = dp.find('.ui-datepicker-calendar td:contains("21")'); + ok(!day20.is('.ui-datepicker-unselectable'), 'Before show day - unselectable 20'); + ok(day21.is('.ui-datepicker-unselectable'), 'Before show day - unselectable 21'); + ok(day20.is('.day10'), 'Before show day - CSS 20'); + ok(!day21.is('.day10'), 'Before show day - CSS 21'); + ok(!day20.attr('title'), 'Before show day - title 20'); + ok(day21.attr('title') == 'Divisble by 3', 'Before show day - title 21'); + inp.datepicker('hide').datepicker('destroy'); +}); + +test('localisation', function() { + var inp = init('#inp', $.datepicker.regional['fr']); + inp.datepicker('option', {dateFormat: 'DD, d MM yy', showButtonPanel:true, changeMonth:true, changeYear:true}).val('').datepicker('show'); + var dp = $('#ui-datepicker-div'); + equals($('.ui-datepicker-close', dp).text(), 'Fermer', 'Localisation - close'); + $('.ui-datepicker-close', dp).simulate('mouseover'); + equals($('.ui-datepicker-prev', dp).text(), 'Précédent', 'Localisation - previous'); + equals($('.ui-datepicker-current', dp).text(), 'Aujourd\'hui', 'Localisation - current'); + equals($('.ui-datepicker-next', dp).text(), 'Suivant', 'Localisation - next'); + var month = 0; + $('.ui-datepicker-month option', dp).each(function() { + equals($(this).text(), $.datepicker.regional['fr'].monthNamesShort[month], + 'Localisation - month ' + month); + month++; + }); + var day = 1; + $('.ui-datepicker-calendar th', dp).each(function() { + equals($(this).text(), $.datepicker.regional['fr'].dayNamesMin[day], + 'Localisation - day ' + day); + day = (day + 1) % 7; + }); + inp.simulate('keydown', {keyCode: $.simulate.VK_ENTER}); + var date = new Date(); + equals(inp.val(), $.datepicker.regional['fr'].dayNames[date.getDay()] + ', ' + + date.getDate() + ' ' + $.datepicker.regional['fr'].monthNames[date.getMonth()] + + ' ' + date.getFullYear(), 'Localisation - formatting'); +}); + +test('noWeekends', function() { + for (var i = 1; i <= 31; i++) { + var date = new Date(2001, 1 - 1, i); + deepEqual($.datepicker.noWeekends(date), [(i + 1) % 7 >= 2, ''], + 'No weekends ' + date); + } +}); + +test('iso8601Week', function() { + var date = new Date(2000, 12 - 1, 31); + equals($.datepicker.iso8601Week(date), 52, 'ISO 8601 week ' + date); + date = new Date(2001, 1 - 1, 1); + equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date); + date = new Date(2001, 1 - 1, 7); + equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date); + date = new Date(2001, 1 - 1, 8); + equals($.datepicker.iso8601Week(date), 2, 'ISO 8601 week ' + date); + date = new Date(2003, 12 - 1, 28); + equals($.datepicker.iso8601Week(date), 52, 'ISO 8601 week ' + date); + date = new Date(2003, 12 - 1, 29); + equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date); + date = new Date(2004, 1 - 1, 4); + equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date); + date = new Date(2004, 1 - 1, 5); + equals($.datepicker.iso8601Week(date), 2, 'ISO 8601 week ' + date); + date = new Date(2009, 12 - 1, 28); + equals($.datepicker.iso8601Week(date), 53, 'ISO 8601 week ' + date); + date = new Date(2010, 1 - 1, 3); + equals($.datepicker.iso8601Week(date), 53, 'ISO 8601 week ' + date); + date = new Date(2010, 1 - 1, 4); + equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date); + date = new Date(2010, 1 - 1, 10); + equals($.datepicker.iso8601Week(date), 1, 'ISO 8601 week ' + date); +}); + +test('parseDate', function() { + init('#inp'); + ok($.datepicker.parseDate('d m y', '') == null, 'Parse date empty'); + equalsDate($.datepicker.parseDate('d m y', '3 2 01'), + new Date(2001, 2 - 1, 3), 'Parse date d m y'); + equalsDate($.datepicker.parseDate('dd mm yy', '03 02 2001'), + new Date(2001, 2 - 1, 3), 'Parse date dd mm yy'); + equalsDate($.datepicker.parseDate('d m y', '13 12 01'), + new Date(2001, 12 - 1, 13), 'Parse date d m y'); + equalsDate($.datepicker.parseDate('dd mm yy', '13 12 2001'), + new Date(2001, 12 - 1, 13), 'Parse date dd mm yy'); + equalsDate($.datepicker.parseDate('y-o', '01-34'), + new Date(2001, 2 - 1, 3), 'Parse date y-o'); + equalsDate($.datepicker.parseDate('yy-oo', '2001-347'), + new Date(2001, 12 - 1, 13), 'Parse date yy-oo'); + equalsDate($.datepicker.parseDate('oo yy', '348 2004'), + new Date(2004, 12 - 1, 13), 'Parse date oo yy'); + equalsDate($.datepicker.parseDate('D d M y', 'Sat 3 Feb 01'), + new Date(2001, 2 - 1, 3), 'Parse date D d M y'); + equalsDate($.datepicker.parseDate('d MM DD yy', '3 February Saturday 2001'), + new Date(2001, 2 - 1, 3), 'Parse date dd MM DD yy'); + equalsDate($.datepicker.parseDate('DD, MM d, yy', 'Saturday, February 3, 2001'), + new Date(2001, 2 - 1, 3), 'Parse date DD, MM d, yy'); + equalsDate($.datepicker.parseDate('\'day\' d \'of\' MM (\'\'DD\'\'), yy', + 'day 3 of February (\'Saturday\'), 2001'), new Date(2001, 2 - 1, 3), + 'Parse date \'day\' d \'of\' MM (\'\'DD\'\'), yy'); + var currentYear = new Date().getFullYear(); + equalsDate($.datepicker.parseDate('y-m-d', (currentYear - 2000) + '-02-03'), + new Date(currentYear, 2 - 1, 3), 'Parse date y-m-d - default cutuff'); + equalsDate($.datepicker.parseDate('y-m-d', (currentYear - 2000 + 10) + '-02-03'), + new Date(currentYear+10, 2 - 1, 3), 'Parse date y-m-d - default cutuff'); + equalsDate($.datepicker.parseDate('y-m-d', (currentYear - 2000 + 11) + '-02-03'), + new Date(currentYear-89, 2 - 1, 3), 'Parse date y-m-d - default cutuff'); + equalsDate($.datepicker.parseDate('y-m-d', '80-02-03', {shortYearCutoff: 80}), + new Date(2080, 2 - 1, 3), 'Parse date y-m-d - cutoff 80'); + equalsDate($.datepicker.parseDate('y-m-d', '81-02-03', {shortYearCutoff: 80}), + new Date(1981, 2 - 1, 3), 'Parse date y-m-d - cutoff 80'); + equalsDate($.datepicker.parseDate('y-m-d', (currentYear - 2000 + 60) + '-02-03', {shortYearCutoff: '+60'}), + new Date(currentYear + 60, 2 - 1, 3), 'Parse date y-m-d - cutoff +60'); + equalsDate($.datepicker.parseDate('y-m-d', (currentYear - 2000 + 61) + '-02-03', {shortYearCutoff: '+60'}), + new Date(currentYear - 39, 2 - 1, 3), 'Parse date y-m-d - cutoff +60'); + var gmtDate = new Date(2001, 2 - 1, 3); + gmtDate.setMinutes(gmtDate.getMinutes() - gmtDate.getTimezoneOffset()); + equalsDate($.datepicker.parseDate('@', '981158400000'), gmtDate, 'Parse date @'); + equalsDate($.datepicker.parseDate('!', '631167552000000000'), gmtDate, 'Parse date !'); + var fr = $.datepicker.regional['fr']; + var settings = {dayNamesShort: fr.dayNamesShort, dayNames: fr.dayNames, + monthNamesShort: fr.monthNamesShort, monthNames: fr.monthNames}; + equalsDate($.datepicker.parseDate('D d M y', 'Lun. 9 Avril 01', settings), + new Date(2001, 4 - 1, 9), 'Parse date D M y with settings'); + equalsDate($.datepicker.parseDate('d MM DD yy', '9 Avril Lundi 2001', settings), + new Date(2001, 4 - 1, 9), 'Parse date d MM DD yy with settings'); + equalsDate($.datepicker.parseDate('DD, MM d, yy', 'Lundi, Avril 9, 2001', settings), + new Date(2001, 4 - 1, 9), 'Parse date DD, MM d, yy with settings'); + equalsDate($.datepicker.parseDate('\'jour\' d \'de\' MM (\'\'DD\'\'), yy', + 'jour 9 de Avril (\'Lundi\'), 2001', settings), new Date(2001, 4 - 1, 9), + 'Parse date \'jour\' d \'de\' MM (\'\'DD\'\'), yy with settings'); + + var zh = $.datepicker.regional['zh-CN']; + equalsDate($.datepicker.parseDate('yy M d', '2011 十一 22', zh), + new Date(2011, 11 - 1, 22), 'Parse date yy M d with zh-CN'); +}); + +test('parseDateErrors', function() { + init('#inp'); + var expectError = function(expr, value, error) { + try { + expr(); + ok(false, 'Parsed error ' + value); + } + catch (e) { + equals(e, error, 'Parsed error ' + value); + } + }; + expectError(function() { $.datepicker.parseDate(null, 'Sat 2 01'); }, + 'Sat 2 01', 'Invalid arguments'); + expectError(function() { $.datepicker.parseDate('d m y', null); }, + 'null', 'Invalid arguments'); + expectError(function() { $.datepicker.parseDate('d m y', 'Sat 2 01'); }, + 'Sat 2 01 - d m y', 'Missing number at position 0'); + expectError(function() { $.datepicker.parseDate('dd mm yy', 'Sat 2 01'); }, + 'Sat 2 01 - dd mm yy', 'Missing number at position 0'); + expectError(function() { $.datepicker.parseDate('d m y', '3 Feb 01'); }, + '3 Feb 01 - d m y', 'Missing number at position 2'); + expectError(function() { $.datepicker.parseDate('dd mm yy', '3 Feb 01'); }, + '3 Feb 01 - dd mm yy', 'Missing number at position 2'); + expectError(function() { $.datepicker.parseDate('d m y', '3 2 AD01'); }, + '3 2 AD01 - d m y', 'Missing number at position 4'); + expectError(function() { $.datepicker.parseDate('d m yy', '3 2 AD01'); }, + '3 2 AD01 - dd mm yy', 'Missing number at position 4'); + expectError(function() { $.datepicker.parseDate('y-o', '01-D01'); }, + '2001-D01 - y-o', 'Missing number at position 3'); + expectError(function() { $.datepicker.parseDate('yy-oo', '2001-D01'); }, + '2001-D01 - yy-oo', 'Missing number at position 5'); + expectError(function() { $.datepicker.parseDate('D d M y', 'D7 3 Feb 01'); }, + 'D7 3 Feb 01 - D d M y', 'Unknown name at position 0'); + expectError(function() { $.datepicker.parseDate('D d M y', 'Sat 3 M2 01'); }, + 'Sat 3 M2 01 - D d M y', 'Unknown name at position 6'); + expectError(function() { $.datepicker.parseDate('DD, MM d, yy', 'Saturday- Feb 3, 2001'); }, + 'Saturday- Feb 3, 2001 - DD, MM d, yy', 'Unexpected literal at position 8'); + expectError(function() { $.datepicker.parseDate('\'day\' d \'of\' MM (\'\'DD\'\'), yy', + 'day 3 of February ("Saturday"), 2001'); }, + 'day 3 of Mon2 ("Day7"), 2001', 'Unexpected literal at position 19'); + expectError(function() { $.datepicker.parseDate('d m y', '29 2 01'); }, + '29 2 01 - d m y', 'Invalid date'); + var fr = $.datepicker.regional['fr']; + var settings = {dayNamesShort: fr.dayNamesShort, dayNames: fr.dayNames, + monthNamesShort: fr.monthNamesShort, monthNames: fr.monthNames}; + expectError(function() { $.datepicker.parseDate('D d M y', 'Mon 9 Avr 01', settings); }, + 'Mon 9 Avr 01 - D d M y', 'Unknown name at position 0'); + expectError(function() { $.datepicker.parseDate('D d M y', 'Lun. 9 Apr 01', settings); }, + 'Lun. 9 Apr 01 - D d M y', 'Unknown name at position 7'); +}); + +test('formatDate', function() { + init('#inp'); + equals($.datepicker.formatDate('d m y', new Date(2001, 2 - 1, 3)), + '3 2 01', 'Format date d m y'); + equals($.datepicker.formatDate('dd mm yy', new Date(2001, 2 - 1, 3)), + '03 02 2001', 'Format date dd mm yy'); + equals($.datepicker.formatDate('d m y', new Date(2001, 12 - 1, 13)), + '13 12 01', 'Format date d m y'); + equals($.datepicker.formatDate('dd mm yy', new Date(2001, 12 - 1, 13)), + '13 12 2001', 'Format date dd mm yy'); + equals($.datepicker.formatDate('yy-o', new Date(2001, 2 - 1, 3)), + '2001-34', 'Format date yy-o'); + equals($.datepicker.formatDate('yy-oo', new Date(2001, 2 - 1, 3)), + '2001-034', 'Format date yy-oo'); + equals($.datepicker.formatDate('D M y', new Date(2001, 2 - 1, 3)), + 'Sat Feb 01', 'Format date D M y'); + equals($.datepicker.formatDate('DD MM yy', new Date(2001, 2 - 1, 3)), + 'Saturday February 2001', 'Format date DD MM yy'); + equals($.datepicker.formatDate('DD, MM d, yy', new Date(2001, 2 - 1, 3)), + 'Saturday, February 3, 2001', 'Format date DD, MM d, yy'); + equals($.datepicker.formatDate('\'day\' d \'of\' MM (\'\'DD\'\'), yy', + new Date(2001, 2 - 1, 3)), 'day 3 of February (\'Saturday\'), 2001', + 'Format date \'day\' d \'of\' MM (\'\'DD\'\'), yy'); + var gmtDate = new Date(2001, 2 - 1, 3); + gmtDate.setMinutes(gmtDate.getMinutes() - gmtDate.getTimezoneOffset()); + equals($.datepicker.formatDate('@', gmtDate), '981158400000', 'Format date @'); + equals($.datepicker.formatDate('!', gmtDate), '631167552000000000', 'Format date !'); + var fr = $.datepicker.regional['fr']; + var settings = {dayNamesShort: fr.dayNamesShort, dayNames: fr.dayNames, + monthNamesShort: fr.monthNamesShort, monthNames: fr.monthNames}; + equals($.datepicker.formatDate('D M y', new Date(2001, 4 - 1, 9), settings), + 'Lun. Avril 01', 'Format date D M y with settings'); + equals($.datepicker.formatDate('DD MM yy', new Date(2001, 4 - 1, 9), settings), + 'Lundi Avril 2001', 'Format date DD MM yy with settings'); + equals($.datepicker.formatDate('DD, MM d, yy', new Date(2001, 4 - 1, 9), settings), + 'Lundi, Avril 9, 2001', 'Format date DD, MM d, yy with settings'); + equals($.datepicker.formatDate('\'jour\' d \'de\' MM (\'\'DD\'\'), yy', + new Date(2001, 4 - 1, 9), settings), 'jour 9 de Avril (\'Lundi\'), 2001', + 'Format date \'jour\' d \'de\' MM (\'\'DD\'\'), yy with settings'); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/datepicker/datepicker_tickets.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/datepicker/datepicker_tickets.js new file mode 100644 index 0000000..3534266 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/datepicker/datepicker_tickets.js @@ -0,0 +1,84 @@ +/* + * datepicker_tickets.js + */ +(function($) { + +module("datepicker: tickets"); + +// http://forum.jquery.com/topic/several-breaking-changes-in-jquery-ui-1-8rc1 +test('beforeShowDay-getDate', function() { + var inp = init('#inp', {beforeShowDay: function(date) { inp.datepicker('getDate'); return [true, '']; }}); + var dp = $('#ui-datepicker-div'); + inp.val('01/01/2010').datepicker('show'); + // contains non-breaking space + equals($('div.ui-datepicker-title').text(), 'January 2010', 'Initial month'); + $('a.ui-datepicker-next', dp).click(); + $('a.ui-datepicker-next', dp).click(); + // contains non-breaking space + equals($('div.ui-datepicker-title').text(), 'March 2010', 'After next clicks'); + inp.datepicker('hide').datepicker('show'); + $('a.ui-datepicker-prev', dp).click(); + $('a.ui-datepicker-prev', dp).click(); + // contains non-breaking space + equals($('div.ui-datepicker-title').text(), 'November 2009', 'After prev clicks'); + inp.datepicker('hide'); +}); + +test('Ticket 7602: Stop datepicker from appearing with beforeShow event handler', function(){ + var inp = init('#inp',{ + beforeShow: function(){ + return false; + } + }); + var dp = $('#ui-datepicker-div'); + inp.datepicker('show'); + equals(dp.css('display'), 'none',"beforeShow returns false"); + inp.datepicker('destroy'); + + inp = init('#inp',{ + beforeShow: function(){ + } + }); + dp = $('#ui-datepicker-div'); + inp.datepicker('show'); + equal(dp.css('display'), 'block',"beforeShow returns nothing"); + inp.datepicker('hide'); + inp.datepicker('destroy'); + + inp = init('#inp',{ + beforeShow: function(){ + return true; + } + }); + dp = $('#ui-datepicker-div'); + inp.datepicker('show'); + equal(dp.css('display'), 'block',"beforeShow returns true"); + inp.datepicker('hide'); + inp.datepicker('destroy'); +}); + +test('Ticket 6827: formatDate day of year calculation is wrong during day lights savings time', function(){ + var time = $.datepicker.formatDate("oo", new Date("2010/03/30 12:00:00 CDT")); + equals(time, "089"); +}); + +test('Ticket #7244: date parser does not fail when too many numbers are passed into the date function', function() { + var date; + try{ + date = $.datepicker.parseDate('dd/mm/yy', '18/04/19881'); + ok(false, "Did not properly detect an invalid date"); + }catch(e){ + ok("invalid date detected"); + } + + try { + date = $.datepicker.parseDate('dd/mm/yy', '18/04/1988 @ 2:43 pm'); + equal(date.getDate(), 18); + equal(date.getMonth(), 3); + equal(date.getFullYear(), 1988); + } catch(e) { + ok(false, "Did not properly parse date with extra text separated by whitespace"); + } +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/dialog/all.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/dialog/all.html new file mode 100644 index 0000000..e0416ec --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/dialog/all.html @@ -0,0 +1,30 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Dialog Test Suite</title> + + <script src="../../../jquery-1.7.1.js"></script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <link rel="stylesheet" href="../subsuiteRunner.css"> + <script src="../../../external/qunit.js"></script> + <script src="../subsuiteRunner.js"></script> + <script src="../subsuite.js"></script> + + <script> + testAllVersions( "dialog" ); + </script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Dialog Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/dialog/dialog.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/dialog/dialog.html new file mode 100644 index 0000000..94b20a2 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/dialog/dialog.html @@ -0,0 +1,60 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Dialog Test Suite</title> + + <script src="../../jquery.js"></script> + <script src="../../../external/jquery.bgiframe-2.1.2.js"></script> + <script src="../../resource_loader.js"></script> + <script> + loadResources({ + css: [ "ui.core", "ui.dialog" ], + js: [ + "ui/jquery.ui.core.js", + "ui/jquery.ui.widget.js", + "ui/jquery.ui.position.js", + "ui/jquery.ui.mouse.js", + "ui/jquery.ui.draggable.js", + "ui/jquery.ui.resizable.js", + "ui/jquery.ui.dialog.js" + ] + }); + </script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <script src="../../../external/qunit.js"></script> + <script src="../../jquery.simulate.js"></script> + <script src="../testsuite.js"></script> + + <script src="dialog_core.js"></script> + <script src="dialog_defaults.js"></script> + <script src="dialog_events.js"></script> + <script src="dialog_methods.js"></script> + <script src="dialog_options.js"></script> + <script src="dialog_tickets.js"></script> + + <script> + // disable this testsuite for testswarm only - until we fix it from freezing IE6 + var url = window.location.search; + url = decodeURIComponent( url.slice( url.indexOf("swarmURL=") + 9 ) ); + if ( url && url.indexOf("http") == 0 ) { + // reset config to kill previous tests; make sure testsuite.js is loaded afterwards to init the testswarm script + QUnit.init(); + test("dialog", function() { ok(true, "disabled dialog testsuite"); }); + } + </script> + <script src="../swarminject.js"></script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Dialog Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/dialog/dialog_core.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/dialog/dialog_core.js new file mode 100644 index 0000000..2003689 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/dialog/dialog_core.js @@ -0,0 +1,138 @@ +/* + * dialog_core.js + */ + +var el, + offsetBefore, offsetAfter, + heightBefore, heightAfter, + widthBefore, widthAfter, + dragged; + +function dlg() { + return el.dialog('widget'); +} + +function isOpen(why) { + ok(dlg().is(":visible"), why); +} + +function isNotOpen(why) { + ok(!dlg().is(":visible"), why); +} + +function drag(handle, dx, dy) { + var d = dlg(); + offsetBefore = d.offset(); + heightBefore = d.height(); + widthBefore = d.width(); + //this mouseover is to work around a limitation in resizable + //TODO: fix resizable so handle doesn't require mouseover in order to be used + $(handle, d).simulate("mouseover"); + $(handle, d).simulate("drag", { + dx: dx || 0, + dy: dy || 0 + }); + dragged = { dx: dx, dy: dy }; + offsetAfter = d.offset(); + heightAfter = d.height(); + widthAfter = d.width(); +} + +function moved(dx, dy, msg) { + msg = msg ? msg + "." : ""; + var actual = { left: Math.round(offsetAfter.left), top: Math.round(offsetAfter.top) }; + var expected = { left: Math.round(offsetBefore.left + dx), top: Math.round(offsetBefore.top + dy) }; + same(actual, expected, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ' + msg); +} + +function shouldmove(why) { + var handle = $(".ui-dialog-titlebar", dlg()); + drag(handle, 50, -50); + moved(50, -50, why); +} + +function shouldnotmove(why) { + var handle = $(".ui-dialog-titlebar", dlg()); + drag(handle, 50, -50); + moved(0, 0, why); +} + +function resized(dw, dh, msg) { + msg = msg ? msg + "." : ""; + var actual = { width: widthAfter, height: heightAfter }; + var expected = { width: widthBefore + dw, height: heightBefore + dh }; + same(actual, expected, 'resized[' + dragged.dx + ', ' + dragged.dy + '] ' + msg); +} + +function shouldresize(why) { + var handle = $(".ui-resizable-se", dlg()); + drag(handle, 50, 50); + resized(50, 50, why); +} + +function shouldnotresize(why) { + var handle = $(".ui-resizable-se", dlg()); + drag(handle, 50, 50); + resized(0, 0, why); +} + +function broder(el, side){ + return parseInt(el.css('border-' + side + '-width'), 10); +} + +function margin(el, side) { + return parseInt(el.css('margin-' + side), 10); +} + +(function($) { + +module("dialog: core"); + +test("title id", function() { + expect(3); + + var titleId; + + // reset the uuid so we know what values to expect + $.ui.dialog.uuid = 0; + + el = $('<div></div>').dialog(); + titleId = dlg().find('.ui-dialog-title').attr('id'); + equals(titleId, 'ui-dialog-title-1', 'auto-numbered title id'); + el.remove(); + + el = $('<div></div>').dialog(); + titleId = dlg().find('.ui-dialog-title').attr('id'); + equals(titleId, 'ui-dialog-title-2', 'auto-numbered title id'); + el.remove(); + + el = $('<div id="foo">').dialog(); + titleId = dlg().find('.ui-dialog-title').attr('id'); + equals(titleId, 'ui-dialog-title-foo', 'carried over title id'); + el.remove(); +}); + +test("ARIA", function() { + expect(4); + + el = $('<div></div>').dialog(); + + equals(dlg().attr('role'), 'dialog', 'dialog role'); + + var labelledBy = dlg().attr('aria-labelledby'); + ok(labelledBy.length > 0, 'has aria-labelledby attribute'); + equals(dlg().find('.ui-dialog-title').attr('id'), labelledBy, + 'proper aria-labelledby attribute'); + + equals(dlg().find('.ui-dialog-titlebar-close').attr('role'), 'button', + 'close link role'); + + el.remove(); +}); + +test("widget method", function() { + var dialog = $("<div>").appendTo("#main").dialog(); + same(dialog.parent()[0], dialog.dialog("widget")[0]); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/dialog/dialog_defaults.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/dialog/dialog_defaults.js new file mode 100644 index 0000000..9f2e4c6 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/dialog/dialog_defaults.js @@ -0,0 +1,34 @@ +commonWidgetTests( "dialog", { + defaults: { + autoOpen: true, + buttons: {}, + closeOnEscape: true, + closeText: 'close', + disabled: false, + dialogClass: '', + draggable: true, + height: 'auto', + hide: null, + maxHeight: false, + maxWidth: false, + minHeight: 150, + minWidth: 150, + modal: false, + position: { + my: 'center', + at: 'center', + of: window, + collision: 'fit', + using: $.ui.dialog.prototype.options.position.using + }, + resizable: true, + show: null, + stack: true, + title: '', + width: 300, + zIndex: 1000, + + // callbacks + create: null + } +}); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/dialog/dialog_events.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/dialog/dialog_events.js new file mode 100644 index 0000000..40a8575 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/dialog/dialog_events.js @@ -0,0 +1,254 @@ +/* + * dialog_events.js + */ +(function($) { + +module("dialog: events"); + +test("open", function() { + expect(13); + + el = $("<div></div>"); + el.dialog({ + open: function(ev, ui) { + ok(el.data("dialog")._isOpen, "interal _isOpen flag is set"); + ok(true, 'autoOpen: true fires open callback'); + equals(this, el[0], "context of callback"); + equals(ev.type, 'dialogopen', 'event type in callback'); + same(ui, {}, 'ui hash in callback'); + } + }); + el.remove(); + + el = $("<div></div>"); + el.dialog({ + autoOpen: false, + open: function(ev, ui) { + ok(true, '.dialog("open") fires open callback'); + equals(this, el[0], "context of callback"); + equals(ev.type, 'dialogopen', 'event type in callback'); + same(ui, {}, 'ui hash in callback'); + } + }).bind('dialogopen', function(ev, ui) { + ok(el.data("dialog")._isOpen, "interal _isOpen flag is set"); + ok(true, 'dialog("open") fires open event'); + equals(this, el[0], 'context of event'); + same(ui, {}, 'ui hash in event'); + }); + el.dialog("open"); + el.remove(); +}); + +test("dragStart", function() { + expect(9); + + el = $('<div></div>').dialog({ + dragStart: function(ev, ui) { + ok(true, 'dragging fires dragStart callback'); + equals(this, el[0], "context of callback"); + equals(ev.type, 'dialogdragstart', 'event type in callback'); + ok(ui.position !== undefined, "ui.position in callback"); + ok(ui.offset !== undefined, "ui.offset in callback"); + } + }).bind('dialogdragstart', function(ev, ui) { + ok(true, 'dragging fires dialogdragstart event'); + equals(this, el[0], 'context of event'); + ok(ui.position !== undefined, "ui.position in callback"); + ok(ui.offset !== undefined, "ui.offset in callback"); + }); + var handle = $(".ui-dialog-titlebar", dlg()); + drag(handle, 50, 50); + el.remove(); +}); + +test("drag", function() { + expect(9); + var hasDragged = false; + + el = $('<div></div>').dialog({ + drag: function(ev, ui) { + if (!hasDragged) { + ok(true, 'dragging fires drag callback'); + equals(this, el[0], "context of callback"); + equals(ev.type, 'dialogdrag', 'event type in callback'); + ok(ui.position !== undefined, "ui.position in callback"); + ok(ui.offset !== undefined, "ui.offset in callback"); + + hasDragged = true; + } + } + }).one('dialogdrag', function(ev, ui) { + ok(true, 'dragging fires dialogdrag event'); + equals(this, el[0], 'context of event'); + ok(ui.position !== undefined, "ui.position in callback"); + ok(ui.offset !== undefined, "ui.offset in callback"); + }); + var handle = $(".ui-dialog-titlebar", dlg()); + drag(handle, 50, 50); + el.remove(); +}); + +test("dragStop", function() { + expect(9); + + el = $('<div></div>').dialog({ + dragStop: function(ev, ui) { + ok(true, 'dragging fires dragStop callback'); + equals(this, el[0], "context of callback"); + equals(ev.type, 'dialogdragstop', 'event type in callback'); + ok(ui.position !== undefined, "ui.position in callback"); + ok(ui.offset !== undefined, "ui.offset in callback"); + } + }).bind('dialogdragstop', function(ev, ui) { + ok(true, 'dragging fires dialogdragstop event'); + equals(this, el[0], 'context of event'); + ok(ui.position !== undefined, "ui.position in callback"); + ok(ui.offset !== undefined, "ui.offset in callback"); + }); + var handle = $(".ui-dialog-titlebar", dlg()); + drag(handle, 50, 50); + el.remove(); +}); + +test("resizeStart", function() { + expect(13); + + el = $('<div></div>').dialog({ + resizeStart: function(ev, ui) { + ok(true, 'resizing fires resizeStart callback'); + equals(this, el[0], "context of callback"); + equals(ev.type, 'dialogresizestart', 'event type in callback'); + ok(ui.originalPosition !== undefined, "ui.originalPosition in callback"); + ok(ui.originalSize !== undefined, "ui.originalSize in callback"); + ok(ui.position !== undefined, "ui.position in callback"); + ok(ui.size !== undefined, "ui.size in callback"); + } + }).bind('dialogresizestart', function(ev, ui) { + ok(true, 'resizing fires dialogresizestart event'); + equals(this, el[0], 'context of event'); + ok(ui.originalPosition !== undefined, "ui.originalPosition in callback"); + ok(ui.originalSize !== undefined, "ui.originalSize in callback"); + ok(ui.position !== undefined, "ui.position in callback"); + ok(ui.size !== undefined, "ui.size in callback"); + }); + var handle = $(".ui-resizable-se", dlg()); + drag(handle, 50, 50); + el.remove(); +}); + +test("resize", function() { + expect(13); + var hasResized = false; + + el = $('<div></div>').dialog({ + resize: function(ev, ui) { + if (!hasResized) { + ok(true, 'resizing fires resize callback'); + equals(this, el[0], "context of callback"); + equals(ev.type, 'dialogresize', 'event type in callback'); + ok(ui.originalPosition !== undefined, "ui.originalPosition in callback"); + ok(ui.originalSize !== undefined, "ui.originalSize in callback"); + ok(ui.position !== undefined, "ui.position in callback"); + ok(ui.size !== undefined, "ui.size in callback"); + + hasResized = true; + } + } + }).one('dialogresize', function(ev, ui) { + ok(true, 'resizing fires dialogresize event'); + equals(this, el[0], 'context of event'); + ok(ui.originalPosition !== undefined, "ui.originalPosition in callback"); + ok(ui.originalSize !== undefined, "ui.originalSize in callback"); + ok(ui.position !== undefined, "ui.position in callback"); + ok(ui.size !== undefined, "ui.size in callback"); + }); + var handle = $(".ui-resizable-se", dlg()); + drag(handle, 50, 50); + el.remove(); +}); + +test("resizeStop", function() { + expect(13); + + el = $('<div></div>').dialog({ + resizeStop: function(ev, ui) { + ok(true, 'resizing fires resizeStop callback'); + equals(this, el[0], "context of callback"); + equals(ev.type, 'dialogresizestop', 'event type in callback'); + ok(ui.originalPosition !== undefined, "ui.originalPosition in callback"); + ok(ui.originalSize !== undefined, "ui.originalSize in callback"); + ok(ui.position !== undefined, "ui.position in callback"); + ok(ui.size !== undefined, "ui.size in callback"); + } + }).bind('dialogresizestop', function(ev, ui) { + ok(true, 'resizing fires dialogresizestop event'); + equals(this, el[0], 'context of event'); + ok(ui.originalPosition !== undefined, "ui.originalPosition in callback"); + ok(ui.originalSize !== undefined, "ui.originalSize in callback"); + ok(ui.position !== undefined, "ui.position in callback"); + ok(ui.size !== undefined, "ui.size in callback"); + }); + var handle = $(".ui-resizable-se", dlg()); + drag(handle, 50, 50); + el.remove(); +}); + +test("close", function() { + expect(7); + + el = $('<div></div>').dialog({ + close: function(ev, ui) { + ok(true, '.dialog("close") fires close callback'); + equals(this, el[0], "context of callback"); + equals(ev.type, 'dialogclose', 'event type in callback'); + same(ui, {}, 'ui hash in callback'); + } + }).bind('dialogclose', function(ev, ui) { + ok(true, '.dialog("close") fires dialogclose event'); + equals(this, el[0], 'context of event'); + same(ui, {}, 'ui hash in event'); + }); + el.dialog('close'); + el.remove(); +}); + +test("beforeClose", function() { + expect(14); + + el = $('<div></div>').dialog({ + beforeClose: function(ev, ui) { + ok(true, '.dialog("close") fires beforeClose callback'); + equals(this, el[0], "context of callback"); + equals(ev.type, 'dialogbeforeclose', 'event type in callback'); + same(ui, {}, 'ui hash in callback'); + return false; + } + }); + el.dialog('close'); + isOpen('beforeClose callback should prevent dialog from closing'); + el.remove(); + + el = $('<div></div>').dialog(); + el.dialog('option', 'beforeClose', function(ev, ui) { + ok(true, '.dialog("close") fires beforeClose callback'); + equals(this, el[0], "context of callback"); + equals(ev.type, 'dialogbeforeclose', 'event type in callback'); + same(ui, {}, 'ui hash in callback'); + return false; + }); + el.dialog('close'); + isOpen('beforeClose callback should prevent dialog from closing'); + el.remove(); + + el = $('<div></div>').dialog().bind('dialogbeforeclose', function(ev, ui) { + ok(true, '.dialog("close") triggers dialogbeforeclose event'); + equals(this, el[0], "context of event"); + same(ui, {}, 'ui hash in event'); + return false; + }); + el.dialog('close'); + isOpen('dialogbeforeclose event should prevent dialog from closing'); + el.remove(); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/dialog/dialog_methods.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/dialog/dialog_methods.js new file mode 100644 index 0000000..a961b4e --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/dialog/dialog_methods.js @@ -0,0 +1,127 @@ +/* + * dialog_methods.js + */ +(function($) { + +module("dialog: methods", { + teardown: function() { + $("body>.ui-dialog").remove(); + } +}); + +test("init", function() { + expect(6); + + $("<div></div>").appendTo('body').dialog().remove(); + ok(true, '.dialog() called on element'); + + $([]).dialog().remove(); + ok(true, '.dialog() called on empty collection'); + + $('<div></div>').dialog().remove(); + ok(true, '.dialog() called on disconnected DOMElement - never connected'); + + $('<div></div>').appendTo('body').remove().dialog().remove(); + ok(true, '.dialog() called on disconnected DOMElement - removed'); + + el = $('<div></div>').dialog(); + var foo = el.dialog("option", "foo"); + el.remove(); + ok(true, 'arbitrary option getter after init'); + + $('<div></div>').dialog().dialog("option", "foo", "bar").remove(); + ok(true, 'arbitrary option setter after init'); +}); + +test("destroy", function() { + $("<div></div>").appendTo('body').dialog().dialog("destroy").remove(); + ok(true, '.dialog("destroy") called on element'); + + $([]).dialog().dialog("destroy").remove(); + ok(true, '.dialog("destroy") called on empty collection'); + + $('<div></div>').dialog().dialog("destroy").remove(); + ok(true, '.dialog("destroy") called on disconnected DOMElement'); + + var expected = $('<div></div>').dialog(), + actual = expected.dialog('destroy'); + equals(actual, expected, 'destroy is chainable'); +}); + +test("enable", function() { + var expected = $('<div></div>').dialog(), + actual = expected.dialog('enable'); + equals(actual, expected, 'enable is chainable'); + + el = $('<div></div>').dialog({ disabled: true }); + el.dialog('enable'); + equals(el.dialog('option', 'disabled'), false, 'enable method sets disabled option to false'); + ok(!dlg().hasClass('ui-dialog-disabled'), 'enable method removes ui-dialog-disabled class from ui-dialog element'); +}); + +test("disable", function() { + var expected = $('<div></div>').dialog(), + actual = expected.dialog('disable'); + equals(actual, expected, 'disable is chainable'); + + el = $('<div></div>').dialog({ disabled: false }); + el.dialog('disable'); + equals(el.dialog('option', 'disabled'), true, 'disable method sets disabled option to true'); + ok(dlg().hasClass('ui-dialog-disabled'), 'disable method adds ui-dialog-disabled class to ui-dialog element'); +}); + +test("close", function() { + var expected = $('<div></div>').dialog(), + actual = expected.dialog('close'); + equals(actual, expected, 'close is chainable'); + + el = $('<div></div>').dialog(); + ok(dlg().is(':visible') && !dlg().is(':hidden'), 'dialog visible before close method called'); + el.dialog('close'); + ok(dlg().is(':hidden') && !dlg().is(':visible'), 'dialog hidden after close method called'); +}); + +test("isOpen", function() { + expect(4); + + el = $('<div></div>').dialog(); + equals(el.dialog('isOpen'), true, "dialog is open after init"); + el.dialog('close'); + equals(el.dialog('isOpen'), false, "dialog is closed"); + el.remove(); + + el = $('<div></div>').dialog({autoOpen: false}); + equals(el.dialog('isOpen'), false, "dialog is closed after init"); + el.dialog('open'); + equals(el.dialog('isOpen'), true, "dialog is open"); + el.remove(); +}); + +test("moveToTop", function() { + var expected = $('<div></div>').dialog(), + actual = expected.dialog('moveToTop'); + equals(actual, expected, 'moveToTop is chainable'); + + var d1 = $('<div></div>').dialog(), dlg1 = d1.parents('.ui-dialog'); + d1.dialog('close'); + d1.dialog('open'); + var d2 = $('<div></div>').dialog(), dlg2 = d2.parents('.ui-dialog'); + d2.dialog('close'); + d2.dialog('open'); + ok(dlg1.css('zIndex') < dlg2.css('zIndex'), 'dialog 1 under dialog 2 before moveToTop method called'); + d1.dialog('moveToTop'); + ok(dlg1.css('zIndex') > dlg2.css('zIndex'), 'dialog 1 above dialog 2 after moveToTop method called'); +}); + +test("open", function() { + var expected = $('<div></div>').dialog(), + actual = expected.dialog('open'); + equals(actual, expected, 'open is chainable'); + + el = $('<div></div>').dialog({ autoOpen: false }); + ok(dlg().is(':hidden') && !dlg().is(':visible'), 'dialog hidden before open method called'); + el.dialog('open'); + ok(dlg().is(':visible') && !dlg().is(':hidden'), 'dialog visible after open method called'); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/dialog/dialog_options.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/dialog/dialog_options.js new file mode 100644 index 0000000..eab577c --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/dialog/dialog_options.js @@ -0,0 +1,444 @@ +/* + * dialog_options.js + */ +(function($) { + +module("dialog: options"); + +test("autoOpen", function() { + expect(2); + + el = $('<div></div>').dialog({ autoOpen: false }); + isNotOpen('.dialog({ autoOpen: false })'); + el.remove(); + + el = $('<div></div>').dialog({ autoOpen: true }); + isOpen('.dialog({ autoOpen: true })'); + el.remove(); +}); + +test("buttons", function() { + expect(21); + + var buttons = { + "Ok": function(ev, ui) { + ok(true, "button click fires callback"); + equals(this, el[0], "context of callback"); + equals(ev.target, btn[0], "event target"); + }, + "Cancel": function(ev, ui) { + ok(true, "button click fires callback"); + equals(this, el[0], "context of callback"); + equals(ev.target, btn[1], "event target"); + } + }; + + el = $('<div></div>').dialog({ buttons: buttons }); + var btn = $("button", dlg()); + equals(btn.length, 2, "number of buttons"); + + var i = 0; + $.each(buttons, function(key, val) { + equals(btn.eq(i).text(), key, "text of button " + (i+1)); + i++; + }); + + ok(btn.parent().hasClass('ui-dialog-buttonset'), "buttons in container"); + ok(el.parent().hasClass('ui-dialog-buttons'), "dialog wrapper adds class about having buttons"); + + btn.trigger("click"); + + var newButtons = { + "Close": function(ev, ui) { + ok(true, "button click fires callback"); + equals(this, el[0], "context of callback"); + equals(ev.target, btn[0], "event target"); + } + }; + + same(el.dialog("option", "buttons"), buttons, '.dialog("option", "buttons") getter'); + el.dialog("option", "buttons", newButtons); + same(el.dialog("option", "buttons"), newButtons, '.dialog("option", "buttons", ...) setter'); + + btn = $("button", dlg()); + equals(btn.length, 1, "number of buttons after setter"); + btn.trigger('click'); + + i = 0; + $.each(newButtons, function(key, val) { + equals(btn.eq(i).text(), key, "text of button " + (i+1)); + i += 1; + }); + + el.dialog("option", "buttons", null); + btn = $("button", dlg()); + equals(btn.length, 0, "all buttons have been removed"); + equals(el.find(".ui-dialog-buttonset").length, 0, "buttonset has been removed"); + equals(el.parent().hasClass('ui-dialog-buttons'), false, "dialog wrapper removes class about having buttons"); + + el.remove(); +}); + +test("buttons - advanced", function() { + expect(5); + + el = $("<div></div>").dialog({ + buttons: [ + { + text: "a button", + "class": "additional-class", + id: "my-button-id", + click: function() { + equals(this, el[0], "correct context"); + } + } + ] + }); + var buttons = dlg().find("button"); + equals(buttons.length, 1, "correct number of buttons"); + equals(buttons.attr("id"), "my-button-id", "correct id"); + equals(buttons.text(), "a button", "correct label"); + ok(buttons.hasClass("additional-class"), "additional classes added"); + buttons.click(); + + el.remove(); +}); + +test("closeOnEscape", function() { + el = $('<div></div>').dialog({ closeOnEscape: false }); + ok(true, 'closeOnEscape: false'); + ok(dlg().is(':visible') && !dlg().is(':hidden'), 'dialog is open before ESC'); + el.simulate('keydown', { keyCode: $.ui.keyCode.ESCAPE }) + .simulate('keypress', { keyCode: $.ui.keyCode.ESCAPE }) + .simulate('keyup', { keyCode: $.ui.keyCode.ESCAPE }); + ok(dlg().is(':visible') && !dlg().is(':hidden'), 'dialog is open after ESC'); + + el.remove(); + + el = $('<div></div>').dialog({ closeOnEscape: true }); + ok(true, 'closeOnEscape: true'); + ok(dlg().is(':visible') && !dlg().is(':hidden'), 'dialog is open before ESC'); + el.simulate('keydown', { keyCode: $.ui.keyCode.ESCAPE }) + .simulate('keypress', { keyCode: $.ui.keyCode.ESCAPE }) + .simulate('keyup', { keyCode: $.ui.keyCode.ESCAPE }); + ok(dlg().is(':hidden') && !dlg().is(':visible'), 'dialog is closed after ESC'); +}); + +test("closeText", function() { + expect(3); + + el = $('<div></div>').dialog(); + equals(dlg().find('.ui-dialog-titlebar-close span').text(), 'close', + 'default close text'); + el.remove(); + + el = $('<div></div>').dialog({ closeText: "foo" }); + equals(dlg().find('.ui-dialog-titlebar-close span').text(), 'foo', + 'closeText on init'); + el.remove(); + + el = $('<div></div>').dialog().dialog('option', 'closeText', 'bar'); + equals(dlg().find('.ui-dialog-titlebar-close span').text(), 'bar', + 'closeText via option method'); + el.remove(); +}); + +test("dialogClass", function() { + expect(4); + + el = $('<div></div>').dialog(); + equals(dlg().is(".foo"), false, 'dialogClass not specified. foo class added'); + el.remove(); + + el = $('<div></div>').dialog({ dialogClass: "foo" }); + equals(dlg().is(".foo"), true, 'dialogClass in init. foo class added'); + el.remove(); + + el = $('<div></div>').dialog({ dialogClass: "foo bar" }); + equals(dlg().is(".foo"), true, 'dialogClass in init, two classes. foo class added'); + equals(dlg().is(".bar"), true, 'dialogClass in init, two classes. bar class added'); + el.remove(); +}); + +test("draggable", function() { + expect(4); + + el = $('<div></div>').dialog({ draggable: false }); + shouldnotmove(); + el.dialog('option', 'draggable', true); + shouldmove(); + el.remove(); + + el = $('<div></div>').dialog({ draggable: true }); + shouldmove(); + el.dialog('option', 'draggable', false); + shouldnotmove(); + el.remove(); +}); + +test("height", function() { + expect(3); + + el = $('<div></div>').dialog(); + equals(dlg().height(), 150, "default height"); + el.remove(); + + el = $('<div></div>').dialog({ height: 237 }); + equals(dlg().height(), 237, "explicit height"); + el.remove(); + + el = $('<div></div>').dialog(); + el.dialog('option', 'height', 238); + equals(dlg().height(), 238, "explicit height set after init"); + el.remove(); +}); + +test("maxHeight", function() { + expect(3); + + el = $('<div></div>').dialog({ maxHeight: 200 }); + drag('.ui-resizable-s', 1000, 1000); + equals(heightAfter, 200, "maxHeight"); + el.remove(); + + el = $('<div></div>').dialog({ maxHeight: 200 }); + drag('.ui-resizable-n', -1000, -1000); + equals(heightAfter, 200, "maxHeight"); + el.remove(); + + el = $('<div></div>').dialog({ maxHeight: 200 }).dialog('option', 'maxHeight', 300); + drag('.ui-resizable-s', 1000, 1000); + equals(heightAfter, 300, "maxHeight"); + el.remove(); +}); + +test("maxWidth", function() { + expect(3); + + el = $('<div></div>').dialog({ maxWidth: 200 }); + drag('.ui-resizable-e', 1000, 1000); + equals(widthAfter, 200, "maxWidth"); + el.remove(); + + el = $('<div></div>').dialog({ maxWidth: 200 }); + drag('.ui-resizable-w', -1000, -1000); + equals(widthAfter, 200, "maxWidth"); + el.remove(); + + el = $('<div></div>').dialog({ maxWidth: 200 }).dialog('option', 'maxWidth', 300); + drag('.ui-resizable-w', -1000, -1000); + equals(widthAfter, 300, "maxWidth"); + el.remove(); +}); + +test("minHeight", function() { + expect(3); + + el = $('<div></div>').dialog({ minHeight: 10 }); + drag('.ui-resizable-s', -1000, -1000); + equals(heightAfter, 10, "minHeight"); + el.remove(); + + el = $('<div></div>').dialog({ minHeight: 10 }); + drag('.ui-resizable-n', 1000, 1000); + equals(heightAfter, 10, "minHeight"); + el.remove(); + + el = $('<div></div>').dialog({ minHeight: 10 }).dialog('option', 'minHeight', 30); + drag('.ui-resizable-n', 1000, 1000); + equals(heightAfter, 30, "minHeight"); + el.remove(); +}); + +test("minWidth", function() { + expect(3); + + el = $('<div></div>').dialog({ minWidth: 10 }); + drag('.ui-resizable-e', -1000, -1000); + equals(widthAfter, 10, "minWidth"); + el.remove(); + + el = $('<div></div>').dialog({ minWidth: 10 }); + drag('.ui-resizable-w', 1000, 1000); + equals(widthAfter, 10, "minWidth"); + el.remove(); + + el = $('<div></div>').dialog({ minWidth: 30 }).dialog('option', 'minWidth', 30); + drag('.ui-resizable-w', 1000, 1000); + equals(widthAfter, 30, "minWidth"); + el.remove(); +}); + +test("position, default center on window", function() { + var el = $('<div></div>').dialog(); + var dialog = el.dialog('widget'); + var offset = dialog.offset(); + same(offset.left, Math.round($(window).width() / 2 - dialog.outerWidth() / 2) + $(window).scrollLeft()); + same(offset.top, Math.round($(window).height() / 2 - dialog.outerHeight() / 2) + $(window).scrollTop()); + el.remove(); +}); + +test("position, top on window", function() { + var el = $('<div></div>').dialog({ position: "top" }); + var dialog = el.dialog('widget'); + var offset = dialog.offset(); + same(offset.left, Math.round($(window).width() / 2 - dialog.outerWidth() / 2) + $(window).scrollLeft()); + same(offset.top, $(window).scrollTop()); + el.remove(); +}); + +test("position, left on window", function() { + var el = $('<div></div>').dialog({ position: "left" }); + var dialog = el.dialog('widget'); + var offset = dialog.offset(); + same(offset.left, 0); + same(offset.top, Math.round($(window).height() / 2 - dialog.outerHeight() / 2) + $(window).scrollTop()); + el.remove(); +}); + +test("position, right bottom on window", function() { + var el = $('<div></div>').dialog({ position: "right bottom" }); + var dialog = el.dialog('widget'); + var offset = dialog.offset(); + same(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft()); + same(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop()); + el.remove(); +}); + +test("position, right bottom on window w/array", function() { + var el = $('<div></div>').dialog({ position: ["right", "bottom"] }); + var dialog = el.dialog('widget'); + var offset = dialog.offset(); + same(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft()); + same(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop()); + el.remove(); +}); + +test("position, offset from top left w/array", function() { + var el = $('<div></div>').dialog({ position: [10, 10] }); + var dialog = el.dialog('widget'); + var offset = dialog.offset(); + same(offset.left, 10 + $(window).scrollLeft()); + same(offset.top, 10 + $(window).scrollTop()); + el.remove(); +}); + +test("position, right bottom at right bottom via ui.position args", function() { + var el = $('<div></div>').dialog({ + position: { + my: "right bottom", + at: "right bottom" + } + }); + + var dialog = el.dialog('widget'); + var offset = dialog.offset(); + + same(offset.left, $(window).width() - dialog.outerWidth() + $(window).scrollLeft()); + same(offset.top, $(window).height() - dialog.outerHeight() + $(window).scrollTop()); + el.remove(); +}); + +test("position, at another element", function() { + var parent = $('<div></div>').css({ + position: 'absolute', + top: 400, + left: 600, + height: 10, + width: 10 + }).appendTo('body'); + + var el = $('<div></div>').dialog({ + position: { + my: "left top", + at: "left top", + of: parent + } + }); + + var dialog = el.dialog('widget'); + var offset = dialog.offset(); + + same(offset.left, 600); + same(offset.top, 400); + + el.dialog('option', 'position', { + my: "left top", + at: "right bottom", + of: parent + }); + + var offset = dialog.offset(); + + same(offset.left, 610); + same(offset.top, 410); + + el.remove(); + parent.remove(); +}); + +test("resizable", function() { + expect(4); + + el = $('<div></div>').dialog(); + shouldresize("[default]"); + el.dialog('option', 'resizable', false); + shouldnotresize('disabled after init'); + el.remove(); + + el = $('<div></div>').dialog({ resizable: false }); + shouldnotresize("disabled in init options"); + el.dialog('option', 'resizable', true); + shouldresize('enabled after init'); + el.remove(); +}); + +test("title", function() { + expect(9); + + function titleText() { + return dlg().find(".ui-dialog-title").html(); + } + + el = $('<div></div>').dialog(); + // some browsers return a non-breaking space and some return " " + // so we get the text to normalize to the actual non-breaking space + equals(dlg().find(".ui-dialog-title").text(), " ", "[default]"); + equals(el.dialog("option", "title"), "", "option not changed"); + el.remove(); + + el = $('<div title="foo">').dialog(); + equals(titleText(), "foo", "title in element attribute"); + equals(el.dialog("option", "title"), "foo", "option updated from attribute"); + el.remove(); + + el = $('<div></div>').dialog({ title: 'foo' }); + equals(titleText(), "foo", "title in init options"); + equals(el.dialog("option", "title"), "foo", "opiton set from options hash"); + el.remove(); + + el = $('<div title="foo">').dialog({ title: 'bar' }); + equals(titleText(), "bar", "title in init options should override title in element attribute"); + equals(el.dialog("option", "title"), "bar", "opiton set from options hash"); + el.remove(); + + el = $('<div></div>').dialog().dialog('option', 'title', 'foo'); + equals(titleText(), 'foo', 'title after init'); + el.remove(); +}); + +test("width", function() { + expect(3); + + el = $('<div></div>').dialog(); + equals(dlg().width(), 300, "default width"); + el.remove(); + + el = $('<div></div>').dialog({width: 437 }); + equals(dlg().width(), 437, "explicit width"); + el.dialog('option', 'width', 438); + equals(dlg().width(), 438, 'explicit width after init'); + el.remove(); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/dialog/dialog_tickets.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/dialog/dialog_tickets.js new file mode 100644 index 0000000..b203ca7 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/dialog/dialog_tickets.js @@ -0,0 +1,143 @@ +/* + * dialog_tickets.js + */ +(function($) { + +module( "dialog: tickets" ); + +asyncTest( "#3123: Prevent tabbing out of modal dialogs", function() { + expect( 3 ); + + var el = $( "<div><input id='t3123-first'><input id='t3123-last'></div>" ).dialog({ modal: true }), + inputs = el.find( "input" ), + widget = el.dialog( "widget" ); + + inputs.eq( 1 ).focus(); + equal( document.activeElement, inputs[1], "Focus set on second input" ); + inputs.eq( 1 ).simulate( "keydown", { keyCode: $.ui.keyCode.TAB }); + + setTimeout( checkTab, 2 ); + + function checkTab() { + ok( $.contains( widget, document.activeElement ), "Tab key event moved focus within the modal" ); + + // check shift tab + $( document.activeElement ).simulate( "keydown", { keyCode: $.ui.keyCode.TAB, shiftKey: true }); + setTimeout( checkShiftTab, 2 ); + } + + function checkShiftTab() { + ok( $.contains( widget, document.activeElement ), "Shift-Tab key event moved focus within the modal" ); + + el.remove(); + start(); + } +}); + +test("#4826: setting resizable false toggles resizable on dialog", function() { + expect(6); + + el = $('<div></div>').dialog({ resizable: false }); + shouldnotresize("[default]"); + for (var i=0; i<2; i++) { + el.dialog('close').dialog('open'); + shouldnotresize('initialized with resizable false toggle ('+ (i+1) +')'); + } + el.remove(); + + el = $('<div></div>').dialog({ resizable: true }); + shouldresize("[default]"); + for (var i=0; i<2; i++) { + el.dialog('close').dialog('option', 'resizable', false).dialog('open'); + shouldnotresize('set option resizable false toggle ('+ (i+1) +')'); + } + el.remove(); + +}); + +test("#5184: isOpen in dialogclose event is true", function() { + expect( 3 ); + + el = $( "<div></div>" ).dialog({ + close: function() { + ok( !el.dialog("isOpen"), "dialog is not open during close" ); + } + }); + ok( el.dialog("isOpen"), "dialog is open after init" ); + el.dialog( "close" ); + ok( !el.dialog("isOpen"), "dialog is not open after close" ); + el.remove(); +}); + +test("#5531: dialog width should be at least minWidth on creation", function () { + el = $('<div></div>').dialog({ + width: 200, + minWidth: 300 + }); + + equals(el.dialog('option', 'width'), 300, "width is minWidth"); + el.dialog('option', 'width', 200); + equals(el.dialog('option', 'width'), 300, "width unchanged when set to < minWidth"); + el.dialog('option', 'width', 320); + equals(el.dialog('option', 'width'), 320, "width changed if set to > minWidth"); + el.remove(); + + el = $('<div></div>').dialog({ + minWidth: 300 + }); + ok(el.dialog('option', 'width') >= 300, "width is at least 300"); + el.remove(); + +}); + +test("#6137: dialog('open') causes form elements to reset on IE7", function() { + expect(2); + + d1 = $('<form><input type="radio" name="radio" id="a" value="a" checked="checked"></input>' + + '<input type="radio" name="radio" id="b" value="b">b</input></form>').appendTo( "body" ).dialog({autoOpen: false}); + + d1.find('#b').prop( "checked", true ); + equal($('input:checked').val(), 'b', "checkbox b is checked"); + + d1.dialog('open'); + equal($('input:checked').val(), 'b', "checkbox b is checked"); + + d1.remove(); +}); + +test("#6645: Missing element not found check in overlay", function(){ + expect(2); + d1 = $('<div title="dialog 1">Dialog 1</div>').dialog({modal: true}); + d2 = $('<div title="dialog 2">Dialog 2</div>').dialog({modal: true, close: function(){ d2.remove()}}); + equals($.ui.dialog.overlay.instances.length, 2, 'two overlays created'); + d2.dialog('close'); + equals($.ui.dialog.overlay.instances.length, 1, 'one overlay remains after closing the 2nd overlay'); + d1.add(d2).remove(); +}); + +test("#6966: Escape key closes all dialogs, not the top one", function(){ + expect(8); + // test with close function removing dialog + d1 = $('<div title="dialog 1">Dialog 1</div>').dialog({modal: true}); + d2 = $('<div title="dialog 2">Dialog 2</div>').dialog({modal: true, close: function(){ d2.remove()}}); + ok(d1.dialog("isOpen"), 'first dialog is open'); + ok(d2.dialog("isOpen"), 'second dialog is open'); + d2.simulate("keydown", {keyCode: $.ui.keyCode.ESCAPE}); + ok(d1.dialog("isOpen"), 'first dialog still open'); + ok(!d2.data('dialog'), 'second dialog is closed'); + d2.remove(); + d1.remove(); + + // test without close function removing dialog + d1 = $('<div title="dialog 1">Dialog 1</div>').dialog({modal: true}); + d2 = $('<div title="dialog 2">Dialog 2</div>').dialog({modal: true}); + ok(d1.dialog("isOpen"), 'first dialog is open'); + ok(d2.dialog("isOpen"), 'second dialog is open'); + d2.simulate("keydown", {keyCode: $.ui.keyCode.ESCAPE}); + ok(d1.dialog("isOpen"), 'first dialog still open'); + ok(!d2.dialog("isOpen"), 'second dialog is closed'); + d2.remove(); + d1.remove(); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/all.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/all.html new file mode 100644 index 0000000..3796d3f --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/all.html @@ -0,0 +1,30 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Draggable Test Suite</title> + + <script src="../../../jquery-1.7.1.js"></script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <link rel="stylesheet" href="../subsuiteRunner.css"> + <script src="../../../external/qunit.js"></script> + <script src="../subsuiteRunner.js"></script> + <script src="../subsuite.js"></script> + + <script> + testAllVersions( "draggable" ); + </script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Draggable Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable.html new file mode 100644 index 0000000..5be71f4 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable.html @@ -0,0 +1,60 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Draggable Test Suite</title> + + <script src="../../jquery.js"></script> + <script src="../../resource_loader.js"></script> + <script> + loadResources({ + css: [ "ui.core" ], + js: [ + "ui/jquery.ui.core.js", + "ui/jquery.ui.widget.js", + "ui/jquery.ui.mouse.js", + "ui/jquery.ui.draggable.js" + ] + }); + </script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <script src="../../../external/qunit.js"></script> + <script src="../../jquery.simulate.js"></script> + <script src="../testsuite.js"></script> + + <script src="draggable_core.js"></script> + <script src="draggable_defaults.js"></script> + <script src="draggable_events.js"></script> + <script src="draggable_methods.js"></script> + <script src="draggable_options.js"></script> + + <script> + // disable this stale testsuite for testswarm only + var url = window.location.search; + url = decodeURIComponent( url.slice( url.indexOf("swarmURL=") + 9 ) ); + if ( url && url.indexOf("http") == 0 ) { + // reset config to kill previous tests; make sure testsuite.js is loaded afterwards to init the testswarm script + QUnit.init(); + test("draggable", function() { ok(true, "disabled draggable testsuite"); }); + } + </script> + <script src="../swarminject.js"></script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Draggable Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +<div id="draggable1" style="background: green; width: 200px; height: 100px;">Relative</div> +<div id="draggable2" style="background: green; width: 200px; height: 100px; position: absolute; top: 10px; left: 10px;"><span>Absolute</span></div> +<div style='width: 1px; height: 1000px;'></div> +<div style="position: absolute; width: 1px; height: 2000px;"></div> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_core.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_core.js new file mode 100644 index 0000000..a01de40 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_core.js @@ -0,0 +1,67 @@ +/* + * draggable_core.js + */ + +var el, offsetBefore, offsetAfter, dragged; + +var drag = function(handle, dx, dy) { + var element = el.data("draggable").element; + offsetBefore = el.offset(); + $(handle).simulate("drag", { + dx: dx || 0, + dy: dy || 0 + }); + dragged = { dx: dx, dy: dy }; + offsetAfter = el.offset(); +} + +var moved = function (dx, dy, msg) { + msg = msg ? msg + "." : ""; + var actual = { left: offsetAfter.left, top: offsetAfter.top }; + var expected = { left: offsetBefore.left + dx, top: offsetBefore.top + dy }; + same(actual, expected, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] ' + msg); +} + +function restoreScroll(what) { + if(what) { + $(document).scrollTop(0); $(document).scrollLeft(0); + } else { + $("#main")[0].scrollTop = 0; $("#main")[0].scrollLeft = 0; + } +} + +(function($) { + +module("draggable"); + +test("element types", function() { + var typeNames = ('p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form' + + ',table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr' + + ',acronym,code,samp,kbd,var,img,object,hr' + + ',input,button,label,select,iframe').split(','); + + $.each(typeNames, function(i) { + var typeName = typeNames[i]; + el = $(document.createElement(typeName)).appendTo('body'); + (typeName == 'table' && el.append("<tr><td>content</td></tr>")); + el.draggable({ cancel: '' }); + drag(el, 50, 50); + moved(50, 50, "<" + typeName + ">"); + el.draggable("destroy"); + el.remove(); + }); +}); + +test("No options, relative", function() { + el = $("#draggable1").draggable(); + drag(el, 50, 50); + moved(50, 50); +}); + +test("No options, absolute", function() { + el = $("#draggable2").draggable(); + drag(el, 50, 50); + moved(50, 50); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_defaults.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_defaults.js new file mode 100644 index 0000000..4b0aaca --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_defaults.js @@ -0,0 +1,36 @@ +/* + * draggable_defaults.js + */ + +var draggable_defaults = { + addClasses: true, + appendTo: "parent", + axis: false, + cancel: ":input,option", + connectToSortable: false, + containment: false, + cursor: "auto", + cursorAt: false, + delay: 0, + disabled: false, + distance: 1, + grid: false, + handle: false, + helper: "original", + iframeFix: false, + opacity: false, + refreshPositions: false, + revert: false, + revertDuration: 500, + scroll: true, + scrollSensitivity: 20, + scrollSpeed: 20, + scope: "default", + snap: false, + snapMode: "both", + snapTolerance: 20, + stack: false, + zIndex: false +}; + +commonWidgetTests('draggable', { defaults: draggable_defaults }); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_events.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_events.js new file mode 100644 index 0000000..d92d8ee --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_events.js @@ -0,0 +1,81 @@ +/* + * draggable_events.js + */ +(function($) { + +module("draggable: events"); + +test("callbacks occurance count", function() { + + expect(3); + + var start = 0, stop = 0, dragc = 0; + el = $("#draggable2").draggable({ + start: function() { start++; }, + drag: function() { dragc++; }, + stop: function() { stop++; } + }); + + drag(el, 10, 10); + + equals(start, 1, "start callback should happen exactly once"); + equals(dragc, 3, "drag callback should happen exactly once per mousemove"); + equals(stop, 1, "stop callback should happen exactly once"); + +}); + +test("stopping the start callback", function() { + + expect(3); + + var start = 0, stop = 0, dragc = 0; + el = $("#draggable2").draggable({ + start: function() { start++; return false; }, + drag: function() { dragc++; }, + stop: function() { stop++; } + }); + + drag(el, 10, 10); + + equals(start, 1, "start callback should happen exactly once"); + equals(dragc, 0, "drag callback should not happen at all"); + equals(stop, 0, "stop callback should not happen if there wasnt even a start"); + +}); + +test("stopping the drag callback", function() { + + expect(3); + + var start = 0, stop = 0, dragc = 0; + el = $("#draggable2").draggable({ + start: function() { start++;}, + drag: function() { dragc++; return false; }, + stop: function() { stop++; } + }); + + drag(el, 10, 10); + + equals(start, 1, "start callback should happen exactly once"); + equals(dragc, 1, "drag callback should happen exactly once"); + equals(stop, 1, "stop callback should happen, as we need to actively stop the drag"); + +}); + +test("stopping the stop callback", function() { + + expect(1); + + el = $("#draggable2").draggable({ + helper: 'clone', + stop: function() { return false; } + }); + + drag(el, 10, 10); + + ok($("#draggable2").data('draggable').helper, "the clone should not be deleted if the stop callback is stopped"); + + +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_methods.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_methods.js new file mode 100644 index 0000000..4ffadf0 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_methods.js @@ -0,0 +1,99 @@ +/* + * draggable_methods.js + */ +(function($) { + +function shouldmove(why) { + drag(el, 50, 50); + moved(50, 50, why); +} + +function shouldnotmove(why) { + drag(el, 50, 50); + moved(0, 0, why); +} + +module("draggable: methods"); + +test("init", function() { + expect(6); + + $("<div></div>").appendTo('body').draggable().remove(); + ok(true, '.draggable() called on element'); + + $([]).draggable(); + ok(true, '.draggable() called on empty collection'); + + $("<div></div>").draggable(); + ok(true, '.draggable() called on disconnected DOMElement'); + + $("<div></div>").draggable().draggable("foo"); + ok(true, 'arbitrary method called after init'); + + $("<div></div>").draggable().draggable("option", "foo"); + ok(true, 'arbitrary option getter after init'); + + $("<div></div>").draggable().draggable("option", "foo", "bar"); + ok(true, 'arbitrary option setter after init'); +}); + +test("destroy", function() { + $("<div></div>").appendTo('body').draggable().draggable("destroy").remove(); + ok(true, '.draggable("destroy") called on element'); + + $([]).draggable().draggable("destroy"); + ok(true, '.draggable("destroy") called on empty collection'); + + $("<div></div>").draggable().draggable("destroy"); + ok(true, '.draggable("destroy") called on disconnected DOMElement'); + + $("<div></div>").draggable().draggable("destroy").draggable("foo"); + ok(true, 'arbitrary method called after destroy'); + + var expected = $('<div></div>').draggable(), + actual = expected.draggable('destroy'); + equals(actual, expected, 'destroy is chainable'); +}); + +test("enable", function() { + expect(7); + el = $("#draggable2").draggable({ disabled: true }); + shouldnotmove('.draggable({ disabled: true })'); + el.draggable("enable"); + shouldmove('.draggable("enable")'); + equals(el.draggable("option", "disabled"), false, "disabled option getter"); + + el.draggable("destroy"); + el.draggable({ disabled: true }); + shouldnotmove('.draggable({ disabled: true })'); + el.draggable("option", "disabled", false); + equals(el.draggable("option", "disabled"), false, "disabled option setter"); + shouldmove('.draggable("option", "disabled", false)'); + + var expected = $('<div></div>').draggable(), + actual = expected.draggable('enable'); + equals(actual, expected, 'enable is chainable'); +}); + +test("disable", function() { + expect(7); + el = $("#draggable2").draggable({ disabled: false }); + shouldmove('.draggable({ disabled: false })'); + el.draggable("disable"); + shouldnotmove('.draggable("disable")'); + equals(el.draggable("option", "disabled"), true, "disabled option getter"); + + el.draggable("destroy"); + + el.draggable({ disabled: false }); + shouldmove('.draggable({ disabled: false })'); + el.draggable("option", "disabled", true); + equals(el.draggable("option", "disabled"), true, "disabled option setter"); + shouldnotmove('.draggable("option", "disabled", true)'); + + var expected = $('<div></div>').draggable(), + actual = expected.draggable('disable'); + equals(actual, expected, 'disable is chainable'); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_options.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_options.js new file mode 100644 index 0000000..8ba77fb --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/draggable/draggable_options.js @@ -0,0 +1,753 @@ +/* + * draggable_options.js + */ +(function($) { + +function testScroll(position) { + $("#main").css('position', position); + drag(el, 50, 50); + moved(50, 50, position+' parent'); +} + +function setScroll(what) { + if(what) { + $(document).scrollTop(100); $(document).scrollLeft(100); + } else { + $("#main")[0].scrollTop = 100; $("#main")[0].scrollLeft = 100; + } +} + +var border = function(el, side) { return parseInt(el.css('border-' + side + '-width')); } + +var margin = function(el, side) { return parseInt(el.css('margin-' + side)); } + +module("draggable: options"); + +test("{ addClasses: true }, default", function() { + equals(draggable_defaults.addClasses, true); + + el = $("<div></div>").draggable({ addClasses: true }); + ok(el.is(".ui-draggable"), "'ui-draggable' class added"); + + el.draggable("destroy"); +}); + +test("{ addClasses: false }", function() { + el = $("<div></div>").draggable({ addClasses: false }); + ok(!el.is(".ui-draggable"), "'ui-draggable' class not added"); + + el.draggable("destroy"); +}); + +test("{ appendTo: 'parent' }, default", function() { + equals(draggable_defaults.appendTo, "parent"); + + el = $("#draggable2").draggable({ appendTo: 'parent' }); + drag(el, 50, 50); + moved(50, 50); + + el = $("#draggable1").draggable({ appendTo: 'parent' }); + drag(el, 50, 50); + moved(50, 50); + +}); + +test("{ appendTo: Element }", function() { + el = $("#draggable2").draggable({ appendTo: $("#draggable2").parent()[0] }); + drag(el, 50, 50); + moved(50, 50); + + el = $("#draggable1").draggable({ appendTo: $("#draggable2").parent()[0] }); + drag(el, 50, 50); + moved(50, 50); +}); + +test("{ appendTo: Selector }", function() { + el = $("#draggable2").draggable({ appendTo: "#main" }); + drag(el, 50, 50); + moved(50, 50); + + el = $("#draggable1").draggable({ appendTo: "#main" }); + drag(el, 50, 50); + moved(50, 50); +}); + +test("{ axis: false }, default", function() { + equals(draggable_defaults.axis, false); + + el = $("#draggable2").draggable({ axis: false }); + drag(el, 50, 50); + moved(50, 50); +}); + +test("{ axis: 'x' }", function() { + el = $("#draggable2").draggable({ axis: "x" }); + drag(el, 50, 50); + moved(50, 0); +}); + +test("{ axis: 'y' }", function() { + el = $("#draggable2").draggable({ axis: "y" }); + drag(el, 50, 50); + moved(0, 50); +}); + +test("{ axis: ? }, unexpected", function() { + var unexpected = { + "true": true, + "{}": {}, + "[]": [], + "null": null, + "undefined": undefined, + "function() {}": function() {} + }; + $.each(unexpected, function(key, val) { + el = $("#draggable2").draggable({ axis: val }); + drag(el, 50, 50); + moved(50, 50, "axis: " + key); + el.draggable("destroy"); + }) +}); + +test("{ cancel: ':input,option' }, default", function() { + equals(draggable_defaults.cancel, ":input,option"); + + $('<div id="draggable-option-cancel-default"><input type="text"></div>').appendTo('#main'); + + el = $("#draggable-option-cancel-default").draggable({ cancel: ":input,option" }); + drag("#draggable-option-cancel-default", 50, 50); + moved(50, 50); + + el = $("#draggable-option-cancel-default").draggable({ cancel: ":input,option" }); + drag("#draggable-option-cancel-default :input", 50, 50); + moved(0, 0); + + el.draggable("destroy"); +}); + +test("{ cancel: 'span' }", function() { + el = $("#draggable2").draggable(); + drag("#draggable2 span", 50, 50); + moved(50, 50); + + el.draggable("destroy"); + + el = $("#draggable2").draggable({ cancel: 'span' }); + drag("#draggable2 span", 50, 50); + moved(0, 0); +}); + +test("{ cancel: ? }, unexpected", function() { + var unexpected = { + "true": true, + "false": false, + "{}": {}, + "[]": [], + "null": null, + "undefined": undefined, + "function() {return '';}": function() {return '';}, + "function() {return true;}": function() {return true;}, + "function() {return false;}": function() {return false;} + }; + $.each(unexpected, function(key, val) { + el = $("#draggable2").draggable({ cancel: val }); + drag(el, 50, 50); + var expected = [50, 50]; + moved(expected[0], expected[1], "cancel: " + key); + el.draggable("destroy"); + }) +}); + +test("{ containment: false }, default", function() { + equals(draggable_defaults.containment, false); + + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ containment: Element }", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ containment: 'parent' }, relative", function() { + el = $("#draggable1").draggable({ containment: 'parent' }); + var p = el.parent(), po = p.offset(); + drag(el, -100, -100); + var expected = { + left: po.left + border(p, 'left') + margin(el, 'left'), + top: po.top + border(p, 'top') + margin(el, 'top') + } + same(offsetAfter, expected, 'compare offset to parent'); +}); + +test("{ containment: 'parent' }, absolute", function() { + el = $("#draggable2").draggable({ containment: 'parent' }); + var p = el.parent(), po = p.offset(); + drag(el, -100, -100); + var expected = { + left: po.left + border(p, 'left') + margin(el, 'left'), + top: po.top + border(p, 'top') + margin(el, 'top') + } + same(offsetAfter, expected, 'compare offset to parent'); +}); + +test("{ containment: 'document' }", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ containment: 'window' }", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ containment: Selector }", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ containment: [x1, y1, x2, y2] }", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ cursor: 'auto' }, default", function() { + equals(draggable_defaults.cursor, 'auto'); + + function getCursor() { return $("#draggable2").css("cursor"); } + + expect(3); + + var expected = "auto", actual, before, after; + + el = $("#draggable2").draggable({ + cursor: expected, + start: function(event, ui) { + actual = getCursor(); + } + }); + + before = getCursor(); + drag("#draggable2", -1, -1); + after = getCursor(); + + equals(actual, expected, "start callback: cursor '" + expected + "'"); + equals(after, before, "after drag: cursor restored"); + +}); + +test("{ cursor: 'move' }", function() { + + function getCursor() { return $("body").css("cursor"); } + + expect(2); + + var expected = "move", actual, before, after; + + el = $("#draggable2").draggable({ + cursor: expected, + start: function(event, ui) { + actual = getCursor(); + } + }); + + before = getCursor(); + drag("#draggable2", -1, -1); + after = getCursor(); + + equals(actual, expected, "start callback: cursor '" + expected + "'"); + equals(after, before, "after drag: cursor restored"); + +}); + +test("{ cursorAt: false}, default", function() { + equals(draggable_defaults.cursorAt, false); + + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ cursorAt: { left: -5, top: -5 } }", function() { + expect(4); + + var deltaX = -3, deltaY = -3, + offsetX = 5, offsetY = 5, + cursorAtX = -5, cursorAtY = -5; + + $.each(['relative', 'absolute'], function(i, position) { + var el = $('#draggable' + (i + 1)).draggable({ + cursorAt: { left: cursorAtX, top: cursorAtY }, + drag: function(event, ui) { + equals(ui.offset.left, expected.left, position + ' left'); + equals(ui.offset.top, expected.top, position + ' top'); + } + }), + before = el.offset(), + pos = { + clientX: before.left + offsetX, + clientY: before.top + offsetY + }, + expected = { + left: before.left + offsetX - cursorAtX + deltaX, + top: before.top + offsetY - cursorAtY + deltaY + }; + + el.simulate("mousedown", pos); + pos.clientX += deltaX; + pos.clientY += deltaY; + $(document).simulate("mousemove", pos); + el.simulate("mouseup", pos); + }); +}); + +test("{ cursorAt: { right: 10, bottom: 20 } }", function() { + expect(4); + + var deltaX = -3, deltaY = -3, + offsetX = 5, offsetY = 5, + cursorAtX = 10, cursorAtY = 20; + + $.each(['relative', 'absolute'], function(i, position) { + var el = $('#draggable' + (i + 1)).draggable({ + cursorAt: { right: cursorAtX, bottom: cursorAtY }, + drag: function(event, ui) { + equals(ui.offset.left, expected.left, position + ' left'); + equals(ui.offset.top, expected.top, position + ' top'); + } + }), + before = el.offset(), + pos = { + clientX: before.left + offsetX, + clientY: before.top + offsetY + }, + expected = { + left: before.left + offsetX - el.width() + cursorAtX + deltaX, + top: before.top + offsetY - el.height() + cursorAtY + deltaY + }; + + el.simulate("mousedown", pos); + pos.clientX += deltaX; + pos.clientY += deltaY; + $(document).simulate("mousemove", pos); + el.simulate("mouseup", pos); + }); +}); + +test("{ cursorAt: [10, 20] }", function() { + expect(4); + + var deltaX = -3, deltaY = -3, + offsetX = 5, offsetY = 5, + cursorAtX = 10, cursorAtY = 20; + + $.each(['relative', 'absolute'], function(i, position) { + var el = $('#draggable' + (i + 1)).draggable({ + cursorAt: { left: cursorAtX, top: cursorAtY }, + drag: function(event, ui) { + equals(ui.offset.left, expected.left, position + ' left'); + equals(ui.offset.top, expected.top, position + ' top'); + } + }), + before = el.offset(), + pos = { + clientX: before.left + offsetX, + clientY: before.top + offsetY + }, + expected = { + left: before.left + offsetX - cursorAtX + deltaX, + top: before.top + offsetY - cursorAtY + deltaY + }; + + el.simulate("mousedown", pos); + pos.clientX += deltaX; + pos.clientY += deltaY; + $(document).simulate("mousemove", pos); + el.simulate("mouseup", pos); + }); +}); + +test("{ cursorAt: '20, 40' }", function() { + expect(4); + + var deltaX = -3, deltaY = -3, + offsetX = 5, offsetY = 5, + cursorAtX = 20, cursorAtY = 40; + + $.each(['relative', 'absolute'], function(i, position) { + var el = $('#draggable' + (i + 1)).draggable({ + cursorAt: { left: cursorAtX, top: cursorAtY }, + drag: function(event, ui) { + equals(ui.offset.left, expected.left, position + ' left'); + equals(ui.offset.top, expected.top, position + ' top'); + } + }), + before = el.offset(), + pos = { + clientX: before.left + offsetX, + clientY: before.top + offsetY + }, + expected = { + left: before.left + offsetX - cursorAtX + deltaX, + top: before.top + offsetY - cursorAtY + deltaY + }; + + el.simulate("mousedown", pos); + pos.clientX += deltaX; + pos.clientY += deltaY; + $(document).simulate("mousemove", pos); + el.simulate("mouseup", pos); + }); +}); + +test("{ distance: 10 }", function() { + + el = $("#draggable2").draggable({ distance: 10 }); + drag(el, -9, -9); + moved(0, 0, 'distance not met'); + + drag(el, -10, -10); + moved(-10, -10, 'distance met'); + + drag(el, 9, 9); + moved(0, 0, 'distance not met'); + +}); + +test("{ grid: [50, 50] }, relative", function() { + el = $("#draggable1").draggable({ grid: [50, 50] }); + drag(el, 24, 24); + moved(0, 0); + drag(el, 26, 25); + moved(50, 50); +}); + +test("{ grid: [50, 50] }, absolute", function() { + el = $("#draggable2").draggable({ grid: [50, 50] }); + drag(el, 24, 24); + moved(0, 0); + drag(el, 26, 25); + moved(50, 50); +}); + +test("{ handle: 'span' }", function() { + el = $("#draggable2").draggable({ handle: 'span' }); + + drag("#draggable2 span", 50, 50); + moved(50, 50, "drag span"); + + drag("#draggable2", 50, 50); + moved(0, 0, "drag element"); +}); + +test("{ helper: 'clone' }, relative", function() { + el = $("#draggable1").draggable({ helper: "clone" }); + drag(el, 50, 50); + moved(0, 0); +}); + +test("{ helper: 'clone' }, absolute", function() { + el = $("#draggable2").draggable({ helper: "clone" }); + drag(el, 50, 50); + moved(0, 0); +}); + +test("{ helper: 'original' }, relative, with scroll offset on parent", function() { + + el = $("#draggable1").draggable({ helper: "original" }); + + setScroll(); + testScroll('relative'); + + setScroll(); + testScroll('static'); + + setScroll(); + testScroll('absolute'); + + restoreScroll(); + +}); + +test("{ helper: 'original' }, relative, with scroll offset on root", function() { + + el = $("#draggable1").draggable({ helper: "original" }); + + setScroll('root'); + testScroll('relative'); + + setScroll('root'); + testScroll('static'); + + setScroll('root'); + testScroll('absolute'); + + restoreScroll('root'); + +}); + +test("{ helper: 'original' }, relative, with scroll offset on root and parent", function() { + + el = $("#draggable1").draggable({ helper: "original" }); + + setScroll(); + setScroll('root'); + testScroll('relative'); + + setScroll(); + setScroll('root'); + testScroll('static'); + + setScroll(); + setScroll('root'); + testScroll('absolute'); + + restoreScroll(); + restoreScroll('root'); + +}); + +test("{ helper: 'original' }, absolute, with scroll offset on parent", function() { + + el = $("#draggable1").css({ position: 'absolute', top: 0, left: 0 }).draggable({ helper: "original" }); + + setScroll(); + testScroll('relative'); + + setScroll(); + testScroll('static'); + + setScroll(); + testScroll('absolute'); + + restoreScroll(); + +}); + +test("{ helper: 'original' }, absolute, with scroll offset on root", function() { + + el = $("#draggable1").css({ position: 'absolute', top: 0, left: 0 }).draggable({ helper: "original" }); + + setScroll('root'); + testScroll('relative'); + + setScroll('root'); + testScroll('static'); + + setScroll('root'); + testScroll('absolute'); + + restoreScroll('root'); + +}); + +test("{ helper: 'original' }, absolute, with scroll offset on root and parent", function() { + + el = $("#draggable1").css({ position: 'absolute', top: 0, left: 0 }).draggable({ helper: "original" }); + + setScroll(); + setScroll('root'); + testScroll('relative'); + + setScroll(); + setScroll('root'); + testScroll('static'); + + setScroll(); + setScroll('root'); + testScroll('absolute'); + + restoreScroll(); + restoreScroll('root'); + +}); + +test("{ helper: 'original' }, fixed, with scroll offset on parent", function() { + + el = $("#draggable1").css({ position: 'fixed', top: 0, left: 0 }).draggable({ helper: "original" }); + + setScroll(); + testScroll('relative'); + + setScroll(); + testScroll('static'); + + setScroll(); + testScroll('absolute'); + + restoreScroll(); + +}); + +test("{ helper: 'original' }, fixed, with scroll offset on root", function() { + + el = $("#draggable1").css({ position: 'fixed', top: 0, left: 0 }).draggable({ helper: "original" }); + + setScroll('root'); + testScroll('relative'); + + setScroll('root'); + testScroll('static'); + + setScroll('root'); + testScroll('absolute'); + + restoreScroll('root'); +}); + +test("{ helper: 'original' }, fixed, with scroll offset on root and parent", function() { + + el = $("#draggable1").css({ position: 'fixed', top: 0, left: 0 }).draggable({ helper: "original" }); + + setScroll(); + setScroll('root'); + testScroll('relative'); + + setScroll(); + setScroll('root'); + testScroll('static'); + + setScroll(); + setScroll('root'); + testScroll('absolute'); + + restoreScroll(); + restoreScroll('root'); + +}); + +test("{ helper: 'clone' }, absolute", function() { + + var helperOffset = null; + var origOffset = $("#draggable1").offset(); + + el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) { + helperOffset = ui.helper.offset(); + } }); + + drag(el, 1, 1); + same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); + +}); + +test("{ helper: 'clone' }, absolute with scroll offset on parent", function() { + + setScroll(); + var helperOffset = null; + var origOffset = null; + + el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) { + helperOffset = ui.helper.offset(); + } }); + + $("#main").css('position', 'relative'); + origOffset = $("#draggable1").offset(); + drag(el, 1, 1); + same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); + + $("#main").css('position', 'static'); + origOffset = $("#draggable1").offset(); + drag(el, 1, 1); + same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); + + $("#main").css('position', 'absolute'); + origOffset = $("#draggable1").offset(); + drag(el, 1, 1); + same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); + + restoreScroll(); + +}); + +test("{ helper: 'clone' }, absolute with scroll offset on root", function() { + + setScroll('root'); + var helperOffset = null; + var origOffset = null; + + el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) { + helperOffset = ui.helper.offset(); + } }); + + $("#main").css('position', 'relative'); + origOffset = $("#draggable1").offset(); + drag(el, 1, 1); + same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); + + $("#main").css('position', 'static'); + origOffset = $("#draggable1").offset(); + drag(el, 1, 1); + same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); + + $("#main").css('position', 'absolute'); + origOffset = $("#draggable1").offset(); + drag(el, 1, 1); + same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); + + restoreScroll('root'); + +}); + +test("{ helper: 'clone' }, absolute with scroll offset on root and parent", function() { + + setScroll('root'); + setScroll(); + var helperOffset = null; + var origOffset = null; + + el = $("#draggable1").draggable({ helper: "clone", drag: function(event, ui) { + helperOffset = ui.helper.offset(); + } }); + + $("#main").css('position', 'relative'); + origOffset = $("#draggable1").offset() + drag(el, 1, 1); + same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); + + $("#main").css('position', 'static'); + origOffset = $("#draggable1").offset() + drag(el, 1, 1); + same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); + + $("#main").css('position', 'absolute'); + origOffset = $("#draggable1").offset() + drag(el, 1, 1); + same({ top: helperOffset.top-1, left: helperOffset.left-1 }, origOffset, 'dragged[' + dragged.dx + ', ' + dragged.dy + '] '); + + restoreScroll('root'); + restoreScroll(); + +}); + +test("{ opacity: 0.5 }", function() { + + expect(1); + + var opacity = null; + el = $("#draggable2").draggable({ + opacity: 0.5, + start: function(event, ui) { + opacity = $(this).css("opacity"); + } + }); + + drag("#draggable2", -1, -1); + + equals(opacity, 0.5, "start callback: opacity is"); + +}); + +test("{ zIndex: 10 }", function() { + + expect(1); + + var expected = 10, actual; + + var zIndex = null; + el = $("#draggable2").draggable({ + zIndex: expected, + start: function(event, ui) { + actual = $(this).css("zIndex"); + } + }); + + drag("#draggable2", -1, -1); + + equals(actual, expected, "start callback: zIndex is"); + +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/droppable/all.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/droppable/all.html new file mode 100644 index 0000000..e7f274c --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/droppable/all.html @@ -0,0 +1,30 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Droppable Test Suite</title> + + <script src="../../../jquery-1.7.1.js"></script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <link rel="stylesheet" href="../subsuiteRunner.css"> + <script src="../../../external/qunit.js"></script> + <script src="../subsuiteRunner.js"></script> + <script src="../subsuite.js"></script> + + <script> + testAllVersions( "droppable" ); + </script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Droppable Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/droppable/droppable.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/droppable/droppable.html new file mode 100644 index 0000000..abf94f0 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/droppable/droppable.html @@ -0,0 +1,60 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Droppable Test Suite</title> + + <script src="../../jquery.js"></script> + <script src="../../resource_loader.js"></script> + <script> + loadResources({ + css: [ "ui.core" ], + js: [ + "ui/jquery.ui.core.js", + "ui/jquery.ui.widget.js", + "ui/jquery.ui.mouse.js", + "ui/jquery.ui.draggable.js", + "ui/jquery.ui.droppable.js" + ] + }); + </script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <script src="../../../external/qunit.js"></script> + <script src="../../jquery.simulate.js"></script> + <script src="../testsuite.js"></script> + + <script src="droppable_core.js"></script> + <script src="droppable_defaults.js"></script> + <script src="droppable_events.js"></script> + <script src="droppable_methods.js"></script> + <script src="droppable_options.js"></script> + + <script> + // disable this stale testsuite for testswarm only + var url = window.location.search; + url = decodeURIComponent( url.slice( url.indexOf("swarmURL=") + 9 ) ); + if ( url && url.indexOf("http") == 0 ) { + // reset config to kill previous tests; make sure testsuite.js is loaded afterwards to init the testswarm script + QUnit.init(); + test("droppable", function() { ok(true, "disabled droppable testsuite"); }); + } + </script> + <script src="../swarminject.js"></script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Droppable Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +<div id="draggable1" style="width: 25px; height: 25px;">Draggable</div> +<div id="droppable1" style="width: 100px; height: 100px;">Droppable</div> +<div style='width:1000px;height:1000px;'> </div> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/droppable/droppable_core.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/droppable/droppable_core.js new file mode 100644 index 0000000..4d82017 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/droppable/droppable_core.js @@ -0,0 +1,36 @@ +/* + * droppable_core.js + */ + +var el, drg; + +function shouldBeDroppable() { + ok(false, 'missing test - untested code is broken code'); +} + +function shouldNotBeDroppable() { + ok(false, 'missing test - untested code is broken code'); +} + +(function($) { + +module("droppable: core"); + +test("element types", function() { + var typeNames = ('p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form' + + ',table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr' + + ',acronym,code,samp,kbd,var,img,object,hr' + + ',input,button,label,select,iframe').split(','); + + $.each(typeNames, function(i) { + var typeName = typeNames[i]; + el = $(document.createElement(typeName)).appendTo('body'); + (typeName == 'table' && el.append("<tr><td>content</td></tr>")); + el.droppable(); + shouldBeDroppable(); + el.droppable("destroy"); + el.remove(); + }); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/droppable/droppable_defaults.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/droppable/droppable_defaults.js new file mode 100644 index 0000000..7584f5e --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/droppable/droppable_defaults.js @@ -0,0 +1,16 @@ +/* + * droppable_defaults.js + */ + +var droppable_defaults = { + accept: '*', + activeClass: false, + addClasses: true, + disabled: false, + greedy: false, + hoverClass: false, + scope: "default", + tolerance: "intersect" +}; + +commonWidgetTests('droppable', { defaults: droppable_defaults }); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/droppable/droppable_events.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/droppable/droppable_events.js new file mode 100644 index 0000000..f22a035 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/droppable/droppable_events.js @@ -0,0 +1,28 @@ +/* + * droppable_events.js + */ +(function($) { + +module("droppable: events"); + +test("activate", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("deactivate", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("over", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("out", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("drop", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/droppable/droppable_methods.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/droppable/droppable_methods.js new file mode 100644 index 0000000..87b9168 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/droppable/droppable_methods.js @@ -0,0 +1,86 @@ +/* + * droppable_methods.js + */ +(function($) { + +module("droppable: methods"); + +test("init", function() { + expect(6); + + $("<div></div>").appendTo('body').droppable().remove(); + ok(true, '.droppable() called on element'); + + $([]).droppable(); + ok(true, '.droppable() called on empty collection'); + + $("<div></div>").droppable(); + ok(true, '.droppable() called on disconnected DOMElement'); + + $("<div></div>").droppable().droppable("foo"); + ok(true, 'arbitrary method called after init'); + + $("<div></div>").droppable().droppable("option", "foo"); + ok(true, 'arbitrary option getter after init'); + + $("<div></div>").droppable().droppable("option", "foo", "bar"); + ok(true, 'arbitrary option setter after init'); +}); + +test("destroy", function() { + $("<div></div>").appendTo('body').droppable().droppable("destroy").remove(); + ok(true, '.droppable("destroy") called on element'); + + $([]).droppable().droppable("destroy"); + ok(true, '.droppable("destroy") called on empty collection'); + + $("<div></div>").droppable().droppable("destroy"); + ok(true, '.droppable("destroy") called on disconnected DOMElement'); + + $("<div></div>").droppable().droppable("destroy").droppable("foo"); + ok(true, 'arbitrary method called after destroy'); + + var expected = $('<div></div>').droppable(), + actual = expected.droppable('destroy'); + equals(actual, expected, 'destroy is chainable'); +}); + +test("enable", function() { + expect(7); + el = $("#droppable1").droppable({ disabled: true }); + shouldNotBeDroppable(); + el.droppable("enable"); + shouldBeDroppable(); + equals(el.droppable("option", "disabled"), false, "disabled option getter"); + el.droppable("destroy"); + el.droppable({ disabled: true }); + shouldNotBeDroppable(); + el.droppable("option", "disabled", false); + equals(el.droppable("option", "disabled"), false, "disabled option setter"); + shouldBeDroppable(); + + var expected = $('<div></div>').droppable(), + actual = expected.droppable('enable'); + equals(actual, expected, 'enable is chainable'); +}); + +test("disable", function() { + expect(7); + el = $("#droppable1").droppable({ disabled: false }); + shouldBeDroppable(); + el.droppable("disable"); + shouldNotBeDroppable(); + equals(el.droppable("option", "disabled"), true, "disabled option getter"); + el.droppable("destroy"); + el.droppable({ disabled: false }); + shouldBeDroppable(); + el.droppable("option", "disabled", true); + equals(el.droppable("option", "disabled"), true, "disabled option setter"); + shouldNotBeDroppable(); + + var expected = $('<div></div>').droppable(), + actual = expected.droppable('disable'); + equals(actual, expected, 'disable is chainable'); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/droppable/droppable_options.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/droppable/droppable_options.js new file mode 100644 index 0000000..2f2dbf6 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/droppable/droppable_options.js @@ -0,0 +1,68 @@ +/* + * droppable_options.js + */ +(function($) { + +module("droppable: options"); + +test("{ accept '*' }, default ", function() { + equals(droppable_defaults.accept, '*'); + + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ accept: Selector }", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ accept: function(draggable) }", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("activeClass", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("{ addClasses: true }, default", function() { + equals(droppable_defaults.addClasses, true); + + el = $("<div></div>").droppable({ addClasses: true }); + ok(el.is(".ui-droppable"), "'ui-droppable' class added"); + el.droppable("destroy"); +}); + +test("{ addClasses: false }", function() { + el = $("<div></div>").droppable({ addClasses: false }); + ok(!el.is(".ui-droppable"), "'ui-droppable' class not added"); + el.droppable("destroy"); +}); + +test("greedy", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("hoverClass", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("scope", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("tolerance, fit", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("tolerance, intersect", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("tolerance, pointer", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +test("tolerance, touch", function() { + ok(false, 'missing test - untested code is broken code'); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/effects/all.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/effects/all.html new file mode 100644 index 0000000..56890ba --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/effects/all.html @@ -0,0 +1,30 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Effects Test Suite</title> + + <script src="../../../jquery-1.7.1.js"></script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <link rel="stylesheet" href="../subsuiteRunner.css"> + <script src="../../../external/qunit.js"></script> + <script src="../subsuiteRunner.js"></script> + <script src="../subsuite.js"></script> + + <script> + testAllVersions( "effects" ); + </script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Effects Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/effects/effects.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/effects/effects.html new file mode 100644 index 0000000..06023c5 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/effects/effects.html @@ -0,0 +1,117 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Effects Test Suite</title> + + <script src="../../jquery.js"></script> + <script> + $.uiBackCompat = false; + </script> + <script src="../../resource_loader.js"></script> + <script> + loadResources({ + js: [ + "ui/jquery.effects.core.js", + "ui/jquery.effects.blind.js", + "ui/jquery.effects.bounce.js", + "ui/jquery.effects.clip.js", + "ui/jquery.effects.drop.js", + "ui/jquery.effects.explode.js", + "ui/jquery.effects.fade.js", + "ui/jquery.effects.fold.js", + "ui/jquery.effects.highlight.js", + "ui/jquery.effects.pulsate.js", + "ui/jquery.effects.scale.js", + "ui/jquery.effects.shake.js", + "ui/jquery.effects.slide.js", + "ui/jquery.effects.transfer.js" + ] + }); + </script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <script src="../../../external/qunit.js"></script> + <script src="../../jquery.simulate.js"></script> + <script src="../testsuite.js"></script> + <script src="effects_core.js"></script> + <script src="effects_scale.js"></script> + + <script src="../swarminject.js"></script> + <style> + #qunit-fixture { + width: 1000px; + height: 1000px; + } + .hidden { + display: none; + } + .test { + background: #000; + border: 0; + width: 100px; + height: 100px; + } + .testAddBorder { + border: 10px solid #000; + } + .testChildren, + .testChangeBackground { + background: #fff; + } + .test h2 { + font-size: 10px; + } + .testChildren h2 { + font-size: 20px; + } + + .relWidth { + width: 50%; + } + + .relHeight { + height: 50%; + } + + .testScale { + border: 5px solid #000; + padding: 5px; + margin: 5px; + width: 50px; + height: 50px; + } + + .ticket7106 { + width: 50px; + height: 50px; + } + .ticket7106.animate { + width: 100px; + } + + </style> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Effects Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> +<div class="hidden test"></div> +<div class="animateClass test"> + <h2>Child Element Test</h2> +</div> +<div class="relWidth relHeight testAddBorder"> + <h2>Slide with relative width</h2> +</div> +<div class="testScale"> +</div> +<div class="ticket7106"> +</div> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/effects/effects_core.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/effects/effects_core.js new file mode 100644 index 0000000..aca4c46 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/effects/effects_core.js @@ -0,0 +1,182 @@ +(function($) { + +function present( value, array, message ) { + QUnit.push( jQuery.inArray( value, array ) !== -1 , value, array, message ); +} + +function notPresent( value, array, message ) { + QUnit.push( jQuery.inArray( value, array ) === -1 , value, array, message ); +} + +// minDuration is used for "short" animate tests where we are only concerned about the final +var minDuration = 15, + + // duration is used for "long" animates where we plan on testing properties during animation + duration = 200, + + // mid is used for testing in the "middle" of the "duration" animations + mid = duration / 2; + +module( "effects.core" ); + +test( "Immediate Return Conditions", function() { + var hidden = $( "div.hidden" ), + count = 0; + expect( 3 ); + hidden.hide( "blind", function() { + equal( ++count, 1, "Hide on hidden returned immediately" ); + }).show().show( "blind", function() { + equal( ++count, 2, "Show on shown returned immediately" ); + }); + equal( ++count, 3, "Both Functions worked properly" ); +}); + +test( "createWrapper and removeWrapper retain focused elements (#7595)", function() { + expect( 2 ); + var test = $( "div.hidden" ).show(), + input = $( "<input type='text'>" ).appendTo( test ).focus(); + + $.effects.createWrapper( test ); + equal( document.activeElement, input[ 0 ], "Active element is still input after createWrapper" ); + $.effects.removeWrapper( test ); + equal( document.activeElement, input[ 0 ], "Active element is still input after removeWrapper" ); +}); + + +module( "effects.core: animateClass" ); + +asyncTest( "animateClass works with borderStyle", function() { + var test = $("div.animateClass"), + count = 0; + expect(3); + test.toggleClass("testAddBorder", minDuration, function() { + test.toggleClass("testAddBorder", minDuration, function() { + equal( test.css("borderLeftStyle"), "none", "None border set" ); + start(); + }); + equal( test.css("borderLeftStyle"), "solid", "None border not immedately set" ); + }); + equal( test.css("borderLeftStyle"), "solid", "Solid border immedately set" ); +}); + +asyncTest( "animateClass works with colors", function() { + var test = $("div.animateClass"), + count = 0; + expect(2); + test.toggleClass("testChangeBackground", duration, function() { + present( test.css("backgroundColor"), [ "#ffffff", "#fff", "rgb(255, 255, 255)" ], "Color is final" ); + start(); + }); + setTimeout(function() { + var color = test.css("backgroundColor"); + notPresent( color, [ "#000000", "#ffffff", "#000", "#fff", "rgb(0, 0, 0)", "rgb(255,255,255)" ], + "Color is not endpoints in middle." ); + }, mid); +}); + +asyncTest( "animateClass works with children", function() { + var test = $("div.animateClass"), + h2 = test.find("h2"); + + expect(4); + setTimeout(function() { + notPresent( h2.css("fontSize"), ["10px","20px"], "Font size is neither endpoint when in middle."); + }, mid); + test.toggleClass("testChildren", { children: true, duration: duration, complete: function() { + equal( h2.css("fontSize"), "20px", "Text size is final during complete"); + test.toggleClass("testChildren", duration, function() { + equal( h2.css("fontSize"), "10px", "Text size revertted after class removed"); + + start(); + }); + setTimeout(function() { + equal( h2.css("fontSize"), "20px", "Text size unchanged during animate with children: undefined" ); + }, mid); + }}); +}); + +asyncTest( "animateClass clears style properties when stopped", function() { + var test = $("div.animateClass"), + style = test[0].style, + orig = style.cssText; + + expect( 2 ); + + test.addClass( "testChangeBackground", duration ); + notEqual( orig, style.cssText, "cssText is not the same after starting animation" ); + + test.stop( true, true ); + equal( orig, $.trim( style.cssText ), "cssText is the same after stopping animation midway" ); + start(); +}); + +asyncTest( "animateClass: css and class changes during animation are not lost (#7106)", function() { + var test = $( "div.ticket7106" ); + + // add a class and change a style property after starting an animated class + test.addClass( "animate", minDuration, animationComplete ) + .addClass( "testClass" ) + .height( 100 ); + + // ensure the class stays and that the css property stays + function animationComplete() { + ok( test.hasClass( "testClass" ), "class change during animateClass was not lost" ); + equal( test.height(), 100, "css change during animateClass was not lost" ); + start(); + } +}); + + +$.each( $.effects.effect, function( effect ) { + if ( effect === "transfer" ) { + return; + } + module( "effect."+effect ); + asyncTest( "show/hide", function() { + var hidden = $( "div.hidden" ); + expect( 8 ); + + var count = 0, + test = 0; + + function queueTest( fn ) { + count++; + var point = count; + return function( next ) { + test++; + equal( point, test, "Queue function fired in order" ); + if ( fn ) { + fn(); + } else { + setTimeout( next, minDuration ); + } + }; + } + + hidden.queue( queueTest() ).show( effect, minDuration, queueTest(function() { + equal( hidden.css("display"), "block", "Hidden is shown after .show(\"" +effect+ "\", time)" ); + })).queue( queueTest() ).hide( effect, minDuration, queueTest(function() { + equal( hidden.css("display"), "none", "Back to hidden after .hide(\"" +effect+ "\", time)" ); + })).queue( queueTest(function(next) { + deepEqual( hidden.queue(), ["inprogress"], "Only the inprogress sentinel remains"); + start(); + })); + }); + + asyncTest( "relative width & height - properties are preserved", function() { + var test = $("div.relWidth.relHeight"), + width = test.width(), height = test.height(), + cssWidth = test[0].style.width, cssHeight = test[0].style.height; + + expect( 4 ); + test.toggle( effect, minDuration, function() { + equal( test[0].style.width, cssWidth, "Inline CSS Width has been reset after animation ended" ); + equal( test[0].style.height, cssHeight, "Inline CSS Height has been rest after animation ended" ); + start(); + }); + equal( test.width(), width, "Width is the same px after animation started" ); + equal( test.height(), height, "Height is the same px after animation started" ); + }); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/effects/effects_scale.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/effects/effects_scale.js new file mode 100644 index 0000000..b9bb91c --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/effects/effects_scale.js @@ -0,0 +1,68 @@ +(function( $ ) { +module( "effect.scale: Scale" ); + +function run( position, v, h, vo, ho ) { + var desc = "End Position Correct: " + position + " (" + v + "," + h + ") - origin: (" + vo + "," + ho + ")"; + asyncTest( desc, function() { + var test = $( ".testScale" ), + css = { + position: position + }, + effect = { + effect: "scale", + mode: "effect", + percent: 200, + origin: [ vo, ho ], + complete: complete, + duration: 1 + }, + target = {}, + relative = position === "relative"; + + css[ h ] = 33; + css[ v ] = 33; + target[ h ] = h === ho ? css[ h ] : ho == "center" ? css[ h ] - 35 : css[ h ] - 70; + target[ v ] = v === vo ? css[ v ] : vo == "middle" ? css[ v ] - 35 : css[ v ] - 70; + if ( relative && h == "right" ) { + target[ h ] += 70; + } + if ( relative && v == "bottom" ) { + target[ v ] += 70; + } + test.css( css ); + test.effect( effect ); + + function complete() { + equal( parseInt( test.css( h ), 10 ), target[ h ], "Horizontal Position Correct " + desc ); + equal( parseInt( test.css( v ), 10 ), target[ v ], "Vertical Position Correct " + desc ); + start(); + } + }); +} + +function suite( position ) { + run( position, "top", "left", "top", "left" ); + run( position, "top", "left", "middle", "center" ); + run( position, "top", "left", "bottom", "right" ); + /* Firefox is currently not capable of supporting detection of bottom and right.... + run( position, "bottom", "right", "top", "left" ); + run( position, "bottom", "right", "middle", "center" ); + run( position, "bottom", "right", "bottom", "right" ); + */ +} + +$(function() { + suite( "absolute" ); + suite( "relative" ); + var fixed = $.support.fixedPosition; + // jQuery < 1.7 uses $.offset.supportsFixedPosition + if ( fixed === undefined ) { + $.offset.initialize(); + fixed = $.offset.supportsFixedPosition; + } + if ( fixed ) { + suite( "fixed" ); + } +}); + +})( jQuery ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/images/jqueryui_32x32.png b/src/main/webapp/jquery-ui-1.9pre/tests/unit/images/jqueryui_32x32.png Binary files differnew file mode 100644 index 0000000..e003d16 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/images/jqueryui_32x32.png diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/index.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/index.html new file mode 100644 index 0000000..b73ede2 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/index.html @@ -0,0 +1,96 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Unit Tests</title> + + <link rel="stylesheet" href="../../themes/base/jquery.ui.core.css"> + <link rel="stylesheet" href="../../themes/base/jquery.ui.theme.css"> + <style> + body { + font-size: 62.5%; + } + .ui-widget-header { + padding: 0.2em 0.5em; + margin: 0; + } + .ui-widget-content { + padding: 1em; + margin-bottom: 1em; + } + ul { + margin: 0; + list-style: none; + } + li { + line-height: 2em; + } + </style> + + <script src="../jquery.js"></script> + <script> + $(function() { + $( "#main" ) + .addClass( "ui-widget" ) + .find( "h1, h2" ) + .addClass( "ui-widget-header ui-corner-top" ) + .next() + .addClass( "ui-widget-content ui-corner-bottom" ); + + }); + </script> +</head> +<body> + +<div id="main"> + <h1>jQuery UI Unit Tests</h1> + <div> + <h2>Full Test Suite</h2> + <ul> + <li><a href="all.html">All</a></li> + </ul> + + <h2>Core</h2> + <ul> + <li><a href="core/core.html">Core</a></li> + <li><a href="widget/widget.html">Widget</a></li> + </ul> + + <h2>Interactions</h2> + <ul> + <li><a href="draggable/draggable.html">Draggable</a></li> + <li><a href="droppable/droppable.html">Droppable</a></li> + <li><a href="resizable/resizable.html">Resizable</a></li> + <li><a href="selectable/selectable.html">Selectable</a></li> + <li><a href="sortable/sortable.html">Sortable</a></li> + </ul> + + <h2>Widgets</h2> + <ul> + <li><a href="accordion/accordion.html">Accordion</a></li> + <li><a href="autocomplete/autocomplete.html">Autocomplete</a></li> + <li><a href="button/button.html">Button</a></li> + <li><a href="datepicker/datepicker.html">Datepicker</a></li> + <li><a href="dialog/dialog.html">Dialog</a></li> + <li><a href="menu/menu.html">Menu</a></li> + <li><a href="progressbar/progressbar.html">Progressbar</a></li> + <li><a href="slider/slider.html">Slider</a></li> + <li><a href="spinner/spinner.html">Spinner</a></li> + <li><a href="tabs/tabs.html">Tabs</a></li> + <li><a href="tooltip/tooltip.html">Tooltip</a></li> + </ul> + + <h2>Utilities</h2> + <ul> + <li><a href="position/position.html">Position</a></li> + </ul> + + <h2>Effects</h2> + <ul> + <li><a href="effects/effects.html">Effects</a></li> + </ul> + </div> +</div> + +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/menu/all.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/menu/all.html new file mode 100644 index 0000000..38b7603 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/menu/all.html @@ -0,0 +1,30 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Menu Test Suite</title> + + <script src="../../../jquery-1.7.1.js"></script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <link rel="stylesheet" href="../subsuiteRunner.css"> + <script src="../../../external/qunit.js"></script> + <script src="../subsuiteRunner.js"></script> + <script src="../subsuite.js"></script> + + <script> + testAllVersions( "menu" ); + </script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Menu Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/menu/menu.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/menu/menu.html new file mode 100644 index 0000000..76f4a7a --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/menu/menu.html @@ -0,0 +1,258 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Menu Test Suite</title> + + <script src="../../jquery.js"></script> + <script src="../../resource_loader.js"></script> + <script> + loadResources({ + css: [ "ui.core", "ui.menu" ], + js: [ + "ui/jquery.ui.core.js", + "ui/jquery.ui.widget.js", + "ui/jquery.ui.menu.js" + ] + }); + </script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <script src="../../../external/qunit.js"></script> + <script src="../../jquery.simulate.js"></script> + <script src="../testsuite.js"></script> + + <script src="menu_test_helpers.js"></script> + <script src="menu_core.js"></script> + <script src="menu_defaults.js"></script> + <script src="menu_events.js"></script> + <script src="menu_methods.js"></script> + <script src="menu_options.js"></script> + + <script src="../swarminject.js"></script> + <style> + .ui-menu { + font-size: 15px; + } + #menu3 { + height: 250px; + overflow: auto; + } + #menu4, #menu4 ul { + height: 250px; + overflow: auto; + } + </style> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Menu Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +<ul class="foo" id="menu1"> + <li class="foo"><a class="foo" href="#">Aberdeen</a></li> + <li class="foo"><a class="foo" href="#">Ada</a></li> + <li class="foo"><a class="foo" href="#">Adamsville</a></li> + <li class="foo"><a class="foo" href="#">Addyston</a></li> + <li class="foo"><a class="foo" href="#">Adelphi</a></li> +</ul> + +<ul id="menu2"> + <li class="foo"><a class="foo" href="#">Aberdeen</a></li> + <li class="foo"><a class="foo" href="#">Ada</a></li> + <li class="foo"><a class="foo" href="#">Adamsville</a></li> + <li class="foo"><a class="foo" href="#">Addyston</a></li> + <li> + <a href="#">Delphi</a> + <ul> + <li class="foo"><a class="foo" href="#">Ada</a></li> + <li class="foo"><a class="foo" href="#">Saarland</a></li> + <li class="foo"><a class="foo" href="#">Salzburg</a></li> + </ul> + </li> + <li class="foo"><a class="foo" href="#">Saarland</a></li> + <li> + <a href="#">Salzburg</a> + <ul> + <li> + <a href="#">Delphi</a> + <ul> + <li class="foo"><a class="foo" href="#">Ada</a></li> + <li class="foo"><a class="foo" href="#">Saarland</a></li> + <li class="foo"><a class="foo" href="#">Salzburg</a></li> + </ul> + </li> + <li> + <a href="#">Delphi</a> + <ul> + <li class="foo"><a class="foo" href="#">Ada</a></li> + <li class="foo"><a class="foo" href="#">Saarland</a></li> + <li class="foo"><a class="foo" href="#">Salzburg</a></li> + </ul> + </li> + <li class="foo"><a class="foo" href="#">Perch</a></li> + </ul> + </li> +</ul> + +<ul class="foo" id="menu3"> + <li class="foo"><a class="foo" href="#">Aberdeen</a></li> + <li class="foo"><a class="foo" href="#">Ada</a></li> + <li class="foo"><a class="foo" href="#">Adamsville</a></li> + <li class="foo"><a class="foo" href="#">Addyston</a></li> + <li class="foo"><a class="foo" href="#">Adelphi</a></li> + <li class="foo"><a class="foo" href="#">Adena</a></li> + <li class="foo"><a class="foo" href="#">Adrian</a></li> + <li class="foo"><a class="foo" href="#">Akron</a></li> + <li class="foo"><a class="foo" href="#">Albany</a></li> + <li class="foo"><a class="foo" href="#">Alexandria</a></li> + <li class="foo"><a class="foo" href="#">Alger</a></li> + <li class="foo"><a class="foo" href="#">Alledonia</a></li> + <li class="foo"><a class="foo" href="#">Alliance</a></li> + <li class="foo"><a class="foo" href="#">Alpha</a></li> + <li class="foo"><a class="foo" href="#">Alvada</a></li> + <li class="foo"><a class="foo" href="#">Alvordton</a></li> + <li class="foo"><a class="foo" href="#">Amanda</a></li> + <li class="foo"><a class="foo" href="#">Amelia</a></li> + <li class="foo"><a class="foo" href="#">Amesville</a></li> + <li class="foo"><a class="foo" href="#">Aberdeen</a></li> + <li class="foo"><a class="foo" href="#">Ada</a></li> + <li class="foo"><a class="foo" href="#">Adamsville</a></li> + <li class="foo"><a class="foo" href="#">Addyston</a></li> + <li class="foo"><a class="foo" href="#">Adelphi</a></li> + <li class="foo"><a class="foo" href="#">Adena</a></li> + <li class="foo"><a class="foo" href="#">Adrian</a></li> + <li class="foo"><a class="foo" href="#">Akron</a></li> + <li class="foo"><a class="foo" href="#">Albany</a></li> + <li class="foo"><a class="foo" href="#">Alexandria</a></li> + <li class="foo"><a class="foo" href="#">Alger</a></li> + <li class="foo"><a class="foo" href="#">Alledonia</a></li> + <li class="foo"><a class="foo" href="#">Alliance</a></li> + <li class="foo"><a class="foo" href="#">Alpha</a></li> + <li class="foo"><a class="foo" href="#">Alvada</a></li> + <li class="foo"><a class="foo" href="#">Alvordton</a></li> + <li class="foo"><a class="foo" href="#">Amanda</a></li> + <li class="foo"><a class="foo" href="#">Amelia</a></li> + <li class="foo"><a class="foo" href="#">Amesville</a></li> +</ul> + +<ul class="foo" id="menu4"> + <li class="foo"><a class="foo" href="#">Aberdeen</a></li> + <li class="foo"> + <a class="foo" href="#">Ada</a> + <ul class="foo"> + <li class="foo"><a class="foo" href="#">Aberdeen</a></li> + <li class="foo"><a class="foo" href="#">Ada</a></li> + <li class="foo"><a class="foo" href="#">Adamsville</a></li> + <li class="foo"><a class="foo" href="#">Addyston</a></li> + <li class="foo"><a class="foo" href="#">Adelphi</a></li> + <li class="foo"><a class="foo" href="#">Adena</a></li> + <li class="foo"><a class="foo" href="#">Adrian</a></li> + <li class="foo"><a class="foo" href="#">Akron</a></li> + <li class="foo"><a class="foo" href="#">Albany</a></li> + <li class="foo"><a class="foo" href="#">Alexandria</a></li> + <li class="foo"><a class="foo" href="#">Alger</a></li> + <li class="foo"><a class="foo" href="#">Alledonia</a></li> + <li class="foo"><a class="foo" href="#">Alliance</a></li> + <li class="foo"><a class="foo" href="#">Alpha</a></li> + <li class="foo"><a class="foo" href="#">Alvada</a></li> + <li class="foo"><a class="foo" href="#">Alvordton</a></li> + <li class="foo"><a class="foo" href="#">Amanda</a></li> + <li class="foo"><a class="foo" href="#">Amelia</a></li> + <li class="foo"><a class="foo" href="#">Amesville</a></li> + <li class="foo"><a class="foo" href="#">Aberdeen</a></li> + <li class="foo"><a class="foo" href="#">Ada</a></li> + <li class="foo"><a class="foo" href="#">Adamsville</a></li> + <li class="foo"><a class="foo" href="#">Addyston</a></li> + <li class="foo"><a class="foo" href="#">Adelphi</a></li> + <li class="foo"><a class="foo" href="#">Adena</a></li> + <li class="foo"><a class="foo" href="#">Adrian</a></li> + <li class="foo"><a class="foo" href="#">Akron</a></li> + <li class="foo"><a class="foo" href="#">Albany</a></li> + </ul> + </li> + <li class="foo"><a class="foo" href="#">Adamsville</a></li> + <li class="foo"><a class="foo" href="#">Addyston</a></li> + <li class="foo"><a class="foo" href="#">Adelphi</a></li> + <li class="foo"><a class="foo" href="#">Adena</a></li> + <li class="foo"><a class="foo" href="#">Adrian</a></li> + <li class="foo"><a class="foo" href="#">Akron</a></li> + <li class="foo"><a class="foo" href="#">Albany</a></li> + <li class="foo"><a class="foo" href="#">Alexandria</a></li> + <li class="foo"><a class="foo" href="#">Alger</a></li> + <li class="foo"><a class="foo" href="#">Alledonia</a></li> + <li class="foo"><a class="foo" href="#">Alliance</a></li> + <li class="foo"><a class="foo" href="#">Alpha</a></li> + <li class="foo"><a class="foo" href="#">Alvada</a></li> + <li class="foo"><a class="foo" href="#">Alvordton</a></li> + <li class="foo"><a class="foo" href="#">Amanda</a></li> + <li class="foo"><a class="foo" href="#">Amelia</a></li> + <li class="foo"><a class="foo" href="#">Amesville</a></li> + <li class="foo"><a class="foo" href="#">Aberdeen</a></li> + <li class="foo"><a class="foo" href="#">Ada</a></li> + <li class="foo"><a class="foo" href="#">Adamsville</a></li> + <li class="foo"><a class="foo" href="#">Addyston</a></li> + <li class="foo"><a class="foo" href="#">Adelphi</a></li> + <li class="foo"><a class="foo" href="#">Adena</a></li> + <li class="foo"><a class="foo" href="#">Adrian</a></li> + <li class="foo"><a class="foo" href="#">Akron</a></li> + <li class="foo"><a class="foo" href="#">Albany</a></li> + <li class="foo"><a class="foo" href="#">Alexandria</a></li> + <li class="foo"><a class="foo" href="#">Alger</a></li> + <li class="foo"><a class="foo" href="#">Alledonia</a></li> + <li class="foo"><a class="foo" href="#">Alliance</a></li> + <li class="foo"><a class="foo" href="#">Alpha</a></li> + <li class="foo"><a class="foo" href="#">Alvada</a></li> + <li class="foo"><a class="foo" href="#">Alvordton</a></li> + <li class="foo"><a class="foo" href="#">Amanda</a></li> + <li class="foo"><a class="foo" href="#">Amelia</a></li> + <li class="foo"><a class="foo" href="#">Amesville</a></li> +</ul> + +<div id="menu5"> + <blockquote><a href="#">Aberdeen</a></blockquote> + <blockquote><a href="#">Ada</a></blockquote> + <blockquote><a href="#">Adamsville</a></blockquote> + <blockquote><a href="#">Addyston</a></blockquote> + <blockquote> + <a href="#">Delphi</a> + <div> + <blockquote><a href="#">Ada</a></blockquote> + <blockquote><a href="#">Saarland</a></blockquote> + <blockquote><a href="#">Salzburg</a></blockquote> + </div> + </blockquote> + <blockquote><a href="#">Saarland</a></blockquote> + <blockquote> + <a href="#">Salzburg</a> + <div> + <blockquote> + <a href="#">Delphi</a> + <div> + <blockquote><a href="#">Ada</a></blockquote> + <blockquote><a href="#">Saarland</a></blockquote> + <blockquote><a href="#">Salzburg</a></blockquote> + </div> + </blockquote> + <blockquote> + <a href="#">Delphi</a> + <div> + <blockquote><a href="#">Ada</a></blockquote> + <blockquote><a href="#">Saarland</a></blockquote> + <blockquote><a href="#">Salzburg</a></blockquote> + </div> + </blockquote> + <blockquote><a href="#">Perch</a></blockquote> + </div> + </blockquote> +</div> + +<div id="log"></div> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/menu/menu_core.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/menu/menu_core.js new file mode 100644 index 0000000..c0feae7 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/menu/menu_core.js @@ -0,0 +1,41 @@ +/* + * menu_core.js + */ + + +(function($) { + +module("menu: core"); + +test("accessibility", function () { + expect(5); + var ac = $('#menu1').menu(); + var item0 = $("li:eq(0) a"); + + ok( ac.hasClass("ui-menu ui-widget ui-widget-content ui-corner-all"), "menu class"); + equals( ac.attr("role"), "menu", "main role"); + ok( !ac.attr("aria-activedescendant"), "aria attribute not yet active"); + + var item = ac.find( "li:first" ).find( "a" ).attr( "id", "xid" ).end(); + ac.menu( "focus", $.Event(), item ); + equals( ac.attr("aria-activedescendant"), "xid", "aria attribute, id from dom"); + + var item = ac.find( "li:last" ); + ac.menu( "focus", $.Event(), item ); + equals( ac.attr("aria-activedescendant"), "menu1-4", "aria attribute, generated id"); +}); + +test("items class and role", function () { + var ac = $('#menu1').menu(); + expect(1 + 5 * $("li",ac).length); + ok( ($("li",ac).length > 0 ), "number of menu items"); + $("li",ac).each(function(item) { + ok( $(this).hasClass("ui-menu-item"), "menu item ("+ item + ") class for item"); + equals( $(this).attr("role"), "presentation", "menu item ("+ item + ") role"); + equals( $("a", this).attr("role"), "menuitem", "menu item ("+ item + ") role"); + ok( $("a",this).hasClass("ui-corner-all"), "a element class for menu item ("+ item + ") "); + equals( $("a",this).attr("tabindex"), "-1", "a element tabindex for menu item ("+ item + ") "); + }); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/menu/menu_defaults.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/menu/menu_defaults.js new file mode 100644 index 0000000..a559a3d --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/menu/menu_defaults.js @@ -0,0 +1,14 @@ +commonWidgetTests( "menu", { + defaults: { + disabled: false, + position: { + my: "left top", + at: "right top" + }, + items: "ul", + trigger: null, + + // callbacks + create: null + } +}); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/menu/menu_events.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/menu/menu_events.js new file mode 100644 index 0000000..55ec1e2 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/menu/menu_events.js @@ -0,0 +1,431 @@ +/* + * menu_events.js + */ +(function($) { + +module("menu: events"); + +test("handle click on menu", function() { + expect(1); + var ac = $('#menu1').menu({ + select: function(event, ui) { + menu_log(); + } + }); + menu_log("click",true); + menu_click($('#menu1'),"1"); + menu_log("afterclick"); + menu_click( ac,"2"); + menu_click($('#menu1'),"3"); + menu_click( ac,"1"); + equals( $("#log").html(), "1,3,2,afterclick,1,click,", "Click order not valid."); +}); + +test("handle click on custom item menu", function() { + expect(1); + var ac = $('#menu5').menu({ + select: function(event, ui) { + menu_log(); + }, + items: "div" + }); + menu_log("click",true); + menu_click($('#menu5'),"1"); + menu_log("afterclick"); + menu_click( ac,"2"); + menu_click($('#menu5'),"3"); + menu_click( ac,"1"); + equals( $("#log").html(), "1,3,2,afterclick,1,click,", "Click order not valid."); +}); + +test( "handle blur: click", function() { + expect( 4 ); + var $menu = $( "#menu1" ).menu({ + focus: function( event, ui ) { + equal( event.originalEvent.type, "click", "focus triggered 'click'" ); + equal( event.type, "menufocus", "focus event.type is 'menufocus'" ); + + }, + blur: function( event, ui ) { + equal( event.originalEvent.type, "click", "blur triggered 'click'" ); + equal( event.type, "menublur", "blur event.type is 'menublur'" ); + } + }); + + $menu.find( "li a:first" ).trigger( "click" ); + $( "<a>", { id: "remove"} ).appendTo("body").trigger( "click" ); + + $("#remove").remove(); +}); + +test( "handle blur on custom item menu: click", function() { + expect( 4 ); + var $menu = $( "#menu5" ).menu({ + focus: function( event, ui ) { + equal( event.originalEvent.type, "click", "focus triggered 'click'" ); + equal( event.type, "menufocus", "focus event.type is 'menufocus'" ); + + }, + blur: function( event, ui ) { + equal( event.originalEvent.type, "click", "blur triggered 'click'" ); + equal( event.type, "menublur", "blur event.type is 'menublur'" ); + }, + items: "div" + }); + + menu_click($('#menu5'),"1"); + $( "<a>", { id: "remove"} ).appendTo("body").trigger( "click" ); + + $("#remove").remove(); +}); + +asyncTest( "handle submenu auto collapse: mouseleave", function() { + expect( 4 ); + var $menu = $( "#menu2" ).menu(); + + $menu.find( "li:nth-child(7)" ).trigger( "mouseover" ); + setTimeout(function() { + equal( $menu.find( "ul[aria-expanded='true']" ).length, 1, "first submenu expanded" ); + $menu.find( "li:nth-child(7) li:first" ).trigger( "mouseover" ); + setTimeout(function() { + equal( $menu.find( "ul[aria-expanded='true']" ).length, 2, "second submenu expanded" ); + $menu.find( "ul[aria-expanded='true']:first" ).trigger( "mouseleave" ); + equal( $menu.find( "ul[aria-expanded='true']" ).length, 1, "second submenu collapsed" ); + $menu.trigger( "mouseleave" ); + equal( $menu.find( "ul[aria-expanded='true']" ).length, 0, "first submenu collapsed" ); + start(); + }, 400); + }, 200); +}); + +asyncTest( "handle custom menu item submenu auto collapse: mouseleave", function() { + expect( 5 ); + var $menu = $( "#menu5" ).menu( { items: "div" } ); + + $menu.children( ":nth-child(7)" ).trigger( "mouseover" ); + setTimeout(function() { + equal( $menu.find( "div[aria-expanded='true']" ).length, 1, "first submenu expanded" ); + $menu.children( ":nth-child(7)" ).find( "div:first" ).children( ":first" ).trigger( "mouseover" ); + setTimeout(function() { + equal( $menu.find( "div[aria-expanded='true']" ).length, 2, "second submenu expanded" ); + $menu.find( "div[aria-expanded='true']:first" ).trigger( "mouseleave" ); + equal( $menu.find( "div[aria-expanded='true']" ).length, 1, "second submenu collapsed" ); + + $menu.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN }); + ok( $menu.find( ".ui-state-active" ).is( "#menu5 :nth-child(7) a" ), + "down keypress selected an item from the first submenu" ); + + $menu.trigger( "mouseleave" ); + equal( $menu.find( "div[aria-expanded='true']" ).length, 0, "first submenu collapsed" ); + start(); + }, 400); + }, 200); +}); + + +test("handle keyboard navigation on menu without scroll and without submenus", function() { + expect(12); + var element = $('#menu1').menu({ + select: function(event, ui) { + menu_log($(ui.item[0]).text()); + }, + focus: function( event, ui ) { + menu_log($(event.target).find(".ui-state-focus").parent().index()); + } + }); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); + element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); + equals( $("#log").html(), "1,0,keydown,", "Keydown DOWN"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); + equals( $("#log").html(), "0,keydown,", "Keydown UP"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); + equals( $("#log").html(), "keydown,", "Keydown LEFT (no effect)"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); + equals( $("#log").html(), "keydown,", "Keydown RIGHT (no effect)"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); + equals( $("#log").html(), "4,keydown,", "Keydown PAGE_DOWN"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); + equals( $("#log").html(), "keydown,", "Keydown PAGE_DOWN (no effect)"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); + equals( $("#log").html(), "0,keydown,", "Keydown PAGE_UP"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); + equals( $("#log").html(), "keydown,", "Keydown PAGE_UP (no effect)"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.END } ); + equals( $("#log").html(), "4,keydown,", "Keydown END"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } ); + equals( $("#log").html(), "0,keydown,", "Keydown HOME"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } ); + equals( $("#log").html(), "keydown,", "Keydown ESCAPE (no effect)"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); + equals( $("#log").html(), "Aberdeen,keydown,", "Keydown ENTER"); +}); + +asyncTest("handle keyboard navigation on menu without scroll and with submenus", function() { + expect(14); + var element = $('#menu2').menu({ + select: function(event, ui) { + menu_log($(ui.item[0]).text()); + }, + focus: function( event, ui ) { + menu_log($(event.target).find(".ui-state-focus").parent().index()); + } + }); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); + element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); + equals( $("#log").html(), "1,0,keydown,", "Keydown DOWN"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); + equals( $("#log").html(), "0,keydown,", "Keydown UP"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); + equals( $("#log").html(), "keydown,", "Keydown LEFT (no effect)"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); + element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); + element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); + element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); + element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); + + setTimeout( function() { + equals( $("#log").html(), "0,4,3,2,1,keydown,", "Keydown RIGHT (open submenu)"); + }, 50); + + setTimeout( function() { + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); + equals( $("#log").html(), "4,keydown,", "Keydown LEFT (close submenu)"); + + //re-open submenu + element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); + + setTimeout( function() { + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); + equals( $("#log").html(), "2,keydown,", "Keydown PAGE_DOWN"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); + equals( $("#log").html(), "keydown,", "Keydown PAGE_DOWN (no effect)"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); + equals( $("#log").html(), "0,keydown,", "Keydown PAGE_UP"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); + equals( $("#log").html(), "keydown,", "Keydown PAGE_UP (no effect)"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.END } ); + equals( $("#log").html(), "2,keydown,", "Keydown END"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } ); + equals( $("#log").html(), "0,keydown,", "Keydown HOME"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } ); + equals( $("#log").html(), "4,keydown,", "Keydown ESCAPE (close submenu)"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); + + setTimeout( function() { + equals( $("#log").html(), "0,keydown,", "Keydown ENTER (open submenu)"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); + equals( $("#log").html(), "Ada,keydown,", "Keydown ENTER (select item)"); + + start(); + }, 200); + }, 150); + }, 100); + +}); + +test("handle keyboard navigation on menu with scroll and without submenus", function() { + expect(14); + var element = $('#menu3').menu({ + select: function(event, ui) { + menu_log($(ui.item[0]).text()); + }, + focus: function( event, ui ) { + menu_log($(event.target).find(".ui-state-focus").parent().index()); + } + }); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); + element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); + equals( $("#log").html(), "1,0,keydown,", "Keydown DOWN"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); + equals( $("#log").html(), "0,keydown,", "Keydown UP"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); + equals( $("#log").html(), "keydown,", "Keydown LEFT (no effect)"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); + equals( $("#log").html(), "keydown,", "Keydown RIGHT (no effect)"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); + equals( $("#log").html(), "10,keydown,", "Keydown PAGE_DOWN"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); + equals( $("#log").html(), "20,keydown,", "Keydown PAGE_DOWN"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); + equals( $("#log").html(), "10,keydown,", "Keydown PAGE_UP"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); + equals( $("#log").html(), "0,keydown,", "Keydown PAGE_UP"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); + equals( $("#log").html(), "keydown,", "Keydown PAGE_UP (no effect)"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.END } ); + equals( $("#log").html(), "37,keydown,", "Keydown END"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); + equals( $("#log").html(), "keydown,", "Keydown PAGE_DOWN (no effect)"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } ); + equals( $("#log").html(), "0,keydown,", "Keydown HOME"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } ); + equals( $("#log").html(), "keydown,", "Keydown ESCAPE (no effect)"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); + equals( $("#log").html(), "Aberdeen,keydown,", "Keydown ENTER"); +}); + +asyncTest("handle keyboard navigation on menu with scroll and with submenus", function() { + expect(14); + var element = $('#menu4').menu({ + select: function(event, ui) { + menu_log($(ui.item[0]).text()); + }, + focus: function( event, ui ) { + menu_log($(event.target).find(".ui-state-focus").parent().index()); + } + }); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); + element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); + equals( $("#log").html(), "1,0,keydown,", "Keydown DOWN"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); + equals( $("#log").html(), "0,keydown,", "Keydown UP"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); + equals( $("#log").html(), "keydown,", "Keydown LEFT (no effect)"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN } ); + element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); + + setTimeout( function() { + equals( $("#log").html(), "0,1,keydown,", "Keydown RIGHT (open submenu)"); + }, 50); + + setTimeout( function() { + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ); + equals( $("#log").html(), "1,keydown,", "Keydown LEFT (close submenu)"); + + //re-open submenu + element.simulate( "keydown", { keyCode: $.ui.keyCode.RIGHT } ); + + setTimeout( function() { + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); + equals( $("#log").html(), "10,keydown,", "Keydown PAGE_DOWN"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_DOWN } ); + equals( $("#log").html(), "20,keydown,", "Keydown PAGE_DOWN"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); + equals( $("#log").html(), "10,keydown,", "Keydown PAGE_UP"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.PAGE_UP } ); + equals( $("#log").html(), "0,keydown,", "Keydown PAGE_UP"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.END } ); + equals( $("#log").html(), "27,keydown,", "Keydown END"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.HOME } ); + equals( $("#log").html(), "0,keydown,", "Keydown HOME"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.ESCAPE } ); + equals( $("#log").html(), "1,keydown,", "Keydown ESCAPE (close submenu)"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); + + setTimeout( function() { + equals( $("#log").html(), "0,keydown,", "Keydown ENTER (open submenu)"); + + menu_log("keydown",true); + element.simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ); + equals( $("#log").html(), "Aberdeen,keydown,", "Keydown ENTER (select item)"); + + start(); + }, 200); + }, 150); + }, 100); + +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/menu/menu_methods.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/menu/menu_methods.js new file mode 100644 index 0000000..0ecaf73 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/menu/menu_methods.js @@ -0,0 +1,15 @@ +/* + * menu_methods.js + */ +(function($) { + +module("menu: methods"); + +test("destroy", function() { + domEqual("#menu1", function() { + $("#menu1").menu().menu("destroy"); + }); +}); + + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/menu/menu_options.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/menu/menu_options.js new file mode 100644 index 0000000..03822fd --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/menu/menu_options.js @@ -0,0 +1,10 @@ +/* + * menu_options.js + */ +(function($) { + +module("menu: options"); + + + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/menu/menu_test_helpers.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/menu/menu_test_helpers.js new file mode 100644 index 0000000..e83795e --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/menu/menu_test_helpers.js @@ -0,0 +1,14 @@ +function menu_log( message, clear ) { + if ( clear ) { + $( "#log" ).empty(); + } + if ( message === undefined ) { + message = $( "#log" ).data( "lastItem" ); + } + $( "#log" ).prepend( $.trim( message ) + "," ); +} + +function menu_click( menu, item ) { + $( "#log" ).data( "lastItem", item ); + menu.children( ":eq(" + item + ")" ).find( "a:first" ).trigger( "click" ); +}
\ No newline at end of file diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/position/all.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/position/all.html new file mode 100644 index 0000000..07676f1 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/position/all.html @@ -0,0 +1,30 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Position Test Suite</title> + + <script src="../../../jquery-1.7.1.js"></script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <link rel="stylesheet" href="../subsuiteRunner.css"> + <script src="../../../external/qunit.js"></script> + <script src="../subsuiteRunner.js"></script> + <script src="../subsuite.js"></script> + + <script> + testAllVersions( "position" ); + </script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Position Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/position/position.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/position/position.html new file mode 100644 index 0000000..115adc3 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/position/position.html @@ -0,0 +1,75 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Position Test Suite</title> + + <script src="../../jquery.js"></script> + <script> + $.uiBackCompat = false; + </script> + <script src="../../resource_loader.js"></script> + <script> + loadResources({ + js: [ "ui/jquery.ui.position.js" ] + }); + </script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <script src="../../../external/qunit.js"></script> + <script src="../../jquery.simulate.js"></script> + <script src="../testsuite.js"></script> + + <script src="position_core.js"></script> + <script src="position_core_within.js"></script> + + <script src="../swarminject.js"></script> +</head> +<body> +<div style="position:relative; z-index:2;"> + <h1 id="qunit-header">jQuery UI Position Test Suite</h1> + <h2 id="qunit-banner"></h2> + <div id="qunit-testrunner-toolbar"></div> + <h2 id="qunit-userAgent"></h2> + <ol id="qunit-tests"> + </ol> +</div> + +<!-- +elements smaller than 10px have a line-height set on them to avoid a bug in IE6 +.height() returns the greater of the height and line-height +--> + +<div id="qunit-fixture" style="top: 0; left: 0; z-index:1"> + <div id="within-container"> + <div id="el1" style="position: absolute; width: 6px; height: 6px; line-height: 6px;"></div> + <div id="el2" style="position: absolute; width: 6px; height: 6px; line-height: 6px;"></div> + <div id="parent" style="position: absolute; width: 6px; height: 6px; top: 4px; left: 4px; line-height: 6px;"></div> + + <div style="position: absolute; top: 0px; left: 0px"> + <div id="elx" style="position: absolute; width: 10px; height: 10px; line-height: 10px;"></div> + <div id="parentx" style="position: absolute; width: 20px; height: 20px; top: 40px; left: 40px;"></div> + </div> + + <div style="position: absolute; top: 200px; left: 100px;"> + <div id="el-offset-100-200" style="position: absolute; width: 10px; height: 10px; line-height: 10px;"></div> + <div style="position: absolute; top: 100px; left: 50px;"> + <div id="el-two-offset-150-300" style="position: absolute; width: 10px; height: 10px; line-height: 10px;"></div> + <div id="el-fixed" style="position: fixed; top: 200px; left: 200px;"></div> + </div> + </div> + + <div style="position: absolute; height: 5000px; width: 5000px;"></div> + + <div id="fractions-parent" style="position: absolute; left: 10.7432222px; top: 10.532325px; height: 30px; width: 201px;"> + <div id="fractions-element"></div> + </div> + </div> + + <div id="bug-5280" style="height: 30px; width: 201px;"> + <div style="width: 50px; height: 10px;"></div> + </div> +</div> + +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/position/position_core.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/position/position_core.js new file mode 100644 index 0000000..ea1baee --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/position/position_core.js @@ -0,0 +1,547 @@ +(function( $ ) { + +function scrollTopSupport() { + $( window ).scrollTop( 1 ); + return $( window ).scrollTop() === 1; +} + +module( "position" ); + +test( "my, at, of", function() { + $( "#elx" ).position({ + my: "left top", + at: "left top", + of: "#parentx", + collision: "none" + }); + same( $( "#elx" ).offset(), { top: 40, left: 40 }, "left top, left top" ); + + $( "#elx" ).position({ + my: "left top", + at: "left bottom", + of: "#parentx", + collision: "none" + }); + same( $( "#elx" ).offset(), { top: 60, left: 40 }, "left top, left bottom" ); + + $( "#elx" ).position({ + my: "left", + at: "bottom", + of: "#parentx", + collision: "none" + }); + same( $( "#elx" ).offset(), { top: 55, left: 50 }, "left, bottom" ); + + $( "#elx" ).position({ + my: "left foo", + at: "bar baz", + of: "#parentx", + collision: "none" + }); + same( $( "#elx" ).offset(), { top: 45, left: 50 }, "left foo, bar baz" ); +}); + +test( "multiple elements", function() { + var elements = $( "#el1, #el2" ); + var result = elements.position({ + my: "left top", + at: "left bottom", + of: "#parent", + collision: "none" + }); + + same( result, elements ); + var expected = { top: 10, left: 4 }; + elements.each(function() { + same( $( this ).offset(), expected ); + }); +}); + +test( "positions", function() { + var definitions = []; + var offsets = { + left: 0, + center: 3, + right: 6, + top: 0, + bottom: 6 + }; + var start = { left: 4, top: 4 }; + $.each( [ 0, 1 ], function( my ) { + $.each( [ "top", "center", "bottom" ], function( vindex, vertical ) { + $.each( [ "left", "center", "right" ], function( hindex, horizontal ) { + definitions.push({ + my: my ? horizontal + " " + vertical : "left top", + at: !my ? horizontal + " " + vertical : "left top", + result: { + top: my ? start.top - offsets[ vertical ] : start.top + offsets[ vertical ], + left: my ? start.left - offsets[ horizontal ] : start.left + offsets[ horizontal ] + } + }); + }); + }); + }); + var el = $( "#el1" ); + $.each( definitions, function( index, definition ) { + el.position({ + my: definition.my, + at: definition.at, + of: "#parent", + collision: "none" + }); + same( el.offset(), definition.result, + "Position via " + QUnit.jsDump.parse({ my:definition.my, at:definition.at }) ); + }); +}); + +test( "of", function() { + $( "#elx" ).position({ + my: "left top", + at: "left top", + of: "#parentx", + collision: "none" + }); + same( $( "#elx" ).offset(), { top: 40, left: 40 }, "selector" ); + + $( "#elx" ).position({ + my: "left top", + at: "left bottom", + of: $( "#parentx"), + collision: "none" + }); + same( $( "#elx" ).offset(), { top: 60, left: 40 }, "jQuery object" ); + + $( "#elx" ).position({ + my: "left top", + at: "left top", + of: $( "#parentx" )[ 0 ], + collision: "none" + }); + same( $( "#elx" ).offset(), { top: 40, left: 40 }, "DOM element" ); + + $( "#elx" ).position({ + my: "right bottom", + at: "right bottom", + of: document, + collision: "none" + }); + same( $( "#elx" ).offset(), { + top: $( document ).height() - 10, + left: $( document ).width() - 10 + }, "document" ); + + $( "#elx" ).position({ + my: "right bottom", + at: "right bottom", + of: $( document ), + collision: "none" + }); + same( $( "#elx" ).offset(), { + top: $( document ).height() - 10, + left: $( document ).width() - 10 + }, "document as jQuery object" ); + + $( window ).scrollTop( 0 ); + + $( "#elx" ).position({ + my: "right bottom", + at: "right bottom", + of: window, + collision: "none" + }); + same( $( "#elx" ).offset(), { + top: $( window ).height() - 10, + left: $( window ).width() - 10 + }, "window" ); + + $( "#elx" ).position({ + my: "right bottom", + at: "right bottom", + of: $( window ), + collision: "none" + }); + same( $( "#elx" ).offset(), { + top: $( window ).height() - 10, + left: $( window ).width() - 10 + }, "window as jQuery object" ); + + if ( scrollTopSupport() ) { + $( window ).scrollTop( 500 ).scrollLeft( 200 ); + $( "#elx" ).position({ + my: "right bottom", + at: "right bottom", + of: window, + collision: "none" + }); + same( $( "#elx" ).offset(), { + top: $( window ).height() + 500 - 10, + left: $( window ).width() + 200 - 10 + }, "window, scrolled" ); + $( window ).scrollTop( 0 ).scrollLeft( 0 ); + } + + var event = $.extend( $.Event( "someEvent" ), { pageX: 200, pageY: 300 } ); + $( "#elx" ).position({ + my: "left top", + at: "left top", + of: event, + collision: "none" + }); + same( $( "#elx" ).offset(), { + top: 300, + left: 200 + }, "event - left top, left top" ); + + event = $.extend( $.Event( "someEvent" ), { pageX: 400, pageY: 600 } ); + $( "#elx" ).position({ + my: "left top", + at: "right bottom", + of: event, + collision: "none" + }); + same( $( "#elx" ).offset(), { + top: 600, + left: 400 + }, "event - left top, right bottom" ); +}); + +test( "offsets", function() { + $( "#elx" ).position({ + my: "left top", + at: "left+10 bottom+10", + of: "#parentx", + collision: "none" + }); + same( $( "#elx" ).offset(), { top: 70, left: 50 }, "offsets in at" ); + + $( "#elx" ).position({ + my: "left+10 top-10", + at: "left bottom", + of: "#parentx", + collision: "none" + }); + same( $( "#elx" ).offset(), { top: 50, left: 50 }, "offsets in my" ); + + $( "#elx" ).position({ + my: "left top", + at: "left+50% bottom-10%", + of: "#parentx", + collision: "none" + }); + same( $( "#elx" ).offset(), { top: 58, left: 50 }, "percentage offsets in at" ); + + $( "#elx" ).position({ + my: "left-30% top+50%", + at: "left bottom", + of: "#parentx", + collision: "none" + }); + same( $( "#elx" ).offset(), { top: 65, left: 37 }, "percentage offsets in my" ); +}); + +test( "using", function() { + expect( 6 ); + + var count = 0, + elems = $( "#el1, #el2" ), + expectedPosition = { top: 40, left: 40 }, + originalPosition = elems.position({ + my: "right bottom", + at: "rigt bottom", + of: "#parentx", + collision: "none" + }).offset(); + + elems.position({ + my: "left top", + at: "left top", + of: "#parentx", + using: function( position ) { + same( this, elems[ count ], "correct context for call #" + count ); + same( position, expectedPosition, "correct position for call #" + count ); + count++; + } + }); + + elems.each(function() { + same( $( this ).offset(), originalPosition, "elements not moved" ); + }); +}); + +function collisionTest( config, result, msg ) { + var elem = $( "#elx" ).position( $.extend({ + my: "left top", + at: "right bottom", + of: window + }, config ) ); + same( elem.offset(), result, msg ); +} + +function collisionTest2( config, result, msg ) { + collisionTest( $.extend({ + my: "right bottom", + at: "left top" + }, config ), result, msg ); +} + +test( "collision: fit, no offset", function() { + collisionTest({ + collision: "fit" + }, { top: $( window ).height() - 10, left: $( window ).width() - 10 }, "right bottom" ); + + collisionTest2({ + collision: "fit" + }, { top: 0, left: 0 }, "left top" ); +}); + +test( "collision: fit, with offset", function() { + collisionTest({ + collision: "fit", + at: "right+2 bottom+3" + }, { top: $(window).height() - 10, left: $(window).width() - 10 }, "right bottom"); + + collisionTest2({ + collision: "fit", + at: "left+2 top+3" + }, { top: 0, left: 0 }, "left top, positive offset" ); + + collisionTest2({ + collision: "fit", + at: "left-2 top-3" + }, { top: 0, left: 0 }, "left top, negative offset" ); +}); + +test( "collision: fit, window scrolled", function() { + if ( scrollTopSupport() ) { + var win = $( window ); + win.scrollTop( 300 ).scrollLeft( 200 ); + + collisionTest({ + collision: "fit", + at: "left-100 top-100" + }, { top: 300, left: 200 }, "top left" ); + collisionTest2({ + collision: "fit", + at: "right+100 bottom+100" + }, { top: 300 + win.height() - 10, left: 200 + win.width() - 10 }, "right bottom" ); + + win.scrollTop( 0 ).scrollLeft( 0 ); + } +}); + +test( "collision: flip, no offset", function() { + collisionTest({ + collision: "flip" + }, { top: $( window ).height(), left: $( window ).width() }, "left top" ); + + collisionTest2({ + collision: "flip" + }, { top: -10, left: -10 }, "right bottom" ); +}); + +test( "collision: flip, with offset", function() { + collisionTest({ + collision: "flip", + at: "right+2 bottom+3" + }, { top: $( window ).height() + 3, left: $( window ).width() + 2 }, "left top, with offset added" ); + + collisionTest2({ + collision: "flip", + at: "left+2 top+3" + }, { top: -7, left: -8 }, "bottom, positive offset" ); + + collisionTest2({ + collision: "flip", + at: "left-2 top-3" + }, { top: -13, left: -12 }, "right bottom, negative offset" ); +}); + +test( "collision: none, no offset", function() { + collisionTest({ + collision: "none" + }, { top: $( window ).height(), left: $( window ).width() }, "left top" ); + + collisionTest2({ + collision: "none" + }, { top: -10, left: -10 }, "moved to the right bottom" ); +}); + +test( "collision: none, with offset", function() { + collisionTest({ + collision: "none", + at: "right+2 bottom+3" + }, { top: $( window ).height() + 3, left: $( window ).width() + 2 }, "right bottom, with offset added" ); + + collisionTest2({ + collision: "none", + at: "left+2 top+3" + }, { top: -7, left: -8 }, "left top, positive offset" ); + + collisionTest2({ + collision: "none", + at: "left-2 top-3" + }, { top: -13, left: -12 }, "left top, negative offset" ); +}); + +test( "collision: fit, with margin", function() { + $( "#elx" ).css( "margin", 10 ); + + collisionTest({ + collision: "fit" + }, { top: $( window ).height() - 20, left: $( window ).width() - 20 }, "right bottom" ); + + collisionTest2({ + collision: "fit" + }, { top: 10, left: 10 }, "left top" ); + + $( "#elx" ).css({ + "margin-left": 5, + "margin-top": 5 + }); + + collisionTest({ + collision: "fit" + }, { top: $( window ).height() - 20, left: $( window ).width() - 20 }, "right bottom" ); + + collisionTest2({ + collision: "fit" + }, { top: 5, left: 5 }, "left top" ); + + $( "#elx" ).css({ + "margin-right": 15, + "margin-bottom": 15 + }); + + collisionTest({ + collision: "fit" + }, { top: $( window ).height() - 25, left: $( window ).width() - 25 }, "right bottom" ); + + collisionTest2({ + collision: "fit" + }, { top: 5, left: 5 }, "left top" ); +}); + +test( "collision: flip, with margin", function() { + $( "#elx" ).css( "margin", 10 ); + + collisionTest({ + collision: "flip", + at: "left top" + }, { top: 0, left: 0 }, "left top" ); + + collisionTest2({ + collision: "flip", + at: "right bottom" + }, { top: $( window ).height() - 10, left: $( window ).width() - 10 }, "right bottom" ); +}); + +test( "addClass: flipped left", function() { + var elem = $( "#elx" ).position( { + my: "left center", + of: window, + collision: "flip", + at: "right center" + }); + + same( elem.hasClass( 'ui-flipped-left' ), false, 'Has ui-flipped-left class' ); + + elem.position( { + my: "right center", + of: window, + collision: "flip", + at: "left center" + }) + + same( elem.hasClass( 'ui-flipped-left' ), false, 'Removed ui-flipped-left class' ); +}); + +test( "addClass: flipped top", function() { + var elem = $( "#elx" ).position( { + my: "left top", + of: window, + collision: "flip", + at: "right bottom" + }); + + same( elem.hasClass( 'ui-flipped-top' ), false, 'Has ui-flipped-top class' ); + + elem.position( { + my: "left bottom", + of: window, + collision: "flip", + at: "right top" + }); + + same( elem.hasClass( 'ui-flipped-top' ), false, 'Removed ui-flipped-top class' ); +}); + +test( "addClass: flipped right", function() { + var elem = $( "#elx" ).position( { + my: "right center", + of: window, + collision: "flip", + at: "left center" + }); + + same( elem.hasClass( 'ui-flipped-right' ), false, 'Has ui-flipped-right class' ); + + elem.position( { + my: "left center", + of: window, + collision: "flip", + at: "right center" + }); + + same( elem.hasClass( 'ui-flipped-right' ), false, 'Removed ui-flipped-right class' ); + +}); + +test( "addClass: flipped bottom", function() { + var elem = $( "#elx" ).position( { + my: "left bottom", + of: window, + collision: "flip", + at: "right top" + }); + + same( elem.hasClass( 'ui-flipped-bottom' ), false, 'Has ui-flipped-bottom class' ); + + elem.position( { + my: "left top", + of: window, + collision: "flip", + at: "right bottom" + }); + + same( elem.hasClass( 'ui-flipped-bottom' ), false, 'Removed ui-flipped-bottom class' ); +}); + +test( "fractions", function() { + $( "#fractions-element" ).position({ + my: "left top", + at: "left top", + of: "#fractions-parent", + collision: "none" + }); + same( $( "#fractions-element" ).offset(), $( "#fractions-parent" ).offset(), "left top, left top" ); +}); + +test( "bug #5280: consistent results (avoid fractional values)", function() { + var wrapper = $( "#bug-5280" ), + elem = wrapper.children(), + offset1 = elem.position({ + my: "center", + at: "center", + of: wrapper, + collision: "none" + }).offset(), + offset2 = elem.position({ + my: "center", + at: "center", + of: wrapper, + collision: "none" + }).offset(); + same( offset1, offset2 ); +}); + +}( jQuery ) ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/position/position_core_within.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/position/position_core_within.js new file mode 100644 index 0000000..392e409 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/position/position_core_within.js @@ -0,0 +1,545 @@ +(function( $ ) { + +function scrollTopSupport() { + $( window ).scrollTop( 1 ); + return $( window ).scrollTop() === 1; +} + +module( "position - within", { + setup: function(){ + $("#within-container").css({"width": "70px", "height": "70px", "top": "20px", "left": "20px", "position": "relative"}).show(); + } +}); + +var addTop = -20, + addLeft = -20; + +$.fn.addOffsets = function() { + var elOffset = this.offset(), + offset = $("#within-container").offset(); + + elOffset.top -= offset.top; + elOffset.left -= offset.left; + + return {top: elOffset.top - offset.top, left: elOffset.left - offset.left }; +}; + +test( "my, at, of", function() { + var within = $("#within-container"); + + $( "#elx" ).position({ + my: "left top", + at: "left top", + of: "#parentx", + collision: "none", + within: within + }); + same( $( "#elx" ).addOffsets(), { top: addTop + 40, left: addLeft + 40 }, "left top, left top" ); + + $( "#elx" ).position({ + my: "left top", + at: "left bottom", + of: "#parentx", + collision: "none", + within: within + }); + same( $( "#elx" ).addOffsets(), { top: addTop + 60, left: addLeft + 40 }, "left top, left bottom" ); + + $( "#elx" ).position({ + my: "left", + at: "bottom", + of: "#parentx", + collision: "none", + within: within + }); + same( $( "#elx" ).addOffsets(), { top: addTop + 55, left: addLeft + 50 }, "left, bottom" ); + + $( "#elx" ).position({ + my: "left foo", + at: "bar baz", + of: "#parentx", + collision: "none", + within: within + }); + same( $( "#elx" ).addOffsets(), { top: addTop + 45, left: addLeft +50 }, "left foo, bar baz" ); +}); + +test( "multiple elements", function() { + var elements = $( "#el1, #el2" ); + var result = elements.position({ + my: "left top", + at: "left bottom", + of: "#parent", + collision: "none", + within: $("#within-container") + }); + + same( result, elements ); + var expected = { top: addTop + 10, left: addLeft + 4 }; + elements.each(function() { + same( $( this ).addOffsets(), expected ); + }); +}); + +test( "positions", function() { + var definitions = []; + var offsets = { + left: 0, + center: 3, + right: 6, + top: 0, + bottom: 6 + }; + var start = { left: 4, top: 4 }; + $.each( [ 0, 1 ], function( my ) { + $.each( [ "top", "center", "bottom" ], function( vindex, vertical ) { + $.each( [ "left", "center", "right" ], function( hindex, horizontal ) { + definitions.push({ + my: my ? horizontal + " " + vertical : "left top", + at: !my ? horizontal + " " + vertical : "left top", + result: { + top: addTop + (my ? start.top - offsets[ vertical ] : start.top + offsets[ vertical ]), + left: addLeft + (my ? start.left - offsets[ horizontal ] : start.left + offsets[ horizontal ]) + } + }); + }); + }); + }); + var el = $( "#el1" ); + $.each( definitions, function( index, definition ) { + el.position({ + my: definition.my, + at: definition.at, + of: "#parent", + collision: "none", + within: $("#within-container") + }); + same( el.addOffsets(), definition.result, + "Position via " + QUnit.jsDump.parse({ my:definition.my, at:definition.at }) ); + }); +}); + +test( "of", function() { + var within = $("#within-container"); + + $( "#elx" ).position({ + my: "left top", + at: "left top", + of: "#parentx", + collision: "none", + within: within + }); + same( $( "#elx" ).addOffsets(), { top: addTop + 40, left: addLeft + 40 }, "selector" ); + + $( "#elx" ).position({ + my: "left top", + at: "left bottom", + of: $( "#parentx"), + collision: "none", + within: within + }); + same( $( "#elx" ).addOffsets(), { top: addTop + 60, left: addLeft + 40 }, "jQuery object" ); + + $( "#elx" ).position({ + my: "left top", + at: "left top", + of: $( "#parentx" )[ 0 ], + collision: "none", + within: within + }); + same( $( "#elx" ).addOffsets(), { top: addTop + 40, left: addLeft + 40 }, "DOM element" ); + + var event = $.extend( $.Event( "someEvent" ), { pageX: 200, pageY: 300 } ); + $( "#elx" ).position({ + my: "left top", + at: "left top", + of: event, + collision: "none", + within: within + }); + same( $( "#elx" ).offset(), { + top: 300, + left: 200 + }, "event - left top, left top" ); + + event = $.extend( $.Event( "someEvent" ), { pageX: 400, pageY: 600 } ); + $( "#elx" ).position({ + my: "left top", + at: "right bottom", + of: event, + collision: "none", + within: within + }); + same( $( "#elx" ).offset(), { + top: 600, + left: 400 + }, "event - left top, right bottom" ); +}); + +test( "within:offsets", function() { + var within = $("#within-container"); + + $( "#elx" ).position({ + my: "left top", + at: "left+10 bottom+10", + of: "#parentx", + collision: "none", + within: within + }); + same( $( "#elx" ).addOffsets(), { top: addTop + 70, left: addLeft + 50 }, "offsets in at" ); + + $( "#elx" ).position({ + my: "left+10 top-10", + at: "left bottom", + of: "#parentx", + collision: "none", + within: within + }); + same( $( "#elx" ).addOffsets(), { top: addTop + 50, left: addLeft + 50 }, "offsets in my" ); + + $( "#elx" ).position({ + my: "left top", + at: "left+50% bottom-10%", + of: "#parentx", + collision: "none", + within: within + }); + same( $( "#elx" ).addOffsets(), { top: addTop + 58, left: addLeft + 50 }, "percentage offsets in at" ); + + $( "#elx" ).position({ + my: "left-30% top+50%", + at: "left bottom", + of: "#parentx", + collision: "none", + within: within + }); + same( $( "#elx" ).addOffsets(), { top: addTop + 65, left: addLeft + 37 }, "percentage offsets in my" ); +}); + +test( "using", function() { + expect( 6 ); + + var within = $("#within-container"); + + var count = 0, + elems = $( "#el1, #el2" ), + expectedPosition = { top: addTop + 40, left: addLeft + 40 }, + originalPosition = elems.position({ + my: "right bottom", + at: "right bottom", + of: "#parentx", + collision: "none", + within: within + }).addOffsets(); + + elems.position({ + my: "left top", + at: "left top", + of: "#parentx", + using: function( position ) { + position.top -= within.offset().top; + position.left -= within.offset().left; + same( this, elems[ count ], "correct context for call #" + count ); + same( position, expectedPosition, "correct position for call #" + count ); + count++; + }, + within: within + }); + + elems.each(function() { + same( $( this ).addOffsets(), originalPosition, "elements not moved" ); + }); +}); + +function collisionTest( config, result, msg ) { + var within = $("#within-container"); + + var elem = $( "#elx" ).position( $.extend({ + my: "left top", + at: "right bottom", + of: "#parentx", + within: within + }, config ) ); + + same( elem.addOffsets(), result, msg ); +} + +function collisionTest2( config, result, msg ) { + collisionTest( $.extend({ + my: "right bottom", + at: "left top" + }, config ), result, msg ); +} + +test( "collision: fit, no offset", function() { + var within = $("#within-container"), + of = $("#parentx"); + + collisionTest({ + collision: "fit" + }, { top: addTop + of.position().top + of.height() - $.position.getScrollInfo( within ).height, left: addLeft + of.position().left + of.width() - $.position.getScrollInfo( within ).width }, "right bottom" ); + + collisionTest2({ + collision: "fit" + }, { top: addTop + of.position().top - 10, left: addLeft + of.position().left - 10 }, "left top" ); +}); + + +test( "collision: fit, with offset", function() { + var within = $("#within-container"), + of = $("#parentx"); + + collisionTest({ + collision: "fit", + at: "right+2 bottom+3" + }, { top: addTop + of.position().top + of.height() - $.position.getScrollInfo( within ).height, left: addLeft + of.position().left + of.width() - $.position.getScrollInfo( within ).width }, "right bottom"); + + collisionTest2({ + collision: "fit", + at: "left+2 top+3" + }, { top: addTop + of.position().top - 7, left: addLeft + of.position().left - 8 }, "left top, positive offset" ); + + collisionTest2({ + collision: "fit", + at: "left-2 top-3" + }, { top: addTop + of.position().top - 13, left: addLeft + of.position().left - 12 }, "left top, negative offset" ); +}); + +test( "collision: none, within scrolled", function() { + if ( scrollTopSupport() ) { + var within = $("#within-container").css({"width": "1000px", "height": "800px", "overflow": "auto"}), + of = $("#parentx"); + within.scrollTop( 300 ).scrollLeft( 150 ); + + collisionTest({ + collision: "none", + at: "left-100 top-100" + }, { top: of.offset().top + addTop - 100 - of.height(), left: of.offset().left + addLeft - 100 - of.width() }, "top left" ); + collisionTest2({ + collision: "none", + at: "right+100 bottom+100" + }, { top: of.offset().top + addTop + 100 - 10, left: of.offset().left + addLeft + 100 - 10 }, "right bottom" ); + within.scrollTop( 0 ).scrollLeft( 0 ); + } +}); + +test( "collision: flip, no offset", function() { + var within = $("#within-container"), + of = $("#parentx"); + + collisionTest({ + collision: "flip" + }, { top: addTop + of.position().top + of.height(), left: addLeft + of.position().left + of.width() }, "left top" ); + + collisionTest2({ + collision: "flip" + }, { top: addTop + of.position().top - 10, left: addTop + of.position().top - 10 }, "right bottom" ); +}); + +test( "collision: flip, with offset", function() { + var within = $("#within-container"), + of = $("#parentx"); + + collisionTest({ + collision: "flip", + at: "right+2 bottom+3" + }, { top: addTop + of.position().top - 13, left: addLeft + of.position().left - 12 }, "left top, with offset added" ); + + collisionTest2({ + collision: "flip", + at: "left+2 top+3" + }, { top: addTop + of.position().top - 10 + 3, left: addLeft + of.position().left - 10 + 2 }, "right bottom, positive offset" ); + + collisionTest2({ + collision: "flip", + at: "left-2 top-3" + }, { top: addTop + of.position().top - 13, left: addLeft + of.position().left - 12 }, "right bottom, negative offset" ); +}); + +test( "collision: none, no offset", function() { + var within = $("#within-container"), + of = $("#parentx"); + + collisionTest({ + collision: "none" + }, { top: addTop + of.position().top + of.height(), left: addLeft + of.position().left + of.width() }, "left top" ); + + collisionTest2({ + collision: "none" + }, { top: addTop + of.position().top - 10, left: addLeft + of.position().left - 10 }, "right bottom" ); +}); + +test( "collision: none, with offset", function() { + var within = $("#within-container"), + of = $("#parentx"); + + collisionTest({ + collision: "none", + at: "right+2 bottom+3" + }, { top: addTop + of.position().top + of.height() + 3, left: addLeft + of.position().left + of.width() + 2 }, "right bottom, with offset added" ); + + collisionTest2({ + collision: "none", + at: "left+2 top+3" + }, { top: addTop + of.position().top - 7, left: addTop + of.position().top - 8 }, "left top, positive offset" ); + + collisionTest2({ + collision: "none", + at: "left-2 top-3" + }, { top: addTop + of.position().top - 13, left: addTop + of.position().top - 12 }, "left top, negative offset" ); +}); + +test( "collision: fit, with margin", function() { + var within = $("#within-container"), + of = $("#parentx"); + + $( "#elx" ).css( "margin", 10 ); + + collisionTest({ + collision: "fit" + }, { top: addTop + of.position().top + of.height() - 10 - $.position.getScrollInfo( within ).height, left: addLeft + of.position().left + of.width() - 10 - $.position.getScrollInfo( within ).width }, "right bottom" ); + + collisionTest2({ + collision: "fit" + }, { top: addTop + of.position().top - 10, left: addLeft + of.position().left - 10 }, "left top" ); + + $( "#elx" ).css({ + "margin-left": 5, + "margin-top": 5 + }); + + collisionTest({ + collision: "fit" + }, { top: addTop + of.position().top + of.height() - 10 - $.position.getScrollInfo( within ).height, left: addLeft + of.position().left + of.width() - 10 - $.position.getScrollInfo( within ).width }, "right bottom" ); + + collisionTest2({ + collision: "fit" + }, { top: addTop + of.position().top - 10, left: addLeft + of.position().left - 10 }, "left top" ); + + $( "#elx" ).css({ + "margin-right": 15, + "margin-bottom": 15 + }); + + collisionTest({ + collision: "fit" + }, { top: addTop + of.position().top + of.height() - 15 - $.position.getScrollInfo( within ).height, left: addLeft + of.position().left + of.width() - 15 - $.position.getScrollInfo( within ).width }, "right bottom" ); + + collisionTest2({ + collision: "fit" + }, { top: addTop + of.position().top - 10, left: addLeft + of.position().left - 10 }, "left top" ); +}); + +test( "collision: flip, with margin", function() { + var within = $("#within-container"), + of = $("#parentx"); + + $( "#elx" ).css( "margin", 10 ); + + collisionTest({ + collision: "flip" + }, { top: addTop + of.position().top - 10, left: addLeft + of.position().left - 10 }, "left top" ); + + collisionTest2({ + collision: "flip" + }, { top: addTop + of.position().top - 10, left: addLeft + of.position().left - 10 }, "right bottom" ); + + $( "#elx" ).css( "margin", 0 ); +}); + +test( "addClass: flipped left", function() { + var within = $("#within-container"); + + var elem = $( "#elx" ).position( { + my: "left center", + of: within[0], + within: within, + collision: "flip", + at: "right center" + }); + + same( elem.hasClass( 'ui-flipped-left' ), false, 'Has ui-flipped-left class' ); + + elem.position( { + my: "right center", + of: within[0], + within: within, + collision: "flip", + at: "left center" + }) + + same( elem.hasClass( 'ui-flipped-left' ), false, 'Removed ui-flipped-left class' ); +}); + +test( "addClass: flipped top", function() { + var within = $("#within-container"); + + var elem = $( "#elx" ).position( { + my: "left top", + of: within[0], + within: within, + collision: "flip", + at: "right bottom" + }); + + same( elem.hasClass( 'ui-flipped-top' ), false, 'Has ui-flipped-top class' ); + + elem.position( { + my: "left bottom", + of: within[0], + within: within, + collision: "flip", + at: "right top" + }); + + same( elem.hasClass( 'ui-flipped-top' ), false, 'Removed ui-flipped-top class' ); +}); + +test( "addClass: flipped right", function() { + var within = $("#within-container"); + + var elem = $( "#elx" ).position( { + my: "right center", + of: within[0], + within: within, + collision: "flip", + at: "left center" + }); + + same( elem.hasClass( 'ui-flipped-right' ), false, 'Has ui-flipped-right class' ); + + elem.position( { + my: "left center", + of: within[0], + within: within, + collision: "flip", + at: "right center" + }); + + same( elem.hasClass( 'ui-flipped-right' ), false, 'Removed ui-flipped-right class' ); + +}); + +test( "addClass: flipped bottom", function() { + var within = $("#within-container"); + + var elem = $( "#elx" ).position( { + my: "left bottom", + of: window, + collision: "flip", + at: "right top" + }); + + same( elem.hasClass( 'ui-flipped-bottom' ), false, 'Has ui-flipped-bottom class' ); + + elem.position( { + my: "left top", + of: window, + collision: "flip", + at: "right bottom" + }); + + same( elem.hasClass( 'ui-flipped-bottom' ), false, 'Removed ui-flipped-bottom class' ); +}); + +}( jQuery ) ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/position/position_deprecated.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/position/position_deprecated.html new file mode 100644 index 0000000..ee9be18 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/position/position_deprecated.html @@ -0,0 +1,68 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Position Test Suite</title> + + <script src="../../jquery.js"></script> + <script src="../../resource_loader.js"></script> + <script> + loadResources({ + js: [ "ui/jquery.ui.position.js" ] + }); + </script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <script src="../../../external/qunit.js"></script> + <script src="../../jquery.simulate.js"></script> + <script src="../testsuite.js"></script> + + <script src="position_core.js"></script> + <script src="position_deprecated.js"></script> + + <script src="../swarminject.js"></script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Position Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> + +<!-- +elements smaller than 10px have a line-height set on them to avoid a bug in IE6 +.height() returns the greater of the height and line-height +--> + +<div id="qunit-fixture" style="top: 0; left: 0;"> + <div id="el1" style="position: absolute; width: 6px; height: 6px; line-height: 6px;"></div> + <div id="el2" style="position: absolute; width: 6px; height: 6px; line-height: 6px;"></div> + <div id="parent" style="position: absolute; width: 6px; height: 6px; top: 4px; left: 4px; line-height: 6px;"></div> +</div> + +<div style="position: absolute; top: 0px; left: 0px"> + <div id="elx" style="position: absolute; width: 10px; height: 10px; line-height: 10px;"></div> + <div id="parentx" style="position: absolute; width: 20px; height: 20px; top: 40px; left: 40px;"></div> +</div> + +<div style="position: absolute; top: 200px; left: 100px;"> + <div id="el-offset-100-200" style="position: absolute; width: 10px; height: 10px; line-height: 10px;"></div> + <div style="position: absolute; top: 100px; left: 50px;"> + <div id="el-two-offset-150-300" style="position: absolute; width: 10px; height: 10px; line-height: 10px;"></div> + <div id="el-fixed" style="position: fixed; top: 200px; left: 200px;"></div> + </div> +</div> + +<div style="position: absolute; height: 5000px; width: 5000px;"></div> + +<div id="bug-5280" style="height: 30px; width: 201px;"> + <div style="width: 50px; height: 10px;"></div> +</div> + +<div id="fractions-parent" style="position: absolute; left: 10.7432222px; top: 10.532325px; height: 30px; width: 201px;"> + <div id="fractions-element"></div> +</div> + +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/position/position_deprecated.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/position/position_deprecated.js new file mode 100644 index 0000000..3e72c4a --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/position/position_deprecated.js @@ -0,0 +1,32 @@ +(function( $ ) { + +test( "offset", function() { + $( "#elx" ).position({ + my: "left top", + at: "left bottom", + of: "#parentx", + offset: "10", + collision: "none" + }); + same( $( "#elx" ).offset(), { top: 70, left: 50 }, "single value" ); + + $( "#elx" ).position({ + my: "left top", + at: "left bottom", + of: "#parentx", + offset: "5 -3", + collision: "none" + }); + same( $( "#elx" ).offset(), { top: 57, left: 45 }, "two values" ); + + $( "#elx" ).position({ + my: "left top", + at: "left bottom", + of: "#parentx", + offset: "5px -3px", + collision: "none" + }); + same( $( "#elx" ).offset(), { top: 57, left: 45 }, "with units" ); +}); + +}( jQuery ) ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/progressbar/all.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/progressbar/all.html new file mode 100644 index 0000000..52c1950 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/progressbar/all.html @@ -0,0 +1,30 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Progressbar Test Suite</title> + + <script src="../../../jquery-1.7.1.js"></script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <link rel="stylesheet" href="../subsuiteRunner.css"> + <script src="../../../external/qunit.js"></script> + <script src="../subsuiteRunner.js"></script> + <script src="../subsuite.js"></script> + + <script> + testAllVersions( "progressbar" ); + </script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Progressbar Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/progressbar/progressbar.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/progressbar/progressbar.html new file mode 100644 index 0000000..8b55f5a --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/progressbar/progressbar.html @@ -0,0 +1,46 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Progressbar Test Suite</title> + + <script src="../../jquery.js"></script> + <script src="../../resource_loader.js"></script> + <script> + loadResources({ + css: [ "ui.core", "ui.progressbar" ], + js: [ + "ui/jquery.ui.core.js", + "ui/jquery.ui.widget.js", + "ui/jquery.ui.progressbar.js" + ] + }); + </script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <script src="../../../external/qunit.js"></script> + <script src="../../jquery.simulate.js"></script> + <script src="../testsuite.js"></script> + + <script src="progressbar_core.js"></script> + <script src="progressbar_defaults.js"></script> + <script src="progressbar_events.js"></script> + <script src="progressbar_methods.js"></script> + <script src="progressbar_options.js"></script> + + <script src="../swarminject.js"></script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Progressbar Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +<div id="progressbar"></div> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/progressbar/progressbar_core.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/progressbar/progressbar_core.js new file mode 100644 index 0000000..a499d85 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/progressbar/progressbar_core.js @@ -0,0 +1,28 @@ +/* + * progressbar_core.js + */ + +var el; + +(function($) { + +module("progressbar: core"); + +test("accessibility", function() { + expect(7); + el = $("#progressbar").progressbar(); + + equals(el.attr("role"), "progressbar", "aria role"); + equals(el.attr("aria-valuemin"), 0, "aria-valuemin"); + equals(el.attr("aria-valuemax"), 100, "aria-valuemax"); + equals(el.attr("aria-valuenow"), 0, "aria-valuenow initially"); + el.progressbar("value", 77); + equals(el.attr("aria-valuenow"), 77, "aria-valuenow"); + el.progressbar("disable"); + equals(el.attr("aria-disabled"), "true", "aria-disabled on"); + el.progressbar("enable"); + // FAIL: for some reason IE6 and 7 return a boolean false instead of the string + equals(el.attr("aria-disabled"), "false", "aria-disabled off"); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/progressbar/progressbar_defaults.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/progressbar/progressbar_defaults.js new file mode 100644 index 0000000..3856e31 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/progressbar/progressbar_defaults.js @@ -0,0 +1,10 @@ +commonWidgetTests( "progressbar", { + defaults: { + disabled: false, + value: 0, + max: 100, + + //callbacks + create: null + } +}); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/progressbar/progressbar_events.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/progressbar/progressbar_events.js new file mode 100644 index 0000000..585c090 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/progressbar/progressbar_events.js @@ -0,0 +1,51 @@ +/* + * progressbar_events.js + */ +(function($) { + +module("progressbar: events"); + +test("create", function() { + expect(1); + $("#progressbar").progressbar({ + value: 5, + create: function() { + same(5, $(this).progressbar("value") ); + }, + change: function() { + ok(false, 'create() has triggered change()'); + } + }) +}); + +test("change", function() { + expect(1); + $("#progressbar").progressbar({ + change: function() { + same( 5, $(this).progressbar("value") ); + } + }).progressbar("value", 5); +}); + +test( "complete", function() { + expect( 3 ); + var changes = 0, + value; + + $( "#progressbar" ).progressbar({ + change: function() { + changes++; + same( $( this ).progressbar( "value" ), value, "change at " + value ); + }, + complete: function() { + equal( changes, 2, "complete triggered after change" ); + } + }); + + value = 5; + $( "#progressbar" ).progressbar( "value", value ); + value = 100; + $( "#progressbar" ).progressbar( "value", value ); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/progressbar/progressbar_methods.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/progressbar/progressbar_methods.js new file mode 100644 index 0000000..a48fa3d --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/progressbar/progressbar_methods.js @@ -0,0 +1,36 @@ +/* + * progressbar_methods.js + */ +(function($) { + +module("progressbar: methods"); + +test("init", function() { + expect(1); + + $("<div></div>").appendTo('body').progressbar().remove(); + ok(true, '.progressbar() called on element'); + +}); + +test("destroy", function() { + expect(2); + + $("<div></div>").appendTo('body').progressbar().progressbar("destroy").remove(); + ok(true, '.progressbar("destroy") called on element'); + + var expected = $('<div></div>').progressbar(), + actual = expected.progressbar('destroy'); + equals(actual, expected, 'destroy is chainable'); +}); + +test('value', function() { + expect(3); + + var el = $('<div></div>').progressbar({ value: 20 }); + equals(el.progressbar('value'), 20, 'correct value as getter'); + equals(el.progressbar('value', 30), el, 'chainable as setter'); + equals(el.progressbar('option', 'value'), 30, 'correct value after setter'); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/progressbar/progressbar_options.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/progressbar/progressbar_options.js new file mode 100644 index 0000000..230c939 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/progressbar/progressbar_options.js @@ -0,0 +1,59 @@ +/* + * progressbar_options.js + */ +(function($) { + +module("progressbar: options"); + +test("{ value : 0 }, default", function() { + $("#progressbar").progressbar(); + same( 0, $("#progressbar").progressbar("value") ); +}); + +// Ticket #7231 - valueDiv should be hidden when value is at 0% +test( "value: visibility of valueDiv", function() { + expect( 5 ); + var element = $( "#progressbar" ).progressbar({ + value: 0 + }); + ok( element.children( ".ui-progressbar-value" ).is( ":hidden" ), "valueDiv hidden when value is initialized at 0" ); + element.progressbar( "value", 1 ); + ok( element.children( ".ui-progressbar-value" ).is( ":visible" ), "valueDiv visible when value is set to 1" ); + element.progressbar( "value", 100 ); + ok( element.children( ".ui-progressbar-value" ).is( ":visible" ), "valueDiv visible when value is set to 100" ); + element.progressbar( "value", 0 ); + ok( element.children( ".ui-progressbar-value" ).is( ":hidden" ), "valueDiv hidden when value is set to 0" ); + element.progressbar( "value", -1 ); + ok( element.children( ".ui-progressbar-value" ).is( ":hidden" ), "valueDiv hidden when value set to -1 (normalizes to 0)" ); +}); + +test("{ value : 5 }", function() { + $("#progressbar").progressbar({ + value: 5 + }); + same( 5, $("#progressbar").progressbar("value") ); +}); + +test("{ value : -5 }", function() { + $("#progressbar").progressbar({ + value: -5 + }); + same( 0, $("#progressbar").progressbar("value") ); +}); + +test("{ value : 105 }", function() { + $("#progressbar").progressbar({ + value: 105 + }); + same( 100, $("#progressbar").progressbar("value") ); +}); + +test("{ max : 5, value : 10 }", function() { + $("#progressbar").progressbar({ + max: 5, + value: 10 + }); + same( 5, $("#progressbar").progressbar("value") ); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/resizable/all.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/resizable/all.html new file mode 100644 index 0000000..2f56d02 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/resizable/all.html @@ -0,0 +1,30 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Resizable Test Suite</title> + + <script src="../../../jquery-1.7.1.js"></script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <link rel="stylesheet" href="../subsuiteRunner.css"> + <script src="../../../external/qunit.js"></script> + <script src="../subsuiteRunner.js"></script> + <script src="../subsuite.js"></script> + + <script> + testAllVersions( "resizable" ); + </script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Resizable Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/resizable/images/test.jpg b/src/main/webapp/jquery-ui-1.9pre/tests/unit/resizable/images/test.jpg Binary files differnew file mode 100644 index 0000000..0175b13 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/resizable/images/test.jpg diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/resizable/resizable.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/resizable/resizable.html new file mode 100644 index 0000000..4e886d2 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/resizable/resizable.html @@ -0,0 +1,58 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Resizable Test Suite</title> + + <script src="../../jquery.js"></script> + <script src="../../resource_loader.js"></script> + <script> + loadResources({ + css: [ "ui.core", "ui.resizable" ], + js: [ + "ui/jquery.ui.core.js", + "ui/jquery.ui.widget.js", + "ui/jquery.ui.mouse.js", + "ui/jquery.ui.resizable.js" + ] + }); + </script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <script src="../../../external/qunit.js"></script> + <script src="../../jquery.simulate.js"></script> + <script src="../testsuite.js"></script> + + <script src="resizable_core.js"></script> + <script src="resizable_defaults.js"></script> + <script src="resizable_events.js"></script> + <script src="resizable_methods.js"></script> + <script src="resizable_options.js"></script> + + <script> + // disable this stale testsuite for testswarm only + var url = window.location.search; + url = decodeURIComponent( url.slice( url.indexOf("swarmURL=") + 9 ) ); + if ( url && url.indexOf("http") == 0 ) { + // reset config to kill previous tests; make sure testsuite.js is loaded afterwards to init the testswarm script + QUnit.init(); + test("resizable", function() { ok(true, "disabled resizable testsuite"); }); + } + </script> + <script src="../swarminject.js"></script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Resizable Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +<div id="resizable1" style="background: green; width: 100px; height: 100px;">I'm a resizable.</div> +<img src="images/test.jpg" id="resizable2" style="width: 100px; height: 100px;"> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/resizable/resizable_core.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/resizable/resizable_core.js new file mode 100644 index 0000000..33a3f72 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/resizable/resizable_core.js @@ -0,0 +1,148 @@ +/* + * resizable_core.js + */ + +var el; + +var drag = function(el, dx, dy, complete) { + + // speed = sync -> Drag syncrhonously. + // speed = fast|slow -> Drag asyncrhonously - animated. + + //this mouseover is to work around a limitation in resizable + //TODO: fix resizable so handle doesn't require mouseover in order to be used + $(el).simulate("mouseover"); + + return $(el).simulate("drag", { + dx: dx||0, dy: dy||0, speed: 'sync', complete: complete + }); +}; + +(function($) { + +module("resizable: core"); + +/* +test("element types", function() { + var typeNames = ('p,h1,h2,h3,h4,h5,h6,blockquote,ol,ul,dl,div,form' + + ',table,fieldset,address,ins,del,em,strong,q,cite,dfn,abbr' + + ',acronym,code,samp,kbd,var,img,object,hr' + + ',input,button,label,select,iframe').split(','); + + $.each(typeNames, function(i) { + var typeName = typeNames[i]; + el = $(document.createElement(typeName)).appendTo('body'); + (typeName == 'table' && el.append("<tr><td>content</td></tr>")); + el.resizable(); + ok(true, '$("<' + typeName + '/>").resizable()'); + el.resizable("destroy"); + el.remove(); + }); +}); +*/ + +test("n", function() { + expect(2); + + var handle = '.ui-resizable-n', target = $('#resizable1').resizable({ handles: 'all' }); + + drag(handle, 0, -50); + equals( target.height(), 150, "compare height" ); + + drag(handle, 0, 50); + equals( target.height(), 100, "compare height" ); +}); + +test("s", function() { + expect(2); + + var handle = '.ui-resizable-s', target = $('#resizable1').resizable({ handles: 'all' }); + + drag(handle, 0, 50); + equals( target.height(), 150, "compare height" ); + + drag(handle, 0, -50); + equals( target.height(), 100, "compare height" ); +}); + +test("e", function() { + expect(2); + + var handle = '.ui-resizable-e', target = $('#resizable1').resizable({ handles: 'all' }); + + drag(handle, 50); + equals( target.width(), 150, "compare width"); + + drag(handle, -50); + equals( target.width(), 100, "compare width" ); +}); + +test("w", function() { + expect(2); + + var handle = '.ui-resizable-w', target = $('#resizable1').resizable({ handles: 'all' }); + + drag(handle, -50); + equals( target.width(), 150, "compare width" ); + + drag(handle, 50); + equals( target.width(), 100, "compare width" ); +}); + +test("ne", function() { + expect(4); + + var handle = '.ui-resizable-ne', target = $('#resizable1').css({ overflow: 'hidden' }).resizable({ handles: 'all' }); + + drag(handle, -50, -50); + equals( target.width(), 50, "compare width" ); + equals( target.height(), 150, "compare height" ); + + drag(handle, 50, 50); + equals( target.width(), 100, "compare width" ); + equals( target.height(), 100, "compare height" ); +}); + +test("se", function() { + expect(4); + + var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ handles: 'all' }); + + drag(handle, 50, 50); + equals( target.width(), 150, "compare width" ); + equals( target.height(), 150, "compare height" ); + + drag(handle, -50, -50); + equals( target.width(), 100, "compare width" ); + equals( target.height(), 100, "compare height" ); +}); + +test("sw", function() { + expect(4); + + var handle = '.ui-resizable-sw', target = $('#resizable1').resizable({ handles: 'all' }); + + drag(handle, -50, -50); + equals( target.width(), 150, "compare width" ); + equals( target.height(), 50, "compare height" ); + + drag(handle, 50, 50); + equals( target.width(), 100, "compare width" ); + equals( target.height(), 100, "compare height" ); +}); + +test("nw", function() { + expect(4); + + var handle = '.ui-resizable-nw', target = $('#resizable1').resizable({ handles: 'all' }); + + drag(handle, -50, -50); + equals( target.width(), 150, "compare width" ); + equals( target.height(), 150, "compare height" ); + + drag(handle, 50, 50); + equals( target.width(), 100, "compare width" ); + equals( target.height(), 100, "compare height" ); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/resizable/resizable_defaults.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/resizable/resizable_defaults.js new file mode 100644 index 0000000..f69e521 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/resizable/resizable_defaults.js @@ -0,0 +1,28 @@ +/* + * resizable_defaults.js + */ + +var resizable_defaults = { + alsoResize: false, + animate: false, + animateDuration: 'slow', + animateEasing: 'swing', + aspectRatio: false, + autoHide: false, + cancel: ':input,option', + containment: false, + delay: 0, + disabled: false, + distance: 1, + ghost: false, + grid: false, + handles: 'e,s,se', + helper: false, + maxHeight: null, + maxWidth: null, + minHeight: 10, + minWidth: 10, + zIndex: 1000 +}; + +commonWidgetTests('resizable', { defaults: resizable_defaults }); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/resizable/resizable_events.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/resizable/resizable_events.js new file mode 100644 index 0000000..e8041f0 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/resizable/resizable_events.js @@ -0,0 +1,20 @@ +/* + * resizable_events.js + */ +(function($) { + +module("resizable: events"); + +test("start", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("resize", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("stop", function() { + ok(false, "missing test - untested code is broken code."); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/resizable/resizable_methods.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/resizable/resizable_methods.js new file mode 100644 index 0000000..6ac287f --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/resizable/resizable_methods.js @@ -0,0 +1,64 @@ +/* + * resizable_methods.js + */ +(function($) { + +module("resizable: methods"); + +test("init", function() { + expect(6); + + $("<div></div>").appendTo('body').resizable().remove(); + ok(true, '.resizable() called on element'); + + $([]).resizable().remove(); + ok(true, '.resizable() called on empty collection'); + + $('<div></div>').resizable().remove(); + ok(true, '.resizable() called on disconnected DOMElement'); + + $('<div></div>').resizable().resizable("foo").remove(); + ok(true, 'arbitrary method called after init'); + + el = $('<div></div>').resizable() + var foo = el.resizable("option", "foo"); + el.remove(); + ok(true, 'arbitrary option getter after init'); + + $('<div></div>').resizable().resizable("option", "foo", "bar").remove(); + ok(true, 'arbitrary option setter after init'); +}); + +test("destroy", function() { + $("<div></div>").appendTo('body').resizable().resizable("destroy").remove(); + ok(true, '.resizable("destroy") called on element'); + + $([]).resizable().resizable("destroy").remove(); + ok(true, '.resizable("destroy") called on empty collection'); + + $('<div></div>').resizable().resizable("destroy").remove(); + ok(true, '.resizable("destroy") called on disconnected DOMElement'); + + $('<div></div>').resizable().resizable("destroy").resizable("foo").remove(); + ok(true, 'arbitrary method called after destroy'); + + var expected = $('<div></div>').resizable(), + actual = expected.resizable('destroy'); + equals(actual, expected, 'destroy is chainable'); +}); + +test("enable", function() { + var expected = $('<div></div>').resizable(), + actual = expected.resizable('enable'); + equals(actual, expected, 'enable is chainable'); + ok(false, "missing test - untested code is broken code."); +}); + +test("disable", function() { + var expected = $('<div></div>').resizable(), + actual = expected.resizable('disable'); + equals(actual, expected, 'disable is chainable'); + ok(false, "missing test - untested code is broken code."); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/resizable/resizable_options.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/resizable/resizable_options.js new file mode 100644 index 0000000..389931f --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/resizable/resizable_options.js @@ -0,0 +1,190 @@ +/* + * resizable_options.js + */ +(function($) { + +module("resizable: options"); + +test("aspectRatio: 'preserve' (e)", function() { + expect(4); + + var handle = '.ui-resizable-e', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); + + drag(handle, 80); + equals( target.width(), 130, "compare maxWidth"); + equals( target.height(), 130, "compare maxHeight"); + + drag(handle, -130); + equals( target.width(), 70, "compare minWidth"); + equals( target.height(), 70, "compare minHeight"); +}); + +test("aspectRatio: 'preserve' (w)", function() { + expect(4); + + var handle = '.ui-resizable-w', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); + + drag(handle, -80); + equals( target.width(), 130, "compare maxWidth"); + equals( target.height(), 130, "compare maxHeight"); + + drag(handle, 130); + equals( target.width(), 70, "compare minWidth"); + equals( target.height(), 70, "compare minHeight"); +}); + +test("aspectRatio: 'preserve' (n)", function() { + expect(4); + + var handle = '.ui-resizable-n', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); + + drag(handle, 0, -80); + equals( target.width(), 130, "compare maxWidth"); + equals( target.height(), 130, "compare maxHeight"); + + drag(handle, 0, 80); + equals( target.width(), 70, "compare minWidth"); + equals( target.height(), 70, "compare minHeight"); +}); + +test("aspectRatio: 'preserve' (s)", function() { + expect(4); + + var handle = '.ui-resizable-s', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); + + drag(handle, 0, 80); + equals( target.width(), 130, "compare maxWidth"); + equals( target.height(), 130, "compare maxHeight"); + + drag(handle, 0, -80); + equals( target.width(), 70, "compare minWidth"); + equals( target.height(), 70, "compare minHeight"); +}); + +test("aspectRatio: 'preserve' (se)", function() { + expect(4); + + var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); + + drag(handle, 80, 80); + equals( target.width(), 130, "compare maxWidth"); + equals( target.height(), 130, "compare maxHeight"); + + drag(handle, -80, -80); + equals( target.width(), 70, "compare minWidth"); + equals( target.height(), 70, "compare minHeight"); +}); + +test("aspectRatio: 'preserve' (sw)", function() { + expect(4); + + var handle = '.ui-resizable-sw', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); + + drag(handle, -80, 80); + equals( target.width(), 130, "compare maxWidth"); + equals( target.height(), 130, "compare maxHeight"); + + drag(handle, 80, -80); + equals( target.width(), 70, "compare minWidth"); + equals( target.height(), 70, "compare minHeight"); +}); + +test("aspectRatio: 'preserve' (ne)", function() { + expect(4); + + var handle = '.ui-resizable-ne', target = $('#resizable1').resizable({ aspectRatio: 'preserve', handles: 'all', minWidth: 70, minHeight: 50, maxWidth: 150, maxHeight: 130 }); + + drag(handle, 80, -80); + equals( target.width(), 130, "compare maxWidth"); + equals( target.height(), 130, "compare maxHeight"); + + drag(handle, -80, 80); + equals( target.width(), 70, "compare minWidth"); + equals( target.height(), 70, "compare minHeight"); +}); + +test("grid", function() { + expect(4); + + var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ handles: 'all', grid: [0, 20] }); + + drag(handle, 3, 9); + equals( target.width(), 103, "compare width"); + equals( target.height(), 100, "compare height"); + + drag(handle, 15, 11); + equals( target.width(), 118, "compare width"); + equals( target.height(), 120, "compare height"); +}); + +test("grid (wrapped)", function() { + expect(4); + + var handle = '.ui-resizable-se', target = $('#resizable2').resizable({ handles: 'all', grid: [0, 20] }); + + drag(handle, 3, 9); + equals( target.width(), 103, "compare width"); + equals( target.height(), 100, "compare height"); + + drag(handle, 15, 11); + equals( target.width(), 118, "compare width"); + equals( target.height(), 120, "compare height"); +}); + +test("ui-resizable-se { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }", function() { + expect(4); + + var handle = '.ui-resizable-se', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }); + + drag(handle, -50, -50); + equals( target.width(), 60, "compare minWidth" ); + equals( target.height(), 60, "compare minHeight" ); + + drag(handle, 70, 70); + equals( target.width(), 100, "compare maxWidth" ); + equals( target.height(), 100, "compare maxHeight" ); +}); + +test("ui-resizable-sw { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }", function() { + expect(4); + + var handle = '.ui-resizable-sw', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }); + + drag(handle, 50, -50); + equals( target.width(), 60, "compare minWidth" ); + equals( target.height(), 60, "compare minHeight" ); + + drag(handle, -70, 70); + equals( target.width(), 100, "compare maxWidth" ); + equals( target.height(), 100, "compare maxHeight" ); +}); + +test("ui-resizable-ne { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }", function() { + expect(4); + + var handle = '.ui-resizable-ne', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }); + + drag(handle, -50, 50); + equals( target.width(), 60, "compare minWidth" ); + equals( target.height(), 60, "compare minHeight" ); + + drag(handle, 70, -70); + equals( target.width(), 100, "compare maxWidth" ); + equals( target.height(), 100, "compare maxHeight" ); +}); + +test("ui-resizable-nw { handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }", function() { + expect(4); + + var handle = '.ui-resizable-nw', target = $('#resizable1').resizable({ handles: 'all', minWidth: 60, minHeight: 60, maxWidth: 100, maxHeight: 100 }); + + drag(handle, 70, 70); + equals( target.width(), 60, "compare minWidth" ); + equals( target.height(), 60, "compare minHeight" ); + + drag(handle, -70, -70); + equals( target.width(), 100, "compare maxWidth" ); + equals( target.height(), 100, "compare maxHeight" ); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/selectable/all.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/selectable/all.html new file mode 100644 index 0000000..e77829b --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/selectable/all.html @@ -0,0 +1,30 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Selectable Test Suite</title> + + <script src="../../../jquery-1.7.1.js"></script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <link rel="stylesheet" href="../subsuiteRunner.css"> + <script src="../../../external/qunit.js"></script> + <script src="../subsuiteRunner.js"></script> + <script src="../subsuite.js"></script> + + <script> + testAllVersions( "selectable" ); + </script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Selectable Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/selectable/selectable.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/selectable/selectable.html new file mode 100644 index 0000000..4f70e8d --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/selectable/selectable.html @@ -0,0 +1,63 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Selectable Test Suite</title> + + <script src="../../jquery.js"></script> + <script src="../../resource_loader.js"></script> + <script> + loadResources({ + css: [ "ui.core", "ui.selectable" ], + js: [ + "ui/jquery.ui.core.js", + "ui/jquery.ui.widget.js", + "ui/jquery.ui.mouse.js", + "ui/jquery.ui.selectable.js" + ] + }); + </script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <script src="../../../external/qunit.js"></script> + <script src="../../jquery.simulate.js"></script> + <script src="../testsuite.js"></script> + + <script src="selectable_core.js"></script> + <script src="selectable_defaults.js"></script> + <script src="selectable_events.js"></script> + <script src="selectable_methods.js"></script> + <script src="selectable_options.js"></script> + + <script> + // disable this stale testsuite for testswarm only + var url = window.location.search; + url = decodeURIComponent( url.slice( url.indexOf("swarmURL=") + 9 ) ); + if ( url && url.indexOf("http") == 0 ) { + // reset config to kill previous tests; make sure testsuite.js is loaded afterwards to init the testswarm script + QUnit.init(); + test("selectable", function() { ok(true, "disabled selectable testsuite"); }); + } + </script> + <script src="../swarminject.js"></script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Selectable Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +<ul id="selectable1"> + <li>Item 1</li> + <li>Item 2</li> + <li class="special">Item 3</li> + <li>Item 4</li> + <li>Item 5</li> +</ul> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/selectable/selectable_core.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/selectable/selectable_core.js new file mode 100644 index 0000000..18ea3a3 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/selectable/selectable_core.js @@ -0,0 +1,16 @@ +/* + * selectable_core.js + */ + +var el; + +var drag = function(dx, dy) { + var off = el.offset(), pos = { clientX: off.left, clientY: off.top }; + el.simulate("mousedown", pos); + $(document).simulate("mousemove", pos); + pos.clientX += dx; + pos.clientY += dy; + $(document).simulate("mousemove", pos); + $(document).simulate("mouseup", pos); +}; + diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/selectable/selectable_defaults.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/selectable/selectable_defaults.js new file mode 100644 index 0000000..dbf799a --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/selectable/selectable_defaults.js @@ -0,0 +1,16 @@ +/* + * selectable_defaults.js + */ + +var selectable_defaults = { + appendTo: 'body', + autoRefresh: true, + cancel: ':input,option', + delay: 0, + disabled: false, + distance: 0, + filter: '*', + tolerance: 'touch' +}; + +commonWidgetTests('selectable', { defaults: selectable_defaults }); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/selectable/selectable_events.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/selectable/selectable_events.js new file mode 100644 index 0000000..03b65ab --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/selectable/selectable_events.js @@ -0,0 +1,32 @@ +/* + * selectable_events.js + */ +(function($) { + +module("selectable: events"); + +test("start", function() { + expect(2); + el = $("#selectable1"); + el.selectable({ + start: function(ev, ui) { + ok(true, "drag fired start callback"); + equals(this, el[0], "context of callback"); + } + }); + el.simulate("drag", 20, 20); +}); + +test("stop", function() { + expect(2); + el = $("#selectable1"); + el.selectable({ + start: function(ev, ui) { + ok(true, "drag fired stop callback"); + equals(this, el[0], "context of callback"); + } + }); + el.simulate("drag", 20, 20); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/selectable/selectable_methods.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/selectable/selectable_methods.js new file mode 100644 index 0000000..06b75f9 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/selectable/selectable_methods.js @@ -0,0 +1,93 @@ +/* + * selectable_methods.js + */ +(function($) { + +module("selectable: methods"); + +test("init", function() { + expect(6); + + $("<div></div>").appendTo('body').selectable().remove(); + ok(true, '.selectable() called on element'); + + $([]).selectable().remove(); + ok(true, '.selectable() called on empty collection'); + + $("<div></div>").selectable().remove(); + ok(true, '.selectable() called on disconnected DOMElement'); + + $("<div></div>").selectable().selectable("foo").remove(); + ok(true, 'arbitrary method called after init'); + + el = $("<div></div>").selectable() + var foo = el.selectable("option", "foo"); + el.remove(); + ok(true, 'arbitrary option getter after init'); + + $("<div></div>").selectable().selectable("option", "foo", "bar").remove(); + ok(true, 'arbitrary option setter after init'); +}); + +test("destroy", function() { + $("<div></div>").appendTo('body').selectable().selectable("destroy").remove(); + ok(true, '.selectable("destroy") called on element'); + + $([]).selectable().selectable("destroy").remove(); + ok(true, '.selectable("destroy") called on empty collection'); + + $("<div></div>").selectable().selectable("destroy").remove(); + ok(true, '.selectable("destroy") called on disconnected DOMElement'); + + $("<div></div>").selectable().selectable("destroy").selectable("foo").remove(); + ok(true, 'arbitrary method called after destroy'); + + var expected = $('<div></div>').selectable(), + actual = expected.selectable('destroy'); + equals(actual, expected, 'destroy is chainable'); +}); + +test("enable", function() { + expect(3); + var fired = false; + + el = $("#selectable1"); + el.selectable({ + disabled: true, + start: function() { fired = true; } + }); + el.simulate("drag", 20, 20); + equals(fired, false, "start fired"); + el.selectable("enable"); + el.simulate("drag", 20, 20); + equals(fired, true, "start fired"); + el.selectable("destroy"); + + var expected = $('<div></div>').selectable(), + actual = expected.selectable('enable'); + equals(actual, expected, 'enable is chainable'); +}); + +test("disable", function() { + expect(3); + var fired = false; + + el = $("#selectable1"); + el.selectable({ + disabled: false, + start: function() { fired = true; } + }); + el.simulate("drag", 20, 20); + equals(fired, true, "start fired"); + el.selectable("disable"); + fired = false; + el.simulate("drag", 20, 20); + equals(fired, false, "start fired"); + el.selectable("destroy"); + + var expected = $('<div></div>').selectable(), + actual = expected.selectable('disable'); + equals(actual, expected, 'disable is chainable'); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/selectable/selectable_options.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/selectable/selectable_options.js new file mode 100644 index 0000000..36b7b5b --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/selectable/selectable_options.js @@ -0,0 +1,46 @@ +/* + * selectable_options.js + */ +(function($) { + +module("selectable: options"); + +test("autoRefresh", function() { + expect(3); + el = $("#selectable1"); + var actual, sel = $("*", el), selected = function() { actual += 1 }; + + actual = 0; + el = $("#selectable1").selectable({ autoRefresh: false, selected: selected }); + sel.hide(); + drag(1000, 1000); + equals(actual, sel.length); + el.selectable("destroy"); + + actual = 0; + sel.show(); + el = $("#selectable1").selectable({ autoRefresh: true, selected: selected }); + sel.hide(); + drag(1000, 1000); + equals(actual, 0); + sel.show(); + drag(1000, 1000); + equals(actual, sel.length); + el.selectable("destroy"); + sel.show(); +}); + +test("filter", function() { + expect(2); + el = $("#selectable1"); + var actual, sel = $("*", el), selected = function() { actual += 1 }; + + actual = 0; + el = $("#selectable1").selectable({ filter: '.special', selected: selected }); + drag(1000, 1000); + ok(sel.length != 1, "this test assumes more than 1 selectee"); + equals(actual, 1); + el.selectable("destroy"); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/all.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/all.html new file mode 100644 index 0000000..cbdbd2f --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/all.html @@ -0,0 +1,30 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Slider Test Suite</title> + + <script src="../../../jquery-1.7.1.js"></script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <link rel="stylesheet" href="../subsuiteRunner.css"> + <script src="../../../external/qunit.js"></script> + <script src="../subsuiteRunner.js"></script> + <script src="../subsuite.js"></script> + + <script> + testAllVersions( "slider" ); + </script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Slider Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider.html new file mode 100644 index 0000000..60d124b --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider.html @@ -0,0 +1,60 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Slider Test Suite</title> + + <script src="../../jquery.js"></script> + <script src="../../resource_loader.js"></script> + <script> + loadResources({ + css: [ "ui.core", "ui.slider" ], + js: [ + "ui/jquery.ui.core.js", + "ui/jquery.ui.widget.js", + "ui/jquery.ui.mouse.js", + "ui/jquery.ui.slider.js" + ] + }); + </script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <script src="../../../external/qunit.js"></script> + <script src="../../jquery.simulate.js"></script> + <script src="../testsuite.js"></script> + + <script src="slider_core.js"></script> + <script src="slider_defaults.js"></script> + <script src="slider_events.js"></script> + <script src="slider_methods.js"></script> + <script src="slider_options.js"></script> + + <script> + // disable this stale testsuite for testswarm only + var url = window.location.search; + url = decodeURIComponent( url.slice( url.indexOf("swarmURL=") + 9 ) ); + if ( url && url.indexOf("http") == 0 ) { + // reset config to kill previous tests; make sure testsuite.js is loaded afterwards to init the testswarm script + QUnit.init(); + test("slider", function() { ok(true, "disabled slider testsuite"); }); + } + </script> + <script src="../swarminject.js"></script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Slider Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +<div id="slider1"></div> +<div id="slider3" style="position: relative; margin: 40px; width: 217px; height: 28px;"> + <div class="ui-slider-handle" style="position: absolute; height: 21px; left: 0px; bottom: 0px; width: 17px;"></div> +</div> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_core.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_core.js new file mode 100644 index 0000000..38d4f46 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_core.js @@ -0,0 +1,292 @@ +/* + * slider unit tests + */ +(function($) { +// +// Slider Test Helper Functions +// + +var el, options; + +function handle() { + return el.find(".ui-slider-handle"); +} + +// Slider Tests +module("slider: core"); + +test("keydown HOME on handle sets value to min", function() { + el = $('<div></div>'); + options = { + max: 5, + min: -5, + orientation: 'horizontal', + step: 1 + }; + el.slider(options); + + el.slider("value", 0); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.HOME }); + equals(el.slider("value"), options.min); + + el.slider('destroy'); + + el = $('<div></div>'); + options = { + max: 5, + min: -5, + orientation: 'vertical', + step: 1 + }; + el.slider(options); + + el.slider("value", 0); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.HOME }); + equals(el.slider("value"), options.min); + + el.slider('destroy'); +}); + +test("keydown END on handle sets value to max", function() { + el = $('<div></div>'); + options = { + max: 5, + min: -5, + orientation: 'horizontal', + step: 1 + }; + el.slider(options); + + el.slider("value", 0); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.END }); + equals(el.slider("value"), options.max); + + el.slider('destroy'); + + el = $('<div></div>'); + options = { + max: 5, + min: -5, + orientation: 'vertical', + step: 1 + }; + el.slider(options); + + el.slider("value", 0); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.END }); + equals(el.slider("value"), options.max); + + el.slider('destroy'); +}); + +test("keydown PAGE_UP on handle increases value by 1/5 range, not greater than max", function() { + $.each(['horizontal', 'vertical'], function(i, orientation) { + el = $('<div></div>'); + options = { + max: 100, + min: 0, + orientation: orientation, + step: 1 + }; + el.slider(options); + + el.slider("value", 70); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.PAGE_UP }); + equals(el.slider("value"), 90); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.PAGE_UP }); + equals(el.slider("value"), 100); + + el.slider("destroy"); + }); +}); + +test("keydown PAGE_DOWN on handle decreases value by 1/5 range, not less than min", function() { + $.each(['horizontal', 'vertical'], function(i, orientation) { + el = $('<div></div>'); + options = { + max: 100, + min: 0, + orientation: orientation, + step: 1 + }; + el.slider(options); + + el.slider("value", 30); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.PAGE_DOWN }); + equals(el.slider("value"), 10); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.PAGE_DOWN }); + equals(el.slider("value"), 0); + + el.slider("destroy"); + }); +}); + +test("keydown UP on handle increases value by step, not greater than max", function() { + el = $('<div></div>'); + options = { + max: 5, + min: -5, + orientation: 'horizontal', + step: 1 + }; + el.slider(options); + + el.slider("value", options.max - options.step); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.UP }); + equals(el.slider("value"), options.max); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.UP }); + equals(el.slider("value"), options.max); + + el.slider("destroy"); + + el = $('<div></div>'); + options = { + max: 5, + min: -5, + orientation: 'vertical', + step: 1 + }; + el.slider(options); + + el.slider("value", options.max - options.step); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.UP }); + equals(el.slider("value"), options.max); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.UP }); + equals(el.slider("value"), options.max); + + el.slider("destroy"); +}); + +test("keydown RIGHT on handle increases value by step, not greater than max", function() { + el = $('<div></div>'); + options = { + max: 5, + min: -5, + orientation: 'horizontal', + step: 1 + }; + el.slider(options); + + el.slider("value", options.max - options.step); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.RIGHT }); + equals(el.slider("value"), options.max); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.RIGHT }); + equals(el.slider("value"), options.max); + + el.slider("destroy"); + + el = $('<div></div>'); + options = { + max: 5, + min: -5, + orientation: 'vertical', + step: 1 + }; + el.slider(options); + + el.slider("value", options.max - options.step); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.RIGHT }); + equals(el.slider("value"), options.max); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.RIGHT }); + equals(el.slider("value"), options.max); + + el.slider("destroy"); +}); + +test("keydown DOWN on handle decreases value by step, not less than min", function() { + el = $('<div></div>'); + options = { + max: 5, + min: -5, + orientation: 'horizontal', + step: 1 + }; + el.slider(options); + + el.slider("value", options.min + options.step); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.DOWN }); + equals(el.slider("value"), options.min); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.DOWN }); + equals(el.slider("value"), options.min); + + el.slider("destroy"); + + el = $('<div></div>'); + options = { + max: 5, + min: -5, + orientation: 'vertical', + step: 1 + }; + el.slider(options); + + el.slider("value", options.min + options.step); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.DOWN }); + equals(el.slider("value"), options.min); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.DOWN }); + equals(el.slider("value"), options.min); + + el.slider("destroy"); +}); + +test("keydown LEFT on handle decreases value by step, not less than min", function() { + el = $('<div></div>'); + options = { + max: 5, + min: -5, + orientation: 'horizontal', + step: 1 + }; + el.slider(options); + + el.slider("value", options.min + options.step); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.LEFT }); + equals(el.slider("value"), options.min); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.LEFT }); + equals(el.slider("value"), options.min); + + el.slider("destroy"); + + el = $('<div></div>'); + options = { + max: 5, + min: -5, + orientation: 'vertical', + step: 1 + }; + el.slider(options); + + el.slider("value", options.min + options.step); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.LEFT }); + equals(el.slider("value"), options.min); + + handle().simulate("keydown", { keyCode: $.ui.keyCode.LEFT }); + equals(el.slider("value"), options.min); + + el.slider("destroy"); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_defaults.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_defaults.js new file mode 100644 index 0000000..8049fe9 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_defaults.js @@ -0,0 +1,19 @@ +commonWidgetTests( "slider", { + defaults: { + animate: false, + cancel: ':input,option', + delay: 0, + disabled: false, + distance: 0, + max: 100, + min: 0, + orientation: 'horizontal', + range: false, + step: 1, + value: 0, + values: null, + + // callbacks + create: null + } +}); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_events.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_events.js new file mode 100644 index 0000000..0b7b250 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_events.js @@ -0,0 +1,109 @@ +/* + * slider_events.js + */ +(function($) { + +module( "slider: events" ); + +//Specs from http://wiki.jqueryui.com/Slider#specs +//"change callback: triggers when the slider has stopped moving and has a new +// value (even if same as previous value), via mouse(mouseup) or keyboard(keyup) +// or value method/option" +test( "mouse based interaction", function() { + expect(4); + + var el = $( "<div></div>" ) + .appendTo( "body" ) + .slider({ + start: function(event, ui) { + equals( event.originalEvent.type, "mousedown", "start triggered by mousedown" ); + }, + slide: function(event, ui) { + equals( event.originalEvent.type, "mousemove", "slider triggered by mousemove" ); + }, + stop: function(event, ui) { + equals( event.originalEvent.type, "mouseup", "stop triggered by mouseup" ); + }, + change: function(event, ui) { + equals( event.originalEvent.type, "mouseup", "change triggered by mouseup" ); + } + }); + + el.find( ".ui-slider-handle" ).eq( 0 ) + .simulate( "drag", { dx: 10, dy: 10 } ); + +}); +test( "keyboard based interaction", function() { + expect(3); + + // Test keyup at end of handle slide (keyboard) + var el = $( "<div></div>" ) + .appendTo( "body" ) + .slider({ + start: function(event, ui) { + equals( event.originalEvent.type, "keydown", "start triggered by keydown" ); + }, + slide: function(event, ui) { + ok( false, "Slider never triggered by keys" ); + }, + stop: function(event, ui) { + equals( event.originalEvent.type, "keyup", "stop triggered by keyup" ); + }, + change: function(event, ui) { + equals( event.originalEvent.type, "keyup", "change triggered by keyup" ); + } + }); + + el.find( ".ui-slider-handle" ).eq( 0 ) + .simulate( "keydown", { keyCode: $.ui.keyCode.LEFT } ) + .simulate( "keypress", { keyCode: $.ui.keyCode.LEFT } ) + .simulate( "keyup", { keyCode: $.ui.keyCode.LEFT } ); + +}); +test( "programmatic event triggers", function() { + expect(6); + + // Test value method + var el = $( "<div></div>" ) + .slider({ + change: function(event, ui) { + ok( true, "change triggered by value method" ); + } + }) + .slider( "value", 0 ); + + QUnit.reset(); + // Test values method + el = $( "<div></div>" ) + .slider({ + values: [ 10, 20 ], + change: function(event, ui) { + ok( true, "change triggered by values method" ); + } + }) + .slider( "values", [80, 90] ); + + QUnit.reset(); + // Test value option + el = $( "<div></div>" ) + .slider({ + change: function(event, ui) { + ok( true, "change triggered by value option" ); + } + }) + .slider( "option", "value", 0 ); + + QUnit.reset(); + // Test values option + el = $( "<div></div>" ) + .slider({ + values: [ 10, 20 ], + change: function(event, ui) { + ok( true, "change triggered by values option" ); + } + }) + .slider( "option", "values", [80, 90] ); + +}); + +}( jQuery ) ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_methods.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_methods.js new file mode 100644 index 0000000..66624e8 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_methods.js @@ -0,0 +1,102 @@ +/* + * slider_methods.js + */ +(function($) { + +module("slider: methods"); + +test("init", function() { + expect(5); + + $("<div></div>").appendTo('body').slider().remove(); + ok(true, '.slider() called on element'); + + $([]).slider().remove(); + ok(true, '.slider() called on empty collection'); + + $('<div></div>').slider().remove(); + ok(true, '.slider() called on disconnected DOMElement'); + + var el = $('<div></div>').slider(); + var foo = el.slider("option", "foo"); + el.remove(); + ok(true, 'arbitrary option getter after init'); + + $('<div></div>').slider().slider("option", "foo", "bar").remove(); + ok(true, 'arbitrary option setter after init'); +}); + +test("destroy", function() { + $("<div></div>").appendTo('body').slider().slider("destroy").remove(); + ok(true, '.slider("destroy") called on element'); + + $([]).slider().slider("destroy").remove(); + ok(true, '.slider("destroy") called on empty collection'); + + $('<div></div>').appendTo('body').remove().slider().slider("destroy").remove(); + ok(true, '.slider("destroy") called on disconnected DOMElement'); + + var expected = $('<div></div>').slider(), + actual = expected.slider('destroy'); + equals(actual, expected, 'destroy is chainable'); +}); + +test("enable", function() { + var expected = $('<div></div>').slider(), + actual = expected.slider('enable'); + equals(actual, expected, 'enable is chainable'); + + var el = $('<div></div>').slider({ disabled: true }); + ok(el.hasClass('ui-disabled'), 'slider has ui-disabled class before enable method call'); + ok(el.hasClass('ui-slider-disabled'), 'slider has ui-slider-disabled class before enable method call'); + el.slider('enable'); + ok(!el.hasClass('ui-disabled'), 'slider does not have ui-disabled class after enable method call'); + ok(!el.hasClass('ui-slider-disabled'), 'slider does not have ui-slider-disabled class after enable method call'); +}); + +test("disable", function() { + var expected = $('<div></div>').slider(), + actual = expected.slider('disable'); + equals(actual, expected, 'disable is chainable'); + + var el = $('<div></div>').slider({ disabled: false }); + ok(!el.hasClass('ui-disabled'), 'slider does not have ui-disabled class before disabled method call'); + ok(!el.hasClass('ui-slider-disabled'), 'slider does not have ui-slider-disabled class before disable method call'); + el.slider('disable'); + ok(el.hasClass('ui-disabled'), 'slider has ui-disabled class after disable method call'); + ok(el.hasClass('ui-slider-disabled'), 'slider has ui-slider-disabled class after disable method call'); +}); + +test("value", function() { + $([false, 'min', 'max']).each(function() { + var el = $('<div></div>').slider({ + range: this, + value: 5 + }); + equals(el.slider('value'), 5, 'range: ' + this + ' slider method get'); + equals(el.slider('value', 10), el, 'value method is chainable'); + equals(el.slider('value'), 10, 'range: ' + this + ' slider method set'); + el.remove(); + }); + var el = $('<div></div>').slider({ + min: -1, value: 0, max: 1 + }); + // min with value option vs value method + el.slider('option', 'value', -2); + equals(el.slider('option', 'value'), -2, 'value option does not respect min'); + equals(el.slider('value'), -1, 'value method get respects min'); + equals(el.slider('value', -2), el, 'value method is chainable'); + equals(el.slider('option', 'value'), -1, 'value method set respects min'); + // max with value option vs value method + el.slider('option', 'value', 2); + equals(el.slider('option', 'value'), 2, 'value option does not respect max'); + equals(el.slider('value'), 1, 'value method get respects max'); + equals(el.slider('value', 2), el, 'value method is chainable'); + equals(el.slider('option', 'value'), 1, 'value method set respects max'); +}); + +//test("values", function() { +// ok(false, "missing test - untested code is broken code."); +//}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_options.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_options.js new file mode 100644 index 0000000..040589b --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/slider/slider_options.js @@ -0,0 +1,146 @@ +/* + * slider_options.js + */ +(function($) { + +var el, options; + +function handle() { + return el.find(".ui-slider-handle"); +} + +module("slider: options"); + +test("max", function() { + el = $('<div></div>'); + + options = { + max: 37, + min: 6, + orientation: 'horizontal', + step: 1, + value: 50 + }; + + el.slider(options); + ok(el.slider("option", "value") == options.value, "value option is not contained by max"); + ok(el.slider("value") == options.max, "value method is contained by max"); + el.slider('destroy'); + +}); + +test("min", function() { + el = $('<div></div>'); + + options = { + max: 37, + min: 6, + orientation: 'vertical', + step: 1, + value: 2 + }; + + el.slider(options); + ok(el.slider("option", "value") == options.value, "value option is not contained by min"); + ok(el.slider("value") == options.min, "value method is contained by min"); + el.slider('destroy'); + +}); + +test("orientation", function() { + el = $('<div></div>'); + + options = { + max: 2, + min: -2, + orientation: 'vertical', + value: 1 + }; + + var percentVal = (options.value - options.min) / (options.max - options.min) * 100; + + el.slider(options).slider("option", "orientation", "horizontal"); + ok(el.is('.ui-slider-horizontal'), "horizontal slider has class .ui-slider-horizontal"); + ok(!el.is('.ui-slider-vertical'), "horizontal slider does not have class .ui-slider-vertical"); + equals(handle().css('left'), percentVal + '%', "horizontal slider handle is positioned with left: %"); + + el.slider('destroy'); + + options = { + max: 2, + min: -2, + orientation: 'horizontal', + value: -1 + }; + + var percentVal = (options.value - options.min) / (options.max - options.min) * 100; + + el.slider(options).slider("option", "orientation", "vertical"); + ok(el.is('.ui-slider-vertical'), "vertical slider has class .ui-slider-vertical"); + ok(!el.is('.ui-slider-horizontal'), "vertical slider does not have class .ui-slider-horizontal"); + equals(handle().css('bottom'), percentVal + '%', "vertical slider handle is positioned with bottom: %"); + + el.slider('destroy'); + +}); + +//test("range", function() { +// ok(false, "missing test - untested code is broken code."); +//}); + +//spec: http://wiki.jqueryui.com/Slider#specs +// value option/method: the value option is not restricted by min/max/step. +// What is returned by the value method is restricted by min (>=), max (<=), and step (even multiple) +test("step", function() { + var el = $('<div></div>').slider({ + min: 0, + value: 0, + step: 10, + max: 100 + }); + equals( el.slider("value"), 0 ); + + el.slider("value", 1); + equals( el.slider("value"), 0 ); + + el.slider("value", 9); + equals( el.slider("value"), 10 ); + + el.slider("value", 11); + equals( el.slider("value"), 10 ); + + el.slider("value", 19); + equals( el.slider("value"), 20 ); + +el = $('<div></div>').slider({ + min: 0, + value: 0, + step: 20, + max: 100 + }); + el.slider("value", 0); + + el.slider("option", "value", 1); + equals( el.slider("value"), 0 ); + + el.slider("option", "value", 9); + equals( el.slider("value"), 0 ); + + el.slider("option", "value", 11); + equals( el.slider("value"), 20 ); + + el.slider("option", "value", 19); + equals( el.slider("value"), 20 ); + + el.slider('destroy'); +}); + +//test("value", function() { +// ok(false, "missing test - untested code is broken code."); +//}); + +//test("values", function() { +// ok(false, "missing test - untested code is broken code."); +//}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/sortable/all.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/sortable/all.html new file mode 100644 index 0000000..0ee6b56 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/sortable/all.html @@ -0,0 +1,30 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Sortable Test Suite</title> + + <script src="../../../jquery-1.7.1.js"></script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <link rel="stylesheet" href="../subsuiteRunner.css"> + <script src="../../../external/qunit.js"></script> + <script src="../subsuiteRunner.js"></script> + <script src="../subsuite.js"></script> + + <script> + testAllVersions( "sortable" ); + </script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Sortable Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/sortable/sortable.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/sortable/sortable.html new file mode 100644 index 0000000..a20eb71 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/sortable/sortable.html @@ -0,0 +1,64 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Sortable Test Suite</title> + + <script src="../../jquery.js"></script> + <script src="../../resource_loader.js"></script> + <script> + loadResources({ + css: [ "ui.core", "ui.sortable" ], + js: [ + "ui/jquery.ui.core.js", + "ui/jquery.ui.widget.js", + "ui/jquery.ui.mouse.js", + "ui/jquery.ui.sortable.js" + ] + }); + </script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <script src="../../../external/qunit.js"></script> + <script src="../../jquery.simulate.js"></script> + <script src="../testsuite.js"></script> + + <script src="sortable_core.js"></script> + <script src="sortable_defaults.js"></script> + <script src="sortable_events.js"></script> + <script src="sortable_methods.js"></script> + <script src="sortable_options.js"></script> + <script src="sortable_tickets.js"></script> + + <script> + // disable this stale testsuite for testswarm only + var url = window.location.search; + url = decodeURIComponent( url.slice( url.indexOf("swarmURL=") + 9 ) ); + if ( url && url.indexOf("http") == 0 ) { + // reset config to kill previous tests; make sure testsuite.js is loaded afterwards to init the testswarm script + QUnit.init(); + test("sortable", function() { ok(true, "disabled sortable testsuite"); }); + } + </script> + <script src="../swarminject.js"></script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Sortable Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +<ul id="sortable"> + <li>Item 1</li> + <li>Item 2</li> + <li>Item 3</li> + <li>Item 4</li> + <li>Item 5</li> +</ul> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/sortable/sortable_core.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/sortable/sortable_core.js new file mode 100644 index 0000000..ff18598 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/sortable/sortable_core.js @@ -0,0 +1,9 @@ +/* + * sortable_core.js + */ + +(function($) { + +module("sortable: core"); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/sortable/sortable_defaults.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/sortable/sortable_defaults.js new file mode 100644 index 0000000..7681add --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/sortable/sortable_defaults.js @@ -0,0 +1,34 @@ +/* + * sortable_defaults.js + */ + +var sortable_defaults = { + appendTo: "parent", + axis: false, + cancel: ":input,option", + connectWith: false, + containment: false, + cursor: 'auto', + cursorAt: false, + delay: 0, + disabled: false, + distance: 1, + dropOnEmpty: true, + forcePlaceholderSize: false, + forceHelperSize: false, + grid: false, + handle: false, + helper: "original", + items: "> *", + opacity: false, + placeholder: false, + revert: false, + scroll: true, + scrollSensitivity: 20, + scrollSpeed: 20, + scope: "default", + tolerance: "intersect", + zIndex: 1000 +}; + +commonWidgetTests('sortable', { defaults: sortable_defaults }); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/sortable/sortable_events.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/sortable/sortable_events.js new file mode 100644 index 0000000..cb4ff4f --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/sortable/sortable_events.js @@ -0,0 +1,147 @@ +/* + * sortable_events.js + */ +(function($) { + +module("sortable: events"); + +test("start", function() { + + var hash; + $("#sortable") + .sortable({ start: function(e, ui) { hash = ui; } }) + .find('li:eq(0)').simulate("drag", { dx: 0, dy: 10 }); + + ok(hash, 'start event triggered'); + ok(hash.helper, 'UI hash includes: helper'); + ok(hash.placeholder, 'UI hash includes: placeholder'); + ok(hash.position && (hash.position.top && hash.position.left), 'UI hash includes: position'); + ok(hash.offset && (hash.offset.top && hash.offset.left), 'UI hash includes: offset'); + ok(hash.item, 'UI hash includes: item'); + ok(!hash.sender, 'UI hash does not include: sender'); + + +}); + +test("sort", function() { + + var hash; + $("#sortable") + .sortable({ sort: function(e, ui) { hash = ui; } }) + .find('li:eq(0)').simulate("drag", { dx: 0, dy: 10 }); + + ok(hash, 'sort event triggered'); + ok(hash.helper, 'UI hash includes: helper'); + ok(hash.placeholder, 'UI hash includes: placeholder'); + ok(hash.position && (hash.position.top && hash.position.left), 'UI hash includes: position'); + ok(hash.offset && (hash.offset.top && hash.offset.left), 'UI hash includes: offset'); + ok(hash.item, 'UI hash includes: item'); + ok(!hash.sender, 'UI hash does not include: sender'); + +}); + +test("change", function() { + + var hash; + $("#sortable") + .sortable({ change: function(e, ui) { hash = ui; } }) + .find('li:eq(0)').simulate("drag", { dx: 1, dy: 1 }); + + ok(!hash, '1px drag, change event should not be triggered'); + + $("#sortable") + .sortable({ change: function(e, ui) { hash = ui; } }) + .find('li:eq(0)').simulate("drag", { dx: 0, dy: 20 }); + + ok(hash, 'change event triggered'); + ok(hash.helper, 'UI hash includes: helper'); + ok(hash.placeholder, 'UI hash includes: placeholder'); + ok(hash.position && (hash.position.top && hash.position.left), 'UI hash includes: position'); + ok(hash.offset && (hash.offset.top && hash.offset.left), 'UI hash includes: offset'); + ok(hash.item, 'UI hash includes: item'); + ok(!hash.sender, 'UI hash does not include: sender'); + +}); + +test("beforeStop", function() { + + var hash; + $("#sortable") + .sortable({ beforeStop: function(e, ui) { hash = ui; } }) + .find('li:eq(0)').simulate("drag", { dx: 0, dy: 20 }); + + ok(hash, 'beforeStop event triggered'); + ok(hash.helper, 'UI hash includes: helper'); + ok(hash.placeholder, 'UI hash includes: placeholder'); + ok(hash.position && (hash.position.top && hash.position.left), 'UI hash includes: position'); + ok(hash.offset && (hash.offset.top && hash.offset.left), 'UI hash includes: offset'); + ok(hash.item, 'UI hash includes: item'); + ok(!hash.sender, 'UI hash does not include: sender'); + +}); + +test("stop", function() { + + var hash; + $("#sortable") + .sortable({ stop: function(e, ui) { hash = ui; } }) + .find('li:eq(0)').simulate("drag", { dx: 0, dy: 20 }); + + ok(hash, 'stop event triggered'); + ok(!hash.helper, 'UI should not include: helper'); + ok(hash.placeholder, 'UI hash includes: placeholder'); + ok(hash.position && (hash.position.top && hash.position.left), 'UI hash includes: position'); + ok(hash.offset && (hash.offset.top && hash.offset.left), 'UI hash includes: offset'); + ok(hash.item, 'UI hash includes: item'); + ok(!hash.sender, 'UI hash does not include: sender'); + +}); + +test("update", function() { + + var hash; + $("#sortable") + .sortable({ update: function(e, ui) { hash = ui; } }) + .find('li:eq(0)').simulate("drag", { dx: 1, dy: 1 }); + + ok(!hash, '1px drag, update event should not be triggered'); + + $("#sortable") + .sortable({ update: function(e, ui) { hash = ui; } }) + .find('li:eq(0)').simulate("drag", { dx: 0, dy: 20 }); + + ok(hash, 'update event triggered'); + ok(!hash.helper, 'UI hash should not include: helper'); + ok(hash.placeholder, 'UI hash includes: placeholder'); + ok(hash.position && (hash.position.top && hash.position.left), 'UI hash includes: position'); + ok(hash.offset && (hash.offset.top && hash.offset.left), 'UI hash includes: offset'); + ok(hash.item, 'UI hash includes: item'); + ok(!hash.sender, 'UI hash does not include: sender'); + +}); + +test("receive", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("remove", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("over", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("out", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("activate", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("deactivate", function() { + ok(false, "missing test - untested code is broken code."); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/sortable/sortable_methods.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/sortable/sortable_methods.js new file mode 100644 index 0000000..c4b5cdc --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/sortable/sortable_methods.js @@ -0,0 +1,108 @@ +/* + * sortable_methods.js + */ +(function($) { + +var el, offsetBefore, offsetAfter, dragged; + +var drag = function(handle, dx, dy) { + offsetBefore = $(handle).offset(); + $(handle).simulate("drag", { + dx: dx || 0, + dy: dy || 0 + }); + dragged = { dx: dx, dy: dy }; + offsetAfter = $(handle).offset(); +} + +var sort = function(handle, dx, dy, index, msg) { + drag(handle, dx, dy); + equals($(handle).parent().children().index(handle), index, msg); +} + +module("sortable: methods"); + +test("init", function() { + expect(6); + + $("<div></div>").appendTo('body').sortable().remove(); + ok(true, '.sortable() called on element'); + + $([]).sortable(); + ok(true, '.sortable() called on empty collection'); + + $("<div></div>").sortable(); + ok(true, '.sortable() called on disconnected DOMElement'); + + $("<div></div>").sortable().sortable("foo"); + ok(true, 'arbitrary method called after init'); + + $("<div></div>").sortable().sortable("option", "foo"); + ok(true, 'arbitrary option getter after init'); + + $("<div></div>").sortable().sortable("option", "foo", "bar"); + ok(true, 'arbitrary option setter after init'); +}); + +test("destroy", function() { + $("<div></div>").appendTo('body').sortable().sortable("destroy").remove(); + ok(true, '.sortable("destroy") called on element'); + + $([]).sortable().sortable("destroy"); + ok(true, '.sortable("destroy") called on empty collection'); + + $("<div></div>").sortable().sortable("destroy"); + ok(true, '.sortable("destroy") called on disconnected DOMElement'); + + $("<div></div>").sortable().sortable("destroy").sortable("foo"); + ok(true, 'arbitrary method called after destroy'); + + var expected = $('<div></div>').sortable(), + actual = expected.sortable('destroy'); + equals(actual, expected, 'destroy is chainable'); +}); + +test("enable", function() { + expect(5); + el = $("#sortable").sortable({ disabled: true }); + + sort($("li", el)[0], 0, 40, 0, '.sortable({ disabled: true })'); + + el.sortable("enable"); + equals(el.sortable("option", "disabled"), false, "disabled option getter"); + + el.sortable("destroy"); + el.sortable({ disabled: true }); + el.sortable("option", "disabled", false); + equals(el.sortable("option", "disabled"), false, "disabled option setter"); + + sort($("li", el)[0], 0, 40, 2, '.sortable("option", "disabled", false)'); + + var expected = $('<div></div>').sortable(), + actual = expected.sortable('enable'); + equals(actual, expected, 'enable is chainable'); +}); + +test("disable", function() { + expect(7); + el = $("#sortable").sortable({ disabled: false }); + sort($("li", el)[0], 0, 40, 2, '.sortable({ disabled: false })'); + + el.sortable("disable"); + sort($("li", el)[0], 0, 40, 0, 'disabled.sortable getter'); + + el.sortable("destroy"); + + el.sortable({ disabled: false }); + sort($("li", el)[0], 0, 40, 2, '.sortable({ disabled: false })'); + el.sortable("option", "disabled", true); + equals(el.sortable("option", "disabled"), true, "disabled option setter"); + ok(el.sortable("widget").is(":not(.ui-state-disabled)"), "sortable element does not get ui-state-disabled since it's an interaction"); + sort($("li", el)[0], 0, 40, 0, '.sortable("option", "disabled", true)'); + + var expected = $('<div></div>').sortable(), + actual = expected.sortable('disable'); + equals(actual, expected, 'disable is chainable'); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/sortable/sortable_options.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/sortable/sortable_options.js new file mode 100644 index 0000000..507d5dc --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/sortable/sortable_options.js @@ -0,0 +1,256 @@ +/* + * sortable_options.js + */ +(function($) { + +module("sortable: options"); + +test("{ appendTo: 'parent' }, default", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ appendTo: Selector }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ axis: false }, default", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ axis: 'x' }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ axis: 'y' }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ axis: ? }, unexpected", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ cancel: ':input,button' }, default", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ cancel: Selector }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ connectWith: false }, default", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ connectWith: Selector }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ containment: false }, default", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ containment: Element }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ containment: 'document' }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ containment: 'parent' }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ containment: 'window' }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ containment: Selector }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ cursor: 'auto' }, default", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ cursor: 'move' }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ cursorAt: false }, default", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ cursorAt: true }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ delay: 0 }, default", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ delay: 100 }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ distance: 1 }, default", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ distance: 10 }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ dropOnEmpty: true }, default", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ dropOnEmpty: false }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ forcePlaceholderSize: false }, default", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ forcePlaceholderSize: true }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ forceHelperSize: false }, default", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ forceHelperSize: true }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ grid: false }, default", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ grid: [17, 3] }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ grid: [3, 7] }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ handle: false }, default", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ handle: Element }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ handle: Selector }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ helper: 'original' }, default", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ helper: Function }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ items: '> *' }, default", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ items: Selector }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ opacity: false }, default", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ opacity: .37 }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ opacity: 1 }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ placeholder: false }, default", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ placeholder: String }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ revert: false }, default", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ revert: true }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ scroll: true }, default", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ scroll: false }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ scrollSensitivity: 20 }, default", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ scrollSensitivity: 2 }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ scrollSensitivity: 200 }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ scrollSpeed: 20 }, default", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ scrollSpeed: 2 }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ scrollSpeed: 200 }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ scope: 'default' }, default", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ scope: ??? }, unexpected", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ tolerance: 'intersect' }, default", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ tolerance: 'pointer' }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ zIndex: 1000 }, default", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ zIndex: 1 }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +test("{ zIndex: false }", function() { + ok(false, "missing test - untested code is broken code."); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/sortable/sortable_tickets.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/sortable/sortable_tickets.js new file mode 100644 index 0000000..3edc8c0 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/sortable/sortable_tickets.js @@ -0,0 +1,83 @@ +/* + * sortable_tickets.js + */ +(function($) { + +var el, offsetBefore, offsetAfter, dragged; + +var drag = function(handle, dx, dy) { + offsetBefore = $(handle).offset(); + $(handle).simulate("drag", { + dx: dx || 0, + dy: dy || 0 + }); + dragged = { dx: dx, dy: dy }; + offsetAfter = $(handle).offset(); +} + +var sort = function(handle, dx, dy, index, msg) { + drag(handle, dx, dy); + equals($(handle).parent().children().index(handle), index, msg); +} + +module("sortable: tickets"); + +test("#3019: Stop fires too early", function() { + + var helper = null; + el = $("#sortable").sortable({ + stop: function(event, ui) { + helper = ui.helper; + } + }); + + sort($("li", el)[0], 0, 40, 2, 'Dragging the sortable'); + equals(helper, null, "helper should be false"); + +}); + +test('#4752: link event firing on sortable with connect list', function () { + var fired = {}, + hasFired = function (type) { return (type in fired) && (true === fired[type]); }; + + $('#sortable').clone().attr('id', 'sortable2').insertAfter('#sortable'); + + $('#main ul').sortable({ + connectWith: '#main ul', + change: function (e, ui) { + fired.change = true; + }, + receive: function (e, ui) { + fired.receive = true; + }, + remove: function (e, ui) { + fired.remove = true; + } + }); + + $('#main ul li').live('click.ui-sortable-test', function () { + fired.click = true; + }); + + $('#sortable li:eq(0)').simulate('click'); + ok(!hasFired('change'), 'Click only, change event should not have fired'); + ok(hasFired('click'), 'Click event should have fired'); + + // Drag an item within the first list + fired = {}; + $('#sortable li:eq(0)').simulate('drag', { dx: 0, dy: 40 }); + ok(hasFired('change'), '40px drag, change event should have fired'); + ok(!hasFired('receive'), 'Receive event should not have fired'); + ok(!hasFired('remove'), 'Remove event should not have fired'); + ok(!hasFired('click'), 'Click event should not have fired'); + + // Drag an item from the first list to the second, connected list + fired = {}; + $('#sortable li:eq(0)').simulate('drag', { dx: 0, dy: 150 }); + ok(hasFired('change'), '150px drag, change event should have fired'); + ok(hasFired('receive'), 'Receive event should have fired'); + ok(hasFired('remove'), 'Remove event should have fired'); + ok(!hasFired('click'), 'Click event should not have fired'); +}); + +})(jQuery); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/spinner/all.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/spinner/all.html new file mode 100644 index 0000000..1075362 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/spinner/all.html @@ -0,0 +1,30 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Spinner Test Suite</title> + + <script src="../../../jquery-1.7.1.js"></script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <link rel="stylesheet" href="../subsuiteRunner.css"> + <script src="../../../external/qunit.js"></script> + <script src="../subsuiteRunner.js"></script> + <script src="../subsuite.js"></script> + + <script> + testAllVersions( "spinner" ); + </script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Spinner Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/spinner/spinner.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/spinner/spinner.html new file mode 100644 index 0000000..0c01a5f --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/spinner/spinner.html @@ -0,0 +1,52 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Spinner Test Suite</title> + + <script src="../../jquery.js"></script> + <script src="../../../external/jquery.mousewheel-3.0.4.js"></script> + <script src="../../../external/globalize.js"></script> + <script src="../../../external/globalize.culture.ja-JP.js"></script> + <script src="../../resource_loader.js"></script> + <script> + loadResources({ + css: [ "ui.core", "ui.button", "ui.spinner" ], + js: [ + "ui/jquery.ui.core.js", + "ui/jquery.ui.widget.js", + "ui/jquery.ui.button.js", + "ui/jquery.ui.spinner.js" + ] + }); + </script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <script src="../../../external/qunit.js"></script> + <script src="../../jquery.simulate.js"></script> + <script src="../testsuite.js"></script> + + <script src="spinner_test_helpers.js"></script> + <script src="spinner_core.js"></script> + <script src="spinner_defaults.js"></script> + <script src="spinner_events.js"></script> + <script src="spinner_methods.js"></script> + <script src="spinner_options.js"></script> + + <script src="../swarminject.js"></script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Spinner Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +<input id="spin" class="foo"> +<input id="spin2" value="2"> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/spinner/spinner_core.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/spinner/spinner_core.js new file mode 100644 index 0000000..e12d1af --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/spinner/spinner_core.js @@ -0,0 +1,206 @@ +(function( $ ) { + +module( "spinner: core" ); + +test( "keydown UP on input, increases value not greater than max", function() { + expect( 5 ); + var element = $( "#spin" ).val( 70 ).spinner({ + max: 100, + step: 10 + }); + + spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); + equal( element.val(), 80 ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); + equal( element.val(), 90 ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); + equal( element.val(), 100 ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); + equal( element.val(), 100 ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); + equal( element.val(), 100 ); +}); + +test( "keydown DOWN on input, decreases value not less than min", function() { + expect( 5 ); + var element = $( "#spin" ).val( 50 ).spinner({ + min: 20, + step: 10 + }); + + spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + equal( element.val(), 40 ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + equal( element.val(), 30 ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + equal( element.val(), 20 ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + equal( element.val(), 20 ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + equal( element.val(), 20 ); +}); + +test( "keydown PAGE_UP on input, increases value not greater than max", function() { + expect( 5 ); + var element = $( "#spin" ).val( 70 ).spinner({ + max: 100, + page: 10 + }); + + spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); + equal( element.val(), 80 ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); + equal( element.val(), 90 ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); + equal( element.val(), 100 ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); + equal( element.val(), 100 ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); + equal( element.val(), 100 ); +}); + +test( "keydown PAGE_DOWN on input, decreases value not less than min", function() { + expect( 5 ); + var element = $( "#spin" ).val( 50 ).spinner({ + min: 20, + page: 10 + }); + + spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); + equal( element.val(), 40 ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); + equal( element.val(), 30 ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); + equal( element.val(), 20 ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); + equal( element.val(), 20 ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); + equal( element.val(), 20 ); +}); + +test( "mouse click on up button, increases value not greater than max", function() { + expect( 3 ); + var element = $( "#spin" ).val( 18 ).spinner({ + max: 20 + }), + button = element.spinner( "widget" ).find( ".ui-spinner-up" ); + + button.trigger( "mousedown" ).trigger( "mouseup" ); + equal( element.val(), 19 ); + button.trigger( "mousedown" ).trigger( "mouseup" ); + equal( element.val(), 20 ); + button.trigger( "mousedown" ).trigger( "mouseup" ); + equal( element.val(), 20 ); +}); + +test( "mouse click on up button, increases value not greater than max", function() { + expect( 3 ); + var element = $( "#spin" ).val( 2 ).spinner({ + min: 0 + }), + button = element.spinner( "widget" ).find( ".ui-spinner-down" ); + + button.trigger( "mousedown" ).trigger( "mouseup" ); + equal( element.val(), 1 ); + button.trigger( "mousedown" ).trigger( "mouseup" ); + equal( element.val(), 0 ); + button.trigger( "mousedown" ).trigger( "mouseup" ); + equal( element.val(), 0 ); +}); + +test( "mousewheel on input", function() { + expect( 4 ); + + var element = $( "#spin" ).val( 0 ).spinner({ + step: 2 + }); + + element.trigger( "mousewheel" ); + equal( element.val(), 0, "mousewheel event without delta does not change value" ); + + element.trigger( "mousewheel", 1 ); + equal( element.val(), 2 ); + + element.trigger( "mousewheel", -0.2 ); + equal( element.val(), 0 ); + + element.trigger( "mousewheel", -15 ); + equal(element.val(), -2 ); +}); + +test( "reading HTML5 attributes", function() { + expect( 6 ); + var markup = "<input type='number' min='-100' max='100' value='5' step='2'>", + element = $( markup ).spinner(); + equal( element.spinner( "option", "min" ), -100, "min from markup" ); + equal( element.spinner( "option", "max" ), 100, "max from markup" ); + equal( element.spinner( "option", "step" ), 2, "step from markup" ); + + element = $( markup ).spinner({ + min: -200, + max: 200, + step: 5 + }); + equal( element.spinner( "option", "min" ), -200, "min from options" ); + equal( element.spinner( "option", "max" ), 200, "max from options" ); + equal( element.spinner( "option", "step" ), 5, "stop from options" ); +}); + +test( "ARIA attributes", function() { + expect( 9 ); + var element = $( "#spin" ).val( 2 ).spinner({ min: -5, max: 5 }); + + equal( element.attr( "role" ), "spinbutton", "role" ); + equal( element.attr( "aria-valuemin" ), "-5", "aria-valuemin" ); + equal( element.attr( "aria-valuemax" ), "5", "aria-valuemax" ); + equal( element.attr( "aria-valuenow" ), "2", "aria-valuenow" ); + + element.spinner( "stepUp" ); + + equal( element.attr( "aria-valuenow" ), "3", "stepUp 1 step changes aria-valuenow" ); + + element.spinner( "option", { min: -10, max: 10 } ); + + equal( element.attr( "aria-valuemin" ), "-10", "min option changed aria-valuemin changes" ); + equal( element.attr( "aria-valuemax" ), "10", "max option changed aria-valuemax changes" ); + + element.spinner( "option", "min", null ); + equal( element.attr( "aria-valuemin" ), undefined, "aria-valuemin not set when no min" ); + + element.spinner( "option", "max", null ); + equal( element.attr( "aria-valuemax" ), undefined, "aria-valuemax not set when no max" ); +}); + +test( "focus text field when pressing button", function() { + expect( 2 ); + var element = $( "#spin" ).spinner(); + $( "body" ).focus(); + ok( element[ 0 ] !== document.activeElement, "not focused before" ); + element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown(); + ok( element[ 0 ] === document.activeElement, "focused after" ); +}); + +test( "don't clear invalid value on blur", function() { + expect( 1 ); + var element = $( "#spin" ).spinner(); + element.focus().val( "a" ).blur(); + equal( element.val(), "a" ); +}); + +test( "precision", function() { + expect( 2 ); + var element = $( "#spin" ).val( .05 ).spinner({ + step: .0001 + }); + element.spinner( "stepUp" ); + equal( element.val(), "0.0501", "precision from step" ); + + element.val( 1.05 ).spinner( "option", { + step: 1, + min: -9.95 + }); + element.spinner( "stepDown" ); + equal( element.val(), "0.05", "precision from min" ); +}); + +})( jQuery ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/spinner/spinner_defaults.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/spinner/spinner_defaults.js new file mode 100644 index 0000000..0a4e7c2 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/spinner/spinner_defaults.js @@ -0,0 +1,19 @@ +commonWidgetTests( "spinner", { + defaults: { + culture: null, + disabled: false, + incremental: true, + max: null, + min: null, + numberFormat: null, + page: 10, + step: 1, + + // callbacks + change: null, + create: null, + spin: null, + start: null, + stop: null + } +}); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/spinner/spinner_events.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/spinner/spinner_events.js new file mode 100644 index 0000000..e43ba33 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/spinner/spinner_events.js @@ -0,0 +1,221 @@ +(function( $ ) { + +module( "spinner: events" ); + +test( "start", function() { + expect( 6 ); + var element = $( "#spin" ).spinner(); + + function shouldStart( expectation, msg ) { + element.spinner( "option", "start", function() { + ok( expectation, msg ); + }); + } + + shouldStart( true, "key UP" ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); + shouldStart( true, "key DOWN" ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + + shouldStart( true, "key PAGE_UP" ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); + shouldStart( true, "key PAGE_DOWN" ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); + + shouldStart( true, "button up" ); + element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown().mouseup(); + shouldStart( true, "button down" ); + element.spinner( "widget" ).find( ".ui-spinner-down" ).mousedown().mouseup(); + + shouldStart( false, "stepUp" ); + element.spinner( "stepUp" ); + shouldStart( false, "stepDown" ); + element.spinner( "stepDown" ); + + shouldStart( false, "pageUp" ); + element.spinner( "pageUp" ); + shouldStart( false, "pageDown" ); + element.spinner( "pageDown" ); + + shouldStart( false, "value" ); + element.spinner( "value", 999 ); +}); + +test( "spin", function() { + expect( 6 ); + var element = $( "#spin" ).spinner(); + + function shouldSpin( expectation, msg ) { + element.spinner( "option", "spin", function() { + ok( expectation, msg ); + }); + } + + shouldSpin( true, "key UP" ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); + shouldSpin( true, "key DOWN" ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + + shouldSpin( true, "key PAGE_UP" ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); + shouldSpin( true, "key PAGE_DOWN" ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); + + shouldSpin( true, "button up" ); + element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown().mouseup(); + shouldSpin( true, "button down" ); + element.spinner( "widget" ).find( ".ui-spinner-down" ).mousedown().mouseup(); + + shouldSpin( false, "stepUp" ); + element.spinner( "stepUp" ); + shouldSpin( false, "stepDown" ); + element.spinner( "stepDown" ); + + shouldSpin( false, "pageUp" ); + element.spinner( "pageUp" ); + shouldSpin( false, "pageDown" ); + element.spinner( "pageDown" ); + + shouldSpin( false, "value" ); + element.spinner( "value", 999 ); +}); + +test( "stop", function() { + expect( 6 ); + var element = $( "#spin" ).spinner(); + + function shouldStop( expectation, msg ) { + element.spinner( "option", "stop", function() { + ok( expectation, msg ); + }); + } + + shouldStop( true, "key UP" ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); + shouldStop( true, "key DOWN" ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + + shouldStop( true, "key PAGE_UP" ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); + shouldStop( true, "key PAGE_DOWN" ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); + + shouldStop( true, "button up" ); + element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown().mouseup(); + shouldStop( true, "button down" ); + element.spinner( "widget" ).find( ".ui-spinner-down" ).mousedown().mouseup(); + + shouldStop( false, "stepUp" ); + element.spinner( "stepUp" ); + shouldStop( false, "stepDown" ); + element.spinner( "stepDown" ); + + shouldStop( false, "pageUp" ); + element.spinner( "pageUp" ); + shouldStop( false, "pageDown" ); + element.spinner( "pageDown" ); + + shouldStop( false, "value" ); + element.spinner( "value", 999 ); +}); + +test( "change", function() { + expect( 14 ); + var element = $( "#spin" ).spinner(); + + function shouldChange( expectation, msg ) { + element.spinner( "option", "change", function() { + ok( expectation, msg ); + }); + } + + element.focus(); + shouldChange( false, "key UP, before blur" ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); + shouldChange( true, "blur after key UP" ); + element.blur(); + + element.focus(); + shouldChange( false, "key DOWN, before blur" ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + shouldChange( true, "blur after key DOWN" ); + element.blur(); + + element.focus(); + shouldChange( false, "key PAGE_UP, before blur" ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); + shouldChange( true, "blur after key PAGE_UP" ); + element.blur(); + + element.focus(); + shouldChange( false, "key PAGE_DOWN, before blur" ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); + shouldChange( true, "blur after key PAGE_DOWN" ); + element.blur(); + + shouldChange( false, "many keys, before blur" ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + shouldChange( true, "blur after many keys" ); + element.blur(); + + shouldChange( false, "many keys, same final value, before blur" ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + shouldChange( false, "blur after many keys, same final value" ); + + shouldChange( false, "button up, before blur" ); + element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown().mouseup(); + shouldChange( true, "blur after button up" ); + element.blur(); + + shouldChange( false, "button down, before blur" ); + element.spinner( "widget" ).find( ".ui-spinner-down" ).mousedown().mouseup(); + shouldChange( true, "blur after button down" ); + element.blur(); + + shouldChange( false, "many buttons, same final value, before blur" ); + element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown().mouseup(); + element.spinner( "widget" ).find( ".ui-spinner-up" ).mousedown().mouseup(); + element.spinner( "widget" ).find( ".ui-spinner-down" ).mousedown().mouseup(); + element.spinner( "widget" ).find( ".ui-spinner-down" ).mousedown().mouseup(); + shouldChange( false, "blur after many buttons, same final value" ); + element.blur(); + + shouldChange( true, "stepUp" ); + element.spinner( "stepUp" ); + + shouldChange( true, "stepDown" ); + element.spinner( "stepDown" ); + + shouldChange( true, "pageUp" ); + element.spinner( "pageUp" ); + + shouldChange( true, "pageDown" ); + element.spinner( "pageDown" ); + + shouldChange( true, "value" ); + element.spinner( "value", 999 ); + + shouldChange( false, "value, same value" ); + element.spinner( "value", 999 ); + + shouldChange( true, "max, value changed" ); + element.spinner( "option", "max", 900 ); + + shouldChange( false, "max, value not changed" ); + element.spinner( "option", "max", 1000 ); + + shouldChange( true, "min, value changed" ); + element.spinner( "option", "min", 950 ); + + shouldChange( false, "min, value not changed" ); + element.spinner( "option", "min", 200 ); +}); + +})( jQuery ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/spinner/spinner_methods.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/spinner/spinner_methods.js new file mode 100644 index 0000000..a9fd6c8 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/spinner/spinner_methods.js @@ -0,0 +1,164 @@ +(function( $ ) { + +module( "spinner: methods" ); + +test( "destroy", function() { + expect( 1 ); + domEqual( "#spin", function() { + $( "#spin" ).spinner().spinner( "destroy" ); + }); +}); + +test( "disable", function() { + expect( 14 ); + var element = $( "#spin" ).val( 2 ).spinner(), + wrapper = $( "#spin" ).spinner( "widget" ); + + ok( !wrapper.hasClass( "ui-spinner-disabled" ), "before: wrapper does not have ui-spinner-disabled class" ); + ok( !element.is( ":disabled" ), "before: input does not have disabled attribute" ); + + element.spinner( "disable" ); + ok( wrapper.hasClass( "ui-spinner-disabled" ), "after: wrapper has ui-spinner-disabled class" ); + ok( element.is( ":disabled"), "after: input has disabled attribute" ); + + spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); + equals( 2, element.val(), "keyboard - value does not change on key UP" ); + + spinner_simulateKeyDownUp( element, $.ui.keyCode.DOWN ); + equals( 2, element.val(), "keyboard - value does not change on key DOWN" ); + + spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_UP ); + equals( 2, element.val(), "keyboard - value does not change on key PGUP" ); + + spinner_simulateKeyDownUp( element, $.ui.keyCode.PAGE_DOWN ); + equals( 2, element.val(), "keyboard - value does not change on key PGDN" ); + + wrapper.find( ".ui-spinner-up" ).trigger( "mousedown" ).trigger( "mouseup" ); + equals( 2, element.val(), "mouse - value does not change on clicking up button" ); + + wrapper.find( ".ui-spinner-down" ).trigger( "mousedown" ).trigger( "mouseup" ); + equals( 2, element.val(), "mouse - value does not change on clicking down button" ); + + element.spinner( "stepUp", 6 ); + equals( 8, element.val(), "script - stepUp 6 steps changes value"); + + element.spinner( "stepDown" ); + equals( 7, element.val(), "script - stepDown 1 step changes value" ); + + element.spinner( "pageUp" ); + equals( 17, element.val(), "script - pageUp 1 page changes value" ); + + element.spinner( "pageDown" ); + equals( 7, element.val(), "script - pageDown 1 page changes value" ); +}); + +test( "enable", function() { + expect( 5 ); + 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" ); + ok( element.is( ":disabled" ), "before: input has disabled attribute" ); + + element.spinner( "enable" ); + + ok( !wrapper.hasClass( ".ui-spinner-disabled" ), "after: wrapper does not have ui-spinner-disabled class" ); + ok( !element.is( ":disabled" ), "after: input does not have disabled attribute" ); + + spinner_simulateKeyDownUp( element, $.ui.keyCode.UP ); + equals( 2, element.val(), "keyboard - value changes on key UP" ); +}); + +test( "pageDown", function() { + expect( 4 ); + var element = $( "#spin" ).val( -12 ).spinner({ + page: 20, + min: -100 + }); + + element.spinner( "pageDown" ); + equals( element.val(), -32, "pageDown 1 page" ); + + element.spinner( "pageDown", 3 ); + equals( element.val(), -92, "pageDown 3 pages" ); + + element.spinner( "pageDown" ); + equals( element.val(), -100, "value close to min and pageDown 1 page" ); + + element.spinner( "pageDown", 10 ); + equals( element.val(), -100, "value at min and pageDown 10 pages" ); +}); + +test( "pageUp", function() { + expect( 4 ); + var element = $( "#spin" ).val( 12 ).spinner({ + page: 20, + max: 100 + }); + + element.spinner( "pageUp" ); + equals( element.val(), 32, "pageUp 1 page" ); + + element.spinner( "pageUp", 3 ); + equals( element.val(), 92, "pageUp 3 pages" ); + + element.spinner( "pageUp" ); + equals( element.val(), 100, "value close to max and pageUp 1 page" ); + + element.spinner( "pageUp", 10 ); + equals( element.val(), 100, "value at max and pageUp 10 pages" ); +}); + +test( "stepDown", function() { + expect( 4 ); + var element = $( "#spin" ).val( 0 ).spinner({ + step: 2, + min: -15 + }); + + element.spinner( "stepDown" ); + equals( element.val(), "-1", "stepDown 1 step" ); + + element.spinner( "stepDown", 5 ); + equals( element.val(), "-11", "stepDown 5 steps" ); + + element.spinner( "stepDown", 4 ); + equals( element.val(), "-15", "close to min and stepDown 4 steps" ); + + element.spinner( "stepDown" ); + equals( element.val(), "-15", "at min and stepDown 1 step" ); +}); + +test( "stepUp", function() { + expect( 4 ); + var element = $( "#spin" ).val( 0 ).spinner({ + step: 2, + max: 16 + }); + + element.spinner( "stepUp" ); + equals( element.val(), 2, "stepUp 1 step" ); + + element.spinner( "stepUp", 5 ); + equals( element.val(), 12, "stepUp 5 steps" ); + + element.spinner( "stepUp", 4 ); + equals( element.val(), 16, "close to min and stepUp 4 steps" ); + + element.spinner( "stepUp" ); + equals( element.val(), 16, "at max and stepUp 1 step" ); +}); + +test( "value", function() { + expect( 2 ); + var element = $( "#spin" ).val( 0 ).spinner({ + step: 3 + }); + + element.spinner( "value", 10 ); + equals( element.val(), 9, "change value via value method" ); + + equals( element.spinner( "value" ), 9, "get value via value method" ); +}); + +})( jQuery ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/spinner/spinner_options.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/spinner/spinner_options.js new file mode 100644 index 0000000..81f434f --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/spinner/spinner_options.js @@ -0,0 +1,190 @@ +(function( $ ) { + +module( "spinner: options" ); + +// culture is tested after numberFormat, since it depends on numberFormat + +test( "incremental, false", function() { + expect( 100 ); + + var i, diff, + prev = 0, + element = $( "#spin" ).val( prev ).spinner({ + incremental: false, + spin: function( event, ui ) { + equal( ui.value - prev, 1 ); + prev = ui.value; + } + }); + + for ( i = 0; i < 100; i++ ) { + element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); + } + element.simulate( "keyup", { keyCode: $.ui.keyCode.UP } ); +}); + +test( "incremental, true", function() { + expect( 100 ); + + function fill( num, val ) { + return $.map( new Array( num ), function() { + return val; + }); + } + + var i, diff, + prev = 0, + expected = [].concat( fill( 18, 1 ), fill( 37, 2 ), fill( 14, 3 ), + fill( 9, 4 ), fill( 6, 5 ), fill( 5, 6 ), fill ( 5, 7 ), + fill( 4, 8 ), fill( 2, 9 ) ), + element = $( "#spin" ).val( prev ).spinner({ + incremental: true, + spin: function( event, ui ) { + equal( ui.value - prev, expected[ i ] ); + prev = ui.value; + } + }); + + for ( i = 0; i < 100; i++ ) { + element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); + } + element.simulate( "keyup", { keyCode: $.ui.keyCode.UP } ); +}); + +test( "incremental, function", function() { + expect( 100 ); + + var i, + prev = 0, + element = $( "#spin" ).val( prev ).spinner({ + incremental: function( i ) { + return i; + }, + spin: function( event, ui ) { + equal( ui.value - prev, i + 1 ); + prev = ui.value; + } + }); + + for ( i = 0; i < 100; i++ ) { + element.simulate( "keydown", { keyCode: $.ui.keyCode.UP } ); + } + element.simulate( "keyup", { keyCode: $.ui.keyCode.UP } ); +}); + +test( "numberFormat, number", function() { + expect( 2 ); + var element = $( "#spin" ).val( 0 ).spinner({ numberFormat: "n" }); + equal( element.val(), "0.00", "formatted on init" ); + element.spinner( "stepUp" ); + equal( element.val(), "1.00", "formatted after step" ); +}); + +test( "numberFormat, number, simple", function() { + expect( 2 ); + var element = $( "#spin" ).val( 0 ).spinner({ numberFormat: "n0" }); + equal( element.val(), "0", "formatted on init" ); + element.spinner( "stepUp" ); + equal( element.val(), "1", "formatted after step" ); +}); + +test( "numberFormat, currency", function() { + expect( 2 ); + var element = $( "#spin" ).val( 0 ).spinner({ numberFormat: "C" }); + equal( element.val(), "$0.00", "formatted on init" ); + element.spinner( "stepUp" ); + equal( element.val(), "$1.00", "formatted after step" ); +}); + +test( "numberFormat, change", function() { + expect( 2 ); + var element = $( "#spin" ).val( 5 ).spinner({ numberFormat: "n1" }); + equal( element.val(), "5.0", "formatted on init" ); + element.spinner( "option", "numberFormat", "c" ); + equal( element.val(), "$5.00", "formatted after change" ); +}); + +test( "culture, null", function() { + expect( 2 ); + Globalize.culture( "ja-JP" ); + var element = $( "#spin" ).val( 0 ).spinner({ numberFormat: "C" }); + equal( element.val(), "¥0", "formatted on init" ); + element.spinner( "stepUp" ); + equal( element.val(), "¥1", "formatted after step" ); + + // reset culture + Globalize.culture( "default" ); +}); + +test( "currency, ja-JP", function() { + expect( 2 ); + var element = $( "#spin" ).val( 0 ).spinner({ + numberFormat: "C", + culture: "ja-JP" + }); + equal( element.val(), "¥0", "formatted on init" ); + element.spinner( "stepUp" ); + equal( element.val(), "¥1", "formatted after step" ); +}); + +test( "currency, change", function() { + expect( 2 ); + var element = $( "#spin" ).val( 5 ).spinner({ + numberFormat: "C", + culture: "ja-JP" + }); + equal( element.val(), "¥5", "formatted on init" ); + element.spinner( "option", "culture", "en" ); + equal( element.val(), "$5.00", "formatted after change" ); +}); + +test( "max", function() { + expect( 3 ); + var element = $( "#spin" ).val( 1000 ).spinner({ max: 100 }); + equals( element.val(), 1000, "value not constrained on init" ); + + element.spinner( "value", 1000 ); + equals( element.val(), 100, "max constrained if value method is greater" ); + + element.val( 1000 ).blur(); + equals( element.val(), 1000, "max not constrained if manual entry" ); +}); + +test( "min", function() { + expect( 3 ); + var element = $( "#spin" ).val( -1000 ).spinner({ min: -100 }); + equals( element.val(), -1000, "value not constrained on init" ); + + element.spinner( "value", -1000 ); + equals( element.val(), -100, "min constrained if value method is greater" ); + + element.val( -1000 ).blur(); + equals( element.val(), -1000, "min not constrained if manual entry" ); +}); + +test( "step, 2", function() { + expect( 3 ); + var element = $( "#spin" ).val( 0 ).spinner({ step: 2 }); + + element.spinner( "stepUp" ); + equals( element.val(), "2", "stepUp" ); + + element.spinner( "value", "10.5" ); + equals( element.val(), "10", "value reset to 10" ); + + element.val( "4.5" ); + element.spinner( "stepUp" ); + equals( element.val(), "6", "stepUp" ); +}); + +test( "step, 0.7", function() { + expect( 1 ); + var element = $("#spin").val( 0 ).spinner({ + step: 0.7 + }); + + element.spinner( "stepUp" ); + equals( element.val(), "0.7", "stepUp" ); +}); + +})( jQuery ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/spinner/spinner_test_helpers.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/spinner/spinner_test_helpers.js new file mode 100644 index 0000000..af555db --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/spinner/spinner_test_helpers.js @@ -0,0 +1,5 @@ +var spinner_simulateKeyDownUp = function( element, keyCode, shift ) { + element + .simulate( "keydown", { keyCode: keyCode, shiftKey: shift || false } ) + .simulate( "keyup", { keyCode: keyCode, shiftKey: shift || false } ); +}; diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/subsuite.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/subsuite.js new file mode 100644 index 0000000..e584d28 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/subsuite.js @@ -0,0 +1,21 @@ +(function() { + +var versions = [ "1.6", "1.6.1", "1.6.2", "1.6.3", "1.6.4", "1.7", "1.7.1", "git" ]; + +var additionalTests = { + accordion: [ "accordion_deprecated.html" ], + position: [ "position_deprecated.html" ], + tabs: [ "tabs_deprecated.html" ] +}; + +window.testAllVersions = function( widget ) { + QUnit.testSuites( $.map( + [ widget + ".html" ].concat( additionalTests[ widget ] || [] ), + function( test ) { + return $.map( versions, function( version ) { + return test + "?jquery=" + version; + }); + })); +}; + +}()); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/subsuiteRunner.css b/src/main/webapp/jquery-ui-1.9pre/tests/unit/subsuiteRunner.css new file mode 100644 index 0000000..bca30a7 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/subsuiteRunner.css @@ -0,0 +1,8 @@ +iframe.qunit-subsuite { + margin: 0; + padding: 0; + border-width: 1px 0 0; + height: 600px; + width: 100%; + background: #fff; +}
\ No newline at end of file diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/subsuiteRunner.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/subsuiteRunner.js new file mode 100644 index 0000000..ddfccc7 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/subsuiteRunner.js @@ -0,0 +1,82 @@ +(function( QUnit ) { + +var subsuiteFrame; + +QUnit.extend( QUnit, { + testSuites: function( suites ) { + for ( var i = 0; i < suites.length; i++ ) { + (function( suite ) { + asyncTest( suite, function() { + QUnit.runSuite( suite ); + }); + }( suites[i] ) ); + } + QUnit.done = function() { + subsuiteFrame.style.display = "none"; + }; + }, + + testStart: function( data ) { + // update the test status to show which test suite is running + QUnit.id( "qunit-testresult" ).innerHTML = "Running " + data.name + "...<br> "; + }, + + testDone: function() { + var current = QUnit.id( this.config.current.id ), + children = current.children; + + // undo the auto-expansion of failed tests + for ( var i = 0; i < children.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; + + iframe.className = "qunit-subsuite"; + body.appendChild( iframe ); + + function onIframeLoad() { + var module, test, + count = 0; + + QUnit.extend( iframeWin.QUnit, { + moduleStart: function( data ) { + // capture module name for messages + module = data.name; + }, + + testStart: function( data ) { + // capture test name for messages + test = data.name; + }, + + log: function( data ) { + // pass all test details through to the main page + var message = module + ": " + test + ": " + data.message; + expect( ++count ); + QUnit.push( data.result, data.actual, data.expected, message ); + }, + + done: function() { + // start the wrapper test from the main page + start(); + } + }); + } + QUnit.addEvent( iframe, "load", onIframeLoad ); + + iframeWin = iframe.contentWindow; + iframe.setAttribute( "src", suite ); + + this.runSuite = function( suite ) { + iframe.setAttribute( "src", suite ); + }; + } +}); +}( QUnit ) ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/swarminject.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/swarminject.js new file mode 100644 index 0000000..db69326 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/swarminject.js @@ -0,0 +1,9 @@ +// load testswarm agent +(function() { + var url = window.location.search; + url = decodeURIComponent( url.slice( url.indexOf("swarmURL=") + 9 ) ); + if ( !url || url.indexOf("http") !== 0 ) { + return; + } + document.write("<scr" + "ipt src='http://swarm.jquery.org/js/inject.js?" + (new Date).getTime() + "'></scr" + "ipt>"); +})(); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/all.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/all.html new file mode 100644 index 0000000..363edc0 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/all.html @@ -0,0 +1,30 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Tabs Test Suite</title> + + <script src="../../../jquery-1.7.1.js"></script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <link rel="stylesheet" href="../subsuiteRunner.css"> + <script src="../../../external/qunit.js"></script> + <script src="../subsuiteRunner.js"></script> + <script src="../subsuite.js"></script> + + <script> + testAllVersions( "tabs" ); + </script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Tabs Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/data/test.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/data/test.html new file mode 100644 index 0000000..cd59e64 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/data/test.html @@ -0,0 +1 @@ +<p>…content loaded via Ajax.</p>
\ No newline at end of file diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/tabs.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/tabs.html new file mode 100644 index 0000000..f2a672b --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/tabs.html @@ -0,0 +1,181 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Tabs Test Suite</title> + + <script src="../../jquery.js"></script> + <script> + $.uiBackCompat = false; + </script> + <script src="../../resource_loader.js"></script> + <script> + loadResources({ + css: [ "ui.core", "ui.tabs" ], + js: [ + "ui/jquery.ui.core.js", + "ui/jquery.ui.widget.js", + "ui/jquery.ui.tabs.js" + ] + }); + </script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <script src="../../../external/qunit.js"></script> + <script src="../../jquery.simulate.js"></script> + <script src="../testsuite.js"></script> + + <script src="tabs_defaults.js"></script> + <script src="tabs_core.js"></script> + <script src="tabs_events.js"></script> + <script src="tabs_methods.js"></script> + <script src="tabs_options.js"></script> + + <script> + function tabs_state( tabs ) { + var expected = $.makeArray( arguments ).slice( 1 ); + var actual = tabs.find( ".ui-tabs-nav li" ).map(function() { + var tab = $( this ), + panel = $( $.ui.tabs.prototype._sanitizeSelector( + "#" + tab.find( "a" ).attr( "aria-controls" ) ) ), + tabIsActive = tab.hasClass( "ui-state-active" ), + panelIsActive = panel.css( "display" ) !== "none"; + + if ( tabIsActive && panelIsActive ) { + return 1; + } + if ( !tabIsActive && !panelIsActive ) { + return 0; + } + return -1; // mixed state - invalid + }).get(); + same( actual, expected ); + } + + function tabs_disabled( tabs, state ) { + var expected = $.map( new Array( tabs.find ( ".ui-tabs-nav li" ).length ), function( _, index ) { + if ( typeof state === "boolean" ) { + return state ? 1 : 0; + } else { + return $.inArray( index, state ) !== -1 ? 1 : 0; + } + }); + + var internalState = tabs.tabs( "option", "disabled" ); + if ( internalState === false ) { + internalState = []; + } + if ( internalState === true ) { + internalState = $.map( new Array( tabs.find( ".ui-tabs-nav li" ).length ), function( _, index ) { + return index; + }); + } + + var actual = tabs.find( ".ui-tabs-nav li" ).map(function( index ) { + var tab = $( this ), + tabIsDisabled = tab.hasClass( "ui-state-disabled" ); + + if ( tabIsDisabled && $.inArray( index, internalState ) !== -1 ) { + return 1; + } + if ( !tabIsDisabled && $.inArray( index, internalState ) === -1 ) { + return 0; + } + return -1; // mixed state - invalid + }).get(); + same( tabs.tabs( "option", "disabled" ), state ); + same( actual, expected ); + } + </script> + <script src="../swarminject.js"></script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Tabs Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +<div id="tabs1"> + <ul> + <li><a href="#fragment-1"><span>1</span></a></li> + <li><a href="#fragment-2"><span>2</span></a></li> + <li><a href="#fragment-3"><span>3</span></a></li> + </ul> + <div id="fragment-1"></div> + <div id="fragment-2"></div> + <div id="fragment-3"></div> +</div> + +<div id="tabs2"> + <ul> + <li><a href="#colon:test"><span>1</span></a></li> + <li><a href="#inline-style"><span>2</span></a></li> + <li><a href="data/test.html#test"><span>3</span></a></li> + <li><a href="data/test.html" aria-controls="custom-id"><span>4</span></a></li> + <li><a href="data/test.html" title="∫ßáö Սե"><span>5</span></a></li> + </ul> + <div id="colon:test"></div> + <div style="height: 300px;" id="inline-style"></div> +</div> + +<div id="tabs3"> + <div> + <ul id="tabs3-list"> + <li><a href="#tabs3-1">1</a></li> + </ul> + </div> +</div> + +<div id="tabs4"> + <ul id="tabs4-list"> + <li><a href="#tabs4-1">1</a></li> + </ul> + <ol> + <li><a href="#tabs4-1">1</a></li> + </ol> +</div> + +<div id="tabs4a"> + <ol id="tabs4a-list"> + <li><a href="#tabs4a-1">1</a></li> + </ol> + <ul> + <li><a href="#tabs4a-1">1</a></li> + </ul> +</div> + +<div id="tabs5"> + <div> + <ul id="tabs5-list"></ul> + </div> +</div> + +<div id="tabs6"> + <ul id="tabs6-list"> + <li><a href="#tabs6-1">1</a> + <ul> + <li><a href="#item6-3">3</a></li> + <li><a href="#item6-4">4</a></li> + </ul> + </li> + <li><a href="#tabs6-2">2</a></li> + </ul> + <div id="tabs6-1"></div> + <div id="tabs6-2"></div> +</div> + +<div id="tabs7"> + <ul id="tabs7-list"> + <li><a href="#tabs7-1">1</a></li> + <li><a href="#tabs7-2">2</a></li> + </ul> + <div id="tabs7-2"></div> + <div id="tabs7-1"></div> +</div> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/tabs_core.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/tabs_core.js new file mode 100644 index 0000000..e7c1ee5 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/tabs_core.js @@ -0,0 +1,94 @@ +(function( $ ) { + +module( "tabs: core" ); + +test( "markup structure", function() { + expect( 3 ); + var element = $( "#tabs1" ).tabs(); + ok( element.hasClass( "ui-tabs" ), "main element is .ui-tabs" ); + ok( element.find( "ul" ).hasClass( "ui-tabs-nav" ), "list item is .ui-tabs-nav" ); + equal( element.find( ".ui-tabs-panel" ).length, 3, + ".ui-tabs-panel elements exist, correct number" ); +}); + +$.each({ + "deep ul": "#tabs3", + "multiple lists, ul first": "#tabs4", + "multiple lists, ol first": "#tabs5", + "empty list": "#tabs6" +}, function( type, selector ) { + test( "markup structure: " + type, function() { + expect( 2 ); + var element = $( selector ).tabs(); + ok( element.hasClass( "ui-tabs" ), "main element is .ui-tabs" ); + ok( $( selector + "-list" ).hasClass( "ui-tabs-nav" ), + "list item is .ui-tabs-nav" ); + }); +}); + +// #5893 - Sublist in the tab list are considered as tab +test( "nested list", function() { + expect( 1 ); + + var element = $( "#tabs6" ).tabs(); + equals( element.data( "tabs" ).anchors.length, 2, "should contain 2 tab" ); +}); + +test( "disconnected from DOM", function() { + expect( 2 ); + + var element = $( "#tabs1" ).remove().tabs(); + equals( element.find( ".ui-tabs-nav" ).length, 1, "should initialize nav" ); + equals( element.find( ".ui-tabs-panel" ).length, 3, "should initialize panels" ); +}); + +test( "aria-controls", function() { + expect( 7 ); + var element = $( "#tabs1" ).tabs(), + tabs = element.find( ".ui-tabs-nav a" ); + tabs.each(function() { + var tab = $( this ); + equal( tab.prop( "hash" ).substring( 1 ), tab.attr( "aria-controls" ) ); + }); + + element = $( "#tabs2" ).tabs(); + tabs = element.find( ".ui-tabs-nav a" ); + equal( tabs.eq( 0 ).attr( "aria-controls" ), "colon:test" ); + equal( tabs.eq( 1 ).attr( "aria-controls" ), "inline-style" ); + ok( /^ui-tabs-\d+$/.test( tabs.eq( 2 ).attr( "aria-controls" ) ), "generated id" ); + equal( tabs.eq( 3 ).attr( "aria-controls" ), "custom-id" ); +}); + +test( "accessibility", function() { + // TODO: add tests +}); + +test( "#3627 - Ajax tab with url containing a fragment identifier fails to load", function() { + expect( 1 ); + + var element = $( "#tabs2" ).tabs({ + active: 2, + beforeLoad: function( event, ui ) { + event.preventDefault(); + ok( /test.html$/.test( ui.ajaxSettings.url ), "should ignore fragment identifier" ); + } + }); +}); + +test( "#4033 - IE expands hash to full url and misinterprets tab as ajax", function() { + expect( 2 ); + + var element = $( "<div><ul><li><a href='#tab'>Tab</a></li></ul><div id='tab'></div></div>" ); + element.appendTo( "#main" ); + element.tabs({ + beforeLoad: function( event, ui ) { + event.preventDefault(); + ok( false, 'should not be an ajax tab'); + } + }); + + equals( element.find( ".ui-tabs-nav a" ).attr( "aria-controls" ), "tab", "aria-contorls attribute is correct" ); + tabs_state( element, 1 ); +}); + +}( jQuery ) ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/tabs_defaults.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/tabs_defaults.js new file mode 100644 index 0000000..52b6f8a --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/tabs_defaults.js @@ -0,0 +1,16 @@ +commonWidgetTests( "tabs", { + defaults: { + active: null, + collapsible: false, + disabled: false, + event: "click", + fx: null, + + // callbacks + activate: null, + beforeActivate: null, + beforeLoad: null, + create: null, + load: null + } +}); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/tabs_defaults_deprecated.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/tabs_defaults_deprecated.js new file mode 100644 index 0000000..1a56297 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/tabs_defaults_deprecated.js @@ -0,0 +1,29 @@ +commonWidgetTests( "tabs", { + defaults: { + active: null, + ajaxOptions: null, + cache: false, + collapsible: false, + cookie: null, + disabled: false, + event: "click", + fx: null, + idPrefix: "ui-tabs-", + panelTemplate: "<div></div>", + spinner: "<em>Loading…</em>", + tabTemplate: "<li><a href='#{href}'><span>#{label}</span></a></li>", + + // callbacks + activate: null, + add: null, + beforeActivate: null, + beforeLoad: null, + create: null, + disable: null, + enable: null, + load: null, + remove: null, + select: null, + show: null + } +}); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/tabs_deprecated.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/tabs_deprecated.html new file mode 100644 index 0000000..92d9be8 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/tabs_deprecated.html @@ -0,0 +1,180 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Tabs Test Suite</title> + + <script src="../../jquery.js"></script> + <script src="../../../external/jquery.cookie.js"></script> + <script src="../../resource_loader.js"></script> + <script> + loadResources({ + css: [ "ui.core", "ui.tabs" ], + js: [ + "ui/jquery.ui.core.js", + "ui/jquery.ui.widget.js", + "ui/jquery.ui.tabs.js" + ] + }); + </script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <script src="../../../external/qunit.js"></script> + <script src="../../jquery.simulate.js"></script> + <script src="../testsuite.js"></script> + + <script src="tabs_defaults_deprecated.js"></script> + <script src="tabs_core.js"></script> + <script src="tabs_events.js"></script> + <script src="tabs_methods.js"></script> + <script src="tabs_options.js"></script> + <script src="tabs_deprecated.js"></script> + + <script> + function tabs_state( tabs ) { + var expected = $.makeArray( arguments ).slice( 1 ); + var actual = tabs.find( ".ui-tabs-nav li" ).map(function() { + var tab = $( this ), + panel = $( $.ui.tabs.prototype._sanitizeSelector( + "#" + tab.find( "a" ).attr( "aria-controls" ) ) ), + tabIsActive = tab.hasClass( "ui-state-active" ), + panelIsActive = panel.css( "display" ) !== "none"; + + if ( tabIsActive && panelIsActive ) { + return 1; + } + if ( !tabIsActive && !panelIsActive ) { + return 0; + } + return -1; // mixed state - invalid + }).get(); + same( actual, expected ); + } + + function tabs_disabled( tabs, state ) { + var expected = $.map( new Array( tabs.find ( ".ui-tabs-nav li" ).length ), function( _, index ) { + if ( typeof state === "boolean" ) { + return state ? 1 : 0; + } else { + return $.inArray( index, state ) !== -1 ? 1 : 0; + } + }); + + var internalState = tabs.tabs( "option", "disabled" ); + if ( internalState === false ) { + internalState = []; + } + if ( internalState === true ) { + internalState = $.map( new Array( tabs.find( ".ui-tabs-nav li" ).length ), function( _, index ) { + return index; + }); + } + + var actual = tabs.find( ".ui-tabs-nav li" ).map(function( index ) { + var tab = $( this ), + tabIsDisabled = tab.hasClass( "ui-state-disabled" ); + + if ( tabIsDisabled && $.inArray( index, internalState ) !== -1 ) { + return 1; + } + if ( !tabIsDisabled && $.inArray( index, internalState ) === -1 ) { + return 0; + } + return -1; // mixed state - invalid + }).get(); + same( tabs.tabs( "option", "disabled" ), state ); + same( actual, expected ); + } + </script> + <script src="../swarminject.js"></script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Tabs Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +<div id="tabs1"> + <ul> + <li><a href="#fragment-1"><span>1</span></a></li> + <li><a href="#fragment-2"><span>2</span></a></li> + <li><a href="#fragment-3"><span>3</span></a></li> + </ul> + <div id="fragment-1"></div> + <div id="fragment-2"></div> + <div id="fragment-3"></div> +</div> + +<div id="tabs2"> + <ul> + <li><a href="#colon:test"><span>1</span></a></li> + <li><a href="#inline-style"><span>2</span></a></li> + <li><a href="data/test.html#test"><span>3</span></a></li> + <li><a href="data/test.html" aria-controls="custom-id"><span>4</span></a></li> + <li><a href="data/test.html" title="∫ßáö Սե"><span>5</span></a></li> + </ul> + <div id="colon:test"></div> + <div style="height: 300px;" id="inline-style"></div> +</div> + +<div id="tabs3"> + <div> + <ul id="tabs3-list"> + <li><a href="#tabs3-1">1</a></li> + </ul> + </div> +</div> + +<div id="tabs4"> + <ul id="tabs4-list"> + <li><a href="#tabs4-1">1</a></li> + </ul> + <ol> + <li><a href="#tabs4-1">1</a></li> + </ol> +</div> + +<div id="tabs4a"> + <ol id="tabs4a-list"> + <li><a href="#tabs4a-1">1</a></li> + </ol> + <ul> + <li><a href="#tabs4a-1">1</a></li> + </ul> +</div> + +<div id="tabs5"> + <div> + <ul id="tabs5-list"></ul> + </div> +</div> + +<div id="tabs6"> + <ul id="tabs6-list"> + <li><a href="#tabs6-1">1</a> + <ul> + <li><a href="#item6-3">3</a></li> + <li><a href="#item6-4">4</a></li> + </ul> + </li> + <li><a href="#tabs6-2">2</a></li> + </ul> + <div id="tabs6-1"></div> + <div id="tabs6-2"></div> +</div> + +<div id="tabs7"> + <ul id="tabs7-list"> + <li><a href="#tabs7-1">1</a></li> + <li><a href="#tabs7-2">2</a></li> + </ul> + <div id="tabs7-2"></div> + <div id="tabs7-1"></div> +</div> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/tabs_deprecated.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/tabs_deprecated.js new file mode 100644 index 0000000..1323c77 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/tabs_deprecated.js @@ -0,0 +1,576 @@ +(function( $ ) { + +module( "tabs (deprecated): core" ); + +test( "panel ids", function() { + expect( 2 ); + + var element = $( "#tabs2" ).tabs(); + + element.one( "tabsbeforeload", function( event, ui ) { + equal( ui.panel.attr( "id" ), "∫ßáö_Սե", "from title attribute" ); + event.preventDefault(); + }); + element.tabs( "option", "active", 4 ); + + element.one( "tabsbeforeload", function( event, ui ) { + ok( /^ui-tabs-\d+$/.test( ui.panel.attr( "id" ) ), "generated id" ); + event.preventDefault(); + }); + element.tabs( "option", "active", 2 ); +}); + +module( "tabs (deprecated): options" ); + +asyncTest( "ajaxOptions", function() { + expect( 1 ); + + var element = $( "#tabs2" ).tabs({ + ajaxOptions: { + converters: { + "text html": function() { + return "test"; + } + } + } + }); + element.one( "tabsload", function( event, ui ) { + equals( $( ui.panel ).html(), "test" ); + start(); + }); + element.tabs( "option", "active", 2 ); +}); + +asyncTest( "cache", function() { + expect( 5 ); + + var element = $( "#tabs2" ).tabs({ + cache: true + }); + element.one( "tabsshow", function( event, ui ) { + tabs_state( element, 0, 0, 1, 0, 0 ); + }); + element.one( "tabsload", function( event, ui ) { + ok( true, "tabsload" ); + + setTimeout(function() { + element.tabs( "option", "active", 0 ); + tabs_state( element, 1, 0, 0, 0, 0 ); + + element.one( "tabsshow", function( event, ui ) { + tabs_state( element, 0, 0, 1, 0, 0 ); + }); + element.one( "tabsload", function( event, ui ) { + ok( false, "should be cached" ); + }); + element.tabs( "option", "active", 2 ); + start(); + }, 1 ); + }); + element.tabs( "option", "active", 2 ); + tabs_state( element, 0, 0, 1, 0, 0 ); +}); + +test( "idPrefix", function() { + expect( 1 ); + + $( "#tabs2" ) + .one( "tabsbeforeload", function( event, ui ) { + ok( /^testing-\d+$/.test( ui.panel.attr( "id" ) ), "generated id" ); + event.preventDefault(); + }) + .tabs({ + idPrefix: "testing-", + active: 2 + }); +}); + +test( "tabTemplate + panelTemplate", function() { + // 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>" + }); + element.one( "tabsadd", function( event, ui ) { + var anchor = $( ui.tab ); + equal( ui.index, 5, "ui.index" ); + equal( anchor.text(), "New", "ui.tab" ); + equal( anchor.attr( "href" ), "http://example.com/#new", "tab href" ); + ok( anchor.parent().hasClass( "customTab" ), "tab custom class" ); + equal( ui.panel.id, "new", "ui.panel" ); + 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" ); + equals( tab.text(), "New", "label" ); + ok( tab.hasClass( "customTab" ), "tab custom class" ); + equals( anchor.attr( "href" ), "http://example.com/#new", "href" ); + equals( anchor.attr( "aria-controls" ), "new", "aria-controls" ); + ok( element.find( "#new" ).hasClass( "customPanel" ), "panel custom class" ); +}); + +test( "cookie", function() { + expect( 6 ); + + var element = $( "#tabs1" ), + cookieName = "tabs_test", + cookieObj = { name: cookieName }; + $.cookie( cookieName, null ); + function cookie() { + return parseInt( $.cookie( cookieName ), 10 ); + } + + element.tabs({ cookie: cookieObj }); + equals( cookie(), 0, "initial cookie value" ); + + element.tabs( "destroy" ); + element.tabs({ active: 1, cookie: cookieObj }); + equals( cookie(), 1, "initial cookie value, from active property" ); + + element.tabs( "option", "active", 2 ); + equals( cookie(), 2, "cookie value updated after activating" ); + + element.tabs( "destroy" ); + $.cookie( cookieName, 1 ); + element.tabs({ cookie: cookieObj }); + equals( cookie(), 1, "initial cookie value, from existing cookie" ); + + element.tabs( "destroy" ); + element.tabs({ cookie: cookieObj, collapsible: true }); + element.tabs( "option", "active", false ); + equals( cookie(), -1, "cookie value for all tabs unselected" ); + + element.tabs( "destroy" ); + ok( $.cookie( cookieName ) === null, "erase cookie after destroy" ); +}); + +asyncTest( "spinner", function() { + expect( 2 ); + + var element = $( "#tabs2" ).tabs(); + + element.one( "tabsbeforeload", function( event, ui ) { + equals( element.find( ".ui-tabs-nav li:eq(2) em" ).length, 1, "beforeload" ); + }); + element.one( "tabsload", function( event, ui ) { + // wait until after the load finishes before checking for the spinner to be removed + setTimeout(function() { + equals( element.find( ".ui-tabs-nav li:eq(2) em" ).length, 0, "load" ); + start(); + }, 1 ); + }); + element.tabs( "option", "active", 2 ); +}); + +test( "selected", function() { + expect( 19 ); + + var element = $( "#tabs1" ).tabs(); + equals( element.tabs( "option", "selected" ), 0, "should be 0 by default" ); + tabs_state( element, 1, 0, 0 ); + element.tabs( "destroy" ); + + location.hash = "#fragment-3"; + element = $( "#tabs1" ).tabs(); + equals( element.tabs( "option", "selected" ), 2, "should be 2 based on URL" ); + tabs_state( element, 0, 0, 1 ); + element.tabs( "destroy" ); + + el = $('#tabs1').tabs({ + selected: -1, + collapsible: true + }); + tabs_state( element, 0, 0, 0 ); + equal( element.find( ".ui-tabs-nav .ui-state-active" ).size(), 0, "no tabs selected" ); + strictEqual( element.tabs( "option", "selected" ), -1 ); + + element.tabs( "option", "collapsible", false ); + tabs_state( element, 1, 0, 0 ); + equal( element.tabs( "option", "selected" ), 0 ); + element.tabs( "destroy" ); + + element.tabs({ + selected: -1 + }); + tabs_state( element, 1, 0, 0 ); + strictEqual( element.tabs( "option", "selected" ), 0 ); + element.tabs( "destroy" ); + + element.tabs({ selected: 2 }); + equals( element.tabs( "option", "selected" ), 2 ); + tabs_state( element, 0, 0, 1 ); + + element.tabs( "option", "selected", 0 ); + equals( element.tabs( "option", "selected" ), 0 ); + tabs_state( element, 1, 0, 0 ); + + element.find( ".ui-tabs-nav a" ).eq( 1 ).click(); + equals( element.tabs( "option", "selected" ), 1 ); + tabs_state( element, 0, 1, 0 ); + + element.tabs( "option", "selected", 10 ); + equals( element.tabs( "option", "selected" ), 1 ); + tabs_state( element, 0, 1, 0 ); + + location.hash = "#"; +}); + +module( "tabs (deprecated): events" ); + +asyncTest( "load", function() { + expect( 15 ); + + var tab, panelId, panel, + element = $( "#tabs2" ); + + // init + element.one( "tabsload", function( event, ui ) { + tab = element.find( ".ui-tabs-nav a" ).eq( 2 ); + panelId = tab.attr( "aria-controls" ); + panel = $( "#" + panelId ); + + ok( !( "originalEvent" in event ), "originalEvent" ); + strictEqual( ui.tab, tab[ 0 ], "tab" ); + strictEqual( ui.panel, panel[ 0 ], "panel" ); + equals( $( ui.panel ).find( "p" ).length, 1, "panel html" ); + tabs_state( element, 0, 0, 1, 0, 0 ); + tabsload1(); + }); + element.tabs({ active: 2 }); + + function tabsload1() { + // .option() + element.one( "tabsload", function( event, ui ) { + tab = element.find( ".ui-tabs-nav a" ).eq( 3 ); + panelId = tab.attr( "aria-controls" ); + panel = $( "#" + panelId ); + + ok( !( "originalEvent" in event ), "originalEvent" ); + strictEqual( ui.tab, tab[ 0 ], "tab" ); + strictEqual( ui.panel, panel[ 0 ], "panel" ); + equals( $( ui.panel ).find( "p" ).length, 1, "panel html" ); + tabs_state( element, 0, 0, 0, 1, 0 ); + tabsload2(); + }); + element.tabs( "option", "active", 3 ); + } + + function tabsload2() { + // click, change panel content + element.one( "tabsload", function( event, ui ) { + tab = element.find( ".ui-tabs-nav a" ).eq( 4 ); + panelId = tab.attr( "aria-controls" ); + panel = $( "#" + panelId ); + + equals( event.originalEvent.type, "click", "originalEvent" ); + strictEqual( ui.tab, tab[ 0 ], "tab" ); + strictEqual( ui.panel, panel[ 0 ], "panel" ); + equals( $( ui.panel ).find( "p" ).length, 1, "panel html" ); + tabs_state( element, 0, 0, 0, 0, 1 ); + start(); + }); + element.find( ".ui-tabs-nav a" ).eq( 4 ).click(); + } +}); + +test( "enable", function() { + expect( 3 ); + + var element = $( "#tabs1" ).tabs({ + disabled: [ 0, 1 ], + enable: function ( event, ui ) { + equals( ui.tab, element.find( ".ui-tabs-nav a" )[ 1 ], "ui.tab" ); + equals( ui.panel, element.find( ".ui-tabs-panel" )[ 1 ], "ui.panel" ); + equals( ui.index, 1, "ui.index" ); + } + }); + element.tabs( "enable", 1 ); + // shouldn't trigger event + element.tabs( "enable", 2 ); +}); + +test( "disable", function() { + expect( 3 ); + + var element = $( "#tabs1" ).tabs({ + disable: function ( event, ui ) { + equals( ui.tab, element.find( ".ui-tabs-nav a" )[ 1 ], "ui.tab" ); + equals( ui.panel, element.find( ".ui-tabs-panel" )[ 1 ], "ui.panel" ); + equals( ui.index, 1, "ui.index" ); + } + }); + element.tabs( "disable", 1 ); + // shouldn't trigger event + element.tabs( "disable", 1 ); +}); + + +test( "show", function() { + expect( 13 ); + + var element = $( "#tabs1" ).tabs({ + active: false, + collapsible: true + }), + tabs = element.find( ".ui-tabs-nav a" ), + panels = element.find( ".ui-tabs-panel" ); + + // from collapsed + element.one( "tabsshow", function( event, ui ) { + ok( !( "originalEvent" in event ), "originalEvent" ); + strictEqual( ui.tab, tabs[ 0 ], "ui.tab" ); + strictEqual( ui.panel, panels[ 0 ], "ui.panel" ); + equal( ui.index, 0, "ui.index" ); + tabs_state( element, 1, 0, 0 ); + }); + element.tabs( "option", "active", 0 ); + tabs_state( element, 1, 0, 0 ); + + // switching tabs + element.one( "tabsshow", function( event, ui ) { + equals( event.originalEvent.type, "click", "originalEvent" ); + strictEqual( ui.tab, tabs[ 1 ], "ui.tab" ); + strictEqual( ui.panel, panels[ 1 ], "ui.panel" ); + equal( ui.index, 1, "ui.index" ); + tabs_state( element, 0, 1, 0 ); + }); + tabs.eq( 1 ).click(); + tabs_state( element, 0, 1, 0 ); + + // collapsing + element.one( "tabsshow", function( event, ui ) { + ok( false, "collapsing" ); + }); + element.tabs( "option", "active", false ); + tabs_state( element, 0, 0, 0 ); +}); + +test( "select", function() { + expect( 13 ); + + var element = $( "#tabs1" ).tabs({ + active: false, + collapsible: true + }), + tabs = element.find( ".ui-tabs-nav a" ), + panels = element.find( ".ui-tabs-panel" ); + + // from collapsed + element.one( "tabsselect", function( event, ui ) { + ok( !( "originalEvent" in event ), "originalEvent" ); + strictEqual( ui.tab, tabs[ 0 ], "ui.tab" ); + strictEqual( ui.panel, panels[ 0 ], "ui.panel" ); + equal( ui.index, 0, "ui.index" ); + tabs_state( element, 0, 0, 0 ); + }); + element.tabs( "option", "active", 0 ); + tabs_state( element, 1, 0, 0 ); + + // switching tabs + element.one( "tabsselect", function( event, ui ) { + equals( event.originalEvent.type, "click", "originalEvent" ); + strictEqual( ui.tab, tabs[ 1 ], "ui.tab" ); + strictEqual( ui.panel, panels[ 1 ], "ui.panel" ); + equal( ui.index, 1, "ui.index" ); + tabs_state( element, 1, 0, 0 ); + }); + tabs.eq( 1 ).click(); + tabs_state( element, 0, 1, 0 ); + + // collapsing + element.one( "tabsselect", function( event, ui ) { + ok( false, "collapsing" ); + }); + element.tabs( "option", "active", false ); + tabs_state( element, 0, 0, 0 ); +}); + +module( "tabs (deprecated): methods" ); + +test( "add", function() { + expect( 27 ); + + var element = $( "#tabs1" ).tabs(); + tabs_state( element, 1, 0, 0 ); + + // add without index + element.one( "tabsadd", function( event, ui ) { + equal( ui.index, 3, "ui.index" ); + equal( $( ui.tab ).text(), "New", "ui.tab" ); + equal( ui.panel.id, "new", "ui.panel" ); + }); + 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" ); + equals( tab.text(), "New", "label" ); + equals( anchor.attr( "href" ), "#new", "href" ); + equals( anchor.attr( "aria-controls" ), "new", "aria-controls" ); + ok( !tab.hasClass( "ui-state-hover" ), "not hovered" ); + anchor.simulate( "mouseover" ); + ok( tab.hasClass( "ui-state-hover" ), "hovered" ); + anchor.simulate( "click" ); + tabs_state( element, 0, 0, 0, 1 ); + + // add remote tab with index + element.one( "tabsadd", function( event, ui ) { + equal( ui.index, 1, "ui.index" ); + equal( $( ui.tab ).text(), "New Remote", "ui.tab" ); + equal( ui.panel.id, $( ui.tab ).attr( "aria-controls" ), "ui.panel" ); + }); + element.tabs( "add", "data/test.html", "New Remote", 1 ); + tabs_state( element, 0, 0, 0, 0, 1 ); + tab = element.find( ".ui-tabs-nav li" ).eq( 1 ); + anchor = tab.find( "a" ); + equals( tab.text(), "New Remote", "label" ); + equals( anchor.attr( "href" ), "data/test.html", "href" ); + ok( /^ui-tabs-\d+$/.test( anchor.attr( "aria-controls" ) ), "aria controls" ); + ok( !tab.hasClass( "ui-state-hover" ), "not hovered" ); + anchor.simulate( "mouseover" ); + ok( tab.hasClass( "ui-state-hover" ), "hovered" ); + anchor.simulate( "click" ); + tabs_state( element, 0, 1, 0, 0, 0 ); + + // add to empty tab set + element = $( "<div><ul></ul></div>" ).tabs(); + equals( element.tabs( "option", "active" ), false, "active: false on init" ); + element.one( "tabsadd", function( event, ui ) { + equal( ui.index, 0, "ui.index" ); + equal( $( ui.tab ).text(), "First", "ui.tab" ); + equal( ui.panel.id, "first", "ui.panel" ); + }); + element.tabs( "add", "#first", "First" ); + tabs_state( element, 1 ); + equals( element.tabs( "option", "active" ), 0, "active: 0 after add" ); +}); + +test( "#5069 - ui.tabs.add creates two tab panels when using a full URL", function() { + expect( 2 ); + + var element = $( "#tabs2" ).tabs(); + equals( element.children( "div" ).length, element.find( ".ui-tabs-nav li" ).length ); + element.tabs( "add", "/new", "New" ); + equals( element.children( "div" ).length, element.find( ".ui-tabs-nav li" ).length ); +}); + +test( "remove", function() { + expect( 17 ); + + var element = $( "#tabs1" ).tabs({ active: 1 }); + tabs_state( element, 0, 1, 0 ); + + element.one( "tabsremove", function( event, ui ) { + equal( ui.index, -1, "ui.index" ); + equal( $( ui.tab ).text(), "2", "ui.tab" ); + equal( ui.panel.id, "fragment-2", "ui.panel" ); + }); + element.tabs( "remove", 1 ); + tabs_state( element, 0, 1 ); + equals( element.tabs( "option", "active" ), 1 ); + equals( element.find( ".ui-tabs-nav li a[href$='fragment-2']" ).length, 0, + "remove correct list item" ); + equals( element.find( "#fragment-2" ).length, 0, "remove correct panel" ); + + element.one( "tabsremove", function( event, ui ) { + equal( ui.index, -1, "ui.index" ); + equal( $( ui.tab ).text(), "3", "ui.tab" ); + equal( ui.panel.id, "fragment-3", "ui.panel" ); + }); + element.tabs( "remove", 1 ); + tabs_state( element, 1 ); + equals( element.tabs( "option", "active"), 0 ); + + element.one( "tabsremove", function( event, ui ) { + equal( ui.index, -1, "ui.index" ); + equal( $( ui.tab ).text(), "1", "ui.tab" ); + equal( ui.panel.id, "fragment-1", "ui.panel" ); + }); + element.tabs( "remove", 0 ); + equals( element.tabs( "option", "active" ), false ); +}); + +test( "select", function() { + expect( 23 ); + + var element = $( "#tabs1" ).tabs(); + tabs_state( element, 1, 0, 0 ); + element.tabs( "select", 1 ); + tabs_state( element, 0, 1, 0 ); + equals( element.tabs( "option", "active" ), 1, "active" ); + equals( element.tabs( "option", "selected" ), 1, "selected" ); + element.tabs( "destroy" ); + + element.tabs({ collapsible: true }); + tabs_state( element, 1, 0, 0 ); + element.tabs( "select", 0 ); + tabs_state( element, 0, 0, 0 ); + equals( element.tabs( "option", "active" ), false, "active" ); + equals( element.tabs( "option", "selected" ), -1, "selected" ); + element.tabs( "destroy" ); + + element.tabs({ collapsible: true }); + element.tabs( "select", -1 ); + tabs_state( element, 0, 0, 0 ); + equals( element.tabs( "option", "active" ), false, "active" ); + equals( element.tabs( "option", "selected" ), -1, "selected" ); + element.tabs( "destroy" ); + + element.tabs(); + tabs_state( element, 1, 0, 0 ); + equals( element.tabs( "option", "active" ), 0, "active" ); + equals( element.tabs( "option", "selected" ), 0, "selected" ); + element.tabs( "select", 0 ); + tabs_state( element, 1, 0, 0 ); + equals( element.tabs( "option", "active" ), 0, "active" ); + equals( element.tabs( "option", "selected" ), 0, "selected" ); + element.tabs( "select", -1 ); + tabs_state( element, 1, 0, 0 ); + equals( element.tabs( "option", "active" ), 0, "active" ); + equals( element.tabs( "option", "selected" ), 0, "selected" ); + + element.tabs( "select", "#fragment-2" ); + tabs_state( element, 0, 1, 0 ); + equals( element.tabs( "option", "active" ), 1, "active" ); + equals( element.tabs( "option", "selected" ), 1, "selected" ); +}); + +test( "length", function() { + expect( 2 ); + + equals( $( "#tabs1" ).tabs().tabs( "length" ), 3, "basic tabs" ); + equals( $( "#tabs2" ).tabs().tabs( "length" ), 5, "ajax tabs with missing panels" ); +}); + +test( "url", function() { + expect( 2 ); + + var element = $( "#tabs2" ).tabs(), + tab = element.find( "a" ).eq( 3 ); + + element.tabs( "url", 3, "data/test2.html" ); + equals( tab.attr( "href" ), "data/test2.html", "href was updated" ); + element.one( "tabsbeforeload", function( event, ui ) { + equals( ui.ajaxSettings.url, "data/test2.html", "ajaxSettings.url" ); + event.preventDefault(); + }); + element.tabs( "option", "active", 3 ); +}); + +asyncTest( "abort", function() { + expect( 1 ); + + var element = $( "#tabs2" ).tabs(); + element.one( "tabsbeforeload", function( event, ui ) { + ui.jqXHR.error(function( jqXHR, status ) { + equals( status, "abort", "aborted" ); + start(); + }); + }); + element.tabs( "option", "active", 2 ); + element.tabs( "abort" ); +}); + +}( jQuery ) ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/tabs_events.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/tabs_events.js new file mode 100644 index 0000000..f5cde18 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/tabs_events.js @@ -0,0 +1,277 @@ +(function( $ ) { + +module( "tabs: events" ); + +test( "beforeActivate", function() { + expect( 38 ); + + var element = $( "#tabs1" ).tabs({ + active: false, + collapsible: true + }), + tabs = element.find( ".ui-tabs-nav a" ), + panels = element.find( ".ui-tabs-panel" ); + + // from collapsed + element.one( "tabsbeforeactivate", function( event, ui ) { + ok( !( "originalEvent" in event ), "originalEvent" ); + equals( ui.oldTab.size(), 0, "oldTab size" ); + equals( ui.oldPanel.size(), 0, "oldPanel size" ); + equals( ui.newTab.size(), 1, "newTab size" ); + strictEqual( ui.newTab[ 0 ], tabs[ 0 ], "newTab" ); + equals( ui.newPanel.size(), 1, "newPanel size" ); + strictEqual( ui.newPanel[ 0 ], panels[ 0 ], "newPanel" ); + tabs_state( element, 0, 0, 0 ); + }); + element.tabs( "option", "active", 0 ); + tabs_state( element, 1, 0, 0 ); + + // switching tabs + element.one( "tabsbeforeactivate", function( event, ui ) { + equals( event.originalEvent.type, "click", "originalEvent" ); + equals( ui.oldTab.size(), 1, "oldTab size" ); + strictEqual( ui.oldTab[ 0 ], tabs[ 0 ], "oldTab" ); + equals( ui.oldPanel.size(), 1, "oldPanel size" ); + strictEqual( ui.oldPanel[ 0 ], panels[ 0 ], "oldPanel" ); + equals( ui.newTab.size(), 1, "newTab size" ); + strictEqual( ui.newTab[ 0 ], tabs[ 1 ], "newTab" ); + equals( ui.newPanel.size(), 1, "newPanel size" ); + strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" ); + tabs_state( element, 1, 0, 0 ); + }); + tabs.eq( 1 ).click(); + tabs_state( element, 0, 1, 0 ); + + // collapsing + element.one( "tabsbeforeactivate", function( event, ui ) { + ok( !( "originalEvent" in event ), "originalEvent" ); + equals( ui.oldTab.size(), 1, "oldTab size" ); + strictEqual( ui.oldTab[ 0 ], tabs[ 1 ], "oldTab" ); + equals( ui.oldPanel.size(), 1, "oldPanel size" ); + strictEqual( ui.oldPanel[ 0 ], panels[ 1 ], "oldPanel" ); + equals( ui.newTab.size(), 0, "newTab size" ); + equals( ui.newPanel.size(), 0, "newPanel size" ); + tabs_state( element, 0, 1, 0 ); + }); + element.tabs( "option", "active", false ); + tabs_state( element, 0, 0, 0 ); + + // prevent activation + element.one( "tabsbeforeactivate", function( event, ui ) { + ok( !( "originalEvent" in event ), "originalEvent" ); + equals( ui.oldTab.size(), 0, "oldTab size" ); + equals( ui.oldPanel.size(), 0, "oldTab" ); + equals( ui.newTab.size(), 1, "newTab size" ); + strictEqual( ui.newTab[ 0 ], tabs[ 1 ], "newTab" ); + equals( ui.newPanel.size(), 1, "newPanel size" ); + strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" ); + event.preventDefault(); + tabs_state( element, 0, 0, 0 ); + }); + element.tabs( "option", "active", 1 ); + tabs_state( element, 0, 0, 0 ); +}); + +test( "activate", function() { + expect( 30 ); + + var element = $( "#tabs1" ).tabs({ + active: false, + collapsible: true + }), + tabs = element.find( ".ui-tabs-nav a" ), + panels = element.find( ".ui-tabs-panel" ); + + // from collapsed + element.one( "tabsactivate", function( event, ui ) { + ok( !( "originalEvent" in event ), "originalEvent" ); + equals( ui.oldTab.size(), 0, "oldTab size" ); + equals( ui.oldPanel.size(), 0, "oldPanel size" ); + equals( ui.newTab.size(), 1, "newTab size" ); + strictEqual( ui.newTab[ 0 ], tabs[ 0 ], "newTab" ); + equals( ui.newPanel.size(), 1, "newPanel size" ); + strictEqual( ui.newPanel[ 0 ], panels[ 0 ], "newPanel" ); + tabs_state( element, 1, 0, 0 ); + }); + element.tabs( "option", "active", 0 ); + tabs_state( element, 1, 0, 0 ); + + // switching tabs + element.one( "tabsactivate", function( event, ui ) { + equals( event.originalEvent.type, "click", "originalEvent" ); + equals( ui.oldTab.size(), 1, "oldTab size" ); + strictEqual( ui.oldTab[ 0 ], tabs[ 0 ], "oldTab" ); + equals( ui.oldPanel.size(), 1, "oldPanel size" ); + strictEqual( ui.oldPanel[ 0 ], panels[ 0 ], "oldPanel" ); + equals( ui.newTab.size(), 1, "newTab size" ); + strictEqual( ui.newTab[ 0 ], tabs[ 1 ], "newTab" ); + equals( ui.newPanel.size(), 1, "newPanel size" ); + strictEqual( ui.newPanel[ 0 ], panels[ 1 ], "newPanel" ); + tabs_state( element, 0, 1, 0 ); + }); + tabs.eq( 1 ).click(); + tabs_state( element, 0, 1, 0 ); + + // collapsing + element.one( "tabsactivate", function( event, ui ) { + ok( !( "originalEvent" in event ), "originalEvent" ); + equals( ui.oldTab.size(), 1, "oldTab size" ); + strictEqual( ui.oldTab[ 0 ], tabs[ 1 ], "oldTab" ); + equals( ui.oldPanel.size(), 1, "oldPanel size" ); + strictEqual( ui.oldPanel[ 0 ], panels[ 1 ], "oldPanel" ); + equals( ui.newTab.size(), 0, "newTab size" ); + equals( ui.newPanel.size(), 0, "newPanel size" ); + tabs_state( element, 0, 0, 0 ); + }); + element.tabs( "option", "active", false ); + tabs_state( element, 0, 0, 0 ); + + // prevent activation + element.one( "tabsbeforeactivate", function( event ) { + ok( true, "tabsbeforeactivate" ); + event.preventDefault(); + }); + element.one( "tabsactivate", function() { + ok( false, "tabsactivate" ); + }); + element.tabs( "option", "active", 1 ); +}); + +test( "beforeLoad", function() { + expect( 32 ); + + var tab, panelId, panel, + element = $( "#tabs2" ); + + // init + element.one( "tabsbeforeload", function( event, ui ) { + tab = element.find( ".ui-tabs-nav a" ).eq( 2 ); + panelId = tab.attr( "aria-controls" ); + panel = $( "#" + panelId ); + + ok( !( "originalEvent" in event ), "originalEvent" ); + ok( "abort" in ui.jqXHR, "jqXHR" ); + ok( ui.ajaxSettings.url, "data/test.html", "ajaxSettings.url" ); + equals( ui.tab.size(), 1, "tab size" ); + strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" ); + equals( ui.panel.size(), 1, "panel size" ); + strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" ); + equals( ui.panel.html(), "", "panel html" ); + event.preventDefault(); + tabs_state( element, 0, 0, 1, 0, 0 ); + }); + element.tabs({ active: 2 }); + tabs_state( element, 0, 0, 1, 0, 0 ); + equals( panel.html(), "", "panel html after" ); + element.tabs( "destroy" ); + + // .option() + element.one( "tabsbeforeload", function( event, ui ) { + tab = element.find( ".ui-tabs-nav a" ).eq( 2 ); + panelId = tab.attr( "aria-controls" ); + panel = $( "#" + panelId ); + + ok( !( "originalEvent" in event ), "originalEvent" ); + ok( "abort" in ui.jqXHR, "jqXHR" ); + ok( ui.ajaxSettings.url, "data/test.html", "ajaxSettings.url" ); + equals( ui.tab.size(), 1, "tab size" ); + strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" ); + equals( ui.panel.size(), 1, "panel size" ); + strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" ); + equals( ui.panel.html(), "", "panel html" ); + event.preventDefault(); + tabs_state( element, 1, 0, 0, 0, 0 ); + }); + element.tabs(); + element.tabs( "option", "active", 2 ); + tabs_state( element, 0, 0, 1, 0, 0 ); + equals( panel.html(), "", "panel html after" ); + + // click, change panel content + element.one( "tabsbeforeload", function( event, ui ) { + tab = element.find( ".ui-tabs-nav a" ).eq( 3 ); + panelId = tab.attr( "aria-controls" ); + panel = $( "#" + panelId ); + + equals( event.originalEvent.type, "click", "originalEvent" ); + ok( "abort" in ui.jqXHR, "jqXHR" ); + ok( ui.ajaxSettings.url, "data/test.html", "ajaxSettings.url" ); + equals( ui.tab.size(), 1, "tab size" ); + strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" ); + equals( ui.panel.size(), 1, "panel size" ); + strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" ); + ui.panel.html( "<p>testing</p>" ); + event.preventDefault(); + tabs_state( element, 0, 0, 1, 0, 0 ); + }); + element.find( ".ui-tabs-nav a" ).eq( 3 ).click(); + tabs_state( element, 0, 0, 0, 1, 0 ); + // .toLowerCase() is needed to convert <P> to <p> in old IEs + equals( panel.html().toLowerCase(), "<p>testing</p>", "panel html after" ); +}); + +if ( $.uiBackCompat === false ) { + asyncTest( "load", function() { + expect( 21 ); + + var tab, panelId, panel, + element = $( "#tabs2" ); + + // init + element.one( "tabsload", function( event, ui ) { + tab = element.find( ".ui-tabs-nav a" ).eq( 2 ); + panelId = tab.attr( "aria-controls" ); + panel = $( "#" + panelId ); + + ok( !( "originalEvent" in event ), "originalEvent" ); + equals( ui.tab.size(), 1, "tab size" ); + strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" ); + equals( ui.panel.size(), 1, "panel size" ); + strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" ); + equals( ui.panel.find( "p" ).length, 1, "panel html" ); + tabs_state( element, 0, 0, 1, 0, 0 ); + tabsload1(); + }); + element.tabs({ active: 2 }); + + function tabsload1() { + // .option() + element.one( "tabsload", function( event, ui ) { + tab = element.find( ".ui-tabs-nav a" ).eq( 3 ); + panelId = tab.attr( "aria-controls" ); + panel = $( "#" + panelId ); + + ok( !( "originalEvent" in event ), "originalEvent" ); + equals( ui.tab.size(), 1, "tab size" ); + strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" ); + equals( ui.panel.size(), 1, "panel size" ); + strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" ); + equals( ui.panel.find( "p" ).length, 1, "panel html" ); + tabs_state( element, 0, 0, 0, 1, 0 ); + tabsload2(); + }); + element.tabs( "option", "active", 3 ); + } + + function tabsload2() { + // click, change panel content + element.one( "tabsload", function( event, ui ) { + tab = element.find( ".ui-tabs-nav a" ).eq( 4 ); + panelId = tab.attr( "aria-controls" ); + panel = $( "#" + panelId ); + + equals( event.originalEvent.type, "click", "originalEvent" ); + equals( ui.tab.size(), 1, "tab size" ); + strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" ); + equals( ui.panel.size(), 1, "panel size" ); + strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" ); + equals( ui.panel.find( "p" ).length, 1, "panel html" ); + tabs_state( element, 0, 0, 0, 0, 1 ); + start(); + }); + element.find( ".ui-tabs-nav a" ).eq( 4 ).click(); + } + }); +} + +}( jQuery ) ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/tabs_methods.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/tabs_methods.js new file mode 100644 index 0000000..b62f7bb --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/tabs_methods.js @@ -0,0 +1,237 @@ +(function( $ ) { + +module( "tabs: methods" ); + +test( "destroy", function() { + domEqual( "#tabs1", function() { + $( "#tabs1" ).tabs().tabs( "destroy" ); + }); +}); + +test( "enable", function() { + expect( 8 ); + + var element = $( "#tabs1" ).tabs({ disabled: true }); + tabs_disabled( element, true ); + element.tabs( "enable" ); + tabs_disabled( element, false ); + element.tabs( "destroy" ); + + element.tabs({ disabled: [ 0, 1 ] }); + tabs_disabled( element, [ 0, 1 ] ); + element.tabs( "enable" ); + tabs_disabled( element, false ); +}); + +test( "enable( index )", function() { + expect( 10 ); + + var element = $( "#tabs1" ).tabs({ disabled: true }); + tabs_disabled( element, true ); + // fully disabled -> partially disabled + element.tabs( "enable", 1 ); + tabs_disabled( element, [ 0, 2 ] ); + // partially disabled -> partially disabled + element.tabs( "enable", 2 ); + tabs_disabled( element, [ 0 ] ); + // already enabled tab, no change + element.tabs( "enable", 2 ); + tabs_disabled( element, [ 0 ] ); + // partially disabled -> fully enabled + element.tabs( "enable", 0 ); + tabs_disabled( element, false ); +}); + +test( "disable", function() { + expect( 8 ); + + var element = $( "#tabs1" ).tabs({ disabled: false }); + tabs_disabled( element, false ); + element.tabs( "disable" ); + tabs_disabled( element, true ); + element.tabs( "destroy" ); + + element.tabs({ disabled: [ 0, 1 ] }); + tabs_disabled( element, [ 0, 1 ] ); + element.tabs( "disable" ); + tabs_disabled( element, true ); +}); + +test( "disable( index )", function() { + expect( 10 ); + + var element = $( "#tabs1" ).tabs({ disabled: false }); + tabs_disabled( element, false ); + // fully enabled -> partially disabled + element.tabs( "disable", 1 ); + tabs_disabled( element, [ 1 ] ); + // partially disabled -> partially disabled + element.tabs( "disable", 2 ); + tabs_disabled( element, [ 1, 2 ] ); + // already disabled tab, no change + element.tabs( "disable", 2 ); + tabs_disabled( element, [ 1, 2 ] ); + // partially disabled -> fully disabled + element.tabs( "disable", 0 ); + tabs_disabled( element, true ); +}); + +test( "refresh", function() { + expect( 27 ); + + var element = $( "#tabs1" ).tabs(); + tabs_state( element, 1, 0, 0 ); + tabs_disabled( element, false ); + + // disable tab via markup + element.find( ".ui-tabs-nav li" ).eq( 1 ).addClass( "ui-state-disabled" ); + element.tabs( "refresh" ); + tabs_state( element, 1, 0, 0 ); + tabs_disabled( element, [ 1 ] ); + + // add remote tab + element.find( ".ui-tabs-nav" ).append( "<li id='newTab'><a href='data/test.html'>new</a></li>" ); + element.tabs( "refresh" ); + tabs_state( element, 1, 0, 0, 0 ); + tabs_disabled( element, [ 1 ] ); + equals( element.find( "#" + $( "#newTab a" ).attr( "aria-controls" ) ).length, 1, + "panel added for remote tab" ); + + // remove all tabs + element.find( ".ui-tabs-nav li, .ui-tabs-panel" ).remove(); + element.tabs( "refresh" ); + tabs_state( element ); + equals( element.tabs( "option", "active" ), false, "no active tab" ); + + // add tabs + element.find( ".ui-tabs-nav" ) + .append( "<li class='ui-state-disabled'><a href='#newTab2'>new 2</a></li>" ) + .append( "<li><a href='#newTab3'>new 3</a></li>" ) + .append( "<li><a href='#newTab4'>new 4</a></li>" ) + .append( "<li><a href='#newTab5'>new 5</a></li>" ); + element + .append( "<div id='newTab2'>new 2</div>" ) + .append( "<div id='newTab3'>new 3</div>" ) + .append( "<div id='newTab4'>new 4</div>" ) + .append( "<div id='newTab5'>new 5</div>" ); + element.tabs( "refresh" ); + tabs_state( element, 0, 0, 0, 0 ); + tabs_disabled( element, [ 0 ] ); + + // activate third tab + element.tabs( "option", "active", 2 ); + tabs_state( element, 0, 0, 1, 0 ); + tabs_disabled( element, [ 0 ] ); + + // remove fourth tab, third tab should stay active + element.find( ".ui-tabs-nav li" ).eq( 3 ).remove(); + element.find( ".ui-tabs-panel" ).eq( 3 ).remove(); + element.tabs( "refresh" ); + tabs_state( element, 0, 0, 1 ); + tabs_disabled( element, [ 0 ] ); + + // remove third (active) tab, second tab should become active + element.find( ".ui-tabs-nav li" ).eq( 2 ).remove(); + element.find( ".ui-tabs-panel" ).eq( 2 ).remove(); + element.tabs( "refresh" ); + tabs_state( element, 0, 1 ); + tabs_disabled( element, [ 0 ] ); + + // remove first tab, previously active tab (now first) should stay active + element.find( ".ui-tabs-nav li" ).eq( 0 ).remove(); + element.find( ".ui-tabs-panel" ).eq( 0 ).remove(); + element.tabs( "refresh" ); + tabs_state( element, 1 ); + tabs_disabled( element, false ); +}); + +asyncTest( "load", function() { + expect( 30 ); + + var element = $( "#tabs2" ).tabs(); + + // load content of inactive tab + // useful for preloading content with custom caching + element.one( "tabsbeforeload", function( event, ui ) { + var tab = element.find( ".ui-tabs-nav a" ).eq( 3 ), + panelId = tab.attr( "aria-controls" ), + panel = $( "#" + panelId ); + + ok( !( "originalEvent" in event ), "originalEvent" ); + equals( ui.tab.size(), 1, "tab size" ); + strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" ); + equals( ui.panel.size(), 1, "panel size" ); + strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" ); + tabs_state( element, 1, 0, 0, 0, 0 ); + }); + 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 ), + panelId = tab.attr( "aria-controls" ), + panel = $( "#" + panelId ); + + ok( !( "originalEvent" in event ), "originalEvent" ); + equals( uiTab.size(), 1, "tab size" ); + strictEqual( uiTab[ 0 ], tab[ 0 ], "tab" ); + equals( uiPanel.size(), 1, "panel size" ); + strictEqual( uiPanel[ 0 ], panel[ 0 ], "panel" ); + equals( uiPanel.find( "p" ).length, 1, "panel html" ); + tabs_state( element, 1, 0, 0, 0, 0 ); + setTimeout( tabsload1, 100 ); + }); + element.tabs( "load", 3 ); + tabs_state( element, 1, 0, 0, 0, 0 ); + + function tabsload1() { + // no need to test details of event (tested in events tests) + element.one( "tabsbeforeload", function() { + ok( true, "tabsbeforeload invoked" ); + }); + element.one( "tabsload", function() { + ok( true, "tabsload invoked" ); + setTimeout( tabsload2, 100 ); + }); + element.tabs( "option", "active", 3 ); + tabs_state( element, 0, 0, 0, 1, 0 ); + } + + function tabsload2() { + // reload content of active tab + element.one( "tabsbeforeload", function( event, ui ) { + var tab = element.find( ".ui-tabs-nav a" ).eq( 3 ), + panelId = tab.attr( "aria-controls" ), + panel = $( "#" + panelId ); + + ok( !( "originalEvent" in event ), "originalEvent" ); + equals( ui.tab.size(), 1, "tab size" ); + strictEqual( ui.tab[ 0 ], tab[ 0 ], "tab" ); + equals( ui.panel.size(), 1, "panel size" ); + strictEqual( ui.panel[ 0 ], panel[ 0 ], "panel" ); + tabs_state( element, 0, 0, 0, 1, 0 ); + }); + 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 ), + panelId = tab.attr( "aria-controls" ), + panel = $( "#" + panelId ); + + ok( !( "originalEvent" in event ), "originalEvent" ); + equals( uiTab.size(), 1, "tab size" ); + strictEqual( uiTab[ 0 ], tab[ 0 ], "tab" ); + equals( uiPanel.size(), 1, "panel size" ); + strictEqual( uiPanel[ 0 ], panel[ 0 ], "panel" ); + tabs_state( element, 0, 0, 0, 1, 0 ); + start(); + }); + element.tabs( "load", 3 ); + tabs_state( element, 0, 0, 0, 1, 0 ); + } +}); + +}( jQuery ) ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/tabs_options.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/tabs_options.js new file mode 100644 index 0000000..8d61c47 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tabs/tabs_options.js @@ -0,0 +1,213 @@ +(function( $ ) { + +module( "tabs: options" ); + +test( "{ active: default }", function() { + expect( 4 ); + + var element = $( "#tabs1" ).tabs(); + equals( element.tabs( "option", "active" ), 0, "should be 0 by default" ); + tabs_state( element, 1, 0, 0 ); + element.tabs( "destroy" ); + + location.hash = "#fragment-3"; + element = $( "#tabs1" ).tabs(); + equals( element.tabs( "option", "active" ), 2, "should be 2 based on URL" ); + tabs_state( element, 0, 0, 1 ); + element.tabs( "destroy" ); + location.hash = "#"; +}); + +test( "{ active: false }", function() { + expect( 7 ); + + var element = $( "#tabs1" ).tabs({ + active: false, + collapsible: true + }); + tabs_state( element, 0, 0, 0 ); + equal( element.find( ".ui-tabs-nav .ui-state-active" ).size(), 0, "no tabs selected" ); + strictEqual( element.tabs( "option", "active" ), false ); + + element.tabs( "option", "collapsible", false ); + tabs_state( element, 1, 0, 0 ); + equal( element.tabs( "option", "active" ), 0 ); + + element.tabs( "destroy" ); + element.tabs({ + active: false + }); + tabs_state( element, 1, 0, 0 ); + strictEqual( element.tabs( "option", "active" ), 0 ); +}); + +test( "{ active: Number }", function() { + expect( 8 ); + + var element = $( "#tabs1" ).tabs({ + active: 2 + }); + equals( element.tabs( "option", "active" ), 2 ); + tabs_state( element, 0, 0, 1 ); + + element.tabs( "option", "active", 0 ); + equals( element.tabs( "option", "active" ), 0 ); + tabs_state( element, 1, 0, 0 ); + + element.find( ".ui-tabs-nav a" ).eq( 1 ).click(); + equals( element.tabs( "option", "active" ), 1 ); + tabs_state( element, 0, 1, 0 ); + + element.tabs( "option", "active", 10 ); + equals( element.tabs( "option", "active" ), 1 ); + tabs_state( element, 0, 1, 0 ); +}); + +if ( $.uiBackCompat === false ) { + test( "{ active: -Number }", function() { + var element = $( "#tabs1" ).tabs({ + active: -1 + }); + equals( element.tabs( "option", "active" ), 2 ); + tabs_state( element, 0, 0, 1 ); + + element.tabs( "option", "active", -2 ); + equals( element.tabs( "option", "active" ), 1 ); + tabs_state( element, 0, 1, 0 ); + + element.tabs( "option", "active", -10 ); + equals( element.tabs( "option", "active" ), 1 ); + tabs_state( element, 0, 1, 0 ); + + element.tabs( "option", "active", -3 ); + equals( element.tabs( "option", "active" ), 0 ); + tabs_state( element, 1, 0, 0 ); + }); +} + +test( "active - mismatched tab/panel order", function() { + expect( 3 ); + + location.hash = "#tabs7-2"; + var element = $( "#tabs7" ).tabs(); + equals( element.tabs( "option", "active" ), 1, "should be 1 based on URL" ); + tabs_state( element, 0, 1 ); + element.tabs( "option", "active", 0 ); + tabs_state( element, 1, 0 ); + location.hash = "#"; +}); + +test( "{ collapsible: false }", function() { + expect( 4 ); + + var element = $( "#tabs1" ).tabs({ + active: 1 + }); + element.tabs( "option", "active", false ); + equal( element.tabs( "option", "active" ), 1 ); + tabs_state( element, 0, 1, 0 ); + + element.find( ".ui-state-active a" ).eq( 1 ).click(); + equal( element.tabs( "option", "active" ), 1 ); + tabs_state( element, 0, 1, 0 ); +}); + +test( "{ collapsible: true }", function() { + expect( 6 ); + + var element = $( "#tabs1" ).tabs({ + active: 1, + collapsible: true + }); + + element.tabs( "option", "active", false ); + equal( element.tabs( "option", "active" ), false ); + tabs_state( element, 0, 0, 0 ); + + element.tabs( "option", "active", 1 ); + equal( element.tabs( "option", "active" ), 1 ); + tabs_state( element, 0, 1, 0 ); + + element.find( ".ui-state-active a" ).click(); + equal( element.tabs( "option", "active" ), false ); + tabs_state( element, 0, 0, 0 ); +}); + +test( "disabled", function() { + expect( 10 ); + + // fully enabled by default + var element = $( "#tabs1" ).tabs(); + tabs_disabled( element, false ); + + // disable single tab + element.tabs( "option", "disabled", [ 1 ] ); + tabs_disabled( element, [ 1 ] ); + + // disabled active tab + element.tabs( "option", "disabled", [ 0, 1 ] ); + tabs_disabled( element, [ 0, 1 ] ); + + // disable all tabs + element.tabs( "option", "disabled", [ 0, 1, 2 ] ); + tabs_disabled( element, true ); + + // enable all tabs + element.tabs( "option", "disabled", [] ); + tabs_disabled( element, false ); +}); + +test( "{ event: null }", function() { + expect( 5 ); + + var element = $( "#tabs1" ).tabs({ + event: null + }); + tabs_state( element, 1, 0, 0 ); + + element.tabs( "option", "active", 1 ); + equal( element.tabs( "option", "active" ), 1 ); + tabs_state( element, 0, 1, 0 ); + + // ensure default click handler isn't bound + element.find( ".ui-tabs-nav a" ).eq( 2 ).click(); + equal( element.tabs( "option", "active" ), 1 ); + tabs_state( element, 0, 1, 0 ); +}); + +test( "{ event: custom }", function() { + expect( 11 ); + + var element = $( "#tabs1" ).tabs({ + event: "custom1 custom2" + }); + tabs_state( element, 1, 0, 0 ); + + element.find( ".ui-tabs-nav a" ).eq( 1 ).trigger( "custom1" ); + equal( element.tabs( "option", "active" ), 1 ); + tabs_state( element, 0, 1, 0 ); + + // ensure default click handler isn't bound + element.find( ".ui-tabs-nav a" ).eq( 2 ).trigger( "click" ); + equal( element.tabs( "option", "active" ), 1 ); + tabs_state( element, 0, 1, 0 ); + + element.find( ".ui-tabs-nav a" ).eq( 2 ).trigger( "custom2" ); + equal( element.tabs( "option", "active" ), 2 ); + tabs_state( element, 0, 0, 1 ); + + element.tabs( "option", "event", "custom3" ); + + // ensure old event handlers are unbound + element.find( ".ui-tabs-nav a" ).eq( 1 ).trigger( "custom1" ); + equal( element.tabs( "option", "active" ), 2 ); + tabs_state( element, 0, 0, 1 ); + + element.find( ".ui-tabs-nav a" ).eq( 1 ).trigger( "custom3" ); + equal( element.tabs( "option", "active" ), 1 ); + tabs_state( element, 0, 1, 0 ); +}); + +// TODO: add animation tests + +}( jQuery ) ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/testsuite.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/testsuite.js new file mode 100644 index 0000000..c8afcbe --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/testsuite.js @@ -0,0 +1,105 @@ +(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", + "destroy", + "option", + "_trigger" +]; + +function testWidgetOverrides( widget ) { + if ( $.uiBackCompat === false ) { + 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 )[ widget ]().remove(); + ok( true, "initialized on disconnected DOMElement - never connected" ); + + $( defaultElement ).appendTo( "body" ).remove()[ widget ]().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 ); + test( "version", function() { + ok( "version" in $.ui[ widget ].prototype, "version property exists" ); + }); +} + +/* + * Experimental assertion for comparing DOM objects. + * + * Serializes an element and some attributes and it's children if any, otherwise the text. + * Then compares the result using deepEqual. + */ +window.domEqual = function( selector, modifier, message ) { + var 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 = {}; + result.nodeName = value[0].nodeName; + $.each(attributes, function(index, attr) { + result[attr] = value.prop(attr); + }); + result.children = []; + var children = value.children(); + if (children.length) { + children.each(function() { + result.children.push(extract($(this))); + }); + } else { + result.text = value.text(); + } + return result; + } + var expected = extract($(selector)); + modifier($(selector)); + + var actual = extract($(selector)); + QUnit.push( QUnit.equiv(actual, expected), actual, expected, message ); +} + +}()); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/tooltip/all.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tooltip/all.html new file mode 100644 index 0000000..0ef6e09 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tooltip/all.html @@ -0,0 +1,30 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Tooltip Test Suite</title> + + <script src="../../../jquery-1.7.1.js"></script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <link rel="stylesheet" href="../subsuiteRunner.css"> + <script src="../../../external/qunit.js"></script> + <script src="../subsuiteRunner.js"></script> + <script src="../subsuite.js"></script> + + <script> + testAllVersions( "tooltip" ); + </script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Tooltip Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/tooltip/tooltip.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tooltip/tooltip.html new file mode 100644 index 0000000..b5e8558 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tooltip/tooltip.html @@ -0,0 +1,51 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Tooltip Test Suite</title> + + <script src="../../jquery.js"></script> + <script src="../../resource_loader.js"></script> + <script> + loadResources({ + css: [ "ui.core", "ui.tooltip" ], + js: [ + "ui/jquery.ui.core.js", + "ui/jquery.ui.widget.js", + "ui/jquery.ui.position.js", + "ui/jquery.ui.tooltip.js" + ] + }); + </script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <script src="../../../external/qunit.js"></script> + <script src="../../jquery.simulate.js"></script> + <script src="../testsuite.js"></script> + + <script src="tooltip_defaults.js"></script> + <script src="tooltip_core.js"></script> + <script src="tooltip_events.js"></script> + <script src="tooltip_methods.js"></script> + <script src="tooltip_options.js"></script> + + <script src="../swarminject.js"></script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Tooltip Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +<div> + <a id="tooltipped1" href="#" title="anchortitle">anchor</a> + <input title="inputtitle"> + <span id="fixture-span" title="title-text">span</span> +</div> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/tooltip/tooltip_core.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tooltip/tooltip_core.js new file mode 100644 index 0000000..d18b853 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tooltip/tooltip_core.js @@ -0,0 +1,26 @@ +(function( $ ) { + +module( "tooltip: core" ); + +test( "markup structure", function() { + expect( 6 ); + var element = $( "#tooltipped1" ).tooltip(), + tooltip = $( ".ui-tooltip" ); + + equal( element.attr( "aria-describedby" ), undefined, "no aria-describedby on init" ); + equal( tooltip.length, 0, "no tooltip on init" ); + + element.tooltip( "open" ); + tooltip = $( "#" + element.attr( "aria-describedby" ) ); + equal( tooltip.length, 1, "tooltip exists" ); + ok( tooltip.hasClass( "ui-tooltip" ), "tooltip is .ui-tooltip" ); + equal( tooltip.length, 1, ".ui-tooltip exists" ); + equal( tooltip.find( ".ui-tooltip-content" ).length, 1, + ".ui-tooltip-content exists" ); +}); + +test( "accessibility", function() { + // TODO: add tests +}); + +}( jQuery ) ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/tooltip/tooltip_defaults.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tooltip/tooltip_defaults.js new file mode 100644 index 0000000..b8b41bf --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tooltip/tooltip_defaults.js @@ -0,0 +1,20 @@ +commonWidgetTests( "tooltip", { + defaults: { + content: function() {}, + disabled: false, + hide: true, + items: "[title]", + position: { + my: "left+15 center", + at: "right center", + collision: "flipfit flipfit" + }, + show: true, + tooltipClass: null, + + // callbacks + close: null, + create: null, + open: null + } +}); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/tooltip/tooltip_events.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tooltip/tooltip_events.js new file mode 100644 index 0000000..99e1fbd --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tooltip/tooltip_events.js @@ -0,0 +1,83 @@ +(function( $ ) { + +module( "tooltip: events" ); + +test( "programmatic triggers", function() { + expect( 4 ); + var tooltip, + element = $( "#tooltipped1" ).tooltip(); + + element.one( "tooltipopen", function( event, ui ) { + tooltip = ui.tooltip; + ok( !( "originalEvent" in event ), "open" ); + strictEqual( ui.tooltip[0], + $( "#" + element.attr( "aria-describedby" ) )[0], "ui.tooltip" ); + }); + element.tooltip( "open" ); + + element.one( "tooltipclose", function( event, ui ) { + ok( !( "originalEvent" in event ), "close" ); + strictEqual( ui.tooltip[0], tooltip[0], "ui.tooltip" ); + }); + element.tooltip( "close" ); +}); + +test( "mouse events", function() { + expect( 2 ); + var element = $( "#tooltipped1" ).tooltip(); + + element.one( "tooltipopen", function( event ) { + same( event.originalEvent.type, "mouseover" ); + }); + element.trigger( "mouseover" ); + + element.one( "tooltipclose", function( event ) { + same( event.originalEvent.type, "mouseleave" ); + }); + element.trigger( "mouseleave" ); +}); + +test( "focus events", function() { + expect( 2 ); + var element = $( "#tooltipped1" ).tooltip(); + + element.one( "tooltipopen", function( event ) { + same( event.originalEvent.type, "focusin" ); + }); + element.trigger( "focusin" ); + + element.one( "tooltipclose", function( event ) { + same( event.originalEvent.type, "blur" ); + }); + element.trigger( "blur" ); +}); + +asyncTest( "mixed events", function() { + expect( 2 ); + var element = $( "#tooltipped1" ).tooltip(); + + element.one( "tooltipopen", function( event ) { + same( event.originalEvent.type, "focusin" ); + }); + element.simulate( "focus" ); + + element.one( "tooltipopen", function() { + ok( false, "open triggered while already open" ); + }); + element.trigger( "mouseover" ); + + element.bind( "tooltipclose", function( event ) { + ok( false, "close triggered while still focused" ); + }); + element.trigger( "mouseleave" ); + element.unbind( "tooltipclose" ); + + // blurring is async in IE + element.one( "tooltipclose", function( event ) { + same( event.originalEvent.type, "blur" ); + start(); + }); + element.simulate( "blur" ); +}); + +}( jQuery ) ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/tooltip/tooltip_methods.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tooltip/tooltip_methods.js new file mode 100644 index 0000000..74fd35d --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tooltip/tooltip_methods.js @@ -0,0 +1,67 @@ +(function( $ ) { + +module( "tooltip: methods" ); + +test( "destroy", function() { + expect( 2 ); + domEqual( "#tooltipped1", function() { + $( "#tooltipped1" ).tooltip().tooltip( "destroy" ); + }); + + // make sure that open tooltips are removed on destroy + $( "#tooltipped1" ).tooltip().tooltip( "open" ).tooltip( "destroy" ); + equal( $( ".ui-tooltip" ).length, 0 ); +}); + +test( "open/close", function() { + expect( 3 ); + $.fx.off = true; + var element = $( "#tooltipped1" ).tooltip(); + equal( $( ".ui-tooltip" ).length, 0, "no tooltip on init" ); + + element.tooltip( "open" ); + var tooltip = $( "#" + element.attr( "aria-describedby" ) ); + ok( tooltip.is( ":visible" ) ); + + element.tooltip( "close" ); + ok( tooltip.is( ":hidden" ) ); + $.fx.off = false; +}); + +test( "enable/disable", function() { + expect( 7 ); + $.fx.off = true; + var element = $( "#tooltipped1" ).tooltip(); + equal( $( ".ui-tooltip" ).length, 0, "no tooltip on init" ); + + element.tooltip( "open" ); + var tooltip = $( "#" + element.attr( "aria-describedby" ) ); + ok( tooltip.is( ":visible" ) ); + + element.tooltip( "disable" ); + equal( $( ".ui-tooltip" ).length, 0, "no tooltip when disabled" ); + equal( tooltip.attr( "title" ), undefined, "title removed on disable" ); + + element.tooltip( "open" ); + equal( $( ".ui-tooltip" ).length, 0, "open does nothing when disabled" ); + + element.tooltip( "enable" ); + equal( element.attr( "title" ), "anchortitle", "title restored on enable" ); + + element.tooltip( "open" ); + tooltip = $( "#" + element.attr( "aria-describedby" ) ); + ok( tooltip.is( ":visible" ) ); + $.fx.off = false; +}); + +/* +TODO currently tooltip doesn't override widget +can't return anything useful if no element is kept around and there's no useful reference +test("widget", function() { + var tooltip = $("#tooltipped1").tooltip(); + same(tooltip.tooltip("widget")[0], $(".ui-tooltip")[0]); + same(tooltip.tooltip("widget").end()[0], tooltip[0]); +}); +*/ + +}( jQuery ) ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/tooltip/tooltip_options.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tooltip/tooltip_options.js new file mode 100644 index 0000000..04bb4c6 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/tooltip/tooltip_options.js @@ -0,0 +1,73 @@ +(function( $ ) { + +module( "tooltip: options" ); + +test( "content: default", function() { + var element = $( "#tooltipped1" ).tooltip().tooltip( "open" ); + same( $( "#" + element.attr( "aria-describedby" ) ).text(), "anchortitle" ); +}); + +test( "content: return string", function() { + var element = $( "#tooltipped1" ).tooltip({ + content: function() { + return "customstring"; + } + }).tooltip( "open" ); + same( $( "#" + element.attr( "aria-describedby" ) ).text(), "customstring" ); +}); + +test( "content: return jQuery", function() { + var element = $( "#tooltipped1" ).tooltip({ + content: function() { + return $( "<div>" ).html( "cu<b>s</b>tomstring" ); + } + }).tooltip( "open" ); + same( $( "#" + element.attr( "aria-describedby" ) ).text(), "customstring" ); +}); + +asyncTest( "content: sync + async callback", function() { + expect( 2 ); + var element = $( "#tooltipped1" ).tooltip({ + content: function( response ) { + setTimeout(function() { + same( $( "#" + element.attr("aria-describedby") ).text(), "loading..." ); + + response( "customstring2" ); + setTimeout(function() { + same( $( "#" + element.attr("aria-describedby") ).text(), "customstring2" ); + start(); + }, 13 ); + }, 13 ); + return "loading..."; + } + }).tooltip( "open" ); +}); + +test( "items", function() { + expect( 2 ); + var element = $( "#qunit-fixture" ).tooltip({ + items: "#fixture-span" + }); + + var event = $.Event( "mouseenter" ); + event.target = $( "#fixture-span" )[ 0 ]; + element.tooltip( "open", event ); + same( $( "#" + $( "#fixture-span" ).attr( "aria-describedby" ) ).text(), "title-text" ); + + // make sure default [title] doesn't get used + event.target = $( "#tooltipped1" )[ 0 ]; + element.tooltip( "open", event ); + same( $( "#tooltipped1" ).attr( "aria-describedby" ), undefined ); + + element.tooltip( "destroy" ); +}); + +test( "tooltipClass", function() { + expect( 1 ) + var element = $( "#tooltipped1" ).tooltip({ + tooltipClass: "custom" + }).tooltip( "open" ); + ok( $( "#" + element.attr( "aria-describedby" ) ).hasClass( "custom" ) ); +}); + +}( jQuery ) ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/widget/all.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/widget/all.html new file mode 100644 index 0000000..ae8bc3c --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/widget/all.html @@ -0,0 +1,30 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Widget Test Suite</title> + + <script src="../../../jquery-1.7.1.js"></script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <link rel="stylesheet" href="../subsuiteRunner.css"> + <script src="../../../external/qunit.js"></script> + <script src="../subsuiteRunner.js"></script> + <script src="../subsuite.js"></script> + + <script> + testAllVersions( "widget" ); + </script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Widget Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/widget/widget.html b/src/main/webapp/jquery-ui-1.9pre/tests/unit/widget/widget.html new file mode 100644 index 0000000..6f4caaa --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/widget/widget.html @@ -0,0 +1,46 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Widget Test Suite</title> + + <script src="../../jquery.js"></script> + <script src="../../resource_loader.js"></script> + <script> + loadResources({ + css: [ "ui.core" ], + js: [ + "ui/jquery.ui.widget.js" + ] + }); + </script> + + <link rel="stylesheet" href="../../../external/qunit.css"> + <script src="../../../external/qunit.js"></script> + <script src="../../jquery.simulate.js"></script> + <script src="../testsuite.js"></script> + + <script src="widget_core.js"></script> + <script src="widget_extend.js"></script> + <script src="widget_animation.js"></script> + + <script src="../swarminject.js"></script> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Widget Test Suite</h1> +<h2 id="qunit-banner"></h2> +<div id="qunit-testrunner-toolbar"></div> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"></ol> +<div id="qunit-fixture"> + +<div id="widget-wrapper"> + <div id="widget"> + <div>...</div> + </div> +</div> + +</div> +</body> +</html> diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/widget/widget_animation.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/widget/widget_animation.js new file mode 100644 index 0000000..8ef55aa --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/widget/widget_animation.js @@ -0,0 +1,257 @@ + +module( "widget animation", (function() { + var show = $.fn.show, + fadeIn = $.fn.fadeIn, + slideDown = $.fn.slideDown; + return { + setup: function() { + $.widget( "ui.testWidget", { + _create: function() { + this.element.hide(); + }, + show: function( fn ) { + this._show( this.element, this.options.show, fn ); + } + }); + $.effects = { effect: { testEffect: $.noop } }; + }, + teardown: function() { + delete $.ui.testWidget; + delete $.effects.effect.testEffect; + $.fn.show = show; + $.fn.fadeIn = fadeIn; + $.fn.slideDown = slideDown; + } + }; +}())); + +asyncTest( "show: null", function() { + expect( 4 ); + + var element = $( "#widget" ).testWidget(), + hasRun = false; + $.fn.show = function() { + ok( true, "show called" ); + equal( arguments.length, 0, "no args passed to show" ); + }; + + element + .delay( 50 ) + .queue(function( next ) { + ok( !hasRun, "queue before show" ); + next(); + }) + .testWidget( "show", function() { + hasRun = true; + }) + .queue(function( next ) { + ok( hasRun, "queue after show" ); + start(); + next(); + }); +}); + +asyncTest( "show: true", function() { + expect( 4 ); + + var element = $( "#widget" ).testWidget({ + show: true + }), + hasRun = false; + $.fn.fadeIn = function( duration, easing, complete ) { + return this.queue(function( next ) { + strictEqual( duration, undefined, "duration" ); + strictEqual( easing, undefined, "easing" ); + complete(); + next(); + }); + }; + + element + .delay( 50 ) + .queue(function( next ) { + ok( !hasRun, "queue before show" ); + next(); + }) + .testWidget( "show", function() { + hasRun = true; + }) + .queue(function( next ) { + ok( hasRun, "queue after show" ); + start(); + next(); + }); +}); + +asyncTest( "show: number", function() { + expect( 4 ); + + var element = $( "#widget" ).testWidget({ + show: 123 + }), + hasRun = false; + $.fn.fadeIn = function( duration, easing, complete ) { + return this.queue(function( next ) { + strictEqual( duration, 123, "duration" ); + strictEqual( easing, undefined, "easing" ); + complete(); + next(); + }); + }; + + element + .delay( 50 ) + .queue(function( next ) { + ok( !hasRun, "queue before show" ); + next(); + }) + .testWidget( "show", function() { + hasRun = true; + }) + .queue(function( next ) { + ok( hasRun, "queue after show" ); + start(); + next(); + }); +}); + +asyncTest( "show: core animation", function() { + expect( 4 ); + + var element = $( "#widget" ).testWidget({ + show: "slideDown" + }), + hasRun = false; + $.fn.slideDown = function( duration, easing, complete ) { + return this.queue(function( next ) { + strictEqual( duration, undefined, "duration" ); + strictEqual( easing, undefined, "easing" ); + complete(); + next(); + }); + }; + + element + .delay( 50 ) + .queue(function( next ) { + ok( !hasRun, "queue before show" ); + next(); + }) + .testWidget( "show", function() { + hasRun = true; + }) + .queue(function( next ) { + ok( hasRun, "queue after show" ); + start(); + next(); + }); +}); + +asyncTest( "show: effect", function() { + expect( 5 ); + + var element = $( "#widget" ).testWidget({ + show: "testEffect" + }), + hasRun = false; + $.fn.show = function( options ) { + return this.queue(function( next ) { + equal( options.effect, "testEffect", "effect" ); + ok( !("duration" in options), "duration" ); + ok( !("easing" in options), "easing" ); + options.complete(); + next(); + }); + }; + + element + .delay( 50 ) + .queue(function( next ) { + ok( !hasRun, "queue before show" ); + next(); + }) + .testWidget( "show", function() { + hasRun = true; + }) + .queue(function( next ) { + ok( hasRun, "queue after show" ); + start(); + next(); + }); +}); + +asyncTest( "show: object(core animation)", function() { + expect( 4 ); + + var element = $( "#widget" ).testWidget({ + show: { + effect: "slideDown", + duration: 123, + easing: "testEasing" + } + }), + hasRun = false; + $.fn.slideDown = function( duration, easing, complete ) { + return this.queue(function( next ) { + equal( duration, 123, "duration" ); + equal( easing, "testEasing", "easing" ); + complete(); + next(); + }); + }; + + element + .delay( 50 ) + .queue(function( next ) { + ok( !hasRun, "queue before show" ); + next(); + }) + .testWidget( "show", function() { + hasRun = true; + }) + .queue(function( next ) { + ok( hasRun, "queue after show" ); + start(); + next(); + }); +}); + +asyncTest( "show: object(effect)", function() { + expect( 3 ); + + var element = $( "#widget" ).testWidget({ + show: { + effect: "testEffect", + duration: 123, + easing: "testEasing" + } + }), + hasRun = false; + $.fn.show = function( options ) { + return this.queue(function( next ) { + deepEqual( options, { + effect: "testEffect", + duration: 123, + easing: "testEasing", + complete: options.complete + }); + options.complete(); + next(); + }); + }; + + element + .delay( 50 ) + .queue(function( next ) { + ok( !hasRun, "queue before show" ); + next(); + }) + .testWidget( "show", function() { + hasRun = true; + }) + .queue(function( next ) { + ok( hasRun, "queue after show" ); + start(); + next(); + }); +}); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/widget/widget_core.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/widget/widget_core.js new file mode 100644 index 0000000..2e55ad7 --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/widget/widget_core.js @@ -0,0 +1,1069 @@ +(function( $ ) { + +module( "widget factory", { + teardown: function() { + delete $.ui.testWidget; + } +}); + +test( "widget creation", function() { + var myPrototype = { + _create: function() {}, + creationTest: function() {} + }; + + $.widget( "ui.testWidget", myPrototype ); + ok( $.isFunction( $.ui.testWidget ), "constructor was created" ); + equals( "object", typeof $.ui.testWidget.prototype, "prototype was created" ); + equals( $.ui.testWidget.prototype._create, myPrototype._create, + "create function is copied over" ); + equals( $.ui.testWidget.prototype.creationTest, myPrototype.creationTest, + "random function is copied over" ); + equals( $.ui.testWidget.prototype.option, $.Widget.prototype.option, + "option method copied over from base widget" ); +}); + +test( "element normalization", function() { + expect( 11 ); + var elem; + $.widget( "ui.testWidget", {} ); + + $.ui.testWidget.prototype._create = function() { + // workaround for core ticket #8381 + this.element.appendTo( "#qunit-fixture" ); + ok( this.element.is( "div" ), "generated div" ); + same( this.element.data( "testWidget" ), this, "intance stored in .data()" ); + }; + $.ui.testWidget(); + + $.ui.testWidget.prototype.defaultElement = "<span data-test='pass'></span>"; + $.ui.testWidget.prototype._create = function() { + ok( this.element.is( "span[data-test=pass]" ), "generated span with properties" ); + same( this.element.data( "testWidget" ), this, "instace stored in .data()" ); + }; + $.ui.testWidget(); + + elem = $( "<input>" ); + $.ui.testWidget.prototype._create = function() { + same( this.element[ 0 ], elem[ 0 ], "from element" ); + same( elem.data( "testWidget" ), this, "instace stored in .data()" ); + }; + $.ui.testWidget( {}, elem[ 0 ] ); + + elem = $( "<div>" ); + $.ui.testWidget.prototype._create = function() { + same( this.element[ 0 ], elem[ 0 ], "from jQuery object" ); + same( elem.data( "testWidget" ), this, "instace stored in .data()" ); + }; + $.ui.testWidget( {}, elem ); + + elem = $( "<div id='element-normalization-selector'></div>" ) + .appendTo( "#qunit-fixture" ); + $.ui.testWidget.prototype._create = function() { + same( this.element[ 0 ], elem[ 0 ], "from selector" ); + same( elem.data( "testWidget" ), this, "instace stored in .data()" ); + }; + $.ui.testWidget( {}, "#element-normalization-selector" ); + + $.ui.testWidget.prototype.defaultElement = null; + $.ui.testWidget.prototype._create = function() { + // using strictEqual throws an error (Maximum call stack size exceeded) + ok( this.element[ 0 ] === this, "instance as element" ); + }; + $.ui.testWidget(); +}); + +test( "jQuery usage", function() { + expect( 13 ); + + var shouldCreate = false; + + $.widget( "ui.testWidget", { + getterSetterVal: 5, + _create: function() { + ok( shouldCreate, "create called on instantiation" ); + }, + methodWithParams: function( param1, param2 ) { + ok( true, "method called via .pluginName(methodName)" ); + equals( param1, "value1", + "parameter passed via .pluginName(methodName, param)" ); + equals( param2, "value2", + "multiple parameters passed via .pluginName(methodName, param, param)" ); + + return this; + }, + getterSetterMethod: function( val ) { + if ( val ) { + this.getterSetterVal = val; + } else { + return this.getterSetterVal; + } + }, + jQueryObject: function() { + return $( "body" ); + } + }); + + shouldCreate = true; + var elem = $( "<div>" ) + .bind( "testwidgetcreate", function() { + ok( shouldCreate, "create event triggered on instantiation" ); + }) + .testWidget(); + shouldCreate = false; + + var instance = elem.data( "testWidget" ); + equals( typeof instance, "object", "instance stored in .data(pluginName)" ); + equals( instance.element[0], elem[0], "element stored on widget" ); + var ret = elem.testWidget( "methodWithParams", "value1", "value2" ); + equals( ret, elem, "jQuery object returned from method call" ); + + ret = elem.testWidget( "getterSetterMethod" ); + equals( ret, 5, "getter/setter can act as getter" ); + ret = elem.testWidget( "getterSetterMethod", 30 ); + equals( ret, elem, "getter/setter method can be chainable" ); + equals( instance.getterSetterVal, 30, "getter/setter can act as setter" ); + ret = elem.testWidget( "jQueryObject" ); + equal( ret[ 0 ], document.body, "returned jQuery object" ); + equal( ret.end(), elem, "stack preserved" ); +}); + +test( "direct usage", function() { + expect( 9 ); + + var shouldCreate = false; + + $.widget( "ui.testWidget", { + getterSetterVal: 5, + _create: function() { + ok( shouldCreate, "create called on instantiation" ); + }, + methodWithParams: function( param1, param2 ) { + ok( true, "method called dirctly" ); + equals( param1, "value1", "parameter passed via direct call" ); + equals( param2, "value2", "multiple parameters passed via direct call" ); + + return this; + }, + getterSetterMethod: function( val ) { + if ( val ) { + this.getterSetterVal = val; + } else { + return this.getterSetterVal; + } + } + }); + + var elem = $( "<div>" )[ 0 ]; + + shouldCreate = true; + var instance = new $.ui.testWidget( {}, elem ); + shouldCreate = false; + + equals( $( elem ).data( "testWidget" ), instance, + "instance stored in .data(pluginName)" ); + equals( instance.element[ 0 ], elem, "element stored on widget" ); + + var ret = instance.methodWithParams( "value1", "value2" ); + equals( ret, instance, "plugin returned from method call" ); + + ret = instance.getterSetterMethod(); + equals( ret, 5, "getter/setter can act as getter" ); + instance.getterSetterMethod( 30 ); + equals( instance.getterSetterVal, 30, "getter/setter can act as setter" ); +}); + +test( "error handling", function() { + expect( 3 ); + var error = $.error; + $.widget( "ui.testWidget", { + _privateMethod: function () {} + }); + $.error = function( msg ) { + equal( msg, "cannot call methods on testWidget prior to initialization; " + + "attempted to call method 'missing'", "method call before init" ); + }; + $( "<div>" ).testWidget( "missing" ); + $.error = function( msg ) { + equal( msg, "no such method 'missing' for testWidget widget instance", + "invalid method call on widget instance" ); + }; + $( "<div>" ).testWidget().testWidget( "missing" ); + $.error = function ( msg ) { + equal( msg, "no such method '_privateMethod' for testWidget widget instance", + "invalid method call on widget instance" ); + }; + $( "<div>" ).testWidget().testWidget( "_privateMethod" ); + $.error = error; +}); + +test( "merge multiple option arguments", function() { + expect( 1 ); + $.widget( "ui.testWidget", { + _create: function() { + same( this.options, { + create: null, + disabled: false, + option1: "value1", + option2: "value2", + option3: "value3", + option4: { + option4a: "valuea", + option4b: "valueb" + } + }); + } + }); + $( "<div>" ).testWidget({ + option1: "valuex", + option2: "valuex", + option3: "value3", + option4: { + option4a: "valuex" + } + }, { + option1: "value1", + option2: "value2", + option4: { + option4b: "valueb" + } + }, { + option4: { + option4a: "valuea" + } + }); +}); + +test( "._getCreateOptions()", function() { + expect( 1 ); + $.widget( "ui.testWidget", { + options: { + option1: "valuex", + option2: "valuex", + option3: "value3" + }, + _getCreateOptions: function() { + return { + option1: "override1", + option2: "overideX" + }; + }, + _create: function() { + same( this.options, { + create: null, + disabled: false, + option1: "override1", + option2: "value2", + option3: "value3" + }); + } + }); + $( "<div>" ).testWidget({ option2: "value2" }); +}); + +test( "re-init", function() { + var div = $( "<div>" ), + actions = []; + + $.widget( "ui.testWidget", { + _create: function() { + actions.push( "create" ); + }, + _init: function() { + actions.push( "init" ); + }, + _setOption: function( key, value ) { + actions.push( "option" + key ); + } + }); + + actions = []; + div.testWidget({ foo: "bar" }); + same( actions, [ "create", "init" ], "correct methods called on init" ); + + actions = []; + div.testWidget(); + same( actions, [ "init" ], "correct methods call on re-init" ); + + actions = []; + div.testWidget({ foo: "bar" }); + same( actions, [ "optionfoo", "init" ], "correct methods called on re-init with options" ); +}); + +test( "inheritance - options", function() { + // #5830 - Widget: Using inheritance overwrites the base classes options + $.widget( "ui.testWidgetBase", { + options: { + obj: { + key1: "foo", + key2: "bar" + }, + arr: [ "testing" ] + } + }); + + $.widget( "ui.testWidgetExtension", $.ui.testWidgetBase, { + options: { + obj: { + key1: "baz" + }, + arr: [ "alpha", "beta" ] + } + }); + + same( $.ui.testWidgetBase.prototype.options.obj, { + key1: "foo", + key2: "bar" + }, "base class option object not overridden"); + same( $.ui.testWidgetBase.prototype.options.arr, [ "testing" ], + "base class option array not overridden"); + + same( $.ui.testWidgetExtension.prototype.options.obj, { + key1: "baz", + key2: "bar" + }, "extension class option object extends base"); + same( $.ui.testWidgetExtension.prototype.options.arr, [ "alpha", "beta" ], + "extension class option array overwrites base"); + + delete $.ui.testWidgetBase; + delete $.ui.testWidgetExtension; +}); + +test( "._super()", function() { + expect( 9 ); + var instance; + $.widget( "ui.testWidget", { + method: function( a, b ) { + same( this, instance, "this is correct in testWidget" ); + same( a, 5, "parameter passed to testWidget" ); + same( b, 20, "second parameter passed to testWidget" ); + return a + b; + } + }); + + $.widget( "ui.testWidget2", $.ui.testWidget, { + method: function( a, b ) { + same( this, instance, "this is correct in testWidget2" ); + same( a, 5, "parameter passed to testWidget2" ); + same( b, 10, "parameter passed to testWidget2" ); + return this._super( a, b*2 ); + } + }); + + $.widget( "ui.testWidget3", $.ui.testWidget2, { + method: function( a ) { + same( this, instance, "this is correct in testWidget3" ); + same( a, 5, "parameter passed to testWidget3" ); + var ret = this._super( a, a*2 ); + same( ret, 25, "super returned value" ); + } + }); + + instance = $( "<div>" ).testWidget3().data( "testWidget3" ); + instance.method( 5 ); + delete $.ui.testWidget3; + delete $.ui.testWidget2; +}); + +test( "._superApply()", function() { + expect( 10 ); + var instance; + $.widget( "ui.testWidget", { + method: function( a, b ) { + same( this, instance, "this is correct in testWidget" ); + same( a, 5, "parameter passed to testWidget" ); + same( b, 10, "second parameter passed to testWidget" ); + return a + b; + } + }); + + $.widget( "ui.testWidget2", $.ui.testWidget, { + method: function( a, b ) { + same( this, instance, "this is correct in testWidget2" ); + same( a, 5, "parameter passed to testWidget2" ); + same( b, 10, "second parameter passed to testWidget2" ); + return this._superApply( arguments ); + } + }); + + $.widget( "ui.testWidget3", $.ui.testWidget2, { + method: function( a, b ) { + same( this, instance, "this is correct in testWidget3" ); + same( a, 5, "parameter passed to testWidget3" ); + same( b, 10, "second parameter passed to testWidget3" ); + var ret = this._superApply( arguments ); + same( ret, 15, "super returned value" ); + } + }); + + instance = $( "<div>" ).testWidget3().data( "testWidget3" ); + instance.method( 5, 10 ); + delete $.ui.testWidget3; + delete $.ui.testWidget2; +}); + +test( ".option() - getter", function() { + $.widget( "ui.testWidget", { + _create: function() {} + }); + + var div = $( "<div>" ).testWidget({ + foo: "bar", + baz: 5, + qux: [ "quux", "quuux" ] + }); + + same( div.testWidget( "option", "x" ), null, "non-existent option" ); + same( div.testWidget( "option", "foo"), "bar", "single option - string" ); + same( div.testWidget( "option", "baz"), 5, "single option - number" ); + same( div.testWidget( "option", "qux"), [ "quux", "quuux" ], + "single option - array" ); + + var options = div.testWidget( "option" ); + same( options, { + create: null, + disabled: false, + foo: "bar", + baz: 5, + qux: [ "quux", "quuux" ] + }, "full options hash returned" ); + options.foo = "notbar"; + same( div.testWidget( "option", "foo"), "bar", + "modifying returned options hash does not modify plugin instance" ); +}); + +test( ".option() - deep option getter", function() { + $.widget( "ui.testWidget", {} ); + var div = $( "<div>" ).testWidget({ + foo: { + bar: "baz", + qux: { + quux: "xyzzy" + } + } + }); + equal( div.testWidget( "option", "foo.bar" ), "baz", "one level deep - string" ); + deepEqual( div.testWidget( "option", "foo.qux" ), { quux: "xyzzy" }, + "one level deep - object" ); + equal( div.testWidget( "option", "foo.qux.quux" ), "xyzzy", "two levels deep - string" ); + equal( div.testWidget( "option", "x.y" ), null, "top level non-existent" ); + equal( div.testWidget( "option", "foo.x.y" ), null, "one level deep - non-existent" ); +}); + +test( ".option() - delegate to ._setOptions()", function() { + var calls = []; + $.widget( "ui.testWidget", { + _create: function() {}, + _setOptions: function( options ) { + calls.push( options ); + } + }); + var div = $( "<div>" ).testWidget(); + + calls = []; + div.testWidget( "option", "foo", "bar" ); + same( calls, [{ foo: "bar" }], "_setOptions called for single option" ); + + calls = []; + div.testWidget( "option", { + bar: "qux", + quux: "quuux" + }); + same( calls, [{ bar: "qux", quux: "quuux" }], + "_setOptions called with multiple options" ); +}); + +test( ".option() - delegate to ._setOption()", function() { + var calls = []; + $.widget( "ui.testWidget", { + _create: function() {}, + _setOption: function( key, val ) { + calls.push({ + key: key, + val: val + }); + } + }); + var div = $( "<div>" ).testWidget(); + + calls = []; + div.testWidget( "option", "foo", "bar" ); + same( calls, [{ key: "foo", val: "bar" }], + "_setOption called for single option" ); + + calls = []; + div.testWidget( "option", { + bar: "qux", + quux: "quuux" + }); + same( calls, [ + { key: "bar", val: "qux" }, + { key: "quux", val: "quuux" } + ], "_setOption called with multiple options" ); +}); + +test( ".option() - deep option setter", function() { + $.widget( "ui.testWidget", {} ); + var div = $( "<div>" ).testWidget(); + function deepOption( from, to, msg ) { + div.data( "testWidget" ).options.foo = from; + $.ui.testWidget.prototype._setOption = function( key, value ) { + same( key, "foo", msg + ": key" ); + same( value, to, msg + ": value" ); + }; + } + + deepOption( { bar: "baz" }, { bar: "qux" }, "one deep" ); + div.testWidget( "option", "foo.bar", "qux" ); + + deepOption( null, { bar: "baz" }, "null" ); + div.testWidget( "option", "foo.bar", "baz" ); + + deepOption( + { bar: "baz", qux: { quux: "quuux" } }, + { bar: "baz", qux: { quux: "quuux", newOpt: "newVal" } }, + "add property" ); + div.testWidget( "option", "foo.qux.newOpt", "newVal" ); +}); + +test( ".enable()", function() { + expect( 2 ); + $.widget( "ui.testWidget", { + _create: function() {}, + _setOption: function( key, val ) { + same( key, "disabled", "_setOption called with disabled option" ); + same( val, false, "disabled set to false" ); + } + }); + $( "<div>" ).testWidget().testWidget( "enable" ); +}); + +test( ".disable()", function() { + expect( 2 ); + $.widget( "ui.testWidget", { + _create: function() {}, + _setOption: function( key, val ) { + same( key, "disabled", "_setOption called with disabled option" ); + same( val, true, "disabled set to true" ); + } + }); + $( "<div>" ).testWidget().testWidget( "disable" ); +}); + +test( ".widget() - base", function() { + $.widget( "ui.testWidget", { + _create: function() {} + }); + var div = $( "<div>" ).testWidget(); + same( div[0], div.testWidget( "widget" )[0]); +}); + +test( ".widget() - overriden", function() { + var wrapper = $( "<div>" ); + $.widget( "ui.testWidget", { + _create: function() {}, + widget: function() { + return wrapper; + } + }); + same( wrapper[0], $( "<div>" ).testWidget().testWidget( "widget" )[0] ); +}); + +test( "._bind() to element (default)", function() { + expect( 12 ); + var that; + $.widget( "ui.testWidget", { + _create: function() { + that = this; + this._bind({ + keyup: this.keyup, + keydown: "keydown" + }); + }, + keyup: function( event ) { + equals( that, this ); + equals( that.element[0], event.currentTarget ); + equals( "keyup", event.type ); + }, + keydown: function( event ) { + equals( that, this ); + equals( that.element[0], event.currentTarget ); + equals( "keydown", event.type ); + } + }); + var widget = $( "<div></div>" ) + .testWidget() + .trigger( "keyup" ) + .trigger( "keydown" ); + widget + .testWidget( "disable" ) + .trigger( "keyup" ) + .trigger( "keydown" ); + widget + .testWidget( "enable" ) + .trigger( "keyup" ) + .trigger( "keydown" ); + widget + .testWidget( "destroy" ) + .trigger( "keyup" ) + .trigger( "keydown" ); +}); + +test( "._bind() to descendent", function() { + expect( 12 ); + var that; + $.widget( "ui.testWidget", { + _create: function() { + that = this; + this._bind( this.element.find( "strong" ), { + keyup: this.keyup, + keydown: "keydown" + }); + }, + keyup: function( event ) { + equals( that, this ); + equals( that.element.find( "strong" )[0], event.currentTarget ); + equals( "keyup", event.type ); + }, + keydown: function(event) { + equals( that, this ); + equals( that.element.find( "strong" )[0], event.currentTarget ); + equals( "keydown", event.type ); + } + }); + // trigger events on both widget and descendent to ensure that only descendent receives them + var widget = $( "<div><p><strong>hello</strong> world</p></div>" ) + .testWidget() + .trigger( "keyup" ) + .trigger( "keydown" ); + var descendent = widget.find( "strong" ) + .trigger( "keyup" ) + .trigger( "keydown" ); + widget + .testWidget( "disable" ) + .trigger( "keyup" ) + .trigger( "keydown" ); + descendent + .trigger( "keyup" ) + .trigger( "keydown" ); + widget + .testWidget( "enable" ) + .trigger( "keyup" ) + .trigger( "keydown" ); + descendent + .trigger( "keyup" ) + .trigger( "keydown" ); + descendent + .addClass( "ui-state-disabled" ) + .trigger( "keyup" ) + .trigger( "keydown" ); + widget + .testWidget( "destroy" ) + .trigger( "keyup" ) + .trigger( "keydown" ); + descendent + .trigger( "keyup" ) + .trigger( "keydown" ); +}); + +test( "_bind() with delegate", function() { + expect( 8 ); + $.widget( "ui.testWidget", { + _create: function() { + this.element = { + bind: function( event, handler ) { + equal( event, "click.testWidget" ); + ok( $.isFunction(handler) ); + }, + trigger: $.noop + }; + this.widget = function() { + return { + delegate: function( selector, event, handler ) { + equal( selector, "a" ); + equal( event, "click.testWidget" ); + ok( $.isFunction(handler) ); + } + }; + }; + this._bind({ + "click": "handler", + "click a": "handler" + }); + this.widget = function() { + return { + delegate: function( selector, event, handler ) { + equal( selector, "form fieldset > input" ); + equal( event, "change.testWidget" ); + ok( $.isFunction(handler) ); + } + }; + }; + this._bind({ + "change form fieldset > input": "handler" + }); + } + }); + $.ui.testWidget(); +}); + +test( "._hoverable()", function() { + $.widget( "ui.testWidget", { + _create: function() { + this._hoverable( this.element.children() ); + } + }); + + var div = $( "#widget" ).testWidget().children(); + ok( !div.hasClass( "ui-state-hover" ), "not hovered on init" ); + div.trigger( "mouseenter" ); + ok( div.hasClass( "ui-state-hover" ), "hovered after mouseenter" ); + div.trigger( "mouseleave" ); + ok( !div.hasClass( "ui-state-hover" ), "not hovered after mouseleave" ); + + div.trigger( "mouseenter" ); + ok( div.hasClass( "ui-state-hover" ), "hovered after mouseenter" ); + $( "#widget" ).testWidget( "disable" ); + ok( !div.hasClass( "ui-state-hover" ), "not hovered while disabled" ); + div.trigger( "mouseenter" ); + ok( !div.hasClass( "ui-state-hover" ), "can't hover while disabled" ); + $( "#widget" ).testWidget( "enable" ); + ok( !div.hasClass( "ui-state-hover" ), "enabling doesn't reset hover" ); + + div.trigger( "mouseenter" ); + ok( div.hasClass( "ui-state-hover" ), "hovered after mouseenter" ); + $( "#widget" ).testWidget( "destroy" ); + ok( !div.hasClass( "ui-state-hover" ), "not hovered after destroy" ); + div.trigger( "mouseenter" ); + ok( !div.hasClass( "ui-state-hover" ), "event handler removed on destroy" ); +}); + +test( "._focusable()", function() { + $.widget( "ui.testWidget", { + _create: function() { + this._focusable( this.element.children() ); + } + }); + + var div = $( "#widget" ).testWidget().children(); + ok( !div.hasClass( "ui-state-focus" ), "not focused on init" ); + div.trigger( "focusin" ); + ok( div.hasClass( "ui-state-focus" ), "focused after explicit focus" ); + div.trigger( "focusout" ); + ok( !div.hasClass( "ui-state-focus" ), "not focused after blur" ); + + div.trigger( "focusin" ); + ok( div.hasClass( "ui-state-focus" ), "focused after explicit focus" ); + $( "#widget" ).testWidget( "disable" ); + ok( !div.hasClass( "ui-state-focus" ), "not focused while disabled" ); + div.trigger( "focusin" ); + ok( !div.hasClass( "ui-state-focus" ), "can't focus while disabled" ); + $( "#widget" ).testWidget( "enable" ); + ok( !div.hasClass( "ui-state-focus" ), "enabling doesn't reset focus" ); + + div.trigger( "focusin" ); + ok( div.hasClass( "ui-state-focus" ), "focused after explicit focus" ); + $( "#widget" ).testWidget( "destroy" ); + ok( !div.hasClass( "ui-state-focus" ), "not focused after destroy" ); + div.trigger( "focusin" ); + ok( !div.hasClass( "ui-state-focus" ), "event handler removed on destroy" ); +}); + +test( "._trigger() - no event, no ui", function() { + expect( 7 ); + var handlers = []; + + $.widget( "ui.testWidget", { + _create: function() {} + }); + + $( "#widget" ).testWidget({ + foo: function( event, ui ) { + same( event.type, "testwidgetfoo", "correct event type in callback" ); + same( ui, {}, "empty ui hash passed" ); + handlers.push( "callback" ); + } + }); + $( document ).add( "#widget-wrapper" ).add( "#widget" ) + .bind( "testwidgetfoo", function( event, ui ) { + same( ui, {}, "empty ui hash passed" ); + handlers.push( this ); + }); + same( $( "#widget" ).data( "testWidget" )._trigger( "foo" ), true, + "_trigger returns true when event is not cancelled" ); + same( handlers, [ + $( "#widget" )[ 0 ], + $( "#widget-wrapper" )[ 0 ], + document, + "callback" + ], "event bubbles and then invokes callback" ); + + $( document ).unbind( "testwidgetfoo" ); +}); + +test( "._trigger() - cancelled event", function() { + expect( 3 ); + + $.widget( "ui.testWidget", { + _create: function() {} + }); + + $( "#widget" ).testWidget({ + foo: function( event, ui ) { + ok( true, "callback invoked even if event is cancelled" ); + } + }) + .bind( "testwidgetfoo", function( event, ui ) { + ok( true, "event was triggered" ); + return false; + }); + same( $( "#widget" ).data( "testWidget" )._trigger( "foo" ), false, + "_trigger returns false when event is cancelled" ); +}); + +test( "._trigger() - cancelled callback", function() { + $.widget( "ui.testWidget", { + _create: function() {} + }); + + $( "#widget" ).testWidget({ + foo: function( event, ui ) { + return false; + } + }); + same( $( "#widget" ).data( "testWidget" )._trigger( "foo" ), false, + "_trigger returns false when callback returns false" ); +}); + +test( "._trigger() - provide event and ui", function() { + expect( 7 ); + + var originalEvent = $.Event( "originalTest" ); + $.widget( "ui.testWidget", { + _create: function() {}, + testEvent: function() { + var ui = { + foo: "bar", + baz: { + qux: 5, + quux: 20 + } + }; + this._trigger( "foo", originalEvent, ui ); + same( ui, { + foo: "notbar", + baz: { + qux: 10, + quux: "jQuery" + } + }, "ui object modified" ); + } + }); + $( "#widget" ).bind( "testwidgetfoo", function( event, ui ) { + equal( event.originalEvent, originalEvent, "original event object passed" ); + same( ui, { + foo: "bar", + baz: { + qux: 5, + quux: 20 + } + }, "ui hash passed" ); + ui.foo = "notbar"; + }); + $( "#widget-wrapper" ).bind( "testwidgetfoo", function( event, ui ) { + equal( event.originalEvent, originalEvent, "original event object passed" ); + same( ui, { + foo: "notbar", + baz: { + qux: 5, + quux: 20 + } + }, "modified ui hash passed" ); + ui.baz.qux = 10; + }); + $( "#widget" ).testWidget({ + foo: function( event, ui ) { + equal( event.originalEvent, originalEvent, "original event object passed" ); + same( ui, { + foo: "notbar", + baz: { + qux: 10, + quux: 20 + } + }, "modified ui hash passed" ); + ui.baz.quux = "jQuery"; + } + }) + .testWidget( "testEvent" ); +}); + +test( "._trigger() - array as ui", function() { + // #6795 - Widget: handle array arguments to _trigger consistently + expect( 4 ); + + $.widget( "ui.testWidget", { + _create: function() {}, + testEvent: function() { + var ui = { + foo: "bar", + baz: { + qux: 5, + quux: 20 + } + }; + var extra = { + bar: 5 + }; + this._trigger( "foo", null, [ ui, extra ] ); + } + }); + $( "#widget" ).bind( "testwidgetfoo", function( event, ui, extra ) { + same( ui, { + foo: "bar", + baz: { + qux: 5, + quux: 20 + } + }, "event: ui hash passed" ); + same( extra, { + bar: 5 + }, "event: extra argument passed" ); + }); + $( "#widget" ).testWidget({ + foo: function( event, ui, extra ) { + same( ui, { + foo: "bar", + baz: { + qux: 5, + quux: 20 + } + }, "callback: ui hash passed" ); + same( extra, { + bar: 5 + }, "callback: extra argument passed" ); + } + }) + .testWidget( "testEvent" ); +}); + +test( "._trigger() - instance as element", function() { + expect( 4 ); + $.widget( "ui.testWidget", { + defaultElement: null, + testEvent: function() { + var ui = { foo: "bar" }; + this._trigger( "foo", null, ui ); + } + }); + var instance = $.ui.testWidget({ + foo: function( event, ui ) { + equal( event.type, "testwidgetfoo", "event object passed to callback" ); + same( ui, { foo: "bar" }, "ui object passed to callback" ); + } + }); + $( instance ).bind( "testwidgetfoo", function( event, ui ) { + equal( event.type, "testwidgetfoo", "event object passed to event handler" ); + same( ui, { foo: "bar" }, "ui object passed to event handler" ); + }); + instance.testEvent(); +}); + +(function() { + function shouldDestroy( expected, callback ) { + expect( 1 ); + var destroyed = false; + $.widget( "ui.testWidget", { + _create: function() {}, + destroy: function() { + destroyed = true; + } + }); + callback(); + equal( destroyed, expected ); + } + + test( "auto-destroy - .remove()", function() { + shouldDestroy( true, function() { + $( "#widget" ).testWidget().remove(); + }); + }); + + test( "auto-destroy - .remove() on parent", function() { + shouldDestroy( true, function() { + $( "#widget" ).testWidget().parent().remove(); + }); + }); + + test( "auto-destroy - .remove() on child", function() { + shouldDestroy( false, function() { + $( "#widget" ).testWidget().children().remove(); + }); + }); + + test( "auto-destroy - .empty()", function() { + shouldDestroy( false, function() { + $( "#widget" ).testWidget().empty(); + }); + }); + + test( "auto-destroy - .empty() on parent", function() { + shouldDestroy( true, function() { + $( "#widget" ).testWidget().parent().empty(); + }); + }); + + test( "auto-destroy - .detach()", function() { + shouldDestroy( false, function() { + $( "#widget" ).testWidget().detach(); + }); + }); +}()); + +test( "redefine", function() { + expect( 4 ); + $.widget( "ui.testWidget", { + method: function( str ) { + strictEqual( this, instance, "original invoked with correct this" ); + equal( str, "bar", "original invoked with correct parameter" ); + } + }); + $.ui.testWidget.foo = "bar"; + $.widget( "ui.testWidget", $.ui.testWidget, { + method: function( str ) { + equal( str, "foo", "new invoked with correct parameter" ); + this._super( "bar" ); + } + }); + + var instance = new $.ui.testWidget(); + instance.method( "foo" ); + equal( $.ui.testWidget.foo, "bar", "static properties remain" ); +}); + +asyncTest( "_delay", function() { + expect( 6 ); + var order = 0, + that; + $.widget( "ui.testWidget", { + defaultElement: null, + _create: function() { + that = this; + var timer = this._delay(function() { + strictEqual( this, that ); + equal( order, 1 ); + start(); + }, 500); + ok( timer !== undefined ); + timer = this._delay("callback"); + ok( timer !== undefined ); + }, + callback: function() { + strictEqual( this, that ); + equal( order, 0 ); + order += 1; + } + }); + $( "#widget" ).testWidget(); +}); + +}( jQuery ) ); diff --git a/src/main/webapp/jquery-ui-1.9pre/tests/unit/widget/widget_extend.js b/src/main/webapp/jquery-ui-1.9pre/tests/unit/widget/widget_extend.js new file mode 100644 index 0000000..90e686e --- /dev/null +++ b/src/main/webapp/jquery-ui-1.9pre/tests/unit/widget/widget_extend.js @@ -0,0 +1,103 @@ +test( "$.widget.extend()", function() { + expect( 26 ); + + var 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" }, + deep1 = { foo: { bar: true } }, + deep2 = { foo: { baz: true }, foo2: document }, + deep2copy = { foo: { baz: true }, foo2: document }, + deepmerged = { foo: { bar: true, baz: true }, foo2: document }, + arr = [1, 2, 3], + nestedarray = { arr: arr }, + ret; + + $.widget.extend( settings, options ); + deepEqual( settings, merged, "Check if extended: settings must be extended" ); + deepEqual( options, optionsCopy, "Check if not modified: options must not be modified" ); + + $.widget.extend( deep1, deep2 ); + deepEqual( deep1.foo, deepmerged.foo, "Check if foo: settings must be extended" ); + deepEqual( deep2.foo, deep2copy.foo, "Check if not deep2: options must not be modified" ); + equal( deep1.foo2, document, "Make sure that a deep clone was not attempted on the document" ); + + 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 } }; + $.widget.extend( empty, optionsWithLength ); + deepEqual( empty.foo, optionsWithLength.foo, "The length property must copy correctly" ); + + empty = {}; + var 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 } }; + empty = {}; + $.widget.extend( empty, optionsWithCustomObject ); + strictEqual( empty.foo.date, customObject, "Custom objects copy correctly (no methods)" ); + + // Makes the class a little more realistic + myKlass.prototype = { someMethod: function(){} }; + empty = {}; + $.widget.extend( empty, optionsWithCustomObject ); + strictEqual( empty.foo.date, customObject, "Custom objects copy correctly" ); + + ret = $.widget.extend({ foo: 4 }, { foo: new 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, { xnumber2: undefined } ); + strictEqual( nullUndef.xnumber2, options.xnumber2, "Check to make sure undefined values are not 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 }; + $.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: [] }, { foo: [0] } ); // 1907 + equal( ret.foo.length, 1, "Check to make sure a value with coersion 'false' copies over when necessary to fix #1907" ); + + ret = $.widget.extend( { foo: "1,2,3" }, { foo: [1, 2, 3] } ); + strictEqual( typeof ret.foo, "object", "Check to make sure values equal with coersion (but not actually equal) overwrite correctly" ); + + 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 }; + $.widget.extend( obj, { foo:"notnull" } ); + equal( obj.foo, "notnull", "Make sure a null value can be overwritten" ); + + var defaults = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" }, + defaultsCopy = { xnumber1: 5, xnumber2: 7, xstring1: "peter", xstring2: "pan" }, + options1 = { xnumber2: 1, xstring2: "x" }, + options1Copy = { xnumber2: 1, xstring2: "x" }, + options2 = { xstring2: "xx", xxx: "newstringx" }, + options2Copy = { xstring2: "xx", xxx: "newstringx" }, + merged2 = { xnumber1: 5, xnumber2: 1, xstring1: "peter", xstring2: "xx", xxx: "newstringx" }; + + var 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 = { + key: [ 1, 2, 3 ] + }; + var output = $.widget.extend( {}, input ); + deepEqual( input, output, "don't clone arrays" ); + input.key[0] = 10; + deepEqual( input, output, "don't clone arrays" ); +}); |