diff --git a/src/lib/viewers/BaseViewer.js b/src/lib/viewers/BaseViewer.js index a03775b104..1b372bd37a 100644 --- a/src/lib/viewers/BaseViewer.js +++ b/src/lib/viewers/BaseViewer.js @@ -1021,11 +1021,16 @@ class BaseViewer extends EventEmitter { /** * Handles the 'scrolltoannotation' event and calls the annotator scroll method - * @param {Object} data - * @param {string} data.id Annotation id + * @param {Object} data - Annotator event data + * @param {string} [data.id] - Annotation Id + * @param {Object} [data.target] - Annotation target + * @param {Object} [data.target.location] - Target location of the annotation + * @param {number} [data.target.location.value] - location value + * + * @return {void} */ - handleScrollToAnnotation({ id }) { - this.annotator.scrollToAnnotation(id); + handleScrollToAnnotation(data) { + this.annotator.scrollToAnnotation(data); } /** diff --git a/src/lib/viewers/__tests__/BaseViewer-test.js b/src/lib/viewers/__tests__/BaseViewer-test.js index c3cb2ad55f..25929653cd 100644 --- a/src/lib/viewers/__tests__/BaseViewer-test.js +++ b/src/lib/viewers/__tests__/BaseViewer-test.js @@ -1270,7 +1270,7 @@ describe('lib/viewers/BaseViewer', () => { base.handleScrollToAnnotation({ id: '123' }); - expect(scrollToAnnotationStub).to.be.calledWith('123'); + expect(scrollToAnnotationStub).to.be.calledWith({ id: '123' }); }); }); diff --git a/src/lib/viewers/doc/PresentationViewer.js b/src/lib/viewers/doc/PresentationViewer.js index 1fa0fe11bb..1f43bf8539 100644 --- a/src/lib/viewers/doc/PresentationViewer.js +++ b/src/lib/viewers/doc/PresentationViewer.js @@ -124,6 +124,19 @@ class PresentationViewer extends DocBaseViewer { return hasXOverflow || hasYOverflow; } + /** + * @override + */ + handleScrollToAnnotation(data) { + const { target } = data; + + if (target && target.location) { + this.setPage(target.location.value); + } + + super.handleScrollToAnnotation(data); + } + //-------------------------------------------------------------------------- // Protected //-------------------------------------------------------------------------- @@ -313,19 +326,6 @@ class PresentationViewer extends DocBaseViewer { }; }; } - - /** - * @override - * @param {Object} data - * @param {string} data.id - location value of the annotation - * @param {Object} data.location - location value of the annotation - * @param {number} data.location.value - location value of the annotation - */ - handleScrollToAnnotation({ id, location: { value = 1 } }) { - this.setPage(value); - - this.annotator.scrollToAnnotation(id); - } } export default PresentationViewer; diff --git a/src/lib/viewers/doc/__tests__/PresentationViewer-test.js b/src/lib/viewers/doc/__tests__/PresentationViewer-test.js index e16ff5c599..81b8b99687 100644 --- a/src/lib/viewers/doc/__tests__/PresentationViewer-test.js +++ b/src/lib/viewers/doc/__tests__/PresentationViewer-test.js @@ -491,18 +491,38 @@ describe('lib/viewers/doc/PresentationViewer', () => { }); describe('handleScrollToAnnotation', () => { + let setPageStub; + let scrollToAnnotationStub; + + beforeEach(() => { + setPageStub = sandbox.stub(presentation, 'setPage'); + scrollToAnnotationStub = sandbox.stub(); + }); + it('should call setPage is location value provided', () => { - const setPageStub = sandbox.stub(presentation, 'setPage'); - const scrollToAnnotationStub = sandbox.stub(); + const mockPartialAnnotation = { id: '123', target: { location: { value: 5 } } }; presentation.annotator = { scrollToAnnotation: scrollToAnnotationStub, }; - presentation.handleScrollToAnnotation({ id: '123', location: { value: 5 } }); + presentation.handleScrollToAnnotation(mockPartialAnnotation); expect(setPageStub).to.be.calledWith(5); - expect(scrollToAnnotationStub).to.be.calledWith('123'); + expect(scrollToAnnotationStub).to.be.calledWith(mockPartialAnnotation); + }); + + it('should not call setPage if target is not provided', () => { + const mockPartialAnnotation = { id: '123' }; + + presentation.annotator = { + scrollToAnnotation: scrollToAnnotationStub, + }; + + presentation.handleScrollToAnnotation(mockPartialAnnotation); + + expect(setPageStub).not.to.be.called; + expect(scrollToAnnotationStub).to.be.calledWith(mockPartialAnnotation); }); }); });