Skip to content

Commit

Permalink
Ref #105 added test cases for Filter JS pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
Aditya Shedge committed Dec 20, 2015
1 parent 5d3d3b1 commit 5287b9a
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions spec/filterjs_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,5 +163,63 @@ describe('FilterJS', function() {
expect(callbacks.afterFilter).toHaveBeenCalled();
});
});

describe('#initialize', function() {
var paginationOpts;
var paginationView = '<nav> <ul class="myPagination"> <% if(currentPage > 1) { %> <li> <a href="#" data-page="first" aria-label="First"><span aria-hidden="true">First</span></a> </li> <li><a href="#" data-page="prev" aria-label="Previous"><span aria-hidden="true">&larr; Previous</span></a></li> <% } %> <% for(var i = 0, l = pages.length; i < l; i++ ){ %> <li class="<%= pages[i] == currentPage ? \'active\' : \'\' %>"> <a href="#" data-page="<%= pages[i] %>"><%= pages[i] %></a> </li> <% } %> <% if( currentPage < totalPages ) { %> <li><a href="#" data-page="next" aria-label="Next"><span aria-hidden="true">Next &rarr;</span></a></li> <li><a href="#" data-page="last" aria-label="Last"><span aria-hidden="true">Last</span></a></li> <% } %> </ul></nav>';

var perPageView = '<select size="1" name="per_page" data-perpage="true" class="per-page"> <% for(var i = 0; i < values.length; i++ ){ %> <option value="<%= values[i] %>"><%= values[i] %></option> <% } %></select>';

it("must not set 'has_pagination' when no pagination options", function() {
fjs = FilterJS(movies, '#movies', options);

expect(fjs.has_pagination).toBeFalsy();
expect(fjs.opts.pagination).toBeUndefined();
});

it("must set default pagination options", function() {
paginationOpts = {
container: '#pagination',
perPage: { container: '#per_page' }
}

options.pagination = paginationOpts;
fjs = FilterJS(movies, '#movies', options);

expect(fjs.has_pagination).toBeTruthy();
expect(fjs.opts.pagination).toEqual(paginationOpts);
expect(fjs.page.currentPage).toEqual(1);
// perPage value is set on 'onPagination' callback, default is 10
expect(fjs.page.perPage).toEqual(10);
// must use default pagination view set in filterjs dist
expect(fjs.opts.pagination.paginationView).toBeUndefined();
expect(fjs.opts.pagination.perPageView).toBeUndefined();
});

it("must set custom pagination options", function() {
paginationOpts = {
container: '#pagination',
visiblePages: 5,
perPage: {
values: [5, 10, 15],
container: '#per_page'
}
};

paginationOpts.paginationView = paginationView;
paginationOpts.perPageView = perPageView;

options.pagination = paginationOpts;
fjs = FilterJS(movies, '#movies', options);

expect(fjs.has_pagination).toBeTruthy();
expect(fjs.opts.pagination).toEqual(paginationOpts);
expect(fjs.page.currentPage).toEqual(1);
// perPage value is set on 'onPagination' callback
expect(fjs.page.perPage).toEqual(paginationOpts.perPage.values[0]);
expect(fjs.opts.pagination.paginationView).toEqual(paginationView);
expect(fjs.opts.pagination.perPageView).toEqual(perPageView);
});
});
});

0 comments on commit 5287b9a

Please sign in to comment.