|
23 | 23 | uiGridScrollerConstants = _uiGridScrollerConstants_;
|
24 | 24 | gridUtil = _gridUtil_;
|
25 | 25 | });
|
26 |
| - |
27 |
| - spyOn(window, 'requestAnimationFrame').and.callFake(angular.noop); |
28 | 26 | });
|
29 | 27 |
|
30 | 28 | describe('when gridUtils.isTouchEnabled returns true', function() {
|
31 |
| - var preventDefaultSpy; |
32 |
| - |
33 | 29 | beforeEach(function() {
|
34 | 30 | 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 |
| - // }); |
66 | 31 | uiGridScroller(element, scrollHandler);
|
67 | 32 | });
|
68 | 33 | it('should initialize uiGridScroller.initiated to NONE', function() {
|
|
71 | 36 | xdescribe('events', function() {
|
72 | 37 | describe('on touchstart', function() {
|
73 | 38 | 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 | + }); |
74 | 47 | uiGridScroller(element, scrollHandler);
|
75 | 48 | });
|
76 | 49 | it('should be initialized', function() {
|
|
79 | 52 | it('should remove the scroll event from the element', function() {
|
80 | 53 | expect(element.off).toHaveBeenCalledWith('scroll', scrollHandler);
|
81 | 54 | });
|
| 55 | + it('should update the uiGridScroller.initiated value to TOUCHABLE', function() { |
| 56 | + expect(uiGridScroller.initiated).toEqual(uiGridScrollerConstants.scrollType.TOUCHABLE); |
| 57 | + }); |
| 58 | + afterEach(function() { |
| 59 | + element.on.and.callFake(angular.noop); |
| 60 | + }); |
82 | 61 | });
|
83 |
| - xdescribe('on touchmove', function() { |
| 62 | + describe('on touchmove', function() { |
| 63 | + var preventDefaultSpy; |
| 64 | + |
84 | 65 | beforeEach(function() {
|
85 |
| - uiGridScroller.initiated = uiGridScrollerConstants.scrollType.TOUCHABLE; |
86 |
| - uiGridScroller(element, scrollHandler); |
| 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 | + }); |
87 | 76 | });
|
88 | 77 | it('should be initialized', function() {
|
89 | 78 | expect(element.on).toHaveBeenCalledWith('touchmove', jasmine.any(Function));
|
90 | 79 | });
|
91 |
| - it('should prevent the default behavior', function() { |
92 |
| - expect(preventDefaultSpy).toHaveBeenCalled(); |
| 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 | + }); |
| 91 | + }); |
| 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 | + }); |
93 | 103 | });
|
94 |
| - it('should call the scrollHandler', function() { |
95 |
| - expect(scrollHandler).toHaveBeenCalled(); |
| 104 | + afterEach(function() { |
| 105 | + element.on.and.callFake(angular.noop); |
96 | 106 | });
|
97 | 107 | });
|
98 | 108 | function testEndFunction() {
|
99 |
| - xdescribe('when the uiGridScroller has been initiated with a touch event', function() { |
| 109 | + describe('when the uiGridScroller has been initiated with a touch event', function() { |
100 | 110 | beforeEach(function() {
|
101 | 111 | uiGridScroller.initiated = uiGridScrollerConstants.scrollType.TOUCHABLE;
|
102 | 112 | uiGridScroller(element, scrollHandler);
|
|
105 | 115 | expect(uiGridScroller.initiated).toEqual(uiGridScrollerConstants.scrollType.NONE);
|
106 | 116 | });
|
107 | 117 | });
|
| 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 | + }); |
108 | 130 | }
|
109 | 131 | describe('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 | + }); |
110 | 142 | it('should be initialized', function() {
|
111 | 143 | expect(element.on).toHaveBeenCalledWith('touchend', jasmine.any(Function));
|
112 | 144 | });
|
113 | 145 | testEndFunction();
|
114 | 146 | });
|
115 | 147 | describe('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 | + }); |
116 | 158 | it('should be initialized', function() {
|
117 | 159 | expect(element.on).toHaveBeenCalledWith('touchcancel', jasmine.any(Function));
|
118 | 160 | });
|
|
0 commit comments