Skip to content

fix(location-strategy): extend support for nested primary outlets #1717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion e2e/nested-router-tab-view/app/app.component.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<page-router-outlet></page-router-outlet>
<page-router-outlet tag="rootPRO"></page-router-outlet>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the tag="rootPRO" used somewhere or just for debugging?

Copy link
Contributor Author

@ADjenkov ADjenkov Feb 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is just for debugging, since it is very easy to distinguish which p-r-o is activated, states and so on..it's also in the test app only

4 changes: 4 additions & 0 deletions e2e/nested-router-tab-view/app/app.routing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ const routes: Routes = [
path: "home-lazy",
loadChildren: "./home-lazy/home-lazy.module#HomeLazyModule",
},
{
path: "custom-tabs",
loadChildren: "./custom-tabs/custom-tabs.module#CustomTabsModule",
},
{
path: "tabs", component: TabsComponent, children: [
{ path: "players", component: PlayerComponent, outlet: "playerTab" },
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<ActionBar title="Custom Tabs Component" class="action-bar">
<NavigationButton text="Root Back"></NavigationButton>

<StackLayout orientation="horizontal">
<Button horizontalAlignment="left" android:visibility="visible" ios:visibility="collapse" text="Root Back" (tap)="onRootBack()"></Button>
<Label horizontalAlignment="center" text="Custom Tabs Component"></Label>
</StackLayout>
</ActionBar>

<GridLayout rows="50,*, auto">
<!-- <Button row="0" text="CanGoBack(ParentRoute)" automationText="CanGoBack(ParentRoute)" col="3" (tap)="canGoBackParentRoute()"></Button> -->
<GridLayout row="1">
<page-router-outlet tag="customTabsPRO"></page-router-outlet>
</GridLayout>
<GridLayout row="2" columns="*, *">
<Button col="0" text="Players Tab" [nsRouterLink]="['../tabs/players']"></Button>
<Button col="1" text="Teams Tab" [nsRouterLink]="['../tabs/teams']"></Button>
</GridLayout>
</GridLayout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { Component, OnInit } from '@angular/core';
import { ModalDialogService, ModalDialogOptions } from "nativescript-angular/directives/dialogs";
import { RouterExtensions } from "nativescript-angular/router";
import { ActivatedRoute } from "@angular/router";
import { confirm } from "tns-core-modules/ui/dialogs";
import { Page } from 'tns-core-modules/ui/page/page';

@Component({
moduleId: module.id,
selector: 'custom-tabs',
templateUrl: './custom-tabs.component.html'
})
export class CustomTabsComponent implements OnInit {

constructor(
private activeRoute: ActivatedRoute,
private routerExtension: RouterExtensions,
private page: Page) { }

ngOnInit() {
}

canGoBackParentRoute() {
const canGoBackParentRoute = this.routerExtension.canGoBack({ relativeTo: this.activeRoute });
const title = "CanGoBack(ParentRoute)";
this.onShowDialog(title, title + ` ${canGoBackParentRoute}`);
}

onRootBack() {
this.page.frame.goBack();
}

onShowDialog(title: string, result: string) {
let options: any = {
title: title,
message: result,
okButtonText: "Ok"
}

confirm(options).then((result: boolean) => {
console.log(result);
})
}
}
38 changes: 38 additions & 0 deletions e2e/nested-router-tab-view/app/custom-tabs/custom-tabs.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { NgModule, NO_ERRORS_SCHEMA } from '@angular/core';
import { NativeScriptCommonModule } from 'nativescript-angular/common';
import { NativeScriptRouterModule } from 'nativescript-angular/router';

import { CustomTabsComponent } from './custom-tabs.component';
import { PlayerComponent } from "../player/players.component";
import { PlayerDetailComponent } from "../player/player-detail.component";
import { TeamsComponent } from "../team/teams.component";
import { TeamDetailComponent } from "../team/team-detail.component";
import { Route } from "@angular/router";
import { SharedModule } from "../shared.module";

const routes: Route[] = [
{
path: 'tabs',
component: CustomTabsComponent,
children: [
{ path: "players", component: PlayerComponent },
{ path: "player/:id", component: PlayerDetailComponent },

{ path: "teams", component: TeamsComponent },
{ path: "team/:id", component: TeamDetailComponent },
]
},
];

@NgModule({
declarations: [CustomTabsComponent
],
imports: [
NativeScriptCommonModule,
NativeScriptRouterModule,
NativeScriptRouterModule.forChild(routes),
SharedModule
],
schemas: [NO_ERRORS_SCHEMA]
})
export class CustomTabsModule { }
2 changes: 1 addition & 1 deletion e2e/nested-router-tab-view/app/login/login.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
</ActionBar>

<StackLayout>
<!-- <Button text="Go To Home Page" [nsRouterLink]="['/home', { outlets: { playerTab: ['players'], teamTab: ['teams'] } }]"></Button> -->
<Button text="Go To Home Page" [nsRouterLink]="['../home', { outlets: { playerTab: ['players'], teamTab: ['teams'] } }]"></Button>
<Button text="Go To Lazy Home Page" [nsRouterLink]="['../home-lazy/home', { outlets: { playerTab: ['players'], teamTab: ['teams'] } }]"></Button>
<Button text="Go To Lazy Custom Tabs" [nsRouterLink]="['../custom-tabs/tabs/players']"></Button>
</StackLayout>
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<ActionBar title="Player Details" class="action-bar"></ActionBar>
<ActionBar title="Player Details" class="action-bar">
<!-- <NavigationButton visibility="hidden"></NavigationButton> -->
</ActionBar>
<StackLayout flexDirection="column" class="page" class="m-15">
<Label [text]="item.id"></Label>
<Label [text]="item.name + ' Details'"></Label>
Expand Down
12 changes: 6 additions & 6 deletions e2e/nested-router-tab-view/app/player/players.component.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<ActionBar title="Player List" class="action-bar"></ActionBar>
<ActionBar title="Player List" class="action-bar">
<!-- <NavigationButton visibility="hidden"></NavigationButton> -->
</ActionBar>

<GridLayout>
<!-- <Button text="Open Named Modal" (tap)="onModalFrame()"></Button> -->
<ListView [items]="items" class="list-group">
<GridLayout rows="auto,*">
<ListView row="1" [items]="items" class="list-group">
<ng-template let-item="item">
<Label [nsRouterLink]="['../player', item.id]" [text]="item.name"
class="list-group-item"></Label>
<Label [nsRouterLink]="['../player', item.id]" [text]="item.name" class="list-group-item"></Label>
</ng-template>
</ListView>
</GridLayout>
6 changes: 4 additions & 2 deletions e2e/nested-router-tab-view/app/player/players.component.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Component, OnInit, ViewContainerRef } from "@angular/core";
import { DataService, DataItem } from "../data.service";
import { RouterExtensions } from "nativescript-angular/router";

import { ModalDialogService, ModalDialogOptions } from "nativescript-angular/directives/dialogs";
import { ModalRouterComponent } from "../modal/modal-router/modal-router.component";
Expand All @@ -12,7 +11,10 @@ import { ModalRouterComponent } from "../modal/modal-router/modal-router.compone
export class PlayerComponent implements OnInit {
items: DataItem[];

constructor(private modal: ModalDialogService, private itemService: DataService, private router: RouterExtensions, private vcRef: ViewContainerRef, ) { }
constructor(
private modal: ModalDialogService,
private itemService: DataService,
private vcRef: ViewContainerRef, ) { }

ngOnInit(): void {
this.items = this.itemService.getPlayers();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<ActionBar title="Team Details" class="action-bar"></ActionBar>
<ActionBar title="Team Details" class="action-bar">
<!-- <NavigationButton visibility="hidden"></NavigationButton> -->
</ActionBar>
<StackLayout flexDirection="column" class="page" class="m-15">
<Label [text]="item.id"></Label>
<Label [text]="item.name + ' Details'"></Label>
Expand Down
4 changes: 3 additions & 1 deletion e2e/nested-router-tab-view/app/team/teams.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<ActionBar title="Team List" class="action-bar"></ActionBar>
<ActionBar title="Team List" class="action-bar">
<!-- <NavigationButton visibility="hidden"></NavigationButton> -->
</ActionBar>

<GridLayout>
<ListView [items]="items" class="list-group">
Expand Down
72 changes: 72 additions & 0 deletions e2e/nested-router-tab-view/e2e/custom-tabs.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { AppiumDriver, createDriver } from "nativescript-dev-appium";
import { Screen } from "./screen"
import {
testPlayerNavigated,
testTeamNavigated,
testPlayerNextNavigated,
testTeamNextNavigated,
} from "./shared.e2e-spec"

describe("custom-tabs:", () => {
let driver: AppiumDriver;
let screen: Screen;

before(async () => {
driver = await createDriver();
screen = new Screen(driver);
});

after(async () => {
await driver.quit();
console.log("Quit driver!");
});

afterEach(async function () {
if (this.currentTest.state === "failed") {
await driver.logTestArtifacts(this.currentTest.title);
}
});

it("loaded custom tab component and tabs", async () => {
await screen.navigateCustomTabsPage();
await screen.loadedCustomTabsPage();
await screen.loadedPlayersList();
await gotoTeamsTab(driver);
await screen.loadedTeamList();
});

it("navigate back to login and again to custom tabs", async () => {
await backRoot(driver);
await screen.loadedLogin();
await screen.navigateCustomTabsPage();
await screen.loadedCustomTabsPage();
await screen.loadedPlayersList();
await gotoTeamsTab(driver);
await screen.loadedTeamList();
});

it("navigate back to login and again to custom tabs", async () => {
await gotoPlayersTab(driver);
await testPlayerNavigated(screen, screen.playerOne);
await gotoTeamsTab(driver);
await screen.loadedTeamList();
await testTeamNavigated(screen, screen.teamOne);
await backRoot(driver);
await screen.loadedLogin();
});
});

async function backRoot(driver: AppiumDriver) {
const btnBackRoot = await driver.findElementByAutomationText("Root Back");
await btnBackRoot.tap();
}

async function gotoPlayersTab(driver: AppiumDriver) {
const btnTabTeams = await driver.findElementByAutomationText("Players Tab");
await btnTabTeams.tap();
}

async function gotoTeamsTab(driver: AppiumDriver) {
const btnTabTeams = await driver.findElementByAutomationText("Teams Tab");
await btnTabTeams.tap();
}
13 changes: 13 additions & 0 deletions e2e/nested-router-tab-view/e2e/screen.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AppiumDriver, SearchOptions } from "nativescript-dev-appium";
import { assert } from "chai";

const customTabs = "Custom Tabs Component";
const home = "Home Component";
const about = "About Component";
const aboutNested = "Nested About Component";
Expand All @@ -18,6 +19,7 @@ const gotoNextTeam = "next team";
const gotoTeams = "teams";

const gotoHomePage = "Go To Home Page";
const gotoCustomTabPage = "Go To Lazy Custom Tabs";
const gotoAboutPage = "Go To About Page";
const gotoTabsPage = "Go To Tabs Page";
const confirmDialog = "Ok";
Expand Down Expand Up @@ -68,6 +70,12 @@ export class Screen {
console.log(home + " loaded!");
}

loadedCustomTabsPage= async () => {
const lblCustomTabs = await this._driver.findElementByAutomationText(customTabs);
assert.isTrue(await lblCustomTabs.isDisplayed());
console.log(home + " loaded!");
}

loadedAbout= async () => {
const lblAbout = await this._driver.findElementByAutomationText(about);
assert.isTrue(await lblAbout.isDisplayed());
Expand Down Expand Up @@ -128,6 +136,11 @@ export class Screen {
await btnNavToHomePage.tap();
}

navigateCustomTabsPage = async () => {
const btnNavToHomePage = await this._driver.findElementByAutomationText(gotoCustomTabPage);
await btnNavToHomePage.tap();
}

navigateToAboutPage = async () => {
const btnNavToAboutPage = await this._driver.findElementByAutomationText(gotoAboutPage);
await btnNavToAboutPage.tap();
Expand Down
Loading