Skip to content

Commit 995013b

Browse files
author
vakrilov
committed
test(router): Added componentless routes
1 parent 50e6ea2 commit 995013b

9 files changed

+244
-19
lines changed

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

+13
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ export const routes = [
2323
{ path: "detail/:id", component: DetailComponent }
2424
]
2525
},
26+
{
27+
path: "c-less",
28+
children: [
29+
{
30+
path: "deep/:depth",
31+
component: SecondComponent,
32+
children: [
33+
{ path: "", component: MasterComponent },
34+
{ path: "detail/:id", component: DetailComponent }
35+
]
36+
}
37+
]
38+
},
2639
{
2740
path: "lazy",
2841
loadChildren: "./lazy/lazy.module#LazyModule",

Diff for: e2e/router/app/app.css

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.header {
22
font-size: 32;
3+
white-space: normal;
34
}
45

56
.nested-header {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import {
1111

1212
import { AppComponent } from "./app.component";
1313

14-
import { rendererTraceCategory, viewUtilCategory } from "nativescript-angular/trace";
14+
import { rendererTraceCategory, viewUtilCategory, routeReuseStrategyTraceCategory, routerTraceCategory } from "nativescript-angular/trace";
1515
import { setCategories, enable } from "trace";
16-
setCategories(rendererTraceCategory + "," + viewUtilCategory);
16+
setCategories(routerTraceCategory + "," + routeReuseStrategyTraceCategory);
1717
enable();
1818

1919
@NgModule({

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ import { Observable } from "rxjs/Observable";
1313
<Label text="FirstComponent" class="header"></Label>
1414
1515
<Button text="GO TO SECOND" [nsRouterLink]="['/second','1']"></Button>
16-
<Button text="GO TO LAZY" [nsRouterLink]="['/lazy','home']"></Button>
16+
<Button text="GO TO C-LESS SECOND" [nsRouterLink]="['/c-less', 'deep', '100', 'detail', '200']"></Button>
17+
18+
19+
<Button text="GO TO LAZY HOME" [nsRouterLink]="['/lazy','home']"></Button>
20+
<Button text="GO TO C-LESS LAZY" [nsRouterLink]="['/lazy','nest','more']"></Button>
1721
1822
<Button text="BACK" (tap)="goBack()"></Button>
1923
<Label [text]="message"></Label>
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import { Component, OnInit, OnDestroy, OnChanges } from "@angular/core";
2+
import { ActivatedRoute, Router, Route } from "@angular/router";
3+
import { Location } from "@angular/common";
4+
import { RouterExtensions } from "nativescript-angular/router";
5+
6+
import { Page } from "ui/page";
7+
import { Observable } from "rxjs/Observable";
8+
9+
@Component({
10+
selector: "lazy",
11+
template: `
12+
<StackLayout>
13+
<Label text="Lazy Componentless Route" class="header"></Label>
14+
15+
<Button text="GO TO LAZY HOME" [nsRouterLink]="['/lazy','home']"></Button>
16+
17+
<Button text="GO TO FIRST" [nsRouterLink]="['/first']"></Button>
18+
<Button text="BACK" (tap)="goBack()"></Button>
19+
<Label [text]="message"></Label>
20+
</StackLayout>`
21+
})
22+
export class LazyComponentlessRouteComponent implements OnInit, OnDestroy {
23+
public message: string = "";
24+
constructor(private routerExt: RouterExtensions, page: Page) {
25+
console.log("LazyNestedRouteComponent - constructor() page: " + page);
26+
}
27+
28+
ngOnInit() {
29+
console.log("LazyNestedRouteComponent - ngOnInit()");
30+
}
31+
32+
ngOnDestroy() {
33+
console.log("LazyNestedRouteComponent - ngOnDestroy()");
34+
}
35+
36+
goBack() {
37+
this.message = "";
38+
if (this.routerExt.canGoBack()) {
39+
this.routerExt.back();
40+
} else {
41+
this.message = "canGoBack() - false"
42+
}
43+
}
44+
}

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

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import { Observable } from "rxjs/Observable";
1212
<StackLayout>
1313
<Label text="LazyComponent" class="header"></Label>
1414
15+
<Button text="GO TO C-LESS LAZY" [nsRouterLink]="['/lazy','nest','more']"></Button>
16+
1517
<Button text="GO TO FIRST" [nsRouterLink]="['/first']"></Button>
1618
<Button text="BACK" (tap)="goBack()"></Button>
1719
<Label [text]="message"></Label>

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

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,25 @@
11
import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
2+
import { Route } from "@angular/router";
3+
24
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
35
import { NativeScriptRouterModule } from "nativescript-angular/router";
46

57
import { LazyComponent } from "./lazy.component";
8+
import { LazyComponentlessRouteComponent } from "./lazy-componentless-route.component";
69

7-
8-
const routes = [
10+
const routes: Route[] = [
911
{
1012
path: "home",
1113
component: LazyComponent
14+
},
15+
{
16+
path: "nest",
17+
children: [
18+
{
19+
path: "more",
20+
component: LazyComponentlessRouteComponent
21+
}
22+
]
1223
}
1324
];
1425

@@ -19,6 +30,9 @@ const routes = [
1930
NativeScriptRouterModule,
2031
NativeScriptRouterModule.forChild(routes)
2132
],
22-
declarations: [LazyComponent]
33+
declarations: [
34+
LazyComponent,
35+
LazyComponentlessRouteComponent
36+
]
2337
})
2438
export class LazyModule { }

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

+157-13
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ describe("Simple navigate and back", () => {
2525
});
2626

2727
it("should navigate to Second(1)/master", async () => {
28-
await goFromFirstToSecond(driverWrapper);
28+
await findAndClick(driverWrapper, "GO TO SECOND");
2929

3030
await assureSecondComponent(driverWrapper, 1);
3131
await assureNestedMasterComponent(driverWrapper);
@@ -56,7 +56,7 @@ describe("Navigate inside nested outlet", () => {
5656
});
5757

5858
it("should navigate to Second(1)/master", async () => {
59-
await goFromFirstToSecond(driverWrapper);
59+
await findAndClick(driverWrapper, "GO TO SECOND");
6060

6161
await assureSecondComponent(driverWrapper, 1)
6262
await assureNestedMasterComponent(driverWrapper);
@@ -109,7 +109,7 @@ describe("Navigate to same component with different param", () => {
109109
});
110110

111111
it("should navigate to Second(1)/master", async () => {
112-
await goFromFirstToSecond(driverWrapper);
112+
await findAndClick(driverWrapper, "GO TO SECOND");
113113

114114
await assureSecondComponent(driverWrapper, 1)
115115
await assureNestedMasterComponent(driverWrapper);
@@ -156,7 +156,7 @@ describe("Nested navigation + page navigation", () => {
156156
});
157157

158158
it("should navigate to Second(1)/master", async () => {
159-
await goFromFirstToSecond(driverWrapper);
159+
await findAndClick(driverWrapper, "GO TO SECOND");
160160

161161
await assureSecondComponent(driverWrapper, 1)
162162
await assureNestedMasterComponent(driverWrapper);
@@ -188,9 +188,7 @@ describe("Nested navigation + page navigation", () => {
188188
});
189189

190190
it("should navigate to First", async () => {
191-
const navigationButton =
192-
await driverWrapper.findElementByText("GO TO FIRST", SearchOptions.exact);
193-
navigationButton.click();
191+
await findAndClick(driverWrapper, "GO TO FIRST");
194192

195193
await assureFirstComponent(driverWrapper);
196194
});
@@ -260,16 +258,15 @@ describe("Shouldn't be able to navigate back after cleared history", () => {
260258
});
261259

262260
it("should navigate to Second(1)/master", async () => {
263-
await goFromFirstToSecond(driverWrapper);
261+
await findAndClick(driverWrapper, "GO TO SECOND");
264262

265263
await assureSecondComponent(driverWrapper, 1)
266264
await assureNestedMasterComponent(driverWrapper);
267265
});
268266

269267
it("should navigate to Second(1)/master", async () => {
270-
const navigationButton =
271-
await driverWrapper.findElementByText("GO TO FIRST(CLEAR)", SearchOptions.exact);
272-
navigationButton.click();
268+
await findAndClick(driverWrapper, "GO TO FIRST(CLEAR)");
269+
273270
await assureFirstComponent(driverWrapper);
274271
});
275272

@@ -279,10 +276,157 @@ describe("Shouldn't be able to navigate back after cleared history", () => {
279276
});
280277
});
281278

279+
describe("Navigate to componentless route", () => {
280+
let driver: AppiumDriver;
281+
let driverWrapper: DriverWrapper;
282+
283+
before(async () => {
284+
driver = await createDriver();
285+
driverWrapper = new DriverWrapper(driver);
286+
});
287+
288+
after(async () => {
289+
await driver.quit();
290+
console.log("Driver quits!");
291+
});
292+
293+
it("should find First", async () => {
294+
await assureFirstComponent(driverWrapper);
295+
});
296+
297+
it("should navigate to ComponentlessSecond(100)/detail(200)", async () => {
298+
const navigationButton =
299+
await driverWrapper.findElementByText("GO TO C-LESS SECOND", SearchOptions.exact);
300+
navigationButton.click();
301+
302+
await assureSecondComponent(driverWrapper, 100)
303+
await assureNestedDetailComponent(driverWrapper, 200);
304+
});
305+
306+
it("should navigate to First", async () => {
307+
await findAndClick(driverWrapper, "GO TO FIRST");
308+
309+
await assureFirstComponent(driverWrapper);
310+
});
311+
312+
it("should navigate the whole stack", async () => {
313+
await goBack(driverWrapper);
314+
await assureSecondComponent(driverWrapper, 100)
315+
await assureNestedDetailComponent(driverWrapper, 200);
316+
317+
await goBack(driverWrapper);
318+
await assureFirstComponent(driverWrapper);
319+
});
320+
});
321+
322+
describe("Navigate to lazy module", () => {
323+
let driver: AppiumDriver;
324+
let driverWrapper: DriverWrapper;
325+
326+
before(async () => {
327+
driver = await createDriver();
328+
driverWrapper = new DriverWrapper(driver);
329+
});
330+
331+
after(async () => {
332+
await driver.quit();
333+
console.log("Driver quits!");
334+
});
335+
336+
it("should find First", async () => {
337+
await assureFirstComponent(driverWrapper);
338+
});
339+
340+
it("should navigate to lazy/home", async () => {
341+
await findAndClick(driverWrapper, "GO TO LAZY HOME");
342+
343+
await assureLazyComponent(driverWrapper);
344+
});
345+
346+
it("should navigate to First", async () => {
347+
await findAndClick(driverWrapper, "GO TO FIRST");
348+
await assureFirstComponent(driverWrapper);
349+
});
350+
351+
it("should navigate back to lazy/home", async () => {
352+
await goBack(driverWrapper);
353+
await assureLazyComponent(driverWrapper);
354+
});
355+
356+
it("should navigate to First again", async () => {
357+
await findAndClick(driverWrapper, "GO TO FIRST");
358+
await assureFirstComponent(driverWrapper);
359+
});
360+
361+
it("should navigate the whole stack", async () => {
362+
await goBack(driverWrapper);
363+
await assureLazyComponent(driverWrapper);
364+
365+
await goBack(driverWrapper);
366+
await assureFirstComponent(driverWrapper);
367+
});
368+
});
369+
370+
describe("Navigate to componentless lazy module route", () => {
371+
let driver: AppiumDriver;
372+
let driverWrapper: DriverWrapper;
373+
374+
before(async () => {
375+
driver = await createDriver();
376+
driverWrapper = new DriverWrapper(driver);
377+
});
378+
379+
after(async () => {
380+
await driver.quit();
381+
console.log("Driver quits!");
382+
});
383+
384+
it("should find First", async () => {
385+
await assureFirstComponent(driverWrapper);
386+
});
387+
388+
it("should navigate to nest/more (componentless lazy route)", async () => {
389+
await findAndClick(driverWrapper, "GO TO C-LESS LAZY");
390+
391+
await assureComponentlessLazyComponent(driverWrapper);
392+
});
393+
394+
it("should navigate to lazy/home", async () => {
395+
await findAndClick(driverWrapper, "GO TO LAZY HOME");
396+
397+
await assureLazyComponent(driverWrapper);
398+
});
399+
400+
it("should navigate to First", async () => {
401+
await findAndClick(driverWrapper, "GO TO FIRST");
402+
403+
await assureFirstComponent(driverWrapper);
404+
});
405+
406+
it("should navigate the whole stack", async () => {
407+
await goBack(driverWrapper);
408+
await assureLazyComponent(driverWrapper);
409+
410+
await goBack(driverWrapper);
411+
await assureComponentlessLazyComponent(driverWrapper);
412+
413+
await goBack(driverWrapper);
414+
await assureFirstComponent(driverWrapper);
415+
});
416+
});
417+
282418
async function assureFirstComponent(driverWrapper: DriverWrapper) {
283419
await driverWrapper.findElementByText("FirstComponent", SearchOptions.exact);
284420
}
285421

422+
async function assureLazyComponent(driverWrapper: DriverWrapper) {
423+
await driverWrapper.findElementByText("LazyComponent", SearchOptions.exact);
424+
}
425+
426+
async function assureComponentlessLazyComponent(driverWrapper: DriverWrapper) {
427+
await driverWrapper.findElementByText("Lazy Componentless Route", SearchOptions.exact);
428+
}
429+
286430
async function assureSecondComponent(driverWrapper: DriverWrapper, param: number) {
287431
await driverWrapper.findElementByText("SecondComponent", SearchOptions.exact);
288432
await driverWrapper.findElementByText(`param: ${param}`, SearchOptions.exact);
@@ -302,8 +446,8 @@ async function goBack(driverWrapper: DriverWrapper) {
302446
await backButton.click();
303447
}
304448

305-
async function goFromFirstToSecond(driverWrapper: DriverWrapper) {
449+
async function findAndClick(driverWrapper: DriverWrapper, text: string) {
306450
const navigationButton =
307-
await driverWrapper.findElementByText("GO TO SECOND", SearchOptions.exact);
451+
await driverWrapper.findElementByText(text, SearchOptions.exact);
308452
navigationButton.click();
309453
}

Diff for: e2e/router/package.json

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
"id": "org.nativescript.router",
88
"tns-android": {
99
"version": "3.2.0-2017-9-4-1"
10+
},
11+
"tns-ios": {
12+
"version": "3.2.0"
1013
}
1114
},
1215
"dependencies": {

0 commit comments

Comments
 (0)