Skip to content

Commit

Permalink
Merge pull request #110 from ant-design/upstream
Browse files Browse the repository at this point in the history
chore: sync upsteam Akiran master
  • Loading branch information
afc163 committed Mar 26, 2024
2 parents 98cee24 + de91e69 commit 0f2eaff
Show file tree
Hide file tree
Showing 84 changed files with 2,447 additions and 5,473 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ jobs:
with:
node-version: '20.x'
- run: npm install
- run: npm run lint
- run: npm run build
- run: npm test
1 change: 1 addition & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
trailingComma: none
5 changes: 2 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
First, thank you for considering contributing to react-slick! It's people like you that make the open source community such a great community! 😊

We welcome any type of contribution, not only code. You can help with

- **QA**: file bug reports, the more details you can give the better (e.g. screenshots with the console open)
- **Marketing**: writing blog posts, howto's, printing stickers, ...
- **Community**: presenting the project at meetups, organizing a dedicated meetup for the local community, ...
Expand All @@ -13,7 +14,7 @@ We welcome any type of contribution, not only code. You can help with

## Your First Contribution

Working on your first Pull Request? You can learn how from this *free* series, [How to Contribute to an Open Source Project on GitHub](https://egghead.io/series/how-to-contribute-to-an-open-source-project-on-github).
Working on your first Pull Request? You can learn how from this _free_ series, [How to Contribute to an Open Source Project on GitHub](https://app.egghead.io/playlists/how-to-contribute-to-an-open-source-project-on-github).

## Submitting code

Expand Down Expand Up @@ -41,14 +42,12 @@ You can also reach us at hello@react-slick.opencollective.com.
Thank you to all the people who have already contributed to react-slick!
<a href="https://github.com/akiran/react-slick/graphs/contributors"><img src="https://opencollective.com/react-slick/contributors.svg?width=890" /></a>


### Backers

Thank you to all our backers! [[Become a backer](https://opencollective.com/react-slick#backer)]

<a href="https://opencollective.com/react-slick#backers" target="_blank"><img src="https://opencollective.com/react-slick/backers.svg?width=890"></a>


### Sponsors

Thank you to all our sponsors! (please ask your company to also support this open source project by [becoming a sponsor](https://opencollective.com/react-slick#sponsor))
Expand Down
17 changes: 8 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### react-slick
### @ant-design/react-slick

[![Backers on Open Collective](https://opencollective.com/react-slick/backers/badge.svg)](#backers) [![Sponsors on Open Collective](https://opencollective.com/react-slick/sponsors/badge.svg)](#sponsors)

Expand All @@ -11,13 +11,13 @@
**npm**

```bash
npm install react-slick --save
npm install @ant-design/react-slick --save
```

**yarn**

```bash
yarn add react-slick
yarn add @ant-design/react-slick
```

**Also install slick-carousel for css and font**
Expand All @@ -37,22 +37,22 @@ or add cdn link in your html
rel="stylesheet"
type="text/css"
charset="UTF-8"
href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.6.0/slick.min.css"
href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick.min.css"
/>
<link
rel="stylesheet"
type="text/css"
href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.6.0/slick-theme.min.css"
href="https://cdnjs.cloudflare.com/ajax/libs/slick-carousel/1.8.1/slick-theme.min.css"
/>
```

### [PlayGround](https://codesandbox.io/s/ppwkk5l6xx)
### [PlayGround](https://stackblitz.com/edit/vitejs-vite-ownrun?file=src%2FImageSlider.jsx)

### Example

```js
import React from "react";
import Slider from "react-slick";
import Slider from "@ant-design/react-slick";

export default function SimpleSlider() {
var settings = {
Expand Down Expand Up @@ -100,7 +100,7 @@ For all available methods, go [here](https://react-slick.neostack.com/docs/api#m
Want to run demos locally

```bash
git clone https://github.com/akiran/react-slick
git clone https://github.com/ant-design/react-slick
cd react-slick
npm install
npm start
Expand All @@ -111,7 +111,6 @@ open http://localhost:8080

Join our [discord channel](https://discord.gg/z7stRE4Cyb) to discuss react-slick bugs and ask for help


## Contributing

Please see the [contributing guidelines](./CONTRIBUTING.md)
5 changes: 2 additions & 3 deletions __tests__/SimpleSlider.test.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// includes tests of
// SimpleSlider, MultipleItems
import { mount } from "enzyme";
import { testSlider } from "./testUtils";

describe("SimpleSlider with combinations of possibilities", function() {
describe("SimpleSlider with combinations of possibilities", function () {
// try around several possibilities
let _noOfSlides = [2, 5, 12];
let _slidesToShow = [2, 5, 10];
Expand Down Expand Up @@ -38,7 +37,7 @@ describe("SimpleSlider with combinations of possibilities", function() {
slidesToScroll,
useCSS: false
};
test(`Test with settings => noOfSlides: ${noOfSlides}, slidesToShow: ${slidesToShow}, slidesToScroll: ${slidesToScroll}`, function() {
test(`Test with settings => noOfSlides: ${noOfSlides}, slidesToShow: ${slidesToShow}, slidesToScroll: ${slidesToScroll}`, function () {
testSlider(settings1);
});
}
Expand Down
13 changes: 13 additions & 0 deletions __tests__/TestComponents.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from "react";
import Slider from "../src/index";

export function GenericSliderComponent({ slidesCount, settings }) {
const slides = [...Array(slidesCount).keys()].map((item) => (
<div key={item}>{item + 1}</div>
));
return <Slider {...settings}>{slides}</Slider>;
}

test("fake test", () => {
expect(1).toBe(1);
});
53 changes: 20 additions & 33 deletions __tests__/afterChange.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import React from "react";
import { mount } from "enzyme";
import { render, fireEvent } from "@testing-library/react";
import Slider from "../src/index";
import {
getActiveSlide,
clickNext,
clickPrevious,
getCurrentSlide
} from "../test-utils";

class SliderWithBeforeChange extends React.Component {
class SliderWithAfterChange extends React.Component {
constructor(props) {
super(props);
this.state = {
Expand All @@ -29,39 +35,20 @@ class SliderWithBeforeChange extends React.Component {
}
}

describe("After change Slider", function() {
it("should render", function() {
const wrapper = mount(<SliderWithBeforeChange />);
expect(wrapper.state()).toEqual({ currentSlide: null });
wrapper.find(".slick-next").simulate("click");
describe("After change Slider", function () {
it("should render", function () {
const { container } = render(<SliderWithAfterChange />);
clickNext(container);
setTimeout(() => {
expect(
wrapper
.find(".slick-slide.slick-active")
.first()
.text()
).toEqual("slide2");
expect(wrapper.state()).toEqual({ currentSlide: 1 });
}, 1);
wrapper.find(".slick-next").simulate("click");
expect(getActiveSlide(container).textContent).toEqual("slide2");
}, 1000);
clickNext(container);
setTimeout(() => {
expect(
wrapper
.find(".slick-slide.slick-active")
.first()
.text()
).toEqual("slide3");
expect(wrapper.state()).toEqual({ currentSlide: 2 });
}, 1);
wrapper.find(".slick-prev").simulate("click");
expect(getActiveSlide(container).textContent).toEqual("slide3");
}, 1000);
clickPrevious(container);
setTimeout(() => {
expect(
wrapper
.find(".slick-slide.slick-active")
.first()
.text()
).toEqual("slide2");
expect(wrapper.state()).toEqual({ currentSlide: 1 });
}, 1);
expect(getActiveSlide(container).textContent).toEqual("slide2");
}, 1000);
});
});
68 changes: 36 additions & 32 deletions __tests__/arrows.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

sinon.stub(console, "error");

import { render, shallow } from "enzyme";
import { render } from "@testing-library/react";
import React from "react";
import sinon from "sinon";

Expand All @@ -22,48 +22,52 @@ function CustomArrow(props) {

describe("Previous arrows", () => {
it("should render arrow", () => {
const wrapper = shallow(<PrevArrow />);
expect(wrapper.find("button")).toHaveLength(1);
const { container } = render(<PrevArrow />);
expect(Array.from(container.getElementsByTagName("button"))).toHaveLength(
1
);
});

it("should not result in errors", () => {
shallow(<PrevArrow />);
render(<PrevArrow />);

expect(console.error.called).toBe(false);
});

// it('should pass slide data to custom arrow', () => {
// let elAttributes;
// let arr = <CustomArrow />
//
// const wrapper = render(<PrevArrow currentSlide={3} prevArrow={arr} slideCount={5} />);
//
// elAttributes = wrapper.find('.sample')[0].attribs;
// expect(elAttributes['data-currentslide']).toBe('3');
// expect(elAttributes['data-slidecount']).toBe('5');
// });
// it('should pass slide data to custom arrow', () => {
// let elAttributes;
// let arr = <CustomArrow />

// const {container}= render(<PrevArrow currentSlide={3} prevArrow={arr} slideCount={5} />);

// elAttributes =x=> container.querySelectorAll('.sample')[0].getAttribute(x);
// expect(elAttributes('data-currentslide')).toBe('3');
// expect(elAttributes('data-slidecount')).toBe('5');
// });
});

describe("Next arrows", () => {
it("should render arrow", () => {
const wrapper = shallow(<NextArrow />);
expect(wrapper.find("button")).toHaveLength(1);
const { container } = render(<NextArrow />);
expect(Array.from(container.getElementsByTagName("button"))).toHaveLength(
1
);
});

// it('should not result in errors', () => {
// shallow(<NextArrow />);
//
// expect(console.error.called).toBe(false);
// });

// it('should pass slide data to custom arrow', () => {
// let elAttributes;
// let arr = <CustomArrow />
//
// const wrapper = render(<NextArrow currentSlide={6} nextArrow={arr} slideCount={9} />);
//
// elAttributes = wrapper.find('.sample')[0].attribs;
// expect(elAttributes['data-currentslide']).toBe('6');
// expect(elAttributes['data-slidecount']).toBe('9');
// });
// it('should not result in errors', () => {
// render(<NextArrow />);

// expect(console.error.called).toBe(false);
// });

// it('should pass slide data to custom arrow', () => {
// let elAttributes;
// let arr = <CustomArrow />

// const {container} = render(<NextArrow currentSlide={6} nextArrow={arr} slideCount={9} />);

// elAttributes =(x)=> container.querySelectorAll('.sample')[0].getAttribute(x);
// expect(elAttributes('data-currentslide')).toBe('6');
// expect(elAttributes('data-slidecount')).toBe('9');
// });
});
44 changes: 16 additions & 28 deletions __tests__/beforeChange.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import React from "react";
import { mount } from "enzyme";
import { render } from "@testing-library/react";
import Slider from "../src/index";
import {
getActiveSlide,
clickNext,
clickPrevious,
getCurrentSlide
} from "../test-utils";

class SliderWithBeforeChange extends React.Component {
constructor(props) {
Expand Down Expand Up @@ -29,32 +35,14 @@ class SliderWithBeforeChange extends React.Component {
}
}

describe.skip("Slider", function() {
it("should render", function() {
const wrapper = mount(<SliderWithBeforeChange />);
wrapper.find(".slick-next").simulate("click");
expect(
wrapper
.find(".slick-slide.slick-active")
.first()
.text()
).toEqual("slide2");
expect(wrapper.state()).toEqual({ currentSlide: 0, nextSlide: 1 });
wrapper.find(".slick-next").simulate("click");
expect(
wrapper
.find(".slick-slide.slick-active")
.first()
.text()
).toEqual("slide3");
expect(wrapper.state()).toEqual({ currentSlide: 1, nextSlide: 2 });
wrapper.find(".slick-prev").simulate("click");
expect(
wrapper
.find(".slick-slide.slick-active")
.first()
.text()
).toEqual("slide2");
expect(wrapper.state()).toEqual({ currentSlide: 2, nextSlide: 1 });
describe("Slider", function () {
it("should render", function () {
const { container } = render(<SliderWithBeforeChange />);
clickNext(container);
expect(getActiveSlide(container).textContent).toEqual("slide2");
clickNext(container);
expect(getActiveSlide(container).textContent).toEqual("slide3");
clickPrevious(container);
expect(getActiveSlide(container).textContent).toEqual("slide2");
});
});
22 changes: 0 additions & 22 deletions __tests__/index.js

This file was deleted.

0 comments on commit 0f2eaff

Please sign in to comment.