Skip to content

refactor: ActionBar directive and patching of Views in renderer #979

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 9 commits into from
Sep 7, 2017
27 changes: 27 additions & 0 deletions e2e/renderer/app/action-bar/action-bar-dynamic-items.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Component } from "@angular/core";

@Component({
template: `
<ActionBar title="Action Bar Dynamic Items">
<NavigationButton
*ngIf="showNavigationButton"
android.systemIcon="ic_menu_back"
></NavigationButton>

<ActionItem text="one" *ngIf="show1"></ActionItem>
<ActionItem text="two" *ngIf="show2"></ActionItem>
</ActionBar>

<StackLayout>
<Button text="toggle nav" (tap)="showNavigationButton = !showNavigationButton"></Button>
<Button text="toggle 1" (tap)="show1 = !show1"></Button>
<Button text="toggle 2" (tap)="show2 = !show2"></Button>
</StackLayout>
`
})
export class ActionBarDynamicItemsComponent {
public showNavigationButton = true;
public show1 = true;
public show2 = true;
}

16 changes: 16 additions & 0 deletions e2e/renderer/app/action-bar/action-bar-extension.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { Component } from "@angular/core";

@Component({
template: `
<ActionBarExtension>
<ActionItem (tap)="show = !show" text="toggle">
</ActionItem>

<ActionItem *ngIf="show" text="conditional">
</ActionItem>
</ActionBarExtension>
`
})
export class ActionBarExtensionComponent {
public show = true;
}
14 changes: 14 additions & 0 deletions e2e/renderer/app/app-routing.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { NgModule, NO_ERRORS_SCHEMA } from "@angular/core";
import { NativeScriptRouterModule } from "nativescript-angular/router";

import { ActionBarDynamicItemsComponent } from "./action-bar/action-bar-dynamic-items.component";
import { ActionBarExtensionComponent } from "./action-bar/action-bar-extension.component";

