Skip to content

Commit 2a7ab73

Browse files
Portugal, MarceloPortugal, Marcelo
authored andcommitted
test(scroller): Updating factory tests to fix build.
1 parent e424b60 commit 2a7ab73

File tree

1 file changed

+85
-43
lines changed

1 file changed

+85
-43
lines changed

src/features/custom-scrolling/test/ui-grid-custom-scroller.factory.spec.js

Lines changed: 85 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -23,46 +23,11 @@
2323
uiGridScrollerConstants = _uiGridScrollerConstants_;
2424
gridUtil = _gridUtil_;
2525
});
26-
27-
spyOn(window, 'requestAnimationFrame').and.callFake(angular.noop);
2826
});
2927

3028
describe('when gridUtils.isTouchEnabled returns true', function() {
31-
var preventDefaultSpy;
32-
3329
beforeEach(function() {
3430
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-
// });
6631
uiGridScroller(element, scrollHandler);
6732
});
6833
it('should initialize uiGridScroller.initiated to NONE', function() {
@@ -71,6 +36,14 @@
7136
xdescribe('events', function() {
7237
describe('on touchstart', function() {
7338
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+
});
7447
uiGridScroller(element, scrollHandler);
7548
});
7649
it('should be initialized', function() {
@@ -79,24 +52,61 @@
7952
it('should remove the scroll event from the element', function() {
8053
expect(element.off).toHaveBeenCalledWith('scroll', scrollHandler);
8154
});
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+
});
8261
});
83-
xdescribe('on touchmove', function() {
62+
describe('on touchmove', function() {
63+
var preventDefaultSpy;
64+
8465
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+
});
8776
});
8877
it('should be initialized', function() {
8978
expect(element.on).toHaveBeenCalledWith('touchmove', jasmine.any(Function));
9079
});
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+
});
93103
});
94-
it('should call the scrollHandler', function() {
95-
expect(scrollHandler).toHaveBeenCalled();
104+
afterEach(function() {
105+
element.on.and.callFake(angular.noop);
96106
});
97107
});
98108
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() {
100110
beforeEach(function() {
101111
uiGridScroller.initiated = uiGridScrollerConstants.scrollType.TOUCHABLE;
102112
uiGridScroller(element, scrollHandler);
@@ -105,14 +115,46 @@
105115
expect(uiGridScroller.initiated).toEqual(uiGridScrollerConstants.scrollType.NONE);
106116
});
107117
});
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+
});
108130
}
109131
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+
});
110142
it('should be initialized', function() {
111143
expect(element.on).toHaveBeenCalledWith('touchend', jasmine.any(Function));
112144
});
113145
testEndFunction();
114146
});
115147
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+
});
116158
it('should be initialized', function() {
117159
expect(element.on).toHaveBeenCalledWith('touchcancel', jasmine.any(Function));
118160
});

0 commit comments

Comments
 (0)