Skip to content
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
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ class Slider extends React.PureComponent {
this.goTo(nextSlideIndex, NEXT);
};

setCurrentSlideByIndex = (index) => {
this.setState({
currentSlideIndex: index
});
}

getSlideClass = (index) => {
const {
currentSlideIndex,
Expand Down
10 changes: 10 additions & 0 deletions src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,16 @@ test('animate previous classNames', () => {
expect(animatedSnapshot).not.toEqual(initialSnapshot);
});

test('setCurrentSlideByIndex changes current Slide', () => {
const slider = ReactTestRenderer.create(<Slider><div>First Slide</div><div>Second Slide</div><div>Third Slide</div><div>Fourth Slide</div></Slider>);
expect(slider.root.findByProps({className: "slide current"}).children).toEqual(['First Slide']);
slider.getInstance().setCurrentSlideByIndex(1);
expect(slider.root.findByProps({className: "slide current"}).children).toEqual(['Second Slide']);
expect(slider.root.findByProps({className: "slide previous"}).children).toEqual(['First Slide']);
expect(slider.root.findByProps({className: "slide next"}).children).toEqual(['Third Slide']);
expect(slider.root.findByProps({className: "slide hidden"}).children).toEqual(['Fourth Slide']);
});

test('does not allow navigation while animating', () => {
const slider = ReactTestRenderer.create(<Slider><div /><div /><div /></Slider>);
slider.getInstance().next();
Expand Down