wrote unit test for pagination detection service

This commit is contained in:
John Mitchell 2016-01-14 16:26:44 -05:00
parent 7b12954127
commit 53cf824602
2 changed files with 40 additions and 1 deletions

View File

@ -4,7 +4,7 @@
* All Rights Reserved
*************************************************/
export default ['$q', '$http', function($q, $http) {
export default ['$http', function($http) {
return {
getInitialPageForList: function(id, url, pageSize) {
// get the name of the object

View File

@ -0,0 +1,39 @@
import '../support/node';
import paginationModule from 'shared/pagination/main';
describe("pagination.service", function() {
var $httpBackend, pagination;
beforeEach("instantiate the pagination module", function() {
angular.mock.module(paginationModule.name);
});
beforeEach("put the service and deps in scope", inject(function($injector) {
$httpBackend = $injector.get('$httpBackend');
pagination = $injector.get('pagination');
}));
afterEach(function() {
$httpBackend.verifyNoOutstandingExpectation();
$httpBackend.verifyNoOutstandingRequest();
});
describe("should return page given obj is on", function() {
it('should return true', function() {
// get the name of the object
$httpBackend.when('GET', '/url/?id=1')
.respond({results: [{name: "foo"}]});
// get how many results are less than or equal to
// the name
$httpBackend.when('GET', '/url/?name__lte=foo')
.respond({count: 24});
var page = pagination.getInitialPageForList("1", "/url/", 20);
$httpBackend.flush();
expect(page).to.eventually.equal(2);
});
});
});