aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/accordion
diff options
context:
space:
mode:
authorRichard Worth <rdworth@gmail.com>2009-01-07 03:31:15 +0000
committerRichard Worth <rdworth@gmail.com>2009-01-07 03:31:15 +0000
commitb792bd46ec9b1b55bf2289faedd4ab3614c9319a (patch)
tree4b1736c703d392ec07fd4a5ae3390151470ae933 /tests/unit/accordion
parent4707debd645e63ea22d7a076e97a34eb3d310ebc (diff)
downloadjquery-ui-b792bd46ec9b1b55bf2289faedd4ab3614c9319a.tar.gz
jquery-ui-b792bd46ec9b1b55bf2289faedd4ab3614c9319a.zip
restructured unit tests folder
Diffstat (limited to 'tests/unit/accordion')
-rw-r--r--tests/unit/accordion/accordion.html96
-rw-r--r--tests/unit/accordion/accordion.js150
2 files changed, 246 insertions, 0 deletions
diff --git a/tests/unit/accordion/accordion.html b/tests/unit/accordion/accordion.html
new file mode 100644
index 000000000..51553d330
--- /dev/null
+++ b/tests/unit/accordion/accordion.html
@@ -0,0 +1,96 @@
+<!doctype html>
+<html lang="en">
+<head>
+ <title>jQuery UI Accordion Test Suite</title>
+
+ <script type="text/javascript" src="../../../jquery-1.3pre.js"></script>
+ <script type="text/javascript" src="../../../ui/ui.core.js"></script>
+ <script type="text/javascript" src="../../../ui/ui.accordion.js"></script>
+
+ <link type="text/css" href="../testsuite.css" rel="stylesheet" />
+ <script type="text/javascript" src="../testsuite.js"></script>
+ <script type="text/javascript" src="../../../external/qunit/testrunner.js"></script>
+ <script type="text/javascript" src="../../../external/simulate/jquery.simulate.js"></script>
+
+ <script type="text/javascript" src="accordion.js"></script>
+</head>
+<body>
+
+<div id="main">
+
+ <div id="list1">
+ <div>
+ <a>There is one obvious advantage:</a>
+ <div>
+ <p>
+ You've seen it coming!
+ <br/>
+ Buy now and get nothing for free!
+ <br/>
+ Well, at least no free beer. Perhaps a bear, if you can afford it.
+ </p>
+ </div>
+ </div>
+ <div>
+ <a>Now that you've got...</a>
+ <div>
+ <p>
+ your bear, you have to admit it!
+ <br/>
+ No, we aren't selling bears.
+ </p>
+ <p>
+ We could talk about renting one.
+ </p>
+ </div>
+ </div>
+ <div>
+ <a>Rent one bear, ...</a>
+ <div>
+ <p>
+ get two for three beer.
+ </p>
+ <p>
+ And now, for something completely different.
+ </p>
+ </div>
+ </div>
+ </div>
+
+ <ul id="navigation">
+ <li>
+ <a href="?p=1.1.1">Guitar</a>
+ <ul>
+ <li><a href="?p=1.1.1.1">Electric</a></li>
+ <li><a href="?p=1.1.1.2">Acoustic</a></li>
+ <li><a href="?p=1.1.1.3">Amps</a></li>
+ <li><a href="?p=1.1.1.4">Effects</a></li>
+ <li><a href="?p=1.1.1.5">Accessories</a></li>
+ </ul>
+ </li>
+ <li>
+ <a href="?p=1.1.2"><span>Bass</span></a>
+ <ul>
+ <li><a href="?p=1.1.2.1">Electric</a></li>
+ <li><a href="?p=1.1.2.2">Acoustic</a></li>
+ <li><a href="?p=1.1.2.3">Amps</a></li>
+ <li><a href="?p=1.1.2.4">Effects</a></li>
+ <li><a href="?p=1.1.2.5">Accessories</a></li>
+ <li><a href="?p=1.1.2.5">Accessories</a></li>
+ <li><a href="?p=1.1.2.5">Accessories</a></li>
+ </ul>
+ </li>
+ <li>
+ <a href="?p=1.1.3">Drums</a>
+ <ul>
+ <li><a href="?p=1.1.3.2">Acoustic Drums</a></li>
+ <li><a href="?p=1.1.3.3">Electronic Drums</a></li>
+ <li><a href="?p=1.1.3.6">Accessories</a></li>
+ </ul>
+ </li>
+ </ul>
+
+</div>
+
+</body>
+</html>
diff --git a/tests/unit/accordion/accordion.js b/tests/unit/accordion/accordion.js
new file mode 100644
index 000000000..d9f8c4b64
--- /dev/null
+++ b/tests/unit/accordion/accordion.js
@@ -0,0 +1,150 @@
+/*
+ * accordion unit tests
+ */
+(function($) {
+
+module("accordion");
+
+jQuery.ui.accordion.defaults.animated = false;
+
+function state(accordion) {
+ var args = $.makeArray(arguments).slice(1);
+ $.each(args, function(i, n) {
+ equals(accordion.find(".ui-accordion-content").parent().eq(i).is(":visible"), n);
+ });
+}
+
+$.fn.triggerEvent = function(type, target) {
+ return this.triggerHandler(type, [jQuery.event.fix({ type: type, target: target })]);
+}
+
+test("basics", function() {
+ state($('#list1').accordion(), 1, 0, 0);
+});
+
+test("autoheight", function() {
+ $('#navigation').accordion({ autoHeight: false });
+ equals( 90, $('#navigation div:first').height() );
+ equals( 126, $('#navigation div:eq(1)').height() );
+ equals( 54, $('#navigation div:last').height() );
+ $('#navigation').accordion("destroy").accordion({ autoHeight: true });
+ equals( 126, $('#navigation div:first').height() );
+ equals( 126, $('#navigation div:eq(1)').height() );
+ equals( 126, $('#navigation div:last').height() );
+});
+
+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);
+ ac.accordion("activate", -1);
+ state(ac, 0, 0, 1);
+});
+
+test("activate, boolean and numeric, alwaysOpen:false", function() {
+ var ac = $('#list1').accordion({alwaysOpen: false}).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, alwaysOpen:true", function() {
+ var ac = $('#list1').accordion().accordion("activate", 2);
+ state(ac, 0, 0, 1);
+ ac.accordion("activate", -1);
+ state(ac, 0, 0, 1);
+});
+
+test("activate, string expression", function() {
+ var ac = $('#list1').accordion({ active: "a: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 a:last") });
+ state(ac, 0, 0, 1);
+ ac.accordion("activate", $("#list1 a:first"));
+ state(ac, 1, 0, 0);
+ ac.accordion("activate", $("#list1 a")[1]);
+ state(ac, 0, 1, 0);
+});
+
+function state2(accordion) {
+ var args = $.makeArray(arguments).slice(1);
+ $.each(args, function(i, n) {
+ equals(accordion.find("div").eq(i).is(":visible"), n);
+ });
+}
+
+test("handle click on header-descendant", function() {
+ var ac = $('#navigation').accordion({ autoHeight: false })
+ ac.triggerEvent("click", $('#navigation span:contains(Bass)')[0]);
+ state2(ac, 0, 1, 0);
+});
+
+test("active:false", function() {
+ $("#list1").accordion({
+ active: false,
+ alwaysOpen: false
+ });
+ equals( $("#list1 a.selected").size(), 0, "no headers selected" );
+});
+
+test("accordionchange event, open closed and close again", function() {
+ expect(8);
+ $("#list1").accordion({
+ active: false,
+ alwaysOpen: false
+ })
+ .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("activate", 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("activate", 0);
+});
+
+test("accessibility", function () {
+ expect(9);
+ var ac = $('#list1').accordion().accordion("activate", 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("activate", 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);