Accordion unit tests: Remove role attribute to pass Opera 9 and adjust height tests to tolerate different results, as long as they are consistent

This commit is contained in:
jzaefferer 2010-04-13 10:13:13 +02:00
parent 53d9ac2098
commit 4f4843a9fb
3 changed files with 27 additions and 32 deletions

View File

@ -29,6 +29,15 @@
});
same(args, result)
}
function equalHeights(accordion, min, max) {
var sizes = [];
accordion.find(".ui-accordion-content").each(function() {
sizes.push($(this).outerHeight());
});
ok( sizes[0] >= min && sizes[0] <= max, "must be within " + min + " and " + max + ", was " + sizes[0] );
same(sizes[0], sizes[1]);
same(sizes[0], sizes[2]);
}
</script>
<script type="text/javascript" src="accordion_core.js"></script>
<script type="text/javascript" src="accordion_defaults.js"></script>
@ -39,7 +48,7 @@
<style>
#main { font-size: 10pt; font-family: 'trebuchet ms', verdana, arial; }
#list, #list1 *, #navigation, #navigation * { margin: 0; padding: 0; font-size: 12px; list-style: none; border: 0; outline: 0; }
#list, #list1 *, #navigation, #navigation * { margin: 0; padding: 0; font-size: 12px; }
</style>
</head>
<body>

View File

@ -33,6 +33,10 @@ test("init", function() {
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, "");
}
equal( afterHtml, beforeHtml );
});
@ -117,20 +121,11 @@ test("resize", function() {
var expected = $('#navigation').parent().height(300).end().accordion({
fillSpace: true
});
var sizes = [];
expected.find(".ui-accordion-content").each(function() {
sizes.push($(this).outerHeight());
});
same(sizes, [246, 246, 246]);
equalHeights(expected, 246, 258);
expected.parent().height(500);
expected.accordion("resize");
var sizes2 = [];
expected.find(".ui-accordion-content").each(function() {
sizes2.push($(this).outerHeight());
});
same(sizes2, [446, 446, 446]);
equalHeights(expected, 446, 458);
});
})(jQuery);

View File

@ -66,17 +66,18 @@ test("{ active: Number }", function() {
});
test("{ autoHeight: true }, default", function() {
$('#navigation').accordion({ autoHeight: true });
equals( $('#navigation > li:eq(0) > ul').height(), 126 );
equals( $('#navigation > li:eq(1) > ul').height(), 126 );
equals( $('#navigation > li:eq(2) > ul').height(), 126 );
equalHeights($('#navigation').accordion({ autoHeight: true }), 95, 130);
});
test("{ autoHeight: false }", function() {
$('#navigation').accordion({ autoHeight: false });
equals( $('#navigation > li:eq(0) > ul').height(), 90 );
equals( $('#navigation > li:eq(1) > ul').height(), 126 );
equals( $('#navigation > li:eq(2) > ul').height(), 54 );
var accordion = $('#navigation').accordion({ autoHeight: false });
var sizes = [];
accordion.find(".ui-accordion-content").each(function() {
sizes.push($(this).outerHeight());
});
ok( sizes[0] >= 70 && sizes[0] <= 90 );
ok( sizes[1] >= 98 && sizes[1] <= 126 );
ok( sizes[2] >= 54 && sizes[2] <= 54 );
});
test("{ collapsible: false }, default", function() {
@ -95,20 +96,10 @@ test("{ collapsible: true }", function() {
state(ac, 0, 0, 0);
});
test("{ fillSpace: false }, default", function() {
$("#navigationWrapper").height(500);
$('#navigation').accordion({ fillSpace: false });
equals( $('#navigation > li:eq(0) > ul').height(), 126 );
equals( $('#navigation > li:eq(1) > ul').height(), 126 );
equals( $('#navigation > li:eq(2) > ul').height(), 126 );
});
// fillSpace: false == autoHeight: true, covered above
test("{ fillSpace: true }", function() {
$("#navigationWrapper").height(500);
$('#navigation').accordion({ fillSpace: true });
equals( $('#navigation > li:eq(0) > ul').height(), 446 );
equals( $('#navigation > li:eq(1) > ul').height(), 446 );
equals( $('#navigation > li:eq(2) > ul').height(), 446 );
equalHeights($('#navigation').accordion({ fillSpace: true }), 446, 458);
});
test("{ header: '> li > :first-child,> :not(li):even' }, default", function() {