Skip to content

Commit 61e064a

Browse files
ADjenkovADjenkov
ADjenkov
authored and
ADjenkov
committed
chore(modal-navigation-ng): add named p-r-o as root tests
1 parent 905e3df commit 61e064a

10 files changed

+95
-8
lines changed

Diff for: e2e/modal-navigation-ng/app/app.module.ts

+11-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
22
import { NativeScriptModule } from "nativescript-angular/nativescript.module";
33
import { AppRoutingModule } from "./app.routing";
44
import { AppComponent } from "./app.component";
5+
import { NamedRouterComponent } from "./named-router.component";
56
import { TabComponent } from "./tab.component";
67
import { LayoutComponent } from "./layout.component";
78

@@ -29,16 +30,18 @@ traceEnable();
2930
AppRoutingModule
3031
],
3132
entryComponents: [
32-
AppComponent,
33-
TabComponent,
34-
LayoutComponent,
35-
ModalRouterComponent,
36-
NestedModalComponent,
37-
ModalComponent,
33+
AppComponent,
34+
NamedRouterComponent,
35+
TabComponent,
36+
LayoutComponent,
37+
ModalRouterComponent,
38+
NestedModalComponent,
39+
ModalComponent,
3840
ModalViewComponent
3941
],
4042
declarations: [
4143
AppComponent,
44+
NamedRouterComponent,
4245
TabComponent,
4346
LayoutComponent,
4447
HomeComponent,
@@ -75,8 +78,9 @@ export class AppModule {
7578
static bootstrapRootComponent() {
7679
const options = {
7780
'page-router': AppComponent,
81+
'named-page-router': NamedRouterComponent,
7882
'tab': TabComponent,
79-
'layout': LayoutComponent
83+
'layout': LayoutComponent
8084
};
8185

8286
const component = options[AppModule.root];

Diff for: e2e/modal-navigation-ng/app/app.routing.ts

+30
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,34 @@ const routes: Routes = [
4040
}
4141
];
4242

43+
const namedOutletRoutes: Routes = [
44+
{ path: "", redirectTo: "/(namedRouter:home)", pathMatch: "full" },
45+
{
46+
path: "home", component: HomeComponent, outlet: "namedRouter", children: [
47+
{
48+
path: "modal", component: ModalComponent, children: [
49+
{ path: "nested-frame-modal", component: NestedModalComponent }]
50+
},
51+
{ path: "modal-second", component: ModalSecondComponent }
52+
]
53+
},
54+
{
55+
path: "second", outlet: "namedRouter", component: SecondComponent, children: [
56+
{
57+
path: "modal", component: ModalComponent, children: [
58+
{ path: "nested-frame-modal", component: NestedModalComponent }]
59+
},
60+
{ path: "modal-second", component: ModalSecondComponent }
61+
]
62+
},
63+
{
64+
path: "modal-shared", component: ModalViewContentComponent, outlet: "modalOutlet"
65+
},
66+
{
67+
path: "modal-shared-second-host", outlet: "namedRouter", component: ModalSharedSecondComponent
68+
}
69+
];
70+
4371
const routesTab: Routes = [
4472
{ path: "", redirectTo: "/home(secondOutlet:second)", pathMatch: "full" },
4573
{
@@ -96,6 +124,8 @@ export class AppRoutingModule {
96124
this.router.resetConfig(routes);
97125
} else if (AppModule.root === "layout") {
98126
this.router.resetConfig(routesLayout);
127+
} else if (AppModule.root === "named-page-router") {
128+
this.router.resetConfig(namedOutletRoutes);
99129
} else {
100130
this.router.resetConfig(routesTab);
101131
}

Diff for: e2e/modal-navigation-ng/app/home/home.component.html

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<Button text="Show Modal Without Frame" (tap)="onModalNoFrame()"></Button>
77
<Button text="Show Modal Page With Frame" (tap)="onModalFrame()"></Button>
88
<Button text="Navigate To Second Page" (tap)="onNavigateSecond()"></Button>
9+
<Button text="Reset Named Frame Root View" (tap)="onNamedFrameRootViewReset()"></Button>
910
<Button text="Reset Frame Root View" (tap)="onFrameRootViewReset()"></Button>
1011
<Button text="Reset Tab Root View" (tap)="onTabRootViewReset()"></Button>
1112
<Button text="Reset Layout Root View" (tap)="onLayoutRootViewReset()"></Button>

Diff for: e2e/modal-navigation-ng/app/home/home.component.ts

+5
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@ export class HomeComponent {
6161
AppModule.platformRef._livesync();
6262
}
6363

64+
onNamedFrameRootViewReset() {
65+
AppModule.root = "named-page-router";
66+
AppModule.platformRef._livesync();
67+
}
68+
6469
onTabRootViewReset() {
6570
AppModule.root = "tab";
6671
AppModule.platformRef._livesync();

Diff for: e2e/modal-navigation-ng/app/layout.component.html

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<Label text="Home" horizontalAlignment="center"></Label>
33
<Button text="Show Modal Without Frame" (tap)="onModalNoFrame()"></Button>
44
<Button text="Show Modal Page With Frame" (tap)="onModalFrame()"></Button>
5+
<Button text="Reset Named Frame Root View" (tap)="onNamedFrameRootViewReset()"></Button>
56
<Button text="Reset Frame Root View" (tap)="onFrameRootViewReset()"></Button>
67
<Button text="Reset Tab Root View" (tap)="onTabRootViewReset()"></Button>
78
<Button text="Reset Layout Root View" (tap)="onLayoutRootViewReset()"></Button>

Diff for: e2e/modal-navigation-ng/app/layout.component.ts

+5
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ export class LayoutComponent {
6767
AppModule.platformRef._livesync();
6868
}
6969

70+
onNamedFrameRootViewReset() {
71+
AppModule.root = "named-page-router";
72+
AppModule.platformRef._livesync();
73+
}
74+
7075
onTabRootViewReset() {
7176
AppModule.root = "tab";
7277
AppModule.platformRef._livesync();
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<page-router-outlet name="namedRouter"></page-router-outlet>
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import { Component, ViewContainerRef } from "@angular/core";
2+
import { Router, NavigationEnd } from "@angular/router";
3+
import { NSLocationStrategy } from "nativescript-angular/router/ns-location-strategy";
4+
5+
import { ViewContainerRefService } from "./shared/ViewContainerRefService";
6+
7+
@Component({
8+
selector: "named-router",
9+
templateUrl: "named-router.component.html",
10+
})
11+
12+
export class NamedRouterComponent {
13+
constructor(
14+
router: Router,
15+
location: NSLocationStrategy,
16+
private _vcRef: ViewContainerRef,
17+
private _viewContainerRefService: ViewContainerRefService) {
18+
router.events.subscribe(e => {
19+
if (e instanceof NavigationEnd) {
20+
console.log("[ROUTER]: " + e.toString());
21+
console.log(location.toString());
22+
}
23+
});
24+
25+
this._viewContainerRefService.root = this._vcRef;
26+
}
27+
}

Diff for: e2e/modal-navigation-ng/e2e/screen.ts

+13
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const modalTabView = "Show Modal TabView";
1616
const navToSecondPage = "Navigate To Second Page";
1717
const showDialog = "Show Dialog";
1818
const resetFrameRootView = "Reset Frame Root View";
19+
const resetNamedFrameRootView = "Reset Named Frame Root View";
1920
const resetTabRootView = "Reset Tab Root View";
2021
const resetLayoutRootView = "Reset Layout Root View";
2122

@@ -48,6 +49,12 @@ export class Screen {
4849
await btnResetFrameRootView.tap();
4950
}
5051

52+
resetNamedFrameRootView = async () => {
53+
console.log("Setting named frame root ...");
54+
const btnResetFrameRootView = await this._driver.findElementByText(resetNamedFrameRootView);
55+
await btnResetFrameRootView.tap();
56+
}
57+
5158
resetLayoutRootView = async () => {
5259
console.log("Setting layout root ...");
5360
const btnResetLayoutRootView = await this._driver.findElementByText(resetLayoutRootView);
@@ -71,6 +78,12 @@ export class Screen {
7178
await this.resetFrameRootView();
7279
}
7380

81+
setNamedFrameRootView = async () => {
82+
// should load named frame root, no need to verify it is loaded
83+
await this.loadedHome();
84+
await this.resetNamedFrameRootView();
85+
}
86+
7487
setTabRootView = async () => {
7588
// should load tab root
7689
await this.loadedHome();

Diff for: e2e/modal-navigation-ng/e2e/shared.e2e-spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { Screen } from "./screen"
33

44
const time = 1;
55

6-
export const roots = ["setFrameRootView", "setLayoutRootView", "setTabRootView"];
6+
export const roots = ["setFrameRootView", "setLayoutRootView", "setTabRootView", "setNamedFrameRootView"];
77

88
export async function modalFrameBackground(driver: AppiumDriver, screen: Screen) {
99
await driver.backgroundApp(time);

0 commit comments

Comments
 (0)