Skip to content

Commit

Permalink
Chore: Add a page # for image annotations that were created without o…
Browse files Browse the repository at this point in the history
…ne (#357)
  • Loading branch information
pramodsum authored Aug 31, 2017
1 parent e01324b commit bf6a6f9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/lib/annotations/image/ImageAnnotator.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class ImageAnnotator extends Annotator {

// Corrects any image annotation page number to 1 instead of -1
const fixedLocation = location;
if (fixedLocation.page < 0) {
if (!fixedLocation.page || fixedLocation.page < 0) {
fixedLocation.page = 1;
}

Expand Down
27 changes: 26 additions & 1 deletion src/lib/annotations/image/__tests__/ImageAnnotator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,12 @@ describe('lib/annotations/image/ImageAnnotator', () => {
sandbox.stub(annotatorUtil, 'validateThreadParams').returns(true);
sandbox.stub(annotator, 'addThreadToMap');
sandbox.stub(annotator, 'handleValidationError');
const thread = annotator.createAnnotationThread([], {}, 'point');
const thread = annotator.createAnnotationThread([], { page: 2 }, 'point');

expect(annotator.addThreadToMap).to.have.been.called;
expect(thread instanceof ImagePointThread).to.be.true;
expect(annotator.handleValidationError).to.not.be.called;
expect(thread.location.page).equals(2);
});

it('should emit error and return undefined if thread params are invalid', () => {
Expand All @@ -143,6 +144,30 @@ describe('lib/annotations/image/ImageAnnotator', () => {
expect(thread instanceof ImagePointThread).to.be.false;
expect(annotator.handleValidationError).to.be.called;
});

it('should force page number 1 if the annotation was created without one', () => {
sandbox.stub(annotatorUtil, 'validateThreadParams').returns(true);
sandbox.stub(annotator, 'addThreadToMap');
sandbox.stub(annotator, 'handleValidationError');
const thread = annotator.createAnnotationThread([], {}, 'point');

expect(annotator.addThreadToMap).to.have.been.called;
expect(thread instanceof ImagePointThread).to.be.true;
expect(annotator.handleValidationError).to.not.be.called;
expect(thread.location.page).equals(1);
});

it('should force page number 1 if the annotation was created wit page number -1', () => {
sandbox.stub(annotatorUtil, 'validateThreadParams').returns(true);
sandbox.stub(annotator, 'addThreadToMap');
sandbox.stub(annotator, 'handleValidationError');
const thread = annotator.createAnnotationThread([], { page: -1 }, 'point');

expect(annotator.addThreadToMap).to.have.been.called;
expect(thread instanceof ImagePointThread).to.be.true;
expect(annotator.handleValidationError).to.not.be.called;
expect(thread.location.page).equals(1);
});
});

describe('hideAllAnnotations()', () => {
Expand Down

0 comments on commit bf6a6f9

Please sign in to comment.