1
1
describe ( 'ui.grid.autoResizeGrid' , function ( ) {
2
- var gridScope , gridElm , viewportElm , $scope , $compile , recompile , uiGridConstants ;
2
+ var gridScope , gridElm , viewportElm , $scope , $compile , recompile , uiGridConstants , $timeout ;
3
3
4
4
var data = [
5
5
{ "name" : "Ethel Price" , "gender" : "female" , "company" : "Enersol" } ,
@@ -11,8 +11,9 @@ describe('ui.grid.autoResizeGrid', function () {
11
11
beforeEach ( module ( 'ui.grid' ) ) ;
12
12
beforeEach ( module ( 'ui.grid.autoResize' ) ) ;
13
13
14
- beforeEach ( inject ( function ( _$compile_ , $rootScope , _uiGridConstants_ ) {
14
+ beforeEach ( inject ( function ( _$compile_ , _$timeout_ , $rootScope , _uiGridConstants_ ) {
15
15
$scope = $rootScope ;
16
+ $timeout = _$timeout_ ;
16
17
$compile = _$compile_ ;
17
18
uiGridConstants = _uiGridConstants_ ;
18
19
@@ -39,30 +40,27 @@ describe('ui.grid.autoResizeGrid', function () {
39
40
} ) ;
40
41
41
42
describe ( 'on grid element dimension change' , function ( ) {
42
-
43
- it ( 'adjusts the grid viewport size' , inject ( function ( $timeout ) {
44
- var w = $ ( viewportElm ) . width ( ) ;
43
+ var w ;
44
+ beforeEach ( function ( done ) {
45
+ w = $ ( viewportElm ) . width ( ) ;
45
46
var h = $ ( viewportElm ) . height ( ) ;
46
47
47
- runs ( function ( ) {
48
- $ ( gridElm ) . width ( 600 ) ;
49
- } ) ;
50
-
51
- waits ( 300 ) ;
52
-
53
- runs ( function ( ) {
54
- var newW = $ ( viewportElm ) . width ( ) ;
55
-
56
- expect ( newW ) . toBeGreaterThan ( w ) ;
57
- } ) ;
58
- } ) ) ;
48
+ $ ( gridElm ) . width ( 600 ) ;
49
+ $scope . $digest ( ) ;
50
+ setTimeout ( done , 300 ) ;
51
+ } ) ;
52
+ it ( 'adjusts the grid viewport size' , function ( ) {
53
+ var newW = $ ( viewportElm ) . width ( ) ;
54
+ expect ( newW ) . toBeGreaterThan ( w ) ;
55
+ } ) ;
59
56
} ) ;
60
57
61
58
// Rebuild the grid as having 100% width and being in a 400px wide container, then change the container width to 500px and make sure it adjusts
62
59
describe ( 'on grid container dimension change' , function ( ) {
63
60
var gridContainerElm ;
61
+ var w ;
64
62
65
- beforeEach ( function ( ) {
63
+ beforeEach ( function ( done ) {
66
64
angular . element ( gridElm ) . remove ( ) ;
67
65
68
66
gridContainerElm = angular . element ( '<div style="width: 400px"><div style="width: 100%; height: 300px" ui-grid="gridOpts" ui-grid-auto-resize></div></div>' ) ;
@@ -73,24 +71,20 @@ describe('ui.grid.autoResizeGrid', function () {
73
71
gridElm = gridContainerElm . find ( '[ui-grid]' ) ;
74
72
75
73
viewportElm = $ ( gridElm ) . find ( '.ui-grid-viewport' ) ;
76
- } ) ;
77
74
78
- it ( 'adjusts the grid viewport size' , inject ( function ( $timeout ) {
79
- var w = $ ( viewportElm ) . width ( ) ;
75
+ w = $ ( viewportElm ) . width ( ) ;
80
76
var h = $ ( viewportElm ) . height ( ) ;
81
77
82
- runs ( function ( ) {
83
- $ ( gridContainerElm ) . width ( 500 ) ;
84
- } ) ;
85
-
86
- waits ( 300 ) ;
78
+ $ ( gridContainerElm ) . width ( 500 ) ;
79
+ $scope . $digest ( ) ;
80
+ setTimeout ( done , 300 ) ;
81
+ } ) ;
87
82
88
- runs ( function ( ) {
89
- var newW = $ ( viewportElm ) . width ( ) ;
83
+ it ( 'adjusts the grid viewport size' , function ( ) {
84
+ var newW = $ ( viewportElm ) . width ( ) ;
90
85
91
- expect ( newW ) . toBeGreaterThan ( w ) ;
92
- } ) ;
93
- } ) ) ;
86
+ expect ( newW ) . toBeGreaterThan ( w ) ;
87
+ } ) ;
94
88
} ) ;
95
89
96
- } ) ;
90
+ } ) ;
0 commit comments