Sitelet https://github.com/NativeScript/NativeScript/commit/430c616b938f8b78cd6b8c4917637f2d7b2aceee
Skip to content

Commit 430c616

Browse files
Merge pull request #7940 from NativeScript/tsenov/merge-release-master-tests
chore: merge release master tests
2 parents 866c2b0 + 6c6cbbc commit 430c616

11 files changed

Lines changed: 344 additions & 83 deletions

File tree

‎e2e/ui-tests-app/.vscode/launch.json‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@
2727
"--colors",
2828
"--opts",
2929
"../config/mocha.opts",
30-
"--grep=bottom-navigation",
30+
"--grep",
31+
"gestures-events-gestures",
3132
"-a",
3233
],
3334
"internalConsoleOptions": "openOnSessionStart",
@@ -45,10 +46,7 @@
4546
"--opts",
4647
"../config/mocha.opts",
4748
"--grep=bottom-navigation",
48-
"android",
49-
"--grep=bottom-navigation",
50-
"--port",
51-
"8889",
49+
"android"
5250
],
5351
"internalConsoleOptions": "openOnSessionStart"
5452
}
Lines changed: 100 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,133 +1,168 @@
1-
import * as labelModule from "tns-core-modules/ui/label";
2-
import * as gestures from "tns-core-modules/ui/gestures";
3-
import * as button from "tns-core-modules/ui/button";
4-
import * as pages from "tns-core-modules/ui/page";
5-
import * as deviceProperties from "tns-core-modules/platform";
6-
import * as stackLayoutModule from "tns-core-modules/ui/layouts/stack-layout";
1+
import {
2+
GestureEventData,
3+
RotationGestureEventData,
4+
GestureTypes,
5+
SwipeGestureEventData,
6+
PanGestureEventData,
7+
PinchGestureEventData,
8+
GestureStateTypes
9+
} from "tns-core-modules/ui/gestures";
10+
import { Button } from "tns-core-modules/ui/button";
11+
import { Label } from "tns-core-modules/ui/label";
12+
import { Page } from "tns-core-modules/ui/page";
13+
import { StackLayout } from "tns-core-modules/ui/layouts/stack-layout";
14+
import { screen, isAndroid } from "tns-core-modules/platform";
715

