@@ -9,50 +9,78 @@ describe('scrolly.dragger', function() {
9
9
} ) ) ;
10
10
11
11
describe ( 'options' , function ( ) {
12
- var elm , spy , d ;
12
+ var elm , dragSpy , d ;
13
13
function setup ( opts ) {
14
14
elm = angular . element ( "<div>" ) ;
15
15
d = new $dragger ( elm , opts ) ;
16
- spy = jasmine . createSpy ( ) ;
17
- d . addListener ( $dragger . DIRECTION_ANY , spy ) ;
16
+ dragSpy = jasmine . createSpy ( ) ;
17
+ d . addListener ( $dragger . DIRECTION_ANY , dragSpy ) ;
18
18
}
19
- function trigger ( elm , type ) {
19
+ function trigger ( elm , type , options ) {
20
20
var e = $ . Event ( type ) ;
21
21
e . pageX = e . pageY = 0 ;
22
+ angular . extend ( e , options || { } ) ;
22
23
$ ( elm [ 0 ] ) . trigger ( e ) ;
23
24
}
25
+ it ( 'should not stop propagation by default' , function ( ) {
26
+ setup ( { } ) ;
27
+ var stopSpy = jasmine . createSpy ( 'stop' ) ;
28
+ trigger ( elm , 'touchstart' , { stopPropagation : stopSpy } ) ;
29
+ expect ( stopSpy ) . not . toHaveBeenCalled ( ) ;
30
+ trigger ( elm , 'touchmove' , { stopPropagation : stopSpy } ) ;
31
+ expect ( stopSpy ) . not . toHaveBeenCalled ( ) ;
32
+ trigger ( elm , 'touchend' , { stopPropagation : stopSpy } ) ;
33
+ expect ( stopSpy ) . not . toHaveBeenCalled ( ) ;
34
+ } ) ;
35
+ it ( 'should stop propagation with option' , function ( ) {
36
+ setup ( {
37
+ stopPropagation : true
38
+ } ) ;
39
+ var stopSpy = jasmine . createSpy ( 'stop' ) ;
40
+
41
+ trigger ( elm , 'touchstart' , { stopPropagation : stopSpy } ) ;
42
+ expect ( stopSpy ) . toHaveBeenCalled ( ) ;
43
+ stopSpy . reset ( ) ;
44
+
45
+ trigger ( elm , 'touchmove' , { stopPropagation : stopSpy } ) ;
46
+ expect ( stopSpy ) . toHaveBeenCalled ( ) ;
47
+ stopSpy . reset ( ) ;
48
+
49
+ trigger ( elm , 'touchend' , { stopPropagation : stopSpy } ) ;
50
+ expect ( stopSpy ) . toHaveBeenCalled ( ) ;
51
+ } ) ;
24
52
it ( 'should mouse and touch by default' , function ( ) {
25
53
setup ( { } ) ;
26
54
27
55
trigger ( elm , 'mousedown' ) ;
28
- expect ( spy ) . toHaveBeenCalled ( ) ;
29
- spy . reset ( ) ;
56
+ expect ( dragSpy ) . toHaveBeenCalled ( ) ;
57
+ dragSpy . reset ( ) ;
30
58
31
59
trigger ( elm , 'touchstart' ) ;
32
- expect ( spy ) . toHaveBeenCalled ( ) ;
60
+ expect ( dragSpy ) . toHaveBeenCalled ( ) ;
33
61
} ) ;
34
62
it ( 'should not listen to mouse events with option' , function ( ) {
35
63
setup ( {
36
64
mouse : false
37
65
} ) ;
38
66
39
67
trigger ( elm , 'mousedown' ) ;
40
- expect ( spy ) . not . toHaveBeenCalled ( ) ;
68
+ expect ( dragSpy ) . not . toHaveBeenCalled ( ) ;
41
69
42
70
trigger ( elm , 'touchstart' ) ;
43
- expect ( spy ) . toHaveBeenCalled ( ) ;
71
+ expect ( dragSpy ) . toHaveBeenCalled ( ) ;
44
72
} ) ;
45
73
it ( 'should not listen to touch events with option' , function ( ) {
46
74
setup ( {
47
75
touch : false
48
76
} ) ;
49
77
50
78
trigger ( elm , 'mousedown' ) ;
51
- expect ( spy ) . toHaveBeenCalled ( ) ;
52
- spy . reset ( ) ;
79
+ expect ( dragSpy ) . toHaveBeenCalled ( ) ;
80
+ dragSpy . reset ( ) ;
53
81
54
82
trigger ( elm , 'touchstart' ) ;
55
- expect ( spy ) . not . toHaveBeenCalled ( ) ;
83
+ expect ( dragSpy ) . not . toHaveBeenCalled ( ) ;
56
84
} ) ;
57
85
} ) ;
58
86
0 commit comments