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

fixed #1874: slick-current is always on first slide despite initialSl… #2330

Merged
merged 1 commit into from
Jan 25, 2024
Merged
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
7 changes: 1 addition & 6 deletions __tests__/regression/fix-1813.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,18 @@

import React from "react";
import { render, fireEvent } from "@testing-library/react";
import Slider from "../../src/index";

import {
activeSlide,
activeSlides,
clickNext,
clickPrevious,
getActiveButton,
getActiveSlidesCount,
getActiveSlidesText,
getButtons,
getButtonsLength,
getButtonsListItem,
getClonesCount,
getCurrentSlide,
getSlidesCount,
hasClass
getSlidesCount
} from "../../test-utils";
import { GenericSliderComponent } from "../TestComponents";

Expand Down
25 changes: 25 additions & 0 deletions __tests__/regression/fix-1874.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Test fix of#1874: "slick-current" is always on first slide despite initialSlide != 0

import React from "react";
import { render } from "@testing-library/react";

import { getCurrentSlideContent, clickNext } from "../../test-utils";
import { GenericSliderComponent } from "../TestComponents";

describe("currentSlide test with different initialSlide values", () => {
it("currentSlide is 0 when initialSlide is 0", function() {
const { container } = render(<GenericSliderComponent slidesCount={6} />);
expect(getCurrentSlideContent(container)).toEqual("1");
clickNext(container);
expect(getCurrentSlideContent(container)).toEqual("2");
});

it("currentSlide is 2 when initialSlide is 2", function() {
const { container } = render(
<GenericSliderComponent slidesCount={6} settings={{ initialSlide: 2 }} />
);
expect(getCurrentSlideContent(container)).toEqual("3");
clickNext(container);
expect(getCurrentSlideContent(container)).toEqual("4");
});
});
1 change: 1 addition & 0 deletions src/inner-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export class InnerSlider extends React.Component {
this.state = {
...initialState,
currentSlide: this.props.initialSlide,
targetSlide: this.props.initialSlide ? this.props.initialSlide : 0,
slideCount: React.Children.count(this.props.children)
};
this.callbackTimers = [];
Expand Down
5 changes: 5 additions & 0 deletions test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ export function getCurrentSlide(container) {
return container.querySelector(".slick-current");
}

export function getCurrentSlideContent(container) {
const slide = container.querySelector(".slick-current");
return slide.textContent;
}

export function getButtons(container) {
return container.querySelectorAll(".slick-dots button");
}
Expand Down