@@ -339,3 +339,67 @@ window.dump = function() {
339339 return angular . mock . dump ( arg ) ;
340340 } ) ) ;
341341} ;
342+
343+ function getInputCompileHelper ( currentSpec ) {
344+
345+ var helper = { } ;
346+
347+ module ( function ( $compileProvider ) {
348+ $compileProvider . directive ( 'attrCapture' , function ( ) {
349+ return function ( scope , element , $attrs ) {
350+ helper . attrs = $attrs ;
351+ } ;
352+ } ) ;
353+ } ) ;
354+
355+ inject ( function ( $compile , $rootScope , $sniffer ) {
356+
357+ helper . compileInput = function ( inputHtml , mockValidity , scope ) {
358+
359+ scope = helper . scope = scope || $rootScope ;
360+
361+ // Create the input element and dealoc when done
362+ helper . inputElm = jqLite ( inputHtml ) ;
363+
364+ // Set up mock validation if necessary
365+ if ( isObject ( mockValidity ) ) {
366+ VALIDITY_STATE_PROPERTY = 'ngMockValidity' ;
367+ helper . inputElm . prop ( VALIDITY_STATE_PROPERTY , mockValidity ) ;
368+ currentSpec . after ( function ( ) {
369+ VALIDITY_STATE_PROPERTY = 'validity' ;
370+ } ) ;
371+ }
372+
373+ // Create the form element and dealoc when done
374+ helper . formElm = jqLite ( '<form name="form"></form>' ) ;
375+ helper . formElm . append ( helper . inputElm ) ;
376+
377+ // Compile the lot and return the input element
378+ $compile ( helper . formElm ) ( scope ) ;
379+
380+ spyOn ( scope . form , '$addControl' ) . andCallThrough ( ) ;
381+ spyOn ( scope . form , '$$renameControl' ) . andCallThrough ( ) ;
382+
383+ scope . $digest ( ) ;
384+
385+ return helper . inputElm ;
386+ } ;
387+
388+ helper . changeInputValueTo = function ( value ) {
389+ helper . inputElm . val ( value ) ;
390+ browserTrigger ( helper . inputElm , $sniffer . hasEvent ( 'input' ) ? 'input' : 'change' ) ;
391+ } ;
392+
393+ helper . changeGivenInputTo = function ( inputElm , value ) {
394+ inputElm . val ( value ) ;
395+ browserTrigger ( inputElm , $sniffer . hasEvent ( 'input' ) ? 'input' : 'change' ) ;
396+ } ;
397+
398+ helper . dealoc = function ( ) {
399+ dealoc ( helper . inputElm ) ;
400+ dealoc ( helper . formElm ) ;
401+ } ;
402+ } ) ;
403+
404+ return helper ;
405+ }
0 commit comments