@@ -14,6 +14,13 @@ describe('dirPagination directive', function() {
14
14
beforeEach ( module ( 'angularUtils.directives.dirPagination' ) ) ;
15
15
beforeEach ( module ( 'templates-main' ) ) ;
16
16
17
+ // used to test the paginationTemplateProvider (see end of file)
18
+ var templateProvider ;
19
+ angular . module ( 'customTemplateTestApp' , [ ] ) ;
20
+ beforeEach ( module ( 'customTemplateTestApp' , function ( paginationTemplateProvider ) {
21
+ templateProvider = paginationTemplateProvider ;
22
+ } ) ) ;
23
+
17
24
beforeEach ( inject ( function ( $rootScope , _$compile_ , _$timeout_ ) {
18
25
19
26
$compile = _$compile_ ;
@@ -1141,6 +1148,52 @@ describe('dirPagination directive', function() {
1141
1148
expect ( getListItems ( $list2 ) ) . toEqual ( [ 'a' , 'b' , 'c' ] ) ;
1142
1149
} ) ;
1143
1150
1151
+ } ) ;
1152
+
1153
+ describe ( 'paginationTemplateProvider' , function ( ) {
1154
+
1155
+ beforeEach ( inject ( function ( $templateCache ) {
1156
+ $templateCache . put ( 'setPath_template' , '<div class="set-path-template"><span>Test Template</span>{{ pages.length }}</div>' ) ;
1157
+ $templateCache . put ( 'templateUrl_template' , '<div class="template-url-template"><span>Test TemplateUrl Template</span>{{ pages.length }}</div>' ) ;
1158
+ } ) ) ;
1159
+
1160
+ it ( 'should use the custom template specified by setPath()' , function ( ) {
1161
+ templateProvider . setPath ( 'setPath_template' ) ;
1162
+ compileElement ( myCollection , 10 ) ;
1163
+
1164
+ expect ( containingElement . find ( '.set-path-template' ) . html ( ) ) . toContain ( 'Test Template' ) ;
1165
+ } ) ;
1166
+
1167
+ it ( 'should use the custom template specified by setString()' , function ( ) {
1168
+ templateProvider . setString ( '<div class="set-string-template"><span>Test Template String</span>{{ pages.length }}</div>' ) ;
1169
+ compileElement ( myCollection , 10 ) ;
1170
+
1171
+ expect ( containingElement . find ( '.set-string-template' ) . html ( ) ) . toContain ( 'Test Template String' ) ;
1172
+ } ) ;
1173
+
1174
+ it ( 'should prioritize setString() if both path and string have been set' , function ( ) {
1175
+ templateProvider . setString ( '<div class="set-string-template"><span>Test Template String</span>{{ pages.length }}</div>' ) ;
1176
+ templateProvider . setPath ( 'setPath_template' ) ;
1177
+ compileElement ( myCollection , 10 ) ;
1178
+
1179
+ expect ( containingElement . find ( '.set-path-template' ) . html ( ) ) . toBeUndefined ( ) ;
1180
+ expect ( containingElement . find ( '.set-string-template' ) . html ( ) ) . toContain ( 'Test Template String' ) ;
1181
+ } ) ;
1182
+
1183
+ it ( 'should prioritize setString() over path and template-url attribute.' , function ( ) {
1184
+ templateProvider . setString ( '<div class="set-string-template"><span>Test Template String</span>{{ pages.length }}</div>' ) ;
1185
+ templateProvider . setPath ( 'setPath_template' ) ;
1186
+
1187
+ var html = '<ul class="list"><li dir-paginate="item in collection | itemsPerPage: itemsPerPage" current-page="currentPage">{{ item }}</li></ul> ' +
1188
+ '<dir-pagination-controls template-url="templateUrl_template"></dir-pagination-controls>' ;
1189
+ containingElement . append ( $compile ( html ) ( $scope ) ) ;
1190
+ $scope . $apply ( ) ;
1191
+
1192
+ expect ( containingElement . find ( '.set-path-template' ) . html ( ) ) . toBeUndefined ( ) ;
1193
+ expect ( containingElement . find ( '.template-url-template' ) . html ( ) ) . toBeUndefined ( ) ;
1194
+ expect ( containingElement . find ( '.set-string-template' ) . html ( ) ) . toContain ( 'Test Template String' ) ;
1195
+ } ) ;
1144
1196
1145
1197
} ) ;
1198
+
1146
1199
} ) ;
0 commit comments