From bc71499a505d0932668b4ae75603cd9dbfd4a2ac Mon Sep 17 00:00:00 2001 From: Scott González Date: Sun, 23 Jan 2011 19:58:31 -0500 Subject: Widget: Added tests for defaultElement and element normalization between jQuery objects, elements and selectors. --- tests/unit/widget/widget_core.js | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'tests/unit') diff --git a/tests/unit/widget/widget_core.js b/tests/unit/widget/widget_core.js index 388e078b0..189b75368 100644 --- a/tests/unit/widget/widget_core.js +++ b/tests/unit/widget/widget_core.js @@ -26,6 +26,47 @@ test( "widget creation", function() { "option method copied over from base widget" ); }); +test( "element normalization", function() { + expect( 10 ); + 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 = ""; + $.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 = $( "" ); + $.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 = $( "
" ); + $.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 = $( "
" ) + .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" ); +}); + test( "jQuery usage", function() { expect( 11 ); -- cgit v1.2.3 From cc90b440607a1af87c4abb8b2ee3325e96b0f5a1 Mon Sep 17 00:00:00 2001 From: Scott González Date: Mon, 24 Jan 2011 13:33:24 -0500 Subject: Widget: Allow this.element to be the widget instance instead of a DOM element. Fixes #6895 - Widget: Allow non-DOM based widget. --- tests/unit/widget/widget_core.js | 32 +++++++++++++++++++++++++++++++- ui/jquery.ui.widget.js | 2 +- 2 files changed, 32 insertions(+), 2 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/widget/widget_core.js b/tests/unit/widget/widget_core.js index 189b75368..269b897c5 100644 --- a/tests/unit/widget/widget_core.js +++ b/tests/unit/widget/widget_core.js @@ -27,7 +27,7 @@ test( "widget creation", function() { }); test( "element normalization", function() { - expect( 10 ); + expect( 12 ); var elem; $.widget( "ui.testWidget", {} ); @@ -65,6 +65,14 @@ test( "element normalization", function() { 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" ); + ok( this.element.data( "testWidget" ) === this, "instance stored in .data()" ); + }; + $.ui.testWidget(); }); test( "jQuery usage", function() { @@ -573,6 +581,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", { diff --git a/ui/jquery.ui.widget.js b/ui/jquery.ui.widget.js index f6089519b..7dfcb4447 100644 --- a/ui/jquery.ui.widget.js +++ b/ui/jquery.ui.widget.js @@ -133,7 +133,7 @@ $.Widget.prototype = { disabled: false }, _createWidget: function( options, element ) { - element = $( element || this.defaultElement )[ 0 ]; + element = $( element || this.defaultElement || this )[ 0 ]; $.data( element, this.widgetName, this ); this.element = $( element ); this.options = $.extend( true, {}, -- cgit v1.2.3 From c96c2497803779c11d8e666f2f8129bbba01fee9 Mon Sep 17 00:00:00 2001 From: Scott González Date: Mon, 24 Jan 2011 14:38:23 -0500 Subject: Accordion: First pass at splitting out tests for deprecated functionality. --- tests/unit/accordion/accordion.html | 85 +++++---- tests/unit/accordion/accordion_defaults.js | 16 +- .../accordion/accordion_defaults_deprecated.js | 25 +++ tests/unit/accordion/accordion_deprecated.html | 139 ++++++++++++++ tests/unit/accordion/accordion_deprecated.js | 154 +++++++++++++++ tests/unit/accordion/accordion_methods.js | 59 +----- tests/unit/accordion/accordion_options.js | 75 -------- ui/jquery.ui.accordion.js | 207 +++++++++++---------- 8 files changed, 474 insertions(+), 286 deletions(-) create mode 100644 tests/unit/accordion/accordion_defaults_deprecated.js create mode 100644 tests/unit/accordion/accordion_deprecated.html create mode 100644 tests/unit/accordion/accordion_deprecated.js (limited to 'tests/unit') diff --git a/tests/unit/accordion/accordion.html b/tests/unit/accordion/accordion.html index 61d168386..88226be31 100644 --- a/tests/unit/accordion/accordion.html +++ b/tests/unit/accordion/accordion.html @@ -1,55 +1,58 @@ - + jQuery UI Accordion Test Suite - + - - - - + + + + + - - - - + + + + - - - - - - - - - + + + + + + + + diff --git a/tests/unit/accordion/accordion_defaults.js b/tests/unit/accordion/accordion_defaults.js index d29c1e848..78630adc7 100644 --- a/tests/unit/accordion/accordion_defaults.js +++ b/tests/unit/accordion/accordion_defaults.js @@ -5,19 +5,15 @@ 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() {} + heightStyle: "auto", + icons: { + "header": "ui-icon-triangle-1-e", + "activeHeader": "ui-icon-triangle-1-s" + } }; -commonWidgetTests('accordion', { defaults: accordion_defaults }); +commonWidgetTests( "accordion", { defaults: accordion_defaults } ); diff --git a/tests/unit/accordion/accordion_defaults_deprecated.js b/tests/unit/accordion/accordion_defaults_deprecated.js new file mode 100644 index 000000000..41998ea7a --- /dev/null +++ b/tests/unit/accordion/accordion_defaults_deprecated.js @@ -0,0 +1,25 @@ +/* + * 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 new file mode 100644 index 000000000..c104df4d5 --- /dev/null +++ b/tests/unit/accordion/accordion_deprecated.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/accordion_deprecated.js b/tests/unit/accordion/accordion_deprecated.js new file mode 100644 index 000000000..b219cf8c3 --- /dev/null +++ b/tests/unit/accordion/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/tests/unit/accordion/accordion_methods.js b/tests/unit/accordion/accordion_methods.js index c801851d0..c6754d277 100644 --- a/tests/unit/accordion/accordion_methods.js +++ b/tests/unit/accordion/accordion_methods.js @@ -57,66 +57,9 @@ test("disable", function() { state(expected, 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({ - fillSpace: true + heightStyle: "fill" }); equalHeights(expected, 246, 258); diff --git a/tests/unit/accordion/accordion_options.js b/tests/unit/accordion/accordion_options.js index abfb82d78..c7b4038ef 100644 --- a/tests/unit/accordion/accordion_options.js +++ b/tests/unit/accordion/accordion_options.js @@ -11,33 +11,6 @@ test("{ active: first child }, default", function() { 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({ active: false, @@ -65,25 +38,10 @@ test("{ active: Number }", function() { equals( $("#list1").accordion('option', 'active'), 0); }); -test("{ autoHeight: true }, default", function() { - equalHeights($('#navigation').accordion({ autoHeight: true }), 95, 130); -}); - 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()); - }); - 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: 'content' }", function() { var accordion = $('#navigation').accordion({ heightStyle: 'content' }); var sizes = []; @@ -110,36 +68,11 @@ test("{ collapsible: true }", function() { 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 = $("

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); -}); - test("{ header: '> li > :first-child,> :not(li):even' }, default", function() { state($("#list1").accordion(), 1, 0, 0); state($("#navigation").accordion(), 1, 0, 0); @@ -192,12 +125,4 @@ test("{ navigation: true, navigationFilter: content }", function() { 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); -}); - })(jQuery); diff --git a/ui/jquery.ui.accordion.js b/ui/jquery.ui.accordion.js index b9147abe0..a06cd2a2a 100644 --- a/ui/jquery.ui.accordion.js +++ b/ui/jquery.ui.accordion.js @@ -20,12 +20,10 @@ $.widget( "ui.accordion", { collapsible: false, event: "click", header: "> li > :first-child,> :not(li):even", - // TODO: set to "auto" in 2.0 (#5868, #5872) - heightStyle: null, // "auto" + heightStyle: "auto", icons: { header: "ui-icon-triangle-1-e", - // TODO: set to "ui-icon-triangle-1-s" in 2.0 (#6835) - activeHeader: null // "ui-icon-triangle-1-s" + activeHeader: "ui-icon-triangle-1-s" } }, @@ -599,115 +597,120 @@ $.extend( $.ui.accordion, { // DEPRECATED - -// navigation options -(function( $, prototype ) { - $.extend( prototype.options, { - navigation: false, - navigationFilter: function() { - return this.href.toLowerCase() === location.href.toLowerCase(); - } - }); - - var _create = prototype._create; - prototype._create = function() { - if ( this.options.navigation ) { - var self = this, - headers = this.element.find( this.options.header ), - content = headers.next(); - current = headers.add( content ) - .find( "a" ) - .filter( this.options.navigationFilter ) - [ 0 ]; - if ( current ) { - headers.add( content ).each( function( index ) { - if ( $.contains( this, current ) ) { - self.options.active = Math.floor( index / 2 ); - return false; - } - }); +if ( $.uiBackCompat !== false ) { + // navigation options + (function( $, prototype ) { + $.extend( prototype.options, { + navigation: false, + navigationFilter: function() { + return this.href.toLowerCase() === location.href.toLowerCase(); + } + }); + + var _create = prototype._create; + prototype._create = function() { + if ( this.options.navigation ) { + var self = this, + headers = this.element.find( this.options.header ), + content = headers.next(); + current = headers.add( content ) + .find( "a" ) + .filter( this.options.navigationFilter ) + [ 0 ]; + if ( current ) { + headers.add( content ).each( function( index ) { + if ( $.contains( this, current ) ) { + self.options.active = Math.floor( index / 2 ); + return false; + } + }); + } } - } - _create.call( this ); - }; -}( jQuery, jQuery.ui.accordion.prototype ) ); - -// height options -(function( $, prototype ) { - $.extend( prototype.options, { - autoHeight: true, // use heightStyle: "auto" - clearStyle: false, // use heightStyle: "content" - fillSpace: false // use heightStyle: "fill" - }); - - var _create = prototype._create, - _setOption = prototype._setOption; - - $.extend( prototype, { - _create: function() { - this.options.heightStyle = this.options.heightStyle || - this._mergeHeightStyle(); - _create.call( this ); - }, + }; + }( jQuery, jQuery.ui.accordion.prototype ) ); + + // height options + (function( $, prototype ) { + $.extend( prototype.options, { + heightStyle: null, // remove default so we fall back to old values + autoHeight: true, // use heightStyle: "auto" + clearStyle: false, // use heightStyle: "content" + fillSpace: false // use heightStyle: "fill" + }); + + var _create = prototype._create, + _setOption = prototype._setOption; + + $.extend( prototype, { + _create: function() { + this.options.heightStyle = this.options.heightStyle || + this._mergeHeightStyle(); + + _create.call( this ); + }, - _setOption: function( key, value ) { - if ( key === "autoHeight" || key === "clearStyle" || key === "fillSpace" ) { - this.options.heightStyle = this._mergeHeightStyle(); - } - _setOption.apply( this, arguments ); - }, + _setOption: function( key, value ) { + if ( key === "autoHeight" || key === "clearStyle" || key === "fillSpace" ) { + this.options.heightStyle = this._mergeHeightStyle(); + } + _setOption.apply( this, arguments ); + }, - _mergeHeightStyle: function() { - var options = this.options; + _mergeHeightStyle: function() { + var options = this.options; - if ( options.fillSpace ) { - return "fill"; - } + if ( options.fillSpace ) { + return "fill"; + } - if ( options.clearStyle ) { - return "content"; - } + if ( options.clearStyle ) { + return "content"; + } - if ( options.autoHeight ) { - return "auto"; + if ( options.autoHeight ) { + return "auto"; + } } - } - }); -}( jQuery, jQuery.ui.accordion.prototype ) ); - -// icon options -(function( $, prototype ) { - prototype.options.icons.headerSelected = "ui-icon-triangle-1-s"; - - var _createIcons = prototype._createIcons; - prototype._createIcons = function() { - this.options.icons.activeHeader = this.options.icons.activeHeader || - this.options.icons.headerSelected; - _createIcons.call( this ); - }; -}( jQuery, jQuery.ui.accordion.prototype ) ); - -// expanded active option, activate method -(function( $, prototype ) { - prototype.activate = prototype._activate; - - var _findActive = prototype._findActive; - prototype._findActive = function( index ) { - if ( index === -1 ) { - index = false; - } - if ( index && typeof index !== "number" ) { - index = this.headers.index( this.headers.filter( index ) ); + }); + }( jQuery, jQuery.ui.accordion.prototype ) ); + + // icon options + (function( $, prototype ) { + $.extend( prototype.options.icons, { + activeHeader: null, // remove default so we fall back to old values + headerSelected: "ui-icon-triangle-1-s" + }); + + var _createIcons = prototype._createIcons; + prototype._createIcons = function() { + this.options.icons.activeHeader = this.options.icons.activeHeader || + this.options.icons.headerSelected; + _createIcons.call( this ); + }; + }( jQuery, jQuery.ui.accordion.prototype ) ); + + // expanded active option, activate method + (function( $, prototype ) { + prototype.activate = prototype._activate; + + var _findActive = prototype._findActive; + prototype._findActive = function( index ) { if ( index === -1 ) { index = false; } - } - return _findActive.call( this, index ); - }; -}( jQuery, jQuery.ui.accordion.prototype ) ); + if ( index && typeof index !== "number" ) { + index = this.headers.index( this.headers.filter( index ) ); + if ( index === -1 ) { + index = false; + } + } + return _findActive.call( this, index ); + }; + }( jQuery, jQuery.ui.accordion.prototype ) ); -// resize method -jQuery.ui.accordion.prototype.resize = jQuery.ui.accordion.prototype.refresh; + // resize method + jQuery.ui.accordion.prototype.resize = jQuery.ui.accordion.prototype.refresh; +} })( jQuery ); -- cgit v1.2.3 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 (limited to 'tests/unit') 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 From ecc0ef53dee0eb3ce432348762abf4550aad8b36 Mon Sep 17 00:00:00 2001 From: Scott González Date: Mon, 24 Jan 2011 16:00:34 -0500 Subject: Accordion tests: Getting really ghetto in an attempt to get deprecated tests to run in TestSwarm. --- tests/unit/accordion/accordio.html | 139 +++++++++++++++++++ .../accordion/accordion_defaults_deprecated.js | 22 +++ tests/unit/accordion/accordion_deprecated.js | 154 +++++++++++++++++++++ tests/unit/accordion/deprecated/accordion.html | 139 ------------------- .../deprecated/accordion_defaults_deprecated.js | 22 --- .../accordion/deprecated/accordion_deprecated.js | 154 --------------------- 6 files changed, 315 insertions(+), 315 deletions(-) create mode 100644 tests/unit/accordion/accordio.html create mode 100644 tests/unit/accordion/accordion_defaults_deprecated.js create mode 100644 tests/unit/accordion/accordion_deprecated.js delete mode 100644 tests/unit/accordion/deprecated/accordion.html delete mode 100644 tests/unit/accordion/deprecated/accordion_defaults_deprecated.js delete mode 100644 tests/unit/accordion/deprecated/accordion_deprecated.js (limited to 'tests/unit') diff --git a/tests/unit/accordion/accordio.html b/tests/unit/accordion/accordio.html new file mode 100644 index 000000000..c104df4d5 --- /dev/null +++ b/tests/unit/accordion/accordio.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/accordion_defaults_deprecated.js b/tests/unit/accordion/accordion_defaults_deprecated.js new file mode 100644 index 000000000..386354e83 --- /dev/null +++ b/tests/unit/accordion/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/accordion_deprecated.js b/tests/unit/accordion/accordion_deprecated.js new file mode 100644 index 000000000..b219cf8c3 --- /dev/null +++ b/tests/unit/accordion/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/tests/unit/accordion/deprecated/accordion.html b/tests/unit/accordion/deprecated/accordion.html deleted file mode 100644 index d5e55f2e4..000000000 --- a/tests/unit/accordion/deprecated/accordion.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/deprecated/accordion_defaults_deprecated.js b/tests/unit/accordion/deprecated/accordion_defaults_deprecated.js deleted file mode 100644 index 386354e83..000000000 --- a/tests/unit/accordion/deprecated/accordion_defaults_deprecated.js +++ /dev/null @@ -1,22 +0,0 @@ - -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 deleted file mode 100644 index b219cf8c3..000000000 --- a/tests/unit/accordion/deprecated/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); -- cgit v1.2.3 From 5ed1046a4ac271a1f20cc1f19aa50bec15cd9704 Mon Sep 17 00:00:00 2001 From: Scott González Date: Mon, 24 Jan 2011 19:20:09 -0500 Subject: Accordion tests: Cleanup. --- tests/unit/accordion/accordio.html | 43 ++-- tests/unit/accordion/accordion.html | 43 ++-- tests/unit/accordion/accordion_core.js | 2 +- tests/unit/accordion/accordion_defaults.js | 29 ++- .../accordion/accordion_defaults_deprecated.js | 43 ++-- tests/unit/accordion/accordion_deprecated.js | 52 ++++- tests/unit/accordion/accordion_events.js | 2 +- tests/unit/accordion/accordion_methods.js | 105 ++++------ tests/unit/accordion/accordion_options.js | 228 +++++++++++++-------- tests/unit/accordion/accordion_tickets.js | 9 +- tests/unit/testsuite.js | 74 ++++--- 11 files changed, 369 insertions(+), 261 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/accordion/accordio.html b/tests/unit/accordion/accordio.html index c104df4d5..db202fe43 100644 --- a/tests/unit/accordion/accordio.html +++ b/tests/unit/accordion/accordio.html @@ -17,30 +17,37 @@ - + diff --git a/tests/unit/accordion/accordion.html b/tests/unit/accordion/accordion.html index 88226be31..23380000e 100644 --- a/tests/unit/accordion/accordion.html +++ b/tests/unit/accordion/accordion.html @@ -20,30 +20,37 @@ - + diff --git a/tests/unit/accordion/accordion_core.js b/tests/unit/accordion/accordion_core.js index fa0facc80..601d2ed44 100644 --- a/tests/unit/accordion/accordion_core.js +++ b/tests/unit/accordion/accordion_core.js @@ -1,6 +1,6 @@ (function( $ ) { -module( "accordion: core" ); +module( "accordion: core", accordionSetupTeardown() ); test( "handle click on header-descendant", function() { var ac = $( "#navigation" ).accordion(); diff --git a/tests/unit/accordion/accordion_defaults.js b/tests/unit/accordion/accordion_defaults.js index c2904d39a..95a478057 100644 --- a/tests/unit/accordion/accordion_defaults.js +++ b/tests/unit/accordion/accordion_defaults.js @@ -1,16 +1,15 @@ - -var accordion_defaults = { - active: 0, - animated: false, - 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" +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" + } } -}; - -commonWidgetTests( "accordion", { defaults: accordion_defaults } ); +}); diff --git a/tests/unit/accordion/accordion_defaults_deprecated.js b/tests/unit/accordion/accordion_defaults_deprecated.js index 386354e83..b90b472e2 100644 --- a/tests/unit/accordion/accordion_defaults_deprecated.js +++ b/tests/unit/accordion/accordion_defaults_deprecated.js @@ -1,22 +1,21 @@ - -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 } ); +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 index b219cf8c3..2fa3ca41a 100644 --- a/tests/unit/accordion/accordion_deprecated.js +++ b/tests/unit/accordion/accordion_deprecated.js @@ -5,7 +5,7 @@ (function($) { -module("accordion (deprecated): expanded active option, activate method"); +module("accordion (deprecated): expanded active option, activate method", accordionSetupTeardown() ); test("activate", function() { var expected = $('#list1').accordion(), @@ -96,7 +96,7 @@ test("{ active: jQuery Object }", function() { -module("accordion (deprecated) - height options"); +module("accordion (deprecated) - height options", accordionSetupTeardown() ); test("{ autoHeight: true }, default", function() { equalHeights($('#navigation').accordion({ autoHeight: true }), 95, 130); @@ -141,7 +141,7 @@ test("{ fillSpace: true } with multiple siblings", function() { -module("accordion (deprecated) - icons"); +module("accordion (deprecated) - icons", accordionSetupTeardown() ); test("change headerSelected option after creation", function() { var list = $("#list1"); @@ -151,4 +151,50 @@ test("change headerSelected option after creation", function() { equals( $( "#list1 span.deprecated" ).length, 1); }); + + + + +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() { + $("#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" ); +}); + +test("{ navigation: true, navigationFilter: content }", function() { + $("#navigation").accordion({ + navigation: true, + navigationFilter: function() { + return /\?p=1\.1\.3\.2$/.test(this.href); + } + }); + equals( $("#navigation .ui-accordion-content:eq(2)").size(), 1, "third content active" ); +}); + })(jQuery); diff --git a/tests/unit/accordion/accordion_events.js b/tests/unit/accordion/accordion_events.js index ff9590eac..e0dbe82eb 100644 --- a/tests/unit/accordion/accordion_events.js +++ b/tests/unit/accordion/accordion_events.js @@ -1,6 +1,6 @@ (function( $ ) { -module( "accordion: events" ); +module( "accordion: events", accordionSetupTeardown() ); // TODO: verify correct elements in ui properties // TODO: add tests for switching between active panels (not collapsed) diff --git a/tests/unit/accordion/accordion_methods.js b/tests/unit/accordion/accordion_methods.js index c6754d277..e0ed734f6 100644 --- a/tests/unit/accordion/accordion_methods.js +++ b/tests/unit/accordion/accordion_methods.js @@ -1,71 +1,48 @@ -/* - * accordion_methods.js - */ -(function($) { - -module("accordion: methods"); - -test("init", function() { - $("
").appendTo('body').accordion().remove(); - ok(true, '.accordion() called on element'); - - $([]).accordion().remove(); - ok(true, '.accordion() called on empty collection'); - - $('
').accordion().remove(); - ok(true, '.accordion() called on disconnected DOMElement - never connected'); - - $('
').appendTo('body').remove().accordion().remove(); - ok(true, '.accordion() called on disconnected DOMElement - removed'); - - var el = $('
').accordion(); - var foo = el.accordion("option", "foo"); - el.remove(); - ok(true, 'arbitrary option getter after init'); - - $('
').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("refresh", function() { - var expected = $('#navigation').parent().height(300).end().accordion({ - heightStyle: "fill" - }); - equalHeights(expected, 246, 258); - - expected.parent().height(500); - expected.accordion("refresh"); - equalHeights(expected, 446, 458); +test( "refresh", function() { + var expected = $( "#navigation" ) + .parent() + .height( 300 ) + .end() + .accordion({ + heightStyle: "fill" + }); + equalHeights( expected, 246, 258 ); + + 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 c7b4038ef..0e02f0372 100644 --- a/tests/unit/accordion/accordion_options.js +++ b/tests/unit/accordion/accordion_options.js @@ -1,128 +1,176 @@ -/* - * 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: 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); + 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() { - expect(4); - $("#list1").accordion({ - active: 0 +test( "{ active: Number }", function() { + var ac = $( "#list1" ).accordion({ + active: 2 }); - equals( $("#list1").accordion('option', 'active'), 0); + equals( ac.accordion( "option", "active" ), 2 ); + state( ac, 0, 0, 1 ); - $("#list1").accordion('option', 'active', 1); - equals( $("#list1").accordion('option', 'active'), 1); + ac.accordion( "option", "active", 0 ); + equals( ac.accordion( "option", "active" ), 0 ); + state( ac, 1, 0, 0 ); - $('.ui-accordion-header:eq(2)', '#list1').click(); - equals( $("#list1").accordion('option', 'active'), 2); + ac.find( ".ui-accordion-header" ).eq( 1 ).click(); + equals( ac.accordion( "option", "active" ), 1 ); + state( ac, 0, 1, 0 ); - $("#list1").accordion('option', 'active', 0); - equals( $("#list1").accordion('option', 'active'), 0); + ac.accordion( "option", "active", 10 ); + equals( ac.accordion( "option", "active" ), 1 ); + state( ac, 0, 1, 0 ); }); -test("{ heightStyle: 'auto' }, default", function() { - equalHeights($('#navigation').accordion({ heightStyle: 'auto' }), 95, 130); -}); +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 ); + }); +} + +// TODO: add animation tests -test("{ heightStyle: 'content' }", function() { - var accordion = $('#navigation').accordion({ heightStyle: 'content' }); - 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] ); -}); -test("{ collapsible: false }, default", function() { - var ac = $("#list1").accordion(); - ac.accordion("option", "active", false); - state(ac, 1, 0, 0); + ac.accordion( "option", "active", false ); + equal( ac.accordion( "option", "active" ), 1 ); + state( ac, 0, 1, 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); + + // 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 ); }); -test("{ heightStyle: 'fill' }", function() { - $("#navigationWrapper").height(500); - equalHeights($('#navigation').accordion({ heightStyle: 'fill' }), 446, 458); +// 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("{ header: '> li > :first-child,> :not(li):even' }, default", function() { - state($("#list1").accordion(), 1, 0, 0); - state($("#navigation").accordion(), 1, 0, 0); +test( "{ heightStyle: 'auto' }", function() { + var ac = $( "#navigation" ).accordion({ heightStyle: "auto" }); + equalHeights( ac, 95, 130 ); }); -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 ); - } - list.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( "{ 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("{ 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( "{ heightStyle: 'fill' }", function() { + $( "#navigationWrapper" ).height( 500 ); + var ac = $( "#navigation" ).accordion({ heightStyle: "fill" }); + equalHeights( ac, 446, 458); + ac.accordion( "destroy" ); + + $( "
" ).height( 100 ).appendTo( "#navigationWrapper" ); + ac.accordion({ heightStyle: "fill" }); + equalHeights( ac, 346, 358 ); }); -test("{ navigation: true, navigationFilter: header }", function() { - $("#navigation").accordion({ - navigation: true, - navigationFilter: function() { - return /\?p=1\.1\.3$/.test(this.href); - } +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: false }); - equals( $("#navigation .ui-accordion-content:eq(2)").size(), 1, "third content active" ); + icons( false ); + list.accordion( "option", "icons", $.ui.accordion.prototype.options.icons ); + 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" ); + 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..23819d0e4 100644 --- a/tests/unit/testsuite.js +++ b/tests/unit/testsuite.js @@ -1,39 +1,67 @@ -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 ) { + 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" ); + + $( defaultElement ).accordion().remove(); + ok( true, "initialized on disconnected DOMElement - never connected" ); - testWidgetDefaults(widget, settings.defaults); - testWidgetOverrides(widget); + $( defaultElement ).appendTo( "body" ).remove().accordion().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 ); +}; + +}()); -- cgit v1.2.3 From 25f420eb9a82dcecc6da8357454cdc3c3327c4d1 Mon Sep 17 00:00:00 2001 From: Scott González Date: Mon, 24 Jan 2011 20:35:58 -0500 Subject: Accordion tests: Cleaned up deprecated tests. --- tests/unit/accordion/accordion_deprecated.js | 280 +++++++++++++++------------ tests/unit/accordion/accordion_options.js | 46 ++++- 2 files changed, 193 insertions(+), 133 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/accordion/accordion_deprecated.js b/tests/unit/accordion/accordion_deprecated.js index 2fa3ca41a..a0ca3f634 100644 --- a/tests/unit/accordion/accordion_deprecated.js +++ b/tests/unit/accordion/accordion_deprecated.js @@ -1,104 +1,100 @@ -/* - * accordion_core.js - */ - - -(function($) { - -module("accordion (deprecated): expanded active option, activate method", accordionSetupTeardown() ); - -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() { +(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); + 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] +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); + 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") +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); + state( ac, 0, 0, 1 ); + ac.accordion( "option", "active", $( "#list1 h3:eq(1)" ) ); + state( ac, 0, 1, 0 ); }); +module( "accordion (deprecated) - height options", accordionSetupTeardown() ); -module("accordion (deprecated) - height options", accordionSetupTeardown() ); - -test("{ autoHeight: true }, default", function() { +test( "{ autoHeight: true }, default", function() { equalHeights($('#navigation').accordion({ autoHeight: true }), 95, 130); }); @@ -113,42 +109,67 @@ test("{ autoHeight: false }", function() { 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", accordionSetupTeardown() ); - -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); +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 ); + $( "

Lorem Ipsum

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

Lorem Ipsum

" ) + .css({ + height: 50, + marginTop: 20, + marginBottom: 30 + }) + .prependTo( "#navigationWrapper" ); + $( "

Lorem Ipsum

" ) + .css({ + height: 50, + marginTop: 20, + marginBottom: 30, + position: "absolute" + }) + .prependTo( "#navigationWrapper" ); + $( "

Lorem Ipsum

" ) + .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" ) ); }); @@ -175,26 +196,29 @@ test( "resize", function() { + module( "accordion (deprecated) - navigation", accordionSetupTeardown() ); -test("{ navigation: true, navigationFilter: header }", function() { - $("#navigation").accordion({ +test( "{ navigation: true, navigationFilter: header }", function() { + var ac = $( "#navigation" ).accordion({ navigation: true, navigationFilter: function() { - return /\?p=1\.1\.3$/.test(this.href); + return /\?p=1\.1\.3$/.test( this.href ); } }); - equals( $("#navigation .ui-accordion-content:eq(2)").size(), 1, "third content active" ); + equal( ac.accordion( "option", "active" ), 2 ); + state( ac, 0, 0, 1 ); }); -test("{ navigation: true, navigationFilter: content }", function() { - $("#navigation").accordion({ +test( "{ navigation: true, navigationFilter: content }", function() { + var ac = $("#navigation").accordion({ navigation: true, navigationFilter: function() { return /\?p=1\.1\.3\.2$/.test(this.href); } }); - equals( $("#navigation .ui-accordion-content:eq(2)").size(), 1, "third content active" ); + equal( ac.accordion( "option", "active" ), 2 ); + state( ac, 0, 0, 1 ); }); })(jQuery); diff --git a/tests/unit/accordion/accordion_options.js b/tests/unit/accordion/accordion_options.js index 0e02f0372..1a7b9550d 100644 --- a/tests/unit/accordion/accordion_options.js +++ b/tests/unit/accordion/accordion_options.js @@ -137,12 +137,48 @@ test( "{ heightStyle: 'content' }", function() { test( "{ heightStyle: 'fill' }", function() { $( "#navigationWrapper" ).height( 500 ); var ac = $( "#navigation" ).accordion({ heightStyle: "fill" }); - equalHeights( ac, 446, 458); - ac.accordion( "destroy" ); + equalHeights( ac, 446, 458 ); +}); - $( "
" ).height( 100 ).appendTo( "#navigationWrapper" ); - ac.accordion({ heightStyle: "fill" }); - equalHeights( ac, 346, 358 ); +test( "{ heightStyle: 'fill' } with sibling", function() { + $( "#navigationWrapper" ).height( 500 ); + $( "

Lorem Ipsum

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

Lorem Ipsum

" ) + .css({ + height: 50, + marginTop: 20, + marginBottom: 30 + }) + .prependTo( "#navigationWrapper" ); + $( "

Lorem Ipsum

" ) + .css({ + height: 50, + marginTop: 20, + marginBottom: 30, + position: "absolute" + }) + .prependTo( "#navigationWrapper" ); + $( "

Lorem Ipsum

" ) + .css({ + height: 25, + marginTop: 10, + marginBottom: 15 + }) + .prependTo( "#navigationWrapper" ); + var ac = $( "#navigation" ).accordion({ heightStyle: "fill" }); + equalHeights( ac, 296, 308 ); }); test( "{ icons: false }", function() { -- cgit v1.2.3 From 2e214f984db8140d77c73fa4a87161e281f92551 Mon Sep 17 00:00:00 2001 From: Scott González Date: Mon, 24 Jan 2011 21:00:39 -0500 Subject: Accordion test: Fixed an icon test. --- tests/unit/accordion/accordion_options.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests/unit') diff --git a/tests/unit/accordion/accordion_options.js b/tests/unit/accordion/accordion_options.js index 1a7b9550d..8fcfdb172 100644 --- a/tests/unit/accordion/accordion_options.js +++ b/tests/unit/accordion/accordion_options.js @@ -193,7 +193,7 @@ test( "{ icons: false }", function() { icons: false }); icons( false ); - list.accordion( "option", "icons", $.ui.accordion.prototype.options.icons ); + list.accordion( "option", "icons", { header: "foo", activeHeader: "bar" } ); icons( true ); list.accordion( "option", "icons", false ); icons( false ); -- cgit v1.2.3 From 8034cc38038ff1246cd98caecd517f9685d50f8b Mon Sep 17 00:00:00 2001 From: Scott González Date: Mon, 24 Jan 2011 21:22:40 -0500 Subject: Widget tests: Cleanup. --- tests/unit/widget/widget.html | 24 ++++++++++++------------ tests/unit/widget/widget_core.js | 29 +++++++++++++---------------- tests/unit/widget/widget_tickets.js | 5 +---- 3 files changed, 26 insertions(+), 32 deletions(-) (limited to 'tests/unit') 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 @@ - + jQuery UI Widget Test Suite - - - + + + - - - - + + + + - - - - + + + + diff --git a/tests/unit/widget/widget_core.js b/tests/unit/widget/widget_core.js index 269b897c5..26059b96b 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", { @@ -104,7 +101,7 @@ test( "jQuery usage", function() { }); shouldCreate = true; - var elem = $( "
" ) + var elem = $( "
" ) .bind( "testwidgetcreate", function() { ok( shouldCreate, "create event triggered on instantiation" ); }) @@ -150,7 +147,7 @@ test( "direct usage", function() { } }); - var elem = $( "
" )[ 0 ]; + var elem = $( "
" )[ 0 ]; shouldCreate = true; var instance = new $.ui.testWidget( {}, elem ); @@ -202,7 +199,7 @@ test("merge multiple option arguments", function() { }); } }); - $( "
" ).testWidget({ + $( "
" ).testWidget({ option1: "valuex", option2: "valuex", option3: "value3", @@ -249,7 +246,7 @@ test( "_getCreateOptions()", function() { }); test( "re-init", function() { - var div = $( "
" ), + var div = $( "
" ), actions = []; $.widget( "ui.testWidget", { @@ -335,7 +332,7 @@ test( ".option() - getter", function() { _create: function() {} }); - var div = $( "
" ).testWidget({ + var div = $( "
" ).testWidget({ foo: "bar", baz: 5, qux: [ "quux", "quuux" ] @@ -366,7 +363,7 @@ test( ".option() - delegate to ._setOptions()", function() { calls.push( options ); } }); - var div = $( "
" ).testWidget(); + var div = $( "
" ).testWidget(); calls = []; div.testWidget( "option", "foo", "bar" ); @@ -392,7 +389,7 @@ test( ".option() - delegate to ._setOption()", function() { }); } }); - var div = $( "
" ).testWidget(); + var div = $( "
" ).testWidget(); calls = []; div.testWidget( "option", "foo", "bar" ); @@ -419,7 +416,7 @@ test( ".enable()", function() { same( val, false, "disabled set to false" ); } }); - $( "
" ).testWidget().testWidget( "enable" ); + $( "
" ).testWidget().testWidget( "enable" ); }); test( ".disable()", function() { @@ -431,26 +428,26 @@ test( ".disable()", function() { same( val, true, "disabled set to true" ); } }); - $( "
" ).testWidget().testWidget( "disable" ); + $( "
" ).testWidget().testWidget( "disable" ); }); test( ".widget() - base", function() { $.widget( "ui.testWidget", { _create: function() {} }); - var div = $( "
" ).testWidget(); + var div = $( "
" ).testWidget(); same( div[0], div.testWidget( "widget" )[0]); }); test( ".widget() - overriden", function() { - var wrapper = $( "
" ); + var wrapper = $( "
" ); $.widget( "ui.testWidget", { _create: function() {}, widget: function() { return wrapper; } }); - same( wrapper[0], $( "
" ).testWidget().testWidget( "widget" )[0] ); + same( wrapper[0], $( "
" ).testWidget().testWidget( "widget" )[0] ); }); test( "._trigger() - no event, no ui", function() { @@ -670,4 +667,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 ) ); -- cgit v1.2.3 From 4a384c63ffa4c4b588b92b2a983a6710bc518284 Mon Sep 17 00:00:00 2001 From: Scott González Date: Mon, 24 Jan 2011 21:31:12 -0500 Subject: Widget tests: Remove workaround for old QUnit bug. --- tests/unit/widget/widget_core.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/widget/widget_core.js b/tests/unit/widget/widget_core.js index 26059b96b..be8a59fb4 100644 --- a/tests/unit/widget/widget_core.js +++ b/tests/unit/widget/widget_core.js @@ -183,7 +183,7 @@ test( "error handling", function() { $.error = error; }); -test("merge multiple option arguments", function() { +test( "merge multiple option arguments", function() { expect( 1 ); $.widget( "ui.testWidget", { _create: function() { @@ -630,8 +630,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() { @@ -642,8 +640,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() { -- cgit v1.2.3 From 63c72aba0d898289b4cb536cd34fee80c15087d1 Mon Sep 17 00:00:00 2001 From: Scott González Date: Mon, 24 Jan 2011 22:37:57 -0500 Subject: Tests: Fixed erroneous refernece to accordion. --- tests/unit/testsuite.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/testsuite.js b/tests/unit/testsuite.js index 23819d0e4..0033182dc 100644 --- a/tests/unit/testsuite.js +++ b/tests/unit/testsuite.js @@ -48,10 +48,10 @@ function testBasicUsage( widget ) { $( defaultElement ).appendTo( "body" )[ widget ]().remove(); ok( true, "initialized on element" ); - $( defaultElement ).accordion().remove(); + $( defaultElement )[ widget ]().remove(); ok( true, "initialized on disconnected DOMElement - never connected" ); - $( defaultElement ).appendTo( "body" ).remove().accordion().remove(); + $( defaultElement ).appendTo( "body" ).remove()[ widget ]().remove(); ok( true, "initialized on disconnected DOMElement - removed" ); }); } -- cgit v1.2.3 From 06d61f5f235f4869bc251ebd1e1e768c56297636 Mon Sep 17 00:00:00 2001 From: Scott González Date: Mon, 24 Jan 2011 22:40:03 -0500 Subject: Accordion: More tests. --- tests/unit/accordion/accordion_core.js | 12 ++++ tests/unit/accordion/accordion_events.js | 107 +++++++++++++++++++++++-------- 2 files changed, 94 insertions(+), 25 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/accordion/accordion_core.js b/tests/unit/accordion/accordion_core.js index 601d2ed44..24dc0146b 100644 --- a/tests/unit/accordion/accordion_core.js +++ b/tests/unit/accordion/accordion_core.js @@ -2,6 +2,18 @@ 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( "handle click on header-descendant", function() { var ac = $( "#navigation" ).accordion(); $( "#navigation h2:eq(1) a" ).click(); diff --git a/tests/unit/accordion/accordion_events.js b/tests/unit/accordion/accordion_events.js index e0dbe82eb..463a277d8 100644 --- a/tests/unit/accordion/accordion_events.js +++ b/tests/unit/accordion/accordion_events.js @@ -2,31 +2,88 @@ module( "accordion: events", accordionSetupTeardown() ); -// 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 ); +test( "changestart", 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( "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 ] ); + }); + ac.accordion( "option", "active", 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 ] ); + }); + headers.eq( 1 ).click(); + + 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 ); + }); + ac.accordion( "option", "active", false ); +}); + +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 ) ); -- cgit v1.2.3 From 088ef05142168de75d2afcbe447a5b44cb2d3673 Mon Sep 17 00:00:00 2001 From: Scott González Date: Tue, 25 Jan 2011 00:05:55 -0500 Subject: Accordion: Renamed changestart and change events to beforeActivate and activate, respectively. Fixes #6840 - Accordion: Rename changestart event to beforeActivate. Fixes #6842 - Accordion: Rename change event to activate. --- tests/unit/accordion/accordion_deprecated.js | 90 ++++++++++++++++++++++++++++ tests/unit/accordion/accordion_events.js | 16 ++--- tests/unit/testsuite.js | 12 ++-- ui/jquery.ui.accordion.js | 22 ++++++- 4 files changed, 124 insertions(+), 16 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/accordion/accordion_deprecated.js b/tests/unit/accordion/accordion_deprecated.js index a0ca3f634..6f1c30562 100644 --- a/tests/unit/accordion/accordion_deprecated.js +++ b/tests/unit/accordion/accordion_deprecated.js @@ -221,4 +221,94 @@ test( "{ navigation: true, navigationFilter: content }", function() { state( ac, 0, 0, 1 ); }); + + + + +module( "accordion (deprecated) - changestart/change events", accordionSetupTeardown() ); + +test( "changestart", 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( "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 ] ); + }); + ac.accordion( "option", "active", 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 ] ); + }); + headers.eq( 1 ).click(); + + 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 ); + }); + ac.accordion( "option", "active", false ); +}); + +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 463a277d8..fd7391387 100644 --- a/tests/unit/accordion/accordion_events.js +++ b/tests/unit/accordion/accordion_events.js @@ -2,7 +2,7 @@ module( "accordion: events", accordionSetupTeardown() ); -test( "changestart", function() { +test( "beforeActivate", function() { expect( 20 ); var ac = $( "#list1" ).accordion({ active: false, @@ -11,7 +11,7 @@ test( "changestart", function() { var headers = ac.find( ".ui-accordion-header" ); var content = ac.find( ".ui-accordion-content" ); - ac.one( "accordionchangestart", function( event, ui ) { + ac.one( "accordionbeforeactivate", function( event, ui ) { equals( ui.oldHeader.size(), 0 ); equals( ui.oldContent.size(), 0 ); equals( ui.newHeader.size(), 1 ); @@ -21,7 +21,7 @@ test( "changestart", function() { }); ac.accordion( "option", "active", 0 ); - ac.one( "accordionchangestart", function( event, ui ) { + ac.one( "accordionbeforeactivate", function( event, ui ) { equals( ui.oldHeader.size(), 1 ); strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] ); equals( ui.oldContent.size(), 1 ); @@ -33,7 +33,7 @@ test( "changestart", function() { }); headers.eq( 1 ).click(); - ac.one( "accordionchangestart", function( event, ui ) { + ac.one( "accordionbeforeactivate", function( event, ui ) { equals( ui.oldHeader.size(), 1 ); strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] ); equals( ui.oldContent.size(), 1 ); @@ -44,7 +44,7 @@ test( "changestart", function() { ac.accordion( "option", "active", false ); }); -test( "change", function() { +test( "activate", function() { expect( 20 ); var ac = $( "#list1" ).accordion({ active: false, @@ -53,7 +53,7 @@ test( "change", function() { var headers = ac.find( ".ui-accordion-header" ); var content = ac.find( ".ui-accordion-content" ); - ac.one( "accordionchange", function( event, ui ) { + ac.one( "accordionactivate", function( event, ui ) { equals( ui.oldHeader.size(), 0 ); equals( ui.oldContent.size(), 0 ); equals( ui.newHeader.size(), 1 ); @@ -63,7 +63,7 @@ test( "change", function() { }); ac.accordion( "option", "active", 0 ); - ac.one( "accordionchange", function( event, ui ) { + ac.one( "accordionactivate", function( event, ui ) { equals( ui.oldHeader.size(), 1 ); strictEqual( ui.oldHeader[ 0 ], headers[ 0 ] ); equals( ui.oldContent.size(), 1 ); @@ -75,7 +75,7 @@ test( "change", function() { }); headers.eq( 1 ).click(); - ac.one( "accordionchange", function( event, ui ) { + ac.one( "accordionactivate", function( event, ui ) { equals( ui.oldHeader.size(), 1 ); strictEqual( ui.oldHeader[ 0 ], headers[ 1 ] ); equals( ui.oldContent.size(), 1 ); diff --git a/tests/unit/testsuite.js b/tests/unit/testsuite.js index 0033182dc..9724a946f 100644 --- a/tests/unit/testsuite.js +++ b/tests/unit/testsuite.js @@ -34,12 +34,14 @@ var privateMethods = [ ]; function testWidgetOverrides( widget ) { - test( "$.widget overrides", function() { - $.each( privateMethods, function( i, method ) { - strictEqual( $.ui[ widget ].prototype[ method ], - $.Widget.prototype[ method ], "should not override " + method ); + 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 ) { diff --git a/ui/jquery.ui.accordion.js b/ui/jquery.ui.accordion.js index d855da5f3..cd6a2ce93 100644 --- a/ui/jquery.ui.accordion.js +++ b/ui/jquery.ui.accordion.js @@ -381,8 +381,7 @@ $.widget( "ui.accordion", { return self._completed.apply( self, arguments ); }; - // trigger changestart event - self._trigger( "changestart", null, self.data ); + self._trigger( "beforeActivate", null, self.data ); // count elements to animate self.running = toHide.size() === 0 ? toShow.size() : toHide.size(); @@ -487,7 +486,7 @@ $.widget( "ui.accordion", { this.toHide.parent()[0].className = this.toHide.parent()[0].className; } - this._trigger( "change", null, this.data ); + this._trigger( "activate", null, this.data ); } }); @@ -711,6 +710,23 @@ if ( $.uiBackCompat !== false ) { // resize method jQuery.ui.accordion.prototype.resize = jQuery.ui.accordion.prototype.refresh; + + (function( $, prototype ) { + var _trigger = prototype._trigger; + prototype._trigger = function( type, event, data ) { + var ret = _trigger.apply( this, arguments ); + if ( !ret ) { + return false; + } + + if ( type === "beforeActivate" ) { + ret = _trigger.call( this, "changestart", event, data ); + } else if ( type === "activate" ) { + ret = _trigger.call( this, "change", event, data ); + } + return ret; + } + }( jQuery, jQuery.ui.accordion.prototype ) ); } })( jQuery ); -- cgit v1.2.3 From 7a6dd71f8cf04d19c938f0678c0f2a2586ed65c5 Mon Sep 17 00:00:00 2001 From: Scott González Date: Tue, 25 Jan 2011 00:52:42 -0500 Subject: Accordion: Allow canceling the beforeActivate event. Fixes #6896 - Accordion: Allow canceling the beforeActivate event. --- tests/unit/accordion/accordion_deprecated.js | 8 +++- tests/unit/accordion/accordion_events.js | 34 +++++++++++++++- ui/jquery.ui.accordion.js | 59 ++++++++++++++++++---------- 3 files changed, 79 insertions(+), 22 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/accordion/accordion_deprecated.js b/tests/unit/accordion/accordion_deprecated.js index 6f1c30562..07974e75e 100644 --- a/tests/unit/accordion/accordion_deprecated.js +++ b/tests/unit/accordion/accordion_deprecated.js @@ -228,7 +228,7 @@ test( "{ navigation: true, navigationFilter: content }", function() { module( "accordion (deprecated) - changestart/change events", accordionSetupTeardown() ); test( "changestart", function() { - expect( 20 ); + expect( 26 ); var ac = $( "#list1" ).accordion({ active: false, collapsible: true @@ -243,8 +243,10 @@ test( "changestart", function() { 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 ); @@ -255,8 +257,10 @@ test( "changestart", function() { 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 ); @@ -265,8 +269,10 @@ test( "changestart", function() { 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() { diff --git a/tests/unit/accordion/accordion_events.js b/tests/unit/accordion/accordion_events.js index fd7391387..0b9f14706 100644 --- a/tests/unit/accordion/accordion_events.js +++ b/tests/unit/accordion/accordion_events.js @@ -3,7 +3,7 @@ module( "accordion: events", accordionSetupTeardown() ); test( "beforeActivate", function() { - expect( 20 ); + expect( 42 ); var ac = $( "#list1" ).accordion({ active: false, collapsible: true @@ -18,8 +18,10 @@ test( "beforeActivate", function() { 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 ); @@ -30,8 +32,10 @@ test( "beforeActivate", function() { 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 ); @@ -40,8 +44,36 @@ test( "beforeActivate", function() { 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() { diff --git a/ui/jquery.ui.accordion.js b/ui/jquery.ui.accordion.js index cd6a2ce93..85a47ddfb 100644 --- a/ui/jquery.ui.accordion.js +++ b/ui/jquery.ui.accordion.js @@ -284,6 +284,17 @@ $.widget( "ui.accordion", { return; } + // allow the activation to be canceled + var eventData = { + oldHeader: this.active, + oldContent: this.active.next(), + newHeader: $(), + newContent: $() + }; + if ( this._trigger( "beforeActivate", null, eventData ) === false ) { + return; + } + this.active .removeClass( "ui-state-active ui-corner-top" ) .addClass( "ui-state-default ui-corner-all" ) @@ -294,24 +305,34 @@ $.widget( "ui.accordion", { var toHide = this.active.next(), data = { options: this.options, - newHeader: $( [] ), + newHeader: $(), oldHeader: this.active, - newContent: $( [] ), + newContent: $(), oldContent: toHide }, - toShow = ( this.active = $( [] ) ); + toShow = ( this.active = $() ); this._toggle( toShow, toHide, data ); }, // TODO: add tests/docs for negative values in 2.0 (#6854) _findActive: function( selector ) { - return typeof selector === "number" ? this.headers.eq( selector ) : $( [] ); + return typeof selector === "number" ? this.headers.eq( selector ) : $(); }, _eventHandler: function( event ) { var options = this.options, + active = this.active, clicked = $( event.currentTarget ), - clickedIsActive = clicked[0] === this.active[0]; + clickedIsActive = clicked[ 0 ] === active[ 0 ], + collapsing = clickedIsActive && options.collapsible, + toShow = clicked.next(), + toHide = active.next(), + eventData = { + oldHeader: active, + oldContent: toHide, + newHeader: collapsing ? $() : clicked, + newContent: collapsing ? $() : toShow + }; event.preventDefault(); @@ -324,26 +345,26 @@ $.widget( "ui.accordion", { return; } - options.active = options.collapsible && clickedIsActive ? - false : - this.headers.index( clicked ); + // allow the activation to be canceled + if ( this._trigger( "beforeActivate", null, eventData ) === false ) { + return; + } + + options.active = collapsing ? false : this.headers.index( clicked ); // find elements to show and hide - var active = this.active, - toShow = clicked.next(), - toHide = this.active.next(), - data = { + var data = { options: options, - newHeader: clickedIsActive && options.collapsible ? $([]) : clicked, - oldHeader: this.active, - newContent: clickedIsActive && options.collapsible ? $([]) : toShow, + newHeader: collapsing ? $() : clicked, + oldHeader: active, + newContent: collapsing ? $() : toShow, oldContent: toHide }, - down = this.headers.index( this.active[0] ) > this.headers.index( clicked[0] ); + down = this.headers.index( active[0] ) > this.headers.index( clicked[0] ); // when the call to ._toggle() comes after the class changes // it causes a very odd bug in IE 8 (see #6720) - this.active = clickedIsActive ? $([]) : clicked; + this.active = clickedIsActive ? $() : clicked; this._toggle( toShow, toHide, data, clickedIsActive, down ); // switch classes @@ -381,8 +402,6 @@ $.widget( "ui.accordion", { return self._completed.apply( self, arguments ); }; - self._trigger( "beforeActivate", null, self.data ); - // count elements to animate self.running = toHide.size() === 0 ? toShow.size() : toHide.size(); @@ -391,7 +410,7 @@ $.widget( "ui.accordion", { if ( options.collapsible && clickedIsActive ) { animOptions = { - toShow: $( [] ), + toShow: $(), toHide: toHide, complete: complete, down: down, -- cgit v1.2.3 From effbb2c0ec2e60bea6ec5e5822ee52f8ea9e18bc Mon Sep 17 00:00:00 2001 From: jzaefferer Date: Mon, 31 Jan 2011 16:37:50 +0100 Subject: Update wigdet test for previous change. No stored intance via data for element == instance. --- tests/unit/widget/widget_core.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'tests/unit') diff --git a/tests/unit/widget/widget_core.js b/tests/unit/widget/widget_core.js index be8a59fb4..94cd664eb 100644 --- a/tests/unit/widget/widget_core.js +++ b/tests/unit/widget/widget_core.js @@ -24,7 +24,7 @@ test( "widget creation", function() { }); test( "element normalization", function() { - expect( 12 ); + expect( 11 ); var elem; $.widget( "ui.testWidget", {} ); @@ -67,7 +67,6 @@ test( "element normalization", function() { $.ui.testWidget.prototype._create = function() { // using strictEqual throws an error (Maximum call stack size exceeded) ok( this.element[ 0 ] === this, "instance as element" ); - ok( this.element.data( "testWidget" ) === this, "instance stored in .data()" ); }; $.ui.testWidget(); }); -- cgit v1.2.3