diff options
author | Scott González <scott.gonzalez@gmail.com> | 2015-04-23 15:11:41 -0400 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2015-05-14 20:39:51 -0400 |
commit | ad98cb167350b8d929b71bfeefc904c8964893dd (patch) | |
tree | 47288df5a25877efa1e41d60807e44f3eec68509 /tests/unit/form-reset-mixin | |
parent | 556b2710f0f09b76909b92c751edc3f4243fa5c0 (diff) | |
download | jquery-ui-ad98cb167350b8d929b71bfeefc904c8964893dd.tar.gz jquery-ui-ad98cb167350b8d929b71bfeefc904c8964893dd.zip |
Form Reset: Add form reset mixin
Fixes #12638
Closes gh-1555
Diffstat (limited to 'tests/unit/form-reset-mixin')
-rw-r--r-- | tests/unit/form-reset-mixin/all.html | 26 | ||||
-rw-r--r-- | tests/unit/form-reset-mixin/core.js | 95 | ||||
-rw-r--r-- | tests/unit/form-reset-mixin/form-reset-mixin.html | 26 |
3 files changed, 147 insertions, 0 deletions
diff --git a/tests/unit/form-reset-mixin/all.html b/tests/unit/form-reset-mixin/all.html new file mode 100644 index 000000000..9acf969e3 --- /dev/null +++ b/tests/unit/form-reset-mixin/all.html @@ -0,0 +1,26 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Form Reset Mixin Test Suite</title> + + <script src="../../../external/jquery/jquery.js"></script> + + <link rel="stylesheet" href="../../../external/qunit/qunit.css"> + <link rel="stylesheet" href="../../../external/qunit-composite/qunit-composite.css"> + <script src="../../../external/qunit/qunit.js"></script> + <script src="../../../external/qunit-composite/qunit-composite.js"></script> + <script src="../subsuite.js"></script> + + <script> + testAllVersions( "form-reset-mixin" ); + </script> +</head> +<body> + +<div id="qunit"></div> +<div id="qunit-fixture"> + +</div> +</body> +</html> diff --git a/tests/unit/form-reset-mixin/core.js b/tests/unit/form-reset-mixin/core.js new file mode 100644 index 000000000..14e804643 --- /dev/null +++ b/tests/unit/form-reset-mixin/core.js @@ -0,0 +1,95 @@ +define( [ + "jquery", + "lib/common", + "ui/widget", + "ui/form-reset-mixin" +], function( $, common ) { + +module( "widget factory", { + setup: function() { + $.widget( "ui.testWidget", [ $.ui.formResetMixin, { + _create: function() { + this._bindFormResetHandler(); + }, + _destroy: function() { + this._unbindFormResetHandler(); + }, + refresh: function() { + $.ui.testWidget.refreshed.push( this.element.attr( "id" ) ); + } + } ] ); + + $.ui.testWidget.refreshed = []; + }, + + teardown: function() { + delete $.ui.testWidget; + delete $.fn.testWidget; + } +}); + +common.testJshint( "form-reset-mixin" ); + +asyncTest( "form reset", function() { + expect( 2 ); + + var form = $( "#main" ); + var inputs = form.find( "input" ); + + inputs.testWidget(); + form.on( "reset", function() { + setTimeout(function() { + deepEqual( $.ui.testWidget.refreshed, [ "input1", "input2", "input3", "input4" ], + "All widgets are refreshed on form reset" ); + equal( form.data( "ui-form-reset-instances" ).length, 4, + "All widget instances are tracked against the form" ); + start(); + } ); + } ); + form[ 0 ].reset(); +} ); + +asyncTest( "destroy", function() { + expect( 2 ); + + var form = $( "#main" ); + var inputs = form.find( "input" ); + + inputs + .testWidget() + .eq( 1 ) + .testWidget( "destroy" ); + + form.on( "reset", function() { + setTimeout(function() { + deepEqual( $.ui.testWidget.refreshed, [ "input1", "input3", "input4" ], + "All widgets are refreshed on form reset" ); + deepEqual( form.data( "ui-form-reset-instances" ).length, 3, + "All widget instances are tracked against the form" ); + start(); + } ); + } ); + form[ 0 ].reset(); +} ); + +asyncTest( "destroy all", function() { + expect( 2 ); + + var form = $( "#main" ); + + form.find( "input" ) + .testWidget() + .testWidget( "destroy" ); + + form.on( "reset", function() { + setTimeout(function() { + deepEqual( $.ui.testWidget.refreshed, [], "No widgets are refreshed after destroy" ); + strictEqual( form.data( "ui-form-reset-instances" ), undefined, + "Form data is removed when the last widget instance is destroyed" ); + start(); + } ); + } ); + form[ 0 ].reset(); +} ); + +} ); diff --git a/tests/unit/form-reset-mixin/form-reset-mixin.html b/tests/unit/form-reset-mixin/form-reset-mixin.html new file mode 100644 index 000000000..a20e25d4a --- /dev/null +++ b/tests/unit/form-reset-mixin/form-reset-mixin.html @@ -0,0 +1,26 @@ +<!doctype html> +<html lang="en"> +<head> + <meta charset="utf-8"> + <title>jQuery UI Form Reset Mixin Test Suite</title> + + <script src="../../../external/requirejs/require.js"></script> + <script src="../../lib/css.js"></script> + <script src="../../lib/bootstrap.js" data-modules="core"> + </script> +</head> +<body> + +<div id="qunit"></div> +<div id="qunit-fixture"> + +<form id="main"> + <input id="input1"> + <input id="input2"> + <input id="input3"> + <input id="input4"> +</form> + +</div> +</body> +</html> |