@@ -138,4 +138,67 @@ test( "uniqueId / removeUniqueId", function() {
138138 equal ( el . attr ( "id" ) , null , "unique id has been removed from element" ) ;
139139} ) ;
140140
141+ test ( "Labels" , function ( ) {
142+ expect ( 2 ) ;
143+
144+ var expected = [ "1" , "2" , "3" , "4" , "5" , "6" , "7" , "8" , "9" , "10" ] ;
145+ var dom = $ ( "#labels-fragment" ) ;
146+
147+ function testLabels ( testType ) {
148+ var labels = dom . find ( "#test" ) . labels ( ) ;
149+ var found = labels . map ( function ( ) {
150+
151+ // Support: Core 1.9 Only
152+ // We use $.trim() because core 1.9.x silently fails when white space is present
153+ return $ . trim ( $ ( this ) . text ( ) ) ;
154+ } ) . get ( ) ;
155+
156+ deepEqual ( found , expected ,
157+ ".labels() finds all labels in " + testType + ", and sorts them in DOM order" ) ;
158+ }
159+
160+ testLabels ( "the DOM" ) ;
161+
162+ // Detach the dom to test on a fragment
163+ dom . detach ( ) ;
164+ testLabels ( "document fragments" ) ;
165+ } ) ;
166+
167+ ( function ( ) {
168+ var domAttached = $ ( "#form-test" ) ;
169+ var domDetached = $ ( "#form-test-detached" ) . detach ( ) ;
170+
171+ function testForm ( name , dom ) {
172+ var inputs = dom . find ( "input" ) ;
173+
174+ inputs . each ( function ( ) {
175+ var input = $ ( this ) ;
176+
177+ asyncTest ( name + this . id . replace ( / _ / g, " " ) , function ( ) {
178+ expect ( 1 ) ;
179+ var form = input . form ( ) ;
180+
181+ // If input has a form the value should reset to "" if not it should be "changed"
182+ var value = form . length ? "" : "changed" ;
183+
184+ input . val ( "changed" ) ;
185+
186+ // If there is a form we reset just that. If there is not a form, reset every form.
187+ // The idea is if a form is found resetting that form should reset the input.
188+ // If no form is found no amount of resetting should change the value.
189+ ( form . length ? form : dom . find ( "form" ) . addBack ( "form" ) ) . each ( function ( ) {
190+ this . reset ( ) ;
191+ } ) ;
192+
193+ setTimeout ( function ( ) {
194+ equal ( input . val ( ) , value , "Proper form found for #" + input . attr ( "id" ) ) ;
195+ start ( ) ;
196+ } ) ;
197+ } ) ;
198+ } ) ;
199+ }
200+
201+ testForm ( "form: attached: " , domAttached ) ;
202+ testForm ( "form: detached: " , domDetached ) ;
203+ } ) ( ) ;
141204} ) ;
0 commit comments