Skip to content

Commit e2e78c8

Browse files
committed
fix(touch): touchend processing should remove the touch from the cache
1 parent 15b4c2c commit e2e78c8

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/internal/NonoRobotImpl.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,16 @@ export class NonoRobotImpl implements NonoRobot {
365365

366366
public touchend(params?: EventTarget | string | (EventTargetInit & TouchEventInit),
367367
touches?: Array<Partial<TouchInit>>, timestamp?: number): this {
368-
return this.processTouchEvent("touchend", this.processPotentialCssSelector(params), touches, timestamp);
368+
const res = this.processTouchEvent("touchend", this.processPotentialCssSelector(params), touches, timestamp);
369+
// Removing the touches that correspond to the touchend
370+
const target = this.currentTarget;
371+
if (target !== undefined) {
372+
const map = this.ongoingtouchevents.get(target);
373+
touches?.map(t => t.identifier ?? -1).forEach(i => {
374+
map?.delete(i);
375+
});
376+
}
377+
return res;
369378
}
370379

371380
public do(fn: () => void): this {

test/internal/NonoRobotImpl.spec.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ describe("robot with default event target", () => {
1515

1616
afterEach(() => {
1717
jest.clearAllTimers();
18+
jest.clearAllMocks();
1819
});
1920

2021
describe("with mouse events", () => {
@@ -233,6 +234,34 @@ describe("robot with default event target", () => {
233234
div2.addEventListener("touchmove", handler2);
234235
});
235236

237+
test("on touchend, the touch is removed from the cache", () => {
238+
robot
239+
.touchmove({}, [
240+
{"identifier": 1, "screenX": 16, "screenY": 130, "clientX": 140, "clientY": 241, "force": 18, "pageX": 1,
241+
"pageY": 5, "radiusX": 420, "radiusY": 540, "rotationAngle": 64, "altitudeAngle": 112, "azimuthAngle": 123}
242+
])
243+
.touchmove({}, [
244+
{"identifier": 2, "screenX": 16, "screenY": 130, "clientX": 140, "clientY": 241, "force": 18, "pageX": 1,
245+
"pageY": 5, "radiusX": 420, "radiusY": 540, "rotationAngle": 64, "altitudeAngle": 112, "azimuthAngle": 123}
246+
])
247+
.touchend({}, [
248+
{"identifier": 1, "screenX": 16, "screenY": 130, "clientX": 140, "clientY": 241, "force": 18, "pageX": 1,
249+
"pageY": 5, "radiusX": 420, "radiusY": 540, "rotationAngle": 64, "altitudeAngle": 112, "azimuthAngle": 123}
250+
])
251+
.touchmove({}, [
252+
{"identifier": 2, "screenX": 17, "screenY": 130, "clientX": 140, "clientY": 241, "force": 18, "pageX": 1,
253+
"pageY": 5, "radiusX": 420, "radiusY": 540, "rotationAngle": 64, "altitudeAngle": 112, "azimuthAngle": 123}
254+
]);
255+
256+
expect(handler).toHaveBeenNthCalledWith(3, expect.objectContaining({
257+
"targetTouches": [
258+
{"identifier": 2, "screenX": 17, "screenY": 130, "clientX": 140, "clientY": 241, "force": 18, "pageX": 1,
259+
"pageY": 5, "radiusX": 420, "radiusY": 540, "rotationAngle": 64, "altitudeAngle": 112, "azimuthAngle": 123,
260+
"target": div, "touchType": "direct"}
261+
]
262+
}));
263+
});
264+
236265
test("targetTouches and touches attribute filled after several touch events", () => {
237266
robot
238267
.touchmove({}, [

0 commit comments

Comments
 (0)