-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2331 from akiran/fix-2315
Fixed #2315
- Loading branch information
Showing
7 changed files
with
84 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
trailingComma: none |
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,35 @@ | ||
// Test fix of #2315: Slider crashing after a state change in parent component | ||
import React from "react"; | ||
import { render, fireEvent } from "@testing-library/react"; | ||
|
||
import { getCurrentSlideContent, getSlidesCount } from "../../test-utils"; | ||
import { GenericSliderComponent } from "../TestComponents"; | ||
|
||
function TestSlider() { | ||
const [count, setCount] = React.useState(); | ||
|
||
return ( | ||
<div> | ||
<button className="increment-button" onClick={() => setCount(count + 1)}> | ||
Increment {count} | ||
</button> | ||
<GenericSliderComponent slidesCount={6} settings={{ count }} /> | ||
</div> | ||
); | ||
} | ||
|
||
describe("State change in parent component of slider", () => { | ||
it("Slider shoud work afer clicking on Increment button", function() { | ||
const { container } = render(<TestSlider />); | ||
fireEvent( | ||
container.getElementsByClassName("increment-button")[0], | ||
new MouseEvent("click", { | ||
bubbles: true, | ||
cancelable: true | ||
}) | ||
); | ||
// Throws an error "Maximum update depth exceeded." if the bug exists | ||
expect(getCurrentSlideContent(container)).toEqual("1"); | ||
expect(getSlidesCount(container)).toEqual(13); | ||
}); | ||
}); |
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 { filterSettings } from "../../src/utils/innerSliderUtils"; | ||
|
||
describe("filterSettings", () => { | ||
it("returns empty object if there are no valid settings", () => { | ||
expect(filterSettings({})).toEqual({}); | ||
expect(filterSettings({ age: 10 })).toEqual({}); | ||
}); | ||
it("return an object with valid settings and omits extra properties", () => { | ||
expect(filterSettings({ arrows: true, dots: true })).toEqual({ | ||
arrows: true, | ||
dots: true | ||
}); | ||
expect(filterSettings({ arrows: true, dots: true, age: 10 })).toEqual({ | ||
arrows: true, | ||
dots: true | ||
}); | ||
}); | ||
}); |
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
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