Skip to content

Commit a6ff509

Browse files
ADjenkovSvetoslavTsenov
authored andcommitted
fix(page-router-outlet): actionBarVisibility not applied (#1621)
* fix(p-r-o): actionBarVisibility has no effect when applied to nested lazy loaded named outlet * tets: add tests for actionBarVisibility and lazy loaded named outlet * chore: include images for ios
1 parent 851ba1d commit a6ff509

32 files changed

+113
-12
lines changed

‎e2e/renderer/app/app-routing.module.ts

+11-2
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 { ActionBarDynamicItemsComponent } from "./action-bar/action-bar-dynamic-items.component";
55
import { ActionBarExtensionComponent } from "./action-bar/action-bar-extension.component";
@@ -54,6 +54,16 @@ export const routes = [
5454
component: NestedPageComponent
5555
}]
5656
},
57+
{
58+
path: "action-bar-visibility-never-lazy",
59+
component: ActionBarVisibilityNeverComponent,
60+
children: [{
61+
path: "nested",
62+
outlet: "nested",
63+
component: NSEmptyOutletComponent,
64+
loadChildren:"~/page-router-outlet/nested-lazy-page.module#NestedLazyPageModule"
65+
}]
66+
},
5767
{
5868
path: "action-bar-dynamic",
5969
component: ActionBarDynamicItemsComponent,
@@ -111,7 +121,6 @@ export const navigatableComponents = [
111121
ActionBarVisibilityAlwaysComponent,
112122
ActionBarVisibilityNeverComponent,
113123
ActionBarVisibilityAutoComponent,
114-
NestedPageComponent,
115124

116125
TabItemBindingComponent,
117126

‎e2e/renderer/app/app.module.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import { ItemsService } from "./items.service";
1111

1212
import { rendererTraceCategory, viewUtilCategory, bootstrapCategory } from "nativescript-angular/trace";
1313
import { addCategories, enable, categories } from "tns-core-modules/trace";
14+
import { SharedModule } from "./shared.module";
15+
1416
addCategories(bootstrapCategory);
1517
addCategories(rendererTraceCategory);
1618
addCategories(viewUtilCategory);
@@ -22,7 +24,7 @@ export class MyErrorHandler implements ErrorHandler {
2224
console.log("### ErrorHandler Error: " + error.toString());
2325
console.log("### ErrorHandler Stack: " + error.stack);
2426
}
25-
}
27+
}
2628

2729

2830
@NgModule({
@@ -38,6 +40,7 @@ export class MyErrorHandler implements ErrorHandler {
3840
imports: [
3941
NativeScriptModule,
4042
AppRoutingModule,
43+
SharedModule
4144
],
4245
schemas: [NO_ERRORS_SCHEMA],
4346
})

‎e2e/renderer/app/list.component.ts

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Component } from "@angular/core";
99
<Button text="ActionBarVisibility Always" [nsRouterLink]="['/action-bar-visibility-always']"></Button>
1010
<Button text="ActionBarVisibility Never" [nsRouterLink]="['/action-bar-visibility-never']"></Button>
1111
<Button text="ActionBarVisibility Auto" [nsRouterLink]="['/action-bar-visibility-auto']"></Button>
12+
<Button text="ActionBarVisibility Never Lazy" [nsRouterLink]="['/action-bar-visibility-never-lazy']"></Button>
1213
<Button text="TabItem Binding" [nsRouterLink]="['/tab-item-binding']"></Button>
1314
<Button text="NgFor" [nsRouterLink]="['/ngfor']"></Button>
1415
<Button text="NgForOf" [nsRouterLink]="['/ngforof']"></Button>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
2+
import { NativeScriptRouterModule } from "nativescript-angular/router";
3+
import { NativeScriptCommonModule } from "nativescript-angular/common";
4+
import { SharedModule } from "~/shared.module";
5+
import { NestedPageComponent } from "./nested-page.component";
6+
7+
@NgModule({
8+
imports: [
9+
SharedModule,
10+
NativeScriptCommonModule,
11+
NativeScriptRouterModule,
12+
NativeScriptRouterModule.forChild([
13+
{ path: "", component: NestedPageComponent }
14+
])
15+
],
16+
providers: [
17+
],
18+
schemas: [NO_ERRORS_SCHEMA]
19+
})
20+
export class NestedLazyPageModule { }

‎e2e/renderer/app/shared.module.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
2+
import { NativeScriptRouterModule } from "nativescript-angular/router";
3+
import { NativeScriptCommonModule } from "nativescript-angular/common";
4+
import { NestedPageComponent } from "./page-router-outlet/nested-page.component";
5+
6+
@NgModule({
7+
imports: [
8+
NativeScriptCommonModule,
9+
NativeScriptRouterModule
10+
],
11+
declarations:[NestedPageComponent],
12+
schemas: [NO_ERRORS_SCHEMA]
13+
})
14+
export class SharedModule { }

