Skip to content
Permalink
Browse files

Accordion tests: Cleanup.

  • Loading branch information
scottgonzalez committed Jan 25, 2011
1 parent ecc0ef5 commit 5ed1046a4ac271a1f20cc1f19aa50bec15cd9704
@@ -17,30 +17,37 @@
<script src="../testsuite.js"></script>

<script>
$.ui.accordion.prototype.options.animated = false;

function state(accordion) {
var args = $.makeArray(arguments).slice(1);
var result = [];
$.each(args, function(i, n) {
result.push( accordion.find(".ui-accordion-content").eq(i).filter(function() {
return $(this).css("display") != "none"
}).length ? 1 : 0 );
});
same(args, result)
function state( accordion ) {
var expected = $.makeArray( arguments ).slice( 1 );
var actual = accordion.find( ".ui-accordion-content" ).map(function() {
return $( this ).css( "display" ) === "none" ? 0 : 1;
}).get();
same( actual, expected );
}
function equalHeights(accordion, min, max) {
function equalHeights( accordion, min, max ) {
var sizes = [];
accordion.find(".ui-accordion-content").each(function() {
sizes.push($(this).outerHeight());
accordion.find( ".ui-accordion-content" ).each(function() {
sizes.push( $( this ).outerHeight() );
});
ok( sizes[0] >= min && sizes[0] <= max, "must be within " + min + " and " + max + ", was " + sizes[0] );
same(sizes[0], sizes[1]);
same(sizes[0], sizes[2]);
ok( sizes[ 0 ] >= min && sizes[ 0 ] <= max,
"must be within " + min + " and " + max + ", was " + sizes[ 0 ] );
same( sizes[ 0 ], sizes[ 1 ] );
same( sizes[ 0 ], sizes[ 2 ] );
}
function accordionSetupTeardown() {
var animated = $.ui.accordion.prototype.options.animated;
return {
setup: function() {
$.ui.accordion.prototype.options.animated = false;
},
teardown: function() {
$.ui.accordion.prototype.options.animated = animated;
}
};
}
</script>
<script src="accordion_core.js"></script>
<script src="accordion_defaults_deprecated.js"></script>
<script src="accordion_core.js"></script>
<script src="accordion_events.js"></script>
<script src="accordion_methods.js"></script>
<script src="accordion_options.js"></script>
@@ -20,30 +20,37 @@
<script src="../testsuite.js"></script>

<script>
$.ui.accordion.prototype.options.animated = false;

function state(accordion) {
var args = $.makeArray(arguments).slice(1);
var result = [];
$.each(args, function(i, n) {
result.push( accordion.find(".ui-accordion-content").eq(i).filter(function() {
return $(this).css("display") != "none"
}).length ? 1 : 0 );
});
same(args, result)
function state( accordion ) {
var expected = $.makeArray( arguments ).slice( 1 );
var actual = accordion.find( ".ui-accordion-content" ).map(function() {
return $( this ).css( "display" ) === "none" ? 0 : 1;
}).get();
same( actual, expected );
}
function equalHeights(accordion, min, max) {
function equalHeights( accordion, min, max ) {
var sizes = [];
accordion.find(".ui-accordion-content").each(function() {
sizes.push($(this).outerHeight());
accordion.find( ".ui-accordion-content" ).each(function() {
sizes.push( $( this ).outerHeight() );
});
ok( sizes[0] >= min && sizes[0] <= max, "must be within " + min + " and " + max + ", was " + sizes[0] );
same(sizes[0], sizes[1]);
same(sizes[0], sizes[2]);
ok( sizes[ 0 ] >= min && sizes[ 0 ] <= max,
"must be within " + min + " and " + max + ", was " + sizes[ 0 ] );
same( sizes[ 0 ], sizes[ 1 ] );
same( sizes[ 0 ], sizes[ 2 ] );
}
function accordionSetupTeardown() {
var animated = $.ui.accordion.prototype.options.animated;
return {
setup: function() {
$.ui.accordion.prototype.options.animated = false;
},
teardown: function() {
$.ui.accordion.prototype.options.animated = animated;
}
};
}
</script>
<script src="accordion_core.js"></script>
<script src="accordion_defaults.js"></script>
<script src="accordion_core.js"></script>
<script src="accordion_events.js"></script>
<script src="accordion_methods.js"></script>
<script src="accordion_options.js"></script>
@@ -1,6 +1,6 @@
(function( $ ) {

module( "accordion: core" );
module( "accordion: core", accordionSetupTeardown() );

test( "handle click on header-descendant", function() {
var ac = $( "#navigation" ).accordion();
@@ -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 } );
});
@@ -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() {}
}
});
@@ -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);
@@ -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)
@@ -1,71 +1,48 @@
/*
* accordion_methods.js
*/
(function($) {

module("accordion: methods");

test("init", function() {
$("<div></div>").appendTo('body').accordion().remove();
ok(true, '.accordion() called on element');

$([]).accordion().remove();
ok(true, '.accordion() called on empty collection');

$('<div></div>').accordion().remove();
ok(true, '.accordion() called on disconnected DOMElement - never connected');

$('<div></div>').appendTo('body').remove().accordion().remove();
ok(true, '.accordion() called on disconnected DOMElement - removed');

var el = $('<div></div>').accordion();
var foo = el.accordion("option", "foo");
el.remove();
ok(true, 'arbitrary option getter after init');

$('<div></div>').accordion().accordion("option", "foo", "bar").remove();
ok(true, 'arbitrary option setter after init');
});

test("destroy", function() {
var beforeHtml = $("#list1").find("div").css("font-style", "normal").end().parent().html();
var afterHtml = $("#list1").accordion().accordion("destroy").parent().html();
// Opera 9 outputs role="" instead of removing the attribute like everyone else
if ($.browser.opera) {
afterHtml = afterHtml.replace(/ role=""/g, "");
}
(function( $ ) {

module( "accordion: methods", accordionSetupTeardown() );

test( "destroy", function() {
var beforeHtml = $( "#list1" )
.find( "div" )
.css( "font-style", "normal" )
.end()
.parent()
.html();
var afterHtml = $( "#list1" )
.accordion()
.accordion( "destroy" )
.parent()
.html()
// Opera 9 outputs role="" instead of removing the attribute like everyone else
.replace( / role=""/g, "" );
equal( afterHtml, beforeHtml );
});

test("enable", function() {
var expected = $('#list1').accordion(),
actual = expected.accordion('enable');
equals(actual, expected, 'enable is chainable');
state(expected, 1, 0, 0)
});

test("disable", function() {
var expected = $('#list1').accordion(),
actual = expected.accordion('disable');
equals(actual, expected, 'disable is chainable');

state(expected, 1, 0, 0)
expected.accordion("option", "active", 1);
state(expected, 1, 0, 0)
expected.accordion("enable");
expected.accordion("option", "active", 1);
state(expected, 0, 1, 0)
test( "enable/disable", function() {
var accordion = $('#list1').accordion();
state( accordion, 1, 0, 0 );
accordion.accordion( "disable" );
accordion.accordion( "option", "active", 1 );
state( accordion, 1, 0, 0 );
accordion.accordion( "enable" );
accordion.accordion( "option", "active", 1 );
state( accordion, 0, 1, 0 );
});

test("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 ) );

0 comments on commit 5ed1046

Please sign in to comment.
You can’t perform that action at this time.