@@ -38,6 +38,70 @@ describe('Grid factory', function () {
38
38
$scope . $digest ( ) ;
39
39
}
40
40
41
+ describe ( 'scrollToIfNecessary' , function ( ) {
42
+ var renderContainers ;
43
+ var prevScrollTop = 100 ;
44
+ var viewportWidth = 100 ;
45
+ var viewportHeight = 100 ;
46
+ var canvasHeight = 360 ;
47
+ var canvasWidth = 100 ;
48
+
49
+ beforeEach ( function ( ) {
50
+ renderContainers = {
51
+ body : {
52
+ visibleRowCache : null ,
53
+ visibleColumnCache : null ,
54
+ prevScrollTop : prevScrollTop ,
55
+ headerHeight : 30 ,
56
+ getViewportWidth : jasmine . createSpy ( 'getViewportWidth' ) . and . callFake ( function ( ) { return viewportWidth ; } ) ,
57
+ getViewportHeight : jasmine . createSpy ( 'getViewportWidth' ) . and . callFake ( function ( ) { return viewportHeight ; } ) ,
58
+ getCanvasHeight : jasmine . createSpy ( 'getCanvasHeight' ) . and . callFake ( function ( ) { return canvasHeight ; } ) ,
59
+ getCanvasWidth : jasmine . createSpy ( 'getCanvasHeight' ) . and . callFake ( function ( ) { return canvasWidth ; } )
60
+ }
61
+ } ;
62
+ } ) ;
63
+
64
+ it ( 'should not scroll.y when scrollpercentage > 100% when row is less then top boundry' , function ( ) {
65
+ // row is less then the top boundary
66
+ var rowCache = [ ] ;
67
+ for ( var i = 0 ; i < 9 ; i ++ ) {
68
+ rowCache . push ( i ) ;
69
+ }
70
+ rowCache . push ( rows [ 1 ] ) ;
71
+ renderContainers . body . prevScrollTop = 100 ;
72
+ renderContainers . body . visibleRowCache = rowCache ;
73
+ renderContainers . body . visibleColumnCache = [ column ] ;
74
+ grid . renderContainers = renderContainers ;
75
+
76
+ // try to scroll to row 10
77
+ grid . scrollToIfNecessary ( rowCache [ 9 ] , column ) . then ( function ( scrollEvent ) {
78
+ expect ( scrollEvent ) . toBeUndefined ( ) ;
79
+ } ) ;
80
+
81
+ $scope . $apply ( ) ;
82
+ } ) ;
83
+
84
+ it ( 'should not scroll.y when scrollpercentage > 100% when row is more then top boundry' , function ( ) {
85
+ // row is more then the top boundary
86
+ var rowCache = [ ] ;
87
+ for ( var i = 0 ; i < 9 ; i ++ ) {
88
+ rowCache . push ( i ) ;
89
+ }
90
+ rowCache . push ( rows [ 1 ] ) ;
91
+ renderContainers . body . prevScrollTop = 300 ;
92
+ renderContainers . body . visibleRowCache = rowCache ;
93
+ renderContainers . body . visibleColumnCache = [ column ] ;
94
+ grid . renderContainers = renderContainers ;
95
+
96
+ // try to scroll to row 10
97
+ grid . scrollToIfNecessary ( rowCache [ 9 ] , column ) . then ( function ( scrollEvent ) {
98
+ expect ( scrollEvent ) . toBeUndefined ( ) ;
99
+ } ) ;
100
+
101
+ $scope . $apply ( ) ;
102
+ } ) ;
103
+ } ) ;
104
+
41
105
describe ( 'constructor' , function ( ) {
42
106
it ( 'should throw an exception if no id is provided' , function ( ) {
43
107
expect ( function ( ) {
0 commit comments