Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

written the tests of all the examples #2247

Open
wants to merge 1 commit into
base: fix-2242
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 107 additions & 0 deletions examples/__tests__/AdaptiveHeight.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import React from "react";
import SimpleSlider from "../SimpleSlider";
import { render, fireEvent, waitFor, screen } from "@testing-library/react";
import { html as beautify_html } from "js-beautify";
import {
getActiveSlide,
clickNext,
clickPrevious,
hasClass,
getActiveSlides,
getActiveSlidesCount,
getActiveSlidesText,
getButtons,
getButtonsListItem,
getCurrentSlide
} from "../../test-utils";

describe("Adaptive Height example", () => {
it("should have 8 slides (1(preclone) + 6(actual) + 1(postclone))", function() {
const { container } = render(<SimpleSlider a={5} />);
expect(container.getElementsByClassName("slick-slide").length).toBe(8);
});
it("should have 3 clone slides", function() {
const { container } = render(<SimpleSlider />);
expect(container.getElementsByClassName("slick-cloned").length).toBe(2);
});
it("should have 1 current slide", function() {
const { container } = render(<SimpleSlider />);
expect(
container.querySelectorAll(".slick-slide.slick-current").length
).toBe(1);
expect(parseInt(getCurrentSlide(container).textContent) - 1).toBe(0);
});
it("should have 1 active slide", function() {
const { container } = render(<SimpleSlider />);
expect(container.querySelectorAll(".slick-slide.slick-active").length).toBe(
1
);
expect(
Array.from(getActiveSlide(container).children).map(
e => parseInt(e.textContent) - 1
)[0]
).toBe(0);
});
it("should have 6 dots", function() {
const { container } = render(<SimpleSlider />);
expect(
container.getElementsByClassName("slick-dots")[0].children.length
).toBe(6);
});
it("should have 1 active dot", function() {
const { container } = render(<SimpleSlider />);

expect(container.querySelectorAll(".slick-dots .slick-active").length).toBe(
1
);
});
it("should have a prev arrow", function() {
const { container } = render(<SimpleSlider />);
expect(container.getElementsByClassName("slick-prev").length).toBe(1);
});
it("should have a next arrow", function() {
const { container } = render(<SimpleSlider />);
expect(container.getElementsByClassName("slick-next").length).toBe(1);
});
it("should got to next slide when next button is clicked", function() {
const { container } = render(<SimpleSlider />);
clickNext(container);
expect(
container.querySelectorAll(".slick-slide.slick-active")[0].textContent
).toBe("2");
expect(container.querySelectorAll(".slick-dots .slick-active").length).toBe(
1
);
expect(
container.querySelectorAll(".slick-dots")[0].children[1]
).toHaveClass("slick-active");
});
it("should goto previous slide when prev button is clicked", function() {
const { container } = render(<SimpleSlider />);
clickPrevious(container);
expect(
container.querySelectorAll(".slick-slide.slick-active")[0].textContent
).toBe("6");
expect(container.querySelectorAll(".slick-dots .slick-active").length).toBe(
1
);
expect(
container.querySelectorAll(".slick-dots")[0].children[5]
).toHaveClass("slick-active");
});
it("should goto 4th slide when 4th dot is clicked", function() {
const { container } = render(<SimpleSlider />);
fireEvent(
container.querySelectorAll(".slick-dots button")[3],
new MouseEvent("click", {
bubbles: true,
cancelable: true
})
);
expect(getActiveSlidesText(container)[0]).toEqual("4");
expect(getActiveSlidesCount(container)).toEqual(1);
expect(hasClass(getButtonsListItem(container)[3], "slick-active")).toEqual(
true
);
});
});
125 changes: 125 additions & 0 deletions examples/__tests__/AppendDots.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
import React from "react";
import AppendDots from "../AppendDots";
import { render, fireEvent, waitFor, screen } from "@testing-library/react";
import { html as beautify_html } from "js-beautify";
import {
getActiveSlide,
clickNext,
clickPrevious,
hasClass,
getActiveSlides,
getActiveSlidesCount,
getActiveSlidesText,
getButtons,
getButtonsListItem,
getCurrentSlide,
getSlideHeight
} from "../../test-utils";

