From 044192022778ddb17afe527a05bf628726139063 Mon Sep 17 00:00:00 2001 From: Sumedha Pramod Date: Thu, 17 Aug 2017 14:31:35 -0700 Subject: [PATCH] Fix: Add page controls between zoom and fullscreen controls (#320) --- src/lib/PageControls.js | 14 +++++++++----- src/lib/__tests__/PageControls-test.js | 12 ++++++++---- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/lib/PageControls.js b/src/lib/PageControls.js index 812e58edc..1886e8b6f 100644 --- a/src/lib/PageControls.js +++ b/src/lib/PageControls.js @@ -37,20 +37,24 @@ class PageControls extends EventEmitter { this.controlsEl = controls.controlsEl; this.currentPageEl = controls.currentPageEl; this.pageNumInputEl = controls.pageNumInputEl; - - this.controls.add(__('previous_page'), previousPage, `bp-previous-page-icon ${PREV_PAGE}`, ICON_DROP_UP); - this.controls.add(__('enter_page_num'), this.showPageNumInput.bind(this), PAGE_NUM, pageNumTemplate); - this.controls.add(__('next_page'), nextPage, `bp-next-page-icon ${NEXT_PAGE}`, ICON_DROP_DOWN); + this.previousPage = previousPage; + this.nextPage = nextPage; } /** - * Initializes page number selector. + * Adds controls and initializes page number selector. * * @private * @param {number} pagesCount - Total number of page * @return {void} */ init(pagesCount) { + // Add controls + this.controls.add(__('previous_page'), this.previousPage, `bp-previous-page-icon ${PREV_PAGE}`, ICON_DROP_UP); + this.controls.add(__('enter_page_num'), this.showPageNumInput.bind(this), PAGE_NUM, pageNumTemplate); + this.controls.add(__('next_page'), this.nextPage, `bp-next-page-icon ${NEXT_PAGE}`, ICON_DROP_DOWN); + + // Initialize page number selector const pageNumEl = this.controlsEl.querySelector(`.${PAGE_NUM}`); this.pagesCount = pagesCount; diff --git a/src/lib/__tests__/PageControls-test.js b/src/lib/__tests__/PageControls-test.js index cba7bf7f1..84b4152fc 100644 --- a/src/lib/__tests__/PageControls-test.js +++ b/src/lib/__tests__/PageControls-test.js @@ -51,20 +51,23 @@ describe('lib/PageControls', () => { describe('constructor()', () => { it('should create the correct DOM structure', () => { expect(pageControls.controlsEl).to.not.be.undefined; - expect(pageControls.controls.buttonRefs.length).equals(3); }); }); describe('init()', () => { it('should initialize the page number selector', () => { const pagesCount = '5'; + pageControls.init(pagesCount); - const totalPageEl = pageControls.controlsEl.querySelector(`.${CONTROLS_TOTAL_PAGES}`); - const pageNumInputEl = pageControls.controlsEl.querySelector(`.${CONTROLS_PAGE_NUM_INPUT_CLASS}`); + expect(pageControls.controls.buttonRefs.length).equals(3); expect(pageControls.pagesCount).equals(pagesCount); + expect(pageControls.currentPageEl).to.not.be.undefined; + + const totalPageEl = pageControls.controlsEl.querySelector(`.${CONTROLS_TOTAL_PAGES}`); expect(totalPageEl).to.have.text(pagesCount); + + const pageNumInputEl = pageControls.controlsEl.querySelector(`.${CONTROLS_PAGE_NUM_INPUT_CLASS}`); expect(pageNumInputEl).to.have.attr('max', pagesCount); - expect(pageControls.currentPageEl).to.not.be.undefined; }); }); @@ -102,6 +105,7 @@ describe('lib/PageControls', () => { describe('checkPaginationButtons()', () => { beforeEach(() => { + pageControls.init(); stubs.pageNumButtonEl = pageControls.controlsEl.querySelector(`.${PAGE_NUM}`); stubs.previousPageButtonEl = pageControls.controlsEl.querySelector(`.${PREV_PAGE}`); stubs.nextPageButtonEl = pageControls.controlsEl.querySelector(`.${NEXT_PAGE}`);