11import { equal } from 'assert' ;
22import PDFJSAnnotate from '../../src/PDFJSAnnotate' ;
33import { firePointerEvent } from '../fireEvent' ;
4- import mockDeleteAnnotation from " ../mockDeleteAnnotation" ;
5- import mockGetAnnotations from " ../mockGetAnnotations" ;
4+ import mockDeleteAnnotation from ' ../mockDeleteAnnotation' ;
5+ import mockGetAnnotations from ' ../mockGetAnnotations' ;
66import mockSVGContainer from '../mockSVGContainer' ;
77import mockTextAnnotation from '../mockTextAnnotation' ;
88import { enableEraser , disableEraser } from '../../src/UI/eraser' ;
@@ -17,30 +17,30 @@ function simulateEraserMovement() {
1717 firePointerEvent ( svg , 'pointerdown' , {
1818 clientX : 10 ,
1919 clientY : 10 ,
20- pointerType : " mouse"
20+ pointerType : ' mouse'
2121 } ) ;
2222
2323 firePointerEvent ( svg , 'pointermove' , {
2424 clientX : 25 ,
2525 clientY : 15 ,
26- pointerType : " mouse"
26+ pointerType : ' mouse'
2727 } ) ;
2828
2929 firePointerEvent ( svg , 'pointermove' , {
3030 clientX : 30 ,
3131 clientY : 30 ,
32- pointerType : " mouse"
32+ pointerType : ' mouse'
3333 } ) ;
3434
3535 firePointerEvent ( svg , 'pointerup' , {
3636 clientX : 30 ,
3737 clientY : 30 ,
38- pointerType : " mouse"
38+ pointerType : ' mouse'
3939 } ) ;
4040}
4141
42- describe ( 'UI::eraser' , function ( ) {
43- beforeEach ( function ( ) {
42+ describe ( 'UI::eraser' , function ( ) {
43+ beforeEach ( function ( ) {
4444 svg = mockSVGContainer ( ) ;
4545 svg . style . width = '100px' ;
4646 svg . style . height = '100px' ;
@@ -53,34 +53,64 @@ describe('UI::eraser', function () {
5353 PDFJSAnnotate . __storeAdapter . getAnnotations = mockGetAnnotations ( ) ;
5454 } ) ;
5555
56- afterEach ( function ( ) {
56+ afterEach ( function ( ) {
5757 if ( svg . parentNode ) {
5858 svg . parentNode . removeChild ( svg ) ;
5959 }
6060
6161 disableEraser ( ) ;
6262 } ) ;
6363
64- after ( function ( ) {
64+ after ( function ( ) {
6565 PDFJSAnnotate . __storeAdapter . deleteAnnotation = __deleteAnnotation ;
6666 PDFJSAnnotate . __storeAdapter . getAnnotations = __getAnnotations ;
6767 } ) ;
6868
69- it ( 'should do nothing when disabled' , function ( done ) {
69+ it ( 'should do nothing when disabled' , function ( done ) {
7070 enableEraser ( ) ;
7171 disableEraser ( ) ;
7272 simulateEraserMovement ( ) ;
73- setTimeout ( function ( ) {
73+ setTimeout ( function ( ) {
7474 equal ( deleteAnnotationSpy . called , false ) ;
7575 done ( ) ;
7676 } , 0 ) ;
7777 } ) ;
7878
79- it ( 'should create an annotation when enabled' , function ( done ) {
79+ it ( 'should delete an annotation when enabled' , function ( done ) {
8080 disableEraser ( ) ;
8181 enableEraser ( ) ;
8282 simulateEraserMovement ( ) ;
83- setTimeout ( function ( ) {
83+ setTimeout ( function ( ) {
84+ equal ( deleteAnnotationSpy . called , true ) ;
85+ let args = deleteAnnotationSpy . getCall ( 0 ) . args ;
86+ equal ( args [ 0 ] , 'test-document-id' ) ;
87+ equal ( args [ 1 ] , text . getAttribute ( 'data-pdf-annotate-id' ) ) ;
88+ done ( ) ;
89+ } , 0 ) ;
90+ } ) ;
91+
92+ it ( 'should delete annotation between pointermove points' , function ( done ) {
93+ disableEraser ( ) ;
94+ enableEraser ( ) ;
95+ firePointerEvent ( svg , 'pointerdown' , {
96+ clientX : 0 ,
97+ clientY : 0 ,
98+ pointerType : 'mouse'
99+ } ) ;
100+
101+ firePointerEvent ( svg , 'pointermove' , {
102+ clientX : 25 ,
103+ clientY : 20 ,
104+ pointerType : 'mouse'
105+ } ) ;
106+
107+ firePointerEvent ( svg , 'pointerup' , {
108+ clientX : 25 ,
109+ clientY : 20 ,
110+ pointerType : 'mouse'
111+ } ) ;
112+
113+ setTimeout ( function ( ) {
84114 equal ( deleteAnnotationSpy . called , true ) ;
85115 let args = deleteAnnotationSpy . getCall ( 0 ) . args ;
86116 equal ( args [ 0 ] , 'test-document-id' ) ;
0 commit comments