diff --git a/src/lib/annotations/image/ImageAnnotator.js b/src/lib/annotations/image/ImageAnnotator.js index befe22c05..4146b41fb 100644 --- a/src/lib/annotations/image/ImageAnnotator.js +++ b/src/lib/annotations/image/ImageAnnotator.js @@ -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; } diff --git a/src/lib/annotations/image/__tests__/ImageAnnotator-test.js b/src/lib/annotations/image/__tests__/ImageAnnotator-test.js index 3ca3fc159..0b4bdfc2d 100644 --- a/src/lib/annotations/image/__tests__/ImageAnnotator-test.js +++ b/src/lib/annotations/image/__tests__/ImageAnnotator-test.js @@ -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', () => { @@ -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()', () => {