From 803eaf29f732a68793b806356096fe849b9f470b Mon Sep 17 00:00:00 2001 From: Alexander Schmitz Date: Sun, 26 Apr 2015 23:38:21 -0400 Subject: Core: Add $.fn.labels, $.fn.form, and $.ui.escapeSelector methods $.fn.labels and $.fn.form mimic the native labels and form properties $.ui.escapeSelector is for escaping attributes and urls for use as selectors Closes gh-1546 --- tests/unit/core/core.html | 77 +++++++++++++++++++++++++++++++++++++++++++++ tests/unit/core/core.js | 63 +++++++++++++++++++++++++++++++++++++ tests/unit/core/selector.js | 7 +++++ 3 files changed, 147 insertions(+) (limited to 'tests/unit') diff --git a/tests/unit/core/core.html b/tests/unit/core/core.html index 354fd8b8e..366eecebe 100644 --- a/tests/unit/core/core.html +++ b/tests/unit/core/core.html @@ -108,6 +108,83 @@
+
+ +
+
+
+ + + +
+ +
+
+
+
+ +
+
+
+
+
+
+
+ + + +
+ +
+
+
+
+ + +
+
+
+
+
+ +
+ + + +
+ + +
+ + +
+
+ + +
+
+
+ + + +
+ + +
+
+ + +
diff --git a/tests/unit/core/core.js b/tests/unit/core/core.js index e50826e4d..ac9f28e00 100644 --- a/tests/unit/core/core.js +++ b/tests/unit/core/core.js @@ -138,4 +138,67 @@ test( "uniqueId / removeUniqueId", function() { equal( el.attr( "id" ), null, "unique id has been removed from element" ); }); +test( "Labels", function() { + expect( 2 ); + + var expected = [ "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ]; + var dom = $( "#labels-fragment" ); + + function testLabels( testType ) { + var labels = dom.find( "#test" ).labels(); + var found = labels.map( function() { + + // Support: Core 1.9 Only + // We use $.trim() because core 1.9.x silently fails when white space is present + return $.trim( $( this ).text() ); + } ).get(); + + deepEqual( found, expected, + ".labels() finds all labels in " + testType + ", and sorts them in DOM order" ); + } + + testLabels( "the DOM" ); + + // Detach the dom to test on a fragment + dom.detach(); + testLabels( "document fragments" ); +} ); + +( function() { + var domAttached = $( "#form-test" ); + var domDetached = $( "#form-test-detached" ).detach(); + + function testForm( name, dom ) { + var inputs = dom.find( "input" ); + + inputs.each( function() { + var input = $( this ); + + asyncTest( name + this.id.replace( /_/g, " " ), function() { + expect( 1 ); + var form = input.form(); + + // If input has a form the value should reset to "" if not it should be "changed" + var value = form.length ? "" : "changed"; + + input.val( "changed" ); + + // If there is a form we reset just that. If there is not a form, reset every form. + // The idea is if a form is found resetting that form should reset the input. + // If no form is found no amount of resetting should change the value. + ( form.length ? form : dom.find( "form" ).addBack( "form" ) ).each( function() { + this.reset(); + } ); + + setTimeout( function() { + equal( input.val(), value, "Proper form found for #" + input.attr( "id" ) ); + start(); + } ); + } ); + } ); + } + + testForm( "form: attached: ", domAttached ); + testForm( "form: detached: ", domDetached ); +} )(); } ); diff --git a/tests/unit/core/selector.js b/tests/unit/core/selector.js index 39b94344b..ff4bb064a 100644 --- a/tests/unit/core/selector.js +++ b/tests/unit/core/selector.js @@ -254,4 +254,11 @@ test( "tabbable - dimensionless parent with overflow", function() { isTabbable( "#dimensionlessParent", "input" ); }); +test( "escapeSelector", function() { + expect( 1 ); + + equal( $( "#" + $.ui.escapeSelector( "weird-['x']-id" ) ).length, 1, + "properly escapes selectors to use as an id" ); +} ); + } ); -- cgit v1.2.3