1- var createHtml = function ( settings ) {
1+ function createHtml ( settings ) {
22 var viewportStyle = ' style="height:' + ( settings . viewportHeight || 200 ) + 'px"' ;
33 var itemStyle = settings . itemHeight ? ' style="height:' + settings . itemHeight + 'px"' : '' ;
44 var bufferSize = settings . bufferSize ? ' buffer-size="' + settings . bufferSize + '"' : '' ;
@@ -14,38 +14,9 @@ var createHtml = function (settings) {
1414 template +
1515 '</div>' +
1616 '</div>' ;
17- } ;
17+ }
1818
19- var runTest = function ( scrollSettings , run , options ) {
20- inject ( function ( $rootScope , $compile , $window , $timeout ) {
21- var scroller = angular . element ( createHtml ( scrollSettings ) ) ;
22- var scope = $rootScope . $new ( ) ;
23-
24- //if (angular.element(document).find('body').find('div').children().length)
25- //debugger
26-
27- angular . element ( document ) . find ( 'body' ) . append ( scroller ) ;
28-
29- $compile ( scroller ) ( scope ) ;
30-
31- scope . $apply ( ) ;
32- $timeout . flush ( ) ;
33-
34- try {
35- run ( scroller , scope , $timeout ) ;
36- }
37- finally {
38- scroller . remove ( ) ;
39-
40- if ( options && typeof options . cleanupTest === 'function' ) {
41- options . cleanupTest ( scroller , scope , $timeout ) ;
42- }
43- }
44-
45- } ) ;
46- } ;
47-
48- var createGridHtml = function ( settings ) {
19+ function createGridHtml ( settings ) {
4920 var viewportStyle = ' style="height:' + ( settings . viewportHeight || 200 ) + 'px"' ;
5021 var columns = [ 'col0' , 'col1' , 'col2' , 'col3' ] ;
5122
@@ -67,16 +38,46 @@ var createGridHtml = function (settings) {
6738 '</tbody>' +
6839 '</table>' ;
6940 return html ;
41+ }
7042
71- } ;
43+ function finalize ( scroller , options , scope , $timeout ) {
44+ scroller . remove ( ) ;
7245
73- var runGridTest = function ( scrollSettings , run , options ) {
46+ if ( options && typeof options . cleanupTest === 'function' ) {
47+ options . cleanupTest ( scroller , scope , $timeout ) ;
48+ }
49+ }
50+
51+ function runTest ( scrollSettings , run , options ) {
7452 inject ( function ( $rootScope , $compile , $window , $timeout ) {
75- var scroller = angular . element ( createGridHtml ( scrollSettings ) ) ;
53+ var scroller = angular . element ( createHtml ( scrollSettings ) ) ;
7654 var scope = $rootScope . $new ( ) ;
7755
78- //if (angular.element(document).find('body').find('div').children().length)
79- //debugger
56+ angular . element ( document ) . find ( 'body' ) . append ( scroller ) ;
57+
58+ if ( options && options . scope ) {
59+ angular . extend ( scope , options . scope ) ;
60+ }
61+
62+ $compile ( scroller ) ( scope ) ;
63+
64+ scope . $apply ( ) ;
65+ $timeout . flush ( ) ;
66+
67+ try {
68+ run ( scroller , scope , $timeout ) ;
69+ }
70+ finally {
71+ finalize ( scroller , options , scope , $timeout ) ;
72+ }
73+
74+ } ) ;
75+ }
76+
77+ function runGridTest ( scrollSettings , run , options ) {
78+ inject ( function ( $rootScope , $compile , $window , $timeout ) {
79+ var scroller = angular . element ( createGridHtml ( scrollSettings ) ) ;
80+ var scope = $rootScope . $new ( ) ;
8081
8182 angular . element ( document ) . find ( 'body' ) . append ( scroller ) ;
8283 var head = angular . element ( scroller . children ( ) [ 0 ] ) ;
@@ -90,14 +91,9 @@ var runGridTest = function (scrollSettings, run, options) {
9091 try {
9192 run ( head , body , scope , $timeout ) ;
9293 } finally {
93- scroller . remove ( ) ;
94-
95- if ( options && typeof options . cleanupTest === 'function' ) {
96- options . cleanupTest ( scroller , scope , $timeout ) ;
97- }
94+ finalize ( scroller , options , scope , $timeout ) ;
9895 }
9996
10097 }
10198 ) ;
102- } ;
103-
99+ }
0 commit comments