describe("Append Dots example", () => {
it("should have 8 slides (1(preclone) + 6(actual) + 1(postclone))", function() {
const { container } = render(<AppendDots a={5} />);
expect(container.getElementsByClassName("slick-slide").length).toBe(8);
});
it("should have 3 clone slides", function() {
const { container } = render(<AppendDots />);
expect(container.getElementsByClassName("slick-cloned").length).toBe(2);
});
it("should have 1 current slide", function() {
const { container } = render(<AppendDots />);
expect(
container.querySelectorAll(".slick-slide.slick-current").length
).toBe(1);
expect(parseInt(getCurrentSlide(container).textContent) - 1).toBe(0);
});
it("should have 1 active slide", function() {
const { container } = render(<AppendDots />);
expect(container.querySelectorAll(".slick-slide.slick-active").length).toBe(
1
);
expect(
Array.from(getActiveSlide(container).children).map(
e => parseInt(e.textContent) - 1
)[0]
).toBe(0);
});
it("should have 6 dots", function() {
const { container } = render(<AppendDots />);
console.log(
Array.from(container.getElementsByClassName("slick-dots"))[0].children[0]
.children.length
);
expect(
container.getElementsByClassName("slick-dots")[0].children[0].children
.length
).toBe(6);
});
it("should have 1 active dot", function() {
const { container } = render(<AppendDots />);

expect(container.querySelectorAll(".slick-dots .slick-active").length).toBe(
1
);
});
it("should have a prev arrow", function() {
const { container } = render(<AppendDots />);
expect(container.getElementsByClassName("slick-prev").length).toBe(1);
});
it("should have a next arrow", function() {
const { container } = render(<AppendDots />);
expect(container.getElementsByClassName("slick-next").length).toBe(1);
});
it("should got to next slide when next button is clicked", function() {
const { container } = render(<AppendDots />);
clickNext(container);
expect(
container.querySelectorAll(".slick-slide.slick-active")[0].textContent
).toBe("2");
expect(container.querySelectorAll(".slick-dots .slick-active").length).toBe(
1
);
expect(
container.getElementsByClassName("slick-dots")[0].children[0].children[1]
).toHaveClass("slick-active");
});
it("should goto previous slide when prev button is clicked", function() {
const { container } = render(<AppendDots />);
clickPrevious(container);
expect(
container.querySelectorAll(".slick-slide.slick-active")[0].textContent
).toBe("6");
expect(container.querySelectorAll(".slick-dots .slick-active").length).toBe(
1
);
expect(
container.getElementsByClassName("slick-dots")[0].children[0].children[5]
).toHaveClass("slick-active");
});
it("should goto 4th slide when 4th dot is clicked", function() {
const { container } = render(<AppendDots />);
fireEvent(
container.querySelectorAll(".slick-dots div")[3],
new MouseEvent("click", {
bubbles: true,
cancelable: true
})
);
expect(getActiveSlidesText(container)[0]).toEqual("4");
expect(getActiveSlidesCount(container)).toEqual(1);
expect(
hasClass(
container.getElementsByClassName("slick-dots")[0].children[0]
.children[3],
"slick-active"
)
).toEqual(true);
});
it("check the content of dots", function() {
const { container } = render(<AppendDots />);
const array = [];
Array.from(
container.getElementsByClassName("slick-dots")[0].children[0].children
).forEach(i => array.push(i.textContent));
expect(array).toEqual(["1", "2", "3", "4", "5", "6"]);
});
});
104 changes: 104 additions & 0 deletions examples/__tests__/AsNavFor.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import React from "react";
import AsNavFor from "../AsNavFor";
import { render, fireEvent, waitFor, screen } from "@testing-library/react";
import { html as beautify_html } from "js-beautify";
import {
getActiveSlide,
clickNext,
clickPrevious,
hasClass,
getActiveSlides,
getActiveSlidesCount,
getActiveSlidesText,
getButtons,
getButtonsListItem,
getCurrentSlide,
getSlideHeight
} from "../../test-utils";

