-
Notifications
You must be signed in to change notification settings - Fork 294
/
Copy pathpointer-test.js
60 lines (52 loc) · 1.72 KB
/
pointer-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import assert from "assert";
import {pointer, pointers} from "../src/index.js";
import it from "./jsdom.js";
it("pointer(mousemove) returns an array of coordinates", "<div>", () => {
const target = document.querySelector("div");
assert.deepStrictEqual(pointer(mousemove(10, 20)), [10, 20]);
assert.deepStrictEqual(pointer(mousemove(10, 20, target), target), [10, 20]);
});
it("pointer(touch, target) returns an array of coordinates", "<div>", () => {
const target = document.querySelector("div");
assert.deepStrictEqual(pointer(touch(10, 20), target), [10, 20]);
});
it("pointers(mousemove) returns an array of arrays of coordinates", "<div>", () => {
const target = document.querySelector("div");
assert.deepStrictEqual(pointers(mousemove(10, 20)), [[10, 20]]);
assert.deepStrictEqual(pointers(mousemove(10, 20, target)), [[10, 20]]);
});
it("pointers(touchmove) returns an array of arrays of coordinates", "<div>", () => {
const target = document.querySelector("div");
assert.deepStrictEqual(pointers(touchmove(10, 20)), [[10, 20]]);
assert.deepStrictEqual(pointers(touchmove(10, 20, target)), [[10, 20]]);
});
it("pointers(touches) returns an array of arrays of coordinates", "<div>", () => {
assert.deepStrictEqual(pointers([touch(10, 20)]), [[10, 20]]);
});
function mousemove(x, y, target = document.body) {
return {
pageX: x,
pageY: y,
clientX: x,
clientY: y,
type: "mousemove",
target: target,
currentTarget: target
};
}
function touchmove(x, y, target = document.body) {
return {
type: "touchmove",
target: target,
currentTarget: target,
touches: [touch(x, y)]
};
}
function touch(x, y) {
return {
pageX: x,
pageY: y,
clientX: x,
clientY: y
};
}