Skip to content

Commit fd7bbbd

Browse files
ADjenkovADjenkov
ADjenkov
authored and
ADjenkov
committed
chore(router-e2e): extend with lazy loaded named outlet
1 parent af4a15d commit fd7bbbd

9 files changed

+193
-19
lines changed

Diff for: e2e/router/app/app-routing.module.ts

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
2-
import { NativeScriptRouterModule } from "nativescript-angular/router";
2+
import { NativeScriptRouterModule, NSEmptyOutletComponent } from "nativescript-angular/router";
33

44
import { FirstComponent } from "./first/first.component"
55
import { SecondComponent } from "./second/second.component"
@@ -17,10 +17,17 @@ export const routes = [
1717
component: FirstComponent,
1818
},
1919
{
20-
path: "second/:depth", component: SecondComponent,
20+
path: "second/:depth",
21+
component: SecondComponent,
2122
children: [
2223
{ path: "", component: MasterComponent },
23-
{ path: "detail/:id", component: DetailComponent }
24+
{ path: "detail/:id", component: DetailComponent },
25+
{
26+
path: "lazy-named",
27+
outlet: "lazyNameOutlet",
28+
component: NSEmptyOutletComponent,
29+
loadChildren: "./lazy-named/lazy-named.module#LazyNamedModule",
30+
}
2431
]
2532
},
2633
{
@@ -50,7 +57,7 @@ export const navigatableComponents = [
5057
];
5158

5259
@NgModule({
53-
imports: [NativeScriptRouterModule.forRoot(routes)],
60+
imports: [NativeScriptRouterModule, NativeScriptRouterModule.forRoot(routes)],
5461
exports: [NativeScriptRouterModule],
5562
})
5663
export class AppRoutingModule { }

Diff for: e2e/router/app/first/first.component.ts

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import { Page } from "ui/page";
1414
<Button text="GO TO SECOND" [nsRouterLink]="['/second','1']"></Button>
1515
<Button text="GO TO C-LESS SECOND" [nsRouterLink]="['/c-less', 'deep', '100', 'detail', '200']"></Button>
1616
17-
1817
<Button text="GO TO LAZY HOME" [nsRouterLink]="['/lazy','home']"></Button>
1918
<Button text="GO TO C-LESS LAZY" [nsRouterLink]="['/lazy','nest','more']"></Button>
2019

Diff for: e2e/router/app/lazy-named/lazy-named.module.ts

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
2+
import { Route } from "@angular/router";
3+
4+
import { NativeScriptCommonModule } from "nativescript-angular/common";
5+
import { NativeScriptRouterModule } from "nativescript-angular/router";
6+
7+
import { NestedMasterComponent } from "./nested-master.component"
8+
import { NestedDetailComponent } from "./nested-detail.component"
9+
10+
const routes: Route[] = [
11+
{ path: "", component: NestedMasterComponent },
12+
{ path: "detail/:id", component: NestedDetailComponent }
13+
];
14+
15+
@NgModule({
16+
schemas: [NO_ERRORS_SCHEMA],
17+
imports: [
18+
NativeScriptCommonModule,
19+
NativeScriptRouterModule,
20+
NativeScriptRouterModule.forChild(routes)
21+
],
22+
declarations: [
23+
NestedMasterComponent,
24+
NestedDetailComponent
25+
],
26+
exports:[
27+
NestedMasterComponent,
28+
NestedDetailComponent
29+
]
30+
})
31+
export class LazyNamedModule { }

Diff for: e2e/router/app/lazy-named/nested-detail.component.ts

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { Component, OnInit, OnDestroy } from "@angular/core";
2+
import { ActivatedRoute, Router, Route } from "@angular/router";
3+
import { Location } from "@angular/common";
4+
import { Observable } from "rxjs";
5+
import { map } from "rxjs/operators";
6+
import { Page } from "tns-core-modules/ui/page";
7+
import { RouterExtensions } from "nativescript-angular/router";
8+
9+
@Component({
10+
selector: "detail",
11+
template: `
12+
<GridLayout rows="auto, auto">
13+
<Label [text]="'nested-named-param: ' + (id$ | async)"></Label>
14+
<Button row="1" text="BACK-NESTED" (tap)="goBack()"></Button>
15+
</GridLayout>
16+
`
17+
})
18+
export class NestedDetailComponent {
19+
public id$: Observable<string>;
20+
21+
constructor(private router: Router, private route: ActivatedRoute, private page: Page, private routerExt: RouterExtensions) {
22+
this.page.actionBar.title = "NamedNestedDetail";
23+
console.log("DetailComponent - constructor()");
24+
this.id$ = route.params.pipe(map(r => r["id"]));
25+
}
26+
27+
ngOnInit() {
28+
console.log("DetailComponent - ngOnInit()");
29+
}
30+
31+
ngOnDestroy() {
32+
console.log("DetailComponent - ngOnDestroy()");
33+
}
34+
35+
goBack(){
36+
this.routerExt.back();
37+
}
38+
}

Diff for: e2e/router/app/lazy-named/nested-master.component.ts

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import { Component, OnInit, OnDestroy } from "@angular/core";
2+
import { Page } from "tns-core-modules/ui/page";
3+
@Component({
4+
selector: "master",
5+
template: `
6+
<GridLayout rows="auto">
7+
<StackLayout row="1" orientation="horizontal">
8+
<Button *ngFor="let detail of details" [text]="'DETAIL-NAMED ' + detail" [nsRouterLink]="['detail', detail]"></Button>
9+
</StackLayout>
10+
</GridLayout>
11+
`
12+
})
13+
export class NestedMasterComponent implements OnInit, OnDestroy {
14+
public details: Array<number> = [1, 2, 3];
15+
16+
constructor(private page: Page) {
17+
this.page.actionBar.title = "NamedNestedMaster";
18+
console.log("MasterComponent - constructor()");
19+
}
20+
21+
ngOnInit() {
22+
console.log("MasterComponent - ngOnInit()");
23+
}
24+
25+
ngOnDestroy() {
26+
console.log("MasterComponent - ngOnDestroy()");
27+
}
28+
}

Diff for: e2e/router/app/second/detail.component.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Component, OnInit, OnDestroy } from "@angular/core";
22
import { ActivatedRoute, Router, Route } from "@angular/router";
33
import { Location } from "@angular/common";
4-
import { Page } from "ui/page";
54
import { Observable } from "rxjs";
65
import { map } from "rxjs/operators";
6+
import { Page } from "tns-core-modules/ui/page";
77

