Implement e2e tests

This commit is contained in:
Surma
2018-04-25 23:24:54 +01:00
parent 60543dd0a5
commit 307e1f9356
5 changed files with 319 additions and 180 deletions

61
test/finger.js Normal file
View File

@@ -0,0 +1,61 @@
let touchPoints = [];
let idCnt = 0;
class Finger {
constructor(point, page) {
this._point = point;
this._page = page;
}
move(x, y) {
if (!this._point) return;
Object.assign(this._point, {
x: Math.floor(x),
y: Math.floor(y)
});
this._page.touchscreen._client.send("Input.dispatchTouchEvent", {
type: "touchMove",
touchPoints,
modifiers: page._keyboard._modifiers
});
}
up() {
if (!this._point) return;
const idx = touchPoints.indexOf(this._point);
touchPoints = touchPoints.splice(idx, 1);
this._point = null;
if (touchPoints.length === 0) {
this._page.touchscreen._client.send("Input.dispatchTouchEvent", {
type: "touchEnd",
modifiers: this._page._keyboard._modifiers
});
} else {
this._page.touchscreen._client.send("Input.dispatchTouchEvent", {
type: "touchMove",
touchPoints,
modifiers: this._page._keyboard._modifiers
});
}
}
}
function fingerDown(page, x, y) {
const id = idCnt++;
const point = {
x: Math.round(x),
y: Math.round(y),
id
};
touchPoints.push(point);
page.touchscreen._client.send("Input.dispatchTouchEvent", {
type: "touchStart",
touchPoints,
modifiers: page._keyboard._modifiers
});
return new Finger(point, page);
}
module.exports = {
fingerDown
};