aboutsummaryrefslogtreecommitdiffstats
path: root/tests/unit/checkboxradio/methods.js
diff options
context:
space:
mode:
authorAlexander Schmitz <arschmitz@gmail.com>2014-08-28 15:16:51 -0400
committerAlexander Schmitz <arschmitz@gmail.com>2015-10-07 10:57:59 -0400
commit25d0c857188c19347c869f803530289762199f92 (patch)
tree768afcbc456f878fb35e96546f468f9ffaa46b80 /tests/unit/checkboxradio/methods.js
parent02033262ee0fb1d9f33c361b3c2ddfa168604854 (diff)
downloadjquery-ui-25d0c857188c19347c869f803530289762199f92.tar.gz
jquery-ui-25d0c857188c19347c869f803530289762199f92.zip
Checkboxradio: Initial commit of new widget
Diffstat (limited to 'tests/unit/checkboxradio/methods.js')
-rw-r--r--tests/unit/checkboxradio/methods.js97
1 files changed, 97 insertions, 0 deletions
diff --git a/tests/unit/checkboxradio/methods.js b/tests/unit/checkboxradio/methods.js
new file mode 100644
index 000000000..f189c9eea
--- /dev/null
+++ b/tests/unit/checkboxradio/methods.js
@@ -0,0 +1,97 @@
+define( [
+ "jquery",
+ "ui/checkboxradio"
+], function( $ ) {
+
+module( "Checkboxradio: methods" );
+
+$.each( [ "checkbox", "radio" ], function( index, value ) {
+ test( value + ": refresh", function( assert ) {
+ var widget, icon,
+ checkbox = value === "checkbox",
+ input = $( "#" + value + "-method-refresh" );
+
+ expect( checkbox ? 11 : 8 );
+
+ input.checkboxradio();
+
+ widget = input.checkboxradio( "widget" );
+ icon = widget.find( ".ui-icon" );
+ strictEqual( icon.length, 1,
+ "There is initally one icon" );
+
+ icon.remove();
+ input.checkboxradio( "refresh" );
+ icon = widget.find( ".ui-icon" );
+ strictEqual( icon.length, 1,
+ "Icon is recreated on refresh if absent" );
+ assert.hasClasses( icon, "ui-icon-blank" );
+ if ( checkbox ) {
+ assert.lacksClasses( icon, "ui-icon-check" );
+ }
+ assert.lacksClasses( widget, "ui-checkboxradio-checked" );
+
+ input.prop( "checked", true );
+ input.checkboxradio( "refresh" );
+ if ( checkbox ) {
+ assert.hasClasses( icon, "ui-icon-check" );
+ }
+ assert[ !checkbox ? "hasClasses" : "lacksClasses" ]( icon, "ui-icon-blank" );
+ assert.hasClasses( widget, "ui-checkboxradio-checked" );
+
+ input.prop( "checked", false );
+ input.checkboxradio( "refresh" );
+ assert.hasClasses( icon, "ui-icon-blank" );
+ if ( checkbox ) {
+ assert.lacksClasses( icon, "ui-icon-check" );
+ }
+ assert.lacksClasses( widget, "ui-checkboxradio-checked" );
+ });
+
+ test( value + ": destroy", function( assert ){
+ expect( 1 );
+ assert.domEqual( "#" + value + "-method-destroy", function() {
+ $( "#" + value + "-method-destroy" ).checkboxradio().checkboxradio( "destroy" );
+ });
+ });
+
+ test( value + ": disable / enable", function( assert ) {
+ expect( 4 );
+ var input = $( "#" + value + "-method-disable" ),
+ widget = input.checkboxradio().checkboxradio( "widget" );
+
+ input.checkboxradio( "disable" );
+ assert.hasClasses( widget, "ui-state-disabled" );
+ strictEqual( input.is( ":disabled" ), true,
+ value + " is disabled when disable is called" );
+
+ input.checkboxradio( "enable" );
+ assert.lacksClasses( widget, "ui-state-disabled" );
+ strictEqual( input.is( ":disabled" ), false,
+ value + " has disabled prop removed when enable is called" );
+ });
+
+ test( value + ": widget returns the label", function(){
+ var input = $( "#" + value + "-method-refresh" ),
+ label = $( "#" + value + "-method-refresh-label" );
+
+ expect( 1 );
+
+ input.checkboxradio();
+ strictEqual( input.checkboxradio( "widget" )[ 0 ], label[ 0 ],
+ "widget method returns label" );
+ });
+
+} );
+
+test( "Input wrapped in a label preserved on refresh", function() {
+ var input = $( "#label-with-no-for" ).checkboxradio(),
+ element = input.checkboxradio( "widget" );
+
+ expect( 1 );
+
+ input.checkboxradio( "refresh" );
+ strictEqual( input.parent()[ 0 ], element[ 0 ], "Input preserved" );
+});
+
+} );