1
1
describe ( 'pager 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/pager.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
$document = _$document_ ;
11
+ $templateCache = _$templateCache_ ;
11
12
element = $compile ( '<pager total-items="total" ng-model="currentPage"></pager>' ) ( $rootScope ) ;
12
13
$rootScope . $digest ( ) ;
13
14
} ) ) ;
@@ -23,7 +24,7 @@ describe('pager directive', function () {
23
24
function clickPaginationEl ( index ) {
24
25
getPaginationEl ( index ) . find ( 'a' ) . click ( ) ;
25
26
}
26
-
27
+
27
28
function getPaginationLinkEl ( elem , index ) {
28
29
return elem . find ( 'li' ) . eq ( index ) . find ( 'a' ) ;
29
30
}
@@ -51,6 +52,21 @@ describe('pager directive', function () {
51
52
expect ( getPaginationEl ( - 1 ) ) . toHaveClass ( 'next' ) ;
52
53
} ) ;
53
54
55
+ it ( 'exposes the controller on the template' , function ( ) {
56
+ $templateCache . put ( 'template/pagination/pager.html' , '<div>{{pagination.text}}</div>' ) ;
57
+
58
+ element = $compile ( '<pager></pager>' ) ( $rootScope ) ;
59
+ $rootScope . $digest ( ) ;
60
+
61
+ var ctrl = element . controller ( 'pager' ) ;
62
+ expect ( ctrl ) . toBeDefined ( ) ;
63
+
64
+ ctrl . text = 'foo' ;
65
+ $rootScope . $digest ( ) ;
66
+
67
+ expect ( element . html ( ) ) . toBe ( 'foo' ) ;
68
+ } ) ;
69
+
54
70
it ( 'disables the "previous" link if current page is 1' , function ( ) {
55
71
updateCurrentPage ( 1 ) ;
56
72
expect ( getPaginationEl ( 0 ) ) . toHaveClass ( 'disabled' ) ;
@@ -104,13 +120,13 @@ describe('pager directive', function () {
104
120
it ( 'should blur the "next" link after it has been clicked' , function ( ) {
105
121
$document . find ( 'body' ) . append ( element ) ;
106
122
var linkEl = getPaginationLinkEl ( element , - 1 ) ;
107
-
123
+
108
124
linkEl . focus ( ) ;
109
125
expect ( linkEl ) . toHaveFocus ( ) ;
110
-
126
+
111
127
linkEl . click ( ) ;
112
128
expect ( linkEl ) . not . toHaveFocus ( ) ;
113
-
129
+
114
130
element . remove ( ) ;
115
131
} ) ;
116
132
@@ -126,7 +142,16 @@ describe('pager directive', function () {
126
142
127
143
element . remove ( ) ;
128
144
} ) ;
129
-
145
+
146
+ it ( 'allows custom templates' , function ( ) {
147
+ $templateCache . put ( 'foo/bar.html' , '<div>baz</div>' ) ;
148
+
149
+ element = $compile ( '<pager template-url="foo/bar.html"></pager>' ) ( $rootScope ) ;
150
+ $rootScope . $digest ( ) ;
151
+
152
+ expect ( element . html ( ) ) . toBe ( 'baz' ) ;
153
+ } ) ;
154
+
130
155
describe ( '`items-per-page`' , function ( ) {
131
156
beforeEach ( function ( ) {
132
157
$rootScope . perpage = 5 ;
0 commit comments