Skip to content

Commit 5ed1046

Browse files
committed
Accordion tests: Cleanup.
1 parent ecc0ef5 commit 5ed1046

11 files changed

+369
-261
lines changed

tests/unit/accordion/accordio.html

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,37 @@
1717
<script src="../testsuite.js"></script>
1818

1919
<script>
20-
$.ui.accordion.prototype.options.animated = false;
21-
22-
function state(accordion) {
23-
var args = $.makeArray(arguments).slice(1);
24-
var result = [];
25-
$.each(args, function(i, n) {
26-
result.push( accordion.find(".ui-accordion-content").eq(i).filter(function() {
27-
return $(this).css("display") != "none"
28-
}).length ? 1 : 0 );
29-
});
30-
same(args, result)
20+
function state( accordion ) {
21+
var expected = $.makeArray( arguments ).slice( 1 );
22+
var actual = accordion.find( ".ui-accordion-content" ).map(function() {
23+
return $( this ).css( "display" ) === "none" ? 0 : 1;
24+
}).get();
25+
same( actual, expected );
3126
}
32-
function equalHeights(accordion, min, max) {
27+
function equalHeights( accordion, min, max ) {
3328
var sizes = [];
34-
accordion.find(".ui-accordion-content").each(function() {
35-
sizes.push($(this).outerHeight());
29+
accordion.find( ".ui-accordion-content" ).each(function() {
30+
sizes.push( $( this ).outerHeight() );
3631
});
37-
ok( sizes[0] >= min && sizes[0] <= max, "must be within " + min + " and " + max + ", was " + sizes[0] );
38-
same(sizes[0], sizes[1]);
39-
same(sizes[0], sizes[2]);
32+
ok( sizes[ 0 ] >= min && sizes[ 0 ] <= max,
33+
"must be within " + min + " and " + max + ", was " + sizes[ 0 ] );
34+
same( sizes[ 0 ], sizes[ 1 ] );
35+
same( sizes[ 0 ], sizes[ 2 ] );
36+
}
37+
function accordionSetupTeardown() {
38+
var animated = $.ui.accordion.prototype.options.animated;
39+
return {
40+
setup: function() {
41+
$.ui.accordion.prototype.options.animated = false;
42+
},
43+
teardown: function() {
44+
$.ui.accordion.prototype.options.animated = animated;
45+
}
46+
};
4047
}
4148
</script>
42-
<script src="accordion_core.js"></script>
4349
<script src="accordion_defaults_deprecated.js"></script>
50+
<script src="accordion_core.js"></script>
4451
<script src="accordion_events.js"></script>
4552
<script src="accordion_methods.js"></script>
4653
<script src="accordion_options.js"></script>

tests/unit/accordion/accordion.html

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,37 @@
2020
<script src="../testsuite.js"></script>
2121

2222
<script>
23-
$.ui.accordion.prototype.options.animated = false;
24-
25-
function state(accordion) {
26-
var args = $.makeArray(arguments).slice(1);
27-
var result = [];
28-
$.each(args, function(i, n) {
29-
result.push( accordion.find(".ui-accordion-content").eq(i).filter(function() {
30-
return $(this).css("display") != "none"
31-
}).length ? 1 : 0 );
32-
});
33-
same(args, result)
23+
function state( accordion ) {
24+
var expected = $.makeArray( arguments ).slice( 1 );
25+
var actual = accordion.find( ".ui-accordion-content" ).map(function() {
26+
return $( this ).css( "display" ) === "none" ? 0 : 1;
27+
}).get();
28+
same( actual, expected );
3429
}
35-
function equalHeights(accordion, min, max) {
30+
function equalHeights( accordion, min, max ) {
3631
var sizes = [];
37-
accordion.find(".ui-accordion-content").each(function() {
38-
sizes.push($(this).outerHeight());
32+
accordion.find( ".ui-accordion-content" ).each(function() {
33+
sizes.push( $( this ).outerHeight() );
3934
});
40-
ok( sizes[0] >= min && sizes[0] <= max, "must be within " + min + " and " + max + ", was " + sizes[0] );
41-
same(sizes[0], sizes[1]);
42-
same(sizes[0], sizes[2]);
35+
ok( sizes[ 0 ] >= min && sizes[ 0 ] <= max,
36+
"must be within " + min + " and " + max + ", was " + sizes[ 0 ] );
37+
same( sizes[ 0 ], sizes[ 1 ] );
38+
same( sizes[ 0 ], sizes[ 2 ] );
39+
}
40+
function accordionSetupTeardown() {
41+
var animated = $.ui.accordion.prototype.options.animated;
42+
return {
43+
setup: function() {
44+
$.ui.accordion.prototype.options.animated = false;
45+
},
46+
teardown: function() {
47+
$.ui.accordion.prototype.options.animated = animated;
48+
}
49+
};
4350
}
4451
</script>
45-
<script src="accordion_core.js"></script>
4652
<script src="accordion_defaults.js"></script>
53+
<script src="accordion_core.js"></script>
4754
<script src="accordion_events.js"></script>
4855
<script src="accordion_methods.js"></script>
4956
<script src="accordion_options.js"></script>

tests/unit/accordion/accordion_core.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(function( $ ) {
22

3-
module( "accordion: core" );
3+
module( "accordion: core", accordionSetupTeardown() );
44

55
test( "handle click on header-descendant", function() {
66
var ac = $( "#navigation" ).accordion();
Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
2-
var accordion_defaults = {
3-
active: 0,
4-
animated: false,
5-
collapsible: false,
6-
disabled: false,
7-
event: "click",
8-
header: "> li > :first-child,> :not(li):even",
9-
heightStyle: "auto",
10-
icons: {
11-
"activeHeader": "ui-icon-triangle-1-s",
12-
"header": "ui-icon-triangle-1-e"
1+
commonWidgetTests( "accordion", {
2+
defaults: {
3+
active: 0,
4+
animated: "slide",
5+
collapsible: false,
6+
disabled: false,
7+
event: "click",
8+
header: "> li > :first-child,> :not(li):even",
9+
heightStyle: "auto",
10+
icons: {
11+
"activeHeader": "ui-icon-triangle-1-s",
12+
"header": "ui-icon-triangle-1-e"
13+
}
1314
}
14-
};
15-
16-
commonWidgetTests( "accordion", { defaults: accordion_defaults } );
15+
});
Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,21 @@
1-
2-
var accordion_defaults = {
3-
active: 0,
4-
animated: false,
5-
autoHeight: true,
6-
clearStyle: false,
7-
collapsible: false,
8-
disabled: false,
9-
event: "click",
10-
fillSpace: false,
11-
header: "> li > :first-child,> :not(li):even",
12-
heightStyle: null,
13-
icons: {
14-
"activeHeader": null,
15-
"header": "ui-icon-triangle-1-e",
16-
"headerSelected": "ui-icon-triangle-1-s"
17-
},
18-
navigation: false,
19-
navigationFilter: function() {}
20-
};
21-
22-
commonWidgetTests( "accordion", { defaults: accordion_defaults } );
1+
commonWidgetTests( "accordion", {
2+
defaults: {
3+
active: 0,
4+
animated: "slide",
5+
autoHeight: true,
6+
clearStyle: false,
7+
collapsible: false,
8+
disabled: false,
9+
event: "click",
10+
fillSpace: false,
11+
header: "> li > :first-child,> :not(li):even",
12+
heightStyle: null,
13+
icons: {
14+
"activeHeader": null,
15+
"header": "ui-icon-triangle-1-e",
16+
"headerSelected": "ui-icon-triangle-1-s"
17+
},
18+
navigation: false,
19+
navigationFilter: function() {}
20+
}
21+
});

tests/unit/accordion/accordion_deprecated.js

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
(function($) {
77

8-
module("accordion (deprecated): expanded active option, activate method");
8+
module("accordion (deprecated): expanded active option, activate method", accordionSetupTeardown() );
99

1010
test("activate", function() {
1111
var expected = $('#list1').accordion(),
@@ -96,7 +96,7 @@ test("{ active: jQuery Object }", function() {
9696

9797

9898

99-
module("accordion (deprecated) - height options");
99+
module("accordion (deprecated) - height options", accordionSetupTeardown() );
100100

101101
test("{ autoHeight: true }, default", function() {
102102
equalHeights($('#navigation').accordion({ autoHeight: true }), 95, 130);
@@ -141,7 +141,7 @@ test("{ fillSpace: true } with multiple siblings", function() {
141141

142142

143143

144-
module("accordion (deprecated) - icons");
144+
module("accordion (deprecated) - icons", accordionSetupTeardown() );
145145

146146
test("change headerSelected option after creation", function() {
147147
var list = $("#list1");
@@ -151,4 +151,50 @@ test("change headerSelected option after creation", function() {
151151
equals( $( "#list1 span.deprecated" ).length, 1);
152152
});
153153

154+
155+
156+
157+
158+
module( "accordion (deprecated) - resize", accordionSetupTeardown() );
159+
160+
test( "resize", function() {
161+
var expected = $( "#navigation" )
162+
.parent()
163+
.height( 300 )
164+
.end()
165+
.accordion({
166+
heightStyle: "fill"
167+
});
168+
equalHeights( expected, 246, 258 );
169+
170+
expected.parent().height( 500 );
171+
expected.accordion( "resize" );
172+
equalHeights( expected, 446, 458 );
173+
});
174+
175+
176+
177+
178+
module( "accordion (deprecated) - navigation", accordionSetupTeardown() );
179+
180+
test("{ navigation: true, navigationFilter: header }", function() {
181+
$("#navigation").accordion({
182+
navigation: true,
183+
navigationFilter: function() {
184+
return /\?p=1\.1\.3$/.test(this.href);
185+
}
186+
});
187+
equals( $("#navigation .ui-accordion-content:eq(2)").size(), 1, "third content active" );
188+
});
189+
190+
test("{ navigation: true, navigationFilter: content }", function() {
191+
$("#navigation").accordion({
192+
navigation: true,
193+
navigationFilter: function() {
194+
return /\?p=1\.1\.3\.2$/.test(this.href);
195+
}
196+
});
197+
equals( $("#navigation .ui-accordion-content:eq(2)").size(), 1, "third content active" );
198+
});
199+
154200
})(jQuery);

tests/unit/accordion/accordion_events.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(function( $ ) {
22

3-
module( "accordion: events" );
3+
module( "accordion: events", accordionSetupTeardown() );
44

55
// TODO: verify correct elements in ui properties
66
// TODO: add tests for switching between active panels (not collapsed)
Lines changed: 41 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,48 @@
1-
/*
2-
* accordion_methods.js
3-
*/
4-
(function($) {
5-
6-
module("accordion: methods");
7-
8-
test("init", function() {
9-
$("<div></div>").appendTo('body').accordion().remove();
10-
ok(true, '.accordion() called on element');
11-
12-
$([]).accordion().remove();
13-
ok(true, '.accordion() called on empty collection');
14-
15-
$('<div></div>').accordion().remove();
16-
ok(true, '.accordion() called on disconnected DOMElement - never connected');
17-
18-
$('<div></div>').appendTo('body').remove().accordion().remove();
19-
ok(true, '.accordion() called on disconnected DOMElement - removed');
20-
21-
var el = $('<div></div>').accordion();
22-
var foo = el.accordion("option", "foo");
23-
el.remove();
24-
ok(true, 'arbitrary option getter after init');
25-
26-
$('<div></div>').accordion().accordion("option", "foo", "bar").remove();
27-
ok(true, 'arbitrary option setter after init');
28-
});
29-
30-
test("destroy", function() {
31-
var beforeHtml = $("#list1").find("div").css("font-style", "normal").end().parent().html();
32-
var afterHtml = $("#list1").accordion().accordion("destroy").parent().html();
33-
// Opera 9 outputs role="" instead of removing the attribute like everyone else
34-
if ($.browser.opera) {
35-
afterHtml = afterHtml.replace(/ role=""/g, "");
36-
}
1+
(function( $ ) {
2+
3+
module( "accordion: methods", accordionSetupTeardown() );
4+
5+
test( "destroy", function() {
6+
var beforeHtml = $( "#list1" )
7+
.find( "div" )
8+
.css( "font-style", "normal" )
9+
.end()
10+
.parent()
11+
.html();
12+
var afterHtml = $( "#list1" )
13+
.accordion()
14+
.accordion( "destroy" )
15+
.parent()
16+
.html()
17+
// Opera 9 outputs role="" instead of removing the attribute like everyone else
18+
.replace( / role=""/g, "" );
3719
equal( afterHtml, beforeHtml );
3820
});
3921

40-
test("enable", function() {
41-
var expected = $('#list1').accordion(),
42-
actual = expected.accordion('enable');
43-
equals(actual, expected, 'enable is chainable');
44-
state(expected, 1, 0, 0)
45-
});
46-
47-
test("disable", function() {
48-
var expected = $('#list1').accordion(),
49-
actual = expected.accordion('disable');
50-
equals(actual, expected, 'disable is chainable');
51-
52-
state(expected, 1, 0, 0)
53-
expected.accordion("option", "active", 1);
54-
state(expected, 1, 0, 0)
55-
expected.accordion("enable");
56-
expected.accordion("option", "active", 1);
57-
state(expected, 0, 1, 0)
22+
test( "enable/disable", function() {
23+
var accordion = $('#list1').accordion();
24+
state( accordion, 1, 0, 0 );
25+
accordion.accordion( "disable" );
26+
accordion.accordion( "option", "active", 1 );
27+
state( accordion, 1, 0, 0 );
28+
accordion.accordion( "enable" );
29+
accordion.accordion( "option", "active", 1 );
30+
state( accordion, 0, 1, 0 );
5831
});
5932

60-
test("refresh", function() {
61-
var expected = $('#navigation').parent().height(300).end().accordion({
62-
heightStyle: "fill"
63-
});
64-
equalHeights(expected, 246, 258);
65-
66-
expected.parent().height(500);
67-
expected.accordion("refresh");
68-
equalHeights(expected, 446, 458);
33+
test( "refresh", function() {
34+
var expected = $( "#navigation" )
35+
.parent()
36+
.height( 300 )
37+
.end()
38+
.accordion({
39+
heightStyle: "fill"
40+
});
41+
equalHeights( expected, 246, 258 );
42+
43+
expected.parent().height( 500 );
44+
expected.accordion( "refresh" );
45+
equalHeights( expected, 446, 458 );
6946
});
7047

71-
})(jQuery);
48+
}( jQuery ) );

0 commit comments

Comments
 (0)