mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
Button: Use new has/lacksClasses assertions for all class checks
This commit is contained in:
parent
0f370b3e35
commit
415675eca1
@ -9,6 +9,7 @@
|
||||
<script src="../../../external/qunit/qunit.js"></script>
|
||||
<script src="../../../external/jquery-simulate/jquery.simulate.js"></script>
|
||||
<script src="../testsuite.js"></script>
|
||||
<script src="../../../external/qunit-assert-classes/qunit-assert-classes.js"></script>
|
||||
<script>
|
||||
TestHelpers.loadResources({
|
||||
css: [ "core", "button" ],
|
||||
|
@ -6,50 +6,55 @@
|
||||
|
||||
module("button: core");
|
||||
|
||||
test("checkbox", function() {
|
||||
test("checkbox", function( assert ) {
|
||||
expect( 4 );
|
||||
var input = $("#check"),
|
||||
label = $("label[for=check]");
|
||||
ok( input.is(":visible") );
|
||||
ok( label.is(":not(.ui-button)") );
|
||||
input.button();
|
||||
ok( input.is(".ui-helper-hidden-accessible") );
|
||||
ok( label.is(".ui-button") );
|
||||
assert.hasClasses( input, "ui-helper-hidden-accessible" );
|
||||
assert.hasClasses( label, "ui-button" );
|
||||
});
|
||||
|
||||
test("radios", function() {
|
||||
expect( 4 );
|
||||
test("radios", function( assert ) {
|
||||
expect( 8 );
|
||||
var inputs = $("#radio0 input"),
|
||||
labels = $("#radio0 label");
|
||||
ok( inputs.is(":visible") );
|
||||
ok( labels.is(":not(.ui-button)") );
|
||||
inputs.button();
|
||||
ok( inputs.is(".ui-helper-hidden-accessible") );
|
||||
ok( labels.is(".ui-button") );
|
||||
inputs.each(function() {
|
||||
assert.hasClasses( this, "ui-helper-hidden-accessible" );
|
||||
});
|
||||
labels.each(function() {
|
||||
assert.hasClasses( this, "ui-button" );
|
||||
});
|
||||
});
|
||||
|
||||
function assert(noForm, form1, form2) {
|
||||
ok( $("#radio0 .ui-button" + noForm).is(".ui-state-active") );
|
||||
ok( $("#radio1 .ui-button" + form1).is(".ui-state-active") );
|
||||
ok( $("#radio2 .ui-button" + form2).is(".ui-state-active") );
|
||||
}
|
||||
|
||||
test("radio groups", function() {
|
||||
test("radio groups", function( assert ) {
|
||||
expect( 12 );
|
||||
|
||||
function assertClasses(noForm, form1, form2) {
|
||||
assert.hasClasses( $("#radio0 .ui-button" + noForm ), "ui-state-active" );
|
||||
assert.hasClasses( $("#radio1 .ui-button" + form1 ), "ui-state-active" );
|
||||
assert.hasClasses( $("#radio2 .ui-button" + form2 ), "ui-state-active" );
|
||||
}
|
||||
|
||||
$("input[type=radio]").button();
|
||||
assert(":eq(0)", ":eq(1)", ":eq(2)");
|
||||
assertClasses(":eq(0)", ":eq(1)", ":eq(2)");
|
||||
|
||||
// click outside of forms
|
||||
$("#radio0 .ui-button:eq(1)").click();
|
||||
assert(":eq(1)", ":eq(1)", ":eq(2)");
|
||||
assertClasses(":eq(1)", ":eq(1)", ":eq(2)");
|
||||
|
||||
// click in first form
|
||||
$("#radio1 .ui-button:eq(0)").click();
|
||||
assert(":eq(1)", ":eq(0)", ":eq(2)");
|
||||
assertClasses(":eq(1)", ":eq(0)", ":eq(2)");
|
||||
|
||||
// click in second form
|
||||
$("#radio2 .ui-button:eq(0)").click();
|
||||
assert(":eq(1)", ":eq(0)", ":eq(0)");
|
||||
assertClasses(":eq(1)", ":eq(0)", ":eq(0)");
|
||||
});
|
||||
|
||||
test( "radio groups - ignore elements with same name", function() {
|
||||
@ -74,10 +79,10 @@ test("input type submit, don't create child elements", function() {
|
||||
deepEqual( input.children().length, 0 );
|
||||
});
|
||||
|
||||
test("buttonset", function() {
|
||||
test("buttonset", function( assert ) {
|
||||
expect( 6 );
|
||||
var set = $("#radio1").buttonset();
|
||||
ok( set.is(".ui-buttonset") );
|
||||
assert.hasClasses( set, "ui-buttonset" );
|
||||
deepEqual( set.children(".ui-button").length, 3 );
|
||||
deepEqual( set.children("input[type=radio].ui-helper-hidden-accessible").length, 3 );
|
||||
ok( set.children("label:eq(0)").is(".ui-button.ui-corner-left:not(.ui-corner-all)") );
|
||||
@ -85,7 +90,7 @@ test("buttonset", function() {
|
||||
ok( set.children("label:eq(2)").is(".ui-button.ui-corner-right:not(.ui-corner-all)") );
|
||||
});
|
||||
|
||||
test("buttonset (rtl)", function() {
|
||||
test("buttonset (rtl)", function( assert ) {
|
||||
expect( 6 );
|
||||
var set,
|
||||
parent = $("#radio1").parent();
|
||||
@ -93,7 +98,7 @@ test("buttonset (rtl)", function() {
|
||||
parent.attr("dir", "rtl");
|
||||
|
||||
set = $("#radio1").buttonset();
|
||||
ok( set.is(".ui-buttonset") );
|
||||
assert.hasClasses( set, "ui-buttonset" );
|
||||
deepEqual( set.children(".ui-button").length, 3 );
|
||||
deepEqual( set.children("input[type=radio].ui-helper-hidden-accessible").length, 3 );
|
||||
ok( set.children("label:eq(0)").is(".ui-button.ui-corner-right:not(.ui-corner-all)") );
|
||||
@ -105,14 +110,14 @@ test("buttonset (rtl)", function() {
|
||||
// remove this when simulate properly simulates this
|
||||
// see http://yuilibrary.com/projects/yui2/ticket/2528826 fore more info
|
||||
if ( !$.ui.ie || ( document.documentMode && document.documentMode > 8 ) ) {
|
||||
asyncTest( "ensure checked and aria after single click on checkbox label button, see #5518", function() {
|
||||
asyncTest( "ensure checked and aria after single click on checkbox label button, see #5518", function( assert ) {
|
||||
expect( 3 );
|
||||
|
||||
$("#check2").button().change( function() {
|
||||
var lbl = $( this ).button("widget");
|
||||
ok( this.checked, "checked ok" );
|
||||
ok( lbl.attr("aria-pressed") === "true", "aria ok" );
|
||||
ok( lbl.hasClass("ui-state-active"), "ui-state-active ok" );
|
||||
assert.hasClasses( lbl, "ui-state-active" );
|
||||
});
|
||||
|
||||
// support: Opera
|
||||
@ -126,47 +131,48 @@ if ( !$.ui.ie || ( document.documentMode && document.documentMode > 8 ) ) {
|
||||
});
|
||||
}
|
||||
|
||||
test( "#7092 - button creation that requires a matching label does not find label in all cases", function() {
|
||||
test( "#7092 - button creation that requires a matching label does not find label in all cases", function( assert ) {
|
||||
expect( 5 );
|
||||
var group = $( "<span><label for='t7092a'></label><input type='checkbox' id='t7092a'></span>" );
|
||||
group.find( "input[type=checkbox]" ).button();
|
||||
ok( group.find( "label" ).is( ".ui-button" ) );
|
||||
assert.hasClasses( group.find( "label" ), "ui-button" );
|
||||
|
||||
group = $( "<input type='checkbox' id='t7092b'><label for='t7092b'></label>" );
|
||||
group.filter( "input[type=checkbox]" ).button();
|
||||
ok( group.filter( "label" ).is( ".ui-button" ) );
|
||||
assert.hasClasses( group.filter( "label" ), "ui-button" );
|
||||
|
||||
group = $( "<span><input type='checkbox' id='t7092c'></span><label for='t7092c'></label>" );
|
||||
group.find( "input[type=checkbox]" ).button();
|
||||
ok( group.filter( "label" ).is( ".ui-button" ) );
|
||||
assert.hasClasses( group.filter( "label" ), "ui-button" );
|
||||
|
||||
group = $( "<span><input type='checkbox' id='t7092d'></span><span><label for='t7092d'></label></span>" );
|
||||
group.find( "input[type=checkbox]" ).button();
|
||||
ok( group.find( "label" ).is( ".ui-button" ) );
|
||||
assert.hasClasses( group.find( "label" ), "ui-button" );
|
||||
|
||||
group = $( "<input type='checkbox' id='t7092e'><span><label for='t7092e'></label></span>" );
|
||||
group.filter( "input[type=checkbox]" ).button();
|
||||
ok( group.find( "label" ).is( ".ui-button" ) );
|
||||
assert.hasClasses( group.find( "label" ), "ui-button" );
|
||||
});
|
||||
|
||||
test( "#5946 - buttonset should ignore buttons that are not :visible", function() {
|
||||
test( "#5946 - buttonset should ignore buttons that are not :visible", function( assert ) {
|
||||
expect( 2 );
|
||||
$( "#radio01" ).next().addBack().hide();
|
||||
var set = $( "#radio0" ).buttonset({ items: "input[type=radio]:visible" });
|
||||
ok( set.find( "label:eq(0)" ).is( ":not(.ui-button):not(.ui-corner-left)" ) );
|
||||
ok( set.find( "label:eq(1)" ).is( ".ui-button.ui-corner-left" ) );
|
||||
assert.hasClasses( set.find( "label:eq(1)" ), "ui-button ui-corner-left" );
|
||||
});
|
||||
|
||||
test( "#6262 - buttonset not applying ui-corner to invisible elements", function() {
|
||||
test( "#6262 - buttonset not applying ui-corner to invisible elements", function( assert ) {
|
||||
expect( 3 );
|
||||
$( "#radio0" ).hide();
|
||||
var set = $( "#radio0" ).buttonset();
|
||||
ok( set.find( "label:eq(0)" ).is( ".ui-button.ui-corner-left" ) );
|
||||
ok( set.find( "label:eq(1)" ).is( ".ui-button" ) );
|
||||
ok( set.find( "label:eq(2)" ).is( ".ui-button.ui-corner-right" ) );
|
||||
assert.hasClasses( set.find( "label:eq(0)" ), "ui-button ui-corner-left" );
|
||||
assert.hasClasses( set.find( "label:eq(1)" ), "ui-button" );
|
||||
assert.hasClasses( set.find( "label:eq(2)" ), "ui-button ui-corner-right" );
|
||||
|
||||
});
|
||||
|
||||
asyncTest( "Resetting a button's form should refresh the visual state of the button widget to match.", function() {
|
||||
asyncTest( "Resetting a button's form should refresh the visual state of the button widget to match.", function( assert ) {
|
||||
expect( 2 );
|
||||
var form = $( "<form>" +
|
||||
"<button></button>" +
|
||||
@ -176,7 +182,7 @@ asyncTest( "Resetting a button's form should refresh the visual state of the but
|
||||
checkbox = form.find( "input[type=checkbox]" ).button();
|
||||
|
||||
checkbox.prop( "checked", false ).button( "refresh" );
|
||||
ok( !checkbox.button( "widget" ).hasClass( "ui-state-active" ) );
|
||||
assert.lacksClasses( checkbox.button( "widget" ), "ui-state-active" );
|
||||
|
||||
form.get( 0 ).reset();
|
||||
|
||||
@ -185,38 +191,38 @@ asyncTest( "Resetting a button's form should refresh the visual state of the but
|
||||
button.remove();
|
||||
|
||||
setTimeout(function() {
|
||||
ok( checkbox.button( "widget" ).hasClass( "ui-state-active" ));
|
||||
assert.hasClasses( checkbox.button( "widget" ), "ui-state-active" );
|
||||
start();
|
||||
}, 1 );
|
||||
});
|
||||
|
||||
asyncTest( "#6711 Checkbox/Radiobutton do not Show Focused State when using Keyboard Navigation", function() {
|
||||
asyncTest( "#6711 Checkbox/Radiobutton do not Show Focused State when using Keyboard Navigation", function( assert ) {
|
||||
expect( 2 );
|
||||
var check = $( "#check" ).button(),
|
||||
label = $( "label[for='check']" );
|
||||
ok( !label.is( ".ui-state-focus" ) );
|
||||
assert.lacksClasses( label, "ui-state-focus" );
|
||||
check.focus();
|
||||
setTimeout(function() {
|
||||
ok( label.is( ".ui-state-focus" ) );
|
||||
assert.hasClasses( label, "ui-state-focus" );
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
||||
test( "#7534 - Button label selector works for ids with \":\"", function() {
|
||||
test( "#7534 - Button label selector works for ids with \":\"", function( assert ) {
|
||||
expect( 1 );
|
||||
var group = $( "<span><input type='checkbox' id='check:7534'><label for='check:7534'>Label</label></span>" );
|
||||
group.find( "input" ).button();
|
||||
ok( group.find( "label" ).is( ".ui-button" ), "Found an id with a :" );
|
||||
assert.hasClasses( group.find( "label" ), "ui-button" , "Found an id with a :" );
|
||||
});
|
||||
|
||||
asyncTest( "#9169 - Disabled button maintains ui-state-focus", function() {
|
||||
asyncTest( "#9169 - Disabled button maintains ui-state-focus", function( assert ) {
|
||||
expect( 2 );
|
||||
var element = $( "#button1" ).button();
|
||||
element[ 0 ].focus();
|
||||
setTimeout(function() {
|
||||
ok( element.hasClass( "ui-state-focus" ), "button has ui-state-focus" );
|
||||
assert.hasClasses( element, "ui-state-focus" );
|
||||
element.button( "disable" );
|
||||
ok( !element.hasClass( "ui-state-focus" ),
|
||||
assert.lacksClasses( element, "ui-state-focus",
|
||||
"button does not have ui-state-focus when disabled" );
|
||||
start();
|
||||
});
|
||||
|
@ -13,14 +13,14 @@ test("buttonset works with single-quote named elements (#7505)", function() {
|
||||
}).click();
|
||||
});
|
||||
|
||||
asyncTest( "when button loses focus, ensure active state is removed (#8559)", function() {
|
||||
asyncTest( "when button loses focus, ensure active state is removed (#8559)", function( assert ) {
|
||||
expect( 1 );
|
||||
|
||||
var element = $( "#button" ).button();
|
||||
|
||||
element.one( "keypress", function() {
|
||||
element.one( "blur", function() {
|
||||
ok( !element.is(".ui-state-active"), "button loses active state appropriately" );
|
||||
assert.lacksClasses( element, "ui-state-active", "button loses active state appropriately" );
|
||||
start();
|
||||
}).blur();
|
||||
});
|
||||
|
@ -5,21 +5,19 @@
|
||||
|
||||
module( "button: options" );
|
||||
|
||||
test( "disabled, explicit value", function() {
|
||||
expect( 9 );
|
||||
test( "disabled, explicit value", function( assert ) {
|
||||
expect( 7 );
|
||||
|
||||
var element = $( "#radio01" ).button({ disabled: false });
|
||||
deepEqual( element.button( "option", "disabled" ), false, "disabled option set to false" );
|
||||
deepEqual( element.prop( "disabled" ), false, "element is disabled" );
|
||||
|
||||
ok( !element.button( "widget" ).hasClass( "ui-state-disabled" ), "element gets ui-state-disabled" );
|
||||
ok( !element.button( "widget" ).hasClass( "ui-button-disabled" ), "element gets ui-button-disabled" );
|
||||
assert.lacksClasses( element.button( "widget" ), "ui-state-disabled ui-button-disabled" );
|
||||
|
||||
element = $( "#radio02" ).button({ disabled: true });
|
||||
|
||||
ok( element.button( "widget" ).hasClass( "ui-state-disabled" ), "element gets ui-state-disabled" );
|
||||
ok( !element.button( "widget" ).attr( "aria-disabled" ), "element does not get aria-disabled" );
|
||||
ok( element.button( "widget" ).hasClass( "ui-button-disabled" ), "element gets ui-button-disabled" );
|
||||
assert.hasClasses( element.button( "widget" ), "ui-button-disabled ui-state-disabled" );
|
||||
|
||||
deepEqual( element.button( "option", "disabled" ), true, "disabled option set to true" );
|
||||
deepEqual( element.prop( "disabled" ), true, "element is not disabled" );
|
||||
@ -38,7 +36,7 @@ test("disabled, null", function() {
|
||||
deepEqual(true, $("#radio02").prop("disabled"), "element is not disabled");
|
||||
});
|
||||
|
||||
test( "disabled, ui-state-active is removed unless checkbox or radio", function() {
|
||||
test( "disabled, ui-state-active is removed unless checkbox or radio", function( assert ) {
|
||||
expect( 12 );
|
||||
var elements = [
|
||||
$( "<input type='button'>" ),
|
||||
@ -59,15 +57,15 @@ test( "disabled, ui-state-active is removed unless checkbox or radio", function(
|
||||
}
|
||||
|
||||
element.trigger( "mousedown" );
|
||||
ok( buttonElement.hasClass( "ui-state-active" ),
|
||||
assert.hasClasses( buttonElement, "ui-state-active",
|
||||
"[" + elementType + "] has ui-state-active class after mousedown." );
|
||||
|
||||
element.button( "disable" );
|
||||
if ( element.is( "[type=checkbox], [type=radio]" ) ) {
|
||||
ok( buttonElement.hasClass( "ui-state-active" ),
|
||||
assert.hasClasses( buttonElement, "ui-state-active",
|
||||
"Disabled [" + elementType + "] has ui-state-active class." );
|
||||
} else {
|
||||
ok( !buttonElement.hasClass( "ui-state-active" ),
|
||||
assert.lacksClasses( buttonElement, "ui-state-active",
|
||||
"Disabled [" + elementType + "] does not have ui-state-active class." );
|
||||
}
|
||||
});
|
||||
@ -145,7 +143,7 @@ test("icons", function() {
|
||||
$("#button").button("destroy");
|
||||
});
|
||||
|
||||
test( "#5295 - button does not remove hoverstate if disabled" , function() {
|
||||
test( "#5295 - button does not remove hoverstate if disabled" , function( assert ) {
|
||||
expect( 1 );
|
||||
var btn = $("#button").button();
|
||||
btn.hover( function() {
|
||||
@ -153,7 +151,7 @@ test( "#5295 - button does not remove hoverstate if disabled" , function() {
|
||||
});
|
||||
btn.trigger( "mouseenter" );
|
||||
btn.trigger( "mouseleave" );
|
||||
ok( !btn.is( ".ui-state-hover") );
|
||||
assert.lacksClasses( btn, "ui-state-hover" );
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
|
Loading…
Reference in New Issue
Block a user