@@ -64,6 +64,9 @@ export default Ember.Component.extend({
6464 */
6565 didInsertElement : function ( ) {
6666
67+ var route = this . get ( "currentRouteName" ) === 'index' ? '/' : this . get ( "currentRouteName" ) ;
68+ this . set ( "generatedScript" , 'visit("' + route + '");<br>' ) ;
69+
6770 var MutationObserver = window . MutationObserver || window . WebKitMutationObserver || window . MozMutationObserver ;
6871
6972 //listen to clicks on ember items, apart from
@@ -74,42 +77,44 @@ export default Ember.Component.extend({
7477 var currentNestedLevel = 0 ; //tracks the nesting level for mutations
7578
7679 /**
77- * This is a helper function extension of jquery to give us a dynamic path incase the user hasn't given an
78- * interactive element an ID. We then use this path to repeat the user action in a test case.
80+ * this is used for capturing text input fill-ins
7981 */
80- Ember . $ . fn . extend ( {
81- path : function ( ) {
82-
83- if ( this . length !== 1 ) {
84- throw 'Requires one element.' ;
85- }
86-
87- var path , node = this ;
88- //this is just to get the path if the user interacts with a non user given id object
89- //we stop at body as qunit tests find statement is relative to the #ember-testing div
90- while ( node . length && node [ 0 ] . localName !== 'body' ) {
91- var realNode = node [ 0 ] , name = realNode . localName ;
92- if ( ! name ) {
93- break ;
94- }
95- name = name . toLowerCase ( ) ;
96-
97- var parent = node . parent ( ) ;
98-
99- var siblings = parent . children ( name ) ;
100- if ( siblings . length > 1 ) {
101- name += ':eq(' + siblings . index ( realNode ) + ')' ;
82+ Ember . $ ( 'input' ) . on ( 'focusout' , function ( e ) {
83+
84+ if ( e . target . localName === 'input' && e . target . type === 'text' ) {
85+
86+ var $target = $ ( e . target ) ;
87+ var $emberTarget = $target . is ( emberSelector ) ? $target : $target . parent ( emberSelector ) ;
88+ if ( $emberTarget . length ) {
89+ // we don't want to output a click (#ember123) as this is not reliable
90+ var hasEmberIdRegex = / e m b e r [ \d ] + / ;
91+ if ( e . target . id && ! hasEmberIdRegex . test ( e . target . id ) ) {
92+ var pathPrint = "#" + e . target . id ;
93+ } else {
94+ //print the nasty DOM path instead, to avoid give your element its own id
95+ var pathPrint = $emberTarget . path ( ) ;
96+ }
97+
98+ var newTestPrint = 'fillIn("' + pathPrint + '", " ' + e . target . value + '");<br/>'
99+
100+ //add to existing tests
101+ self . set ( "generatedScript" , self . get ( "generatedScript" ) + newTestPrint ) ;
102+
103+ //wrap in <pre> block to make code well formatted
104+ self . set ( "renderedScript" , '<pre>' + self . get ( "generatedScript" ) + '</pre>' ) ;
105+ } else {
106+ return ;
102107 }
103-
104- path = name + ( path ? '>' + path : '' ) ;
105- node = parent ;
106108 }
107-
108- return path ;
109109 }
110- } ) ;
110+ ) ;
111+
111112 Ember . $ ( document ) . on ( 'click' , function ( e ) {
112113
114+ if ( e . target . localName === 'input' && e . target . type === 'text' ) {
115+ return ; //for text inputs we capture mouse out and use this to generate a fillIn test helper
116+ }
117+
113118 //clear this if not DOM mutations happen ()
114119 var cleanText = self . get ( "generatedScript" ) . replace ( self . get ( "MUTATIONS_PLACEHOLDER" ) , "" ) ;
115120 self . set ( "generatedScript" , cleanText ) ;
@@ -270,3 +275,39 @@ function filterDoNotRecordAndWhiteSpace(node) {
270275 var hasDoNotRecordClass = classListArray ? ( classListArray . indexOf ( "doNotRecord" ) !== - 1 ) : false ;
271276 return node . nodeType !== 3 && ! hasDoNotRecordClass ;
272277}
278+
279+ /**
280+ * This is a helper function extension of jquery to give us a dynamic path incase the user hasn't given an
281+ * interactive element an ID. We then use this path to repeat the user action in a test case.
282+ */
283+ Ember . $ . fn . extend ( {
284+ path : function ( ) {
285+
286+ if ( this . length !== 1 ) {
287+ throw 'Requires one element.' ;
288+ }
289+
290+ var path , node = this ;
291+ //this is just to get the path if the user interacts with a non user given id object
292+ //we stop at body as qunit tests find statement is relative to the #ember-testing div
293+ while ( node . length && node [ 0 ] . localName !== 'body' ) {
294+ var realNode = node [ 0 ] , name = realNode . localName ;
295+ if ( ! name ) {
296+ break ;
297+ }
298+ name = name . toLowerCase ( ) ;
299+
300+ var parent = node . parent ( ) ;
301+
302+ var siblings = parent . children ( name ) ;
303+ if ( siblings . length > 1 ) {
304+ name += ':eq(' + siblings . index ( realNode ) + ')' ;
305+ }
306+
307+ path = name + ( path ? '>' + path : '' ) ;
308+ node = parent ;
309+ }
310+
311+ return path ;
312+ }
313+ } ) ;
0 commit comments