mirror of
https://github.com/jquery/jquery-ui.git
synced 2026-04-20 03:02:41 -04:00
Accordion tests: Cleanup.
This commit is contained in:
@@ -17,30 +17,37 @@
|
||||
<script src="../testsuite.js"></script>
|
||||
|
||||
<script>
|
||||
$.ui.accordion.prototype.options.animated = false;
|
||||
|
||||
function state(accordion) {
|
||||
var args = $.makeArray(arguments).slice(1);
|
||||
var result = [];
|
||||
$.each(args, function(i, n) {
|
||||
result.push( accordion.find(".ui-accordion-content").eq(i).filter(function() {
|
||||
return $(this).css("display") != "none"
|
||||
}).length ? 1 : 0 );
|
||||
});
|
||||
same(args, result)
|
||||
function state( accordion ) {
|
||||
var expected = $.makeArray( arguments ).slice( 1 );
|
||||
var actual = accordion.find( ".ui-accordion-content" ).map(function() {
|
||||
return $( this ).css( "display" ) === "none" ? 0 : 1;
|
||||
}).get();
|
||||
same( actual, expected );
|
||||
}
|
||||
function equalHeights(accordion, min, max) {
|
||||
function equalHeights( accordion, min, max ) {
|
||||
var sizes = [];
|
||||
accordion.find(".ui-accordion-content").each(function() {
|
||||
sizes.push($(this).outerHeight());
|
||||
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]);
|
||||
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 ] );
|
||||
}
|
||||
function accordionSetupTeardown() {
|
||||
var animated = $.ui.accordion.prototype.options.animated;
|
||||
return {
|
||||
setup: function() {
|
||||
$.ui.accordion.prototype.options.animated = false;
|
||||
},
|
||||
teardown: function() {
|
||||
$.ui.accordion.prototype.options.animated = animated;
|
||||
}
|
||||
};
|
||||
}
|
||||
</script>
|
||||
<script src="accordion_core.js"></script>
|
||||
<script src="accordion_defaults_deprecated.js"></script>
|
||||
<script src="accordion_core.js"></script>
|
||||
<script src="accordion_events.js"></script>
|
||||
<script src="accordion_methods.js"></script>
|
||||
<script src="accordion_options.js"></script>
|
||||
|
||||
@@ -20,30 +20,37 @@
|
||||
<script src="../testsuite.js"></script>
|
||||
|
||||
<script>
|
||||
$.ui.accordion.prototype.options.animated = false;
|
||||
|
||||
function state(accordion) {
|
||||
var args = $.makeArray(arguments).slice(1);
|
||||
var result = [];
|
||||
$.each(args, function(i, n) {
|
||||
result.push( accordion.find(".ui-accordion-content").eq(i).filter(function() {
|
||||
return $(this).css("display") != "none"
|
||||
}).length ? 1 : 0 );
|
||||
});
|
||||
same(args, result)
|
||||
function state( accordion ) {
|
||||
var expected = $.makeArray( arguments ).slice( 1 );
|
||||
var actual = accordion.find( ".ui-accordion-content" ).map(function() {
|
||||
return $( this ).css( "display" ) === "none" ? 0 : 1;
|
||||
}).get();
|
||||
same( actual, expected );
|
||||
}
|
||||
function equalHeights(accordion, min, max) {
|
||||
function equalHeights( accordion, min, max ) {
|
||||
var sizes = [];
|
||||
accordion.find(".ui-accordion-content").each(function() {
|
||||
sizes.push($(this).outerHeight());
|
||||
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]);
|
||||
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 ] );
|
||||
}
|
||||
function accordionSetupTeardown() {
|
||||
var animated = $.ui.accordion.prototype.options.animated;
|
||||
return {
|
||||
setup: function() {
|
||||
$.ui.accordion.prototype.options.animated = false;
|
||||
},
|
||||
teardown: function() {
|
||||
$.ui.accordion.prototype.options.animated = animated;
|
||||
}
|
||||
};
|
||||
}
|
||||
</script>
|
||||
<script src="accordion_core.js"></script>
|
||||
<script src="accordion_defaults.js"></script>
|
||||
<script src="accordion_core.js"></script>
|
||||
<script src="accordion_events.js"></script>
|
||||
<script src="accordion_methods.js"></script>
|
||||
<script src="accordion_options.js"></script>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(function( $ ) {
|
||||
|
||||
module( "accordion: core" );
|
||||
module( "accordion: core", accordionSetupTeardown() );
|
||||
|
||||
test( "handle click on header-descendant", function() {
|
||||
var ac = $( "#navigation" ).accordion();
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
|
||||
var accordion_defaults = {
|
||||
active: 0,
|
||||
animated: false,
|
||||
collapsible: false,
|
||||
disabled: false,
|
||||
event: "click",
|
||||
header: "> li > :first-child,> :not(li):even",
|
||||
heightStyle: "auto",
|
||||
icons: {
|
||||
"activeHeader": "ui-icon-triangle-1-s",
|
||||
"header": "ui-icon-triangle-1-e"
|
||||
commonWidgetTests( "accordion", {
|
||||
defaults: {
|
||||
active: 0,
|
||||
animated: "slide",
|
||||
collapsible: false,
|
||||
disabled: false,
|
||||
event: "click",
|
||||
header: "> li > :first-child,> :not(li):even",
|
||||
heightStyle: "auto",
|
||||
icons: {
|
||||
"activeHeader": "ui-icon-triangle-1-s",
|
||||
"header": "ui-icon-triangle-1-e"
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
commonWidgetTests( "accordion", { defaults: accordion_defaults } );
|
||||
});
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
|
||||
var accordion_defaults = {
|
||||
active: 0,
|
||||
animated: false,
|
||||
autoHeight: true,
|
||||
clearStyle: false,
|
||||
collapsible: false,
|
||||
disabled: false,
|
||||
event: "click",
|
||||
fillSpace: false,
|
||||
header: "> li > :first-child,> :not(li):even",
|
||||
heightStyle: null,
|
||||
icons: {
|
||||
"activeHeader": null,
|
||||
"header": "ui-icon-triangle-1-e",
|
||||
"headerSelected": "ui-icon-triangle-1-s"
|
||||
},
|
||||
navigation: false,
|
||||
navigationFilter: function() {}
|
||||
};
|
||||
|
||||
commonWidgetTests( "accordion", { defaults: accordion_defaults } );
|
||||
commonWidgetTests( "accordion", {
|
||||
defaults: {
|
||||
active: 0,
|
||||
animated: "slide",
|
||||
autoHeight: true,
|
||||
clearStyle: false,
|
||||
collapsible: false,
|
||||
disabled: false,
|
||||
event: "click",
|
||||
fillSpace: false,
|
||||
header: "> li > :first-child,> :not(li):even",
|
||||
heightStyle: null,
|
||||
icons: {
|
||||
"activeHeader": null,
|
||||
"header": "ui-icon-triangle-1-e",
|
||||
"headerSelected": "ui-icon-triangle-1-s"
|
||||
},
|
||||
navigation: false,
|
||||
navigationFilter: function() {}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
(function($) {
|
||||
|
||||
module("accordion (deprecated): expanded active option, activate method");
|
||||
module("accordion (deprecated): expanded active option, activate method", accordionSetupTeardown() );
|
||||
|
||||
test("activate", function() {
|
||||
var expected = $('#list1').accordion(),
|
||||
@@ -96,7 +96,7 @@ test("{ active: jQuery Object }", function() {
|
||||
|
||||
|
||||
|
||||
module("accordion (deprecated) - height options");
|
||||
module("accordion (deprecated) - height options", accordionSetupTeardown() );
|
||||
|
||||
test("{ autoHeight: true }, default", function() {
|
||||
equalHeights($('#navigation').accordion({ autoHeight: true }), 95, 130);
|
||||
@@ -141,7 +141,7 @@ test("{ fillSpace: true } with multiple siblings", function() {
|
||||
|
||||
|
||||
|
||||
module("accordion (deprecated) - icons");
|
||||
module("accordion (deprecated) - icons", accordionSetupTeardown() );
|
||||
|
||||
test("change headerSelected option after creation", function() {
|
||||
var list = $("#list1");
|
||||
@@ -151,4 +151,50 @@ test("change headerSelected option after creation", function() {
|
||||
equals( $( "#list1 span.deprecated" ).length, 1);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
module( "accordion (deprecated) - resize", accordionSetupTeardown() );
|
||||
|
||||
test( "resize", function() {
|
||||
var expected = $( "#navigation" )
|
||||
.parent()
|
||||
.height( 300 )
|
||||
.end()
|
||||
.accordion({
|
||||
heightStyle: "fill"
|
||||
});
|
||||
equalHeights( expected, 246, 258 );
|
||||
|
||||
expected.parent().height( 500 );
|
||||
expected.accordion( "resize" );
|
||||
equalHeights( expected, 446, 458 );
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
module( "accordion (deprecated) - navigation", accordionSetupTeardown() );
|
||||
|
||||
test("{ navigation: true, navigationFilter: header }", function() {
|
||||
$("#navigation").accordion({
|
||||
navigation: true,
|
||||
navigationFilter: function() {
|
||||
return /\?p=1\.1\.3$/.test(this.href);
|
||||
}
|
||||
});
|
||||
equals( $("#navigation .ui-accordion-content:eq(2)").size(), 1, "third content active" );
|
||||
});
|
||||
|
||||
test("{ navigation: true, navigationFilter: content }", function() {
|
||||
$("#navigation").accordion({
|
||||
navigation: true,
|
||||
navigationFilter: function() {
|
||||
return /\?p=1\.1\.3\.2$/.test(this.href);
|
||||
}
|
||||
});
|
||||
equals( $("#navigation .ui-accordion-content:eq(2)").size(), 1, "third content active" );
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(function( $ ) {
|
||||
|
||||
module( "accordion: events" );
|
||||
module( "accordion: events", accordionSetupTeardown() );
|
||||
|
||||
// TODO: verify correct elements in ui properties
|
||||
// TODO: add tests for switching between active panels (not collapsed)
|
||||
|
||||
@@ -1,71 +1,48 @@
|
||||
/*
|
||||
* accordion_methods.js
|
||||
*/
|
||||
(function($) {
|
||||
(function( $ ) {
|
||||
|
||||
module("accordion: methods");
|
||||
module( "accordion: methods", accordionSetupTeardown() );
|
||||
|
||||
test("init", function() {
|
||||
$("<div></div>").appendTo('body').accordion().remove();
|
||||
ok(true, '.accordion() called on element');
|
||||
|
||||
$([]).accordion().remove();
|
||||
ok(true, '.accordion() called on empty collection');
|
||||
|
||||
$('<div></div>').accordion().remove();
|
||||
ok(true, '.accordion() called on disconnected DOMElement - never connected');
|
||||
|
||||
$('<div></div>').appendTo('body').remove().accordion().remove();
|
||||
ok(true, '.accordion() called on disconnected DOMElement - removed');
|
||||
|
||||
var el = $('<div></div>').accordion();
|
||||
var foo = el.accordion("option", "foo");
|
||||
el.remove();
|
||||
ok(true, 'arbitrary option getter after init');
|
||||
|
||||
$('<div></div>').accordion().accordion("option", "foo", "bar").remove();
|
||||
ok(true, 'arbitrary option setter after init');
|
||||
});
|
||||
|
||||
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, "");
|
||||
}
|
||||
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
|
||||
.replace( / role=""/g, "" );
|
||||
equal( afterHtml, beforeHtml );
|
||||
});
|
||||
|
||||
test("enable", function() {
|
||||
var expected = $('#list1').accordion(),
|
||||
actual = expected.accordion('enable');
|
||||
equals(actual, expected, 'enable is chainable');
|
||||
state(expected, 1, 0, 0)
|
||||
test( "enable/disable", function() {
|
||||
var accordion = $('#list1').accordion();
|
||||
state( accordion, 1, 0, 0 );
|
||||
accordion.accordion( "disable" );
|
||||
accordion.accordion( "option", "active", 1 );
|
||||
state( accordion, 1, 0, 0 );
|
||||
accordion.accordion( "enable" );
|
||||
accordion.accordion( "option", "active", 1 );
|
||||
state( accordion, 0, 1, 0 );
|
||||
});
|
||||
|
||||
test("disable", function() {
|
||||
var expected = $('#list1').accordion(),
|
||||
actual = expected.accordion('disable');
|
||||
equals(actual, expected, 'disable is chainable');
|
||||
|
||||
state(expected, 1, 0, 0)
|
||||
expected.accordion("option", "active", 1);
|
||||
state(expected, 1, 0, 0)
|
||||
expected.accordion("enable");
|
||||
expected.accordion("option", "active", 1);
|
||||
state(expected, 0, 1, 0)
|
||||
test( "refresh", function() {
|
||||
var expected = $( "#navigation" )
|
||||
.parent()
|
||||
.height( 300 )
|
||||
.end()
|
||||
.accordion({
|
||||
heightStyle: "fill"
|
||||
});
|
||||
equalHeights( expected, 246, 258 );
|
||||
|
||||
expected.parent().height( 500 );
|
||||
expected.accordion( "refresh" );
|
||||
equalHeights( expected, 446, 458 );
|
||||
});
|
||||
|
||||
test("refresh", function() {
|
||||
var expected = $('#navigation').parent().height(300).end().accordion({
|
||||
heightStyle: "fill"
|
||||
});
|
||||
equalHeights(expected, 246, 258);
|
||||
|
||||
expected.parent().height(500);
|
||||
expected.accordion("refresh");
|
||||
equalHeights(expected, 446, 458);
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
}( jQuery ) );
|
||||
|
||||
@@ -1,128 +1,176 @@
|
||||
/*
|
||||
* accordion_options.js
|
||||
*/
|
||||
(function($) {
|
||||
(function( $ ) {
|
||||
|
||||
module("accordion: options");
|
||||
module( "accordion: options", accordionSetupTeardown() );
|
||||
|
||||
test("{ active: first child }, default", function() {
|
||||
var ac = $("#list1").accordion();
|
||||
equals( ac.accordion('option', 'active'), 0);
|
||||
state(ac, 1, 0, 0)
|
||||
test( "{ active: default }", function() {
|
||||
var ac = $( "#list1" ).accordion();
|
||||
equals( ac.accordion( "option", "active" ), 0 );
|
||||
state( ac, 1, 0, 0 );
|
||||
});
|
||||
|
||||
test("{ active: false }", function() {
|
||||
var ac = $("#list1").accordion({
|
||||
test( "{ active: false }", function() {
|
||||
var ac = $( "#list1" ).accordion({
|
||||
active: false,
|
||||
collapsible: true
|
||||
});
|
||||
state(ac, 0, 0, 0);
|
||||
equals( $("#list1 .ui-accordion-header.ui-state-active").size(), 0, "no headers selected" );
|
||||
equals( $("#list1").accordion('option', 'active'), false);
|
||||
state( ac, 0, 0, 0 );
|
||||
equals( ac.find( ".ui-accordion-header.ui-state-active" ).size(), 0, "no headers selected" );
|
||||
equals( ac.accordion( "option", "active" ), false );
|
||||
|
||||
// TODO: fix active: false when not collapsible
|
||||
// ac.accordion( "option", "collapsible", false );
|
||||
// state( ac, 1, 0, 0 );
|
||||
// equals( ac.accordion( "option", "active" ), 0 );
|
||||
//
|
||||
// ac.accordion( "destroy" );
|
||||
// ac.accordion({
|
||||
// active: false
|
||||
// });
|
||||
// state( ac, 1, 0, 0 );
|
||||
// strictEqual( ac.accordion( "option", "active" ), 0 );
|
||||
});
|
||||
|
||||
test("{ active: Number }", function() {
|
||||
expect(4);
|
||||
$("#list1").accordion({
|
||||
active: 0
|
||||
test( "{ active: Number }", function() {
|
||||
var ac = $( "#list1" ).accordion({
|
||||
active: 2
|
||||
});
|
||||
equals( $("#list1").accordion('option', 'active'), 0);
|
||||
equals( ac.accordion( "option", "active" ), 2 );
|
||||
state( ac, 0, 0, 1 );
|
||||
|
||||
$("#list1").accordion('option', 'active', 1);
|
||||
equals( $("#list1").accordion('option', 'active'), 1);
|
||||
ac.accordion( "option", "active", 0 );
|
||||
equals( ac.accordion( "option", "active" ), 0 );
|
||||
state( ac, 1, 0, 0 );
|
||||
|
||||
$('.ui-accordion-header:eq(2)', '#list1').click();
|
||||
equals( $("#list1").accordion('option', 'active'), 2);
|
||||
ac.find( ".ui-accordion-header" ).eq( 1 ).click();
|
||||
equals( ac.accordion( "option", "active" ), 1 );
|
||||
state( ac, 0, 1, 0 );
|
||||
|
||||
$("#list1").accordion('option', 'active', 0);
|
||||
equals( $("#list1").accordion('option', 'active'), 0);
|
||||
ac.accordion( "option", "active", 10 );
|
||||
equals( ac.accordion( "option", "active" ), 1 );
|
||||
state( ac, 0, 1, 0 );
|
||||
});
|
||||
|
||||
test("{ heightStyle: 'auto' }, default", function() {
|
||||
equalHeights($('#navigation').accordion({ heightStyle: 'auto' }), 95, 130);
|
||||
});
|
||||
if ( $.uiBackCompat === false ) {
|
||||
test( "{ active: -Number }", function() {
|
||||
// TODO: fix initializing with negative value
|
||||
var ac = $( "#list1" ).accordion({
|
||||
// active: -1
|
||||
});
|
||||
// equals( ac.accordion( "option", "active" ), 2 );
|
||||
// state( ac, 0, 0, 1 );
|
||||
|
||||
test("{ heightStyle: 'content' }", function() {
|
||||
var accordion = $('#navigation').accordion({ heightStyle: 'content' });
|
||||
var sizes = [];
|
||||
accordion.find(".ui-accordion-content").each(function() {
|
||||
sizes.push($(this).height());
|
||||
ac.accordion( "option", "active", -2 );
|
||||
equals( ac.accordion( "option", "active" ), 1 );
|
||||
state( ac, 0, 1, 0 );
|
||||
|
||||
ac.accordion( "option", "active", -10 );
|
||||
equals( ac.accordion( "option", "active" ), 1 );
|
||||
state( ac, 0, 1, 0 );
|
||||
|
||||
ac.accordion( "option", "active", -3 );
|
||||
equals( ac.accordion( "option", "active" ), 0 );
|
||||
state( ac, 1, 0, 0 );
|
||||
});
|
||||
ok( sizes[0] >= 70 && sizes[0] <= 90, "was " + sizes[0] );
|
||||
ok( sizes[1] >= 98 && sizes[1] <= 126, "was " + sizes[1] );
|
||||
ok( sizes[2] >= 42 && sizes[2] <= 54, "was " + sizes[2] );
|
||||
});
|
||||
test("{ collapsible: false }, default", function() {
|
||||
var ac = $("#list1").accordion();
|
||||
ac.accordion("option", "active", false);
|
||||
state(ac, 1, 0, 0);
|
||||
}
|
||||
|
||||
// TODO: add animation tests
|
||||
|
||||
test( "{ collapsible: false }", function() {
|
||||
var ac = $( "#list1" ).accordion({
|
||||
active: 1
|
||||
});
|
||||
ac.accordion( "option", "active", false );
|
||||
equal( ac.accordion( "option", "active" ), 1 );
|
||||
state( ac, 0, 1, 0 );
|
||||
|
||||
ac.find( ".ui-accordion-header" ).eq( 1 ).click();
|
||||
equal( ac.accordion( "option", "active" ), 1 );
|
||||
state( ac, 0, 1, 0 );
|
||||
});
|
||||
|
||||
test("{ collapsible: true }", function() {
|
||||
var ac = $("#list1").accordion({
|
||||
test( "{ collapsible: true }", function() {
|
||||
var ac = $( "#list1" ).accordion({
|
||||
active: 1,
|
||||
collapsible: true
|
||||
});
|
||||
var header = $('#list1 .ui-accordion-header:eq(1)').click();
|
||||
equals( $("#list1").accordion('option', 'active'), false);
|
||||
state(ac, 0, 0, 0);
|
||||
|
||||
// TODO: fix setting active to false
|
||||
// ac.accordion( "option", "active", false );
|
||||
// equal( ac.accordion( "option", "active" ), false );
|
||||
// state( ac, 0, 0, 0 );
|
||||
|
||||
ac.accordion( "option", "active", 1 );
|
||||
equal( ac.accordion( "option", "active" ), 1 );
|
||||
state( ac, 0, 1, 0 );
|
||||
|
||||
ac.find( ".ui-accordion-header" ).eq( 1 ).click();
|
||||
equals( ac.accordion( "option", "active" ), false );
|
||||
state( ac, 0, 0, 0 );
|
||||
});
|
||||
|
||||
test("{ heightStyle: 'fill' }", function() {
|
||||
$("#navigationWrapper").height(500);
|
||||
equalHeights($('#navigation').accordion({ heightStyle: 'fill' }), 446, 458);
|
||||
// TODO: add event tests
|
||||
|
||||
// TODO: add more header tests
|
||||
test( "{ header: default }", function() {
|
||||
// default: > li > :first-child,> :not(li):even
|
||||
// > :not(li):even
|
||||
state( $( "#list1" ).accordion(), 1, 0, 0);
|
||||
// > li > :first-child
|
||||
state( $( "#navigation" ).accordion(), 1, 0, 0);
|
||||
});
|
||||
|
||||
test("{ header: '> li > :first-child,> :not(li):even' }, default", function() {
|
||||
state($("#list1").accordion(), 1, 0, 0);
|
||||
state($("#navigation").accordion(), 1, 0, 0);
|
||||
test( "{ heightStyle: 'auto' }", function() {
|
||||
var ac = $( "#navigation" ).accordion({ heightStyle: "auto" });
|
||||
equalHeights( ac, 95, 130 );
|
||||
});
|
||||
|
||||
test("{ icons: false }", function() {
|
||||
var list = $("#list1");
|
||||
function icons(on) {
|
||||
same($("span.ui-icon", list).length, on ? 3 : 0);
|
||||
same( list.hasClass("ui-accordion-icons"), on );
|
||||
test( "{ heightStyle: 'content' }", function() {
|
||||
var ac = $( "#navigation" ).accordion({ heightStyle: "content" });
|
||||
var sizes = ac.find( ".ui-accordion-content" ).map(function() {
|
||||
return $( this ).height();
|
||||
}).get();
|
||||
ok( sizes[ 0 ] >= 70 && sizes[ 0 ] <= 90, "was " + sizes[ 0 ] );
|
||||
ok( sizes[ 1 ] >= 98 && sizes[ 1 ] <= 126, "was " + sizes[ 1 ] );
|
||||
ok( sizes[ 2 ] >= 42 && sizes[ 2 ] <= 54, "was " + sizes[ 2 ] );
|
||||
});
|
||||
|
||||
test( "{ heightStyle: 'fill' }", function() {
|
||||
$( "#navigationWrapper" ).height( 500 );
|
||||
var ac = $( "#navigation" ).accordion({ heightStyle: "fill" });
|
||||
equalHeights( ac, 446, 458);
|
||||
ac.accordion( "destroy" );
|
||||
|
||||
$( "<div>" ).height( 100 ).appendTo( "#navigationWrapper" );
|
||||
ac.accordion({ heightStyle: "fill" });
|
||||
equalHeights( ac, 346, 358 );
|
||||
});
|
||||
|
||||
test( "{ icons: false }", function() {
|
||||
var list = $( "#list1" );
|
||||
function icons( on ) {
|
||||
same( list.find( "span.ui-icon").length, on ? 3 : 0 );
|
||||
same( list.hasClass( "ui-accordion-icons" ), on );
|
||||
}
|
||||
list.accordion();
|
||||
icons(true);
|
||||
list.accordion("destroy").accordion({
|
||||
icons( true );
|
||||
list.accordion( "destroy" ).accordion({
|
||||
icons: false
|
||||
});
|
||||
icons(false);
|
||||
list.accordion("option", "icons", $.ui.accordion.prototype.options.icons);
|
||||
icons(true);
|
||||
list.accordion("option", "icons", false);
|
||||
icons(false);
|
||||
icons( false );
|
||||
list.accordion( "option", "icons", $.ui.accordion.prototype.options.icons );
|
||||
icons( true );
|
||||
list.accordion( "option", "icons", false );
|
||||
icons( false );
|
||||
});
|
||||
|
||||
test("{ icons: { activeHeader : 'test' } }", function() {
|
||||
var list = $("#list1");
|
||||
list.accordion( { icons: { "activeHeader": "test" } } );
|
||||
equals( $( "#list1 span.test" ).length, 1);
|
||||
list.accordion("option", "icons", { "activeHeader": "news" } );
|
||||
equals( $( "#list1 span.test" ).length, 0);
|
||||
equals( $( "#list1 span.news" ).length, 1);
|
||||
});
|
||||
|
||||
test("{ navigation: true, navigationFilter: header }", function() {
|
||||
$("#navigation").accordion({
|
||||
navigation: true,
|
||||
navigationFilter: function() {
|
||||
return /\?p=1\.1\.3$/.test(this.href);
|
||||
}
|
||||
test( "{ icons: hash }", function() {
|
||||
var list = $( "#list1" ).accordion({
|
||||
icons: { activeHeader: "a1", header: "h1" }
|
||||
});
|
||||
equals( $("#navigation .ui-accordion-content:eq(2)").size(), 1, "third content active" );
|
||||
ok( list.find( ".ui-accordion-header.ui-state-active span.ui-icon" ).hasClass( "a1" ) );
|
||||
list.accordion( "option", "icons", { activeHeader: "a2", header: "h2" } );
|
||||
ok( !list.find( ".ui-accordion-header.ui-state-active span.ui-icon" ).hasClass( "a1" ) );
|
||||
ok( list.find( ".ui-accordion-header.ui-state-active span.ui-icon" ).hasClass( "a2" ) );
|
||||
});
|
||||
|
||||
test("{ navigation: true, navigationFilter: content }", function() {
|
||||
$("#navigation").accordion({
|
||||
navigation: true,
|
||||
navigationFilter: function() {
|
||||
return /\?p=1\.1\.3\.2$/.test(this.href);
|
||||
}
|
||||
});
|
||||
equals( $("#navigation .ui-accordion-content:eq(2)").size(), 1, "third content active" );
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
}( jQuery ) );
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
/*
|
||||
* accordion_tickets.js
|
||||
*/
|
||||
(function($) {
|
||||
(function( $ ) {
|
||||
|
||||
module("accordion: tickets");
|
||||
module( "accordion: tickets", accordionSetupTeardown() );
|
||||
|
||||
})(jQuery);
|
||||
}( jQuery ) );
|
||||
|
||||
@@ -1,39 +1,67 @@
|
||||
function testWidgetDefaults(widget, defaults) {
|
||||
var pluginDefaults = $.extend({},
|
||||
$.ui[widget].prototype.options
|
||||
);
|
||||
|
||||
(function() {
|
||||
|
||||
function testWidgetDefaults( widget, defaults ) {
|
||||
var pluginDefaults = $.ui[ widget ].prototype.options;
|
||||
|
||||
// ensure that all defaults have the correct value
|
||||
test('defined defaults', function() {
|
||||
$.each(defaults, function(key, val) {
|
||||
if ($.isFunction(val)) {
|
||||
ok(val !== undefined, key);
|
||||
test( "defined defaults", function() {
|
||||
$.each( defaults, function( key, val ) {
|
||||
if ( $.isFunction( val ) ) {
|
||||
ok( $.isFunction( pluginDefaults[ key ] ), key );
|
||||
return;
|
||||
}
|
||||
same(pluginDefaults[key], val, key);
|
||||
same( pluginDefaults[ key ], val, key );
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// ensure that all defaults were tested
|
||||
test('tested defaults', function() {
|
||||
$.each(pluginDefaults, function(key, val) {
|
||||
ok(key in defaults, key);
|
||||
test( "tested defaults", function() {
|
||||
$.each( pluginDefaults, function( key, val ) {
|
||||
ok( key in defaults, key );
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function testWidgetOverrides(widget) {
|
||||
test('$.widget overrides', function() {
|
||||
$.each(['_widgetInit', 'option', '_trigger'], function(i, method) {
|
||||
ok($.Widget.prototype[method] == $.ui[widget].prototype[method],
|
||||
'should not override ' + method);
|
||||
var privateMethods = [
|
||||
"_createWidget",
|
||||
"_super",
|
||||
"_superApply",
|
||||
"destroy",
|
||||
"option",
|
||||
"enable",
|
||||
"disable",
|
||||
"_trigger"
|
||||
];
|
||||
|
||||
function testWidgetOverrides( widget ) {
|
||||
test( "$.widget overrides", function() {
|
||||
$.each( privateMethods, function( i, method ) {
|
||||
strictEqual( $.ui[ widget ].prototype[ method ],
|
||||
$.Widget.prototype[ method ], "should not override " + method );
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function commonWidgetTests(widget, settings) {
|
||||
module(widget + ": common widget");
|
||||
function testBasicUsage( widget ) {
|
||||
test( "basic usage", function() {
|
||||
var defaultElement = $.ui[ widget ].prototype.defaultElement;
|
||||
$( defaultElement ).appendTo( "body" )[ widget ]().remove();
|
||||
ok( true, "initialized on element" );
|
||||
|
||||
testWidgetDefaults(widget, settings.defaults);
|
||||
testWidgetOverrides(widget);
|
||||
$( defaultElement ).accordion().remove();
|
||||
ok( true, "initialized on disconnected DOMElement - never connected" );
|
||||
|
||||
$( defaultElement ).appendTo( "body" ).remove().accordion().remove();
|
||||
ok( true, "initialized on disconnected DOMElement - removed" );
|
||||
});
|
||||
}
|
||||
|
||||
window.commonWidgetTests = function( widget, settings ) {
|
||||
module( widget + ": common widget" );
|
||||
|
||||
testWidgetDefaults( widget, settings.defaults );
|
||||
testWidgetOverrides( widget );
|
||||
testBasicUsage( widget );
|
||||
};
|
||||
|
||||
}());
|
||||
|
||||
Reference in New Issue
Block a user