Skip to content

Commit

Permalink
Chore: Clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
pramodsum committed Jul 27, 2017
1 parent 1088fe8 commit 553b14d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 35 deletions.
6 changes: 1 addition & 5 deletions src/lib/annotations/doc/DocAnnotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,7 @@ class DocAnnotator extends Annotator {
}

// Get correct page
let { pageEl, page } = annotatorUtil.getPageInfo(event.target);
if (page === -1) {
// The ( .. ) around assignment is required syntax
({ pageEl, page } = annotatorUtil.getPageInfo(window.getSelection().anchorNode));
}
const { pageEl, page } = annotatorUtil.getPageInfo(event.target);

// Use highlight module to calculate quad points
const { highlightEls } = docAnnotatorUtil.getHighlightAndHighlightEls(this.highlighter, pageEl);
Expand Down
33 changes: 6 additions & 27 deletions src/lib/annotations/doc/__tests__/DocAnnotator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,10 @@ describe('lib/annotations/doc/DocAnnotator', () => {

it('should infer page from selection if it cannot be inferred from event', () => {
annotator.highlighter.highlights = [{}, {}];
stubs.getPageInfo.onFirstCall().returns({ pageEl: null, page: -1 });
stubs.getPageInfo.onSecondCall().returns({
pageEl: {
getBoundingClientRect: sandbox.stub().returns({
width: 100,
height: 100
})
},
page: 2
});
stubs.getPageInfo.returns({ pageEl: null, page: -1 });

annotator.getLocationFromEvent({}, TYPES.highlight);
expect(stubs.getPageInfo).to.be.called.twice;
expect(stubs.getPageInfo).to.be.called;
});

it('should not return a valid highlight location if no highlights exist', () => {
Expand Down Expand Up @@ -178,27 +169,15 @@ describe('lib/annotations/doc/DocAnnotator', () => {
});

it('should not return a location if there is no selection present', () => {
annotator.highlighter.highlights = [];
const location = annotator.getLocationFromEvent({}, TYPES.highlight_comment);
expect(location).to.be.null;
expect(annotator.getLocationFromEvent({}, TYPES.highlight_comment)).to.be.null;
});

it('should infer page from selection if it cannot be inferred from event', () => {
annotator.highlighter.highlights = [{}];
const getPageStub = stubs.getPageInfo;
getPageStub.onFirstCall().returns({ pageEl: null, page: -1 });
getPageStub.onSecondCall().returns({
pageEl: {
getBoundingClientRect: sandbox.stub().returns({
width: 100,
height: 100
})
},
page: 2
});
annotator.highlighter.highlights = [{}, {}];
stubs.getPageInfo.returns({ pageEl: null, page: -1 });

annotator.getLocationFromEvent({}, TYPES.highlight_comment);
expect(stubs.getSel).to.have.been.called;
expect(stubs.getPageInfo).to.be.called;
});

it('should not return a valid highlight location if no highlights exist', () => {
Expand Down
3 changes: 0 additions & 3 deletions src/lib/annotations/image/ImageAnnotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ class ImageAnnotator extends Annotator {

// If no image page was selected, ignore, as all images have a page number.
const { page } = annotatorUtil.getPageInfo(imageEl);
if (!page) {
return location;
}

// Location based only on image position
const imageDimensions = imageEl.getBoundingClientRect();
Expand Down

0 comments on commit 553b14d

Please sign in to comment.