88
@Component({
99
selector: "detail",
@@ -18,7 +18,8 @@ import { map } from "rxjs/operators";
1818
export class DetailComponent {
1919
public id$: Observable<string>;
2020

21-
constructor(private router: Router, private route: ActivatedRoute) {
21+
constructor(private router: Router, private route: ActivatedRoute, private page: Page) {
22+
page.actionBarHidden = true;
2223
console.log("DetailComponent - constructor()");
2324
this.id$ = route.params.pipe(map(r => r["id"]));
2425
}

Diff for: e2e/router/app/second/master.component.ts

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
import { Component, OnInit, OnDestroy } from "@angular/core";
2-
2+
import { Page } from "tns-core-modules/ui/page";
33
@Component({
44
selector: "master",
55
template: `
6-
<StackLayout>
6+
<GridLayout rows="auto, auto">
77
<Label text="NestedMaster" class="nested-header"></Label>
8-
9-
<Button *ngFor="let detail of details" [text]="'DETAIL ' + detail" [nsRouterLink]="['detail', detail]"></Button>
10-
</StackLayout>
8+
9+
<StackLayout row="1" orientation="horizontal">
10+
<Button *ngFor="let detail of details" [text]="'DETAIL ' + detail" [nsRouterLink]="['detail', detail]"></Button>
11+
</StackLayout>
12+
</GridLayout>
1113
`
1214
})
1315
export class MasterComponent implements OnInit, OnDestroy {
1416
public details: Array<number> = [1, 2, 3];
1517

16-
constructor() {
18+
constructor(private page: Page) {
19+
this.page.actionBarHidden = true;
1720
console.log("MasterComponent - constructor()");
1821
}
1922

Diff for: e2e/router/app/second/second.component.ts

+16-6
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,24 @@ import { map } from "rxjs/operators";
1616
<Button text="GO TO FIRST" [nsRouterLink]="['/first']"></Button>
1717
<Button text="GO TO FIRST(CLEAR)" [nsRouterLink]="['/first']" clearHistory="true" pageTransition="flipRight"></Button>
1818
<Button text="GO TO NEXT SECOND" [nsRouterLink]="['/second', (nextDepth$ | async)]"></Button>
19+
<Button text="LOAD NESTED NAMED OUTLET" (tap)="loadNestedNamedOutlet()"></Button>
1920
<Button text="BACK" (tap)="goBack()"></Button>
20-
21-
<StackLayout class="nested-outlet">
22-
<router-outlet></router-outlet>
23-
</StackLayout>
21+
22+
<GridLayout row="1" rows="*,*">
23+
<GridLayout row="0" class="nested-outlet">
24+
<router-outlet></router-outlet>
25+
</GridLayout>
26+
<GridLayout row="1">
27+
<page-router-outlet name="lazyNameOutlet"></page-router-outlet>
28+
</GridLayout>
29+
</GridLayout>
2430
</StackLayout>`
2531
})
2632
export class SecondComponent implements OnInit, OnDestroy {
2733
public depth$: Observable<string>;
2834
public nextDepth$: Observable<number>;
2935

30-
constructor(private routerExt: RouterExtensions, route: ActivatedRoute, page: Page) {
36+
constructor(private routerExt: RouterExtensions, private route: ActivatedRoute, page: Page) {
3137
console.log("SecondComponent - constructor() page: " + page);
3238
this.depth$ = route.params.pipe(map(r => r["depth"]));
3339
this.nextDepth$ = route.params.pipe(map(r => +r["depth"] + 1));
@@ -42,6 +48,10 @@ export class SecondComponent implements OnInit, OnDestroy {
4248
}
4349

4450
goBack() {
45-
this.routerExt.back();
51+
this.routerExt.back({ relativeTo: this.route });
52+
}
53+
54+
loadNestedNamedOutlet() {
55+
this.routerExt.navigate([{ outlets: { lazyNameOutlet: ["lazy-named"] } }], { relativeTo: this.route });
4656
}
4757
}

Diff for: e2e/router/e2e/router.e2e-spec.ts

+57
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,53 @@ describe("Nested navigation + page navigation", () => {
190190
});
191191
});
192192

193+
describe("Nested name navigation + page navigation", () => {
194+
let driver: AppiumDriver;
195+
196+
before(async () => {
197+
driver = await createDriver();
198+
await driver.resetApp();
199+
});
200+
201+
it("should find First", async () => {
202+
await assureFirstComponent(driver);
203+
});
204+
205+
it("should navigate to Second(1)/master", async () => {
206+
await findAndClick(driver, "GO TO SECOND");
207+
208+
await assureSecondComponent(driver, 1)
209+
await assureNestedMasterComponent(driver);
210+
});
211+
212+
it("should load nested named Master", async () => {
213+
await findAndClick(driver, "LOAD NESTED NAMED OUTLET");
214+
await assureNamedNestedMasterComponent(driver);
215+
});
216+
217+
it("should navigate to nested named Master Detail/1", async () => {
218+
const navigationButton =
219+
await driver.findElementByText("DETAIL-NAMED 1", SearchOptions.exact);
220+
navigationButton.click();
221+
222+
await assureNamedNestedDetailComponent(driver, 1);
223+
});
224+
225+
it("should navigate back to Master and navigate to Detail/2", async () => {
226+
let navigationButton =
227+
await driver.findElementByText("BACK-NESTED", SearchOptions.exact);
228+
navigationButton.click();
229+
230+
await assureNamedNestedMasterComponent(driver);
231+
232+
navigationButton =
233+
await driver.findElementByText("DETAIL-NAMED 2", SearchOptions.exact);
234+
navigationButton.click();
235+
236+
await assureNamedNestedDetailComponent(driver, 2);
237+
});
238+
});
239+
193240
describe("Shouldn't be able to navigate back on startup", () => {
194241
let driver: AppiumDriver;
195242

@@ -371,6 +418,16 @@ async function assureComponentlessLazyComponent(driver: AppiumDriver) {
371418
await driver.findElementByText("Lazy Componentless Route", SearchOptions.exact);
372419
}
373420

421+
async function assureNamedNestedMasterComponent(driver: AppiumDriver) {
422+
await driver.findElementByText("NamedNestedMaster", SearchOptions.exact);
423+
}
424+
425+
async function assureNamedNestedDetailComponent(driver: AppiumDriver, param: number) {
426+
await driver.findElementByText("NamedNestedDetail", SearchOptions.exact);
427+
await driver.findElementByText(`nested-named-param: ${param}`, SearchOptions.exact);
428+
429+
}
430+
374431
async function assureSecondComponent(driver: AppiumDriver, param: number) {
375432
await driver.findElementByText("SecondComponent", SearchOptions.exact);
376433
await driver.findElementByText(`param: ${param}`, SearchOptions.exact);

0 commit comments

Comments
 (0)