-
Notifications
You must be signed in to change notification settings - Fork 2.6k
/
helper.ts
86 lines (69 loc) · 1.51 KB
/
helper.ts
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
74
75
76
77
78
79
80
81
82
83
84
85
86
export function find(selector: string | HTMLElement): HTMLElement {
if (typeof selector === "string") {
return document.querySelector(selector) as HTMLElement;
}
if (selector instanceof Element) {
return selector;
}
throw Error("invalid selector");
}
export function content(selector: string | HTMLElement): string | null {
const el = find(selector);
if (el) {
return el.innerHTML;
}
return null;
}
export function className(selector: string | HTMLElement): string | null {
const el = find(selector);
if (el) {
return el.className;
}
return null;
}
export function skipButton() {
return find(".introjs-skipbutton");
}
export function nextButton() {
return find(".introjs-nextbutton");
}
export function prevButton() {
return find(".introjs-prevbutton");
}
export function doneButton() {
return find(".introjs-donebutton");
}
export function tooltipText() {
return find(".introjs-tooltiptext");
}
export function appendDummyElement(
name?: string,
text?: string,
style?: string
): HTMLElement {
const el = document.createElement(name || "p");
el.innerHTML = text || "hello world";
el.setAttribute("style", style || "");
document.body.appendChild(el);
return el;
}
export function getBoundingClientRectSpy(
width: number,
height: number,
top: number,
left: number,
bottom: number,
right: number
) {
return jest.fn(
() =>
({
top,
left,
bottom,
right,
width,
height,
} as DOMRect)
);
}