From e98503a80d53ae8e5d261dc4da70d3e37016ad28 Mon Sep 17 00:00:00 2001 From: "Portugal, Marcelo" Date: Thu, 8 Dec 2016 20:45:25 -0500 Subject: [PATCH] test(scroller): Updating scroller factory tests. --- .../ui-grid-custom-scroller.factory.spec.js | 129 ++++++------------ 1 file changed, 45 insertions(+), 84 deletions(-) diff --git a/src/features/custom-scrolling/test/ui-grid-custom-scroller.factory.spec.js b/src/features/custom-scrolling/test/ui-grid-custom-scroller.factory.spec.js index cc6f1982ae..d432bfdde3 100644 --- a/src/features/custom-scrolling/test/ui-grid-custom-scroller.factory.spec.js +++ b/src/features/custom-scrolling/test/ui-grid-custom-scroller.factory.spec.js @@ -23,27 +23,54 @@ uiGridScrollerConstants = _uiGridScrollerConstants_; gridUtil = _gridUtil_; }); + + spyOn(window, 'requestAnimationFrame').and.callFake(angular.noop); }); describe('when gridUtils.isTouchEnabled returns true', function() { + var preventDefaultSpy; + beforeEach(function() { spyOn(gridUtil, 'isTouchEnabled').and.returnValue(true); + preventDefaultSpy = jasmine.createSpy('preventDefault'); + + element.on.and.callFake(function(eventName, callback) { + switch (eventName) { + case 'touchstart': + callback({ + type: eventName, + touches: [true] + }); + break; + case 'touchmove': + callback({ + type: eventName, + touches: [true], + preventDefault: preventDefaultSpy + }); + break; + case 'touchend': + callback({ + type: eventName, + touches: [true] + }); + break; + case 'touchcancel': + callback({ + type: eventName, + touches: [true] + }); + break; + } + }); uiGridScroller(element, scrollHandler); }); it('should initialize uiGridScroller.initiated to NONE', function() { expect(uiGridScroller.initiated).toEqual(uiGridScrollerConstants.scrollType.NONE); }); - xdescribe('events', function() { + describe('events', function() { describe('on touchstart', function() { beforeEach(function() { - element.on.and.callFake(function(eventName, callback) { - if (eventName === 'touchstart') { - callback({ - type: eventName, - touches: [true] - }); - } - }); uiGridScroller(element, scrollHandler); }); it('should be initialized', function() { @@ -52,57 +79,23 @@ it('should remove the scroll event from the element', function() { expect(element.off).toHaveBeenCalledWith('scroll', scrollHandler); }); - it('should update the uiGridScroller.initiated value to TOUCHABLE', function() { - expect(uiGridScroller.initiated).toEqual(uiGridScrollerConstants.scrollType.TOUCHABLE); - }); afterEach(function() { element.on.and.callFake(angular.noop); }); }); - xdescribe('on touchmove', function() { - var preventDefaultSpy; - + describe('on touchmove', function() { beforeEach(function() { - preventDefaultSpy = jasmine.createSpy('preventDefault'); - element.on.and.callFake(function(eventName, callback) { - if (eventName === 'touchmove') { - callback({ - type: eventName, - touches: [true], - preventDefault: preventDefaultSpy - }); - } - }); + uiGridScroller.initiated = uiGridScrollerConstants.scrollType.TOUCHABLE; + uiGridScroller(element, scrollHandler); }); it('should be initialized', function() { expect(element.on).toHaveBeenCalledWith('touchmove', jasmine.any(Function)); }); - describe('when the uiGridScroller has been initiated with a touch event', function() { - beforeEach(function() { - uiGridScroller.initiated = uiGridScrollerConstants.scrollType.TOUCHABLE; - uiGridScroller(element, scrollHandler); - }); - it('should prevent the default behavior', function() { - expect(preventDefaultSpy).toHaveBeenCalled(); - }); - it('should call the scrollHandler', function() { - expect(scrollHandler).toHaveBeenCalled(); - }); + it('should prevent the default behavior', function() { + expect(preventDefaultSpy).toHaveBeenCalled(); }); - describe('when the uiGridScroller has not been initiated with a touch event', function() { - beforeEach(function() { - uiGridScroller.initiated = uiGridScrollerConstants.scrollType.NONE; - uiGridScroller(element, scrollHandler); - }); - it('should prevent the default behavior', function() { - expect(preventDefaultSpy).toHaveBeenCalled(); - }); - it('should not call the scrollHandler', function() { - expect(scrollHandler).not.toHaveBeenCalled(); - }); - }); - afterEach(function() { - element.on.and.callFake(angular.noop); + it('should call the scrollHandler', function() { + expect(scrollHandler).toHaveBeenCalled(); }); }); function testEndFunction() { @@ -115,46 +108,14 @@ expect(uiGridScroller.initiated).toEqual(uiGridScrollerConstants.scrollType.NONE); }); }); - describe('when the uiGridScroller has not been initiated with a touch event', function() { - beforeEach(function() { - uiGridScroller.initiated = uiGridScrollerConstants.scrollType.MOUSE; - uiGridScroller(element, scrollHandler); - }); - it('should not update the uiGridScroller.initiated value', function() { - expect(uiGridScroller.initiated).toEqual(uiGridScrollerConstants.scrollType.MOUSE); - }); - }); - afterEach(function() { - element.on.and.callFake(angular.noop); - }); } - xdescribe('on touchend', function() { - beforeEach(function() { - element.on.and.callFake(function(eventName, callback) { - if (eventName === 'touchend') { - callback({ - type: eventName, - touches: [true] - }); - } - }); - }); + describe('on touchend', function() { it('should be initialized', function() { expect(element.on).toHaveBeenCalledWith('touchend', jasmine.any(Function)); }); testEndFunction(); }); - xdescribe('on touchcancel', function() { - beforeEach(function() { - element.on.and.callFake(function(eventName, callback) { - if (eventName === 'touchcancel') { - callback({ - type: eventName, - touches: [true] - }); - } - }); - }); + describe('on touchcancel', function() { it('should be initialized', function() { expect(element.on).toHaveBeenCalledWith('touchcancel', jasmine.any(Function)); });