Skip to content

Commit

Permalink
Chore: Removing initAnnotations() from DocBaseViewer (#259)
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodsum authored Jul 29, 2017
1 parent fc25534 commit b7cde84
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 31 deletions.
16 changes: 4 additions & 12 deletions src/lib/viewers/doc/DocBaseViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -651,18 +651,7 @@ class DocBaseViewer extends BaseViewer {
}

/**
* Initializes annotations.
*
* @protected
* @return {void}
*/
initAnnotations() {
super.initAnnotations();
this.setupPageIds();
}

/**
* Add page IDs to each page since annotations explicitly needs IDs per page (rangy).
* Add page IDs to each page
*
* @private
* @return {void}
Expand Down Expand Up @@ -1001,6 +990,9 @@ class DocBaseViewer extends BaseViewer {
endProgress: false, // Indicate that viewer will end progress later
scale: this.pdfViewer.currentScale
});

// Add page IDs to each page after page structure is available
this.setupPageIds();
}
}

Expand Down
21 changes: 2 additions & 19 deletions src/lib/viewers/doc/__tests__/DocBaseViewer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1083,25 +1083,6 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
});
});

describe('initAnnotations()', () => {
const initFunc = BaseViewer.prototype.initAnnotations;

afterEach(() => {
Object.defineProperty(BaseViewer.prototype, 'initAnnotations', { value: initFunc });
});

it('should set up page IDs and initialize the annotator', () => {
docBase.pdfViewer = {
currentScale: 1
};
sandbox.stub(docBase, 'setupPageIds');
Object.defineProperty(BaseViewer.prototype, 'initAnnotations', { value: sandbox.mock() });

docBase.initAnnotations();
expect(docBase.setupPageIds).to.be.called;
});
});

describe('setupPageIds()', () => {
it('should add page IDs', () => {
const pageEl = document.createElement('div');
Expand Down Expand Up @@ -1412,6 +1393,7 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
stubs.setPage = sandbox.stub(docBase, 'setPage');
stubs.getCachedPage = sandbox.stub(docBase, 'getCachedPage');
stubs.emit = sandbox.stub(docBase, 'emit');
stubs.setupPages = sandbox.stub(docBase, 'setupPageIds');
});

it('should load UI, check the pagination buttons, set the page, and make document scrollable', () => {
Expand All @@ -1424,6 +1406,7 @@ describe('src/lib/viewers/doc/DocBaseViewer', () => {
expect(stubs.checkPaginationButtons).to.be.called;
expect(stubs.setPage).to.be.called;
expect(docBase.docEl).to.have.class('bp-is-scrollable');
expect(stubs.setupPages).to.be.called;
});

it('should broadcast that the preview is loaded if it hasn\'t already', () => {
Expand Down

0 comments on commit b7cde84

Please sign in to comment.