From f375fd1300b4e08c0e71a073131260dfb8e5762f Mon Sep 17 00:00:00 2001 From: Amanpreet Singh Date: Sun, 3 Apr 2016 20:13:27 +0530 Subject: [PATCH] Button: Shift to no globals --- tests/unit/button/core.js | 16 ++-- tests/unit/button/deprecated.js | 101 ++++++++++++------------ tests/unit/button/events.js | 14 ++-- tests/unit/button/methods.js | 19 ++--- tests/unit/button/options.js | 135 ++++++++++++++++---------------- 5 files changed, 146 insertions(+), 139 deletions(-) diff --git a/tests/unit/button/core.js b/tests/unit/button/core.js index de26b0312..13bc94e33 100644 --- a/tests/unit/button/core.js +++ b/tests/unit/button/core.js @@ -1,23 +1,25 @@ define( [ + "qunit", "jquery", "ui/safe-active-element", "ui/widgets/button" -], function( $ ) { +], function( QUnit, $ ) { -module( "Button: core" ); +QUnit.module( "Button: core" ); -asyncTest( "Disabled button loses focus", function() { - expect( 2 ); +QUnit.test( "Disabled button loses focus", function( assert ) { + var ready = assert.async(); + assert.expect( 2 ); var element = $( "#button" ).button(); element.focus(); setTimeout( function() { - equal( element[ 0 ], $.ui.safeActiveElement( document ), "Button is focused" ); + assert.equal( element[ 0 ], $.ui.safeActiveElement( document ), "Button is focused" ); element.button( "disable" ); - notEqual( element[ 0 ], $.ui.safeActiveElement( document ), "Button has had focus removed" ); - start(); + assert.notEqual( element[ 0 ], $.ui.safeActiveElement( document ), "Button has had focus removed" ); + ready(); } ); } ); diff --git a/tests/unit/button/deprecated.js b/tests/unit/button/deprecated.js index fac02e2a6..81a0281b7 100644 --- a/tests/unit/button/deprecated.js +++ b/tests/unit/button/deprecated.js @@ -1,134 +1,135 @@ define( [ + "qunit", "jquery", "ui/widgets/button" -], function( $ ) { +], function( QUnit, $ ) { -module( "Button (deprecated): core" ); +QUnit.module( "Button (deprecated): core" ); -test( "Calling button on a checkbox input calls checkboxradio widget", function() { +QUnit.test( "Calling button on a checkbox input calls checkboxradio widget", function( assert ) { var checkbox = $( "#checkbox01" ); - expect( 2 ); + assert.expect( 2 ); checkbox.button(); - ok( !!checkbox.checkboxradio( "instance" ), + assert.ok( !!checkbox.checkboxradio( "instance" ), "Calling button on a checkbox creates checkboxradio instance" ); - ok( !checkbox.checkboxradio( "option", "icon" ), + assert.ok( !checkbox.checkboxradio( "option", "icon" ), "Calling button on a checkbox sets the checkboxradio icon option to false" ); } ); -test( "Calling buttonset calls controlgroup", function() { +QUnit.test( "Calling buttonset calls controlgroup", function( assert ) { var controlgroup = $( ".buttonset" ); - expect( 1 ); + assert.expect( 1 ); controlgroup.buttonset(); - ok( controlgroup.is( ":ui-controlgroup" ), "Calling buttonset creates controlgroup instance" ); + assert.ok( controlgroup.is( ":ui-controlgroup" ), "Calling buttonset creates controlgroup instance" ); } ); -module( "Button (deprecated): methods" ); +QUnit.module( "Button (deprecated): methods" ); -test( "destroy", function( assert ) { - expect( 1 ); +QUnit.test( "destroy", function( assert ) { + assert.expect( 1 ); assert.domEqual( "#checkbox02", function() { $( "#checkbox02" ).button().button( "destroy" ); } ); } ); -test( "refresh: Ensure disabled state is preserved correctly.", function() { - expect( 5 ); +QUnit.test( "refresh: Ensure disabled state is preserved correctly.", function( assert ) { + assert.expect( 5 ); var element = null; element = $( "#checkbox02" ); element.button( { disabled: true } ).button( "refresh" ); - ok( element.button( "option", "disabled" ), "Checkboxes should remain disabled after refresh" ); - ok( element.prop( "disabled" ), "Input remains disabled after refresh" ); + assert.ok( element.button( "option", "disabled" ), "Checkboxes should remain disabled after refresh" ); + assert.ok( element.prop( "disabled" ), "Input remains disabled after refresh" ); element = $( "#radio02" ); element.button( { disabled: true } ).button( "refresh" ); - ok( element.button( "option", "disabled" ), "Radio buttons should remain disabled after refresh" ); + assert.ok( element.button( "option", "disabled" ), "Radio buttons should remain disabled after refresh" ); element = $( "#checkbox02" ); element.button( { disabled: true } ).prop( "disabled", false ).button( "refresh" ); - ok( !element.button( "option", "disabled" ), "Changing a checkbox's disabled property should update the state after refresh." ); + assert.ok( !element.button( "option", "disabled" ), "Changing a checkbox's disabled property should update the state after refresh." ); element = $( "#radio02" ); element.button( { disabled: true } ).prop( "disabled", false ).button( "refresh" ); - ok( !element.button( "option", "disabled" ), "Changing a radio button's disabled property should update the state after refresh." ); + assert.ok( !element.button( "option", "disabled" ), "Changing a radio button's disabled property should update the state after refresh." ); } ); -module( "button (deprecated): options" ); +QUnit.module( "button (deprecated): options" ); -test( "Setting items option on buttonset sets the button properties on the items option", function() { - expect( 2 ); +QUnit.test( "Setting items option on buttonset sets the button properties on the items option", function( assert ) { + assert.expect( 2 ); var controlgroup = $( ".buttonset" ); controlgroup.buttonset( { items: "bar" } ); - equal( controlgroup.controlgroup( "option", "items.button" ), "bar", + assert.equal( controlgroup.controlgroup( "option", "items.button" ), "bar", "items.button set when setting items option on init on buttonset" ); controlgroup.buttonset( "option", "items", "foo" ); - equal( controlgroup.controlgroup( "option", "items.button" ), "foo", + assert.equal( controlgroup.controlgroup( "option", "items.button" ), "foo", "items.button set when setting items option on buttonset" ); } ); -test( "disabled, null", function() { - expect( 2 ); +QUnit.test( "disabled, null", function( assert ) { + assert.expect( 2 ); $( "#radio02" ).prop( "disabled", true ).button( { disabled: null } ); - deepEqual( $( "#radio02" ).button( "option", "disabled" ), true, + assert.deepEqual( $( "#radio02" ).button( "option", "disabled" ), true, "disabled option set to true" ); - deepEqual( true, $( "#radio02" ).prop( "disabled" ), "element is not disabled" ); + assert.deepEqual( true, $( "#radio02" ).prop( "disabled" ), "element is not disabled" ); } ); -test( "text / showLabel options proxied", function() { - expect( 8 ); +QUnit.test( "text / showLabel options proxied", function( assert ) { + assert.expect( 8 ); var button = $( "#button" ); button.button( { text: false, icon: "ui-icon-gear" } ); - equal( button.button( "option", "showLabel" ), false, + assert.equal( button.button( "option", "showLabel" ), false, "Setting the text option to false sets the showLabel option to false on init" ); button.button( "option", "showLabel", true ); - equal( button.button( "option", "text" ), true, + assert.equal( button.button( "option", "text" ), true, "Setting showLabel true with option method sets text option to true" ); button.button( "option", "text", false ); - equal( button.button( "option", "showLabel" ), false, + assert.equal( button.button( "option", "showLabel" ), false, "Setting text false with option method sets showLabel option to false" ); button.button( "option", "text", true ); - equal( button.button( "option", "showLabel" ), true, + assert.equal( button.button( "option", "showLabel" ), true, "Setting text true with option method sets showLabel option to true" ); button.button( "option", "showLabel", false ); - equal( button.button( "option", "text" ), false, + assert.equal( button.button( "option", "text" ), false, "Setting showLabel false with option method sets text option to false" ); button.button( "destroy" ); button.button( { text: true, icon: "ui-icon-gear" } ); - equal( button.button( "option", "showLabel" ), true, + assert.equal( button.button( "option", "showLabel" ), true, "Setting the text option to true sets the showLabel option to true on init" ); button.button( "destroy" ); button.button( { showLabel: true, icon: "ui-icon-gear" } ); - equal( button.button( "option", "text" ), true, + assert.equal( button.button( "option", "text" ), true, "Setting the showLabel option to true sets the text option to true on init" ); button.button( "destroy" ); button.button( { showLabel: false, icon: "ui-icon-gear" } ); - equal( button.button( "option", "text" ), false, + assert.equal( button.button( "option", "text" ), false, "Setting the showLabel option to false sets the text option to false on init" ); } ); -test( "icon / icons options properly proxied", function() { - expect( 10 ); +QUnit.test( "icon / icons options properly proxied", function( assert ) { + assert.expect( 10 ); var button = $( "#button" ); @@ -136,14 +137,14 @@ test( "icon / icons options properly proxied", function() { icon: "foo" } ); - equal( button.button( "option", "icons.primary" ), "foo", + assert.equal( button.button( "option", "icons.primary" ), "foo", "Icon option properly proxied on init" ); button.button( { icon: "bar" } ); - equal( button.button( "option", "icons.primary" ), "bar", + assert.equal( button.button( "option", "icons.primary" ), "bar", "Icon option properly proxied with option method" ); button.button( { @@ -152,9 +153,9 @@ test( "icon / icons options properly proxied", function() { } } ); - equal( button.button( "option", "icon" ), "foo", + assert.equal( button.button( "option", "icon" ), "foo", "Icons primary option properly proxied with option method" ); - equal( button.button( "option", "iconPosition" ), "beginning", + assert.equal( button.button( "option", "iconPosition" ), "beginning", "Icons primary option sets iconPosition option to beginning" ); button.button( { @@ -163,9 +164,9 @@ test( "icon / icons options properly proxied", function() { } } ); - equal( button.button( "option", "icon" ), "bar", + assert.equal( button.button( "option", "icon" ), "bar", "Icons secondary option properly proxied with option method" ); - equal( button.button( "option", "iconPosition" ), "end", + assert.equal( button.button( "option", "iconPosition" ), "end", "Icons secondary option sets iconPosition option to end" ); button.button( "destroy" ); @@ -176,9 +177,9 @@ test( "icon / icons options properly proxied", function() { } } ); - equal( button.button( "option", "icon" ), "foo", + assert.equal( button.button( "option", "icon" ), "foo", "Icons primary option properly proxied on init" ); - equal( button.button( "option", "iconPosition" ), "beginning", + assert.equal( button.button( "option", "iconPosition" ), "beginning", "Icons primary option sets iconPosition option to beginning on init" ); button.button( { @@ -187,9 +188,9 @@ test( "icon / icons options properly proxied", function() { } } ); - equal( button.button( "option", "icon" ), "bar", + assert.equal( button.button( "option", "icon" ), "bar", "Icons secondary option properly proxied on init" ); - equal( button.button( "option", "iconPosition" ), "end", + assert.equal( button.button( "option", "iconPosition" ), "end", "Icons secondary option sets iconPosition option to end on init" ); } ); diff --git a/tests/unit/button/events.js b/tests/unit/button/events.js index f780fb494..e8b5e01d6 100644 --- a/tests/unit/button/events.js +++ b/tests/unit/button/events.js @@ -1,18 +1,20 @@ define( [ + "qunit", "jquery", "ui/widgets/button" -], function( $ ) { +], function( QUnit, $ ) { -module( "Button: events" ); +QUnit.module( "Button: events" ); -asyncTest( "Anchor recieves click event when spacebar is pressed", function() { - expect( 1 ); +QUnit.test( "Anchor recieves click event when spacebar is pressed", function( assert ) { + var ready = assert.async(); + assert.expect( 1 ); var element = $( "#anchor-button" ).button(); element.on( "click", function( event ) { event.preventDefault(); - ok( true, "click occcured as a result of spacebar" ); - start(); + assert.ok( true, "click occcured as a result of spacebar" ); + ready(); } ); element.trigger( $.Event( "keyup", { keyCode: $.ui.keyCode.SPACE } ) ); diff --git a/tests/unit/button/methods.js b/tests/unit/button/methods.js index 09a91bbc0..823acee34 100644 --- a/tests/unit/button/methods.js +++ b/tests/unit/button/methods.js @@ -1,32 +1,33 @@ define( [ + "qunit", "jquery", "ui/widgets/button" -], function( $ ) { +], function( QUnit, $ ) { -module( "Button: methods" ); +QUnit.module( "Button: methods" ); -test( "destroy", function( assert ) { - expect( 1 ); +QUnit.test( "destroy", function( assert ) { + assert.expect( 1 ); assert.domEqual( "#button", function() { $( "#button" ).button().button( "destroy" ); } ); } ); -test( "refresh: Ensure disabled state is preserved correctly.", function() { - expect( 3 ); +QUnit.test( "refresh: Ensure disabled state is preserved correctly.", function( assert ) { + assert.expect( 3 ); var element = $( "" ); element.button( { disabled: true } ).button( "refresh" ); - ok( element.button( "option", "disabled" ), + assert.ok( element.button( "option", "disabled" ), "Anchor button 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" ), + assert.ok( !element.button( "option", "disabled" ), "Changing a