Skip to content

Commit 5b2e405

Browse files
committed
added tests for #1813
1 parent 15d93c5 commit 5b2e405

16 files changed

+199
-1
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

__tests__/regression/fix-1813.js

+196
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
//Test fix of #1813: In infinite mode, when slidesToShow equal to the length of slides, infinite functionality is not working.
2+
3+
import React from "react";
4+
import { render, fireEvent } from "@testing-library/react";
5+
import Slider from "../../src/index";
6+
7+
import {
8+
activeSlide,
9+
activeSlides,
10+
clickNext,
11+
clickPrevious,
12+
getActiveButton,
13+
getActiveSlidesCount,
14+
getActiveSlidesText,
15+
getButtons,
16+
getButtonsLength,
17+
getButtonsListItem,
18+
getClonesCount,
19+
getCurrentSlide,
20+
getSlidesCount,
21+
hasClass
22+
} from "../../test-utils";
23+
24+
function MultipleItems() {
25+
const settings = {
26+
dots: true,
27+
infinite: true,
28+
speed: 500,
29+
slidesToShow: 9,
30+
slidesToScroll: 3
31+
};
32+
return (
33+
<div>
34+
<h2> Multiple items </h2>
35+
<Slider {...settings}>
36+
<div>
37+
<h3>1</h3>
38+
</div>
39+
<div>
40+
<h3>2</h3>
41+
</div>
42+
<div>
43+
<h3>3</h3>
44+
</div>
45+
<div>
46+
<h3>4</h3>
47+
</div>
48+
<div>
49+
<h3>5</h3>
50+
</div>
51+
<div>
52+
<h3>6</h3>
53+
</div>
54+
<div>
55+
<h3>7</h3>
56+
</div>
57+
<div>
58+
<h3>8</h3>
59+
</div>
60+
<div>
61+
<h3>9</h3>
62+
</div>
63+
</Slider>
64+
</div>
65+
);
66+
}
67+
68+
describe("Multiple Items with slidesToShow = slides count in infinite mode", function() {
69+
it("should have 9 actual slides and (9(pre) + 9(post)) clone slides", function() {
70+
//Todo: Need to fix extra clones
71+
const { container } = render(<MultipleItems />);
72+
expect(getSlidesCount(container)).toEqual(27);
73+
expect(getClonesCount(container)).toEqual(18);
74+
});
75+
it("should have 9 active slides", function() {
76+
const { container } = render(<MultipleItems />);
77+
expect(getActiveSlidesCount(container)).toEqual(9);
78+
});
79+
it("should have 3 dots", function() {
80+
const { container } = render(<MultipleItems />);
81+
expect(getButtonsLength(container)).toEqual(3);
82+
});
83+
it("should show first 9 slides", function() {
84+
const { container } = render(<MultipleItems />);
85+
expect(getActiveButton(container)).toEqual(["1"]);
86+
expect(getActiveSlidesText(container)).toEqual([
87+
"1",
88+
"2",
89+
"3",
90+
"4",
91+
"5",
92+
"6",
93+
"7",
94+
"8",
95+
"9"
96+
]);
97+
});
98+
it("should show slides from 4 when next button is clicked", function() {
99+
const { container } = render(<MultipleItems />);
100+
clickNext(container);
101+
expect(getActiveButton(container)).toEqual(["2"]);
102+
expect(getActiveSlidesText(container)).toEqual([
103+
"4",
104+
"5",
105+
"6",
106+
"7",
107+
"8",
108+
"9",
109+
"1",
110+
"2",
111+
"3"
112+
]);
113+
});
114+
it("should show slides from 7 when previous button is clicked", function() {
115+
const { container } = render(<MultipleItems />);
116+
clickPrevious(container);
117+
expect(getActiveButton(container)).toEqual(["3"]);
118+
expect(getActiveSlidesText(container)).toEqual([
119+
"7",
120+
"8",
121+
"9",
122+
"1",
123+
"2",
124+
"3",
125+
"4",
126+
"5",
127+
"6"
128+
]);
129+
});
130+
it("should show slides first 9 slides when first dot is clicked", function() {
131+
const { container } = render(<MultipleItems />);
132+
fireEvent(
133+
getButtons(container)[0],
134+
new MouseEvent("click", {
135+
bubbles: true,
136+
cancelable: true
137+
})
138+
);
139+
expect(getActiveButton(container)).toEqual(["1"]);
140+
expect(getActiveSlidesText(container)).toEqual([
141+
"1",
142+
"2",
143+
"3",
144+
"4",
145+
"5",
146+
"6",
147+
"7",
148+
"8",
149+
"9"
150+
]);
151+
});
152+
it("should show slides from 4 when middle dot is clicked", function() {
153+
const { container } = render(<MultipleItems />);
154+
fireEvent(
155+
getButtons(container)[1],
156+
new MouseEvent("click", {
157+
bubbles: true,
158+
cancelable: true
159+
})
160+
);
161+
expect(getActiveButton(container)).toEqual(["2"]);
162+
expect(getActiveSlidesText(container)).toEqual([
163+
"4",
164+
"5",
165+
"6",
166+
"7",
167+
"8",
168+
"9",
169+
"1",
170+
"2",
171+
"3"
172+
]);
173+
});
174+
it("should show slides from 7 when last dot is clicked", function() {
175+
const { container } = render(<MultipleItems />);
176+
fireEvent(
177+
getButtons(container)[2],
178+
new MouseEvent("click", {
179+
bubbles: true,
180+
cancelable: true
181+
})
182+
);
183+
expect(getActiveButton(container)).toEqual(["3"]);
184+
expect(getActiveSlidesText(container)).toEqual([
185+
"7",
186+
"8",
187+
"9",
188+
"1",
189+
"2",
190+
"3",
191+
"4",
192+
"5",
193+
"6"
194+
]);
195+
});
196+
});
File renamed without changes.
File renamed without changes.

docs/single-demo.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import React from "react";
44
import ReactDOM from "react-dom";
55
import Slider from "../src/slider";
6+
import MultipleItems from "../examples/MultipleItems";
67
function SimpleSlider() {
78
const settings = {
89
dots: true,
@@ -41,7 +42,8 @@ function SimpleSlider() {
4142
function App() {
4243
return (
4344
<div className="content">
44-
<SimpleSlider />
45+
{/* <SimpleSlider /> */}
46+
<MultipleItems />
4547
</div>
4648
);
4749
}

0 commit comments

Comments
 (0)