@@ -636,6 +636,55 @@ describe('doc/DocAnnotator', () => {
636636 } ) ;
637637 } ) ;
638638
639+ describe ( 'toggleAnnotationHandler()' , ( ) => {
640+ beforeEach ( ( ) => {
641+ stubs . destroyStub = sandbox . stub ( annotator , 'destroyPendingThreads' ) ;
642+ stubs . annotationMode = sandbox . stub ( annotator , 'isInAnnotationMode' ) ;
643+ stubs . exitModes = sandbox . stub ( annotator , 'exitAnnotationModesExcept' ) ;
644+ stubs . disable = sandbox . stub ( annotator , 'disableAnnotationMode' ) ;
645+ stubs . enable = sandbox . stub ( annotator , 'enableAnnotationMode' ) ;
646+ sandbox . stub ( annotator , 'getAnnotateButton' ) ;
647+ stubs . isAnnotatable = sandbox . stub ( annotator , 'isModeAnnotatable' ) . returns ( true ) ;
648+
649+ annotator . modeButtons = {
650+ point : { selector : 'point_btn' } ,
651+ draw : { selector : 'draw_btn' }
652+ } ;
653+
654+ annotator . createHighlightDialog = {
655+ isVisible : false ,
656+ hide : sandbox . stub ( ) ,
657+ destroy : sandbox . stub ( )
658+ }
659+ } ) ;
660+
661+ afterEach ( ( ) => {
662+ annotator . modeButtons = { } ;
663+ } ) ;
664+
665+ it ( 'should do nothing if specified annotation type is not annotatable' , ( ) => {
666+ stubs . isAnnotatable . returns ( false ) ;
667+ annotator . toggleAnnotationHandler ( 'bleh' ) ;
668+ expect ( stubs . destroyStub ) . to . not . be . called ;
669+ } ) ;
670+
671+ it ( 'should hide the highlight dialog and remove selection if it is visible' , ( ) => {
672+ const getSelectionStub = sandbox . stub ( document , 'getSelection' ) . returns ( {
673+ removeAllRanges : sandbox . stub ( )
674+ } ) ;
675+
676+ annotator . toggleAnnotationHandler ( TYPES . highlight ) ;
677+ expect ( annotator . createHighlightDialog . hide ) . to . not . be . called ;
678+ expect ( getSelectionStub ) . to . not . be . called ;
679+
680+ annotator . createHighlightDialog . isVisible = true ;
681+
682+ annotator . toggleAnnotationHandler ( TYPES . highlight ) ;
683+ expect ( annotator . createHighlightDialog . hide ) . to . be . called ;
684+ expect ( getSelectionStub ) . to . be . called ;
685+ } ) ;
686+ } ) ;
687+
639688 describe ( 'setupAnnotations()' , ( ) => {
640689 const setupFunc = Annotator . prototype . setupAnnotations ;
641690
@@ -1079,7 +1128,7 @@ describe('doc/DocAnnotator', () => {
10791128 expect ( annotator . highlighter . removeAllHighlights ) . to . be . called ;
10801129 } ) ;
10811130
1082- it ( 'should hide the highlight dialog and clear selection if it is visible' , ( ) => {
1131+ it ( 'should not hide the highlight dialog and clear selection if the CreateHighlightDialog is not visible' , ( ) => {
10831132 annotator . createHighlightDialog = {
10841133 isVisible : false ,
10851134 hide : sandbox . stub ( ) ,
@@ -1094,8 +1143,19 @@ describe('doc/DocAnnotator', () => {
10941143 annotator . highlightMouseupHandler ( { x : 0 , y : 0 } ) ;
10951144 expect ( annotator . createHighlightDialog . hide ) . to . not . be . called ;
10961145 expect ( getSelectionStub ) . to . not . be . called ;
1146+ } ) ;
10971147
1098- annotator . createHighlightDialog . isVisible = true ;
1148+ it ( 'should hide the highlight dialog and clear selection if the CreateHighlightDialog is visible' , ( ) => {
1149+ annotator . createHighlightDialog = {
1150+ isVisible : true ,
1151+ hide : sandbox . stub ( ) ,
1152+ removeListener : sandbox . stub ( ) ,
1153+ destroy : sandbox . stub ( )
1154+ }
1155+
1156+ const getSelectionStub = sandbox . stub ( document , 'getSelection' ) . returns ( {
1157+ removeAllRanges : sandbox . stub ( )
1158+ } ) ;
10991159
11001160 annotator . highlightMouseupHandler ( { x : 0 , y : 0 } ) ;
11011161 expect ( annotator . createHighlightDialog . hide ) . to . be . called ;
0 commit comments