diff options
author | Scott González <scott.gonzalez@gmail.com> | 2011-01-31 22:04:09 -0500 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2011-01-31 22:04:09 -0500 |
commit | cb8f5b7f2679ab5473229cac432f28c72521048c (patch) | |
tree | 60b63ec0b7f190832dcadef9e04a195985e61621 /tests | |
parent | bb857ddd8d6d4ac7620b49bf765352cd064494c0 (diff) | |
parent | effbb2c0ec2e60bea6ec5e5822ee52f8ea9e18bc (diff) | |
download | jquery-ui-cb8f5b7f2679ab5473229cac432f28c72521048c.tar.gz jquery-ui-cb8f5b7f2679ab5473229cac432f28c72521048c.zip |
Merge branch 'master' into widget-events
Conflicts:
ui/jquery.ui.widget.js
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/accordion/accordio.html | 146 | ||||
-rw-r--r-- | tests/unit/accordion/accordion.html | 94 | ||||
-rw-r--r-- | tests/unit/accordion/accordion_core.js | 73 | ||||
-rw-r--r-- | tests/unit/accordion/accordion_defaults.js | 38 | ||||
-rw-r--r-- | tests/unit/accordion/accordion_defaults_deprecated.js | 21 | ||||
-rw-r--r-- | tests/unit/accordion/accordion_deprecated.js | 320 | ||||
-rw-r--r-- | tests/unit/accordion/accordion_events.js | 123 | ||||
-rw-r--r-- | tests/unit/accordion/accordion_methods.js | 160 | ||||
-rw-r--r-- | tests/unit/accordion/accordion_options.js | 361 | ||||
-rw-r--r-- | tests/unit/accordion/accordion_tickets.js | 9 | ||||
-rw-r--r-- | tests/unit/testsuite.js | 78 | ||||
-rw-r--r-- | tests/unit/widget/widget.html | 24 | ||||
-rw-r--r-- | tests/unit/widget/widget_core.js | 103 | ||||
-rw-r--r-- | tests/unit/widget/widget_tickets.js | 5 |
14 files changed, 1079 insertions, 476 deletions
diff --git a/tests/unit/accordion/accordio.html b/tests/unit/accordion/accordio.html new file mode 100644 index 000000000..db202fe43 --- /dev/null +++ b/tests/unit/accordion/accordio.html @@ -0,0 +1,146 @@ +<!DOCTYPE html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Accordion Test Suite</title> + + <link rel="stylesheet" href="../../../themes/base/jquery.ui.accordion.css"> + + <script src="../../../jquery-1.4.4.js"></script> + <script src="../../../ui/jquery.ui.core.js"></script> + <script src="../../../ui/jquery.ui.widget.js"></script> + <script src="../../../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> + function 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(); + same( actual, expected ); + } + function 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 ] ); + same( sizes[ 0 ], sizes[ 1 ] ); + same( sizes[ 0 ], sizes[ 2 ] ); + } + function accordionSetupTeardown() { + var animated = $.ui.accordion.prototype.options.animated; + return { + setup: function() { + $.ui.accordion.prototype.options.animated = false; + }, + teardown: function() { + $.ui.accordion.prototype.options.animated = animated; + } + }; + } + </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_tickets.js"></script> + <script src="accordion_deprecated.js"></script> + + <script src="../swarminject.js"></script> + <style> + #main { font-size: 10pt; font-family: "trebuchet ms", verdana, arial; } + #list, #list1 *, #navigation, #navigation * { margin: 0; padding: 0; font-size: 12px; } + </style> +</head> +<body> + +<h1 id="qunit-header">jQuery UI Accordion Test Suite</h1> +<h2 id="qunit-banner"></h2> +<h2 id="qunit-userAgent"></h2> +<ol id="qunit-tests"> +</ol> + +<div id="main" style="position: absolute; top: -10000px; left: -10000px;"> + + <div> + <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> + +<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 Drums</a></li> + <li><a href="?p=1.1.3.3">Electronic Drums</a></li> + <li><a href="?p=1.1.3.6">Accessories</a></li> + </ul> + </li> + </ul> +</div> + +</div> + +</body> +</html> diff --git a/tests/unit/accordion/accordion.html b/tests/unit/accordion/accordion.html index 61d168386..23380000e 100644 --- a/tests/unit/accordion/accordion.html +++ b/tests/unit/accordion/accordion.html @@ -1,55 +1,65 @@ <!DOCTYPE html> <html lang="en"> <head> - <meta charset="UTF-8" /> + <meta charset="utf-8"> <title>jQuery UI Accordion Test Suite</title> - <link type="text/css" href="../../../themes/base/jquery.ui.accordion.css" rel="stylesheet" /> + <link rel="stylesheet" href="../../../themes/base/jquery.ui.accordion.css"> - <script type="text/javascript" src="../../../jquery-1.4.4.js"></script> - <script type="text/javascript" src="../../../ui/jquery.ui.core.js"></script> - <script type="text/javascript" src="../../../ui/jquery.ui.widget.js"></script> - <script type="text/javascript" src="../../../ui/jquery.ui.accordion.js"></script> - - <link rel="stylesheet" href="../../../external/qunit.css" type="text/css"/> - <script type="text/javascript" src="../../../external/qunit.js"></script> - <script type="text/javascript" src="../../jquery.simulate.js"></script> - <script type="text/javascript" src="../testsuite.js"></script> + <script src="../../../jquery-1.4.4.js"></script> + <script> + $.uiBackCompat = false; + </script> + <script src="../../../ui/jquery.ui.core.js"></script> + <script src="../../../ui/jquery.ui.widget.js"></script> + <script src="../../../ui/jquery.ui.accordion.js"></script> - <script type="text/javascript"> - $.ui.accordion.prototype.options.animated = false; + <link rel="stylesheet" href="../../../external/qunit.css"> + <script src="../../../external/qunit.js"></script> + <script src="../../jquery.simulate.js"></script> + <script src="../testsuite.js"></script> - function state(accordion) { - var args = $.makeArray(arguments).slice(1); - var result = []; - $.each(args, function(i, n) { - result.push( accordion.find(".ui-accordion-content").eq(i).filter(function() { - return $(this).css("display") != "none" - }).length ? 1 : 0 ); - }); - same(args, result) - } - function 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] ); - same(sizes[0], sizes[1]); - same(sizes[0], sizes[2]); - } + <script> + function 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(); + same( actual, expected ); + } + function 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 ] ); + same( sizes[ 0 ], sizes[ 1 ] ); + same( sizes[ 0 ], sizes[ 2 ] ); + } + function accordionSetupTeardown() { + var animated = $.ui.accordion.prototype.options.animated; + return { + setup: function() { + $.ui.accordion.prototype.options.animated = false; + }, + teardown: function() { + $.ui.accordion.prototype.options.animated = animated; + } + }; + } </script> - <script type="text/javascript" src="accordion_core.js"></script> - <script type="text/javascript" src="accordion_defaults.js"></script> - <script type="text/javascript" src="accordion_events.js"></script> - <script type="text/javascript" src="accordion_methods.js"></script> - <script type="text/javascript" src="accordion_options.js"></script> - <script type="text/javascript" src="accordion_tickets.js"></script> - - <script type="text/javascript" src="../swarminject.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="accordion_tickets.js"></script> + + <script src="../swarminject.js"></script> <style> - #main { font-size: 10pt; font-family: 'trebuchet ms', verdana, arial; } - #list, #list1 *, #navigation, #navigation * { margin: 0; padding: 0; font-size: 12px; } + #main { font-size: 10pt; font-family: "trebuchet ms", verdana, arial; } + #list, #list1 *, #navigation, #navigation * { margin: 0; padding: 0; font-size: 12px; } </style> </head> <body> diff --git a/tests/unit/accordion/accordion_core.js b/tests/unit/accordion/accordion_core.js index 40a711abf..24dc0146b 100644 --- a/tests/unit/accordion/accordion_core.js +++ b/tests/unit/accordion/accordion_core.js @@ -1,40 +1,47 @@ -/* - * accordion_core.js - */ - - -(function($) { - -module("accordion: core"); - -test("handle click on header-descendant", function() { - var ac = $('#navigation').accordion({ autoHeight: false }); - $('#navigation h2:eq(1) a').trigger("click"); - state(ac, 0, 1, 0); +(function( $ ) { + +module( "accordion: core", accordionSetupTeardown() ); + +test( "markup structure", function() { + var ac = $( "#navigation" ).accordion(); + ok( ac.hasClass( "ui-accordion" ), "main element is .ui-accordion" ); + equal( ac.find( ".ui-accordion-header" ).length, 3, + ".ui-accordion-header elements exist, correct number" ); + equal( ac.find( ".ui-accordion-content" ).length, 3, + ".ui-accordion-content elements exist, correct number" ); + same( ac.find( ".ui-accordion-header" ).next().get(), + ac.find( ".ui-accordion-content" ).get(), + "content panels come immediately after headers" ); }); -test("ui-accordion-heading class added to headers anchor", function() { - expect(1); - var ac = $("#list1").accordion(); - var anchors = $(".ui-accordion-heading"); - equals( anchors.length, "3"); +test( "handle click on header-descendant", function() { + var ac = $( "#navigation" ).accordion(); + $( "#navigation h2:eq(1) a" ).click(); + state( ac, 0, 1, 0 ); }); -test("accessibility", function () { - expect(9); - var ac = $('#list1').accordion().accordion("option", "active", 1); - var headers = $(".ui-accordion-header"); +test( "ui-accordion-heading class added to headers anchor", function() { + expect( 1 ); + var ac = $( "#list1" ).accordion(); + var anchors = $( ".ui-accordion-heading" ); + equals( anchors.length, 3 ); +}); - equals( headers.eq(1).attr("tabindex"), "0", "active header should have tabindex=0"); - equals( headers.eq(0).attr("tabindex"), "-1", "inactive header should have tabindex=-1"); - equals( ac.attr("role"), "tablist", "main role"); - equals( headers.attr("role"), "tab", "tab roles"); - equals( headers.next().attr("role"), "tabpanel", "tabpanel roles"); - equals( headers.eq(1).attr("aria-expanded"), "true", "active tab has aria-expanded"); - equals( headers.eq(0).attr("aria-expanded"), "false", "inactive tab has aria-expanded"); - ac.accordion("option", "active", 0); - equals( headers.eq(0).attr("aria-expanded"), "true", "newly active tab has aria-expanded"); - equals( headers.eq(1).attr("aria-expanded"), "false", "newly inactive tab has aria-expanded"); +test( "accessibility", function () { + expect( 9 ); + var ac = $( "#list1" ).accordion().accordion( "option", "active", 1 ); + var headers = $( ".ui-accordion-header" ); + + equals( headers.eq( 1 ).attr( "tabindex" ), 0, "active header should have tabindex=0" ); + equals( headers.eq( 0 ).attr( "tabindex" ), -1, "inactive header should have tabindex=-1" ); + equals( ac.attr( "role" ), "tablist", "main role" ); + equals( headers.attr( "role" ), "tab", "tab roles" ); + equals( headers.next().attr( "role" ), "tabpanel", "tabpanel roles" ); + equals( headers.eq( 1 ).attr( "aria-expanded" ), "true", "active tab has aria-expanded" ); + equals( headers.eq( 0 ).attr( "aria-expanded" ), "false", "inactive tab has aria-expanded" ); + ac.accordion( "option", "active", 0 ); + equals( headers.eq( 0 ).attr( "aria-expanded" ), "true", "newly active tab has aria-expanded" ); + equals( headers.eq( 1 ).attr( "aria-expanded" ), "false", "newly inactive tab has aria-expanded" ); }); -})(jQuery); +}( jQuery ) ); diff --git a/tests/unit/accordion/accordion_defaults.js b/tests/unit/accordion/accordion_defaults.js index d29c1e848..95a478057 100644 --- a/tests/unit/accordion/accordion_defaults.js +++ b/tests/unit/accordion/accordion_defaults.js @@ -1,23 +1,15 @@ -/* - * accordion_defaults.js - */ - -var accordion_defaults = { - active: 0, - animated: false, - autoHeight: true, - clearStyle: false, - collapsible: false, - disabled: false, - event: "click", - fillSpace: false, - header: "> li > :first-child,> :not(li):even", - heightStyle: null, - icons: { "header": "ui-icon-triangle-1-e", - "activeHeader": null, - "headerSelected": "ui-icon-triangle-1-s" }, - navigation: false, - navigationFilter: function() {} -}; - -commonWidgetTests('accordion', { defaults: accordion_defaults }); +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" + } + } +}); diff --git a/tests/unit/accordion/accordion_defaults_deprecated.js b/tests/unit/accordion/accordion_defaults_deprecated.js new file mode 100644 index 000000000..b90b472e2 --- /dev/null +++ b/tests/unit/accordion/accordion_defaults_deprecated.js @@ -0,0 +1,21 @@ +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() {} + } +}); diff --git a/tests/unit/accordion/accordion_deprecated.js b/tests/unit/accordion/accordion_deprecated.js new file mode 100644 index 000000000..07974e75e --- /dev/null +++ b/tests/unit/accordion/accordion_deprecated.js @@ -0,0 +1,320 @@ +(function( $ ) { + +module( "accordion (deprecated): expanded active option, activate method", accordionSetupTeardown() ); + +test( "activate, numeric", function() { + var ac = $( "#list1" ).accordion({ active: 1 }); + state( ac, 0, 1, 0 ); + ac.accordion( "activate", 2 ); + state( ac, 0, 0, 1 ); + ac.accordion( "activate", 0 ); + state( ac, 1, 0, 0 ); + ac.accordion( "activate", 1 ); + state( ac, 0, 1, 0 ); + ac.accordion( "activate", 2 ); + state( ac, 0, 0, 1 ); +}); + +test( "activate, numeric, collapsible:true", function() { + var ac = $( "#list1" ).accordion({ collapsible: true }); + ac.accordion( "activate", 2 ); + state( ac, 0, 0, 1 ); + ac.accordion( "activate", 0 ); + state( ac, 1, 0, 0 ); + ac.accordion( "activate", -1 ); + state( ac, 0, 0, 0 ); +}); + +test( "activate, boolean, collapsible: true", function() { + var ac = $( "#list1" ).accordion({ collapsible: true }); + ac.accordion( "activate", 2 ); + state( ac, 0, 0, 1 ); + ac.accordion( "activate", false ); + state( ac, 0, 0, 0 ); +}); + +test( "activate, boolean, collapsible: false", function() { + var ac = $( "#list1" ).accordion(); + ac.accordion( "activate", 2 ); + state( ac, 0, 0, 1 ); + ac.accordion( "activate", false ); + state( ac, 0, 0, 1 ); +}); + +test( "activate, string expression", function() { + var ac = $( "#list1" ).accordion({ active: "h3:last" }); + state( ac, 0, 0, 1 ); + ac.accordion( "activate", ":first" ); + state( ac, 1, 0, 0 ); + ac.accordion( "activate", ":eq(1)" ); + state( ac, 0, 1, 0 ); + ac.accordion( "activate", ":last" ); + state( ac, 0, 0, 1 ); +}); + +test( "activate, jQuery or DOM element", function() { + var ac = $( "#list1" ).accordion({ active: $( "#list1 h3:last" ) }); + state( ac, 0, 0, 1 ); + ac.accordion( "activate", $( "#list1 h3:first" ) ); + state( ac, 1, 0, 0 ); + ac.accordion( "activate", $( "#list1 h3" )[ 1 ] ); + state( ac, 0, 1, 0 ); +}); + +test( "{ active: Selector }", function() { + var ac = $("#list1").accordion({ + active: "h3:last" + }); + state( ac, 0, 0, 1 ); + ac.accordion( "option", "active", "h3:eq(1)" ); + state( ac, 0, 1, 0 ); +}); + +test( "{ active: Element }", function() { + var ac = $( "#list1" ).accordion({ + active: $( "#list1 h3:last" )[ 0 ] + }); + state( ac, 0, 0, 1 ); + ac.accordion( "option", "active", $( "#list1 h3:eq(1)" )[ 0 ] ); + state( ac, 0, 1, 0 ); +}); + +test( "{ active: jQuery Object }", function() { + var ac = $( "#list1" ).accordion({ + active: $( "#list1 h3:last" ) + }); + state( ac, 0, 0, 1 ); + ac.accordion( "option", "active", $( "#list1 h3:eq(1)" ) ); + state( ac, 0, 1, 0 ); +}); + + + + + +module( "accordion (deprecated) - height options", accordionSetupTeardown() ); + +test( "{ autoHeight: true }, default", function() { + equalHeights($('#navigation').accordion({ autoHeight: true }), 95, 130); +}); + +test("{ autoHeight: false }", function() { + var accordion = $('#navigation').accordion({ autoHeight: false }); + var sizes = []; + accordion.find(".ui-accordion-content").each(function() { + sizes.push($(this).height()); + }); + ok( sizes[0] >= 70 && sizes[0] <= 90, "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() { + $( "#navigationWrapper" ).height( 500 ); + var ac = $( "#navigation" ).accordion({ fillSpace: true }); + equalHeights( ac, 446, 458 ); +}); + +test( "{ fillSapce: true } with sibling", function() { + $( "#navigationWrapper" ).height( 500 ); + $( "<p>Lorem Ipsum</p>" ) + .css({ + height: 50, + marginTop: 20, + marginBottom: 30 + }) + .prependTo( "#navigationWrapper" ); + var ac = $( "#navigation" ).accordion({ fillSpace: true }); + equalHeights( ac , 346, 358); +}); + +test( "{ fillSpace: true } with multiple siblings", function() { + $( "#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 ac = $( "#navigation" ).accordion({ fillSpace: true }); + equalHeights( ac, 296, 308 ); +}); + + + + + +module( "accordion (deprecated) - icons", accordionSetupTeardown() ); + +test( "icons, headerSelected", function() { + var list = $( "#list1" ).accordion({ + icons: { headerSelected: "a1", header: "h1" } + }); + ok( list.find( ".ui-accordion-header.ui-state-active span.ui-icon" ).hasClass( "a1" ) ); + list.accordion( "option", "icons", { headerSelected: "a2", header: "h2" } ); + ok( !list.find( ".ui-accordion-header.ui-state-active span.ui-icon" ).hasClass( "a1" ) ); + ok( list.find( ".ui-accordion-header.ui-state-active span.ui-icon" ).hasClass( "a2" ) ); +}); + + + + + +module( "accordion (deprecated) - resize", accordionSetupTeardown() ); + +test( "resize", function() { + var expected = $( "#navigation" ) + .parent() + .height( 300 ) + .end() + .accordion({ + heightStyle: "fill" + }); + equalHeights( expected, 246, 258 ); + + expected.parent().height( 500 ); + expected.accordion( "resize" ); + equalHeights( expected, 446, 458 ); +}); + + + + + +module( "accordion (deprecated) - navigation", accordionSetupTeardown() ); + +test( "{ navigation: true, navigationFilter: header }", function() { + var ac = $( "#navigation" ).accordion({ + navigation: true, + navigationFilter: function() { + return /\?p=1\.1\.3$/.test( this.href ); + } + }); + equal( ac.accordion( "option", "active" ), 2 ); + state( ac, 0, 0, 1 ); +}); + +test( "{ navigation: true, navigationFilter: content }", function() { + var ac = $("#navigation").accordion({ + navigation: true, + navigationFilter: function() { + return /\?p=1\.1\.3\.2$/.test(this.href); + } + }); + equal( ac.accordion( "option", "active" ), 2 ); + state( ac, 0, 0, 1 ); +}); + + + + + +module( "accordion (deprecated) - changestart/change events", accordionSetupTeardown() ); + +test( "changestart", function() { + expect( 26 ); + var ac = $( "#list1" ).accordion({ + active: false, + collapsible: true + }); + var headers = ac.find( ".ui-accordion-header" ); + var content = ac.find( ".ui-accordion-content" ); + + ac.one( "accordionchangestart", function( event, ui ) { + equals( ui.oldHeader.size(), 0 ); + equals( ui.oldContent.size(), 0 ); + equals( ui.newHeader.size(), 1 ); + strictEqual( ui.newHeader[ 0 ], headers[ 0 ] ); + equals( ui.newContent.size(), 1 ); + strictEqual( ui.newContent[ 0 ], content[ 0 ] ); + state( ac, 0, 0, 0 ); + }); + ac.accordion( "option", "active", 0 ); + state( ac, 1, 0, 0 ); + + ac.one( "accordionchangestart", function( event, ui ) { + equals( ui.oldHeader.size(), 1 ); + strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] ); + equals( ui.oldContent.size(), 1 ); + strictEqual( ui.oldContent[ 0 ], content[ 0 ] ); + equals( ui.newHeader.size(), 1 ); + strictEqual( ui.newHeader[ 0 ], headers[ 1 ] ); + equals( ui.newContent.size(), 1 ); + strictEqual( ui.newContent[ 0 ], content[ 1 ] ); + state( ac, 1, 0, 0 ); + }); + headers.eq( 1 ).click(); + state( ac, 0, 1, 0 ); + + ac.one( "accordionchangestart", function( event, ui ) { + equals( ui.oldHeader.size(), 1 ); + strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] ); + equals( ui.oldContent.size(), 1 ); + strictEqual( ui.oldContent[ 0 ], content[ 1 ] ); + equals( ui.newHeader.size(), 0 ); + equals( ui.newContent.size(), 0 ); + state( ac, 0, 1, 0 ); + }); + ac.accordion( "option", "active", false ); + state( ac, 0, 0, 0 ); +}); + +test( "change", function() { + expect( 20 ); + var ac = $( "#list1" ).accordion({ + active: false, + collapsible: true + }); + var headers = ac.find( ".ui-accordion-header" ); + var content = ac.find( ".ui-accordion-content" ); + + ac.one( "accordionchange", function( event, ui ) { + equals( ui.oldHeader.size(), 0 ); + equals( ui.oldContent.size(), 0 ); + equals( ui.newHeader.size(), 1 ); + strictEqual( ui.newHeader[ 0 ], headers[ 0 ] ); + equals( ui.newContent.size(), 1 ); + strictEqual( ui.newContent[ 0 ], content[ 0 ] ); + }); + ac.accordion( "option", "active", 0 ); + + ac.one( "accordionchange", function( event, ui ) { + equals( ui.oldHeader.size(), 1 ); + strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] ); + equals( ui.oldContent.size(), 1 ); + strictEqual( ui.oldContent[ 0 ], content[ 0 ] ); + equals( ui.newHeader.size(), 1 ); + strictEqual( ui.newHeader[ 0 ], headers[ 1 ] ); + equals( ui.newContent.size(), 1 ); + strictEqual( ui.newContent[ 0 ], content[ 1 ] ); + }); + headers.eq( 1 ).click(); + + ac.one( "accordionchange", function( event, ui ) { + equals( ui.oldHeader.size(), 1 ); + strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] ); + equals( ui.oldContent.size(), 1 ); + strictEqual( ui.oldContent[ 0 ], content[ 1 ] ); + equals( ui.newHeader.size(), 0 ); + equals( ui.newContent.size(), 0 ); + }); + ac.accordion( "option", "active", false ); +}); + +})(jQuery); diff --git a/tests/unit/accordion/accordion_events.js b/tests/unit/accordion/accordion_events.js index 4798f7404..0b9f14706 100644 --- a/tests/unit/accordion/accordion_events.js +++ b/tests/unit/accordion/accordion_events.js @@ -1,30 +1,121 @@ -/* - * accordion_events.js - */ -(function($) { +(function( $ ) { -module("accordion: events"); +module( "accordion: events", accordionSetupTeardown() ); -test("accordionchange event, open closed and close again", function() { - expect(8); - $("#list1").accordion({ +test( "beforeActivate", function() { + expect( 42 ); + var ac = $( "#list1" ).accordion({ active: false, collapsible: true - }) - .one("accordionchange", function(event, ui) { + }); + var headers = ac.find( ".ui-accordion-header" ); + var content = ac.find( ".ui-accordion-content" ); + + ac.one( "accordionbeforeactivate", function( event, ui ) { + equals( ui.oldHeader.size(), 0 ); + equals( ui.oldContent.size(), 0 ); + equals( ui.newHeader.size(), 1 ); + strictEqual( ui.newHeader[ 0 ], headers[ 0 ] ); + equals( ui.newContent.size(), 1 ); + strictEqual( ui.newContent[ 0 ], content[ 0 ] ); + state( ac, 0, 0, 0 ); + }); + ac.accordion( "option", "active", 0 ); + state( ac, 1, 0, 0 ); + + ac.one( "accordionbeforeactivate", function( event, ui ) { + equals( ui.oldHeader.size(), 1 ); + strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] ); + equals( ui.oldContent.size(), 1 ); + strictEqual( ui.oldContent[ 0 ], content[ 0 ] ); + equals( ui.newHeader.size(), 1 ); + strictEqual( ui.newHeader[ 0 ], headers[ 1 ] ); + equals( ui.newContent.size(), 1 ); + strictEqual( ui.newContent[ 0 ], content[ 1 ] ); + state( ac, 1, 0, 0 ); + }); + headers.eq( 1 ).click(); + state( ac, 0, 1, 0 ); + + ac.one( "accordionbeforeactivate", function( event, ui ) { + equals( ui.oldHeader.size(), 1 ); + strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] ); + equals( ui.oldContent.size(), 1 ); + strictEqual( ui.oldContent[ 0 ], content[ 1 ] ); + equals( ui.newHeader.size(), 0 ); + equals( ui.newContent.size(), 0 ); + state( ac, 0, 1, 0 ); + }); + ac.accordion( "option", "active", false ); + state( ac, 0, 0, 0 ); + + ac.one( "accordionbeforeactivate", function( event, ui ) { + equals( ui.oldHeader.size(), 0 ); + equals( ui.oldContent.size(), 0 ); + equals( ui.newHeader.size(), 1 ); + strictEqual( ui.newHeader[ 0 ], headers[ 1 ] ); + equals( ui.newContent.size(), 1 ); + strictEqual( ui.newContent[ 0 ], content[ 1 ] ); + event.preventDefault(); + state( ac, 0, 0, 0 ); + }); + ac.accordion( "option", "active", 1 ); + state( ac, 0, 0, 0 ); + + ac.one( "accordionbeforeactivate", function( event, ui ) { + equals( ui.oldHeader.size(), 0 ); + equals( ui.oldContent.size(), 0 ); + equals( ui.newHeader.size(), 1 ); + strictEqual( ui.newHeader[ 0 ], headers[ 2 ] ); + equals( ui.newContent.size(), 1 ); + strictEqual( ui.newContent[ 0 ], content[ 2 ] ); + event.preventDefault(); + state( ac, 0, 0, 0 ); + }); + headers.eq( 2 ).click(); + state( ac, 0, 0, 0 ); +}); + +test( "activate", function() { + expect( 20 ); + var ac = $( "#list1" ).accordion({ + active: false, + collapsible: true + }); + var headers = ac.find( ".ui-accordion-header" ); + var content = ac.find( ".ui-accordion-content" ); + + ac.one( "accordionactivate", function( event, ui ) { equals( ui.oldHeader.size(), 0 ); equals( ui.oldContent.size(), 0 ); equals( ui.newHeader.size(), 1 ); + strictEqual( ui.newHeader[ 0 ], headers[ 0 ] ); equals( ui.newContent.size(), 1 ); - }) - .accordion("option", "active", 0) - .one("accordionchange", function(event, ui) { + strictEqual( ui.newContent[ 0 ], content[ 0 ] ); + }); + ac.accordion( "option", "active", 0 ); + + ac.one( "accordionactivate", function( event, ui ) { + equals( ui.oldHeader.size(), 1 ); + strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] ); + equals( ui.oldContent.size(), 1 ); + strictEqual( ui.oldContent[ 0 ], content[ 0 ] ); + equals( ui.newHeader.size(), 1 ); + strictEqual( ui.newHeader[ 0 ], headers[ 1 ] ); + equals( ui.newContent.size(), 1 ); + strictEqual( ui.newContent[ 0 ], content[ 1 ] ); + }); + headers.eq( 1 ).click(); + + ac.one( "accordionactivate", function( event, ui ) { equals( ui.oldHeader.size(), 1 ); + strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] ); equals( ui.oldContent.size(), 1 ); + strictEqual( ui.oldContent[ 0 ], content[ 1 ] ); equals( ui.newHeader.size(), 0 ); equals( ui.newContent.size(), 0 ); - }) - .accordion("option", "active", false); + }); + ac.accordion( "option", "active", false ); }); -})(jQuery); +}( jQuery ) ); diff --git a/tests/unit/accordion/accordion_methods.js b/tests/unit/accordion/accordion_methods.js index c801851d0..e0ed734f6 100644 --- a/tests/unit/accordion/accordion_methods.js +++ b/tests/unit/accordion/accordion_methods.js @@ -1,128 +1,48 @@ -/* - * accordion_methods.js - */ -(function($) { - -module("accordion: methods"); - -test("init", function() { - $("<div></div>").appendTo('body').accordion().remove(); - ok(true, '.accordion() called on element'); - - $([]).accordion().remove(); - ok(true, '.accordion() called on empty collection'); - - $('<div></div>').accordion().remove(); - ok(true, '.accordion() called on disconnected DOMElement - never connected'); - - $('<div></div>').appendTo('body').remove().accordion().remove(); - ok(true, '.accordion() called on disconnected DOMElement - removed'); - - var el = $('<div></div>').accordion(); - var foo = el.accordion("option", "foo"); - el.remove(); - ok(true, 'arbitrary option getter after init'); - - $('<div></div>').accordion().accordion("option", "foo", "bar").remove(); - ok(true, 'arbitrary option setter after init'); -}); - -test("destroy", function() { - var beforeHtml = $("#list1").find("div").css("font-style", "normal").end().parent().html(); - var afterHtml = $("#list1").accordion().accordion("destroy").parent().html(); - // Opera 9 outputs role="" instead of removing the attribute like everyone else - if ($.browser.opera) { - afterHtml = afterHtml.replace(/ role=""/g, ""); - } +(function( $ ) { + +module( "accordion: methods", accordionSetupTeardown() ); + +test( "destroy", function() { + var beforeHtml = $( "#list1" ) + .find( "div" ) + .css( "font-style", "normal" ) + .end() + .parent() + .html(); + var afterHtml = $( "#list1" ) + .accordion() + .accordion( "destroy" ) + .parent() + .html() + // Opera 9 outputs role="" instead of removing the attribute like everyone else + .replace( / role=""/g, "" ); equal( afterHtml, beforeHtml ); }); -test("enable", function() { - var expected = $('#list1').accordion(), - actual = expected.accordion('enable'); - equals(actual, expected, 'enable is chainable'); - state(expected, 1, 0, 0) -}); - -test("disable", function() { - var expected = $('#list1').accordion(), - actual = expected.accordion('disable'); - equals(actual, expected, 'disable is chainable'); - - state(expected, 1, 0, 0) - expected.accordion("option", "active", 1); - state(expected, 1, 0, 0) - expected.accordion("enable"); - expected.accordion("option", "active", 1); - state(expected, 0, 1, 0) +test( "enable/disable", function() { + var accordion = $('#list1').accordion(); + state( accordion, 1, 0, 0 ); + accordion.accordion( "disable" ); + accordion.accordion( "option", "active", 1 ); + state( accordion, 1, 0, 0 ); + accordion.accordion( "enable" ); + accordion.accordion( "option", "active", 1 ); + state( accordion, 0, 1, 0 ); }); -test("activate", function() { - var expected = $('#list1').accordion(), - actual = expected.accordion('activate', 2); - equals(actual, expected, 'activate is chainable'); -}); - -test("activate, numeric", function() { - var ac = $('#list1').accordion({ active: 1 }); - state(ac, 0, 1, 0); - ac.accordion("activate", 2); - state(ac, 0, 0, 1); - ac.accordion("activate", 0); - state(ac, 1, 0, 0); - ac.accordion("activate", 1); - state(ac, 0, 1, 0); - ac.accordion("activate", 2); - state(ac, 0, 0, 1); -}); - -test("activate, boolean and numeric, collapsible:true", function() { - var ac = $('#list1').accordion({collapsible: true}).accordion("activate", 2); - state(ac, 0, 0, 1); - ok("x", "----"); - ac.accordion("activate", 0); - state(ac, 1, 0, 0); - ok("x", "----"); - ac.accordion("activate", -1); - state(ac, 0, 0, 0); -}); - -test("activate, boolean, collapsible: false", function() { - var ac = $('#list1').accordion().accordion("activate", 2); - state(ac, 0, 0, 1); - ac.accordion("activate", false); - state(ac, 0, 0, 1); -}); - -test("activate, string expression", function() { - var ac = $('#list1').accordion({ active: "h3:last" }); - state(ac, 0, 0, 1); - ac.accordion("activate", ":first"); - state(ac, 1, 0, 0); - ac.accordion("activate", ":eq(1)"); - state(ac, 0, 1, 0); - ac.accordion("activate", ":last"); - state(ac, 0, 0, 1); -}); - -test("activate, jQuery or DOM element", function() { - var ac = $('#list1').accordion({ active: $("#list1 h3:last") }); - state(ac, 0, 0, 1); - ac.accordion("activate", $("#list1 h3:first")); - state(ac, 1, 0, 0); - ac.accordion("activate", $("#list1 h3")[1]); - state(ac, 0, 1, 0); -}); +test( "refresh", function() { + var expected = $( "#navigation" ) + .parent() + .height( 300 ) + .end() + .accordion({ + heightStyle: "fill" + }); + equalHeights( expected, 246, 258 ); -test("refresh", function() { - var expected = $('#navigation').parent().height(300).end().accordion({ - fillSpace: true - }); - equalHeights(expected, 246, 258); - - expected.parent().height(500); - expected.accordion("refresh"); - equalHeights(expected, 446, 458); + expected.parent().height( 500 ); + expected.accordion( "refresh" ); + equalHeights( expected, 446, 458 ); }); -})(jQuery); +}( jQuery ) ); diff --git a/tests/unit/accordion/accordion_options.js b/tests/unit/accordion/accordion_options.js index abfb82d78..8fcfdb172 100644 --- a/tests/unit/accordion/accordion_options.js +++ b/tests/unit/accordion/accordion_options.js @@ -1,203 +1,212 @@ -/* - * accordion_options.js - */ -(function($) { +(function( $ ) { -module("accordion: options"); +module( "accordion: options", accordionSetupTeardown() ); -test("{ active: first child }, default", function() { - var ac = $("#list1").accordion(); - equals( ac.accordion('option', 'active'), 0); - state(ac, 1, 0, 0) +test( "{ active: default }", function() { + var ac = $( "#list1" ).accordion(); + equals( ac.accordion( "option", "active" ), 0 ); + state( ac, 1, 0, 0 ); }); -test("{ active: Selector }", function() { - var ac = $("#list1").accordion({ - active: "h3:last" - }); - state(ac, 0, 0, 1); - ac.accordion('option', 'active', "h3:eq(1)"); - state(ac, 0, 1, 0); -}); - -test("{ active: Element }", function() { - var ac = $("#list1").accordion({ - active: $("#list1 h3:last")[0] - }); - state(ac, 0, 0, 1); - ac.accordion('option', 'active', $("#list1 h3:eq(1)")[0]); - state(ac, 0, 1, 0); -}); - -test("{ active: jQuery Object }", function() { - var ac = $("#list1").accordion({ - active: $("#list1 h3:last") - }); - state(ac, 0, 0, 1); - ac.accordion('option', 'active', $("#list1 h3:eq(1)")); - state(ac, 0, 1, 0); -}); - -test("{ active: false }", function() { - var ac = $("#list1").accordion({ +test( "{ active: false }", function() { + var ac = $( "#list1" ).accordion({ active: false, collapsible: true }); - state(ac, 0, 0, 0); - equals( $("#list1 .ui-accordion-header.ui-state-active").size(), 0, "no headers selected" ); - equals( $("#list1").accordion('option', 'active'), false); -}); - -test("{ active: Number }", function() { - expect(4); - $("#list1").accordion({ - active: 0 + state( ac, 0, 0, 0 ); + equals( ac.find( ".ui-accordion-header.ui-state-active" ).size(), 0, "no headers selected" ); + equals( ac.accordion( "option", "active" ), false ); + + // TODO: fix active: false when not collapsible +// ac.accordion( "option", "collapsible", false ); +// state( ac, 1, 0, 0 ); +// equals( ac.accordion( "option", "active" ), 0 ); +// +// ac.accordion( "destroy" ); +// ac.accordion({ +// active: false +// }); +// state( ac, 1, 0, 0 ); +// strictEqual( ac.accordion( "option", "active" ), 0 ); +}); + +test( "{ active: Number }", function() { + var ac = $( "#list1" ).accordion({ + active: 2 }); - equals( $("#list1").accordion('option', 'active'), 0); - - $("#list1").accordion('option', 'active', 1); - equals( $("#list1").accordion('option', 'active'), 1); - - $('.ui-accordion-header:eq(2)', '#list1').click(); - equals( $("#list1").accordion('option', 'active'), 2); - - $("#list1").accordion('option', 'active', 0); - equals( $("#list1").accordion('option', 'active'), 0); -}); + equals( ac.accordion( "option", "active" ), 2 ); + state( ac, 0, 0, 1 ); + + ac.accordion( "option", "active", 0 ); + equals( ac.accordion( "option", "active" ), 0 ); + state( ac, 1, 0, 0 ); + + ac.find( ".ui-accordion-header" ).eq( 1 ).click(); + equals( ac.accordion( "option", "active" ), 1 ); + state( ac, 0, 1, 0 ); + + ac.accordion( "option", "active", 10 ); + equals( ac.accordion( "option", "active" ), 1 ); + state( ac, 0, 1, 0 ); +}); + +if ( $.uiBackCompat === false ) { + test( "{ active: -Number }", function() { + // TODO: fix initializing with negative value + var ac = $( "#list1" ).accordion({ +// active: -1 + }); +// equals( ac.accordion( "option", "active" ), 2 ); +// state( ac, 0, 0, 1 ); + + ac.accordion( "option", "active", -2 ); + equals( ac.accordion( "option", "active" ), 1 ); + state( ac, 0, 1, 0 ); + + ac.accordion( "option", "active", -10 ); + equals( ac.accordion( "option", "active" ), 1 ); + state( ac, 0, 1, 0 ); + + ac.accordion( "option", "active", -3 ); + equals( ac.accordion( "option", "active" ), 0 ); + state( ac, 1, 0, 0 ); + }); +} -test("{ autoHeight: true }, default", function() { - equalHeights($('#navigation').accordion({ autoHeight: true }), 95, 130); -}); +// TODO: add animation tests -test("{ heightStyle: 'auto' }, default", function() { - equalHeights($('#navigation').accordion({ heightStyle: 'auto' }), 95, 130); -}); - -test("{ autoHeight: false }", function() { - var accordion = $('#navigation').accordion({ autoHeight: false }); - var sizes = []; - accordion.find(".ui-accordion-content").each(function() { - sizes.push($(this).height()); +test( "{ collapsible: false }", function() { + var ac = $( "#list1" ).accordion({ + active: 1 }); - ok( sizes[0] >= 70 && sizes[0] <= 90, "was " + sizes[0] ); - ok( sizes[1] >= 98 && sizes[1] <= 126, "was " + sizes[1] ); - ok( sizes[2] >= 42 && sizes[2] <= 54, "was " + sizes[2] ); -}); + ac.accordion( "option", "active", false ); + equal( ac.accordion( "option", "active" ), 1 ); + state( ac, 0, 1, 0 ); -test("{ heightStyle: 'content' }", function() { - var accordion = $('#navigation').accordion({ heightStyle: 'content' }); - var sizes = []; - accordion.find(".ui-accordion-content").each(function() { - sizes.push($(this).height()); - }); - ok( sizes[0] >= 70 && sizes[0] <= 90, "was " + sizes[0] ); - ok( sizes[1] >= 98 && sizes[1] <= 126, "was " + sizes[1] ); - ok( sizes[2] >= 42 && sizes[2] <= 54, "was " + sizes[2] ); -}); -test("{ collapsible: false }, default", function() { - var ac = $("#list1").accordion(); - ac.accordion("option", "active", false); - state(ac, 1, 0, 0); + ac.find( ".ui-accordion-header" ).eq( 1 ).click(); + equal( ac.accordion( "option", "active" ), 1 ); + state( ac, 0, 1, 0 ); }); -test("{ collapsible: true }", function() { - var ac = $("#list1").accordion({ +test( "{ collapsible: true }", function() { + var ac = $( "#list1" ).accordion({ active: 1, collapsible: true }); - var header = $('#list1 .ui-accordion-header:eq(1)').click(); - equals( $("#list1").accordion('option', 'active'), false); - state(ac, 0, 0, 0); -}); - -// fillSpace: false == autoHeight: true, covered above -test("{ fillSpace: true }", function() { - $("#navigationWrapper").height(500); - equalHeights($('#navigation').accordion({ fillSpace: true }), 446, 458); -}); - -test("{ heightStyle: 'fill' }", function() { - $("#navigationWrapper").height(500); - equalHeights($('#navigation').accordion({ heightStyle: 'fill' }), 446, 458); -}); - -test("{ fillSpace: true } with sibling", function() { - $("#navigationWrapper").height(500); - var sibling = $("<p>Lorem Ipsum</p>"); - $("#navigationWrapper").prepend( sibling.height(100) ); - //sibling.outerHeight(true) == 126 - equalHeights($('#navigation').accordion({ fillSpace: true}), 320, 332); -}); - -test("{ fillSpace: true } with multiple siblings", function() { - $("#navigationWrapper").height(500); - var sibling = $("<p>Lorem Ipsum</p>"); - $("#navigationWrapper") - .prepend( sibling.clone().height(100) ) - .prepend( sibling.clone().height(100).css( "position", "absolute" ) ) - .prepend( sibling.clone().height(50) ); - //sibling.outerHeight(true) == 126 - equalHeights($('#navigation').accordion({ fillSpace: true}), 244, 256); -}); - -test("{ header: '> li > :first-child,> :not(li):even' }, default", function() { - state($("#list1").accordion(), 1, 0, 0); - state($("#navigation").accordion(), 1, 0, 0); -}); -test("{ icons: false }", function() { - var list = $("#list1"); - function icons(on) { - same($("span.ui-icon", list).length, on ? 3 : 0); - same( list.hasClass("ui-accordion-icons"), on ); + // TODO: fix setting active to false +// ac.accordion( "option", "active", false ); +// equal( ac.accordion( "option", "active" ), false ); +// state( ac, 0, 0, 0 ); + + ac.accordion( "option", "active", 1 ); + equal( ac.accordion( "option", "active" ), 1 ); + state( ac, 0, 1, 0 ); + + ac.find( ".ui-accordion-header" ).eq( 1 ).click(); + equals( ac.accordion( "option", "active" ), false ); + state( ac, 0, 0, 0 ); +}); + +// TODO: add event tests + +// TODO: add more header tests +test( "{ header: default }", function() { + // default: > li > :first-child,> :not(li):even + // > :not(li):even + state( $( "#list1" ).accordion(), 1, 0, 0); + // > li > :first-child + state( $( "#navigation" ).accordion(), 1, 0, 0); +}); + +test( "{ heightStyle: 'auto' }", function() { + var ac = $( "#navigation" ).accordion({ heightStyle: "auto" }); + equalHeights( ac, 95, 130 ); +}); + +test( "{ heightStyle: 'content' }", function() { + var ac = $( "#navigation" ).accordion({ heightStyle: "content" }); + var sizes = ac.find( ".ui-accordion-content" ).map(function() { + return $( this ).height(); + }).get(); + ok( sizes[ 0 ] >= 70 && sizes[ 0 ] <= 90, "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() { + $( "#navigationWrapper" ).height( 500 ); + var ac = $( "#navigation" ).accordion({ heightStyle: "fill" }); + equalHeights( ac, 446, 458 ); +}); + +test( "{ heightStyle: 'fill' } with sibling", function() { + $( "#navigationWrapper" ).height( 500 ); + $( "<p>Lorem Ipsum</p>" ) + .css({ + height: 50, + marginTop: 20, + marginBottom: 30 + }) + .prependTo( "#navigationWrapper" ); + var ac = $( "#navigation" ).accordion({ heightStyle: "fill" }); + equalHeights( ac , 346, 358); +}); + +test( "{ heightStyle: 'fill' } with multiple siblings", function() { + $( "#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 ac = $( "#navigation" ).accordion({ heightStyle: "fill" }); + equalHeights( ac, 296, 308 ); +}); + +test( "{ icons: false }", function() { + var list = $( "#list1" ); + function icons( on ) { + same( list.find( "span.ui-icon").length, on ? 3 : 0 ); + same( list.hasClass( "ui-accordion-icons" ), on ); } list.accordion(); - icons(true); - list.accordion("destroy").accordion({ + icons( true ); + list.accordion( "destroy" ).accordion({ icons: false }); - icons(false); - list.accordion("option", "icons", $.ui.accordion.prototype.options.icons); - icons(true); - list.accordion("option", "icons", false); - icons(false); -}); - -test("{ icons: { activeHeader : 'test' } }", function() { - var list = $("#list1"); - list.accordion( { icons: { "activeHeader": "test" } } ); - equals( $( "#list1 span.test" ).length, 1); - list.accordion("option", "icons", { "activeHeader": "news" } ); - equals( $( "#list1 span.test" ).length, 0); - equals( $( "#list1 span.news" ).length, 1); -}); - -test("{ navigation: true, navigationFilter: header }", function() { - $("#navigation").accordion({ - navigation: true, - navigationFilter: function() { - return /\?p=1\.1\.3$/.test(this.href); - } - }); - equals( $("#navigation .ui-accordion-content:eq(2)").size(), 1, "third content active" ); + icons( false ); + list.accordion( "option", "icons", { header: "foo", activeHeader: "bar" } ); + icons( true ); + list.accordion( "option", "icons", false ); + icons( false ); }); -test("{ navigation: true, navigationFilter: content }", function() { - $("#navigation").accordion({ - navigation: true, - navigationFilter: function() { - return /\?p=1\.1\.3\.2$/.test(this.href); - } +test( "{ icons: hash }", function() { + var list = $( "#list1" ).accordion({ + icons: { activeHeader: "a1", header: "h1" } }); - equals( $("#navigation .ui-accordion-content:eq(2)").size(), 1, "third content active" ); -}); - -test("change headerSelected option after creation", function() { - var list = $("#list1"); - list.accordion( { icons: { "activeHeader": "test" } } ); - equals( $( "#list1 span.test" ).length, 1); - list.accordion( "option", "icons", { "headerSelected": "deprecated" } ); - equals( $( "#list1 span.deprecated" ).length, 1); + ok( list.find( ".ui-accordion-header.ui-state-active span.ui-icon" ).hasClass( "a1" ) ); + list.accordion( "option", "icons", { activeHeader: "a2", header: "h2" } ); + ok( !list.find( ".ui-accordion-header.ui-state-active span.ui-icon" ).hasClass( "a1" ) ); + ok( list.find( ".ui-accordion-header.ui-state-active span.ui-icon" ).hasClass( "a2" ) ); }); -})(jQuery); +}( jQuery ) ); diff --git a/tests/unit/accordion/accordion_tickets.js b/tests/unit/accordion/accordion_tickets.js index 98d8fbe4c..b301051da 100644 --- a/tests/unit/accordion/accordion_tickets.js +++ b/tests/unit/accordion/accordion_tickets.js @@ -1,8 +1,5 @@ -/* - * accordion_tickets.js - */ -(function($) { +(function( $ ) { -module("accordion: tickets"); +module( "accordion: tickets", accordionSetupTeardown() ); -})(jQuery); +}( jQuery ) ); diff --git a/tests/unit/testsuite.js b/tests/unit/testsuite.js index d152f84cd..9724a946f 100644 --- a/tests/unit/testsuite.js +++ b/tests/unit/testsuite.js @@ -1,39 +1,69 @@ -function testWidgetDefaults(widget, defaults) { - var pluginDefaults = $.extend({}, - $.ui[widget].prototype.options - ); - +(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(val !== undefined, key); + test( "defined defaults", function() { + $.each( defaults, function( key, val ) { + if ( $.isFunction( val ) ) { + ok( $.isFunction( pluginDefaults[ key ] ), key ); return; } - same(pluginDefaults[key], val, key); + 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); + test( "tested defaults", function() { + $.each( pluginDefaults, function( key, val ) { + ok( key in defaults, key ); }); }); } -function testWidgetOverrides(widget) { - test('$.widget overrides', function() { - $.each(['_widgetInit', 'option', '_trigger'], function(i, method) { - ok($.Widget.prototype[method] == $.ui[widget].prototype[method], - 'should not override ' + method); +var privateMethods = [ + "_createWidget", + "_super", + "_superApply", + "destroy", + "option", + "enable", + "disable", + "_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 commonWidgetTests(widget, settings) { - module(widget + ": common widget"); +function testBasicUsage( widget ) { + test( "basic usage", function() { + var defaultElement = $.ui[ widget ].prototype.defaultElement; + $( defaultElement ).appendTo( "body" )[ widget ]().remove(); + ok( true, "initialized on element" ); - testWidgetDefaults(widget, settings.defaults); - testWidgetOverrides(widget); + $( 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 ); +}; + +}()); diff --git a/tests/unit/widget/widget.html b/tests/unit/widget/widget.html index c6fa54e41..d8fa2ecaf 100644 --- a/tests/unit/widget/widget.html +++ b/tests/unit/widget/widget.html @@ -1,22 +1,22 @@ <!DOCTYPE html> <html lang="en"> <head> - <meta charset="UTF-8" /> + <meta charset="utf-8"> <title>jQuery UI Widget Test Suite</title> - <script type="text/javascript" src="../../../jquery-1.4.4.js"></script> - <script type="text/javascript" src="../../../ui/jquery.ui.core.js"></script> - <script type="text/javascript" src="../../../ui/jquery.ui.widget.js"></script> + <script src="../../../jquery-1.4.4.js"></script> + <script src="../../../ui/jquery.ui.core.js"></script> + <script src="../../../ui/jquery.ui.widget.js"></script> - <link rel="stylesheet" href="../../../external/qunit.css" type="text/css"/> - <script type="text/javascript" src="../../../external/qunit.js"></script> - <script type="text/javascript" src="../../jquery.simulate.js"></script> - <script type="text/javascript" src="../testsuite.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 type="text/javascript" src="widget_core.js"></script> - <script type="text/javascript" src="widget_tickets.js"></script> - - <script type="text/javascript" src="../swarminject.js"></script> + <script src="widget_core.js"></script> + <script src="widget_tickets.js"></script> + + <script src="../swarminject.js"></script> </head> <body> diff --git a/tests/unit/widget/widget_core.js b/tests/unit/widget/widget_core.js index d993194e2..6f4930621 100644 --- a/tests/unit/widget/widget_core.js +++ b/tests/unit/widget/widget_core.js @@ -1,6 +1,3 @@ -/* - * widget unit tests - */ (function( $ ) { module( "widget factory", { @@ -26,6 +23,54 @@ test( "widget creation", function() { "option method copied over from base widget" ); }); +test( "element normalization", function() { + expect( 11 ); + var elem; + $.widget( "ui.testWidget", {} ); + + $.ui.testWidget.prototype._create = function() { + 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'>"; + $.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( "#main" ); + $.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( 11 ); @@ -55,7 +100,7 @@ test( "jQuery usage", function() { }); shouldCreate = true; - var elem = $( "<div></div>" ) + var elem = $( "<div>" ) .bind( "testwidgetcreate", function() { ok( shouldCreate, "create event triggered on instantiation" ); }) @@ -101,7 +146,7 @@ test( "direct usage", function() { } }); - var elem = $( "<div></div>" )[ 0 ]; + var elem = $( "<div>" )[ 0 ]; shouldCreate = true; var instance = new $.ui.testWidget( {}, elem ); @@ -153,7 +198,7 @@ test( "merge multiple option arguments", function() { }); } }); - $( "<div></div>" ).testWidget({ + $( "<div>" ).testWidget({ option1: "valuex", option2: "valuex", option3: "value3", @@ -200,7 +245,7 @@ test( "._getCreateOptions()", function() { }); test( "re-init", function() { - var div = $( "<div></div>" ), + var div = $( "<div>" ), actions = []; $.widget( "ui.testWidget", { @@ -286,7 +331,7 @@ test( ".option() - getter", function() { _create: function() {} }); - var div = $( "<div></div>" ).testWidget({ + var div = $( "<div>" ).testWidget({ foo: "bar", baz: 5, qux: [ "quux", "quuux" ] @@ -317,7 +362,7 @@ test( ".option() - delegate to ._setOptions()", function() { calls.push( options ); } }); - var div = $( "<div></div>" ).testWidget(); + var div = $( "<div>" ).testWidget(); calls = []; div.testWidget( "option", "foo", "bar" ); @@ -343,7 +388,7 @@ test( ".option() - delegate to ._setOption()", function() { }); } }); - var div = $( "<div></div>" ).testWidget(); + var div = $( "<div>" ).testWidget(); calls = []; div.testWidget( "option", "foo", "bar" ); @@ -370,7 +415,7 @@ test( ".enable()", function() { same( val, false, "disabled set to false" ); } }); - $( "<div></div>" ).testWidget().testWidget( "enable" ); + $( "<div>" ).testWidget().testWidget( "enable" ); }); test( ".disable()", function() { @@ -382,26 +427,26 @@ test( ".disable()", function() { same( val, true, "disabled set to true" ); } }); - $( "<div></div>" ).testWidget().testWidget( "disable" ); + $( "<div>" ).testWidget().testWidget( "disable" ); }); test( ".widget() - base", function() { $.widget( "ui.testWidget", { _create: function() {} }); - var div = $( "<div></div>" ).testWidget(); + var div = $( "<div>" ).testWidget(); same( div[0], div.testWidget( "widget" )[0]); }); test( ".widget() - overriden", function() { - var wrapper = $( "<div></div>" ); + var wrapper = $( "<div>" ); $.widget( "ui.testWidget", { _create: function() {}, widget: function() { return wrapper; } }); - same( wrapper[0], $( "<div></div>" ).testWidget().testWidget( "widget" )[0] ); + same( wrapper[0], $( "<div>" ).testWidget().testWidget( "widget" )[0] ); }); test( "._bind() to element (default)", function() { @@ -691,6 +736,28 @@ test( "._trigger() - provide event and ui", function() { .testWidget( "testEvent" ); }); +test( "._triger() - 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(); +}); + test( "auto-destroy - .remove()", function() { expect( 1 ); $.widget( "ui.testWidget", { @@ -721,8 +788,6 @@ test( "auto-destroy - .remove() on child", function() { } }); $( "#widget" ).testWidget().children().remove(); - // http://github.com/jquery/qunit/pull/34 - $.ui.testWidget.prototype.destroy = $.noop; }); test( "auto-destroy - .empty()", function() { @@ -733,8 +798,6 @@ test( "auto-destroy - .empty()", function() { } }); $( "#widget" ).testWidget().empty(); - // http://github.com/jquery/qunit/pull/34 - $.ui.testWidget.prototype.destroy = $.noop; }); test( "auto-destroy - .empty() on parent", function() { @@ -758,4 +821,4 @@ test( "auto-destroy - .detach()", function() { $( "#widget" ).testWidget().detach(); }); -})( jQuery ); +}( jQuery ) ); diff --git a/tests/unit/widget/widget_tickets.js b/tests/unit/widget/widget_tickets.js index 21f44b54c..0267c8ff4 100644 --- a/tests/unit/widget/widget_tickets.js +++ b/tests/unit/widget/widget_tickets.js @@ -1,6 +1,3 @@ -/* - * widget unit tests - */ (function( $ ) { module( "widget: tickets" ); @@ -43,4 +40,4 @@ test( "#5830 - Widget: Using inheritance overwrites the base classes options", f delete $.ui.testWidgetExtension; }); -})( jQuery ); +}( jQuery ) ); |