From 4f4843a9fb69c95f5fba0a4b2bbf526c035a8430 Mon Sep 17 00:00:00 2001 From: jzaefferer Date: Tue, 13 Apr 2010 10:13:13 +0200 Subject: [PATCH] Accordion unit tests: Remove role attribute to pass Opera 9 and adjust height tests to tolerate different results, as long as they are consistent --- tests/unit/accordion/accordion.html | 11 +++++++- tests/unit/accordion/accordion_methods.js | 17 +++++-------- tests/unit/accordion/accordion_options.js | 31 ++++++++--------------- 3 files changed, 27 insertions(+), 32 deletions(-) diff --git a/tests/unit/accordion/accordion.html b/tests/unit/accordion/accordion.html index 7c1165fc8..c53db8c75 100644 --- a/tests/unit/accordion/accordion.html +++ b/tests/unit/accordion/accordion.html @@ -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]); + } @@ -39,7 +48,7 @@ diff --git a/tests/unit/accordion/accordion_methods.js b/tests/unit/accordion/accordion_methods.js index 85f037a55..73faff27c 100644 --- a/tests/unit/accordion/accordion_methods.js +++ b/tests/unit/accordion/accordion_methods.js @@ -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); diff --git a/tests/unit/accordion/accordion_options.js b/tests/unit/accordion/accordion_options.js index e46795993..31aabc0d1 100644 --- a/tests/unit/accordion/accordion_options.js +++ b/tests/unit/accordion/accordion_options.js @@ -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() { -- 2.39.5