From bde431bb449b1d957d4e0b736111ff342f2a919d Mon Sep 17 00:00:00 2001 From: Scott González Date: Tue, 7 Apr 2015 10:55:52 -0400 Subject: Tests: Rename files Ref gh-1528 --- tests/unit/button/button_common.js | 22 ---- tests/unit/button/button_core.js | 230 ------------------------------------ tests/unit/button/button_events.js | 36 ------ tests/unit/button/button_methods.js | 73 ------------ tests/unit/button/button_options.js | 157 ------------------------ tests/unit/button/common.js | 22 ++++ tests/unit/button/core.js | 230 ++++++++++++++++++++++++++++++++++++ tests/unit/button/events.js | 36 ++++++ tests/unit/button/methods.js | 73 ++++++++++++ tests/unit/button/options.js | 157 ++++++++++++++++++++++++ 10 files changed, 518 insertions(+), 518 deletions(-) delete mode 100644 tests/unit/button/button_common.js delete mode 100644 tests/unit/button/button_core.js delete mode 100644 tests/unit/button/button_events.js delete mode 100644 tests/unit/button/button_methods.js delete mode 100644 tests/unit/button/button_options.js create mode 100644 tests/unit/button/common.js create mode 100644 tests/unit/button/core.js create mode 100644 tests/unit/button/events.js create mode 100644 tests/unit/button/methods.js create mode 100644 tests/unit/button/options.js (limited to 'tests/unit/button') diff --git a/tests/unit/button/button_common.js b/tests/unit/button/button_common.js deleted file mode 100644 index d376f4f05..000000000 --- a/tests/unit/button/button_common.js +++ /dev/null @@ -1,22 +0,0 @@ -define( [ - "lib/common", - "ui/button" -], function( common ) { - -common.testWidget( "button", { - defaults: { - classes: {}, - disabled: null, - icons: { - primary: null, - secondary: null - }, - label: null, - text: true, - - // callbacks - create: null - } -}); - -} ); diff --git a/tests/unit/button/button_core.js b/tests/unit/button/button_core.js deleted file mode 100644 index 4bc8d9fe5..000000000 --- a/tests/unit/button/button_core.js +++ /dev/null @@ -1,230 +0,0 @@ -define( [ - "jquery", - "ui/button" -], function( $ ) { - -module("button: core"); - -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(); - assert.hasClasses( input, "ui-helper-hidden-accessible" ); - assert.hasClasses( label, "ui-button" ); -}); - -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(); - inputs.each(function() { - assert.hasClasses( this, "ui-helper-hidden-accessible" ); - }); - labels.each(function() { - assert.hasClasses( this, "ui-button" ); - }); -}); - -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(); - assertClasses(":eq(0)", ":eq(1)", ":eq(2)"); - - // click outside of forms - $("#radio0 .ui-button:eq(1)").click(); - assertClasses(":eq(1)", ":eq(1)", ":eq(2)"); - - // click in first form - $("#radio1 .ui-button:eq(0)").click(); - assertClasses(":eq(1)", ":eq(0)", ":eq(2)"); - - // click in second form - $("#radio2 .ui-button:eq(0)").click(); - assertClasses(":eq(1)", ":eq(0)", ":eq(0)"); -}); - -test( "radio groups - ignore elements with same name", function() { - expect( 1 ); - var form = $( "form:first" ), - radios = form.find( "[type=radio]" ).button(), - checkbox = $( "", { - type: "checkbox", - name: radios.attr( "name" ) - }); - - form.append( checkbox ); - radios.button( "refresh" ); - ok( true, "no exception from accessing button instance of checkbox" ); -}); - -test("input type submit, don't create child elements", function() { - expect( 2 ); - var input = $("#submit"); - deepEqual( input.children().length, 0 ); - input.button(); - deepEqual( input.children().length, 0 ); -}); - -test("buttonset", function( assert ) { - expect( 6 ); - var set = $("#radio1").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)") ); - ok( set.children("label:eq(1)").is(".ui-button:not(.ui-corner-all)") ); - ok( set.children("label:eq(2)").is(".ui-button.ui-corner-right:not(.ui-corner-all)") ); -}); - -test("buttonset (rtl)", function( assert ) { - expect( 6 ); - var set, - parent = $("#radio1").parent(); - // Set to rtl - parent.attr("dir", "rtl"); - - set = $("#radio1").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)") ); - ok( set.children("label:eq(1)").is(".ui-button:not(.ui-corner-all)") ); - ok( set.children("label:eq(2)").is(".ui-button.ui-corner-left:not(.ui-corner-all)") ); -}); - -// TODO: simulated click events don't behave like real click events in IE -// 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( 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" ); - assert.hasClasses( lbl, "ui-state-active" ); - }); - - // support: Opera - // Opera doesn't trigger a change event when this is done synchronously. - // This seems to be a side effect of another test, but until that can be - // tracked down, this delay will have to do. - setTimeout(function() { - $("#check2").button("widget").simulate("click"); - start(); - }, 1 ); - }); -} - -test( "#7092 - button creation that requires a matching label does not find label in all cases", function( assert ) { - expect( 5 ); - var group = $( "" ); - group.find( "input[type=checkbox]" ).button(); - assert.hasClasses( group.find( "label" ), "ui-button" ); - - group = $( "" ); - group.filter( "input[type=checkbox]" ).button(); - assert.hasClasses( group.filter( "label" ), "ui-button" ); - - group = $( "" ); - group.find( "input[type=checkbox]" ).button(); - assert.hasClasses( group.filter( "label" ), "ui-button" ); - - group = $( "" ); - group.find( "input[type=checkbox]" ).button(); - assert.hasClasses( group.find( "label" ), "ui-button" ); - - group = $( "" ); - group.filter( "input[type=checkbox]" ).button(); - assert.hasClasses( group.find( "label" ), "ui-button" ); -}); - -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)" ) ); - assert.hasClasses( set.find( "label:eq(1)" ), "ui-button ui-corner-left" ); -}); - -test( "#6262 - buttonset not applying ui-corner to invisible elements", function( assert ) { - expect( 3 ); - $( "#radio0" ).hide(); - var set = $( "#radio0" ).buttonset(); - 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( assert ) { - expect( 2 ); - var form = $( "
" + - "" + - "" + - "
" ), - button = form.find( "button" ).button(), - checkbox = form.find( "input[type=checkbox]" ).button(); - - checkbox.prop( "checked", false ).button( "refresh" ); - assert.lacksClasses( checkbox.button( "widget" ), "ui-state-active" ); - - form.get( 0 ).reset(); - - // #9213: If a button has been removed, refresh should not be called on it when - // its corresponding form is reset. - button.remove(); - - setTimeout(function() { - assert.hasClasses( checkbox.button( "widget" ), "ui-state-active" ); - start(); - }, 1 ); -}); - -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']" ); - assert.lacksClasses( label, "ui-state-focus" ); - check.focus(); - setTimeout(function() { - assert.hasClasses( label, "ui-state-focus" ); - start(); - }); -}); - -test( "#7534 - Button label selector works for ids with \":\"", function( assert ) { - expect( 1 ); - var group = $( "" ); - group.find( "input" ).button(); - assert.hasClasses( group.find( "label" ), "ui-button" , "Found an id with a :" ); -}); - -asyncTest( "#9169 - Disabled button maintains ui-state-focus", function( assert ) { - expect( 2 ); - var element = $( "#button1" ).button(); - element[ 0 ].focus(); - setTimeout(function() { - assert.hasClasses( element, "ui-state-focus" ); - element.button( "disable" ); - assert.lacksClasses( element, "ui-state-focus", - "button does not have ui-state-focus when disabled" ); - start(); - }); -}); - -} ); diff --git a/tests/unit/button/button_events.js b/tests/unit/button/button_events.js deleted file mode 100644 index ec930077c..000000000 --- a/tests/unit/button/button_events.js +++ /dev/null @@ -1,36 +0,0 @@ -define( [ - "jquery", - "ui/button" -], function( $ ) { - -module("button: events"); - -test("buttonset works with single-quote named elements (#7505)", function() { - expect( 1 ); - $("#radio3").buttonset(); - $("#radio33").click( function(){ - ok( true, "button clicks work with single-quote named elements" ); - }).click(); -}); - -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() { - assert.lacksClasses( element, "ui-state-active", "button loses active state appropriately" ); - start(); - }).blur(); - }); - - element.focus(); - setTimeout(function() { - element - .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ) - .simulate( "keypress", { keyCode: $.ui.keyCode.ENTER } ); - }); -}); - -} ); diff --git a/tests/unit/button/button_methods.js b/tests/unit/button/button_methods.js deleted file mode 100644 index be36096b2..000000000 --- a/tests/unit/button/button_methods.js +++ /dev/null @@ -1,73 +0,0 @@ -define( [ - "jquery", - "ui/button" -], function( $ ) { - -module("button: methods"); - -test("destroy", function( assert ) { - expect( 1 ); - assert.domEqual( "#button", function() { - $( "#button" ).button().button( "destroy" ); - }); -}); - -test( "refresh: Ensure disabled state is preserved correctly.", function() { - expect( 8 ); - - var element = $( "" ); - element.button({ disabled: true }).button( "refresh" ); - ok( element.button( "option", "disabled" ), "Anchor button should remain disabled after refresh" ); //See #8237 - - element = $( "
" ); - element.button({ disabled: true }).button( "refresh" ); - ok( element.button( "option", "disabled" ), "
buttons should remain disabled after refresh" ); - - element = $( "" ); - element.button( { disabled: true} ).button( "refresh" ); - ok( element.button( "option", "disabled" ), "" ); - element.button( { disabled: true} ).prop( "disabled", false ).button( "refresh" ); - ok( !element.button( "option", "disabled" ), "Changing a " ), - $( "" ), - $( "
" ), - $( "" ), - $( "" ) - ]; - - $.each( elements, function() { - var element = $( this ).first().button(), - buttonElement = element.button( "widget" ), - elementType = element.prop( "nodeName" ).toLowerCase(); - - if ( element.is( "input" ) ) { - elementType += ":" + element.attr( "type" ); - } - - element.trigger( "mousedown" ); - assert.hasClasses( buttonElement, "ui-state-active", - "[" + elementType + "] has ui-state-active class after mousedown." ); - - element.button( "disable" ); - if ( element.is( "[type=checkbox], [type=radio]" ) ) { - assert.hasClasses( buttonElement, "ui-state-active", - "Disabled [" + elementType + "] has ui-state-active class." ); - } else { - assert.lacksClasses( buttonElement, "ui-state-active", - "Disabled [" + elementType + "] does not have ui-state-active class." ); - } - }); -}); - -test("text false without icon", function() { - expect( 1 ); - $("#button").button({ - text: false - }); - ok( $("#button").is(".ui-button-text-only:not(.ui-button-icon-only)") ); - - $("#button").button("destroy"); -}); - -test("text false with icon", function() { - expect( 1 ); - $("#button").button({ - text: false, - icons: { - primary: "iconclass" - } - }); - ok( $("#button").is(".ui-button-icon-only:not(.ui-button-text):has(span.ui-icon.iconclass)") ); - - $("#button").button("destroy"); -}); - -test("label, default", function() { - expect( 2 ); - $("#button").button(); - deepEqual( $("#button").text(), "Label" ); - deepEqual( $( "#button").button( "option", "label" ), "Label" ); - - $("#button").button("destroy"); -}); - -test("label", function() { - expect( 2 ); - $("#button").button({ - label: "xxx" - }); - deepEqual( $("#button").text(), "xxx" ); - deepEqual( $("#button").button( "option", "label" ), "xxx" ); - - $("#button").button("destroy"); -}); - -test("label default with input type submit", function() { - expect( 2 ); - deepEqual( $("#submit").button().val(), "Label" ); - deepEqual( $("#submit").button( "option", "label" ), "Label" ); -}); - -test("label with input type submit", function() { - expect( 2 ); - var label = $("#submit").button({ - label: "xxx" - }).val(); - deepEqual( label, "xxx" ); - deepEqual( $("#submit").button( "option", "label" ), "xxx" ); -}); - -test("icons", function() { - expect( 1 ); - $("#button").button({ - text: false, - icons: { - primary: "iconclass", - secondary: "iconclass2" - } - }); - ok( $("#button").is(":has(span.ui-icon.ui-button-icon-primary.iconclass):has(span.ui-icon.ui-button-icon-secondary.iconclass2)") ); - - $("#button").button("destroy"); -}); - -test( "#5295 - button does not remove hoverstate if disabled" , function( assert ) { - expect( 1 ); - var btn = $("#button").button(); - btn.hover( function() { - btn.button( "disable" ); - }); - btn.trigger( "mouseenter" ); - btn.trigger( "mouseleave" ); - assert.lacksClasses( btn, "ui-state-hover" ); -}); - -} ); diff --git a/tests/unit/button/common.js b/tests/unit/button/common.js new file mode 100644 index 000000000..d376f4f05 --- /dev/null +++ b/tests/unit/button/common.js @@ -0,0 +1,22 @@ +define( [ + "lib/common", + "ui/button" +], function( common ) { + +common.testWidget( "button", { + defaults: { + classes: {}, + disabled: null, + icons: { + primary: null, + secondary: null + }, + label: null, + text: true, + + // callbacks + create: null + } +}); + +} ); diff --git a/tests/unit/button/core.js b/tests/unit/button/core.js new file mode 100644 index 000000000..4bc8d9fe5 --- /dev/null +++ b/tests/unit/button/core.js @@ -0,0 +1,230 @@ +define( [ + "jquery", + "ui/button" +], function( $ ) { + +module("button: core"); + +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(); + assert.hasClasses( input, "ui-helper-hidden-accessible" ); + assert.hasClasses( label, "ui-button" ); +}); + +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(); + inputs.each(function() { + assert.hasClasses( this, "ui-helper-hidden-accessible" ); + }); + labels.each(function() { + assert.hasClasses( this, "ui-button" ); + }); +}); + +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(); + assertClasses(":eq(0)", ":eq(1)", ":eq(2)"); + + // click outside of forms + $("#radio0 .ui-button:eq(1)").click(); + assertClasses(":eq(1)", ":eq(1)", ":eq(2)"); + + // click in first form + $("#radio1 .ui-button:eq(0)").click(); + assertClasses(":eq(1)", ":eq(0)", ":eq(2)"); + + // click in second form + $("#radio2 .ui-button:eq(0)").click(); + assertClasses(":eq(1)", ":eq(0)", ":eq(0)"); +}); + +test( "radio groups - ignore elements with same name", function() { + expect( 1 ); + var form = $( "form:first" ), + radios = form.find( "[type=radio]" ).button(), + checkbox = $( "", { + type: "checkbox", + name: radios.attr( "name" ) + }); + + form.append( checkbox ); + radios.button( "refresh" ); + ok( true, "no exception from accessing button instance of checkbox" ); +}); + +test("input type submit, don't create child elements", function() { + expect( 2 ); + var input = $("#submit"); + deepEqual( input.children().length, 0 ); + input.button(); + deepEqual( input.children().length, 0 ); +}); + +test("buttonset", function( assert ) { + expect( 6 ); + var set = $("#radio1").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)") ); + ok( set.children("label:eq(1)").is(".ui-button:not(.ui-corner-all)") ); + ok( set.children("label:eq(2)").is(".ui-button.ui-corner-right:not(.ui-corner-all)") ); +}); + +test("buttonset (rtl)", function( assert ) { + expect( 6 ); + var set, + parent = $("#radio1").parent(); + // Set to rtl + parent.attr("dir", "rtl"); + + set = $("#radio1").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)") ); + ok( set.children("label:eq(1)").is(".ui-button:not(.ui-corner-all)") ); + ok( set.children("label:eq(2)").is(".ui-button.ui-corner-left:not(.ui-corner-all)") ); +}); + +// TODO: simulated click events don't behave like real click events in IE +// 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( 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" ); + assert.hasClasses( lbl, "ui-state-active" ); + }); + + // support: Opera + // Opera doesn't trigger a change event when this is done synchronously. + // This seems to be a side effect of another test, but until that can be + // tracked down, this delay will have to do. + setTimeout(function() { + $("#check2").button("widget").simulate("click"); + start(); + }, 1 ); + }); +} + +test( "#7092 - button creation that requires a matching label does not find label in all cases", function( assert ) { + expect( 5 ); + var group = $( "" ); + group.find( "input[type=checkbox]" ).button(); + assert.hasClasses( group.find( "label" ), "ui-button" ); + + group = $( "" ); + group.filter( "input[type=checkbox]" ).button(); + assert.hasClasses( group.filter( "label" ), "ui-button" ); + + group = $( "" ); + group.find( "input[type=checkbox]" ).button(); + assert.hasClasses( group.filter( "label" ), "ui-button" ); + + group = $( "" ); + group.find( "input[type=checkbox]" ).button(); + assert.hasClasses( group.find( "label" ), "ui-button" ); + + group = $( "" ); + group.filter( "input[type=checkbox]" ).button(); + assert.hasClasses( group.find( "label" ), "ui-button" ); +}); + +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)" ) ); + assert.hasClasses( set.find( "label:eq(1)" ), "ui-button ui-corner-left" ); +}); + +test( "#6262 - buttonset not applying ui-corner to invisible elements", function( assert ) { + expect( 3 ); + $( "#radio0" ).hide(); + var set = $( "#radio0" ).buttonset(); + 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( assert ) { + expect( 2 ); + var form = $( "
" + + "" + + "" + + "
" ), + button = form.find( "button" ).button(), + checkbox = form.find( "input[type=checkbox]" ).button(); + + checkbox.prop( "checked", false ).button( "refresh" ); + assert.lacksClasses( checkbox.button( "widget" ), "ui-state-active" ); + + form.get( 0 ).reset(); + + // #9213: If a button has been removed, refresh should not be called on it when + // its corresponding form is reset. + button.remove(); + + setTimeout(function() { + assert.hasClasses( checkbox.button( "widget" ), "ui-state-active" ); + start(); + }, 1 ); +}); + +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']" ); + assert.lacksClasses( label, "ui-state-focus" ); + check.focus(); + setTimeout(function() { + assert.hasClasses( label, "ui-state-focus" ); + start(); + }); +}); + +test( "#7534 - Button label selector works for ids with \":\"", function( assert ) { + expect( 1 ); + var group = $( "" ); + group.find( "input" ).button(); + assert.hasClasses( group.find( "label" ), "ui-button" , "Found an id with a :" ); +}); + +asyncTest( "#9169 - Disabled button maintains ui-state-focus", function( assert ) { + expect( 2 ); + var element = $( "#button1" ).button(); + element[ 0 ].focus(); + setTimeout(function() { + assert.hasClasses( element, "ui-state-focus" ); + element.button( "disable" ); + assert.lacksClasses( element, "ui-state-focus", + "button does not have ui-state-focus when disabled" ); + start(); + }); +}); + +} ); diff --git a/tests/unit/button/events.js b/tests/unit/button/events.js new file mode 100644 index 000000000..ec930077c --- /dev/null +++ b/tests/unit/button/events.js @@ -0,0 +1,36 @@ +define( [ + "jquery", + "ui/button" +], function( $ ) { + +module("button: events"); + +test("buttonset works with single-quote named elements (#7505)", function() { + expect( 1 ); + $("#radio3").buttonset(); + $("#radio33").click( function(){ + ok( true, "button clicks work with single-quote named elements" ); + }).click(); +}); + +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() { + assert.lacksClasses( element, "ui-state-active", "button loses active state appropriately" ); + start(); + }).blur(); + }); + + element.focus(); + setTimeout(function() { + element + .simulate( "keydown", { keyCode: $.ui.keyCode.ENTER } ) + .simulate( "keypress", { keyCode: $.ui.keyCode.ENTER } ); + }); +}); + +} ); diff --git a/tests/unit/button/methods.js b/tests/unit/button/methods.js new file mode 100644 index 000000000..be36096b2 --- /dev/null +++ b/tests/unit/button/methods.js @@ -0,0 +1,73 @@ +define( [ + "jquery", + "ui/button" +], function( $ ) { + +module("button: methods"); + +test("destroy", function( assert ) { + expect( 1 ); + assert.domEqual( "#button", function() { + $( "#button" ).button().button( "destroy" ); + }); +}); + +test( "refresh: Ensure disabled state is preserved correctly.", function() { + expect( 8 ); + + var element = $( "" ); + element.button({ disabled: true }).button( "refresh" ); + ok( element.button( "option", "disabled" ), "Anchor button should remain disabled after refresh" ); //See #8237 + + element = $( "
" ); + element.button({ disabled: true }).button( "refresh" ); + ok( element.button( "option", "disabled" ), "
buttons should remain disabled after refresh" ); + + element = $( "" ); + element.button( { disabled: true} ).button( "refresh" ); + ok( element.button( "option", "disabled" ), "" ); + element.button( { disabled: true} ).prop( "disabled", false ).button( "refresh" ); + ok( !element.button( "option", "disabled" ), "Changing a " ), + $( "" ), + $( "
" ), + $( "" ), + $( "" ) + ]; + + $.each( elements, function() { + var element = $( this ).first().button(), + buttonElement = element.button( "widget" ), + elementType = element.prop( "nodeName" ).toLowerCase(); + + if ( element.is( "input" ) ) { + elementType += ":" + element.attr( "type" ); + } + + element.trigger( "mousedown" ); + assert.hasClasses( buttonElement, "ui-state-active", + "[" + elementType + "] has ui-state-active class after mousedown." ); + + element.button( "disable" ); + if ( element.is( "[type=checkbox], [type=radio]" ) ) { + assert.hasClasses( buttonElement, "ui-state-active", + "Disabled [" + elementType + "] has ui-state-active class." ); + } else { + assert.lacksClasses( buttonElement, "ui-state-active", + "Disabled [" + elementType + "] does not have ui-state-active class." ); + } + }); +}); + +test("text false without icon", function() { + expect( 1 ); + $("#button").button({ + text: false + }); + ok( $("#button").is(".ui-button-text-only:not(.ui-button-icon-only)") ); + + $("#button").button("destroy"); +}); + +test("text false with icon", function() { + expect( 1 ); + $("#button").button({ + text: false, + icons: { + primary: "iconclass" + } + }); + ok( $("#button").is(".ui-button-icon-only:not(.ui-button-text):has(span.ui-icon.iconclass)") ); + + $("#button").button("destroy"); +}); + +test("label, default", function() { + expect( 2 ); + $("#button").button(); + deepEqual( $("#button").text(), "Label" ); + deepEqual( $( "#button").button( "option", "label" ), "Label" ); + + $("#button").button("destroy"); +}); + +test("label", function() { + expect( 2 ); + $("#button").button({ + label: "xxx" + }); + deepEqual( $("#button").text(), "xxx" ); + deepEqual( $("#button").button( "option", "label" ), "xxx" ); + + $("#button").button("destroy"); +}); + +test("label default with input type submit", function() { + expect( 2 ); + deepEqual( $("#submit").button().val(), "Label" ); + deepEqual( $("#submit").button( "option", "label" ), "Label" ); +}); + +test("label with input type submit", function() { + expect( 2 ); + var label = $("#submit").button({ + label: "xxx" + }).val(); + deepEqual( label, "xxx" ); + deepEqual( $("#submit").button( "option", "label" ), "xxx" ); +}); + +test("icons", function() { + expect( 1 ); + $("#button").button({ + text: false, + icons: { + primary: "iconclass", + secondary: "iconclass2" + } + }); + ok( $("#button").is(":has(span.ui-icon.ui-button-icon-primary.iconclass):has(span.ui-icon.ui-button-icon-secondary.iconclass2)") ); + + $("#button").button("destroy"); +}); + +test( "#5295 - button does not remove hoverstate if disabled" , function( assert ) { + expect( 1 ); + var btn = $("#button").button(); + btn.hover( function() { + btn.button( "disable" ); + }); + btn.trigger( "mouseenter" ); + btn.trigger( "mouseleave" ); + assert.lacksClasses( btn, "ui-state-hover" ); +}); + +} ); -- cgit v1.2.3