Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Add a page # for image annotations that were created without one #357

Merged
merged 1 commit into from
Aug 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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