1
1
describe ( 'GridColumn factory' , function ( ) {
2
- var $q , $scope , cols , grid , gridCol , Grid , GridColumn , gridClassFactory , GridRenderContainer , uiGridConstants ;
2
+ var $q , $scope , cols , grid , gridCol , Grid , GridColumn , gridClassFactory , GridRenderContainer , uiGridConstants , $httpBackend ;
3
3
4
4
beforeEach ( module ( 'ui.grid' ) ) ;
5
5
6
6
function buildCols ( ) {
7
- grid . buildColumns ( ) ;
7
+ return grid . buildColumns ( ) ;
8
8
}
9
9
10
10
11
- beforeEach ( inject ( function ( _$q_ , _$rootScope_ , _Grid_ , _GridColumn_ , _gridClassFactory_ , _GridRenderContainer_ , _uiGridConstants_ ) {
11
+ beforeEach ( inject ( function ( _$q_ , _$rootScope_ , _Grid_ , _GridColumn_ , _gridClassFactory_ , _GridRenderContainer_ , _uiGridConstants_ , _$httpBackend_ ) {
12
12
$q = _$q_ ;
13
13
$scope = _$rootScope_ ;
14
14
Grid = _Grid_ ;
15
15
GridColumn = _GridColumn_ ;
16
16
gridClassFactory = _gridClassFactory_ ;
17
17
GridRenderContainer = _GridRenderContainer_ ;
18
18
uiGridConstants = _uiGridConstants_ ;
19
+ $httpBackend = _$httpBackend_ ;
19
20
20
21
cols = [
21
22
{ field : 'firstName' }
@@ -220,4 +221,113 @@ describe('GridColumn factory', function () {
220
221
} ) ;
221
222
} ) ;
222
223
224
+ describe ( 'getCompiledElementFn()' , function ( ) {
225
+ var col ;
226
+
227
+ beforeEach ( function ( ) {
228
+ col = grid . columns [ 0 ] ;
229
+ } ) ;
230
+
231
+ it ( 'should return a promise' , function ( ) {
232
+ expect ( col . getCompiledElementFn ( ) . hasOwnProperty ( 'then' ) ) . toBe ( true ) ;
233
+ } ) ;
234
+
235
+ it ( 'should return a promise that is resolved when the cellTemplate is compiled' , function ( ) {
236
+ var resolved = false ;
237
+
238
+ runs ( function ( ) {
239
+ buildCols ( ) . then ( function ( ) {
240
+ grid . preCompileCellTemplates ( ) ;
241
+ } ) ;
242
+ } ) ;
243
+
244
+ runs ( function ( ) {
245
+ col . getCompiledElementFn ( ) . then ( function ( ) {
246
+ resolved = true ;
247
+ } ) ;
248
+
249
+ $scope . $digest ( ) ;
250
+ } ) ;
251
+
252
+ // $scope.$digest();
253
+
254
+ runs ( function ( ) {
255
+ expect ( resolved ) . toBe ( true ) ;
256
+ } ) ;
257
+ } ) ;
258
+
259
+ it ( 'should return a promise that is resolved when a URL-based cellTemplate is available' , function ( ) {
260
+ var resolved = false ;
261
+
262
+ var url = 'http://www.a-really-fake-url.com/template.html' ;
263
+ cols [ 0 ] . cellTemplate = url ;
264
+
265
+ $httpBackend . when ( 'GET' , url ) . respond ( '<div>foo</div>' ) ;
266
+
267
+ runs ( function ( ) {
268
+ buildCols ( ) . then ( function ( ) {
269
+ grid . preCompileCellTemplates ( ) ;
270
+ } ) ;
271
+
272
+ col . getCompiledElementFn ( ) . then ( function ( ) {
273
+ resolved = true ;
274
+ } ) ;
275
+
276
+ expect ( resolved ) . toBe ( false ) ;
277
+
278
+ $httpBackend . flush ( ) ;
279
+ } ) ;
280
+
281
+ runs ( function ( ) {
282
+ $scope . $digest ( ) ;
283
+ } ) ;
284
+
285
+ runs ( function ( ) {
286
+ expect ( resolved ) . toBe ( true ) ;
287
+ } ) ;
288
+ } ) ;
289
+ } ) ;
290
+
291
+ describe ( 'getCellTemplate()' , function ( ) {
292
+ var col ;
293
+
294
+ beforeEach ( function ( ) {
295
+ col = grid . columns [ 0 ] ;
296
+ } ) ;
297
+
298
+ it ( 'should return a promise' , function ( ) {
299
+ expect ( col . getCellTemplate ( ) . hasOwnProperty ( 'then' ) ) . toBe ( true ) ;
300
+ } ) ;
301
+
302
+ it ( 'should return a promise that is resolved when a URL-based cellTemplate is available' , function ( ) {
303
+ var resolved = false ;
304
+
305
+ var url = 'http://www.a-really-fake-url.com/template.html' ;
306
+ cols [ 0 ] . cellTemplate = url ;
307
+
308
+ $httpBackend . when ( 'GET' , url ) . respond ( '<div>foo</div>' ) ;
309
+
310
+ runs ( function ( ) {
311
+ buildCols ( ) . then ( function ( ) {
312
+ grid . preCompileCellTemplates ( ) ;
313
+ } ) ;
314
+
315
+ col . getCellTemplate ( ) . then ( function ( ) {
316
+ resolved = true ;
317
+ } ) ;
318
+
319
+ expect ( resolved ) . toBe ( false ) ;
320
+
321
+ $httpBackend . flush ( ) ;
322
+ } ) ;
323
+
324
+ runs ( function ( ) {
325
+ $scope . $digest ( ) ;
326
+ } ) ;
327
+
328
+ runs ( function ( ) {
329
+ expect ( resolved ) . toBe ( true ) ;
330
+ } ) ;
331
+ } ) ;
332
+ } ) ;
223
333
} ) ;
0 commit comments