Added tests for pagination component
diff --git a/views/ngXosLib/xosHelpers/spec/csrftoken.test.js b/views/ngXosLib/xosHelpers/spec/csrftoken.test.js
index 200014d..8901bde 100644
--- a/views/ngXosLib/xosHelpers/spec/csrftoken.test.js
+++ b/views/ngXosLib/xosHelpers/spec/csrftoken.test.js
@@ -34,6 +34,7 @@
httpBackend.when('POST', 'http://example.com', null, function(headers) {
expect(headers['X-CSRFToken']).toBe(fakeToken);
done();
+ return headers;
}).respond(200, {name: 'example' });
http.post('http://example.com');
diff --git a/views/ngXosLib/xosHelpers/spec/noHyperlinks.test.js b/views/ngXosLib/xosHelpers/spec/noHyperlinks.test.js
index a3646e3..7b6e9d0 100644
--- a/views/ngXosLib/xosHelpers/spec/noHyperlinks.test.js
+++ b/views/ngXosLib/xosHelpers/spec/noHyperlinks.test.js
@@ -12,7 +12,7 @@
describe('The xos.helper module', function(){
describe('The NoHyperlinks factory', () => {
- let httpProviderObj, httpBackend, http, noHyperlinks;
+ let httpProviderObj, noHyperlinks;
beforeEach(() => {
module(
@@ -23,9 +23,7 @@
}
);
- inject(function (_$httpBackend_, _$http_, _NoHyperlinks_) {
- httpBackend = _$httpBackend_;
- http = _$http_;
+ inject(function (_NoHyperlinks_) {
noHyperlinks = _NoHyperlinks_
});
diff --git a/views/ngXosLib/xosHelpers/spec/ui/pagination.test.js b/views/ngXosLib/xosHelpers/spec/ui/pagination.test.js
new file mode 100644
index 0000000..a8a7482
--- /dev/null
+++ b/views/ngXosLib/xosHelpers/spec/ui/pagination.test.js
@@ -0,0 +1,53 @@
+(function () {
+ 'use strict';
+
+ describe('The xos.helper module', function(){
+ describe('The xos-pagination component', () => {
+
+ let scope, element, isolatedScope;
+ let cb = jasmine.createSpy('callback')
+
+ beforeEach(module('xos.helpers'));
+
+ beforeEach(inject(function ($compile, $rootScope) {
+ scope = $rootScope.$new();
+
+ scope.pageSize = 2;
+
+ scope.totalElements = 5;
+
+ scope.change = cb;
+
+ element = angular.element('<xos-pagination page-size="pageSize" total-elements="totalElements" change="change"></xos-table>');
+ $compile(element)(scope);
+ scope.$digest();
+ isolatedScope = element.isolateScope().vm;
+ }));
+
+ it('should contain 3 pages', function() {
+ var li = element[0].getElementsByTagName('li');
+ expect(li.length).toEqual(5);
+ });
+
+ it('should call the change function', () => {
+ var li = element[0].getElementsByTagName('li')[3];
+ let link = li.getElementsByTagName('a')[0];
+ link.click();
+ expect(cb).toHaveBeenCalledWith(2);
+ });
+
+ describe('when elements number is less than page size', () => {
+ beforeEach(() => {
+ isolatedScope.pageSize = 10;
+ isolatedScope.totalElements = 9;
+ scope.$digest();
+ });
+
+ it('should not be rendered', () => {
+ var pagination = element[0].getElementsByClassName('pagination');
+ expect(pagination.length).toEqual(0);
+ });
+ });
+ });
+ });
+})();
\ No newline at end of file
diff --git a/views/ngXosLib/xosHelpers/src/ui_components/table/pagination.component.js b/views/ngXosLib/xosHelpers/src/ui_components/table/pagination.component.js
index 0f7099b..bcf56ea 100644
--- a/views/ngXosLib/xosHelpers/src/ui_components/table/pagination.component.js
+++ b/views/ngXosLib/xosHelpers/src/ui_components/table/pagination.component.js
@@ -19,7 +19,7 @@
change: '='
},
template: `
- <div class="row">
+ <div class="row" ng-if="vm.pageList.length > 1">
<div class="col-xs-12 text-center">
<ul class="pagination">
<li
@@ -68,7 +68,7 @@
// watch for data changes
$scope.$watch(() => this.totalElements, () => {
if(this.totalElements){
- this.pages = Math.round(this.totalElements / this.pageSize);
+ this.pages = Math.ceil(this.totalElements / this.pageSize);
this.pageList = this.createPages(this.pages);
}
// scope.getPages();