816
export function createPage() {
9-
10-
var stack = new stackLayoutModule.StackLayout();
11-
var labelHeight = Math.round(deviceProperties.screen.mainScreen.heightPixels / (7 * deviceProperties.screen.mainScreen.scale));
12-
var stopButton = new button.Button();
17+
const stack = new StackLayout();
18+
var stopButton = new Button();
19+
if (isAndroid) {
20+
stopButton.height = 30;
21+
stopButton.fontSize = 8;
22+
}
1323
stopButton.text = "Stop Detecting Gestures";
24+
stopButton.automationText = "stopGesturesDetecting";
1425
stack.addChild(stopButton);
1526

16-
var tapLabel = new labelModule.Label();
17-
tapLabel.text = "Tap here";
27+
const labelHeight = Math.round(screen.mainScreen.heightPixels / (10 * screen.mainScreen.scale));
28+
29+
const tapLabel = createLabel("Tap here", labelHeight);
1830
stack.addChild(tapLabel);
1931

20-
var doubletapLabel = new labelModule.Label();
21-
doubletapLabel.text = "Double Tap here";
22-
stack.addChild(doubletapLabel);
32+
const doubleTapLabel = createLabel("Double Tap here", labelHeight);
33+
stack.addChild(doubleTapLabel);
34+
35+
const longPressLabel = createLabel("Long Press here", labelHeight);
36+
stack.addChild(longPressLabel);
2337

24-
var longpressLabel = new labelModule.Label();
25-
longpressLabel.text = "Long Press here";
26-
stack.addChild(longpressLabel);
38+
const tapAndDoubleTapLabel = createLabel("Tap or Double Tap", labelHeight, true);
39+
stack.addChild(tapAndDoubleTapLabel);
2740

28-
var swipeLabel = new labelModule.Label();
29-
swipeLabel.height = labelHeight;
30-
swipeLabel.text = "Swipe here";
31-
swipeLabel.textWrap = true;
41+
const swipeLabel = createLabel("Swipe here", labelHeight, true);
3242
stack.addChild(swipeLabel);
3343

34-
var panLabel = new labelModule.Label();
35-
panLabel.height = labelHeight;
36-
panLabel.text = "Pan here";
37-
panLabel.textWrap = true;
44+
const panLabel = createLabel("Pan here", labelHeight, true);
3845
stack.addChild(panLabel);
3946

40-
var pinchLabel = new labelModule.Label();
41-
pinchLabel.height = labelHeight;
42-
pinchLabel.text = "Pinch here";
43-
pinchLabel.textWrap = true;
47+
const pinchLabel = createLabel("Pinch here", labelHeight, true);
4448
stack.addChild(pinchLabel);
4549

46-
var rotaionLabel = new labelModule.Label();
47-
rotaionLabel.height = labelHeight;
48-
rotaionLabel.text = "Rotate here";
49-
rotaionLabel.textWrap = true;
50-
stack.addChild(rotaionLabel);
50+
const rotationLabel = createLabel("Rotate here", labelHeight, true);
51+
stack.addChild(rotationLabel);
5152

52-
stopButton.on(button.Button.tapEvent, function () {
53+
stopButton.on("tap", function () {
5354
observer1.disconnect();
5455
observer2.disconnect();
5556
observer3.disconnect();
5657
observer4.disconnect();
5758
observer5.disconnect();
5859
observer6.disconnect();
5960
observer7.disconnect();
61+
observer8.disconnect();
62+
observer9.disconnect();
6063
tapLabel.text = "Gestures detection disabled";
61-
doubletapLabel.text = "Gestures detection disabled";
62-
longpressLabel.text = "Gestures detection disabled";
63-
swipeLabel.text = "Gesturesd detection disabled";
64+
tapLabel.automationText = "Gestures detection disabled";
65+
doubleTapLabel.text = "Gestures detection disabled";
66+
doubleTapLabel.automationText = "Gestures detection disabled";
67+
longPressLabel.text = "Gestures detection disabled";
68+
longPressLabel.automationText = "Gestures detection disabled";
69+
swipeLabel.text = "Gestures detection disabled";
70+
swipeLabel.automationText = "Gestures detection disabled";
6471
panLabel.text = "Gestures detection disabled";
72+
panLabel.automationText = "Gestures detection disabled";
6573
pinchLabel.text = "Gestures detection disabled";
66-
rotaionLabel.text = "Gestures detection disabled";
74+
pinchLabel.automationText = "Gestures detection disabled";
75+
rotationLabel.text = "Gestures detection disabled";
76+
rotationLabel.automationText = "Gestures detection disabled";
77+
tapAndDoubleTapLabel.text = "Gestures detection disabled";
78+
tapAndDoubleTapLabel.automationText = "Gestures detection disabled";
6779
});
6880

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

73-
var observer1 = tapLabel.getGestureObservers(gestures.GestureTypes.tap)[0];
85+
const observer1 = tapLabel.getGestureObservers(GestureTypes.tap)[0];
7486

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

79-
var observer2 = doubletapLabel.getGestureObservers(gestures.GestureTypes.doubleTap)[0];
91+
const observer2 = doubleTapLabel.getGestureObservers(GestureTypes.doubleTap)[0];
8092

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

85-
var observer3 = longpressLabel.getGestureObservers(gestures.GestureTypes.longPress)[0];
97+
const observer3 = longPressLabel.getGestureObservers(GestureTypes.longPress)[0];
8698

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

91-
var observer4 = swipeLabel.getGestureObservers(gestures.GestureTypes.swipe)[0];
103+
const observer4 = swipeLabel.getGestureObservers(GestureTypes.swipe)[0];
92104

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

97-
var observer5 = panLabel.getGestureObservers(gestures.GestureTypes.pan)[0];
109+
const observer5 = panLabel.getGestureObservers(GestureTypes.pan)[0];
98110

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

103-
var observer6 = pinchLabel.getGestureObservers(gestures.GestureTypes.pinch)[0];
115+
const observer6 = pinchLabel.getGestureObservers(GestureTypes.pinch)[0];
104116

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

109-
var observer7 = rotaionLabel.getGestureObservers(gestures.GestureTypes.rotation)[0];
121+
const observer7 = rotationLabel.getGestureObservers(GestureTypes.rotation)[0];
110122

111-
var page = new pages.Page();
112-
page.content = stack;
123+
tapAndDoubleTapLabel.on(GestureTypes[GestureTypes.doubleTap], function (args: GestureEventData) {
124+
tapAndDoubleTapLabel.text = "Last action: Double tap gesture, " + (args.object === tapAndDoubleTapLabel);
125+
});
126+
127+
const observer8 = tapAndDoubleTapLabel.getGestureObservers(GestureTypes.doubleTap)[0];
113128

129+
tapAndDoubleTapLabel.on(GestureTypes[GestureTypes.tap], function (args: GestureEventData) {
130+
tapAndDoubleTapLabel.text = "Last action: Tap gesture, " + (args.object === tapAndDoubleTapLabel);
131+
});
132+
133+
const observer9 = tapAndDoubleTapLabel.getGestureObservers(GestureTypes.tap)[0];
134+
135+
const page = new Page();
136+
page.content = stack;
137+
114138
return page;
115139
}
116140

117-
var states = new Array<string>();
118-
function getStateAsString(state: gestures.GestureStateTypes): string {
119-
if (state === gestures.GestureStateTypes.began) {
141+
function getStateAsString(state: GestureStateTypes): string {
142+
const states = new Array<string>();
143+
if (state === GestureStateTypes.began) {
120144
states.length = 0;
121145
states.push("began");
122-
} else if (state === gestures.GestureStateTypes.cancelled) {
146+
} else if (state === GestureStateTypes.cancelled) {
123147
states.push("cancelled");
124-
} else if (state === gestures.GestureStateTypes.changed) {
148+
} else if (state === GestureStateTypes.changed) {
125149
if (states.indexOf("changed") === -1) {
126150
states.push("changed");
127151
}
128-
} else if (state === gestures.GestureStateTypes.ended) {
152+
} else if (state === GestureStateTypes.ended) {
129153
states.push("ended");
130154
}
131155

132156
return ", states: " + states.join(",");
133157
}
158+
159+
function createLabel(text: string, labelHeight: number, shouldWrap = false) {
160+
const label = new Label();
161+
label.height = labelHeight;
162+
label.text = text;
163+
label.textWrap = shouldWrap;
164+
label.borderColor = "green";
165+
label.borderWidth = 1;
166+
167+
return label;
168+
}
Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
1-
import * as observable from "tns-core-modules/data/observable";
2-
import * as gestures from "tns-core-modules/ui/gestures";
3-
import * as pages from "tns-core-modules/ui/page";
1+
import { EventData } from "tns-core-modules/data/observable";
2+
import { GestureEventData } from "tns-core-modules/ui/gestures";
3+
import { Page } from "tns-core-modules/ui/page";
4+
import { Label } from "tns-core-modules/ui/label/label";
45

5-
export function pageLoaded(args: observable.EventData) {
6-
var page = <pages.Page>args.object;
7-
page.bindingContext = { tapAction: tapAction, doubleTapAction: doubleTapAction };
6+
export function pageLoaded(args: EventData) {
7+
var page = <Page>args.object;
8+
page.bindingContext = { tapAction: tapAction, doubleTapAction: doubleTapAction, cleanResult: cleanResult };
89
}
910

10-
export function tapAction(args: gestures.GestureEventData) {
11-
console.log("tapAction");
11+
export function tapAction(args: GestureEventData) {
12+
setResult(args, "tapAction");
1213
}
1314

14-
export function doubleTapAction(args: gestures.GestureEventData) {
15-
console.log("doubleTapAction");
15+
export function doubleTapAction(args: GestureEventData) {
16+
setResult(args, "doubleTapAction");
1617
}
18+
19+
export function cleanResult(args: GestureEventData) {
20+
setResult(args, "");
21+
}
22+
23+
const setResult = (args: GestureEventData, text: string) => {
24+
console.log(text);
25+
const resultPanel: Label = (<Page>((<any>args.object).page)).getViewById("resultContainer");
26+
resultPanel.text = text;
27+
};

‎e2e/ui-tests-app/app/events/handlers-page.xml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,8 @@
22
<StackLayout>
33
<Label text="Handlers as exports" tap="tapAction" doubleTap="doubleTapAction" />
44
<Label text="Bound handlers" tap="{{ tapAction }}" doubleTap="{{ doubleTapAction }}" />
5+
<Label text="Result: "></Label>
6+
<Label id="resultContainer"></Label>
7+
<Button text="clean-result" tap="{{ cleanResult }}" />
58
</StackLayout>
69
</Page>

‎e2e/ui-tests-app/e2e/suites/css/styles/styles-page.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class StylesPage extends PageObjectBaseModel {
1515
}
1616

1717
async tapAppBtn() {
18-
await (await this.btnApp()).tap();
18+
await (await this.btnApp()).click();
1919
logInfo(`Tap on '${this.app}' button.`);
2020
}
2121
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import { AppiumDriver, createDriver, nsCapabilities } from "nativescript-dev-appium";
2+
import { assert } from "chai";
3+
import { setImageName } from "../../../helpers/image-helper";
4+
import { EventsGesturesBasePage } from "../events-gestures-base-page";
5+
6+
const suite = "gestures-events";
7+
const spec = "common";
8+
const imagePrefix = `${suite}-${spec}`;
9+
10+
describe(`${imagePrefix}-suite`, () => {
11+
let driver: AppiumDriver;
12+
let basePage: EventsGesturesBasePage;
13+
14+
before(async function () {
15+
nsCapabilities.testReporter.context = this;
16+
driver = await createDriver();
17+
await driver.restartApp();
18+
basePage = new EventsGesturesBasePage(driver);
19+
await basePage.initSuite();
20+
});
21+
22+
after(async function () {
23+
await basePage.endSuite();
24+
});
25+
26+
beforeEach(function () {
27+
driver.imageHelper.testName = setImageName(suite, spec, this.currentTest.title);
28+
});
29+
30+
afterEach(async function () {
31+
if (this.currentTest.state === "failed") {
32+
await driver.logTestArtifacts(this.currentTest.title);
33+
await driver.restartApp();
34+
await basePage.initSuite();
35+
}
36+
});
37+
38+
it(`${imagePrefix}-handlers`, async function () {
39+
const getResult = async (text) => {
40+
return (await driver.waitForElement(text));
41+
};
42+
43+
const cleanResult = async () => {
44+
return await (await driver.waitForElement("clean-result")).click();
45+
};
46+
47+
await basePage.navigateToSample("handlers");
48+
49+
const handlersExport = await driver.findElementByText("Handlers as exports");
50+
51+
await handlersExport.click();
52+
assert.isTrue(getResult("tapAction") != null);
53+
await cleanResult();
54+
55+
await handlersExport.doubleTap();
56+
assert.isTrue(getResult("doubleTapAction") != null);
57+
await cleanResult();
58+
59+
const boundHandlers = await driver.findElementByText("Bound handlers");
60+
await boundHandlers.click();
61+
assert.isTrue(getResult("tapAction") != null);
62+
await cleanResult();
63+
await handlersExport.doubleTap();
64+
assert.isTrue(getResult("doubleTapAction") != null);
65+
await cleanResult();
66+
});
67+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import { AppiumDriver } from "nativescript-dev-appium";
2+
import { PageObjectBaseModel } from "../../page-object-base-model";
3+
import { ElementCacheStrategy } from "../../helpers/navigation-helper";
4+
5+
export class EventsGesturesBasePage extends PageObjectBaseModel {
6+
7+
constructor(_driver: AppiumDriver, navigationLinks?: Array<string>) {
8+
super(_driver, navigationLinks ? navigationLinks.unshift("events") && navigationLinks : ["events"], ElementCacheStrategy.none);
9+
}
10+
}

0 commit comments

Comments
 (0)