mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-22 21:48:42 +08:00
test(ngmodule): update to ngmodule
This commit is contained in:
@ -1,11 +1,11 @@
|
||||
import { Component, ViewChild } from '@angular/core';
|
||||
import { ionicBootstrap, InfiniteScroll, NavController } from '../../../../../src';
|
||||
import { Component, ViewChild, NgModule } from '@angular/core';
|
||||
import { IonicApp, IonicModule, InfiniteScroll, NavController } from '../../../..';
|
||||
|
||||
|
||||
@Component({
|
||||
templateUrl: 'main.html'
|
||||
})
|
||||
class E2EPage1 {
|
||||
export class E2EPage1 {
|
||||
@ViewChild(InfiniteScroll) infiniteScroll: InfiniteScroll;
|
||||
items: number[] = [];
|
||||
enabled: boolean = true;
|
||||
@ -48,7 +48,7 @@ class E2EPage1 {
|
||||
@Component({
|
||||
template: '<ion-content><button ion-button (click)="navCtrl.pop()">Pop</button></ion-content>'
|
||||
})
|
||||
class E2EPage2 {
|
||||
export class E2EPage2 {
|
||||
constructor(public navCtrl: NavController) {}
|
||||
}
|
||||
|
||||
@ -56,11 +56,27 @@ class E2EPage2 {
|
||||
@Component({
|
||||
template: '<ion-nav [root]="root"></ion-nav>'
|
||||
})
|
||||
class E2EApp {
|
||||
export class E2EApp {
|
||||
root = E2EPage1;
|
||||
}
|
||||
|
||||
ionicBootstrap(E2EApp);
|
||||
@NgModule({
|
||||
declarations: [
|
||||
E2EApp,
|
||||
E2EPage1,
|
||||
E2EPage2
|
||||
],
|
||||
imports: [
|
||||
IonicModule.forRoot(E2EApp)
|
||||
],
|
||||
bootstrap: [IonicApp],
|
||||
entryComponents: [
|
||||
E2EApp,
|
||||
E2EPage1,
|
||||
E2EPage2
|
||||
]
|
||||
})
|
||||
export class AppModule {}
|
||||
|
||||
|
||||
function getAsyncData(): Promise<any[]> {
|
@ -1,6 +1,7 @@
|
||||
import { InfiniteScroll, Content, Config } from '../../../../src';
|
||||
import { Content } from '../../content/content';
|
||||
import { InfiniteScroll } from '../infinite-scroll';
|
||||
import { mockConfig, mockElementRef, mockRenderer, mockZone } from '../../../util/mock-providers';
|
||||
|
||||
export function run() {
|
||||
|
||||
describe('Infinite Scroll', () => {
|
||||
|
||||
@ -9,56 +10,57 @@ describe('Infinite Scroll', () => {
|
||||
it('should not set loading state when does not meet threshold', () => {
|
||||
setInfiniteScrollHeight(25);
|
||||
content.getContentDimensions = function() {
|
||||
return { scrollHeight: 1000, scrollTop: 350, contentHeight: 500 };
|
||||
return mockGetContentDimensions(1000, 350, 500);
|
||||
};
|
||||
|
||||
inf.threshold = '100px';
|
||||
|
||||
setInfiniteScrollTop(300);
|
||||
|
||||
var result = inf._onScroll(scrollEv());
|
||||
var result = inf._onScroll();
|
||||
expect(result).toEqual(6);
|
||||
});
|
||||
|
||||
it('should set loading state when meets threshold', () => {
|
||||
setInfiniteScrollHeight(25);
|
||||
content.getContentDimensions = function() {
|
||||
return { scrollHeight: 1000, scrollTop: 500, contentHeight: 500 };
|
||||
return mockGetContentDimensions(1000, 500, 500);
|
||||
};
|
||||
inf.threshold = '100px';
|
||||
|
||||
setInfiniteScrollTop(300);
|
||||
|
||||
var result = inf._onScroll(scrollEv());
|
||||
var result = inf._onScroll();
|
||||
expect(result).toEqual(5);
|
||||
});
|
||||
|
||||
it('should not run if there is not infinite element height', () => {
|
||||
setInfiniteScrollTop(0);
|
||||
var result = inf._onScroll(scrollEv());
|
||||
var result = inf._onScroll();
|
||||
expect(result).toEqual(3);
|
||||
});
|
||||
|
||||
it('should not run again if ran less than 32ms ago', () => {
|
||||
inf._lastCheck = Date.now();
|
||||
var result = inf._onScroll(scrollEv());
|
||||
var result = inf._onScroll();
|
||||
expect(result).toEqual(2);
|
||||
});
|
||||
|
||||
it('should not run if state is disabled', () => {
|
||||
inf.state = 'disabled';
|
||||
var result = inf._onScroll(scrollEv());
|
||||
var result = inf._onScroll();
|
||||
expect(result).toEqual(1);
|
||||
});
|
||||
|
||||
it('should not run if state is loading', () => {
|
||||
inf.state = 'loading';
|
||||
var result = inf._onScroll(scrollEv());
|
||||
var result = inf._onScroll();
|
||||
expect(result).toEqual(1);
|
||||
});
|
||||
|
||||
it('should not run if not enabled', () => {
|
||||
inf.state = 'disabled';
|
||||
var result = inf._onScroll(scrollEv());
|
||||
var result = inf._onScroll();
|
||||
expect(result).toEqual(1);
|
||||
});
|
||||
|
||||
@ -88,39 +90,22 @@ describe('Infinite Scroll', () => {
|
||||
});
|
||||
|
||||
|
||||
let config = new Config();
|
||||
let config = mockConfig();
|
||||
let inf: InfiniteScroll;
|
||||
let content: Content;
|
||||
let contentElementRef;
|
||||
let infiniteElementRef;
|
||||
let zone = {
|
||||
run: function(cb) {cb()},
|
||||
runOutsideAngular: function(cb) {cb()}
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
contentElementRef = mockElementRef();
|
||||
content = new Content(contentElementRef, config, null, null, null);
|
||||
content.scrollElement = document.createElement('scroll-content');
|
||||
content = new Content(config, contentElementRef, mockRenderer(), null, null, null, null, null);
|
||||
content._scrollEle = document.createElement('div');
|
||||
content._scrollEle.className = 'scroll-content';
|
||||
|
||||
infiniteElementRef = mockElementRef();
|
||||
inf = new InfiniteScroll(content, zone, infiniteElementRef);
|
||||
inf = new InfiniteScroll(content, mockZone(), infiniteElementRef);
|
||||
});
|
||||
|
||||
function scrollEv() {
|
||||
return {}
|
||||
}
|
||||
|
||||
function mockElementRef() {
|
||||
return {
|
||||
nativeElement: {
|
||||
classList: { add: function(){}, remove: function(){} },
|
||||
scrollTop: 0,
|
||||
hasAttribute: function(){}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function setInfiniteScrollTop(scrollTop) {
|
||||
infiniteElementRef.nativeElement.scrollTop = scrollTop;
|
||||
}
|
||||
@ -129,10 +114,22 @@ describe('Infinite Scroll', () => {
|
||||
infiniteElementRef.nativeElement.scrollHeight = scrollHeight;
|
||||
}
|
||||
|
||||
function getScrollElementStyles() {
|
||||
return content.scrollElement.style;
|
||||
function mockGetContentDimensions(scrollHeight, scrollTop, contentHeight) {
|
||||
return {
|
||||
scrollHeight: scrollHeight,
|
||||
scrollTop: scrollTop,
|
||||
contentHeight: contentHeight,
|
||||
|
||||
contentTop: null,
|
||||
contentBottom: null,
|
||||
contentWidth: null,
|
||||
contentLeft: null,
|
||||
contentRight: null,
|
||||
scrollBottom: null,
|
||||
scrollWidth: null,
|
||||
scrollLeft: null,
|
||||
scrollRight: null
|
||||
};
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
import { Component, ViewChild } from '@angular/core';
|
||||
import { ionicBootstrap, InfiniteScroll } from '../../../../../src';
|
||||
import { Component, NgModule } from '@angular/core';
|
||||
import { IonicApp, IonicModule, InfiniteScroll } from '../../../..';
|
||||
|
||||
|
||||
@Component({
|
||||
templateUrl: 'main.html'
|
||||
})
|
||||
class E2EPage {
|
||||
export class E2EPage {
|
||||
items: number[] = [];
|
||||
|
||||
constructor() {
|
||||
@ -36,11 +36,24 @@ class E2EPage {
|
||||
@Component({
|
||||
template: '<ion-nav [root]="rootPage"></ion-nav>'
|
||||
})
|
||||
class E2EApp {
|
||||
export class E2EApp {
|
||||
rootPage = E2EPage;
|
||||
}
|
||||
|
||||
ionicBootstrap(E2EApp);
|
||||
@NgModule({
|
||||
declarations: [
|
||||
E2EApp,
|
||||
E2EPage
|
||||
],
|
||||
imports: [
|
||||
IonicModule.forRoot(E2EApp)
|
||||
],
|
||||
bootstrap: [IonicApp],
|
||||
entryComponents: [
|
||||
E2EPage
|
||||
]
|
||||
})
|
||||
export class AppModule {}
|
||||
|
||||
function getAsyncData(): Promise<number[]> {
|
||||
// async return mock data
|
Reference in New Issue
Block a user