From 5287b9a3755a8c1e6a55426df4e59488d1f8ef68 Mon Sep 17 00:00:00 2001 From: Aditya Shedge Date: Sun, 20 Dec 2015 21:30:24 +0530 Subject: [PATCH] Ref #105 added test cases for Filter JS pagination --- spec/filterjs_spec.js | 58 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/spec/filterjs_spec.js b/spec/filterjs_spec.js index f8735b7..e23d794 100644 --- a/spec/filterjs_spec.js +++ b/spec/filterjs_spec.js @@ -163,5 +163,63 @@ describe('FilterJS', function() { expect(callbacks.afterFilter).toHaveBeenCalled(); }); }); + + describe('#initialize', function() { + var paginationOpts; + var paginationView = ''; + + var perPageView = ''; + + 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); + }); + }); });