‎e2e/renderer/e2e/page-router-outlet.e2e-spec.ts

+46
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,52 @@ describe("page-router-outlet-scenario", () => {
9393
});
9494
});
9595

96+
describe("actionBarVisibility 'never' doesn't show action bars in lazy module page", async () => {
97+
let imagePostFix = "";
98+
before(async () => {
99+
driver = await createDriver();
100+
await driver.driver.resetApp();
101+
if (driver.isIOS && driver.nsCapabilities.device.name.toLowerCase().includes("x")) {
102+
imagePostFix = "-lazy";
103+
}
104+
});
105+
106+
afterEach(async function () {
107+
if (this.currentTest.state === "failed") {
108+
await driver.logTestArtifacts(this.currentTest.title);
109+
}
110+
});
111+
112+
it("should navigate to page", async () => {
113+
const navigationButton =
114+
await driver.findElementByAutomationText("ActionBarVisibility Never Lazy");
115+
await navigationButton.click();
116+
117+
await driver.findElementByAutomationText("ShowActionBar");
118+
});
119+
120+
it("should hide action bar by default", async () => {
121+
const screenMatches = await driver.compareScreen(`actionBarVisibility-never-default${imagePostFix}`, 5);
122+
assert(screenMatches);
123+
});
124+
125+
it("should not show action bar when shown by page", async () => {
126+
const showActionBarButton = await driver.findElementByAutomationText("ShowActionBar");
127+
showActionBarButton.click();
128+
129+
const screenMatches = await driver.compareScreen(`actionBarVisibility-never-shown${imagePostFix}`, 5);
130+
assert(screenMatches);
131+
});
132+
133+
it("should not do anything when hidden action bar by page", async () => {
134+
const hideActionBarButton = await driver.findElementByAutomationText("HideActionBar");
135+
hideActionBarButton.click();
136+
137+
const screenMatches = await driver.compareScreen(`actionBarVisibility-never-hidden${imagePostFix}`, 5);
138+
assert(screenMatches);
139+
});
140+
});
141+
96142
describe("actionBarVisibility 'auto' shows action bars based on page", async () => {
97143
before(async () => {
98144
driver = await createDriver();

‎e2e/renderer/package.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@
2424
},
2525
"devDependencies": {
2626
"@angular/compiler-cli": "~7.0.0",
27-
"@types/chai": "^4.0.2",
28-
"@types/mocha": "^2.2.41",
29-
"@types/node": "^7.0.5",
27+
"@ngtools/webpack": "~7.0.0",
28+
"@types/chai": "~4.1.3",
29+
"@types/mocha": "~5.2.1",
30+
"@types/node": "10.11.4",
3031
"babel-traverse": "6.25.0",
3132
"babel-types": "6.25.0",
3233
"babylon": "6.17.4",
3334
"chai": "~4.1.1",
3435
"chai-as-promised": "~7.1.1",
3536
"colors": "^1.1.2",
3637
"lazy": "1.0.11",
37-
"mocha": "~3.5.0",
38-
"mocha-junit-reporter": "^1.13.0",
39-
"mocha-multi": "^0.11.0",
38+
"mocha": "~5.1.0",
39+
"mocha-junit-reporter": "~1.17.0",
40+
"mocha-multi": "~1.0.0",
4041
"nativescript-dev-appium": "next",
4142
"nativescript-dev-typescript": "~0.7.1",
4243
"nativescript-dev-webpack": "next",
4344
"tslib": "^1.7.1",
44-
"typescript": "~3.1.1",
45-
"@ngtools/webpack": "~7.0.0"
45+
"typescript": "~3.1.1"
4646
},
4747
"scripts": {
4848
"e2e": "tsc -p e2e && mocha --opts ../config/mocha.opts --recursive e2e --appiumCapsLocation ../config/appium.capabilities.json",
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
1-
import { Component } from "@angular/core";
1+
import { Component, ViewChild } from "@angular/core";
22
import { Page } from "tns-core-modules/ui/page";
3+
import { PageRouterOutlet } from "./page-router-outlet";
34
@Component({
45
// tslint:disable-next-line:component-selector
56
selector: "ns-empty-outlet",
67
moduleId: module.id,
78
template: "<page-router-outlet isEmptyOutlet='true'></page-router-outlet>"
89
})
910
export class NSEmptyOutletComponent {
11+
@ViewChild(PageRouterOutlet) pageRouterOutlet: PageRouterOutlet;
1012
constructor(private page: Page) {
1113
if (this.page) {
1214
this.page.actionBarHidden = true;
15+
16+
this.page.on("loaded", () => {
17+
if (this.pageRouterOutlet && this.page.frame) {
18+
this.pageRouterOutlet.setActionBarVisibility(this.page.frame.actionBarVisibility);
19+
}
20+
});
1321
}
1422
}
1523
}

0 commit comments

Comments
 (0)