|
23 | 23 | uiGridScrollerConstants = _uiGridScrollerConstants_; |
24 | 24 | gridUtil = _gridUtil_; |
25 | 25 | }); |
| 26 | + |
| 27 | + spyOn(window, 'requestAnimationFrame').and.callFake(angular.noop); |
26 | 28 | }); |
27 | 29 |
|
28 | 30 | describe('when gridUtils.isTouchEnabled returns true', function() { |
| 31 | + var preventDefaultSpy; |
| 32 | + |
29 | 33 | beforeEach(function() { |
30 | 34 | spyOn(gridUtil, 'isTouchEnabled').and.returnValue(true); |
| 35 | + preventDefaultSpy = jasmine.createSpy('preventDefault'); |
| 36 | + |
| 37 | + element.on.and.callFake(function(eventName, callback) { |
| 38 | + switch (eventName) { |
| 39 | + case 'touchstart': |
| 40 | + callback({ |
| 41 | + type: eventName, |
| 42 | + touches: [true] |
| 43 | + }); |
| 44 | + break; |
| 45 | + case 'touchmove': |
| 46 | + callback({ |
| 47 | + type: eventName, |
| 48 | + touches: [true], |
| 49 | + preventDefault: preventDefaultSpy |
| 50 | + }); |
| 51 | + break; |
| 52 | + case 'touchend': |
| 53 | + callback({ |
| 54 | + type: eventName, |
| 55 | + touches: [true] |
| 56 | + }); |
| 57 | + break; |
| 58 | + case 'touchcancel': |
| 59 | + callback({ |
| 60 | + type: eventName, |
| 61 | + touches: [true] |
| 62 | + }); |
| 63 | + break; |
| 64 | + } |
| 65 | + }); |
31 | 66 | uiGridScroller(element, scrollHandler); |
32 | 67 | }); |
33 | 68 | it('should initialize uiGridScroller.initiated to NONE', function() { |
34 | 69 | expect(uiGridScroller.initiated).toEqual(uiGridScrollerConstants.scrollType.NONE); |
35 | 70 | }); |
36 | | - xdescribe('events', function() { |
| 71 | + describe('events', function() { |
37 | 72 | describe('on touchstart', function() { |
38 | 73 | beforeEach(function() { |
39 | | - element.on.and.callFake(function(eventName, callback) { |
40 | | - if (eventName === 'touchstart') { |
41 | | - callback({ |
42 | | - type: eventName, |
43 | | - touches: [true] |
44 | | - }); |
45 | | - } |
46 | | - }); |
47 | 74 | uiGridScroller(element, scrollHandler); |
48 | 75 | }); |
49 | 76 | it('should be initialized', function() { |
|
52 | 79 | it('should remove the scroll event from the element', function() { |
53 | 80 | expect(element.off).toHaveBeenCalledWith('scroll', scrollHandler); |
54 | 81 | }); |
55 | | - it('should update the uiGridScroller.initiated value to TOUCHABLE', function() { |
56 | | - expect(uiGridScroller.initiated).toEqual(uiGridScrollerConstants.scrollType.TOUCHABLE); |
57 | | - }); |
58 | 82 | afterEach(function() { |
59 | 83 | element.on.and.callFake(angular.noop); |
60 | 84 | }); |
61 | 85 | }); |
62 | | - xdescribe('on touchmove', function() { |
63 | | - var preventDefaultSpy; |
64 | | - |
| 86 | + describe('on touchmove', function() { |
65 | 87 | beforeEach(function() { |
66 | | - preventDefaultSpy = jasmine.createSpy('preventDefault'); |
67 | | - element.on.and.callFake(function(eventName, callback) { |
68 | | - if (eventName === 'touchmove') { |
69 | | - callback({ |
70 | | - type: eventName, |
71 | | - touches: [true], |
72 | | - preventDefault: preventDefaultSpy |
73 | | - }); |
74 | | - } |
75 | | - }); |
| 88 | + uiGridScroller.initiated = uiGridScrollerConstants.scrollType.TOUCHABLE; |
| 89 | + uiGridScroller(element, scrollHandler); |
76 | 90 | }); |
77 | 91 | it('should be initialized', function() { |
78 | 92 | expect(element.on).toHaveBeenCalledWith('touchmove', jasmine.any(Function)); |
79 | 93 | }); |
80 | | - describe('when the uiGridScroller has been initiated with a touch event', function() { |
81 | | - beforeEach(function() { |
82 | | - uiGridScroller.initiated = uiGridScrollerConstants.scrollType.TOUCHABLE; |
83 | | - uiGridScroller(element, scrollHandler); |
84 | | - }); |
85 | | - it('should prevent the default behavior', function() { |
86 | | - expect(preventDefaultSpy).toHaveBeenCalled(); |
87 | | - }); |
88 | | - it('should call the scrollHandler', function() { |
89 | | - expect(scrollHandler).toHaveBeenCalled(); |
90 | | - }); |
| 94 | + it('should prevent the default behavior', function() { |
| 95 | + expect(preventDefaultSpy).toHaveBeenCalled(); |
91 | 96 | }); |
92 | | - describe('when the uiGridScroller has not been initiated with a touch event', function() { |
93 | | - beforeEach(function() { |
94 | | - uiGridScroller.initiated = uiGridScrollerConstants.scrollType.NONE; |
95 | | - uiGridScroller(element, scrollHandler); |
96 | | - }); |
97 | | - it('should prevent the default behavior', function() { |
98 | | - expect(preventDefaultSpy).toHaveBeenCalled(); |
99 | | - }); |
100 | | - it('should not call the scrollHandler', function() { |
101 | | - expect(scrollHandler).not.toHaveBeenCalled(); |
102 | | - }); |
103 | | - }); |
104 | | - afterEach(function() { |
105 | | - element.on.and.callFake(angular.noop); |
| 97 | + it('should call the scrollHandler', function() { |
| 98 | + expect(scrollHandler).toHaveBeenCalled(); |
106 | 99 | }); |
107 | 100 | }); |
108 | 101 | function testEndFunction() { |
|
115 | 108 | expect(uiGridScroller.initiated).toEqual(uiGridScrollerConstants.scrollType.NONE); |
116 | 109 | }); |
117 | 110 | }); |
118 | | - describe('when the uiGridScroller has not been initiated with a touch event', function() { |
119 | | - beforeEach(function() { |
120 | | - uiGridScroller.initiated = uiGridScrollerConstants.scrollType.MOUSE; |
121 | | - uiGridScroller(element, scrollHandler); |
122 | | - }); |
123 | | - it('should not update the uiGridScroller.initiated value', function() { |
124 | | - expect(uiGridScroller.initiated).toEqual(uiGridScrollerConstants.scrollType.MOUSE); |
125 | | - }); |
126 | | - }); |
127 | | - afterEach(function() { |
128 | | - element.on.and.callFake(angular.noop); |
129 | | - }); |
130 | 111 | } |
131 | | - xdescribe('on touchend', function() { |
132 | | - beforeEach(function() { |
133 | | - element.on.and.callFake(function(eventName, callback) { |
134 | | - if (eventName === 'touchend') { |
135 | | - callback({ |
136 | | - type: eventName, |
137 | | - touches: [true] |
138 | | - }); |
139 | | - } |
140 | | - }); |
141 | | - }); |
| 112 | + describe('on touchend', function() { |
142 | 113 | it('should be initialized', function() { |
143 | 114 | expect(element.on).toHaveBeenCalledWith('touchend', jasmine.any(Function)); |
144 | 115 | }); |
145 | 116 | testEndFunction(); |
146 | 117 | }); |
147 | | - xdescribe('on touchcancel', function() { |
148 | | - beforeEach(function() { |
149 | | - element.on.and.callFake(function(eventName, callback) { |
150 | | - if (eventName === 'touchcancel') { |
151 | | - callback({ |
152 | | - type: eventName, |
153 | | - touches: [true] |
154 | | - }); |
155 | | - } |
156 | | - }); |
157 | | - }); |
| 118 | + describe('on touchcancel', function() { |
158 | 119 | it('should be initialized', function() { |
159 | 120 | expect(element.on).toHaveBeenCalledWith('touchcancel', jasmine.any(Function)); |
160 | 121 | }); |
|
0 commit comments