hover.js
1.89 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.hover = hover;
exports.unhover = unhover;
var _dom = require("@testing-library/dom");
var _utils = require("./utils");
// includes `element`
function getParentElements(element) {
const parentElements = [element];
let currentElement = element;
while ((currentElement = currentElement.parentElement) != null) {
parentElements.push(currentElement);
}
return parentElements;
}
function hover(element, init) {
if ((0, _utils.isLabelWithInternallyDisabledControl)(element)) return;
const parentElements = getParentElements(element).reverse();
_dom.fireEvent.pointerOver(element, init);
for (const el of parentElements) {
_dom.fireEvent.pointerEnter(el, init);
}
if (!element.disabled) {
_dom.fireEvent.mouseOver(element, (0, _utils.getMouseEventOptions)('mouseover', init));
for (const el of parentElements) {
_dom.fireEvent.mouseEnter(el, (0, _utils.getMouseEventOptions)('mouseenter', init));
}
}
_dom.fireEvent.pointerMove(element, init);
if (!element.disabled) {
_dom.fireEvent.mouseMove(element, (0, _utils.getMouseEventOptions)('mousemove', init));
}
}
function unhover(element, init) {
if ((0, _utils.isLabelWithInternallyDisabledControl)(element)) return;
const parentElements = getParentElements(element);
_dom.fireEvent.pointerMove(element, init);
if (!element.disabled) {
_dom.fireEvent.mouseMove(element, (0, _utils.getMouseEventOptions)('mousemove', init));
}
_dom.fireEvent.pointerOut(element, init);
for (const el of parentElements) {
_dom.fireEvent.pointerLeave(el, init);
}
if (!element.disabled) {
_dom.fireEvent.mouseOut(element, (0, _utils.getMouseEventOptions)('mouseout', init));
for (const el of parentElements) {
_dom.fireEvent.mouseLeave(el, (0, _utils.getMouseEventOptions)('mouseleave', init));
}
}
}