Skip to content

Commit

Permalink
fix(tabs): return promises where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
danbucholtz committed Oct 5, 2017
1 parent c963745 commit a77bb2c
Show file tree
Hide file tree
Showing 69 changed files with 1,109 additions and 194 deletions.
56 changes: 28 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 21 additions & 19 deletions src/components/app/test/app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('App', () => {

describe('goBack', () => {

it('should not select the previous tab', () => {
it('should not select the previous tab', (done: Function) => {
const nav = mockNavController();
app.registerRootNav(nav);

Expand All @@ -23,24 +23,26 @@ describe('App', () => {

nav.registerChildNav(tabs);

tabs.select(tab1);
tabs.select(tab2);

expect(tabs._selectHistory).toEqual([tab1.id, tab2.id]);

spyOn(plt, 'exitApp');
spyOn(tabs, 'select');
spyOn(tab1, 'pop');
spyOn(tab2, 'pop');
spyOn(portal, 'pop');

app.goBack();

expect(tabs.select).not.toHaveBeenCalled();
expect(tab1.pop).not.toHaveBeenCalled();
expect(tab2.pop).not.toHaveBeenCalled();
expect(portal.pop).not.toHaveBeenCalled();
expect(plt.exitApp).toHaveBeenCalled();
tabs.select(tab1).then(() => {
return tabs.select(tab2);
}).then(() => {
expect(tabs._selectHistory).toEqual([tab1.id, tab2.id]);
spyOn(plt, 'exitApp');
spyOn(tabs, 'select');
spyOn(tab1, 'pop');
spyOn(tab2, 'pop');
spyOn(portal, 'pop');
return app.goBack();
}).then(() => {
expect(tabs.select).not.toHaveBeenCalled();
expect(tab1.pop).not.toHaveBeenCalled();
expect(tab2.pop).not.toHaveBeenCalled();
expect(portal.pop).not.toHaveBeenCalled();
expect(plt.exitApp).toHaveBeenCalled();
done();
}).catch((err: Error) => {
done(err);
});
});

it('should pop from the active tab, when tabs is nested is the root nav', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Component } from '@angular/core';

@Component({
template: `<ion-nav [root]="root" name="default"></ion-nav>`
})
export class AppComponent {
root = 'FirstPage';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { IonicApp, IonicModule } from '../../../../..';

import { AppComponent } from './app.component';

@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
IonicModule.forRoot(AppComponent, { swipeBackEnabled: true, preloadModules: true }),
],
bootstrap: [IonicApp]
})
export class AppModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app.module';

platformBrowserDynamic().bootstrapModule(AppModule);
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<ion-header>
<ion-navbar>
<ion-title>First Page</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
Page One
<button ion-button (click)="goToPageTwo()">Go to Page Two</button>
<a href="#/nav/n4/user/123/name/ted">Using href</a>
</ion-content>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { NgModule } from '@angular/core';
import { IonicPageModule } from '../../../../../..';
import { FirstPage } from './first-page';

@NgModule({
imports: [
IonicPageModule.forChild(FirstPage)
],
declarations: [
FirstPage
]
})
export class FirstPageModule { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Component } from '@angular/core';
import { IonicPage, NavController, } from '../../../../../..';

@IonicPage()
@Component({
templateUrl: 'first-page.html'
})
export class FirstPage {
constructor(public nav: NavController) {
}

goToPageTwo() {
this.nav.push('SecondPage', { userId: '123', name: 'ted'});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<ion-header>
<ion-navbar>
<ion-title>Second Page</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<div>
User ID: {{userId}}
</div>
<div>
Name {{name}}
</div>
<div>
<button ion-button (click)="goToNextPage()">Go to Next Page</button>
</div>
</ion-content>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { NgModule } from '@angular/core';
import { IonicPageModule } from '../../../../../..';
import { SecondPage } from './second-page';

@NgModule({
imports: [
IonicPageModule.forChild(SecondPage)
],
declarations: [
SecondPage
]
})
export class SecondPageModule { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from '../../../../../..';

@IonicPage({
segment: 'user/:userId/name/:name',
defaultHistory: [
'FirstPage'
]
})
@Component({
templateUrl: 'second-page.html'
})
export class SecondPage {

userId: string;
name: string;
constructor(public nav: NavController, public params: NavParams) {
this.userId = this.params.data.userId;
this.name = this.params.data.name;
}

goToNextPage() {
this.nav.push('ThirdPage', { paramOne: 'Hello', paramTwo: 'Its me'});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<ion-header>
<ion-navbar>
<ion-title>Third Page</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<div>
Param One: {{paramOne}}
</div>
<div>
Param Two: {{paramTwo}}
</div>
</ion-content>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { NgModule } from '@angular/core';
import { IonicPageModule } from '../../../../../..';
import { ThirdPage } from './third-page';

@NgModule({
imports: [
IonicPageModule.forChild(ThirdPage)
],
declarations: [
ThirdPage
]
})
export class ThirdPageModule { }
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from '../../../../../..';

@IonicPage({
segment: 'paramOne/:paramOne/paramTwo/:paramTwo',
defaultHistory: [
'FirstPage'
]
})
@Component({
templateUrl: 'third-page.html'
})
export class ThirdPage {

paramOne: string;
paramTwo: string;
constructor(public nav: NavController, public params: NavParams) {
this.paramOne = this.params.data.paramOne;
this.paramTwo = this.params.data.paramTwo;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Component } from '@angular/core';

@Component({
template: `<ion-nav [root]="root"></ion-nav>`
})
export class AppComponent {
root = 'LoginPage';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { IonicApp, IonicModule } from '../../../../..';

import { AppComponent } from './app.component';

@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
IonicModule.forRoot(AppComponent, { swipeBackEnabled: true, preloadModules: true }),
],
bootstrap: [IonicApp]
})
export class AppModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app.module';

platformBrowserDynamic().bootstrapModule(AppModule);
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { NgModule } from '@angular/core';
import { IonicPageModule } from '../../../../../..';
import { LoginPage } from './login-page';

@NgModule({
imports: [
IonicPageModule.forChild(LoginPage)
],
declarations: [
LoginPage
]
})
export class LoginPageModule { }
Loading

0 comments on commit a77bb2c

Please sign in to comment.