describe("As Nav For example", () => {
it("Number of slides should be 2", function() {
const { container } = render(<AsNavFor />);
expect(container.getElementsByClassName("slick-slider").length).toBe(2);
});
it("First Slide should have 8 slides (1(preclone) + 6(actual) + 1(postclone))", function() {
const { container } = render(<AsNavFor a={5} />);
expect(
container
.getElementsByClassName("slick-slider")[0]
.getElementsByClassName("slick-slide").length
).toBe(8);
});
it("Second Slide should have 8 slides (1(preclone) + 6(actual) + 1(postclone))", function() {
const { container } = render(<AsNavFor a={5} />);
expect(
container
.getElementsByClassName("slick-slider")[1]
.getElementsByClassName("slick-slide").length
).toBe(12);
});
it("Clicking on next of first slide should change second slide too", function() {
const { container } = render(<AsNavFor />);
expect(
getActiveSlidesText(container.getElementsByClassName("slick-slider")[0])
).toEqual(["1"]);
expect(
getActiveSlidesText(container.getElementsByClassName("slick-slider")[1])
).toEqual(["1", "2", "3"]);
clickNext(container.getElementsByClassName("slick-slider")[0]);
expect(
getActiveSlidesText(container.getElementsByClassName("slick-slider")[0])
).toEqual(["2"]);
expect(
getActiveSlidesText(container.getElementsByClassName("slick-slider")[1])
).toEqual(["2", "3", "4"]);
});
it("Clicking on next of second slide should change first slide too", function() {
const { container } = render(<AsNavFor />);
expect(
getActiveSlidesText(container.getElementsByClassName("slick-slider")[0])
).toEqual(["1"]);
expect(
getActiveSlidesText(container.getElementsByClassName("slick-slider")[1])
).toEqual(["1", "2", "3"]);
clickNext(container.getElementsByClassName("slick-slider")[1]);
expect(
getActiveSlidesText(container.getElementsByClassName("slick-slider")[0])
).toEqual(["2"]);
expect(
getActiveSlidesText(container.getElementsByClassName("slick-slider")[1])
).toEqual(["2", "3", "4"]);
});
it("Clicking on previous button of first slide should change second slide too", function() {
const { container } = render(<AsNavFor />);
expect(
getActiveSlidesText(container.getElementsByClassName("slick-slider")[0])
).toEqual(["1"]);
expect(
getActiveSlidesText(container.getElementsByClassName("slick-slider")[1])
).toEqual(["1", "2", "3"]);
clickPrevious(container.getElementsByClassName("slick-slider")[0]);
expect(
getActiveSlidesText(container.getElementsByClassName("slick-slider")[0])
).toEqual(["6"]);
expect(
getActiveSlidesText(container.getElementsByClassName("slick-slider")[1])
).toEqual(["6", "1", "2"]);
});
it("Clicking on previous button of second slide should change first slide too", function() {
const { container } = render(<AsNavFor />);
expect(
getActiveSlidesText(container.getElementsByClassName("slick-slider")[0])
).toEqual(["1"]);
expect(
getActiveSlidesText(container.getElementsByClassName("slick-slider")[1])
).toEqual(["1", "2", "3"]);
clickPrevious(container.getElementsByClassName("slick-slider")[1]);
expect(
getActiveSlidesText(container.getElementsByClassName("slick-slider")[0])
).toEqual(["6"]);
expect(
getActiveSlidesText(container.getElementsByClassName("slick-slider")[1])
).toEqual(["6", "1", "2"]);
});
});
Loading