From 140d90a9a4d0c77658ff8a811aebe899dcf11f2b Mon Sep 17 00:00:00 2001 From: Scott González Date: Mon, 24 Jan 2011 15:45:29 -0500 Subject: Accordion: Test cleanup. --- tests/unit/accordion/accordion_core.js | 59 ++++---- tests/unit/accordion/accordion_defaults.js | 7 +- .../accordion/accordion_defaults_deprecated.js | 25 ---- tests/unit/accordion/accordion_deprecated.html | 139 ------------------- tests/unit/accordion/accordion_deprecated.js | 154 --------------------- tests/unit/accordion/accordion_events.js | 54 ++++---- tests/unit/accordion/deprecated/accordion.html | 139 +++++++++++++++++++ .../deprecated/accordion_defaults_deprecated.js | 22 +++ .../accordion/deprecated/accordion_deprecated.js | 154 +++++++++++++++++++++ ui/jquery.ui.accordion.js | 4 +- 10 files changed, 374 insertions(+), 383 deletions(-) delete mode 100644 tests/unit/accordion/accordion_defaults_deprecated.js delete mode 100644 tests/unit/accordion/accordion_deprecated.html delete mode 100644 tests/unit/accordion/accordion_deprecated.js create mode 100644 tests/unit/accordion/deprecated/accordion.html create mode 100644 tests/unit/accordion/deprecated/accordion_defaults_deprecated.js create mode 100644 tests/unit/accordion/deprecated/accordion_deprecated.js diff --git a/tests/unit/accordion/accordion_core.js b/tests/unit/accordion/accordion_core.js index 40a711abf..fa0facc80 100644 --- a/tests/unit/accordion/accordion_core.js +++ b/tests/unit/accordion/accordion_core.js @@ -1,40 +1,35 @@ -/* - * accordion_core.js - */ +(function( $ ) { +module( "accordion: core" ); -(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); +test( "handle click on header-descendant", function() { + var ac = $( "#navigation" ).accordion(); + $( "#navigation h2:eq(1) a" ).click(); + state( ac, 0, 1, 0 ); }); -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( "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("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"); +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 78630adc7..c2904d39a 100644 --- a/tests/unit/accordion/accordion_defaults.js +++ b/tests/unit/accordion/accordion_defaults.js @@ -1,6 +1,3 @@ -/* - * accordion_defaults.js - */ var accordion_defaults = { active: 0, @@ -11,8 +8,8 @@ var accordion_defaults = { header: "> li > :first-child,> :not(li):even", heightStyle: "auto", icons: { - "header": "ui-icon-triangle-1-e", - "activeHeader": "ui-icon-triangle-1-s" + "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 deleted file mode 100644 index 41998ea7a..000000000 --- a/tests/unit/accordion/accordion_defaults_deprecated.js +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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 } ); diff --git a/tests/unit/accordion/accordion_deprecated.html b/tests/unit/accordion/accordion_deprecated.html deleted file mode 100644 index c104df4d5..000000000 --- a/tests/unit/accordion/accordion_deprecated.html +++ /dev/null @@ -1,139 +0,0 @@ - - - - - jQuery UI Accordion Test Suite - - - - - - - - - - - - - - - - - - - - - - - - - - - -

jQuery UI Accordion Test Suite

-

-

-
    -
- -
- -
-
-

There is one obvious advantage:

-
-

- You've seen it coming! -
- Buy now and get nothing for free! -
- Well, at least no free beer. Perhaps a bear, if you can afford it. -

-
-

Now that you've got...

-
-

- your bear, you have to admit it! -
- No, we aren't selling bears. -

-

- We could talk about renting one. -

-
-

Rent one bear, ...

-
-

- get two for three beer. -

-

- And now, for something completely different. -

-
-
-
- - - -
- - - diff --git a/tests/unit/accordion/accordion_deprecated.js b/tests/unit/accordion/accordion_deprecated.js deleted file mode 100644 index b219cf8c3..000000000 --- a/tests/unit/accordion/accordion_deprecated.js +++ /dev/null @@ -1,154 +0,0 @@ -/* - * accordion_core.js - */ - - -(function($) { - -module("accordion (deprecated): expanded active option, activate method"); - -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("{ 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"); - -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] ); -}); - -// fillSpace: false == autoHeight: true, covered above -test("{ fillSpace: true }", function() { - $("#navigationWrapper").height(500); - equalHeights($('#navigation').accordion({ fillSpace: true }), 446, 458); -}); - -test("{ fillSpace: true } with sibling", function() { - $("#navigationWrapper").height(500); - var sibling = $("

Lorem Ipsum

"); - $("#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 = $("

Lorem Ipsum

