| [ Index ] |
PHP Cross Reference of Drupal 6 (gatewave) |
[Summary view] [Print] [Text view]
1 /* 2 * accordion unit tests 3 */ 4 (function($) { 5 6 module("accordion"); 7 8 jQuery.ui.accordion.defaults.animated = false; 9 10 function state(accordion) { 11 var args = $.makeArray(arguments).slice(1); 12 $.each(args, function(i, n) { 13 equals(accordion.find("div").eq(i).is(":visible"), n); 14 }); 15 } 16 17 $.fn.triggerEvent = function(type, target) { 18 return this.triggerHandler(type, [jQuery.event.fix({ type: type, target: target })]); 19 } 20 21 test("basics", function() { 22 state($('#list1').accordion(), 1, 0, 0); 23 }); 24 25 test("autoheight", function() { 26 $('#navigation').accordion({ header: '.head', autoHeight: false }); 27 equals( 90, $('#navigation ul:first').height() ); 28 equals( 126, $('#navigation ul:eq(1)').height() ); 29 equals( 54, $('#navigation ul:last').height() ); 30 $('#navigation').accordion("destroy").accordion({ header: '.head', autoHeight: true }); 31 equals( 126, $('#navigation ul:first').height() ); 32 equals( 126, $('#navigation ul:eq(1)').height() ); 33 equals( 126, $('#navigation ul:last').height() ); 34 }); 35 36 test("activate, numeric", function() { 37 var ac = $('#list1').accordion({ active: 1 }); 38 state(ac, 0, 1, 0); 39 ac.accordion("activate", 2); 40 state(ac, 0, 0, 1); 41 ac.accordion("activate", 0); 42 state(ac, 1, 0, 0); 43 ac.accordion("activate", 1); 44 state(ac, 0, 1, 0); 45 ac.accordion("activate", 2); 46 state(ac, 0, 0, 1); 47 ac.accordion("activate", -1); 48 state(ac, 0, 0, 1); 49 }); 50 51 test("activate, boolean and numeric, alwaysOpen:false", function() { 52 var ac = $('#list1').accordion({alwaysOpen: false}).accordion("activate", 2); 53 state(ac, 0, 0, 1); 54 ok("x", "----"); 55 ac.accordion("activate", 0); 56 state(ac, 1, 0, 0); 57 ok("x", "----"); 58 ac.accordion("activate", -1); 59 state(ac, 0, 0, 0); 60 }); 61 62 test("activate, boolean, alwaysOpen:true", function() { 63 var ac = $('#list1').accordion().accordion("activate", 2); 64 state(ac, 0, 0, 1); 65 ac.accordion("activate", -1); 66 state(ac, 0, 0, 1); 67 }); 68 69 test("activate, string expression", function() { 70 var ac = $('#list1').accordion({ active: ":last" }); 71 state(ac, 0, 0, 1); 72 ac.accordion("activate", ":first"); 73 state(ac, 1, 0, 0); 74 ac.accordion("activate", ":eq(1)"); 75 state(ac, 0, 1, 0); 76 ac.accordion("activate", ":last"); 77 state(ac, 0, 0, 1); 78 }); 79 80 test("activate, jQuery or DOM element", function() { 81 var ac = $('#list1').accordion({ active: $("#list1 a:last") }); 82 state(ac, 0, 0, 1); 83 ac.accordion("activate", $("#list1 a:first")); 84 state(ac, 1, 0, 0); 85 ac.accordion("activate", $("#list1 a")[1]); 86 state(ac, 0, 1, 0); 87 }); 88 89 function state2(accordion) { 90 var args = $.makeArray(arguments).slice(1); 91 $.each(args, function(i, n) { 92 equals(accordion.find("ul").eq(i).is(":visible"), n); 93 }); 94 } 95 96 test("handle click on header-descendant", function() { 97 var ac = $('#navigation').accordion({ header: '.head', autoHeight: false }) 98 ac.triggerEvent("click", $('#navigation span:contains(Bass)')[0]); 99 state2(ac, 0, 1, 0); 100 }); 101 102 test("active:false", function() { 103 $("#list1").accordion({ 104 active: false, 105 alwaysOpen: false 106 }); 107 equals( $("#list1 a.selected").size(), 0, "no headers selected" ); 108 }); 109 110 test("accordionchange event, open closed and close again", function() { 111 expect(8); 112 $("#list1").accordion({ 113 active: false, 114 alwaysOpen: false 115 }) 116 .one("accordionchange", function(event, ui) { 117 equals( ui.oldHeader.size(), 0 ) 118 equals( ui.oldContent.size(), 0 ) 119 equals( ui.newHeader.size(), 1 ) 120 equals( ui.newContent.size(), 1 ) 121 }) 122 .accordion("activate", 0) 123 .one("accordionchange", function(event, ui) { 124 equals( ui.oldHeader.size(), 1 ) 125 equals( ui.oldContent.size(), 1 ) 126 equals( ui.newHeader.size(), 0 ) 127 equals( ui.newContent.size(), 0 ) 128 }) 129 .accordion("activate", 0); 130 }); 131 132 test("accessibility", function () { 133 expect(9); 134 var ac = $('#list1').accordion().accordion("activate", 1); 135 var headers = $(".ui-accordion-header"); 136 137 equals( headers.eq(1).attr("tabindex"), "0", "active header should have tabindex=0"); 138 equals( headers.eq(0).attr("tabindex"), "-1", "inactive header should have tabindex=-1"); 139 equals( ac.attr("role"), "tablist", "main role"); 140 equals( headers.attr("role"), "tab", "tab roles"); 141 equals( headers.next().attr("role"), "tabpanel", "tabpanel roles"); 142 equals( headers.eq(1).attr("aria-expanded"), "true", "active tab has aria-expanded"); 143 equals( headers.eq(0).attr("aria-expanded"), "false", "inactive tab has aria-expanded"); 144 ac.accordion("activate", 0); 145 equals( headers.eq(0).attr("aria-expanded"), "true", "newly active tab has aria-expanded"); 146 equals( headers.eq(1).attr("aria-expanded"), "false", "newly inactive tab has aria-expanded"); 147 }); 148 149 150 })(jQuery);
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Mar 24 11:18:33 2011 | Cross-referenced by PHPXref 0.7 |