forked from akiran/react-slick
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
migrated all the test of examples from enezyme to react-testing-library
- Loading branch information
1 parent
0711da9
commit c4f6fde
Showing
13 changed files
with
435 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import React from "react"; | ||
import { render } from "@testing-library/react"; | ||
import Fade from "../Fade"; | ||
import { activeSlide, clickNext, clickPrevious } from "../../test-utils"; | ||
|
||
describe("Fade", () => { | ||
it("should change slides when clicked on next & prev buttons", () => { | ||
const { container } = render(<Fade />); | ||
let activeslide = activeSlide(container); | ||
expect(parseInt(activeslide.getAttribute("data-index"))).toEqual(0); | ||
clickNext(container); | ||
activeslide = activeSlide(container); | ||
expect(parseInt(activeslide.getAttribute("data-index"))).toEqual(1); | ||
clickPrevious(container); | ||
activeslide = activeSlide(container); | ||
expect(parseInt(activeslide.getAttribute("data-index"))).toEqual(0); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import React from "react"; | ||
import { render, fireEvent } from "@testing-library/react"; | ||
import { html as beautify_html } from "js-beautify"; | ||
import { | ||
activeSlide, | ||
clickNext, | ||
clickPrevious, | ||
getButtons, | ||
getCurrentSlide | ||
} from "../../test-utils"; | ||
import FocusOnSelect from "../FocusOnSelect"; | ||
|
||
describe("FocusOnSelect Tests", () => { | ||
test("Activity Test", () => { | ||
const { container } = render(<FocusOnSelect />); | ||
expect( | ||
parseInt(getCurrentSlide(container).getAttribute("data-index")) | ||
).toEqual(0); | ||
expect(beautify_html(toString(container))).toMatchSnapshot(); | ||
Array.from(container.getElementsByClassName("slick-slide")).map(e => | ||
e.getAttribute("data-index") == "2" | ||
? fireEvent( | ||
e, | ||
new MouseEvent("click", { bubbles: true, cancelable: true }) | ||
) | ||
: null | ||
); | ||
expect( | ||
parseInt(getCurrentSlide(container).getAttribute("data-index")) | ||
).toEqual(2); | ||
expect(beautify_html(toString(container))).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import React from "react"; | ||
import { render, fireEvent } from "@testing-library/react"; | ||
import { html as beautify_html } from "js-beautify"; | ||
import { | ||
activeSlide, | ||
activeSlides, | ||
clickNext, | ||
clickPrevious, | ||
getActiveSlidesCount, | ||
getActiveSlidesText, | ||
getButtons, | ||
getButtonsLength, | ||
getClonesCount, | ||
getCurrentSlide, | ||
getSlidesCount | ||
} from "../../test-utils"; | ||
import MultipleItems from "../MultipleItems"; | ||
|
||
describe("Multiple Items", function() { | ||
it("should have 9 actual slides and (3(pre) + 9(post)) clone slides", function() { | ||
const { container } = render(<MultipleItems />); | ||
expect(getSlidesCount(container)).toEqual(21); | ||
expect(getClonesCount(container)).toEqual(12); | ||
expect(beautify_html(toString(container))).toMatchSnapshot(); | ||
}); | ||
it("should have 3 active slides", function() { | ||
const { container } = render(<MultipleItems />); | ||
expect(getActiveSlidesCount(container)).toEqual(3); | ||
expect(beautify_html(toString(container))).toMatchSnapshot(); | ||
}); | ||
it("should have 3 dots", function() { | ||
const { container } = render(<MultipleItems />); | ||
expect(getButtonsLength(container)).toEqual(3); | ||
expect(beautify_html(toString(container))).toMatchSnapshot(); | ||
}); | ||
it("should show first 3 slides", function() { | ||
const { container } = render(<MultipleItems />); | ||
expect(getActiveSlidesText(container)).toEqual(["1", "2", "3"]); | ||
expect(beautify_html(toString(container))).toMatchSnapshot(); | ||
}); | ||
it("should show slides from 4 to 6 when next button is clicked", function() { | ||
const { container } = render(<MultipleItems />); | ||
clickNext(container); | ||
expect(getActiveSlidesText(container)).toEqual(["4", "5", "6"]); | ||
expect(beautify_html(toString(container))).toMatchSnapshot(); | ||
}); | ||
it("should show last 3 slides when previous button is clicked", function() { | ||
const { container } = render(<MultipleItems />); | ||
clickPrevious(container); | ||
expect(getActiveSlidesText(container)).toEqual(["7", "8", "9"]); | ||
expect(beautify_html(toString(container))).toMatchSnapshot(); | ||
}); | ||
it("should show slides first 3 slides when first dot is clicked", function() { | ||
const { container } = render(<MultipleItems />); | ||
fireEvent( | ||
getButtons(container)[0], | ||
new MouseEvent("click", { | ||
bubbles: true, | ||
cancelable: true | ||
}) | ||
); | ||
expect(getActiveSlidesText(container)).toEqual(["1", "2", "3"]); | ||
expect(beautify_html(toString(container))).toMatchSnapshot(); | ||
}); | ||
it("should show slides from 4 to 6 when middle dot is clicked", function() { | ||
const { container } = render(<MultipleItems />); | ||
fireEvent( | ||
getButtons(container)[1], | ||
new MouseEvent("click", { | ||
bubbles: true, | ||
cancelable: true | ||
}) | ||
); | ||
expect(getActiveSlidesText(container)).toEqual(["4", "5", "6"]); | ||
expect(beautify_html(toString(container))).toMatchSnapshot(); | ||
}); | ||
it("should show last 3 slides when last dot is clicked", function() { | ||
const { container } = render(<MultipleItems />); | ||
fireEvent( | ||
getButtons(container)[2], | ||
new MouseEvent("click", { | ||
bubbles: true, | ||
cancelable: true | ||
}) | ||
); | ||
expect(getActiveSlidesText(container)).toEqual(["7", "8", "9"]); | ||
expect(beautify_html(toString(container))).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React from "react"; | ||
import { fireEvent, getRoles, render } from "@testing-library/react"; | ||
import SlickGoTo from "../SlickGoTo"; | ||
import { activeSlide, getActiveSlides, getSlidesCount } from "../../test-utils"; | ||
|
||
describe.skip("SlickGoTo", () => { | ||
it("should goto 2nd slide", () => { | ||
const { container } = render(<SlickGoTo />); | ||
fireEvent.change(container.getElementsByTagName("input")[0], { | ||
target: { value: 1 } | ||
}); | ||
let currentImg = Array.from( | ||
activeSlide(container).getElementsByTagName("img") | ||
)[0]; | ||
expect(currentImg.getAttribute("src")).toEqual( | ||
"/img/react-slick/abstract02.jpg" | ||
); | ||
}); | ||
it("should goto 2nd slide, even if input is number in string format", () => { | ||
const { container } = render(<SlickGoTo />); | ||
fireEvent.change(container.getElementsByTagName("input")[0], { | ||
target: { value: "1" } | ||
}); | ||
let currentImg = Array.from( | ||
activeSlide(container).getElementsByTagName("img") | ||
)[0]; | ||
expect(currentImg.getAttribute("src")).toEqual( | ||
"/img/react-slick/abstract02.jpg" | ||
); | ||
}); | ||
it("should remain at 1st slide", () => { | ||
const { container } = render(<SlickGoTo />); | ||
fireEvent.change(container.getElementsByTagName("input")[0], { | ||
target: { value: 0 } | ||
}); | ||
let currentImg = Array.from( | ||
activeSlide(container).getElementsByTagName("img") | ||
)[0]; | ||
expect(currentImg.getAttribute("src")).toEqual( | ||
"/img/react-slick/abstract01.jpg" | ||
); | ||
}); | ||
it.skip("should go to 1st slide from another 3rd slide", () => { | ||
// skipped because two simultaneous clicks dont' work with css and speed>0 | ||
const wrapper = render(<SlickGoTo waitForAnimate={false} />); | ||
wrapper.find("input").simulate("change", { target: { value: 3 } }); | ||
wrapper.find("input").simulate("change", { target: { value: 0 } }); | ||
expect(wrapper.find(".slick-slide.slick-active img").props().src).toEqual( | ||
"/img/react-slick/abstract01.jpg" | ||
); | ||
}); | ||
}); |
Oops, something went wrong.