Skip to content

fix: mark reattached view for CD #1803

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 2 commits into from
May 8, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 13 additions & 0 deletions e2e/router/app/counter.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Injectable } from "@angular/core";
import { BehaviorSubject } from "rxjs";

@Injectable({
providedIn: "root"
})
export class CounterService {
counter$ = new BehaviorSubject<number>(0);

tick() {
this.counter$.next(this.counter$.value + 1);
}
}
8 changes: 6 additions & 2 deletions e2e/router/app/first/first.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { Location } from "@angular/common";
import { RouterExtensions } from "nativescript-angular/router";

import { Page } from "tns-core-modules/ui/page";
import { CounterService } from "~/counter.service";
import { Observable } from "rxjs";

@Component({
selector: "first",
Expand All @@ -21,12 +23,14 @@ import { Page } from "tns-core-modules/ui/page";
<Button text="RESET" automationText="RESET" (tap)="reset()"></Button>
<Label [text]="message"></Label>
<Label [text]="'CHECK: ' + doCheckCount"></Label>
<Label [text]="'COUNTER: ' + (service.counter$ | async)"></Label>
</StackLayout>`
})
export class FirstComponent implements OnInit, OnDestroy, DoCheck {
public message: string = "";
public doCheckCount: number = 0;
constructor(private routerExt: RouterExtensions, page: Page) {

constructor(private routerExt: RouterExtensions, page: Page, private service: CounterService) {
console.log("FirstComponent - constructor() page: " + page);
}

Expand All @@ -42,7 +46,7 @@ export class FirstComponent implements OnInit, OnDestroy, DoCheck {
this.doCheckCount++;
console.log("FirstComponent - ngDoCheck(): " + this.doCheckCount);
}

reset() {
this.doCheckCount = 0;
}
Expand Down
9 changes: 8 additions & 1 deletion e2e/router/app/second/second.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { RouterExtensions } from "nativescript-angular/router";
import { Page } from "tns-core-modules/ui/page";
import { Observable } from "rxjs";
import { map } from "rxjs/operators";
import { CounterService } from "../counter.service";

@Component({
selector: "second",
Expand All @@ -19,6 +20,8 @@ import { map } from "rxjs/operators";
<Button text="LOAD NESTED NAMED OUTLET" (tap)="loadNestedNamedOutlet()"></Button>
<Button text="BACK" automationText="BACK" (tap)="goBack()"></Button>

<Button text="TICK" automationText="TICK" (tap)="service.tick()"></Button>

<GridLayout row="1" rows="*,*">
<GridLayout row="0" class="nested-outlet">
<router-outlet></router-outlet>
Expand All @@ -33,7 +36,11 @@ export class SecondComponent implements OnInit, OnDestroy {
public depth$: Observable<string>;
public nextDepth$: Observable<number>;

constructor(private routerExt: RouterExtensions, private route: ActivatedRoute, page: Page) {
constructor(
private routerExt: RouterExtensions,
private route: ActivatedRoute,
public service: CounterService,
page: Page) {
console.log("SecondComponent - constructor() page: " + page);
this.depth$ = route.params.pipe(map(r => r["depth"]));
this.nextDepth$ = route.params.pipe(map(r => +r["depth"] + 1));
Expand Down
40 changes: 40 additions & 0 deletions e2e/router/e2e/router.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,46 @@ describe("Simple navigate and back should trigger only one CD on FirstComponent"
});
});

describe("Simple navigate and back should trigger only one CD on FirstComponent even with 3 changes in service", () => {
let driver: AppiumDriver;

before(async () => {
driver = await createDriver();
await driver.resetApp();
});

it("should find First", async () => {
await assureFirstComponent(driver);
});

it("should reset counter", async () => {
await findAndClick(driver, "RESET");
await driver.waitForElement("CHECK: 1");
await driver.waitForElement("COUNTER: 0");
});

it("should navigate to Second(1)/master", async () => {
await findAndClick(driver, "GO TO SECOND");

await assureSecondComponent(driver, 1);
await assureNestedMasterComponent(driver);
});

it("should increase counter", async () => {
await findAndClick(driver, "TICK");
await findAndClick(driver, "TICK");
await findAndClick(driver, "TICK");
});

it("should navigate back to First", async () => {
await goBack(driver);
await assureFirstComponent(driver);
await driver.waitForElement("CHECK: 2");
await driver.waitForElement("COUNTER: 3");
});
});


async function assureFirstComponent(driver: AppiumDriver) {
await driver.findElementByAutomationText("FirstComponent");
}
Expand Down
1 change: 1 addition & 0 deletions nativescript-angular/router/page-router-outlet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ export class PageRouterOutlet implements OnDestroy { // tslint:disable-line:dire
this.activated = ref;

// reattach to ChangeDetection
this.activated.hostView.markForCheck();
this.activated.hostView.reattach();
this._activatedRoute = activatedRoute;
this.markActivatedRoute(activatedRoute);
Expand Down