"); - $("#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); -}); - - - - -module("accordion (deprecated) - icons"); - -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); -}); - -})(jQuery); diff --git a/tests/unit/accordion/accordion_events.js b/tests/unit/accordion/accordion_events.js index 4798f7404..ff9590eac 100644 --- a/tests/unit/accordion/accordion_events.js +++ b/tests/unit/accordion/accordion_events.js @@ -1,30 +1,32 @@ -/* - * accordion_events.js - */ -(function($) { +(function( $ ) { -module("accordion: events"); +module( "accordion: events" ); -test("accordionchange event, open closed and close again", function() { - expect(8); - $("#list1").accordion({ - active: false, - collapsible: true - }) - .one("accordionchange", function(event, ui) { - equals( ui.oldHeader.size(), 0 ); - equals( ui.oldContent.size(), 0 ); - equals( ui.newHeader.size(), 1 ); - equals( ui.newContent.size(), 1 ); - }) - .accordion("option", "active", 0) - .one("accordionchange", function(event, ui) { - equals( ui.oldHeader.size(), 1 ); - equals( ui.oldContent.size(), 1 ); - equals( ui.newHeader.size(), 0 ); - equals( ui.newContent.size(), 0 ); - }) - .accordion("option", "active", false); +// TODO: verify correct elements in ui properties +// TODO: add tests for switching between active panels (not collapsed) +// TODO: add tests for changestart +// TODO: move change/changestart to deprecated tests (add activate/beforeactivate) +test( "accordionchange event, open closed and close again", function() { + expect( 8 ); + $( "#list1" ) + .accordion({ + active: false, + collapsible: true + }) + .one( "accordionchange", function( event, ui ) { + equals( ui.oldHeader.size(), 0 ); + equals( ui.oldContent.size(), 0 ); + equals( ui.newHeader.size(), 1 ); + equals( ui.newContent.size(), 1 ); + }) + .accordion( "option", "active", 0 ) + .one( "accordionchange", function( event, ui ) { + equals( ui.oldHeader.size(), 1 ); + equals( ui.oldContent.size(), 1 ); + equals( ui.newHeader.size(), 0 ); + equals( ui.newContent.size(), 0 ); + }) + .accordion( "option", "active", false ); }); -})(jQuery); +}( jQuery ) ); diff --git a/tests/unit/accordion/deprecated/accordion.html b/tests/unit/accordion/deprecated/accordion.html new file mode 100644 index 000000000..d5e55f2e4 --- /dev/null +++ b/tests/unit/accordion/deprecated/accordion.html @@ -0,0 +1,139 @@ + + + + + jQuery UI Accordion Test Suite + + + + + + + + + + + + + + + + + + + + + + + + + + + +

jQuery UI Accordion Test Suite

+

+

+
    +
+ +
+ +
+
+

There is one obvious advantage:

+
+

+ You've seen it coming! +
+ Buy now and get nothing for free! +
+ Well, at least no free beer. Perhaps a bear, if you can afford it. +

+
+

Now that you've got...

+
+

+ your bear, you have to admit it! +
+ No, we aren't selling bears. +

+

+ We could talk about renting one. +

+
+

Rent one bear, ...

+
+

+ get two for three beer. +

+

+ And now, for something completely different. +

+
+
+
+ + + +
+ + + diff --git a/tests/unit/accordion/deprecated/accordion_defaults_deprecated.js b/tests/unit/accordion/deprecated/accordion_defaults_deprecated.js new file mode 100644 index 000000000..386354e83 --- /dev/null +++ b/tests/unit/accordion/deprecated/accordion_defaults_deprecated.js @@ -0,0 +1,22 @@ + +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: { + "activeHeader": null, + "header": "ui-icon-triangle-1-e", + "headerSelected": "ui-icon-triangle-1-s" + }, + navigation: false, + navigationFilter: function() {} +}; + +commonWidgetTests( "accordion", { defaults: accordion_defaults } ); diff --git a/tests/unit/accordion/deprecated/accordion_deprecated.js b/tests/unit/accordion/deprecated/accordion_deprecated.js new file mode 100644 index 000000000..b219cf8c3 --- /dev/null +++ b/tests/unit/accordion/deprecated/accordion_deprecated.js @@ -0,0 +1,154 @@ +/* + * accordion_core.js + */ + + +(function($) { + +module("accordion (deprecated): expanded active option, activate method"); + +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("{ 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"); + +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] ); +}); + +// fillSpace: false == autoHeight: true, covered above +test("{ fillSpace: true }", function() { + $("#navigationWrapper").height(500); + equalHeights($('#navigation').accordion({ fillSpace: true }), 446, 458); +}); + +test("{ fillSpace: true } with sibling", function() { + $("#navigationWrapper").height(500); + var sibling = $("

Lorem Ipsum

"); + $("#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 = $("

Lorem Ipsum

"); + $("#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); +}); + + + + +module("accordion (deprecated) - icons"); + +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); +}); + +})(jQuery); diff --git a/ui/jquery.ui.accordion.js b/ui/jquery.ui.accordion.js index a06cd2a2a..d855da5f3 100644 --- a/ui/jquery.ui.accordion.js +++ b/ui/jquery.ui.accordion.js @@ -22,8 +22,8 @@ $.widget( "ui.accordion", { header: "> li > :first-child,> :not(li):even", heightStyle: "auto", icons: { - header: "ui-icon-triangle-1-e", - activeHeader: "ui-icon-triangle-1-s" + activeHeader: "ui-icon-triangle-1-s", + header: "ui-icon-triangle-1-e" } }, -- cgit v1.2.3