Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 3 additions & 5 deletions e2e/ui-tests-app/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
"--colors",
"--opts",
"../config/mocha.opts",
"--grep=bottom-navigation",
"--grep",
"gestures-events-gestures",
"-a",
],
"internalConsoleOptions": "openOnSessionStart",
Expand All @@ -45,10 +46,7 @@
"--opts",
"../config/mocha.opts",
"--grep=bottom-navigation",
"android",
"--grep=bottom-navigation",
"--port",
"8889",
"android"
],
"internalConsoleOptions": "openOnSessionStart"
}
Expand Down
165 changes: 100 additions & 65 deletions e2e/ui-tests-app/app/events/gestures-page.ts
Original file line number Diff line number Diff line change
@@ -1,133 +1,168 @@
import * as labelModule from "tns-core-modules/ui/label";
import * as gestures from "tns-core-modules/ui/gestures";
import * as button from "tns-core-modules/ui/button";
import * as pages from "tns-core-modules/ui/page";
import * as deviceProperties from "tns-core-modules/platform";
import * as stackLayoutModule from "tns-core-modules/ui/layouts/stack-layout";
import {
GestureEventData,
RotationGestureEventData,
GestureTypes,
SwipeGestureEventData,
PanGestureEventData,
PinchGestureEventData,
GestureStateTypes
} from "tns-core-modules/ui/gestures";
import { Button } from "tns-core-modules/ui/button";
import { Label } from "tns-core-modules/ui/label";
import { Page } from "tns-core-modules/ui/page";
import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout";
import { screen, isAndroid } from "tns-core-modules/platform";

