Skip to content

Commit e98503a

Browse files
Portugal, MarceloPortugal, Marcelo
authored andcommitted
test(scroller): Updating scroller factory tests.
1 parent 2ec8a4f commit e98503a

File tree

1 file changed

+45
-84
lines changed

1 file changed

+45
-84
lines changed

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

Lines changed: 45 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,54 @@
2323
uiGridScrollerConstants = _uiGridScrollerConstants_;
2424
gridUtil = _gridUtil_;
2525
});
26+
27+
spyOn(window, 'requestAnimationFrame').and.callFake(angular.noop);
2628
});
2729

2830
describe('when gridUtils.isTouchEnabled returns true', function() {
31+
var preventDefaultSpy;
32+
2933
beforeEach(function() {
3034
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+
});
3166
uiGridScroller(element, scrollHandler);
3267
});
3368
it('should initialize uiGridScroller.initiated to NONE', function() {
3469
expect(uiGridScroller.initiated).toEqual(uiGridScrollerConstants.scrollType.NONE);
3570
});
36-
xdescribe('events', function() {
71+
describe('events', function() {
3772
describe('on touchstart', function() {
3873
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-
});
4774
uiGridScroller(element, scrollHandler);
4875
});
4976
it('should be initialized', function() {
@@ -52,57 +79,23 @@
5279
it('should remove the scroll event from the element', function() {
5380
expect(element.off).toHaveBeenCalledWith('scroll', scrollHandler);
5481
});
55-
it('should update the uiGridScroller.initiated value to TOUCHABLE', function() {
56-
expect(uiGridScroller.initiated).toEqual(uiGridScrollerConstants.scrollType.TOUCHABLE);
57-
});
5882
afterEach(function() {
5983
element.on.and.callFake(angular.noop);
6084
});
6185
});
62-
xdescribe('on touchmove', function() {
63-
var preventDefaultSpy;
64-
86+
describe('on touchmove', function() {
6587
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);
7690
});
7791
it('should be initialized', function() {
7892
expect(element.on).toHaveBeenCalledWith('touchmove', jasmine.any(Function));
7993
});
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();
9196
});
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();
10699
});
107100
});
108101
function testEndFunction() {
@@ -115,46 +108,14 @@
115108
expect(uiGridScroller.initiated).toEqual(uiGridScrollerConstants.scrollType.NONE);
116109
});
117110
});
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-
});
130111
}
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() {
142113
it('should be initialized', function() {
143114
expect(element.on).toHaveBeenCalledWith('touchend', jasmine.any(Function));
144115
});
145116
testEndFunction();
146117
});
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() {
158119
it('should be initialized', function() {
159120
expect(element.on).toHaveBeenCalledWith('touchcancel', jasmine.any(Function));
160121
});

0 commit comments

Comments
 (0)