forked from akiran/react-slick
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-utils.js
81 lines (70 loc) · 2.26 KB
/
test-utils.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import { render, fireEvent, waitFor, screen } from "@testing-library/react";
export function getSlidesCount(container) {
return container.getElementsByClassName("slick-slide").length;
}
export function getSlides(container) {
return container.getElementsByClassName("slick-slide");
}
export function getClonesCount(container) {
return container.getElementsByClassName("slick-cloned").length;
}
export function getActiveSlidesCount(container) {
return container.querySelectorAll(".slick-slide.slick-active").length;
}
export function getCurrentSlide(container) {
return container.querySelector(".slick-current");
}
export function getButtons(container) {
return container.querySelectorAll(".slick-dots button");
}
export function getButtonsListItem(container) {
return container.querySelectorAll(".slick-dots")[0].children;
}
export function getButtonsLength(container) {
return container.querySelectorAll(".slick-dots")[0].children.length;
}
export function hasClass(element, classname) {
if (element.className != undefined) {
return element.classList.contains(classname);
}
return false;
}
export function getActiveButton(container) {
return Array.from(
container.querySelectorAll(".slick-dots .slick-active button")
).map(e => e.textContent);
}
// export function getCurrentSlideIdState(container) {
// return parseInt(getCurrentSlide(container).getAttribute("data-index")) + 1;
// }
// export function activeSlides(container) {
// return container.querySelectorAll(".slick-slide.slick-active");
// }
export function getActiveSlide(container) {
return container.querySelector(".slick-slide.slick-active");
}
export function getActiveSlides(container) {
return container.querySelectorAll(".slick-slide.slick-active");
}
export function getActiveSlidesText(container) {
const slides = getActiveSlides(container);
return Array.from(slides).map(e => e.textContent);
}
export function clickNext(container) {
fireEvent(
container.getElementsByClassName("slick-next")[0],
new MouseEvent("click", {
bubbles: true,
cancelable: true
})
);
}
export function clickPrevious(container) {
fireEvent(
container.getElementsByClassName("slick-prev")[0],
new MouseEvent("click", {
bubbles: true,
cancelable: true
})
);
}