|
1 | 1 | describe('pagination directive', function () {
|
2 |
| - var $compile, $rootScope, $document, element; |
| 2 | + var $compile, $rootScope, $document, $templateCache, element; |
3 | 3 | beforeEach(module('ui.bootstrap.pagination'));
|
4 | 4 | beforeEach(module('template/pagination/pagination.html'));
|
5 |
| - beforeEach(inject(function(_$compile_, _$rootScope_, _$document_) { |
| 5 | + beforeEach(inject(function(_$compile_, _$rootScope_, _$document_, _$templateCache_) { |
6 | 6 | $compile = _$compile_;
|
7 | 7 | $rootScope = _$rootScope_;
|
8 | 8 | $rootScope.total = 47; // 5 pages
|
9 | 9 | $rootScope.currentPage = 3;
|
10 | 10 | $rootScope.disabled = false;
|
11 | 11 | $document = _$document_;
|
| 12 | + $templateCache = _$templateCache_; |
12 | 13 | element = $compile('<pagination total-items="total" ng-model="currentPage"></pagination>')($rootScope);
|
13 | 14 | $rootScope.$digest();
|
14 | 15 | }));
|
@@ -44,6 +45,33 @@ describe('pagination directive', function () {
|
44 | 45 | expect(element.hasClass('pagination')).toBe(true);
|
45 | 46 | });
|
46 | 47 |
|
| 48 | + it('exposes the controller to the template', function() { |
| 49 | + $templateCache.put('template/pagination/pagination.html', '<div>{{pagination.randomText}}</div>'); |
| 50 | + var scope = $rootScope.$new(); |
| 51 | + |
| 52 | + element = $compile('<pagination></pagination>')(scope); |
| 53 | + $rootScope.$digest(); |
| 54 | + |
| 55 | + var ctrl = element.controller('pagination'); |
| 56 | + |
| 57 | + expect(ctrl).toBeDefined(); |
| 58 | + |
| 59 | + ctrl.randomText = 'foo'; |
| 60 | + $rootScope.$digest(); |
| 61 | + |
| 62 | + expect(element.html()).toBe('foo'); |
| 63 | + }); |
| 64 | + |
| 65 | + it('allows custom templates', function() { |
| 66 | + $templateCache.put('foo/bar.html', '<div>baz</div>'); |
| 67 | + var scope = $rootScope.$new(); |
| 68 | + |
| 69 | + element = $compile('<pagination template-url="foo/bar.html"></pagination>')(scope); |
| 70 | + $rootScope.$digest(); |
| 71 | + |
| 72 | + expect(element.html()).toBe('baz'); |
| 73 | + }); |
| 74 | + |
47 | 75 | it('contains num-pages + 2 li elements', function() {
|
48 | 76 | expect(getPaginationBarSize()).toBe(7);
|
49 | 77 | expect(getPaginationEl(0).text()).toBe('Previous');
|
|
0 commit comments