diff options
author | Jörn Zaefferer <joern.zaefferer@gmail.com> | 2009-09-15 08:33:28 +0000 |
---|---|---|
committer | Jörn Zaefferer <joern.zaefferer@gmail.com> | 2009-09-15 08:33:28 +0000 |
commit | b9b604936e29c3d6a5a50f75460eb3c98ee80f30 (patch) | |
tree | f4b8d05dc0c0f2e29ad5e3a3f29663e5fadd70d9 /tests/unit/accordion | |
parent | a282bba6cdb63f2565562e358c93b9643ff09b54 (diff) | |
download | jquery-ui-b9b604936e29c3d6a5a50f75460eb3c98ee80f30.tar.gz jquery-ui-b9b604936e29c3d6a5a50f75460eb3c98ee80f30.zip |
accordion: remove deprecated alwaysOpen option (collapsible was introduced in last stable release); fixed collapsible-false accordion in combination with activate method (with fasly-argument to close all); changed activate-option default to 0 (which was the "computed" default anyway); lots of fixes for the testsuite, while removing some of the "missing" tests: header accepts only a selector (updated spec to make that more clear), while testing animations in unit tests is rather pointless
Diffstat (limited to 'tests/unit/accordion')
-rw-r--r-- | tests/unit/accordion/accordion_core.js | 24 | ||||
-rw-r--r-- | tests/unit/accordion/accordion_defaults.js | 6 | ||||
-rw-r--r-- | tests/unit/accordion/accordion_methods.js | 90 | ||||
-rw-r--r-- | tests/unit/accordion/accordion_options.js | 101 |
4 files changed, 129 insertions, 92 deletions
diff --git a/tests/unit/accordion/accordion_core.js b/tests/unit/accordion/accordion_core.js index 524842037..797ead864 100644 --- a/tests/unit/accordion/accordion_core.js +++ b/tests/unit/accordion/accordion_core.js @@ -2,34 +2,26 @@ * accordion_core.js */ + +(function($) { + jQuery.ui.accordion.defaults.animated = false; function state(accordion) { var args = $.makeArray(arguments).slice(1); + var result = []; $.each(args, function(i, n) { - equals(accordion.find(".ui-accordion-content").eq(i).is(":visible"), n); + result.push( accordion.find(".ui-accordion-content").eq(i).is(":visible") ? 1 : 0 ); }); + same(args, result) } -function state2(accordion) { - var args = $.makeArray(arguments).slice(1); - $.each(args, function(i, n) { - equals(accordion.find("div").eq(i).is(":visible"), n); - }); -} - -$.fn.triggerEvent = function(type, target) { - return this.triggerHandler(type, [jQuery.event.fix({ type: type, target: target })]); -}; - -(function($) { - module("accordion: core"); test("handle click on header-descendant", function() { var ac = $('#navigation').accordion({ autoHeight: false }); - ac.triggerEvent("click", $('#navigation span:contains(Bass)')[0]); - state2(ac, 0, 1, 0); + $('#navigation h2:eq(1) a').trigger("click"); + state(ac, 0, 1, 0); }); test("accessibility", function () { diff --git a/tests/unit/accordion/accordion_defaults.js b/tests/unit/accordion/accordion_defaults.js index 78561ca36..e472734bc 100644 --- a/tests/unit/accordion/accordion_defaults.js +++ b/tests/unit/accordion/accordion_defaults.js @@ -3,7 +3,7 @@ */ var accordion_defaults = { - active: null, + active: 0, animated: false, autoHeight: true, clearStyle: false, @@ -14,9 +14,7 @@ var accordion_defaults = { header: "> li > :first-child,> :not(li):even", icons: { "header": "ui-icon-triangle-1-e", "headerSelected": "ui-icon-triangle-1-s" }, navigation: false, - navigationFilter: function() { - return this.href.toLowerCase() == location.href.toLowerCase(); - } + navigationFilter: function() {} }; commonWidgetTests('accordion', { defaults: accordion_defaults }); diff --git a/tests/unit/accordion/accordion_methods.js b/tests/unit/accordion/accordion_methods.js index e13a4a47e..75c11b46b 100644 --- a/tests/unit/accordion/accordion_methods.js +++ b/tests/unit/accordion/accordion_methods.js @@ -3,31 +3,87 @@ */ (function($) { +function state(accordion) { + var expected = $.makeArray(arguments).slice(1); + var actual = []; + $.each(expected, function(i, n) { + actual.push( accordion.find(".ui-accordion-content").eq(i).is(":visible") ? 1 : 0 ); + }); + same(actual, expected) +} + module("accordion: methods"); test("init", function() { - ok(false, 'missing test - untested code is broken code'); + $("<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'); + + $('<div></div>').accordion().accordion("foo").remove(); + ok(true, 'arbitrary method called after init'); + + var el = $('<div></div>').accordion(); + var foo = el.data("foo.accordion"); + el.remove(); + ok(true, 'arbitrary option getter after init'); + + $('<div></div>').accordion().data("foo.accordion", "bar").remove(); + ok(true, 'arbitrary option setter after init'); }); test("destroy", function() { - var expected = $('#list1').accordion(), + $("<div></div>").appendTo('body').accordion().accordion("destroy").remove(); + ok(true, '.accordion("destroy") called on element'); + + $([]).accordion().accordion("destroy").remove(); + ok(true, '.accordion("destroy") called on empty collection'); + + $('<div></div>').accordion().accordion("destroy").remove(); + ok(true, '.accordion("destroy") called on disconnected DOMElement'); + + $('<div></div>').accordion().accordion("destroy").accordion("foo").remove(); + ok(true, 'arbitrary method called after destroy'); + + var el = $('<div></div>').accordion(); + var foo = el.accordion("destroy").data("foo.accordion"); + el.remove(); + ok(true, 'arbitrary option getter after destroy'); + + $('<div></div>').accordion().accordion("destroy").data("foo.accordion", "bar").remove(); + ok(true, 'arbitrary option setter after destroy'); + + var expected = $('<div></div>').accordion(), actual = expected.accordion('destroy'); equals(actual, expected, 'destroy is chainable'); - ok(false, 'missing test - untested code is broken code'); }); test("enable", function() { var expected = $('#list1').accordion(), actual = expected.accordion('enable'); equals(actual, expected, 'enable is chainable'); - ok(false, 'missing test - untested code is broken code'); + + state(expected, 1, 0, 0) }); test("disable", function() { var expected = $('#list1').accordion(), actual = expected.accordion('disable'); equals(actual, expected, 'disable is chainable'); - ok(false, 'missing test - untested code is broken code'); + + state(expected, 1, 0, 0) + expected.accordion("activate", 1); + state(expected, 1, 0, 0) + expected.accordion("enable"); + expected.accordion("activate", 1); + state(expected, 0, 1, 0) }); test("activate", function() { @@ -47,8 +103,6 @@ test("activate, numeric", function() { state(ac, 0, 1, 0); ac.accordion("activate", 2); state(ac, 0, 0, 1); - ac.accordion("activate", -1); - state(ac, 0, 0, 1); }); test("activate, boolean and numeric, collapsible:true", function() { @@ -62,7 +116,7 @@ test("activate, boolean and numeric, collapsible:true", function() { state(ac, 0, 0, 0); }); -test("activate, boolean, collapsible:false", function() { +test("activate, boolean, collapsible: false", function() { var ac = $('#list1').accordion().accordion("activate", 2); state(ac, 0, 0, 1); ac.accordion("activate", -1); @@ -90,10 +144,24 @@ test("activate, jQuery or DOM element", function() { }); test("resize", function() { - var expected = $('#list1').accordion(), - actual = expected.accordion('resize'); + var expected = $('#list1').accordion(); + + var sizes = []; + expected.find(".ui-accordion-content").each(function() { + sizes.push($(this).outerHeight()); + }); + + var actual = expected.accordion('resize'); equals(actual, expected, 'resize is chainable'); - ok(false, 'missing test - untested code is broken code'); + + var sizes2 = []; + expected.find(".ui-accordion-content").each(function() { + sizes2.push($(this).outerHeight()); + }); + same(sizes, sizes2); + + expected.find(".ui-accordion-content:first").height(500) + var sizes3 = []; }); })(jQuery); diff --git a/tests/unit/accordion/accordion_options.js b/tests/unit/accordion/accordion_options.js index 29fc9c032..35e87d432 100644 --- a/tests/unit/accordion/accordion_options.js +++ b/tests/unit/accordion/accordion_options.js @@ -3,38 +3,57 @@ */ (function($) { +function state(accordion) { + var expected = $.makeArray(arguments).slice(1); + var actual = []; + $.each(expected, function(i, n) { + actual.push( accordion.find(".ui-accordion-content").eq(i).is(":visible") ? 1 : 0 ); + }); + same(actual, expected) +} + + module("accordion: options"); test("{ active: first child }, default", function() { - $("#list1").accordion(); - equals( $("#list1").accordion('option', 'active'), 0); + var ac = $("#list1").accordion(); + equals( ac.accordion('option', 'active'), 0); + state(ac, 1, 0, 0) }); test("{ active: Selector }", function() { - ok(false, 'missing test - untested code is broken code'); + var ac = $("#list1").accordion({ + active: "a:last" + }); + state(ac, 0, 0, 1); + ac.accordion('option', 'active', "a:eq(1)"); + state(ac, 0, 1, 0); }); test("{ active: Element }", function() { - ok(false, 'missing test - untested code is broken code'); + var ac = $("#list1").accordion({ + active: $("#list1 a:last")[0] + }); + state(ac, 0, 0, 1); + ac.accordion('option', 'active', $("#list1 a:eq(1)")[0]); + state(ac, 0, 1, 0); }); test("{ active: jQuery Object }", function() { - ok(false, 'missing test - untested code is broken code'); -}); - -test("{ active: true }", function() { - $("#list1").accordion({ - active: true, - collapsible: false + var ac = $("#list1").accordion({ + active: $("#list1 a:last") }); - equals( $("#list1 .ui-accordion-header.ui-state-active").size(), 1, "one header selected" ); + state(ac, 0, 0, 1); + ac.accordion('option', 'active', $("#list1 a:eq(1)")); + state(ac, 0, 1, 0); }); test("{ active: false }", function() { - $("#list1").accordion({ + 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); }); @@ -56,18 +75,6 @@ test("{ active: Number }", function() { equals( $("#list1").accordion('option', 'active'), 0); }); -test("{ animated: false }, default", function() { - ok(false, 'missing test - untested code is broken code'); -}); - -test("{ animated: true }", function() { - ok(false, 'missing test - untested code is broken code'); -}); - -test("{ animated: String }", function() { - ok(false, 'missing test - untested code is broken code'); -}); - test("{ autoHeight: true }, default", function() { $('#navigation').accordion({ autoHeight: true }); equals( $('#navigation > li:eq(0) > ul').height(), 126 ); @@ -82,33 +89,20 @@ test("{ autoHeight: false }", function() { equals( $('#navigation > li:eq(2) > ul').height(), 54 ); }); -test("{ clearStyle: false }, default", function() { - ok(false, 'missing test - untested code is broken code'); -}); - -test("{ clearStyle: true }", function() { - ok(false, 'missing test - untested code is broken code'); -}); - test("{ collapsible: false }, default", function() { - ok(false, 'missing test - untested code is broken code'); + var ac = $("#list1").accordion(); + ac.accordion("activate", false); + state(ac, 1, 0, 0); }); test("{ collapsible: true }", function() { - $("#list1").accordion({ + var ac = $("#list1").accordion({ active: 1, collapsible: true }); - $('.ui-accordion-header:eq(1)', '#list1').click(); + var header = $('#list1 .ui-accordion-header:eq(1)').click(); equals( $("#list1").accordion('option', 'active'), false); -}); - -test("{ event: 'click' }, default", function() { - ok(false, 'missing test - untested code is broken code'); -}); - -test("{ event: 'mouseover' }", function() { - ok(false, 'missing test - untested code is broken code'); + state(ac, 0, 0, 0); }); test("{ fillSpace: false }, default", function() { @@ -128,23 +122,8 @@ test("{ fillSpace: true }", function() { }); test("{ header: '> li > :first-child,> :not(li):even' }, default", function() { - ok(false, 'missing test - untested code is broken code'); -}); - -test("{ header: Selector }", function() { - ok(false, 'missing test - untested code is broken code'); -}); - -test("{ header: jQuery Object }", function() { - ok(false, 'missing test - untested code is broken code'); -}); - -test("{ icons: { 'header': 'ui-icon-triangle-1-e', 'headerSelected': 'ui-icon-triangle-1-s' } }, default", function() { - ok(false, 'missing test - untested code is broken code'); -}); - -test("{ icons: { 'header': 'ui-icon-foo', 'headerSelected': 'ui-icon-bar' } }", function() { - ok(false, 'missing test - untested code is broken code'); + state($("#list1").accordion(), 1, 0, 0); + state($("#navigation").accordion(), 1, 0, 0); }); test("{ icons: false }", function() { |