From 0ba1965d5eaab17d2094b1017eff074483e736ce Mon Sep 17 00:00:00 2001 From: Sumedha Pramod Date: Fri, 10 Nov 2017 13:37:25 -0800 Subject: [PATCH] Fix: only show newly created annotation dialog on hover (#25) --- src/AnnotationThread.js | 9 +++++---- src/__tests__/AnnotationThread-test.js | 19 +++++++++++++++++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/AnnotationThread.js b/src/AnnotationThread.js index c2edb7377..29cabae09 100644 --- a/src/AnnotationThread.js +++ b/src/AnnotationThread.js @@ -155,9 +155,6 @@ class AnnotationThread extends EventEmitter { const tempAnnotation = new Annotation(tempAnnotationData); this.saveAnnotationToThread(tempAnnotation); - // Changing state from pending - this.state = STATES.hover; - // Save annotation on server return this.annotationService .create(annotationData) @@ -499,7 +496,11 @@ class AnnotationThread extends EventEmitter { this.dialog.removeAnnotation(tempAnnotation.annotationID); } - this.showDialog(); + if (this.isMobile) { + // Changing state from pending + this.state = STATES.hover; + this.showDialog(); + } this.emit(THREAD_EVENT.save); } diff --git a/src/__tests__/AnnotationThread-test.js b/src/__tests__/AnnotationThread-test.js index 36b9a9096..36c8a6684 100644 --- a/src/__tests__/AnnotationThread-test.js +++ b/src/__tests__/AnnotationThread-test.js @@ -168,7 +168,6 @@ describe('AnnotationThread', () => { threadNumber: '1' }) ); - expect(thread.state).to.equal(STATES.hover); }); it('should delete the temporary annotation and broadcast an error if there was an error saving', (done) => { @@ -210,7 +209,6 @@ describe('AnnotationThread', () => { stubs.create = sandbox.stub(annotationService, 'create'); stubs.saveAnnotationToThread = sandbox.stub(thread, 'saveAnnotationToThread'); sandbox.stub(thread, 'getThreadEventData').returns({}); - sandbox.stub(thread, 'showDialog'); }); it('should save annotation to thread if it does not exist in annotations array', () => { @@ -243,6 +241,23 @@ describe('AnnotationThread', () => { thread.updateTemporaryAnnotation(tempAnnotation, serverAnnotation); }); + + it('should only show dialog immediately on mobile devices', () => { + const serverAnnotation = { threadNumber: 1 }; + const tempAnnotation = serverAnnotation; + sandbox.stub(thread, 'showDialog'); + + // Don't show dialog on web browsers + thread.updateTemporaryAnnotation(tempAnnotation, serverAnnotation); + expect(thread.showDialog).to.not.be.called; + expect(thread.state).not.equals(STATES.hover); + + // Only show dialog on mobile browsers + thread.isMobile = true; + thread.updateTemporaryAnnotation(tempAnnotation, serverAnnotation); + expect(thread.showDialog).to.be.called; + expect(thread.state).equals(STATES.hover); + }); }) describe('deleteAnnotation()', () => {