mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-18 19:21:34 +08:00
navController setViews test
This commit is contained in:
@ -1,19 +1,19 @@
|
|||||||
import {
|
// import {
|
||||||
ddescribe,
|
// ddescribe,
|
||||||
describe,
|
// describe,
|
||||||
xdescribe,
|
// xdescribe,
|
||||||
it,
|
// it,
|
||||||
iit,
|
// iit,
|
||||||
xit,
|
// xit,
|
||||||
expect,
|
// expect,
|
||||||
beforeEach,
|
// beforeEach,
|
||||||
afterEach,
|
// afterEach,
|
||||||
AsyncTestCompleter,
|
// AsyncTestCompleter,
|
||||||
inject,
|
// inject,
|
||||||
beforeEachBindings
|
// beforeEachBindings
|
||||||
} from 'angular2/test';
|
// } from 'angular2/test';
|
||||||
|
|
||||||
import {Compiler} from 'angular2/angular2';
|
// import {Compiler} from 'angular2/angular2';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
NavController,
|
NavController,
|
||||||
@ -23,18 +23,43 @@ import {
|
|||||||
} from 'ionic/ionic';
|
} from 'ionic/ionic';
|
||||||
|
|
||||||
|
|
||||||
@Page({
|
|
||||||
template: ''
|
|
||||||
})
|
|
||||||
class SomePage {}
|
|
||||||
|
|
||||||
export function run() {
|
export function run() {
|
||||||
describe("NavController", () => {
|
describe("NavController", () => {
|
||||||
let nav;
|
let nav;
|
||||||
|
|
||||||
beforeEach(inject([Compiler], compiler => {
|
class FirstPage {}
|
||||||
nav = new NavController(null, null, new IonicConfig(), null, compiler, null, null, null);
|
class SecondPage {}
|
||||||
}));
|
class ThirdPage {}
|
||||||
|
|
||||||
|
function mockTransitionFn(enteringView, leavingView, opts, cb) {
|
||||||
|
let destroys = [];
|
||||||
|
|
||||||
|
nav._views.forEach(view => {
|
||||||
|
if (view) {
|
||||||
|
if (view.shouldDestroy) {
|
||||||
|
destroys.push(view);
|
||||||
|
|
||||||
|
} else if (view.state === 2 && view.shouldCache) {
|
||||||
|
view.shouldCache = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
destroys.forEach(view => {
|
||||||
|
nav.remove(view);
|
||||||
|
view.destroy();
|
||||||
|
});
|
||||||
|
cb();
|
||||||
|
}
|
||||||
|
|
||||||
|
function mockCanGoBackFn() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// beforeEach(inject([Compiler], compiler => {
|
||||||
|
beforeEach(() => {
|
||||||
|
nav = new NavController(null, null, new IonicConfig(), null, null, null, null, null);
|
||||||
|
});
|
||||||
|
|
||||||
it('should exist', () => {
|
it('should exist', () => {
|
||||||
expect(nav).not.toBeUndefined();
|
expect(nav).not.toBeUndefined();
|
||||||
@ -93,13 +118,62 @@ export function run() {
|
|||||||
expect(push).toThrow();
|
expect(push).toThrow();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('be successful', () => {
|
it('to add the pushed page to the nav stack', (done) => {
|
||||||
expect(SomePage).toBeDefined();
|
expect(FirstPage).toBeDefined();
|
||||||
|
expect(nav._views.length).toBe(0);
|
||||||
|
|
||||||
nav.push(SomePage, {}, {});
|
spyOn(nav, 'add').and.callThrough();
|
||||||
|
|
||||||
|
nav.transition = mockTransitionFn;
|
||||||
|
nav.push(FirstPage, {}, {}).then(() => {
|
||||||
|
expect(nav.add).toHaveBeenCalled();
|
||||||
|
expect(nav._views.length).toBe(1);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("setViews", () => {
|
||||||
|
it('should return a resolved Promise if components is falsy', done => {
|
||||||
|
let s = jasmine.createSpy('success');
|
||||||
|
let f = jasmine.createSpy('fail');
|
||||||
|
|
||||||
|
let promise = nav.setViews();
|
||||||
|
|
||||||
|
promise.then(s, f).then(() => {
|
||||||
|
expect(s).toHaveBeenCalled();
|
||||||
|
expect(f).not.toHaveBeenCalled();
|
||||||
|
done();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
})
|
it('replace views with the supplied views', () => {
|
||||||
});
|
let vc1 = new ViewController(),
|
||||||
|
vc2 = new ViewController(),
|
||||||
|
vc3 = new ViewController();
|
||||||
|
nav._views = [vc1, vc2, vc3];
|
||||||
|
let arr = [FirstPage, SecondPage, ThirdPage];
|
||||||
|
|
||||||
|
nav.transition = mockTransitionFn;
|
||||||
|
nav.setViews(arr);
|
||||||
|
|
||||||
|
//_views[0] will be transitioned out of
|
||||||
|
expect(nav._views[1].componentType).toBe(FirstPage);
|
||||||
|
expect(nav._views[2].componentType).toBe(SecondPage);
|
||||||
|
expect(nav._views[3].componentType).toBe(ThirdPage);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user