import { ListComponent } from "./list.component";
import { NgForComponent } from "./ngfor.component";
import { NgForOfComponent } from "./ngforof.component";
Expand All @@ -17,6 +20,14 @@ export const routes = [
redirectTo: "/list",
pathMatch: "full"
},
{
path: "action-bar-dynamic",
component: ActionBarDynamicItemsComponent,
},
{
path: "action-bar-extension",
component: ActionBarExtensionComponent,
},
{
path: "list",
component: ListComponent,
Expand Down Expand Up @@ -56,6 +67,9 @@ export const routes = [
];

export const navigatableComponents = [
ActionBarDynamicItemsComponent,
ActionBarExtensionComponent,

ListComponent,
NgForComponent,
NgForOfComponent,
Expand Down
1 change: 0 additions & 1 deletion e2e/renderer/app/content-view.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Component } from "@angular/core";

@Component({
selector: "my-app",
template: `
<ActionBar title="Content View">
<ActionItem (tap)="toggle()">
Expand Down
2 changes: 2 additions & 0 deletions e2e/renderer/app/list.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Component } from "@angular/core";
@Component({
template: `
<FlexboxLayout flexDirection="column">
<Button text="ActionBar dynamic" [nsRouterLink]="['/action-bar-dynamic']"></Button>
<Button text="ActionBarExtension" [nsRouterLink]="['/action-bar-extension']"></Button>
<Button text="NgFor" [nsRouterLink]="['/ngfor']"></Button>
<Button text="NgForOf" [nsRouterLink]="['/ngforof']"></Button>
<Button text="NgIf no layout" [nsRouterLink]="['/ngif-no-layout']"></Button>
Expand Down
163 changes: 163 additions & 0 deletions e2e/renderer/e2e/action-bar.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
import {
AppiumDriver,
createDriver,
SearchOptions,
elementHelper,
} from "nativescript-dev-appium";

import { isOnTheLeft } from "./helpers/location";
import { DriverWrapper, ExtendedUIElement } from "./helpers/appium-elements";

describe("Action Bar scenario", () => {
let driver: AppiumDriver;
let driverWrapper: DriverWrapper;

describe("dynamically add/remove ActionItems", async () => {
let firstActionItem: ExtendedUIElement;
let secondActionItem: ExtendedUIElement;
let toggleFirstButton: ExtendedUIElement;
let toggleSecondButton: ExtendedUIElement;

before(async () => {
driver = await createDriver();
driverWrapper = new DriverWrapper(driver);
});

after(async () => {
await driver.quit();
console.log("Driver quits!");
});

it("should navigate to page", async () => {
const navigationButton =
await driverWrapper.findElementByText("ActionBar dynamic", SearchOptions.exact);
await navigationButton.click();

const actionBar =
await driverWrapper.findElementByText("Action Bar Dynamic Items", SearchOptions.exact);
});

it("should find elements", async () => {
firstActionItem = await driverWrapper.findElementByText("one");
secondActionItem = await driverWrapper.findElementByText("two");

toggleFirstButton = await driverWrapper.findElementByText("toggle 1");
toggleSecondButton = await driverWrapper.findElementByText("toggle 2");
});

it("should initially render the action items in the correct order", async () => {
await checkOrderIsCorrect();
});

it("should detach first element when its condition is false", done => {
(async () => {
await toggleFirst();

try {
await driverWrapper.findElementByText("one", SearchOptions.exact);
} catch (e) {
done();
}
})();
});

it("should attach first element in the correct position", async () => {
await toggleFirst();
await checkOrderIsCorrect();
});

it("should detach second element when its condition is false", done => {
(async () => {
await toggleSecond();

try {
await driverWrapper.findElementByText("two", SearchOptions.exact);
} catch (e) {
done();
}
})();
});

it("should attach second element in the correct position", async () => {
await toggleSecond();
await checkOrderIsCorrect();
});

it("should detach and then reattach both at correct places", async () => {
await toggleFirst();
await toggleSecond();

await toggleFirst();
await toggleSecond();

await checkOrderIsCorrect();
});

const checkOrderIsCorrect = async () => {
await isOnTheLeft(firstActionItem, secondActionItem);
};

const toggleFirst = async () => {
toggleFirstButton = await toggleFirstButton.refetch();
await toggleFirstButton.click();
};

const toggleSecond = async () => {
toggleSecondButton = await toggleSecondButton.refetch();
await toggleSecondButton.click();
};

});

describe("Action Bar extension with dynamic ActionItem", async () => {
let toggleButton: ExtendedUIElement;
let conditional: ExtendedUIElement;

before(async () => {
driver = await createDriver();
driverWrapper = new DriverWrapper(driver);
});

after(async () => {
await driver.quit();
console.log("Driver quits!");
});

it("should navigate to page", async () => {
const navigationButton =
await driverWrapper.findElementByText("ActionBarExtension", SearchOptions.exact);
await navigationButton.click();
});

it("should find elements", async () => {
toggleButton = await driverWrapper.findElementByText("toggle");
conditional = await driverWrapper.findElementByText("conditional");
});

it("should detach conditional action item when its condition is false", done => {
(async () => {
await toggle();

try {
await driverWrapper.findElementByText("conditional", SearchOptions.exact);
} catch (e) {
done();
}
})();
});

it("should reattach conditional action item at correct place", async () => {
await toggle();
await checkOrderIsCorrect();
});

const checkOrderIsCorrect = async () => {
await isOnTheLeft(toggleButton, conditional);
};

const toggle = async () => {
toggleButton = await toggleButton.refetch();
await toggleButton.click();
};
});
});
21 changes: 21 additions & 0 deletions e2e/renderer/e2e/helpers/appium-elements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,25 @@ export class DriverWrapper {

return result;
}

@refetchable()
async findElementByXPath(...args: any[]): Promise<ExtendedUIElement> {
const result = await (<any>this.driver).findElementByXPath(...args);

return result;
}

@refetchable()
async findElementsByXPath(...args: any[]): Promise<ExtendedUIElement[]> {
const result = await (<any>this.driver).findElementsByXPath(...args);

return result || [];
}

@refetchable()
async findElementsByClassName(...args: any[]): Promise<ExtendedUIElement[]> {
const result = await (<any>this.driver).findElementsByClassName(...args);

return result || [];
}
}
11 changes: 11 additions & 0 deletions e2e/renderer/e2e/helpers/location.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,14 @@ export const isAbove = async (first: ExtendedUIElement, second: ExtendedUIElemen

assert.isTrue(firstY < secondY);
}

export const isOnTheLeft = async (first: ExtendedUIElement, second: ExtendedUIElement) => {
first = await first.refetch();
second = await second.refetch();

const { x: firstX } = await first.location();
const { x: secondX } = await second.location();

assert.isTrue(firstX < secondX);
}

Loading