1
1
import { equal } from 'assert' ;
2
2
import PDFJSAnnotate from '../../src/PDFJSAnnotate' ;
3
3
import { firePointerEvent } from '../fireEvent' ;
4
- import mockDeleteAnnotation from " ../mockDeleteAnnotation" ;
5
- import mockGetAnnotations from " ../mockGetAnnotations" ;
4
+ import mockDeleteAnnotation from ' ../mockDeleteAnnotation' ;
5
+ import mockGetAnnotations from ' ../mockGetAnnotations' ;
6
6
import mockSVGContainer from '../mockSVGContainer' ;
7
7
import mockTextAnnotation from '../mockTextAnnotation' ;
8
8
import { enableEraser , disableEraser } from '../../src/UI/eraser' ;
@@ -17,30 +17,30 @@ function simulateEraserMovement() {
17
17
firePointerEvent ( svg , 'pointerdown' , {
18
18
clientX : 10 ,
19
19
clientY : 10 ,
20
- pointerType : " mouse"
20
+ pointerType : ' mouse'
21
21
} ) ;
22
22
23
23
firePointerEvent ( svg , 'pointermove' , {
24
24
clientX : 25 ,
25
25
clientY : 15 ,
26
- pointerType : " mouse"
26
+ pointerType : ' mouse'
27
27
} ) ;
28
28
29
29
firePointerEvent ( svg , 'pointermove' , {
30
30
clientX : 30 ,
31
31
clientY : 30 ,
32
- pointerType : " mouse"
32
+ pointerType : ' mouse'
33
33
} ) ;
34
34
35
35
firePointerEvent ( svg , 'pointerup' , {
36
36
clientX : 30 ,
37
37
clientY : 30 ,
38
- pointerType : " mouse"
38
+ pointerType : ' mouse'
39
39
} ) ;
40
40
}
41
41
42
- describe ( 'UI::eraser' , function ( ) {
43
- beforeEach ( function ( ) {
42
+ describe ( 'UI::eraser' , function ( ) {
43
+ beforeEach ( function ( ) {
44
44
svg = mockSVGContainer ( ) ;
45
45
svg . style . width = '100px' ;
46
46
svg . style . height = '100px' ;
@@ -53,34 +53,64 @@ describe('UI::eraser', function () {
53
53
PDFJSAnnotate . __storeAdapter . getAnnotations = mockGetAnnotations ( ) ;
54
54
} ) ;
55
55
56
- afterEach ( function ( ) {
56
+ afterEach ( function ( ) {
57
57
if ( svg . parentNode ) {
58
58
svg . parentNode . removeChild ( svg ) ;
59
59
}
60
60
61
61
disableEraser ( ) ;
62
62
} ) ;
63
63
64
- after ( function ( ) {
64
+ after ( function ( ) {
65
65
PDFJSAnnotate . __storeAdapter . deleteAnnotation = __deleteAnnotation ;
66
66
PDFJSAnnotate . __storeAdapter . getAnnotations = __getAnnotations ;
67
67
} ) ;
68
68
69
- it ( 'should do nothing when disabled' , function ( done ) {
69
+ it ( 'should do nothing when disabled' , function ( done ) {
70
70
enableEraser ( ) ;
71
71
disableEraser ( ) ;
72
72
simulateEraserMovement ( ) ;
73
- setTimeout ( function ( ) {
73
+ setTimeout ( function ( ) {
74
74
equal ( deleteAnnotationSpy . called , false ) ;
75
75
done ( ) ;
76
76
} , 0 ) ;
77
77
} ) ;
78
78
79
- it ( 'should create an annotation when enabled' , function ( done ) {
79
+ it ( 'should delete an annotation when enabled' , function ( done ) {
80
80
disableEraser ( ) ;
81
81
enableEraser ( ) ;
82
82
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 ( ) {
84
114
equal ( deleteAnnotationSpy . called , true ) ;
85
115
let args = deleteAnnotationSpy . getCall ( 0 ) . args ;
86
116
equal ( args [ 0 ] , 'test-document-id' ) ;
0 commit comments