export function createPage() {

var stack = new stackLayoutModule.StackLayout();
var labelHeight = Math.round(deviceProperties.screen.mainScreen.heightPixels / (7 * deviceProperties.screen.mainScreen.scale));
var stopButton = new button.Button();
const stack = new StackLayout();
var stopButton = new Button();
if (isAndroid) {
stopButton.height = 30;
stopButton.fontSize = 8;
}
stopButton.text = "Stop Detecting Gestures";
stopButton.automationText = "stopGesturesDetecting";
stack.addChild(stopButton);

var tapLabel = new labelModule.Label();
tapLabel.text = "Tap here";
const labelHeight = Math.round(screen.mainScreen.heightPixels / (10 * screen.mainScreen.scale));

const tapLabel = createLabel("Tap here", labelHeight);
stack.addChild(tapLabel);

var doubletapLabel = new labelModule.Label();
doubletapLabel.text = "Double Tap here";
stack.addChild(doubletapLabel);
const doubleTapLabel = createLabel("Double Tap here", labelHeight);
stack.addChild(doubleTapLabel);

const longPressLabel = createLabel("Long Press here", labelHeight);
stack.addChild(longPressLabel);

var longpressLabel = new labelModule.Label();
longpressLabel.text = "Long Press here";
stack.addChild(longpressLabel);
const tapAndDoubleTapLabel = createLabel("Tap or Double Tap", labelHeight, true);
stack.addChild(tapAndDoubleTapLabel);

var swipeLabel = new labelModule.Label();
swipeLabel.height = labelHeight;
swipeLabel.text = "Swipe here";
swipeLabel.textWrap = true;
const swipeLabel = createLabel("Swipe here", labelHeight, true);
stack.addChild(swipeLabel);

var panLabel = new labelModule.Label();
panLabel.height = labelHeight;
panLabel.text = "Pan here";
panLabel.textWrap = true;
const panLabel = createLabel("Pan here", labelHeight, true);
stack.addChild(panLabel);

var pinchLabel = new labelModule.Label();
pinchLabel.height = labelHeight;
pinchLabel.text = "Pinch here";
pinchLabel.textWrap = true;
const pinchLabel = createLabel("Pinch here", labelHeight, true);
stack.addChild(pinchLabel);

var rotaionLabel = new labelModule.Label();
rotaionLabel.height = labelHeight;
rotaionLabel.text = "Rotate here";
rotaionLabel.textWrap = true;
stack.addChild(rotaionLabel);
const rotationLabel = createLabel("Rotate here", labelHeight, true);
stack.addChild(rotationLabel);

stopButton.on(button.Button.tapEvent, function () {
stopButton.on("tap", function () {
observer1.disconnect();
observer2.disconnect();
observer3.disconnect();
observer4.disconnect();
observer5.disconnect();
observer6.disconnect();
observer7.disconnect();
observer8.disconnect();
observer9.disconnect();
tapLabel.text = "Gestures detection disabled";
doubletapLabel.text = "Gestures detection disabled";
longpressLabel.text = "Gestures detection disabled";
swipeLabel.text = "Gesturesd detection disabled";
tapLabel.automationText = "Gestures detection disabled";
doubleTapLabel.text = "Gestures detection disabled";
doubleTapLabel.automationText = "Gestures detection disabled";
longPressLabel.text = "Gestures detection disabled";
longPressLabel.automationText = "Gestures detection disabled";
swipeLabel.text = "Gestures detection disabled";
swipeLabel.automationText = "Gestures detection disabled";
panLabel.text = "Gestures detection disabled";
panLabel.automationText = "Gestures detection disabled";
pinchLabel.text = "Gestures detection disabled";
rotaionLabel.text = "Gestures detection disabled";
pinchLabel.automationText = "Gestures detection disabled";
rotationLabel.text = "Gestures detection disabled";
rotationLabel.automationText = "Gestures detection disabled";
tapAndDoubleTapLabel.text = "Gestures detection disabled";
tapAndDoubleTapLabel.automationText = "Gestures detection disabled";
});

tapLabel.on(gestures.GestureTypes.tap, function (args: gestures.GestureEventData) {
tapLabel.on(GestureTypes[GestureTypes.tap], function (args: GestureEventData) {
tapLabel.text = "Tap gesture detected, " + (args.object === tapLabel);
});

var observer1 = tapLabel.getGestureObservers(gestures.GestureTypes.tap)[0];
const observer1 = tapLabel.getGestureObservers(GestureTypes.tap)[0];

doubletapLabel.on(gestures.GestureTypes.doubleTap, function (args: gestures.GestureEventData) {
doubletapLabel.text = "Double Tap gesture detected, " + (args.object === doubletapLabel);
doubleTapLabel.on(GestureTypes[GestureTypes.doubleTap], function (args: GestureEventData) {
doubleTapLabel.text = "Double Tap gesture detected, " + (args.object === doubleTapLabel);
});

var observer2 = doubletapLabel.getGestureObservers(gestures.GestureTypes.doubleTap)[0];
const observer2 = doubleTapLabel.getGestureObservers(GestureTypes.doubleTap)[0];

longpressLabel.on(gestures.GestureTypes.longPress, function (args: gestures.GestureEventData) {
longpressLabel.text = "Long Press gesture detected, " + (args.object === longpressLabel);
longPressLabel.on(GestureTypes[GestureTypes.longPress], function (args: GestureEventData) {
longPressLabel.text = "Long Press gesture detected, " + (args.object === longPressLabel);
});

var observer3 = longpressLabel.getGestureObservers(gestures.GestureTypes.longPress)[0];
const observer3 = longPressLabel.getGestureObservers(GestureTypes.longPress)[0];

swipeLabel.on(gestures.GestureTypes.swipe, function (args: gestures.SwipeGestureEventData) {
swipeLabel.on(GestureTypes[GestureTypes.swipe], function (args: SwipeGestureEventData) {
swipeLabel.text = "Swipe Direction: " + args.direction + ", " + (args.object === swipeLabel); // + getStateAsString(args.state);
});

var observer4 = swipeLabel.getGestureObservers(gestures.GestureTypes.swipe)[0];
const observer4 = swipeLabel.getGestureObservers(GestureTypes.swipe)[0];

panLabel.on(gestures.GestureTypes.pan, function (args: gestures.PanGestureEventData) {
panLabel.on(GestureTypes[GestureTypes.pan], function (args: PanGestureEventData) {
panLabel.text = "Pan deltaX:" + Math.round(args.deltaX) + "; deltaY:" + Math.round(args.deltaY) + ";" + ", " + (args.object === panLabel) + getStateAsString(args.state);
});

var observer5 = panLabel.getGestureObservers(gestures.GestureTypes.pan)[0];
const observer5 = panLabel.getGestureObservers(GestureTypes.pan)[0];

pinchLabel.on(gestures.GestureTypes.pinch, function (args: gestures.PinchGestureEventData) {
pinchLabel.on(GestureTypes[GestureTypes.pinch], function (args: PinchGestureEventData) {
pinchLabel.text = "Pinch Scale: " + Math.round(args.scale) + ", " + (args.object === pinchLabel) + getStateAsString(args.state);
});

var observer6 = pinchLabel.getGestureObservers(gestures.GestureTypes.pinch)[0];
const observer6 = pinchLabel.getGestureObservers(GestureTypes.pinch)[0];

rotaionLabel.on(gestures.GestureTypes.rotation, function (args: gestures.RotationGestureEventData) {
rotaionLabel.text = "Rotation: " + Math.round(args.rotation) + ", " + (args.object === rotaionLabel) + getStateAsString(args.state);
rotationLabel.on(GestureTypes[GestureTypes.rotation], function (args: RotationGestureEventData) {
rotationLabel.text = "Rotation: " + Math.round(args.rotation) + ", " + (args.object === rotationLabel) + getStateAsString(args.state);
});

var observer7 = rotaionLabel.getGestureObservers(gestures.GestureTypes.rotation)[0];
const observer7 = rotationLabel.getGestureObservers(GestureTypes.rotation)[0];

var page = new pages.Page();
page.content = stack;
tapAndDoubleTapLabel.on(GestureTypes[GestureTypes.doubleTap], function (args: GestureEventData) {
tapAndDoubleTapLabel.text = "Last action: Double tap gesture, " + (args.object === tapAndDoubleTapLabel);
});

const observer8 = tapAndDoubleTapLabel.getGestureObservers(GestureTypes.doubleTap)[0];

tapAndDoubleTapLabel.on(GestureTypes[GestureTypes.tap], function (args: GestureEventData) {
tapAndDoubleTapLabel.text = "Last action: Tap gesture, " + (args.object === tapAndDoubleTapLabel);
});

const observer9 = tapAndDoubleTapLabel.getGestureObservers(GestureTypes.tap)[0];

const page = new Page();
page.content = stack;

return page;
}

var states = new Array<string>();
function getStateAsString(state: gestures.GestureStateTypes): string {
if (state === gestures.GestureStateTypes.began) {
function getStateAsString(state: GestureStateTypes): string {
const states = new Array<string>();
if (state === GestureStateTypes.began) {
states.length = 0;
states.push("began");
} else if (state === gestures.GestureStateTypes.cancelled) {
} else if (state === GestureStateTypes.cancelled) {
states.push("cancelled");
} else if (state === gestures.GestureStateTypes.changed) {
} else if (state === GestureStateTypes.changed) {
if (states.indexOf("changed") === -1) {
states.push("changed");
}
} else if (state === gestures.GestureStateTypes.ended) {
} else if (state === GestureStateTypes.ended) {
states.push("ended");
}

return ", states: " + states.join(",");
}

function createLabel(text: string, labelHeight: number, shouldWrap = false) {
const label = new Label();
label.height = labelHeight;
label.text = text;
label.textWrap = shouldWrap;
label.borderColor = "green";
label.borderWidth = 1;

return label;
}
31 changes: 21 additions & 10 deletions e2e/ui-tests-app/app/events/handlers-page.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
import * as observable from "tns-core-modules/data/observable";
import * as gestures from "tns-core-modules/ui/gestures";
import * as pages from "tns-core-modules/ui/page";
import { EventData } from "tns-core-modules/data/observable";
import { GestureEventData } from "tns-core-modules/ui/gestures";
import { Page } from "tns-core-modules/ui/page";
import { Label } from "tns-core-modules/ui/label/label";

export function pageLoaded(args: observable.EventData) {
var page = <pages.Page>args.object;
page.bindingContext = { tapAction: tapAction, doubleTapAction: doubleTapAction };
export function pageLoaded(args: EventData) {
var page = <Page>args.object;
page.bindingContext = { tapAction: tapAction, doubleTapAction: doubleTapAction, cleanResult: cleanResult };
}

export function tapAction(args: gestures.GestureEventData) {
console.log("tapAction");
export function tapAction(args: GestureEventData) {
setResult(args, "tapAction");
}

export function doubleTapAction(args: gestures.GestureEventData) {
console.log("doubleTapAction");
export function doubleTapAction(args: GestureEventData) {
setResult(args, "doubleTapAction");
}

export function cleanResult(args: GestureEventData) {
setResult(args, "");
}

const setResult = (args: GestureEventData, text: string) => {
console.log(text);
const resultPanel: Label = (<Page>((<any>args.object).page)).getViewById("resultContainer");
resultPanel.text = text;
};
3 changes: 3 additions & 0 deletions e2e/ui-tests-app/app/events/handlers-page.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@
<StackLayout>
<Label text="Handlers as exports" tap="tapAction" doubleTap="doubleTapAction" />
<Label text="Bound handlers" tap="{{ tapAction }}" doubleTap="{{ doubleTapAction }}" />
<Label text="Result: "></Label>
<Label id="resultContainer"></Label>
<Button text="clean-result" tap="{{ cleanResult }}" />
</StackLayout>
</Page>
2 changes: 1 addition & 1 deletion e2e/ui-tests-app/e2e/suites/css/styles/styles-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export class StylesPage extends PageObjectBaseModel {
}

async tapAppBtn() {
await (await this.btnApp()).tap();
await (await this.btnApp()).click();
logInfo(`Tap on '${this.app}' button.`);
}
}
68 changes: 68 additions & 0 deletions e2e/ui-tests-app/e2e/suites/gestures-events/common/common-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import { AppiumDriver, createDriver, nsCapabilities, SearchOptions, Direction, LogType } from "nativescript-dev-appium";
import { GesturesPage } from "../gestures/gestures-page";
import { assert } from "chai";
import { setImageName } from "../../../helpers/image-helper";
import { EventsGesturesBasePage } from "../events-gestures-base-page";

const suite = "gestures-events";
const spec = "common";
const imagePrefix = `${suite}-${spec}`;

describe(`${imagePrefix}-suite`, () => {
let driver: AppiumDriver;
let basePage: EventsGesturesBasePage;

before(async function () {
nsCapabilities.testReporter.context = this;
driver = await createDriver();
await driver.restartApp();
basePage = new EventsGesturesBasePage(driver);
await basePage.initSuite();
});

after(async function () {
await basePage.endSuite();
});

beforeEach(function () {
driver.imageHelper.testName = setImageName(suite, spec, this.currentTest.title);
});

afterEach(async function () {
if (this.currentTest.state === "failed") {
await driver.logTestArtifacts(this.currentTest.title);
await driver.restartApp();
await basePage.initSuite();
}
});

it(`${imagePrefix}-handlers`, async function () {
const getResult = async (text) => {
return (await driver.waitForElement(text));
};

const cleanResult = async () => {
return await (await driver.waitForElement("clean-result")).click();
};

basePage.navigateToSample("handlers");

const handlersExport = await driver.findElementByText("Handlers as exports");

await handlersExport.click();
assert.isTrue(getResult("tapAction") != null);
await cleanResult();

await handlersExport.doubleTap();
assert.isTrue(getResult("doubleTapAction") != null);
await cleanResult();

const boundHandlers = await driver.findElementByText("Bound handlers");
await boundHandlers.click();
assert.isTrue(getResult("tapAction") != null);
await cleanResult();
await handlersExport.doubleTap();
assert.isTrue(getResult("doubleTapAction") != null);
await cleanResult();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { AppiumDriver } from "nativescript-dev-appium";
import { PageObjectBaseModel } from "../../page-object-base-model";
import { ElementCacheStrategy } from "../../helpers/navigation-helper";

export class EventsGesturesBasePage extends PageObjectBaseModel {

constructor(_driver: AppiumDriver, navigationLinks?: Array<string>) {
super(_driver, navigationLinks ? navigationLinks.unshift("events") && navigationLinks : ["events"], ElementCacheStrategy.none);
}
}
Loading