@@ -659,7 +659,7 @@ describe('doc/DocAnnotator', () => {
659659
660660 it ( 'should bind DOM listeners if user can annotate and highlight' , ( ) => {
661661 stubs . elMock . expects ( 'addEventListener' ) . withArgs ( 'mouseup' , annotator . highlightMouseupHandler ) ;
662- stubs . elMock . expects ( 'addEventListener' ) . withArgs ( 'wheel' , annotator . resetHighlightSelection ) ;
662+ stubs . elMock . expects ( 'addEventListener' ) . withArgs ( 'wheel' , annotator . hideCreateDialog ) ;
663663 stubs . elMock . expects ( 'addEventListener' ) . withArgs ( 'dblclick' , annotator . highlightMouseupHandler ) ;
664664 stubs . elMock . expects ( 'addEventListener' ) . withArgs ( 'mousedown' , annotator . highlightMousedownHandler ) ;
665665 stubs . elMock . expects ( 'addEventListener' ) . withArgs ( 'contextmenu' , annotator . highlightMousedownHandler ) ;
@@ -689,7 +689,7 @@ describe('doc/DocAnnotator', () => {
689689 annotator . drawEnabled = false ;
690690
691691 stubs . elMock . expects ( 'addEventListener' ) . withArgs ( 'mouseup' , annotator . highlightMouseupHandler ) ;
692- stubs . elMock . expects ( 'addEventListener' ) . withArgs ( 'wheel' , annotator . resetHighlightSelection ) ;
692+ stubs . elMock . expects ( 'addEventListener' ) . withArgs ( 'wheel' , annotator . hideCreateDialog ) ;
693693 annotator . bindDOMListeners ( ) ;
694694 } ) ;
695695
@@ -734,7 +734,7 @@ describe('doc/DocAnnotator', () => {
734734 . never ( ) ;
735735 stubs . elMock
736736 . expects ( 'addEventListener' )
737- . withArgs ( 'wheel' , annotator . resetHighlightSelection )
737+ . withArgs ( 'wheel' , annotator . hideCreateDialog )
738738 . never ( ) ;
739739 stubs . elMock
740740 . expects ( 'addEventListener' )
@@ -770,7 +770,8 @@ describe('doc/DocAnnotator', () => {
770770 annotator . permissions . canAnnotate = true ;
771771
772772 stubs . elMock . expects ( 'removeEventListener' ) . withArgs ( 'mouseup' , annotator . highlightMouseupHandler ) ;
773- stubs . elMock . expects ( 'removeEventListener' ) . withArgs ( 'wheel' , annotator . resetHighlightSelection ) ;
773+ stubs . elMock . expects ( 'removeEventListener' ) . withArgs ( 'wheel' , annotator . hideCreateDialog ) ;
774+ stubs . elMock . expects ( 'removeEventListener' ) . withArgs ( 'touchend' , annotator . hideCreateDialog ) ;
774775 stubs . elMock . expects ( 'removeEventListener' ) . withArgs ( 'dblclick' , annotator . highlightMouseupHandler ) ;
775776 stubs . elMock . expects ( 'removeEventListener' ) . withArgs ( 'mousedown' , annotator . highlightMousedownHandler ) ;
776777 stubs . elMock . expects ( 'removeEventListener' ) . withArgs ( 'contextmenu' , annotator . highlightMousedownHandler ) ;
@@ -846,44 +847,18 @@ describe('doc/DocAnnotator', () => {
846847
847848 describe ( 'resetHighlightSelection()' , ( ) => {
848849 beforeEach ( ( ) => {
849- annotator . createHighlightDialog = {
850- isVisible : false ,
851- hide : sandbox . stub ( ) ,
852- destroy : sandbox . stub ( )
853- } ;
854- stubs . isInDialog = sandbox . stub ( util , 'isInDialog' ) . returns ( false ) ;
855- } ) ;
856-
857- it ( 'should do nothing if the createHighlightDialog is hidden' , ( ) => {
858- annotator . resetHighlightSelection ( { } ) ;
859- expect ( annotator . createHighlightDialog . hide ) . to . not . be . called ;
860- } ) ;
861-
862- it ( 'should do nothing if the mouse event was triggered in an annotation dialog' , ( ) => {
863- stubs . isInDialog . returns ( true ) ;
864- annotator . resetHighlightSelection ( { } ) ;
865- expect ( annotator . createHighlightDialog . hide ) . to . not . be . called ;
850+ sandbox . stub ( annotator , 'hideCreateDialog' ) ;
866851 } ) ;
867852
868853 it ( 'should hide the visible createHighlightDialog and clear the text selection' , ( ) => {
869- annotator . createHighlightDialog . isVisible = true ;
870- annotator . resetHighlightSelection ( { } ) ;
871- expect ( annotator . createHighlightDialog . hide ) . to . be . called ;
872- } ) ;
873-
874- it ( 'should only clear the selected text if the user is creating a new highlight' , ( ) => {
875854 const selection = {
876855 removeAllRanges : sandbox . stub ( )
877856 } ;
878857 sandbox . stub ( document , 'getSelection' ) . returns ( selection ) ;
879- annotator . createHighlightDialog . isVisible = true ;
880-
881- annotator . isCreatingHighlight = true ;
882- annotator . resetHighlightSelection ( { } ) ;
883- expect ( selection . removeAllRanges ) . to . not . be . called ;
884858
885- annotator . isCreatingHighlight = false ;
886859 annotator . resetHighlightSelection ( { } ) ;
860+ expect ( annotator . hideCreateDialog ) . to . be . called ;
861+ expect ( annotator . isCreatingHighlight ) . to . be . false ;
887862 expect ( selection . removeAllRanges ) . to . be . called ;
888863 } ) ;
889864 } ) ;
@@ -943,7 +918,6 @@ describe('doc/DocAnnotator', () => {
943918 beforeEach ( ( ) => {
944919 stubs . create = sandbox . stub ( annotator , 'highlightCreateHandler' ) ;
945920 stubs . click = sandbox . stub ( annotator , 'highlightClickHandler' ) ;
946- sandbox . stub ( annotator , 'resetHighlightSelection' ) ;
947921 annotator . mouseX = undefined ;
948922 annotator . mouseY = undefined ;
949923 } ) ;
@@ -954,16 +928,12 @@ describe('doc/DocAnnotator', () => {
954928 annotator . highlightMouseupHandler ( { x : 0 , y : 0 } ) ;
955929 expect ( stubs . create ) . to . be . called ;
956930 expect ( stubs . click ) . to . not . be . called ;
957- expect ( annotator . isCreatingHighlight ) . to . be . false ;
958- expect ( annotator . resetHighlightSelection ) . to . be . called ;
959931 } ) ;
960932
961933 it ( 'should call highlightCreateHandler if on desktop and the user double clicked' , ( ) => {
962934 annotator . highlightMouseupHandler ( { type : 'dblclick' } ) ;
963935 expect ( stubs . create ) . to . be . called ;
964936 expect ( stubs . click ) . to . not . be . called ;
965- expect ( annotator . isCreatingHighlight ) . to . be . false ;
966- expect ( annotator . resetHighlightSelection ) . to . be . called ;
967937 } ) ;
968938
969939 it ( 'should call highlightClickHandler if on desktop and createHighlightDialog exists' , ( ) => {
@@ -972,8 +942,6 @@ describe('doc/DocAnnotator', () => {
972942 annotator . highlightMouseupHandler ( { x : 0 , y : 0 } ) ;
973943 expect ( stubs . create ) . to . not . be . called ;
974944 expect ( stubs . click ) . to . be . called ;
975- expect ( annotator . isCreatingHighlight ) . to . be . false ;
976- expect ( annotator . resetHighlightSelection ) . to . be . called ;
977945 } ) ;
978946
979947 it ( 'should call highlighter.removeAllHighlghts' , ( ) => {
@@ -982,7 +950,6 @@ describe('doc/DocAnnotator', () => {
982950 } ;
983951 annotator . highlightMouseupHandler ( { x : 0 , y : 0 } ) ;
984952 expect ( annotator . highlighter . removeAllHighlights ) . to . be . called ;
985- expect ( annotator . resetHighlightSelection ) . to . be . called ;
986953 } ) ;
987954 } ) ;
988955
@@ -1192,6 +1159,7 @@ describe('doc/DocAnnotator', () => {
11921159 sandbox . stub ( annotator , 'clickThread' ) ;
11931160 sandbox . stub ( annotator , 'removeThreadFromSharedDialog' ) ;
11941161 sandbox . stub ( annotator , 'hideAnnotations' ) ;
1162+ sandbox . stub ( annotator , 'resetHighlightSelection' ) ;
11951163
11961164 annotator . modeControllers = {
11971165 highlight : {
@@ -1237,16 +1205,22 @@ describe('doc/DocAnnotator', () => {
12371205 annotator . plainHighlightEnabled = false ;
12381206 annotator . commentHighlightEnabled = false ;
12391207 stubs . threadMock . expects ( 'show' ) . never ( ) ;
1208+ annotator . isMobile = true ;
12401209
1241- annotator . isMobile = false ;
12421210 annotator . highlightClickHandler ( stubs . event ) ;
1243- expect ( annotator . removeThreadFromSharedDialog ) . to . not . be . called ;
1211+ expect ( annotator . removeThreadFromSharedDialog ) . to . be . called ;
1212+ expect ( annotator . hideAnnotations ) . to . be . called ;
1213+ } ) ;
12441214
1215+ it ( 'should reset highlight selection if not on mobile and no active threads exist' , ( ) => {
12451216 annotator . plainHighlightEnabled = false ;
1246- annotator . isMobile = true ;
1217+ annotator . commentHighlightEnabled = false ;
1218+ stubs . threadMock . expects ( 'show' ) . never ( ) ;
1219+
1220+ annotator . isMobile = false ;
12471221 annotator . highlightClickHandler ( stubs . event ) ;
1248- expect ( annotator . removeThreadFromSharedDialog ) . to . be . called ;
1249- expect ( annotator . hideAnnotations ) . to . be . called ;
1222+ expect ( annotator . removeThreadFromSharedDialog ) . to . not . be . called ;
1223+ expect ( annotator . resetHighlightSelection ) . to . be . called ;
12501224 } ) ;
12511225 } ) ;
12521226
@@ -1422,6 +1396,7 @@ describe('doc/DocAnnotator', () => {
14221396 } ;
14231397 sandbox . stub ( annotator , 'renderPage' ) ;
14241398 sandbox . stub ( annotator , 'resetHighlightSelection' ) ;
1399+ sandbox . stub ( annotator , 'hideCreateDialog' ) ;
14251400 } ) ;
14261401
14271402 afterEach ( ( ) => {
@@ -1435,13 +1410,7 @@ describe('doc/DocAnnotator', () => {
14351410
14361411 it ( 'should hide the createHighlightDialog on binddomlisteners' , ( ) => {
14371412 annotator . handleControllerEvents ( { event : CONTROLLER_EVENT . bindDOMListeners } ) ;
1438- expect ( annotator . createHighlightDialog . hide ) . to . be . called ;
1439- } ) ;
1440-
1441- it ( 'should do nothing if createHighlightDialog is hidden or does not exist on binddomlisteners' , ( ) => {
1442- annotator . createHighlightDialog . isVisible = false ;
1443- annotator . handleControllerEvents ( { event : CONTROLLER_EVENT . bindDOMListeners } ) ;
1444- expect ( annotator . createHighlightDialog . hide ) . to . not . be . called ;
1413+ expect ( annotator . hideCreateDialog ) . to . be . called ;
14451414 } ) ;
14461415
14471416 it ( 'should render the specified page on annotationsrenderpage' , ( ) => {
0 commit comments