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) 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>
<script type="text/javascript" src="accordion_core.js"></script> <script type="text/javascript" src="accordion_core.js"></script>
<script type="text/javascript" src="accordion_defaults.js"></script> <script type="text/javascript" src="accordion_defaults.js"></script>
@ -39,7 +48,7 @@
<style> <style>
#main { font-size: 10pt; font-family: 'trebuchet ms', verdana, arial; } #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> </style>
</head> </head>
<body> <body>

View File

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

View File

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