aboutsummaryrefslogtreecommitdiffstats
path: root/tests/accordion.js
blob: ff3719b41a27bc188042df8b8d7ff89af9483d67 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
 * 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("div").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({ header: '.head', autoHeight: false });
	equals( 90, $('#navigation ul:first').height() );
	equals( 126, $('#navigation ul:eq(1)').height() );
	equals( 54, $('#navigation ul:last').height() );
	$('#navigation').accordion("destroy").accordion({ header: '.head', autoHeight: true });
	equals( 126, $('#navigation ul:first').height() );
	equals( 126, $('#navigation ul:eq(1)').height() );
	equals( 126, $('#navigation ul: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: ":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("ul").eq(i).is(":visible"), n);
	});
}

test("handle click on header-descendant", function() {
	var ac = $('#navigation').accordion({ header: '.head', 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);
});

})(jQuery);