Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 1a79f97

Browse files
ADjenkovADjenkov
ADjenkov
authored and
ADjenkov
committedFeb 21, 2019
tests: add e2e tests in single-page app
1 parent ccc75ee commit 1a79f97

File tree

6 files changed

+73
-11
lines changed

6 files changed

+73
-11
lines changed
 

‎e2e/single-page/app/app.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.title {
2-
font-size: 30;
2+
font-size: 15;
33
margin: 16;
44
}
55

‎e2e/single-page/app/app.module.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,19 @@ import { AppComponent } from "./app.component";
1111

1212
import { rendererTraceCategory, viewUtilCategory, routeReuseStrategyTraceCategory, routerTraceCategory } from "nativescript-angular/trace";
1313
import { setCategories, enable } from "tns-core-modules/trace";
14+
import { ModalComponent } from "./second/modal/modal.component";
1415
setCategories(routerTraceCategory + "," + routeReuseStrategyTraceCategory);
1516
enable();
1617

1718
@NgModule({
1819
declarations: [
1920
AppComponent,
21+
ModalComponent,
2022
...navigatableComponents,
2123
],
24+
entryComponents:[
25+
ModalComponent
26+
],
2227
bootstrap: [AppComponent],
2328
providers: [
2429
{ provide: NgModuleFactoryLoader, useClass: NSModuleFactoryLoader }
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<StackLayout>
2+
<Label text="Welcome to modal"></Label>
3+
<Button text="Close Modal" (tap)="close()"></Button>
4+
</StackLayout>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { Component } from '@angular/core';
2+
import { ModalDialogParams } from "nativescript-angular/modal-dialog";
3+
4+
@Component({
5+
moduleId: module.id,
6+
selector: 'modal',
7+
templateUrl: './modal.component.html'
8+
})
9+
10+
export class ModalComponent {
11+
12+
constructor(private params: ModalDialogParams) {
13+
}
14+
15+
public close(result: string) {
16+
this.params.closeCallback(result);
17+
}
18+
19+
}

‎e2e/single-page/app/second/second.component.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
import { Component, OnInit, OnDestroy } from "@angular/core";
1+
import { Component, OnInit, OnDestroy, ViewContainerRef } from "@angular/core";
22
import { ActivatedRoute, Router, Route } from "@angular/router";
33

4+
import { ModalDialogService, ModalDialogOptions } from "nativescript-angular";
45
import { Page } from "tns-core-modules/ui/page";
56
import { Observable } from "rxjs";
67
import { map } from "rxjs/operators";
78
import { RouterExtensions } from "nativescript-angular/router";
9+
import { ModalComponent } from "./modal/modal.component";
810

911
@Component({
1012
selector: "second",
@@ -19,12 +21,16 @@ import { RouterExtensions } from "nativescript-angular/router";
1921
2022
<StackLayout>
2123
<Label [text]="'Second Component: ' + (id$ | async)" class="title"></Label>
24+
<Button text="Show Modal" (tap)="onShowModal()"></Button>
2225
<Button text="Back" (tap)="back()"></Button>
2326
</StackLayout>`
2427
})
2528
export class SecondComponent implements OnInit, OnDestroy {
2629
public id$: Observable<number>;
27-
constructor(route: ActivatedRoute, private routerExtensions: RouterExtensions) {
30+
constructor(route: ActivatedRoute,
31+
private routerExtensions: RouterExtensions,
32+
private viewContainerRef: ViewContainerRef,
33+
private modalService: ModalDialogService) {
2834
this.id$ = route.params.pipe(map(r => +r["id"]));
2935
}
3036

@@ -39,4 +45,16 @@ export class SecondComponent implements OnInit, OnDestroy {
3945
back() {
4046
this.routerExtensions.back();
4147
}
48+
49+
onShowModal() {
50+
let options: ModalDialogOptions = {
51+
viewContainerRef: this.viewContainerRef,
52+
context: {
53+
},
54+
fullscreen: true
55+
};
56+
57+
this.modalService.showModal(ModalComponent, options).then((dialogResult: string) => {
58+
});
59+
}
4260
}

‎e2e/single-page/e2e/tests.e2e-spec.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,29 +19,45 @@ describe("Single page app", () => {
1919
});
2020

2121
it("should load second(1) page", async () => {
22-
await findAndClick(driver, "SECOND(1)")
22+
await findAndClick(driver, "SECOND(1)");
2323

2424
await driver.findElementByAutomationText("Second Component: 1");
25-
25+
2626
// ActionBar Title and item
2727
await driver.findElementByAutomationText("Second Title");
2828
await driver.findElementByAutomationText("ACTION2");
2929
});
3030

3131
it("should load second(2) page", async () => {
32-
await findAndClick(driver, "SECOND(2)")
32+
await findAndClick(driver, "SECOND(2)");
33+
34+
await driver.findElementByAutomationText("Second Component: 2");
3335

34-
await driver.findElementByAutomationText("Second Component: 1");
35-
3636
// ActionBar Title and items
3737
await driver.findElementByAutomationText("Second Title");
3838
await driver.findElementByAutomationText("ACTION2");
3939
await driver.findElementByAutomationText("ADD");
4040
});
41+
42+
it("should open and close modal view", async () => {
43+
await findAndClick(driver, "Show Modal");
44+
45+
await driver.findElementByAutomationText("Welcome to modal");
46+
await findAndClick(driver, "Close Modal");
47+
48+
await driver.findElementByAutomationText("Second Component: 2");
49+
});
50+
51+
it("should go back to second(1) and first", async () => {
52+
await findAndClick(driver, "Back");
53+
await driver.findElementByAutomationText("Second Component: 1");
54+
await findAndClick(driver, "Back");
55+
await driver.findElementByAutomationText("First Title");
56+
await driver.findElementByAutomationText("ACTION1");
57+
});
4158
});
4259

4360
async function findAndClick(driver: AppiumDriver, text: string) {
44-
const navigationButton =
45-
await driver.findElementByAutomationText(text);
46-
navigationButton.click();
61+
const navigationButton = await driver.findElementByAutomationText(text);
62+
await navigationButton.click();
4763
}

0 commit comments

Comments
 (0)
Please sign in to comment.