|
| 1 | +(function() { |
| 2 | + 'use strict'; |
| 3 | + |
| 4 | + describe('uiGridGridFooter', function() { |
| 5 | + var $compile, $document, $rootScope, $scope, data, grid; |
| 6 | + |
| 7 | + function recompile(template) { |
| 8 | + grid = angular.element(template); |
| 9 | + |
| 10 | + $compile(grid)($scope); |
| 11 | + $document[0].body.appendChild(grid[0]); |
| 12 | + |
| 13 | + $scope.$apply(); |
| 14 | + } |
| 15 | + |
| 16 | + beforeEach(function() { |
| 17 | + module('ui.grid'); |
| 18 | + module('ui.grid.treeView'); |
| 19 | + |
| 20 | + inject(function(_$compile_, _$document_, _$rootScope_) { |
| 21 | + $compile = _$compile_; |
| 22 | + $document = _$document_; |
| 23 | + $rootScope = _$rootScope_; |
| 24 | + }); |
| 25 | + |
| 26 | + $scope = $rootScope.$new(); |
| 27 | + |
| 28 | + data = [ |
| 29 | + {name: 'Bob', age: 35}, |
| 30 | + {name: 'Bill', age: 25}, |
| 31 | + {name: 'Sam', age: 17}, |
| 32 | + {name: 'Jane', age: 19} |
| 33 | + ]; |
| 34 | + |
| 35 | + $scope.gridOpts = { |
| 36 | + showGridFooter: true, |
| 37 | + data: data |
| 38 | + }; |
| 39 | + }); |
| 40 | + |
| 41 | + it('should compile the grid footer', function() { |
| 42 | + recompile('<div style="width: 500px; height: 300px" ui-grid="gridOpts"></div>'); |
| 43 | + expect(grid.find('.ui-grid-grid-footer').length).toEqual(1); |
| 44 | + grid.remove(); |
| 45 | + }); |
| 46 | + it('should display the total number of rows in the grid', function() { |
| 47 | + recompile('<div style="width: 500px; height: 300px" ui-grid="gridOpts"></div>'); |
| 48 | + expect(grid.find('.ui-grid-grid-footer').text()).toContain('Total Items: ' + $scope.gridOpts.data.length); |
| 49 | + grid.remove(); |
| 50 | + }); |
| 51 | + describe('when tree view is enabled', function() { |
| 52 | + beforeEach(function() { |
| 53 | + $scope.gridOpts.showTreeExpandNoChildren = true; |
| 54 | + for (var i = 1; i <= $scope.gridOpts.data.length; i ++) { |
| 55 | + data[i-1].$$treeLevel = i%2 === 0 ? 1 : 0; |
| 56 | + } |
| 57 | + recompile('<div style="width: 500px; height: 300px" ui-grid="gridOpts" ui-grid-tree-view></div>'); |
| 58 | + }); |
| 59 | + afterEach(function() { |
| 60 | + grid.remove(); |
| 61 | + }); |
| 62 | + it('should display how many items are showing', function() { |
| 63 | + expect(grid.find('.ui-grid-grid-footer').text()).toContain('(Showing Items: ' + $scope.gridOpts.data.length/2 + ')'); |
| 64 | + }); |
| 65 | + }); |
| 66 | + }); |
| 67 | +})(); |
0 commit comments