test(refresher): fix refresher unit tests

This commit is contained in:
Adam Bradley
2016-02-29 13:27:44 -06:00
parent 4e3604e3ed
commit d39f21f410
2 changed files with 13 additions and 3 deletions

View File

@ -302,12 +302,13 @@ export class Refresher {
// this refresh is not already actively pulling down // this refresh is not already actively pulling down
// get the content's scrollTop // get the content's scrollTop
let scrollHostScrollTop = this._content.scrollElement.scrollTop; let scrollHostScrollTop = this._content.getContentDimensions().scrollTop;
// if the scrollTop is greater than zero then it's // if the scrollTop is greater than zero then it's
// not possible to pull the content down yet // not possible to pull the content down yet
if (scrollHostScrollTop > 0) { if (scrollHostScrollTop > 0) {
this.progress = 0; this.progress = 0;
this.startY = null;
return 7; return 7;
} }

View File

@ -119,6 +119,8 @@ describe('Refresher', () => {
let result = refresher._onMove( touchEv(125) ); let result = refresher._onMove( touchEv(125) );
expect(refresher.state).toEqual('inactive'); expect(refresher.state).toEqual('inactive');
expect(refresher.progress).toEqual(0);
expect(refresher.startY).toEqual(null);
expect(result).toEqual(7); expect(result).toEqual(7);
}); });
@ -153,13 +155,16 @@ describe('Refresher', () => {
}); });
it('should set the deltaY', () => { it('should set the deltaY', () => {
setContentScrollTop(1);
refresher.startY = 100; refresher.startY = 100;
refresher._onMove( touchEv(133) ); refresher._onMove( touchEv(133) );
expect(refresher.deltaY).toEqual(33); expect(refresher.deltaY).toEqual(33);
refresher._lastCheck = 0; // force allow next check refresher._lastCheck = 0; // force allow next check
refresher.startY = 100;
refresher._onMove( touchEv(50) ); var results = refresher._onMove( touchEv(50) );
expect(results).toEqual(6);
expect(refresher.deltaY).toEqual(-50); expect(refresher.deltaY).toEqual(-50);
}); });
@ -245,7 +250,11 @@ describe('Refresher', () => {
} }
function setContentScrollTop(scrollTop) { function setContentScrollTop(scrollTop) {
contentElementRef.nativeElement.scrollTop = scrollTop; content.getContentDimensions = function() {
return {
scrollTop: scrollTop
};
};
} }
function getScrollElementStyles() { function getScrollElementStyles() {