From e7f55042bd9b8a1b45dd18c97c75e84afeb343f5 Mon Sep 17 00:00:00 2001 From: Tim Lancina Date: Thu, 8 Oct 2015 15:54:25 -0500 Subject: [PATCH] navController setViews test --- .../nav/test/nav-controller.spec.ts | 130 ++++++++++++++---- 1 file changed, 102 insertions(+), 28 deletions(-) diff --git a/ionic/components/nav/test/nav-controller.spec.ts b/ionic/components/nav/test/nav-controller.spec.ts index 70c965074e..12ba26bb53 100644 --- a/ionic/components/nav/test/nav-controller.spec.ts +++ b/ionic/components/nav/test/nav-controller.spec.ts @@ -1,19 +1,19 @@ -import { - ddescribe, - describe, - xdescribe, - it, - iit, - xit, - expect, - beforeEach, - afterEach, - AsyncTestCompleter, - inject, - beforeEachBindings -} from 'angular2/test'; +// import { +// ddescribe, +// describe, +// xdescribe, +// it, +// iit, +// xit, +// expect, +// beforeEach, +// afterEach, +// AsyncTestCompleter, +// inject, +// beforeEachBindings +// } from 'angular2/test'; -import {Compiler} from 'angular2/angular2'; +// import {Compiler} from 'angular2/angular2'; import { NavController, @@ -23,18 +23,43 @@ import { } from 'ionic/ionic'; -@Page({ - template: '' -}) -class SomePage {} - export function run() { describe("NavController", () => { let nav; - beforeEach(inject([Compiler], compiler => { - nav = new NavController(null, null, new IonicConfig(), null, compiler, null, null, null); - })); + class FirstPage {} + 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', () => { expect(nav).not.toBeUndefined(); @@ -93,13 +118,62 @@ export function run() { expect(push).toThrow(); }); - it('be successful', () => { - expect(SomePage).toBeDefined(); + it('to add the pushed page to the nav stack', (done) => { + 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); + }); + + }); + + + + + + + + + + + + }); }