53 lines
1.5 KiB
Python
53 lines
1.5 KiB
Python
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
from driver._w3c_actions import (
|
|
build_double_tap_actions,
|
|
build_swipe_actions,
|
|
)
|
|
|
|
|
|
def test_build_swipe_actions_shape_and_duration_split():
|
|
actions = build_swipe_actions([(0, 0), (50, 10), (100, 0)], 600)
|
|
assert len(actions) == 1
|
|
pointer = actions[0]
|
|
assert pointer["type"] == "pointer"
|
|
assert pointer["id"] == "finger1"
|
|
assert pointer["parameters"]["pointerType"] == "touch"
|
|
seq = pointer["actions"]
|
|
types = [a["type"] for a in seq]
|
|
assert types == [
|
|
"pointerMove",
|
|
"pointerDown",
|
|
"pointerMove",
|
|
"pointerMove",
|
|
"pointerUp",
|
|
]
|
|
# 600ms over 2 segments => 300ms per move after pointerDown
|
|
moves_after_down = [a for a in seq if a["type"] == "pointerMove"][1:]
|
|
assert all(m["duration"] == 300 for m in moves_after_down)
|
|
assert seq[0]["x"] == 0 and seq[0]["y"] == 0
|
|
assert seq[-1]["x"] == 100 and seq[-1]["y"] == 0
|
|
|
|
|
|
def test_build_swipe_actions_requires_two_waypoints():
|
|
with pytest.raises(ValueError):
|
|
build_swipe_actions([(1, 1)], 100)
|
|
|
|
|
|
def test_build_double_tap_actions_shape():
|
|
actions = build_double_tap_actions(10, 20, interval_ms=80)
|
|
seq = actions[0]["actions"]
|
|
types = [a["type"] for a in seq]
|
|
assert types == [
|
|
"pointerMove",
|
|
"pointerDown",
|
|
"pointerUp",
|
|
"pause",
|
|
"pointerDown",
|
|
"pointerUp",
|
|
]
|
|
pause = next(a for a in seq if a["type"] == "pause")
|
|
assert pause["duration"] == 80
|
|
assert seq[0]["x"] == 10 and seq[0]["y"] == 20 |