[Improvement] Slider: add test cases (#1192)

This commit is contained in:
neverland
2018-05-30 14:57:14 +08:00
committed by GitHub
parent 4614260e1c
commit 92c108e245
10 changed files with 104 additions and 28 deletions

View File

@@ -1,5 +1,5 @@
// Trigger touch event
export function triggerTouch(wrapper, eventName, x = 0, y = 0) {
// Trigger pointer/touch event
export function trigger(wrapper, eventName, x = 0, y = 0) {
const el = wrapper.element ? wrapper.element : wrapper;
const touch = {
identifier: Date.now(),
@@ -19,16 +19,18 @@ export function triggerTouch(wrapper, eventName, x = 0, y = 0) {
event.touches = [touch];
event.targetTouches = [touch];
event.changedTouches = [touch];
event.clientX = x;
event.clientY = y;
el.dispatchEvent(event);
}
// simulate drag gesture
export function triggerDrag(el, x = 0, y = 0) {
triggerTouch(el, 'touchstart', 0, 0);
triggerTouch(el, 'touchmove', x / 4, y / 4);
triggerTouch(el, 'touchmove', x / 3, y / 3);
triggerTouch(el, 'touchmove', x / 2, y / 2);
triggerTouch(el, 'touchmove', x, y);
triggerTouch(el, 'touchend', x, y);
trigger(el, 'touchstart', 0, 0);
trigger(el, 'touchmove', x / 4, y / 4);
trigger(el, 'touchmove', x / 3, y / 3);
trigger(el, 'touchmove', x / 2, y / 2);
trigger(el, 'touchmove', x, y);
trigger(el, 'touchend', x, y);
}