From 181476df3b506330e83ebeccc65b28024040fd55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Braian=20Vogri=C4=8D?= <53317134+Vogric@users.noreply.github.com> Date: Sat, 6 Feb 2021 16:38:15 -0300 Subject: [PATCH 01/58] Upgrade AdaptiveHeight to functional component The class component was updated by a functional component. var was changed to const --- examples/AdaptiveHeight.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/AdaptiveHeight.js b/examples/AdaptiveHeight.js index 7ecad701d..8db8e6b13 100644 --- a/examples/AdaptiveHeight.js +++ b/examples/AdaptiveHeight.js @@ -1,9 +1,9 @@ -import React, { Component } from "react"; +import React from "react"; import Slider from "../src/slider"; -export default class AdaptiveHeight extends Component { - render() { - var settings = { +const AdaptiveHeight = () => { + + const settings = { className: "", dots: true, infinite: true, @@ -11,6 +11,7 @@ export default class AdaptiveHeight extends Component { slidesToScroll: 1, adaptiveHeight: true }; + return (

Adaptive height

@@ -40,4 +41,5 @@ export default class AdaptiveHeight extends Component {
); } -} + +export default AdaptiveHeight; From 994ce1c1dbe2b59f45beec2a062f6d84f873aec6 Mon Sep 17 00:00:00 2001 From: Kiran Abburi Date: Fri, 17 Sep 2021 15:21:39 +0530 Subject: [PATCH 02/58] Update FUNDING.yml --- .github/FUNDING.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index 5fa15fc91..e26119c87 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1 +1,2 @@ +github: akiran open_collective: react-slick From 06a607fe24f75dea8224765518d783d66d5fc717 Mon Sep 17 00:00:00 2001 From: akiran Date: Sat, 11 Dec 2021 20:36:09 +0530 Subject: [PATCH 03/58] removed sass --- gulpfile.js | 18 ++---------------- package.json | 5 +---- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index 9cdbb5f6a..b0351b5a4 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2,7 +2,6 @@ var gulp = require("gulp"); var del = require("del"); -var sass = require("gulp-sass"); var webpack = require("webpack"); var WebpackDevServer = require("webpack-dev-server"); var assign = require("object-assign"); @@ -30,22 +29,9 @@ gulp.task("copy", function() { .pipe(gulp.dest("./build")); }); -gulp.task("sass", function() { - return gulp - .src(["./docs/**/*.{scss,sass}"]) - .pipe( - sass({ - includePaths: ["bower_components", "node_modules"], - errLogToConsole: true - }) - ) - .pipe(gulp.dest("./build")); -}); - gulp.task( "watch", - gulp.series(["copy", "sass"], function(done) { - gulp.watch(["./docs/**/*.{scss,sass}"], gulp.parallel(["sass"])); + gulp.series(["copy"], function(done) { gulp.watch(["./docs/index.html"], gulp.parallel(["copy"])); gulp.watch(["./docs/docs.css"], gulp.parallel(["copy"])); gulp.watch(["./docs/slick.css"], gulp.parallel(["copy"])); @@ -56,7 +42,7 @@ gulp.task( gulp.task( "server", - gulp.series(["watch", "copy", "sass"], function() { + gulp.series(["watch", "copy"], function() { console.log("Start"); var myConfig = require("./webpack.config"); if (process.env.SINGLE_DEMO) { diff --git a/package.json b/package.json index 03e7e3e53..4896f23ce 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "scripts": { "start": "gulp server", "demo": "SINGLE_DEMO=true gulp server", - "build-dev": "gulp clean && gulp sass && gulp copy && webpack", + "build-dev": "gulp clean && gulp copy && webpack", "lib": "babel ./src --out-dir ./lib", "build": "npm run lib && gulp dist", "prepublish": "npm run build", @@ -59,7 +59,6 @@ "express": "^4.14.0", "foundation-apps": "^1.2.0", "gulp": "^4.0.0", - "gulp-sass": "^4.0.0", "husky": "^0.14.3", "jasmine-core": "^2.5.2", "jest": "^24.8.0", @@ -67,7 +66,6 @@ "js-beautify": "^1.7.5", "json-loader": "^0.5.4", "lint-staged": "^7.0.3", - "node-sass": "^4.5.2", "opn": "^5.4.0", "postcss-loader": "^1.3.3", "prettier": "^1.14.3", @@ -76,7 +74,6 @@ "react-addons-test-utils": "^15.6.2", "react-dom": "^16.0.0", "react-test-renderer": "^16.0.0", - "sass-loader": "^6.0.3", "sinon": "^2.1.0", "slick-carousel": "^1.8.1", "style-loader": "^0.16.1", From c923c95dce4b4efaf21e83f912c5055298a84be4 Mon Sep 17 00:00:00 2001 From: akiran Date: Sat, 11 Dec 2021 22:46:06 +0530 Subject: [PATCH 04/58] updated eslint packages to fix #2078 --- .eslintrc | 14 +++++++++----- package.json | 13 ++++++------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/.eslintrc b/.eslintrc index 2d8316668..563dcfb00 100644 --- a/.eslintrc +++ b/.eslintrc @@ -9,7 +9,8 @@ "react/prop-types": 0, "react/no-find-dom-node": 0, "react/display-name": 0, - "no-console": 0 + "no-console": 0, + "no-prototype-builtins": 0 }, "env": { "node": true, @@ -17,14 +18,17 @@ "es6": true, "jasmine": true }, - "parser": "babel-eslint", + "parser": "@babel/eslint-parser", + "parserOptions": { + "requireConfigFile": false + }, "plugins": [ - "react", - "import" + "react", + "import" ], "extends": [ "eslint:recommended", "plugin:import/errors", "plugin:react/recommended" ] -} +} \ No newline at end of file diff --git a/package.json b/package.json index 4896f23ce..1546b69f6 100644 --- a/package.json +++ b/package.json @@ -36,14 +36,14 @@ ], "devDependencies": { "@babel/cli": "^7.0.0", - "@babel/core": "^7.1.2", + "@babel/core": "^7.16.0", + "@babel/eslint-parser": "^7.16.3", "@babel/plugin-proposal-class-properties": "^7.1.0", "@babel/polyfill": "^7.0.0", "@babel/preset-env": "^7.1.0", "@babel/preset-react": "^7.0.0", "autoprefixer": "^7.1.2", "babel-core": "^7.0.0-bridge.0", - "babel-eslint": "^9.0.0", "babel-jest": "^24.8.0", "babel-loader": "^8.0.4", "babel-preset-airbnb": "^2.1.1", @@ -53,9 +53,9 @@ "enzyme": "^3.2.0", "enzyme-adapter-react-16": "^1.1.0", "es5-shim": "^4.5.9", - "eslint": "^5.9.0", - "eslint-plugin-import": "^2.9.0", - "eslint-plugin-react": "^6.3.0", + "eslint": "^8.4.1", + "eslint-plugin-import": "^2.25.3", + "eslint-plugin-react": "^7.27.1", "express": "^4.14.0", "foundation-apps": "^1.2.0", "gulp": "^4.0.0", @@ -65,13 +65,12 @@ "jquery": "^3.2.1", "js-beautify": "^1.7.5", "json-loader": "^0.5.4", - "lint-staged": "^7.0.3", + "lint-staged": "^12.1.2", "opn": "^5.4.0", "postcss-loader": "^1.3.3", "prettier": "^1.14.3", "raf": "^3.4.0", "react": "^16.0.0", - "react-addons-test-utils": "^15.6.2", "react-dom": "^16.0.0", "react-test-renderer": "^16.0.0", "sinon": "^2.1.0", From fd9de1ac79d610792e42fe57f410e6c0085537d4 Mon Sep 17 00:00:00 2001 From: Paolo Pialorsi Date: Tue, 12 Apr 2022 10:20:12 +0200 Subject: [PATCH 05/58] Fixed issue with image click event --- src/inner-slider.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/inner-slider.js b/src/inner-slider.js index 7cbdb27ad..79b9dc987 100644 --- a/src/inner-slider.js +++ b/src/inner-slider.js @@ -316,8 +316,8 @@ export class InnerSlider extends React.Component { image.onclick = () => image.parentNode.focus(); } else { const prevClickHandler = image.onclick; - image.onclick = () => { - prevClickHandler(); + image.onclick = (e) => { + prevClickHandler(e); image.parentNode.focus(); }; } From 9eb7df71efdda125653d4af45459a7113dfea197 Mon Sep 17 00:00:00 2001 From: jeffascript Date: Sun, 17 Apr 2022 12:44:03 +0200 Subject: [PATCH 06/58] add support for React18 --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 1546b69f6..2bed75285 100644 --- a/package.json +++ b/package.json @@ -90,8 +90,8 @@ "resize-observer-polyfill": "^1.5.0" }, "peerDependencies": { - "react": "^0.14.0 || ^15.0.1 || ^16.0.0 || ^17.0.0", - "react-dom": "^0.14.0 || ^15.0.1 || ^16.0.0 || ^17.0.0" + "react": "^0.14.0 || ^15.0.1 || ^16.0.0 || ^17.0.0 || ^18.0.0", + "react-dom": "^0.14.0 || ^15.0.1 || ^16.0.0 || ^17.0.0 || ^18.0.0" }, "jest": { "setupFiles": [ From c3e16847c9a1ad7423c49993ffeff38a32885dd2 Mon Sep 17 00:00:00 2001 From: akiran Date: Sun, 17 Apr 2022 17:10:00 +0530 Subject: [PATCH 07/58] released 0.29.0 --- package.json | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 2bed75285..938ff8cd4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-slick", - "version": "0.28.1", + "version": "0.29.0", "description": " React port of slick carousel", "main": "./lib", "files": [ @@ -70,9 +70,9 @@ "postcss-loader": "^1.3.3", "prettier": "^1.14.3", "raf": "^3.4.0", - "react": "^16.0.0", - "react-dom": "^16.0.0", - "react-test-renderer": "^16.0.0", + "react": "^18.0.0", + "react-dom": "^18.0.0", + "react-test-renderer": "^18.0.0", "sinon": "^2.1.0", "slick-carousel": "^1.8.1", "style-loader": "^0.16.1", From 2f7fdf56684a81588194013db812c8da0defcd13 Mon Sep 17 00:00:00 2001 From: akiran Date: Tue, 26 Jul 2022 19:37:05 +0530 Subject: [PATCH 08/58] remove old tests --- __tests__/SimpleSlider.test.js | 47 - __tests__/afterChange.test.js | 67 - __tests__/arrows.js | 69 - __tests__/beforeChange.test.js | 60 - __tests__/index.js | 22 - __tests__/jQSlickUtils.js | 133 -- __tests__/lazyLoad.test.js | 67 - __tests__/mount/centerMode.test.js | 78 - __tests__/mount/lazyload.test.js | 78 - __tests__/mount/live.test.js | 77 - __tests__/mount/simple.test.js | 77 - __tests__/observations.json | 54 - __tests__/reactSlickUtils.js | 94 -- __tests__/sliderStyles.test.js | 45 - __tests__/testUtils.js | 171 -- examples/__tests__/CenterMode.test.js | 54 - examples/__tests__/Fade.js | 18 - examples/__tests__/FocusOnSelect.test.js | 16 - examples/__tests__/MultipleItems.test.js | 169 -- examples/__tests__/SimpleSlider.test.js | 130 -- examples/__tests__/SlickGoTo.test.js | 36 - examples/__tests__/UnevenSets.test.js | 125 -- .../__snapshots__/CenterMode.test.js.snap | 373 ----- .../__snapshots__/FocusOnSelect.test.js.snap | 237 --- .../__snapshots__/MultipleItems.test.js.snap | 1477 ----------------- .../__snapshots__/SimpleSlider.test.js.snap | 445 ----- .../__snapshots__/UnevenSets.test.js.snap | 559 ------- examples/__tests__/sample.test.js | 26 - package.json | 17 - test-helpers.js | 11 - test-setup.js | 23 - 31 files changed, 4855 deletions(-) delete mode 100644 __tests__/SimpleSlider.test.js delete mode 100644 __tests__/afterChange.test.js delete mode 100644 __tests__/arrows.js delete mode 100644 __tests__/beforeChange.test.js delete mode 100644 __tests__/index.js delete mode 100644 __tests__/jQSlickUtils.js delete mode 100644 __tests__/lazyLoad.test.js delete mode 100644 __tests__/mount/centerMode.test.js delete mode 100644 __tests__/mount/lazyload.test.js delete mode 100644 __tests__/mount/live.test.js delete mode 100644 __tests__/mount/simple.test.js delete mode 100644 __tests__/observations.json delete mode 100644 __tests__/reactSlickUtils.js delete mode 100644 __tests__/sliderStyles.test.js delete mode 100644 __tests__/testUtils.js delete mode 100644 examples/__tests__/CenterMode.test.js delete mode 100644 examples/__tests__/Fade.js delete mode 100644 examples/__tests__/FocusOnSelect.test.js delete mode 100644 examples/__tests__/MultipleItems.test.js delete mode 100644 examples/__tests__/SimpleSlider.test.js delete mode 100644 examples/__tests__/SlickGoTo.test.js delete mode 100644 examples/__tests__/UnevenSets.test.js delete mode 100644 examples/__tests__/__snapshots__/CenterMode.test.js.snap delete mode 100644 examples/__tests__/__snapshots__/FocusOnSelect.test.js.snap delete mode 100644 examples/__tests__/__snapshots__/MultipleItems.test.js.snap delete mode 100644 examples/__tests__/__snapshots__/SimpleSlider.test.js.snap delete mode 100644 examples/__tests__/__snapshots__/UnevenSets.test.js.snap delete mode 100644 examples/__tests__/sample.test.js delete mode 100644 test-helpers.js delete mode 100644 test-setup.js diff --git a/__tests__/SimpleSlider.test.js b/__tests__/SimpleSlider.test.js deleted file mode 100644 index af9aa149b..000000000 --- a/__tests__/SimpleSlider.test.js +++ /dev/null @@ -1,47 +0,0 @@ -// includes tests of -// SimpleSlider, MultipleItems -import { mount } from "enzyme"; -import { testSlider } from "./testUtils"; - -describe("SimpleSlider with combinations of possibilities", function() { - // try around several possibilities - let _noOfSlides = [2, 5, 12]; - let _slidesToShow = [2, 5, 10]; - let _slidesToScroll = [1, 2, 3, 10]; - if (true) { - // for switching real quick to lesser/easier tests for simplicity - _noOfSlides = [5]; - _slidesToShow = [2]; - _slidesToScroll = [1, 2]; - } - - for (let noOfSlides of _noOfSlides) { - for (let slidesToShow of _slidesToShow) { - for (let slidesToScroll of _slidesToScroll) { - // following restrictions may not be 100% correct, and there may be more restrictions - if (slidesToShow > noOfSlides || slidesToScroll > slidesToShow) { - continue; - } - if (noOfSlides === slidesToShow) { - // temporary, jquery slick disables arrows in this case, so the tests fail - continue; - } - if (slidesToShow === slidesToScroll) { - // temporary, active-class is not being assigned properly, so tests fail - continue; - } - const settings1 = { - infinite: true, - speed: 0, - noOfSlides, - slidesToShow, - slidesToScroll, - useCSS: false - }; - test(`Test with settings => noOfSlides: ${noOfSlides}, slidesToShow: ${slidesToShow}, slidesToScroll: ${slidesToScroll}`, function() { - testSlider(settings1); - }); - } - } - } -}); diff --git a/__tests__/afterChange.test.js b/__tests__/afterChange.test.js deleted file mode 100644 index 8e96e5b92..000000000 --- a/__tests__/afterChange.test.js +++ /dev/null @@ -1,67 +0,0 @@ -import React from "react"; -import { mount } from "enzyme"; -import Slider from "../src/index"; - -class SliderWithBeforeChange extends React.Component { - constructor(props) { - super(props); - this.state = { - currentSlide: null - }; - this.afterChange = this.afterChange.bind(this); - } - - afterChange(currentSlide) { - console.log(currentSlide, "afterChange"); - this.setState({ - currentSlide - }); - } - render() { - return ( - -
slide1
-
slide2
-
slide3
-
slide4
-
- ); - } -} - -describe("After change Slider", function() { - it("should render", function() { - const wrapper = mount(); - expect(wrapper.state()).toEqual({ currentSlide: null }); - wrapper.find(".slick-next").simulate("click"); - 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"); - 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"); - setTimeout(() => { - expect( - wrapper - .find(".slick-slide.slick-active") - .first() - .text() - ).toEqual("slide2"); - expect(wrapper.state()).toEqual({ currentSlide: 1 }); - }, 1); - }); -}); diff --git a/__tests__/arrows.js b/__tests__/arrows.js deleted file mode 100644 index ea8915dd0..000000000 --- a/__tests__/arrows.js +++ /dev/null @@ -1,69 +0,0 @@ -/** - * Arrow component tests - */ - -sinon.stub(console, "error"); - -import { render, shallow } from "enzyme"; -import React from "react"; -import sinon from "sinon"; - -import { NextArrow, PrevArrow } from "../src/arrows"; - -function CustomArrow(props) { - return ( - - ); -} - -describe("Previous arrows", () => { - it("should render arrow", () => { - const wrapper = shallow(); - expect(wrapper.find("button")).toHaveLength(1); - }); - - it("should not result in errors", () => { - shallow(); - - expect(console.error.called).toBe(false); - }); - - // it('should pass slide data to custom arrow', () => { - // let elAttributes; - // let arr = - // - // const wrapper = render(); - // - // elAttributes = wrapper.find('.sample')[0].attribs; - // expect(elAttributes['data-currentslide']).toBe('3'); - // expect(elAttributes['data-slidecount']).toBe('5'); - // }); -}); - -describe("Next arrows", () => { - it("should render arrow", () => { - const wrapper = shallow(); - expect(wrapper.find("button")).toHaveLength(1); - }); - - // it('should not result in errors', () => { - // shallow(); - // - // expect(console.error.called).toBe(false); - // }); - - // it('should pass slide data to custom arrow', () => { - // let elAttributes; - // let arr = - // - // const wrapper = render(); - // - // elAttributes = wrapper.find('.sample')[0].attribs; - // expect(elAttributes['data-currentslide']).toBe('6'); - // expect(elAttributes['data-slidecount']).toBe('9'); - // }); -}); diff --git a/__tests__/beforeChange.test.js b/__tests__/beforeChange.test.js deleted file mode 100644 index 16733b296..000000000 --- a/__tests__/beforeChange.test.js +++ /dev/null @@ -1,60 +0,0 @@ -import React from "react"; -import { mount } from "enzyme"; -import Slider from "../src/index"; - -class SliderWithBeforeChange extends React.Component { - constructor(props) { - super(props); - this.state = { - currentSlide: null, - nextSlide: null - }; - this.beforeChange = this.beforeChange.bind(this); - } - beforeChange(currentSlide, nextSlide) { - this.setState({ - currentSlide, - nextSlide - }); - } - render() { - return ( - -
slide1
-
slide2
-
slide3
-
slide4
-
- ); - } -} - -describe.skip("Slider", function() { - it("should render", function() { - const wrapper = mount(); - 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 }); - }); -}); diff --git a/__tests__/index.js b/__tests__/index.js deleted file mode 100644 index 099e87cf3..000000000 --- a/__tests__/index.js +++ /dev/null @@ -1,22 +0,0 @@ -"use strict"; - -import React from "react"; -import { shallow, mount } from "enzyme"; -import Slider from "../src/index"; - -describe("Slider", function() { - it("should render", function() { - const wrapper = shallow( - -
slide1
-
- ); - expect( - wrapper.contains( -
- slide1 -
- ) - ).toBe(true); - }); -}); diff --git a/__tests__/jQSlickUtils.js b/__tests__/jQSlickUtils.js deleted file mode 100644 index e353cf45e..000000000 --- a/__tests__/jQSlickUtils.js +++ /dev/null @@ -1,133 +0,0 @@ -// this is for fetching details after initializing react and jquery slicks -// and compare those details to see if things are going different - -import { - createSliderReact, - createJQuerySliderChildren, - activeSlideInLastTransition -} from "./testUtils"; -import $ from "jquery"; -import * as slickCarousel from "slick-carousel"; -import util from "util"; -import js_beautify, { html as html_beautify } from "js-beautify"; - -// simulates actions from given actions object -// takes document from the scope from where it's called -function simulateActions(actions) { - if (actions.clickNext) { - for (let click = 0; click < actions.clickNext; click++) { - $(".slick-next").click(); - } - } - if (actions.clickPrev) { - for (let click = 0; click < actions.clickPrev; click++) { - $(".slick-prev").click(); - } - } - if (actions.clickSequence) { - for (let click of actions.clickSequence) { - if (click === "n") { - $(".slick-next").click(); - } else if (click === "p") { - $(".slick-prev").click(); - } else { - // that's right, you can't even write n/p properly - } - } - } -} - -// takes an object of keys and returns those details -/* Possible keys can be one of the following -currentSlide(index and value), activeSlides(index and value), -allSlides(index and value), clonedSlides(index and value) -*/ -function fetchDetails(keys) { - let details = {}; - let currentSlide = null, - activeSlides = [], - allSlides = [], - clonedSlides = [], - visibleSlides = []; - for (let slide of $("div.slick-slide")) { - const slideObj = { - index: $(slide).attr("data-slick-index"), - value: $(slide) - .find("div") - .find("div") - .find("h3") - .text() - }; - allSlides.push(slideObj); - if ($(slide).hasClass("slick-current")) { - currentSlide = slideObj.index; - } - if ($(slide).hasClass("slick-active")) { - activeSlides.push(slideObj); - } - if ($(slide).hasClass("slick-cloned")) { - clonedSlides.push(slideObj); - } - if ($(slide).attr("aria-hidden") == "false") { - visibleSlides.push(slideObj); - } - } - if (keys.currentSlide) { - details.currentSlide = currentSlide; - } - if (keys.activeSlides) { - details.activeSlides = activeSlides; - } - if (keys.allSlides) { - details.allSlides = allSlides; - } - if (keys.clonedSlides) { - details.clonedSlides = clonedSlides; - } - if (keys.visibleSlides) { - details.visibleSlides = visibleSlides; - } - return details; -} - -// creates a jQuery slick with given settings and -// performs the given actions -// returns the given keys -export function getJQuerySlickDetails(settings, actions, keys) { - // create new slider - document.body.innerHTML = ` -
- ${createJQuerySliderChildren(settings.noOfSlides)} -
- `; - $(".regular.slider").slick({ - ...settings - }); - simulateActions(actions); - // console.log(html_beautify($('.regular.slider').html())) - return fetchDetails(keys); -} - -const settings = { - infinite: true, - noOfSlides: 5, - slidesToShow: 3, - slidesToScroll: 2, - useCSS: false, - speed: 0 -}; -const actions = { - clickNext: 2, - clickPrev: 1, - clickSequence: ["n", "p", "n"] -}; -const keys = { - activeSlides: true, - visibleSlides: true, - allSlides: true -}; - -test("testing getJQuerySlickDetails utility", () => { - const details = getJQuerySlickDetails(settings, actions, keys); - expect(details.activeSlides).toEqual(details.visibleSlides); -}); diff --git a/__tests__/lazyLoad.test.js b/__tests__/lazyLoad.test.js deleted file mode 100644 index df2ca6ff4..000000000 --- a/__tests__/lazyLoad.test.js +++ /dev/null @@ -1,67 +0,0 @@ -import { mount } from "enzyme"; -import assign from "object-assign"; -import { getRequiredLazySlides } from "../src/utils/innerSliderUtils"; -import { - createInnerSliderWrapper, - clickNext, - clickPrev, - tryAllConfigs -} from "./testUtils"; - -const testSettings = settings => { - let slider = createInnerSliderWrapper(settings); - for (let click = 0; click < settings.noOfSlides + 2; click++) { - let lazyLoadedList = slider.state().lazyLoadedList; - let expectedLazyLoadedList = getRequiredLazySlides( - assign({}, slider.props(), slider.state()) - ); - expectedLazyLoadedList.forEach(slide => { - expect(lazyLoadedList.indexOf(slide) >= 0).toEqual(true); - }); - clickNext(slider); - } - - slider = createInnerSliderWrapper(settings); - for (let click = 0; click < settings.noOfSlides + 2; click++) { - let lazyLoadedList = slider.state().lazyLoadedList; - let expectedLazyLoadedList = getRequiredLazySlides( - assign({}, slider.props(), slider.state()) - ); - expectedLazyLoadedList.forEach(slide => { - expect(lazyLoadedList.indexOf(slide) >= 0).toEqual(true); - }); - clickPrev(slider); - } - - slider = createInnerSliderWrapper(settings); - for (let click = 0; click < settings.noOfSlides + 2; click++) { - let lazyLoadedList = slider.state().lazyLoadedList; - lazyLoadedList.forEach(slideIndex => { - expect( - slider.find(`[data-index=${slideIndex}]`).props().children !== undefined - ).toBe(true); - }); - } -}; - -describe("LazyLoad test", () => { - let settings = { - lazyLoad: true, - useCSS: false, - speed: 0, - noOfSlides: [7, 8], - initialSlide: [0, 5], - slidesToShow: [1, 3, 4], - slidesToScroll: [1, 3], - centerMode: [true, false] - }; - let settingsList = []; - tryAllConfigs(settings, settingsList); - // shuffle the list - settingsList.sort(() => 0.5 - Math.random()); - settingsList.forEach((settings, index) => { - if (Math.random() < 0.5) { - test(`Testing config no. ${index}`, () => testSettings(settings)); - } - }); -}); diff --git a/__tests__/mount/centerMode.test.js b/__tests__/mount/centerMode.test.js deleted file mode 100644 index e37db0923..000000000 --- a/__tests__/mount/centerMode.test.js +++ /dev/null @@ -1,78 +0,0 @@ -import { getJQuerySlickDetails } from "../jQSlickUtils"; -import { getReactSlickDetails } from "../reactSlickUtils"; - -let settings = { - infinite: true, - speed: 0, - useCSS: false, - noOfSlides: 5, - slidesToShow: 3, - slidesToScroll: 1, - centerMode: true -}; -let actions = { - clickNext: 0, - clickPrev: 0, - clickSequence: [] -}; -let keys = { - currentSlide: true, - activeSlides: true, - clonedSlides: true, - allSlides: true -}; - -const testsUtil = (settings, actions, keys) => { - const jqDetails = getJQuerySlickDetails(settings, actions, keys); - const reactDetails = getReactSlickDetails(settings, actions, keys); - test("checking current slide jQuery vs react", () => { - expect(reactDetails.currentSlide).toEqual(jqDetails.currentSlide); - }); - test("checking active slides jQuery vs react", () => { - expect(reactDetails.activeSlides).toEqual(jqDetails.activeSlides); - }); - - // Following two tests fail - test("checking cloned slides jQuery vs react", () => { - expect(reactDetails.clonedSlides.map(slide => slide.index)).toEqual( - jqDetails.clonedSlides.map(slide => slide.index) - ); - }); - test("checking all slides jQuery vs react", () => { - expect(reactDetails.allSlides.map(slide => slide.index)).toEqual( - jqDetails.allSlides.map(slide => slide.index) - ); - }); -}; - -describe("InnerSlider component tests: Part 1", () => { - testsUtil(settings, actions, keys); -}); -describe("InnerSlider component tests: Part 2", () => { - settings.slidesToScroll = 2; - testsUtil(settings, actions, keys); -}); -describe("InnerSlider component tests: Part 3", () => { - actions.clickNext = 2; - testsUtil(settings, actions, keys); -}); -describe("InnerSlider component tests: Part 4", () => { - actions.clickPrev = 2; - testsUtil(settings, actions, keys); -}); -describe("InnerSlider component tests: Part 5", () => { - actions.clickNext = 6; - testsUtil(settings, actions, keys); -}); -describe("InnerSlider component tests: Part 6", () => { - actions.clickPrev = 6; - testsUtil(settings, actions, keys); -}); -describe("InnerSlider component tests: Part 7", () => { - actions.clickSequence = ["n", "n", "n", "n", "n", "n", "p", "p", "p"]; - testsUtil(settings, actions, keys); -}); -describe("InnerSlider component tests: Part 8", () => { - actions.clickSequence = ["p", "p", "p", "p", "p", "p", "n", "n", "n"]; - testsUtil(settings, actions, keys); -}); diff --git a/__tests__/mount/lazyload.test.js b/__tests__/mount/lazyload.test.js deleted file mode 100644 index 08db3c1ab..000000000 --- a/__tests__/mount/lazyload.test.js +++ /dev/null @@ -1,78 +0,0 @@ -import { getJQuerySlickDetails } from "../jQSlickUtils"; -import { getReactSlickDetails } from "../reactSlickUtils"; - -let settings = { - infinite: true, - speed: 0, - useCSS: false, - lazyLoad: true, - noOfSlides: 5, - slidesToShow: 3, - slidesToScroll: 1 -}; -let actions = { - clickNext: 0, - clickPrev: 0, - clickSequence: [] -}; -let keys = { - currentSlide: true, - activeSlides: true, - clonedSlides: true, - allSlides: true -}; - -const testsUtil = (settings, actions, keys) => { - const jqDetails = getJQuerySlickDetails(settings, actions, keys); - const reactDetails = getReactSlickDetails(settings, actions, keys); - test.skip("checking current slide jQuery vs react", () => { - expect(reactDetails.currentSlide).toEqual(jqDetails.currentSlide); - }); - test.skip("checking active slides jQuery vs react", () => { - expect(reactDetails.activeSlides).toEqual(jqDetails.activeSlides); - }); - - // Following two tests fail - test("checking cloned slides jQuery vs react", () => { - expect(reactDetails.clonedSlides.map(slide => slide.index)).toEqual( - jqDetails.clonedSlides.map(slide => slide.index) - ); - }); - test("checking all slides jQuery vs react", () => { - expect(reactDetails.allSlides.map(slide => slide.index)).toEqual( - jqDetails.allSlides.map(slide => slide.index) - ); - }); -}; - -describe("InnerSlider component tests with lazyload: Part 1", () => { - testsUtil(settings, actions, keys); -}); -describe("InnerSlider component tests with lazyload: Part 2", () => { - settings.slidesToScroll = 2; - testsUtil(settings, actions, keys); -}); -describe("InnerSlider component tests with lazyload: Part 3", () => { - actions.clickNext = 2; - testsUtil(settings, actions, keys); -}); -describe("InnerSlider component tests with lazyload: Part 4", () => { - actions.clickPrev = 2; - testsUtil(settings, actions, keys); -}); -describe("InnerSlider component tests with lazyload: Part 5", () => { - actions.clickNext = 6; - testsUtil(settings, actions, keys); -}); -describe("InnerSlider component tests with lazyload: Part 6", () => { - actions.clickPrev = 6; - testsUtil(settings, actions, keys); -}); -describe("InnerSlider component tests with lazyload: Part 7", () => { - actions.clickSequence = ["n", "n", "n", "n", "n", "n", "p", "p", "p"]; - testsUtil(settings, actions, keys); -}); -describe("InnerSlider component tests with lazyload: Part 8", () => { - actions.clickSequence = ["p", "p", "p", "p", "p", "p", "n", "n", "n"]; - testsUtil(settings, actions, keys); -}); diff --git a/__tests__/mount/live.test.js b/__tests__/mount/live.test.js deleted file mode 100644 index 069a457d9..000000000 --- a/__tests__/mount/live.test.js +++ /dev/null @@ -1,77 +0,0 @@ -import { getJQuerySlickDetails } from "../jQSlickUtils"; -import { getReactSlickDetails } from "../reactSlickUtils"; - -describe("live testing module", () => { - let settings = { - infinite: true, - speed: 0, - useCSS: false, - noOfSlides: 5, - slidesToShow: 3, - slidesToScroll: 1 - // centerMode: true, - }; - let actions = { - clickNext: 0, - clickPrev: 0, - clickSequence: [] - }; - let keys = { - // currentSlide: true, - // activeSlides: true, - clonedSlides: true - // allSlides: true, - }; - let reactDetails = getReactSlickDetails(settings, actions, keys); - let jqueryDetails = getJQuerySlickDetails(settings, actions, keys); - - // for(let noOfSlides of [5, 12]){ - // for (let slidesToShow of [1, 11, 12]){ - // for (let slidesToScroll of [1, 2, 11, 12]){ - - // for(let noOfSlides of [2, 3, 5, 6, 12]){ - // for (let slidesToShow of [1, 2, 3, 5, 11, 12]){ - // for (let slidesToScroll of [1, 2, 3, 5, 11, 12]){ - // if(noOfSlides < slidesToShow || noOfSlides < slidesToScroll || slidesToShow < slidesToScroll){ - // continue; - // } - // settings.noOfSlides = noOfSlides - // settings.slidesToShow = slidesToShow - // settings.slidesToScroll = slidesToScroll - // const jqueryDetails = getJQuerySlickDetails(settings, actions, keys) - // const reactDetails = getReactSlickDetails(settings, actions, keys) - // // test('number of cloned slides', () => { - // // expect(jqueryDetails.clonedSlides.filter(slide => slide.index < 0).length).toEqual( - // // noOfSlides === slidesToShow ? 0 : (settings.centerMode ? slidesToShow+1 : slidesToShow) - // // ) - // // expect(jqueryDetails.clonedSlides.filter(slide => slide.index >= 0).length).toEqual( - // // noOfSlides === slidesToShow ? 0 : noOfSlides - // // ) - // // }) - - // test('number of cloned slides, react vs jquery', () => { - // expect(reactDetails.clonedSlides.filter(slide => slide.index < 0).length).toEqual( - // jqueryDetails.clonedSlides.filter(slide => slide.index < 0).length - // ) - // expect(reactDetails.clonedSlides.filter(slide => slide.index >= 0).length).toEqual( - // jqueryDetails.clonedSlides.filter(slide => slide.index >= 0).length - // ) - // }) - - // // console.log( - // // 'settings:', settings, '\n', - // // 'pre:', jqueryDetails.clonedSlides.filter(slide => slide.index < 0).length, - // // 'post:', jqueryDetails.clonedSlides.filter(slide => slide.index >= 0).length - // // ) - // // console.log( - // // 'settings2:', settings.noOfSlides, '\n', - // // 'details2:', reactDetails.clonedSlides - // // .filter(slide => slide.index > 0).length - // // ) - // } - // } - // } - test("fake test", () => { - expect(1).toBe(1); - }); -}); diff --git a/__tests__/mount/simple.test.js b/__tests__/mount/simple.test.js deleted file mode 100644 index 06253ae52..000000000 --- a/__tests__/mount/simple.test.js +++ /dev/null @@ -1,77 +0,0 @@ -import { getJQuerySlickDetails } from "../jQSlickUtils"; -import { getReactSlickDetails } from "../reactSlickUtils"; - -let settings = { - infinite: true, - speed: 0, - useCSS: false, - noOfSlides: 5, - slidesToShow: 3, - slidesToScroll: 1 -}; -let actions = { - clickNext: 0, - clickPrev: 0, - clickSequence: [] -}; -let keys = { - currentSlide: true, - activeSlides: true, - clonedSlides: true, - allSlides: true -}; - -const testsUtil = (settings, actions, keys) => { - const jqDetails = getJQuerySlickDetails(settings, actions, keys); - const reactDetails = getReactSlickDetails(settings, actions, keys); - test("checking current slide jQuery vs react", () => { - expect(reactDetails.currentSlide).toEqual(jqDetails.currentSlide); - }); - test("checking active slides jQuery vs react", () => { - expect(reactDetails.activeSlides).toEqual(jqDetails.activeSlides); - }); - - // Following two tests fail - test("checking cloned slides jQuery vs react", () => { - expect(reactDetails.clonedSlides.map(slide => slide.index)).toEqual( - jqDetails.clonedSlides.map(slide => slide.index) - ); - }); - test("checking all slides jQuery vs react", () => { - expect(reactDetails.allSlides.map(slide => slide.index)).toEqual( - jqDetails.allSlides.map(slide => slide.index) - ); - }); -}; - -describe("InnerSlider component tests: Part 1", () => { - testsUtil(settings, actions, keys); -}); -describe("InnerSlider component tests: Part 2", () => { - settings.slidesToScroll = 2; - testsUtil(settings, actions, keys); -}); -describe("InnerSlider component tests: Part 3", () => { - actions.clickNext = 2; - testsUtil(settings, actions, keys); -}); -describe("InnerSlider component tests: Part 4", () => { - actions.clickPrev = 2; - testsUtil(settings, actions, keys); -}); -describe("InnerSlider component tests: Part 5", () => { - actions.clickNext = 6; - testsUtil(settings, actions, keys); -}); -describe("InnerSlider component tests: Part 6", () => { - actions.clickPrev = 6; - testsUtil(settings, actions, keys); -}); -describe("InnerSlider component tests: Part 7", () => { - actions.clickSequence = ["n", "n", "n", "n", "n", "n", "p", "p", "p"]; - testsUtil(settings, actions, keys); -}); -describe("InnerSlider component tests: Part 8", () => { - actions.clickSequence = ["p", "p", "p", "p", "p", "p", "n", "n", "n"]; - testsUtil(settings, actions, keys); -}); diff --git a/__tests__/observations.json b/__tests__/observations.json deleted file mode 100644 index 300bdcf15..000000000 --- a/__tests__/observations.json +++ /dev/null @@ -1,54 +0,0 @@ -{ - "jQueryTest": [ - { - "observation": "Clicks on arrows are not working properly", - "possibleCause": "Animation effects are taking effects somehow", - "solutions": [ - { - "description": "set useCSS property to false", - "status": "did not work" - }, - { - "description": "set speed property to 0", - "status": "worked, now the clicks are working as of now" - } - ] - }, - { - "observation": "arrows are disabled when slidesToShow are equal to noOfSlides", - "status": "causes few tests to fail" - }, - { - "observation": "tests are very slow", - "possibleCause": "synchronous click event simulation and slow DOM api", - "status": "not tried yet" - } - ], - "reactTest": [ - { - "observation": "Clicks on arrows are not working properly", - "possibleCause": "Animation effects are taking effects somehow", - "solutions": [ - { - "description": "set useCSS property to false", - "status": "worked, now the clicks are working as of now" - } - ] - } - ], - "misc": [ - { - "observation": "In case of reverse scrolling, slick-active class is not being assigned properly.", - "example": { - "settings": { - "noOfSlides": 5, - "slidesToShow": 2, - "slidesToScroll": 2 - }, - "jqueryBehaviour": "after one prev click, current-slide is 5th and active-class is assigned to slide 4th and 5th while the same are displayed in frame", - "reactBehaviour": "after one prev click, current-slide is 5th and active-class is assigned to slide 5th and 1st(cloned) while 4th and 5th are displayed in frame", - "status": "several tests are failing due to this property" - } - } - ] -} \ No newline at end of file diff --git a/__tests__/reactSlickUtils.js b/__tests__/reactSlickUtils.js deleted file mode 100644 index cf44a155b..000000000 --- a/__tests__/reactSlickUtils.js +++ /dev/null @@ -1,94 +0,0 @@ -import { createInnerSliderWrapper } from "./testUtils"; - -// given slider and actions objects, and simulates given actions -function simulateActions(slider, actions) { - const nextArrow = slider.find(".slick-next"); - const prevArrow = slider.find(".slick-prev"); - if (actions.clickNext) { - for (let click = 0; click < actions.clickNext; click++) { - nextArrow.simulate("click"); - } - } - if (actions.clickPrev) { - for (let click = 0; click < actions.clickPrev; click++) { - prevArrow.simulate("click"); - } - } - if (actions.clickSequence) { - for (let click of actions.clickSequence) { - if (click === "n") { - nextArrow.simulate("click"); - } else if (click === "p") { - prevArrow.simulate("click"); - } else { - // not a valid action for now - } - } - } - // console.log('after simulating actions, state of slider:', slider.state()) -} - -function fetchDetails(slider, keys) { - let details = { ...fetchDOMDetails(slider, keys) }; - if (keys.currentSlide) { - details.currentSlide = slider.state().currentSlide.toString(); - } - return details; -} - -function fetchDOMDetails(slider, keys) { - let details = {}; - let currentSlide = null, - activeSlides = [], - allSlides = [], - clonedSlides = [], - visibleSlides = []; // currently no way to find these - slider.find("div.slick-slide").forEach((slide, index) => { - const slideObj = { - index: slide.prop("data-index").toString(), - value: slide.find("h3").length === 1 ? slide.find("h3").text() : "..." - }; - allSlides.push(slideObj); - if (slide.hasClass("slick-active")) { - activeSlides.push(slideObj); - } - if (slide.hasClass("slick-cloned")) { - clonedSlides.push(slideObj); - } - if (slide.hasClass("slick-current")) { - currentSlide = slideObj; - } - }); - if (keys.currentSlide) { - details.currentSlide = currentSlide; - } - if (keys.activeSlides) { - details.activeSlides = activeSlides; - } - if (keys.allSlides) { - details.allSlides = allSlides; - } - if (keys.clonedSlides) { - details.clonedSlides = clonedSlides; - } - if (keys.visibleSlides) { - details.visibleSlides = visibleSlides; - } - return details; -} - -export function getReactSlickDetails(settings, actions, keys) { - const slider = createInnerSliderWrapper(settings); - simulateActions(slider, actions); - return fetchDetails(slider, keys); -} - -/* -settings: [...sliderProps, noOfSlides], -actions: [clickNext, clickPrev, clickSequence], -keys: [currentSlide, activeSlides, clonedSlides, allSlides, visibleSlides] -*/ - -test("fake test", () => { - expect(1).toBe(1); -}); diff --git a/__tests__/sliderStyles.test.js b/__tests__/sliderStyles.test.js deleted file mode 100644 index a34f2a705..000000000 --- a/__tests__/sliderStyles.test.js +++ /dev/null @@ -1,45 +0,0 @@ -import { mount } from "enzyme"; -import assign from "object-assign"; -import { getRequiredLazySlides } from "../src/utils/innerSliderUtils"; -import { - createInnerSliderWrapper, - clickNext, - clickPrev, - tryAllConfigs, - actualTrackLeft, - testTrackLeft -} from "./testUtils"; -import { getTrackLeft } from "../src/utils/innerSliderUtils"; - -const testSettings = settings => { - let slider = createInnerSliderWrapper(settings); - for (let click = 0; click < settings.noOfSlides + 2; click++) { - testTrackLeft(slider); - clickNext(slider); - } - slider = createInnerSliderWrapper(settings); - for (let click = 0; click < settings.noOfSlides + 2; click++) { - testTrackLeft(slider); - clickPrev(slider); - } -}; - -describe("Slider Styles Tests", () => { - let settings = { - useCSS: false, - speed: 0, - centerMode: [true, false], - noOfSlides: [7, 8], - initialSlide: [0, 5], - slidesToShow: [1, 3, 4] - }; - let settingsList = []; - tryAllConfigs(settings, settingsList); - // shuffle the list - settingsList.sort(() => 0.5 - Math.random()); - settingsList.forEach((settings, index) => { - if (Math.random() < 0.5) { - test(`Testing config no. ${index}`, () => testSettings(settings)); - } - }); -}); diff --git a/__tests__/testUtils.js b/__tests__/testUtils.js deleted file mode 100644 index ce4a12047..000000000 --- a/__tests__/testUtils.js +++ /dev/null @@ -1,171 +0,0 @@ -import React from "react"; -import $ from "jquery"; -import assign from "object-assign"; -import { mount } from "enzyme"; -import Slider from "../src/slider"; -import { InnerSlider } from "../src/inner-slider"; -import defaultProps from "../src/default-props"; -import * as slickCarousel from "slick-carousel"; // defining slick in global environment -import { getTrackLeft } from "../src/utils/innerSliderUtils"; - -// finds active slide number in the last transition in the forward direction -export function activeSlideInLastTransition( - noOfSlides, - slidesToShow, - slidesToScroll -) { - let currentSlide = 0; - while (currentSlide < noOfSlides) { - currentSlide += slidesToScroll; - } - return currentSlide - slidesToScroll; -} - -// create jsx-form children for react slider -export function createReactSliderChildren(noOfSlides) { - return Array.from(Array(noOfSlides).keys()).map(i => ( -
-

{i + 1}

-
- )); -} - -// create a react-slider with given noOfSlides and other props -// variable widths are ignored for now for simplicity -export function createReactSlider({ noOfSlides, ...props }) { - return {createReactSliderChildren(noOfSlides)}; -} - -// create a react inner-slider with given noOfSlides and other props -// performs most operations like the ones when mounted inside Slider component -export function createInnerSlider({ noOfSlides, ...settings }) { - if (settings.centerMode) { - settings.slidesToScroll = 1; // always scroll by one when centerMode is enabled - } - settings = assign({}, defaultProps, settings); - const children = React.Children.toArray( - createReactSliderChildren(noOfSlides) - ); - return {children}; -} - -export function createInnerSliderWrapper(settings) { - return mount(createInnerSlider(settings)); -} - -// creates a dom string, containing children of slick children -export function createJQuerySliderChildren(noOfSlides) { - let children = []; - for (let i = 0; i < noOfSlides; i++) { - children.push(`

${i + 1}

`); - } - return children.join(""); -} - -// performs the very basic tests while clicking next or prev -export function testSliderScroll({ direction, ...settings }) { - const { noOfSlides, slidesToShow, slidesToScroll, initialSlide } = settings; - // initialize react slider - const slider = mount(createReactSlider(settings)); - // initialize jquery slider - document.body.innerHTML = ` -
- ${createJQuerySliderChildren(noOfSlides)} -
- `; - $(".regular.slider").slick({ - ...settings - }); - // console.log('setings:', settings) - - let expectedSlideIndex = initialSlide || 0; - for (let click = 0; click < 2 * noOfSlides + 2; click++) { - let activeSlides = slider.find(".slick-slide.slick-active"); - let $activeSlides = $(".regular.slider").find("div.slick-active"); - expect(activeSlides.length).toEqual(slidesToShow || 1); - expect($activeSlides.length).toEqual(slidesToShow || 1); - let firstActiveSlide = activeSlides.first(); - let $firstActiveSlide = $activeSlides.first(); - // console.log('classes', $firstActiveSlide.attr('data-slick-index')) - // console.warn('currentSlide:', firstActiveSlide.prop('data-index'), 'expected slide', expectedSlideIndex) - expect(firstActiveSlide.prop("data-index")).toEqual( - expectedSlideIndex % noOfSlides - ); - expect(parseInt($firstActiveSlide.attr("data-slick-index"))).toEqual( - expectedSlideIndex % noOfSlides - ); - if (direction === "next") { - // click the next arrow button - slider.find(".slick-next").simulate("click"); - $("button.slick-next").click(); - expectedSlideIndex += slidesToScroll || 1; - if (expectedSlideIndex >= noOfSlides) { - expectedSlideIndex = 0; - } - } else { - // click on the prev arrow button - slider.find(".slick-prev").simulate("click"); - $("button.slick-prev").click(); - expectedSlideIndex -= slidesToScroll || 1; - if (expectedSlideIndex < 0) { - expectedSlideIndex = activeSlideInLastTransition( - noOfSlides, - slidesToShow, - slidesToScroll - ); - } - } - } -} - -// function to run tests on a slider, -// scrolls slider to the right by clicking right arrow several times -// scrolls slider to the left by clicking left arrow several times -export function testSlider(settings) { - const settings1 = { direction: "next", ...settings }; - const settings2 = { direction: "prev", ...settings }; - testSliderScroll(settings1); - testSliderScroll(settings2); -} - -export const clickNext = wrapper => - wrapper.find(".slick-next").simulate("click"); -export const clickPrev = wrapper => - wrapper.find(".slick-prev").simulate("click"); - -export const tryAllConfigs = (settings, settingsList) => { - let leaf = true; - for (let key of Object.keys(settings)) { - if (Array.isArray(settings[key])) { - leaf = false; - for (let val of settings[key]) { - tryAllConfigs({ ...settings, [key]: val }, settingsList); - } - } - } - if (leaf) { - if ( - settingsList - .map(setting => JSON.stringify(setting)) - .indexOf(JSON.stringify(settings)) < 0 - ) { - settingsList.push(settings); - } - } -}; - -export const actualTrackLeft = wrapper => - wrapper - .find(".slick-track") - .props() - .style.transform.match(/translate3d\((\d+)px/i)[1]; - -export const testTrackLeft = wrapper => { - let trackLeft = parseInt(actualTrackLeft(wrapper)); - let spec = assign({}, wrapper.props(), wrapper.state(), { - slideIndex: wrapper.state().currentSlide, - trackRef: null - }); - let expectedTrackLeft = getTrackLeft(spec); - expect(trackLeft).toEqual(parseInt(expectedTrackLeft)); -}; diff --git a/examples/__tests__/CenterMode.test.js b/examples/__tests__/CenterMode.test.js deleted file mode 100644 index 1123c2aa3..000000000 --- a/examples/__tests__/CenterMode.test.js +++ /dev/null @@ -1,54 +0,0 @@ -import React from "react"; -import { mount } from "enzyme"; -import CenterMode from "../CenterMode"; -import { html as beautify_html } from "js-beautify"; -import { clickNext } from "../../__tests__/testUtils"; - -describe("CenterMode Tests", () => { - test("Counting test", () => { - const slider = mount(); - let totalSlides = slider.find(".slick-slide").length; - let clonedSlides = slider.find(".slick-cloned").length; - let activeSlides = slider.find(".slick-slide.slick-active").length; - expect(totalSlides).toEqual(16); - expect(clonedSlides).toEqual(10); - expect(activeSlides).toEqual(3); - expect(beautify_html(slider.html())).toMatchSnapshot(); - }); - test("Positioning test", () => { - const slider = mount(); - let currentSlide = slider.find("div.slick-current"); - let activeSlides = slider.find("div.slick-active"); - expect(currentSlide.props()["data-index"]).toEqual(0); - expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([ - -1, - 0, - 1 - ]); - expect(beautify_html(slider.html())).toMatchSnapshot(); - }); - test("Activity test", () => { - const slider = mount(); - let currentSlide = slider.find("div.slick-current"); - let activeSlides = slider.find("div.slick-active"); - expect(currentSlide.props()["data-index"]).toEqual(0); - expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([ - -1, - 0, - 1 - ]); - - clickNext(slider); - - currentSlide = slider.find("div.slick-current"); - activeSlides = slider.find("div.slick-active"); - expect(currentSlide.props()["data-index"]).toEqual(1); - expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([ - 0, - 1, - 2 - ]); - - expect(beautify_html(slider.html())).toMatchSnapshot(); - }); -}); diff --git a/examples/__tests__/Fade.js b/examples/__tests__/Fade.js deleted file mode 100644 index 80a1095f3..000000000 --- a/examples/__tests__/Fade.js +++ /dev/null @@ -1,18 +0,0 @@ -import React from "react"; -import { mount } from "enzyme"; -import Fade from "../Fade"; -import { clickNext, clickPrev } from "../../__tests__/testUtils"; - -describe("Fade", () => { - it("should change slides when clicked on next & prev buttons", () => { - const slider = mount(); - let activeSlide = slider.find("div.slick-active"); - expect(activeSlide.props()["data-index"]).toEqual(0); - clickNext(slider); - activeSlide = slider.find("div.slick-active"); - expect(activeSlide.props()["data-index"]).toEqual(1); - clickPrev(slider); - activeSlide = slider.find("div.slick-active"); - expect(activeSlide.props()["data-index"]).toEqual(0); - }); -}); diff --git a/examples/__tests__/FocusOnSelect.test.js b/examples/__tests__/FocusOnSelect.test.js deleted file mode 100644 index a7928cfea..000000000 --- a/examples/__tests__/FocusOnSelect.test.js +++ /dev/null @@ -1,16 +0,0 @@ -import React from "react"; -import { mount } from "enzyme"; -import { html as beautify_html } from "js-beautify"; -import { clickNext } from "../../__tests__/testUtils"; -import FocusOnSelect from "../FocusOnSelect"; - -describe("FocusOnSelect Tests", () => { - test("Activity Test", () => { - const slider = mount(); - expect(slider.find("div.slick-current").props()["data-index"]).toEqual(0); - expect(beautify_html(slider.html())).toMatchSnapshot(); - slider.find("[data-index=2]").simulate("click"); - expect(slider.find("div.slick-current").props()["data-index"]).toEqual(2); - expect(beautify_html(slider.html())).toMatchSnapshot(); - }); -}); diff --git a/examples/__tests__/MultipleItems.test.js b/examples/__tests__/MultipleItems.test.js deleted file mode 100644 index 571479960..000000000 --- a/examples/__tests__/MultipleItems.test.js +++ /dev/null @@ -1,169 +0,0 @@ -import React from "react"; -import { mount } from "enzyme"; -import MultipleItems from "../MultipleItems"; -import { html as beautify_html } from "js-beautify"; - -describe("Multiple Items", function() { - it("should have 9 actual slides and (3(pre) + 9(post)) clone slides", function() { - const wrapper = mount(); - expect(wrapper.find(".slick-slide").length).toEqual(21); - expect(wrapper.find(".slick-cloned").length).toEqual(12); - expect(beautify_html(wrapper.html())).toMatchSnapshot(); - }); - it("should have 3 active slides", function() { - const wrapper = mount(); - expect(wrapper.find(".slick-slide.slick-active").length).toEqual(3); - expect(beautify_html(wrapper.html())).toMatchSnapshot(); - }); - it("should have 3 dots", function() { - const wrapper = mount(); - expect(wrapper.find(".slick-dots button").length).toEqual(3); - expect(beautify_html(wrapper.html())).toMatchSnapshot(); - }); - it("should show first 3 slides", function() { - const wrapper = mount(); - expect( - wrapper - .find(".slick-slide.slick-active") - .first() - .text() - ).toEqual("1"); - expect( - wrapper - .find(".slick-slide.slick-active") - .at(1) - .text() - ).toEqual("2"); - expect( - wrapper - .find(".slick-slide.slick-active") - .last() - .text() - ).toEqual("3"); - expect(beautify_html(wrapper.html())).toMatchSnapshot(); - }); - it("should show slides from 4 to 6 when next button is clicked", function() { - const wrapper = mount(); - wrapper.find(".slick-next").simulate("click"); - expect( - wrapper - .find(".slick-slide.slick-active") - .first() - .text() - ).toEqual("4"); - expect( - wrapper - .find(".slick-slide.slick-active") - .at(1) - .text() - ).toEqual("5"); - expect( - wrapper - .find(".slick-slide.slick-active") - .last() - .text() - ).toEqual("6"); - expect(beautify_html(wrapper.html())).toMatchSnapshot(); - }); - it("should show last 3 slides when previous button is clicked", function() { - const wrapper = mount(); - wrapper.find(".slick-prev").simulate("click"); - expect( - wrapper - .find(".slick-slide.slick-active") - .first() - .text() - ).toEqual("7"); - expect( - wrapper - .find(".slick-slide.slick-active") - .at(1) - .text() - ).toEqual("8"); - expect( - wrapper - .find(".slick-slide.slick-active") - .last() - .text() - ).toEqual("9"); - expect(beautify_html(wrapper.html())).toMatchSnapshot(); - }); - it("should show slides first 3 slides when middle dot is clicked", function() { - const wrapper = mount(); - wrapper - .find(".slick-dots button") - .at(0) - .simulate("click"); - expect( - wrapper - .find(".slick-slide.slick-active") - .first() - .text() - ).toEqual("1"); - expect( - wrapper - .find(".slick-slide.slick-active") - .at(1) - .text() - ).toEqual("2"); - expect( - wrapper - .find(".slick-slide.slick-active") - .last() - .text() - ).toEqual("3"); - expect(beautify_html(wrapper.html())).toMatchSnapshot(); - }); - it("should show slides from 4 to 6 when middle dot is clicked", function() { - const wrapper = mount(); - wrapper - .find(".slick-dots button") - .at(1) - .simulate("click"); - expect( - wrapper - .find(".slick-slide.slick-active") - .first() - .text() - ).toEqual("4"); - expect( - wrapper - .find(".slick-slide.slick-active") - .at(1) - .text() - ).toEqual("5"); - expect( - wrapper - .find(".slick-slide.slick-active") - .last() - .text() - ).toEqual("6"); - expect(beautify_html(wrapper.html())).toMatchSnapshot(); - }); - it("should show last 3 slides when last dot is clicked", function() { - const wrapper = mount(); - wrapper - .find(".slick-dots button") - .at(2) - .simulate("click"); - expect( - wrapper - .find(".slick-slide.slick-active") - .first() - .text() - ).toEqual("7"); - expect( - wrapper - .find(".slick-slide.slick-active") - .at(1) - .text() - ).toEqual("8"); - expect( - wrapper - .find(".slick-slide.slick-active") - .last() - .text() - ).toEqual("9"); - expect(beautify_html(wrapper.html())).toMatchSnapshot(); - }); -}); diff --git a/examples/__tests__/SimpleSlider.test.js b/examples/__tests__/SimpleSlider.test.js deleted file mode 100644 index b430bc3c7..000000000 --- a/examples/__tests__/SimpleSlider.test.js +++ /dev/null @@ -1,130 +0,0 @@ -import React from "react"; -import { mount } from "enzyme"; -import SimpleSlider from "../SimpleSlider"; -import { repeatClicks } from "../../test-helpers"; -import { html as beautify_html } from "js-beautify"; - -describe("Simple Slider", function() { - it("should have 13 slides (1(preclone) + 6(actual) + 6(postclone))", function() { - const wrapper = mount(); - expect(wrapper.find(".slick-slide").length).toEqual(13); - }); - it("should have 7 clone slides", function() { - const wrapper = mount(); - expect(wrapper.find(".slick-cloned").length).toEqual(7); - }); - it("should have 1 active slide", function() { - const wrapper = mount(); - expect(wrapper.find(".slick-slide.slick-active").length).toEqual(1); - }); - it("should have 6 dots", function() { - const wrapper = mount(); - expect(wrapper.find(".slick-dots").children().length).toEqual(6); - }); - it("should have 1 active dot", function() { - const wrapper = mount(); - expect(wrapper.find(".slick-dots .slick-active").length).toEqual(1); - }); - it("should have a prev arrow", function() { - const wrapper = mount(); - expect(wrapper.find(".slick-prev").length).toEqual(1); - }); - it("should have a next arrow", function() { - const wrapper = mount(); - expect(wrapper.find(".slick-next").length).toEqual(1); - }); - - it("should got to second slide when next button is clicked", function() { - const wrapper = mount(); - wrapper.find(".slick-next").simulate("click"); - expect( - wrapper - .find(".slick-slide.slick-active") - .first() - .text() - ).toEqual("2"); - expect(wrapper.find(".slick-dots .slick-active").length).toEqual(1); - expect( - wrapper - .find(".slick-dots") - .childAt(1) - .hasClass("slick-active") - ).toEqual(true); - }); - it("should goto last slide when prev button is clicked", function() { - const wrapper = mount(); - wrapper.find(".slick-prev").simulate("click"); - expect( - wrapper - .find(".slick-slide.slick-active") - .first() - .text() - ).toEqual("6"); - expect(wrapper.find(".slick-dots .slick-active").length).toEqual(1); - expect( - wrapper - .find(".slick-dots") - .childAt(5) - .hasClass("slick-active") - ).toEqual(true); - }); - it("should goto 4th slide when 4th dot is clicked", function() { - const wrapper = mount(); - wrapper - .find(".slick-dots button") - .at(3) - .simulate("click"); - expect( - wrapper - .find(".slick-slide.slick-active") - .first() - .text() - ).toEqual("4"); - expect(wrapper.find(".slick-dots .slick-active").length).toEqual(1); - expect( - wrapper - .find(".slick-dots") - .childAt(3) - .hasClass("slick-active") - ).toEqual(true); - }); - // it('should come back to 1st slide after 6 clicks on next button', function () { - // // waitForAnimate option is causing problem for this test - // const wrapper = mount(); - // wrapper.find('.slick-next').first().simulate('click').simulate('click') - // // wrapper.find('.slick-prev').first().simulate('click') - // // wrapper.find('.slick-next').first().simulate('click') - // // console.log(nextButton) - // // nextButton.simulate('click').simulate('click') - // // nextButton.simulate('click') - // // repeatClicks(wrapper.find('.slick-next'), 1) - // expect(wrapper.find('.slick-slide.slick-active').first().text()).toEqual('1'); - // expect(wrapper.find('.slick-dots .slick-active').length).toEqual(1); - // expect(wrapper.find('.slick-dots').childAt(0).hasClass('slick-active')).toEqual(true) - // }) -}); - -describe("Simple Slider Snapshots", function() { - it("slider initial state", function() { - const wrapper = mount(); - expect(beautify_html(wrapper.html())).toMatchSnapshot(); - }); - it("click on next button", function() { - const wrapper = mount(); - wrapper.find(".slick-next").simulate("click"); - expect(beautify_html(wrapper.html())).toMatchSnapshot(); - }); - it("click on prev button", function() { - const wrapper = mount(); - wrapper.find(".slick-prev").simulate("click"); - expect(beautify_html(wrapper.html())).toMatchSnapshot(); - }); - it("click on 3rd dot", function() { - const wrapper = mount(); - wrapper - .find(".slick-dots button") - .at(2) - .simulate("click"); - expect(beautify_html(wrapper.html())).toMatchSnapshot(); - }); -}); diff --git a/examples/__tests__/SlickGoTo.test.js b/examples/__tests__/SlickGoTo.test.js deleted file mode 100644 index 08a88dab5..000000000 --- a/examples/__tests__/SlickGoTo.test.js +++ /dev/null @@ -1,36 +0,0 @@ -import React from "react"; -import { mount } from "enzyme"; -import SlickGoTo from "../SlickGoTo"; - -describe.skip("SlickGoTo", () => { - it("should goto 2nd slide", () => { - const wrapper = mount(); - wrapper.find("input").simulate("change", { target: { value: 1 } }); - expect(wrapper.find(".slick-slide.slick-active img").props().src).toEqual( - "/img/react-slick/abstract02.jpg" - ); - }); - it("should goto 2nd slide, even if input is number in string format", () => { - const wrapper = mount(); - wrapper.find("input").simulate("change", { target: { value: "1" } }); - expect(wrapper.find(".slick-slide.slick-active img").props().src).toEqual( - "/img/react-slick/abstract02.jpg" - ); - }); - it("should remain at 1st slide", () => { - const wrapper = mount(); - wrapper.find("input").simulate("change", { target: { value: 0 } }); - expect(wrapper.find(".slick-slide.slick-active img").props().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 = mount(); - 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" - ); - }); -}); diff --git a/examples/__tests__/UnevenSets.test.js b/examples/__tests__/UnevenSets.test.js deleted file mode 100644 index 1c47291ff..000000000 --- a/examples/__tests__/UnevenSets.test.js +++ /dev/null @@ -1,125 +0,0 @@ -import React from "react"; -import { mount } from "enzyme"; -import UnevenSetsFinite from "../UnevenSetsFinite"; -import UnevenSetsInfinite from "../UnevenSetsInfinite"; -import { html as beautify_html } from "js-beautify"; -import { clickNext } from "../../__tests__/testUtils"; - -describe("UnevenSets Finite", () => { - test("Counting test", () => { - const slider = mount(); - let totalSlides = slider.find(".slick-slide").length; - let clonedSlides = slider.find(".slick-cloned").length; - let activeSlides = slider.find(".slick-slide.slick-active").length; - let dots = slider.find(".slick-dots").children().length; - expect(totalSlides).toEqual(6); - expect(clonedSlides).toEqual(0); - expect(activeSlides).toEqual(4); - expect(dots).toEqual(2); - expect(beautify_html(slider.html())).toMatchSnapshot(); - }); - test("Positioning test", () => { - const slider = mount(); - let currentSlide = slider.find("div.slick-current"); - let activeSlides = slider.find("div.slick-active"); - expect(currentSlide.props()["data-index"]).toEqual(0); - expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([ - 0, - 1, - 2, - 3 - ]); - expect(beautify_html(slider.html())).toMatchSnapshot(); - }); - test("Activity test", () => { - const slider = mount(); - let currentSlide = slider.find("div.slick-current"); - let activeSlides = slider.find("div.slick-active"); - expect(currentSlide.props()["data-index"]).toEqual(0); - expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([ - 0, - 1, - 2, - 3 - ]); - - clickNext(slider); - - currentSlide = slider.find("div.slick-current"); - activeSlides = slider.find("div.slick-active"); - expect(currentSlide.props()["data-index"]).toEqual(4); - expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([ - 2, - 3, - 4, - 5 - ]); - - clickNext(slider); - - currentSlide = slider.find("div.slick-current"); - activeSlides = slider.find("div.slick-active"); - expect(currentSlide.props()["data-index"]).toEqual(4); - expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([ - 2, - 3, - 4, - 5 - ]); - - expect(beautify_html(slider.html())).toMatchSnapshot(); - }); -}); - -describe("UnevenSets Infinite", () => { - test("Counting test", () => { - const slider = mount(); - let totalSlides = slider.find(".slick-slide").length; - let clonedSlides = slider.find(".slick-cloned").length; - let activeSlides = slider.find(".slick-slide.slick-active").length; - let dots = slider.find(".slick-dots").children().length; - expect(totalSlides).toEqual(16); - expect(clonedSlides).toEqual(10); - expect(activeSlides).toEqual(4); - expect(dots).toEqual(2); - expect(beautify_html(slider.html())).toMatchSnapshot(); - }); - test("Positioning test", () => { - const slider = mount(); - let currentSlide = slider.find("div.slick-current"); - let activeSlides = slider.find("div.slick-active"); - expect(currentSlide.props()["data-index"]).toEqual(0); - expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([ - 0, - 1, - 2, - 3 - ]); - expect(beautify_html(slider.html())).toMatchSnapshot(); - }); - test("Activity test", () => { - const slider = mount(); - let currentSlide = slider.find("div.slick-current"); - let activeSlides = slider.find("div.slick-active"); - expect(currentSlide.props()["data-index"]).toEqual(0); - expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([ - 0, - 1, - 2, - 3 - ]); - - clickNext(slider); - - currentSlide = slider.find("div.slick-current"); - activeSlides = slider.find("div.slick-active"); - expect(currentSlide.props()["data-index"]).toEqual(4); - expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([ - 4, - 5, - 6, - 7 - ]); - expect(beautify_html(slider.html())).toMatchSnapshot(); - }); -}); diff --git a/examples/__tests__/__snapshots__/CenterMode.test.js.snap b/examples/__tests__/__snapshots__/CenterMode.test.js.snap deleted file mode 100644 index cf1b20d1b..000000000 --- a/examples/__tests__/__snapshots__/CenterMode.test.js.snap +++ /dev/null @@ -1,373 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`CenterMode Tests Activity test 1`] = ` -"
-

Center Mode

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-
" -`; - -exports[`CenterMode Tests Counting test 1`] = ` -"
-

Center Mode

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-
" -`; - -exports[`CenterMode Tests Positioning test 1`] = ` -"
-

Center Mode

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-
" -`; diff --git a/examples/__tests__/__snapshots__/FocusOnSelect.test.js.snap b/examples/__tests__/__snapshots__/FocusOnSelect.test.js.snap deleted file mode 100644 index 181930df8..000000000 --- a/examples/__tests__/__snapshots__/FocusOnSelect.test.js.snap +++ /dev/null @@ -1,237 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`FocusOnSelect Tests Activity Test 1`] = ` -"
-

FocusOnSelect

-
Click on any slide to select and make it current slide
-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-
" -`; - -exports[`FocusOnSelect Tests Activity Test 2`] = ` -"
-

FocusOnSelect

-
Click on any slide to select and make it current slide
-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-
" -`; diff --git a/examples/__tests__/__snapshots__/MultipleItems.test.js.snap b/examples/__tests__/__snapshots__/MultipleItems.test.js.snap deleted file mode 100644 index 7e4aabd01..000000000 --- a/examples/__tests__/__snapshots__/MultipleItems.test.js.snap +++ /dev/null @@ -1,1477 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Multiple Items should have 3 active slides 1`] = ` -"
-

Multiple items

-
-
-
-
-
-
-

7

-
-
-
-
-
-
-

8

-
-
-
-
-
-
-

9

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

7

-
-
-
-
-
-
-

8

-
-
-
-
-
-
-

9

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

7

-
-
-
-
-
-
-

8

-
-
-
-
-
-
-

9

-
-
-
-
-
-
    -
  • -
  • -
  • -
-
-
" -`; - -exports[`Multiple Items should have 3 dots 1`] = ` -"
-

Multiple items

-
-
-
-
-
-
-

7

-
-
-
-
-
-
-

8

-
-
-
-
-
-
-

9

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

7

-
-
-
-
-
-
-

8

-
-
-
-
-
-
-

9

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

7

-
-
-
-
-
-
-

8

-
-
-
-
-
-
-

9

-
-
-
-
-
-
    -
  • -
  • -
  • -
-
-
" -`; - -exports[`Multiple Items should have 9 actual slides and (3(pre) + 9(post)) clone slides 1`] = ` -"
-

Multiple items

-
-
-
-
-
-
-

7

-
-
-
-
-
-
-

8

-
-
-
-
-
-
-

9

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

7

-
-
-
-
-
-
-

8

-
-
-
-
-
-
-

9

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

7

-
-
-
-
-
-
-

8

-
-
-
-
-
-
-

9

-
-
-
-
-
-
    -
  • -
  • -
  • -
-
-
" -`; - -exports[`Multiple Items should show first 3 slides 1`] = ` -"
-

Multiple items

-
-
-
-
-
-
-

7

-
-
-
-
-
-
-

8

-
-
-
-
-
-
-

9

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

7

-
-
-
-
-
-
-

8

-
-
-
-
-
-
-

9

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

7

-
-
-
-
-
-
-

8

-
-
-
-
-
-
-

9

-
-
-
-
-
-
    -
  • -
  • -
  • -
-
-
" -`; - -exports[`Multiple Items should show last 3 slides when last dot is clicked 1`] = ` -"
-

Multiple items

-
-
-
-
-
-
-

7

-
-
-
-
-
-
-

8

-
-
-
-
-
-
-

9

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

7

-
-
-
-
-
-
-

8

-
-
-
-
-
-
-

9

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

7

-
-
-
-
-
-
-

8

-
-
-
-
-
-
-

9

-
-
-
-
-
-
    -
  • -
  • -
  • -
-
-
" -`; - -exports[`Multiple Items should show last 3 slides when previous button is clicked 1`] = ` -"
-

Multiple items

-
-
-
-
-
-
-

7

-
-
-
-
-
-
-

8

-
-
-
-
-
-
-

9

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

7

-
-
-
-
-
-
-

8

-
-
-
-
-
-
-

9

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

7

-
-
-
-
-
-
-

8

-
-
-
-
-
-
-

9

-
-
-
-
-
-
    -
  • -
  • -
  • -
-
-
" -`; - -exports[`Multiple Items should show slides first 3 slides when middle dot is clicked 1`] = ` -"
-

Multiple items

-
-
-
-
-
-
-

7

-
-
-
-
-
-
-

8

-
-
-
-
-
-
-

9

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

7

-
-
-
-
-
-
-

8

-
-
-
-
-
-
-

9

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

7

-
-
-
-
-
-
-

8

-
-
-
-
-
-
-

9

-
-
-
-
-
-
    -
  • -
  • -
  • -
-
-
" -`; - -exports[`Multiple Items should show slides from 4 to 6 when middle dot is clicked 1`] = ` -"
-

Multiple items

-
-
-
-
-
-
-

7

-
-
-
-
-
-
-

8

-
-
-
-
-
-
-

9

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

7

-
-
-
-
-
-
-

8

-
-
-
-
-
-
-

9

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

7

-
-
-
-
-
-
-

8

-
-
-
-
-
-
-

9

-
-
-
-
-
-
    -
  • -
  • -
  • -
-
-
" -`; - -exports[`Multiple Items should show slides from 4 to 6 when next button is clicked 1`] = ` -"
-

Multiple items

-
-
-
-
-
-
-

7

-
-
-
-
-
-
-

8

-
-
-
-
-
-
-

9

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

7

-
-
-
-
-
-
-

8

-
-
-
-
-
-
-

9

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

7

-
-
-
-
-
-
-

8

-
-
-
-
-
-
-

9

-
-
-
-
-
-
    -
  • -
  • -
  • -
-
-
" -`; diff --git a/examples/__tests__/__snapshots__/SimpleSlider.test.js.snap b/examples/__tests__/__snapshots__/SimpleSlider.test.js.snap deleted file mode 100644 index 08be35767..000000000 --- a/examples/__tests__/__snapshots__/SimpleSlider.test.js.snap +++ /dev/null @@ -1,445 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Simple Slider Snapshots click on 3rd dot 1`] = ` -"
-

Single Item

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
    -
  • -
  • -
  • -
  • -
  • -
  • -
-
-
" -`; - -exports[`Simple Slider Snapshots click on next button 1`] = ` -"
-

Single Item

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
    -
  • -
  • -
  • -
  • -
  • -
  • -
-
-
" -`; - -exports[`Simple Slider Snapshots click on prev button 1`] = ` -"
-

Single Item

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
    -
  • -
  • -
  • -
  • -
  • -
  • -
-
-
" -`; - -exports[`Simple Slider Snapshots slider initial state 1`] = ` -"
-

Single Item

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
    -
  • -
  • -
  • -
  • -
  • -
  • -
-
-
" -`; diff --git a/examples/__tests__/__snapshots__/UnevenSets.test.js.snap b/examples/__tests__/__snapshots__/UnevenSets.test.js.snap deleted file mode 100644 index b1dacdf75..000000000 --- a/examples/__tests__/__snapshots__/UnevenSets.test.js.snap +++ /dev/null @@ -1,559 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`UnevenSets Finite Activity test 1`] = ` -"
-

Uneven sets (finite)

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
    -
  • -
  • -
-
-
" -`; - -exports[`UnevenSets Finite Counting test 1`] = ` -"
-

Uneven sets (finite)

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
    -
  • -
  • -
-
-
" -`; - -exports[`UnevenSets Finite Positioning test 1`] = ` -"
-

Uneven sets (finite)

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
    -
  • -
  • -
-
-
" -`; - -exports[`UnevenSets Infinite Activity test 1`] = ` -"
-

Uneven sets (infinite)

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
    -
  • -
  • -
-
-
" -`; - -exports[`UnevenSets Infinite Counting test 1`] = ` -"
-

Uneven sets (infinite)

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
    -
  • -
  • -
-
-
" -`; - -exports[`UnevenSets Infinite Positioning test 1`] = ` -"
-

Uneven sets (infinite)

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
-

1

-
-
-
-
-
-
-

2

-
-
-
-
-
-
-

3

-
-
-
-
-
-
-

4

-
-
-
-
-
-
-

5

-
-
-
-
-
-
-

6

-
-
-
-
-
-
    -
  • -
  • -
-
-
" -`; diff --git a/examples/__tests__/sample.test.js b/examples/__tests__/sample.test.js deleted file mode 100644 index 4a17f8ea0..000000000 --- a/examples/__tests__/sample.test.js +++ /dev/null @@ -1,26 +0,0 @@ -import React from "react"; -import { mount } from "enzyme"; - -export default class Counter extends React.Component { - constructor(props) { - super(props); - this.state = { - count: 0 - }; - } - render() { - return ( - - ); - } -} - -describe("sample counter test", function() { - it("mutliple counts", function() { - const wrapper = mount(); - wrapper.simulate("click").simulate("click"); - expect(wrapper.text()).toEqual("Count 2"); - }); -}); diff --git a/package.json b/package.json index 938ff8cd4..e7c92d77d 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,6 @@ "lib": "babel ./src --out-dir ./lib", "build": "npm run lib && gulp dist", "prepublish": "npm run build", - "test": "npm run lint && jest", - "test:watch": "jest --watch", "lint": "eslint src", "gen": "node examples/scripts/generateExampleConfigs.js && node examples/scripts/generateExamples.js && xdg-open docs/jquery.html", "precommit": "lint-staged" @@ -50,8 +48,6 @@ "css-loader": "^2.1.1", "deepmerge": "^1.1.0", "del": "^2.2.2", - "enzyme": "^3.2.0", - "enzyme-adapter-react-16": "^1.1.0", "es5-shim": "^4.5.9", "eslint": "^8.4.1", "eslint-plugin-import": "^2.25.3", @@ -60,9 +56,6 @@ "foundation-apps": "^1.2.0", "gulp": "^4.0.0", "husky": "^0.14.3", - "jasmine-core": "^2.5.2", - "jest": "^24.8.0", - "jquery": "^3.2.1", "js-beautify": "^1.7.5", "json-loader": "^0.5.4", "lint-staged": "^12.1.2", @@ -72,7 +65,6 @@ "raf": "^3.4.0", "react": "^18.0.0", "react-dom": "^18.0.0", - "react-test-renderer": "^18.0.0", "sinon": "^2.1.0", "slick-carousel": "^1.8.1", "style-loader": "^0.16.1", @@ -93,15 +85,6 @@ "react": "^0.14.0 || ^15.0.1 || ^16.0.0 || ^17.0.0 || ^18.0.0", "react-dom": "^0.14.0 || ^15.0.1 || ^16.0.0 || ^17.0.0 || ^18.0.0" }, - "jest": { - "setupFiles": [ - "./test-setup.js" - ], - "testPathIgnorePatterns": [ - "/__tests__/scripts.js", - "/__tests__/testUtils.js" - ] - }, "lint-staged": { "*.{js,json,md}": [ "prettier --write", diff --git a/test-helpers.js b/test-helpers.js deleted file mode 100644 index a778a0eca..000000000 --- a/test-helpers.js +++ /dev/null @@ -1,11 +0,0 @@ -export function repeatClicks(node, count) { - for (let i = 0; i < count; i++) { - node.simulate("click"); - } -} - -export function delay(duration) { - return new Promise(function(resolve) { - setTimeout(resolve, duration); - }); -} diff --git a/test-setup.js b/test-setup.js deleted file mode 100644 index 7f4f7b011..000000000 --- a/test-setup.js +++ /dev/null @@ -1,23 +0,0 @@ -import "core-js/es6/map"; -import "core-js/es6/set"; -import "raf/polyfill"; - -import Enzyme from "enzyme"; -import Adapter from "enzyme-adapter-react-16"; - -Enzyme.configure({ adapter: new Adapter() }); -window.matchMedia = - window.matchMedia || - function() { - return { - matches: false, - addListener: function() {}, - removeListener: function() {} - }; - }; - -window.requestAnimationFrame = - window.requestAnimationFrame || - function(callback) { - setTimeout(callback, 0); - }; From 472c848e0159d0813037d61177574ac6959103b6 Mon Sep 17 00:00:00 2001 From: akiran Date: Tue, 26 Jul 2022 20:14:00 +0530 Subject: [PATCH 09/58] test setup with testing library --- examples/__tests__/SimpleSlider.test.js | 10 ++++++++++ jest.config.js | 4 ++++ package.json | 8 +++++++- test-setup.js | 12 ++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 examples/__tests__/SimpleSlider.test.js create mode 100644 jest.config.js create mode 100644 test-setup.js diff --git a/examples/__tests__/SimpleSlider.test.js b/examples/__tests__/SimpleSlider.test.js new file mode 100644 index 000000000..db195bb74 --- /dev/null +++ b/examples/__tests__/SimpleSlider.test.js @@ -0,0 +1,10 @@ +import React from "react"; +import SimpleSlider from "../SimpleSlider"; +import { render, fireEvent, waitFor, screen } from "@testing-library/react"; + +describe("SimpleSlider example", () => { + test("render", () => { + const { container } = render(); + expect(container.getElementsByClassName("slick-slide").length).toBe(13); + }); +}); diff --git a/jest.config.js b/jest.config.js new file mode 100644 index 000000000..4973d7e41 --- /dev/null +++ b/jest.config.js @@ -0,0 +1,4 @@ +module.exports = { + testEnvironment: "jsdom", + setupFilesAfterEnv: ["/test-setup.js"] +}; diff --git a/package.json b/package.json index e7c92d77d..ee96a1981 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,9 @@ "prepublish": "npm run build", "lint": "eslint src", "gen": "node examples/scripts/generateExampleConfigs.js && node examples/scripts/generateExamples.js && xdg-open docs/jquery.html", - "precommit": "lint-staged" + "precommit": "lint-staged", + "test": "jest", + "test-watch": "jest --watch" }, "author": "Kiran Abburi", "license": "MIT", @@ -40,6 +42,8 @@ "@babel/polyfill": "^7.0.0", "@babel/preset-env": "^7.1.0", "@babel/preset-react": "^7.0.0", + "@testing-library/jest-dom": "^5.16.4", + "@testing-library/react": "^13.3.0", "autoprefixer": "^7.1.2", "babel-core": "^7.0.0-bridge.0", "babel-jest": "^24.8.0", @@ -56,6 +60,8 @@ "foundation-apps": "^1.2.0", "gulp": "^4.0.0", "husky": "^0.14.3", + "jest": "^28.1.3", + "jest-environment-jsdom": "^28.1.3", "js-beautify": "^1.7.5", "json-loader": "^0.5.4", "lint-staged": "^12.1.2", diff --git a/test-setup.js b/test-setup.js new file mode 100644 index 000000000..544d67a38 --- /dev/null +++ b/test-setup.js @@ -0,0 +1,12 @@ +import "@testing-library/jest-dom/extend-expect"; + +//Fix for "matchMedia not present, legacy browsers require a polyfill jest" error +window.matchMedia = + window.matchMedia || + function() { + return { + matches: false, + addListener: function() {}, + removeListener: function() {} + }; + }; From 4e6250b953ee74870583b8ef3c434db6438c6292 Mon Sep 17 00:00:00 2001 From: akiran Date: Wed, 27 Jul 2022 00:05:48 +0530 Subject: [PATCH 10/58] wrote tests for basic slider example --- examples/__tests__/SimpleSlider.test.js | 54 ++++++++++++++++++++++++- package.json | 1 + 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/examples/__tests__/SimpleSlider.test.js b/examples/__tests__/SimpleSlider.test.js index db195bb74..dec3390dc 100644 --- a/examples/__tests__/SimpleSlider.test.js +++ b/examples/__tests__/SimpleSlider.test.js @@ -3,8 +3,60 @@ import SimpleSlider from "../SimpleSlider"; import { render, fireEvent, waitFor, screen } from "@testing-library/react"; describe("SimpleSlider example", () => { - test("render", () => { + it("should have 13 slides (1(preclone) + 6(actual) + 6(postclone))", function() { const { container } = render(); expect(container.getElementsByClassName("slick-slide").length).toBe(13); }); + it("should have 7 clone slides", function() { + const { container } = render(); + + expect(container.getElementsByClassName("slick-cloned").length).toBe(7); + }); + it("should have 1 active slide", function() { + const { container } = render(); + expect(container.querySelectorAll(".slick-slide.slick-active").length).toBe( + 1 + ); + }); + it("should have 6 dots", function() { + const { container } = render(); + expect( + container.getElementsByClassName("slick-dots")[0].children.length + ).toBe(6); + }); + it("should have 1 active dot", function() { + const { container } = render(); + expect(container.querySelectorAll(".slick-dots .slick-active").length).toBe( + 1 + ); + }); + it("should have a prev arrow", function() { + const { container } = render(); + expect(container.getElementsByClassName("slick-prev").length).toBe(1); + }); + it("should have a next arrow", function() { + const { container } = render(); + expect(container.getElementsByClassName("slick-next").length).toBe(1); + }); + it("should got to second slide when next button is clicked", function() { + const { container } = render(); + fireEvent( + container.getElementsByClassName("slick-next")[0], + new MouseEvent("click", { + bubbles: true, + cancelable: true + }) + ); + expect( + container.querySelectorAll(".slick-slide.slick-active")[0].textContent + ).toBe("2"); + expect(container.querySelectorAll(".slick-dots .slick-active").length).toBe( + 1 + ); + expect( + container + .querySelectorAll(".slick-dots")[0] + .children[1].classList.contains("slick-active") + ).toBe(true); + }); }); diff --git a/package.json b/package.json index ee96a1981..95be2dfe2 100644 --- a/package.json +++ b/package.json @@ -81,6 +81,7 @@ "why-did-you-update": "^0.1.1" }, "dependencies": { + "@testing-library/user-event": "^14.3.0", "classnames": "^2.2.5", "enquire.js": "^2.1.6", "json2mq": "^0.2.0", From 19b770e939f6352f766fdbbf1fbef594764b62ce Mon Sep 17 00:00:00 2001 From: Kiran Abburi Date: Sun, 21 Aug 2022 21:11:07 +0530 Subject: [PATCH 11/58] Update README.md --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 5a2ff3872..c65078cd4 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ### 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) [![Join the chat at https://gitter.im/akiran/react-slick](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/akiran/react-slick?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) +[![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) [![Join the chat at https://gitter.im/akiran/react-slick] ##### Carousel component built with React. It is a react port of [slick carousel](http://kenwheeler.github.io/slick/) @@ -107,6 +107,11 @@ npm start open http://localhost:8080 ``` +## Community + +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) From b9302d687ac85f1eaac9c971d9391aeb83b963a4 Mon Sep 17 00:00:00 2001 From: Kiran Abburi Date: Sun, 21 Aug 2022 21:11:34 +0530 Subject: [PATCH 12/58] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index c65078cd4..c5e654e5b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ ### 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) [![Join the chat at https://gitter.im/akiran/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) ##### Carousel component built with React. It is a react port of [slick carousel](http://kenwheeler.github.io/slick/) From 89d1e896ca8974e3ca2ae3c94a5b66882b81a171 Mon Sep 17 00:00:00 2001 From: Pedro Zaccaria Date: Sat, 15 Oct 2022 11:27:50 -0300 Subject: [PATCH 13/58] Fixed broken link from CONTRIBUTING.md --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 8988e69a1..e9ff889b4 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -13,7 +13,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 From 7035d84ba24c98ba092d1c5a48c820662fcd9192 Mon Sep 17 00:00:00 2001 From: akiran Date: Mon, 15 May 2023 11:16:47 +0530 Subject: [PATCH 14/58] tests init --- examples/__tests__/SimpleSlider.test.js | 17 +++------- test-utils.js | 42 +++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 12 deletions(-) create mode 100644 test-utils.js diff --git a/examples/__tests__/SimpleSlider.test.js b/examples/__tests__/SimpleSlider.test.js index dec3390dc..faac1e299 100644 --- a/examples/__tests__/SimpleSlider.test.js +++ b/examples/__tests__/SimpleSlider.test.js @@ -1,6 +1,7 @@ import React from "react"; import SimpleSlider from "../SimpleSlider"; import { render, fireEvent, waitFor, screen } from "@testing-library/react"; +import { clickNext } from "../../test-utils"; describe("SimpleSlider example", () => { it("should have 13 slides (1(preclone) + 6(actual) + 6(postclone))", function() { @@ -9,7 +10,6 @@ describe("SimpleSlider example", () => { }); it("should have 7 clone slides", function() { const { container } = render(); - expect(container.getElementsByClassName("slick-cloned").length).toBe(7); }); it("should have 1 active slide", function() { @@ -17,6 +17,7 @@ describe("SimpleSlider example", () => { expect(container.querySelectorAll(".slick-slide.slick-active").length).toBe( 1 ); + expect(activeSlide(container)).toBe(0); }); it("should have 6 dots", function() { const { container } = render(); @@ -40,13 +41,7 @@ describe("SimpleSlider example", () => { }); it("should got to second slide when next button is clicked", function() { const { container } = render(); - fireEvent( - container.getElementsByClassName("slick-next")[0], - new MouseEvent("click", { - bubbles: true, - cancelable: true - }) - ); + clickNext(container); expect( container.querySelectorAll(".slick-slide.slick-active")[0].textContent ).toBe("2"); @@ -54,9 +49,7 @@ describe("SimpleSlider example", () => { 1 ); expect( - container - .querySelectorAll(".slick-dots")[0] - .children[1].classList.contains("slick-active") - ).toBe(true); + container.querySelectorAll(".slick-dots")[0].children[1] + ).toHaveClass("slick-active"); }); }); diff --git a/test-utils.js b/test-utils.js new file mode 100644 index 000000000..923d9d53b --- /dev/null +++ b/test-utils.js @@ -0,0 +1,42 @@ +import { render, fireEvent, waitFor, screen } from "@testing-library/react"; + +export function getSlidesCount(container) { + return container.getElementsByClassName("slick-slide").length; +} + +export function getClonesCount(container) { + return container.getElementsByClassName("slick-cloned").length; +} + +export function getActiveSlidesCount(container) { + return container.querySelectorAll(".slick-slide.slick-active").length; +} + +export function getActiveSlides(container) { + return container.querySelectorAll(".slick-slide.slick-active"); +} + +export function getActiveSlidesText(container) { + const slides = activeSlides(container); + return Array.from(slides).map(e => e.textContent); +} + +export function clickNext(container) { + fireEvent( + container.getElementsByClassName("slick-next")[0], + new MouseEvent("click", { + bubbles: true, + cancelable: true + }) + ); +} + +export function clickPrevious(container) { + fireEvent( + container.getElementsByClassName("slick-prev")[0], + new MouseEvent("click", { + bubbles: true, + cancelable: true + }) + ); +} From 0711da92cb23f31ee4b98fb6bc2d04e159d5c602 Mon Sep 17 00:00:00 2001 From: Pratyush Bhatnagar <38534434+pratyushbh@users.noreply.github.com> Date: Mon, 15 May 2023 17:46:20 +0530 Subject: [PATCH 15/58] completed the simpleslider test and started centerMode test --- examples/__tests__/CentreMode.test.js | 62 +++++++++++++++++ examples/__tests__/SimpleSlider.test.js | 67 ++++++++++++++++++- .../__snapshots__/CentreMode.test.js.snap | 3 + .../__snapshots__/SimpleSlider.test.js.snap | 9 +++ test-utils.js | 23 +++++++ 5 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 examples/__tests__/CentreMode.test.js create mode 100644 examples/__tests__/__snapshots__/CentreMode.test.js.snap create mode 100644 examples/__tests__/__snapshots__/SimpleSlider.test.js.snap diff --git a/examples/__tests__/CentreMode.test.js b/examples/__tests__/CentreMode.test.js new file mode 100644 index 000000000..a12a6faf4 --- /dev/null +++ b/examples/__tests__/CentreMode.test.js @@ -0,0 +1,62 @@ +import React from "react"; +import CenterMode from "../CenterMode"; +import { render, fireEvent, waitFor, screen } from "@testing-library/react"; +import { html as beautify_html } from "js-beautify"; +import { + activeSlides, + getActiveSlidesCount, + getClonesCount, + getCurrentSlide, + getSlidesCount +} from "../../test-utils"; + +describe("CenterMode Tests", () => { + test("Counting test", () => { + const { container } = render(); + let totalSlides = getSlidesCount(container); + let clonedSlides = getClonesCount(container); + let activeSlides = getActiveSlidesCount(container); + expect(totalSlides).toEqual(16); + expect(clonedSlides).toEqual(10); + expect(activeSlides).toEqual(3); + expect(beautify_html(toString(container))).toMatchSnapshot(); + }); + test("Positioning test", () => { + const { container } = render(); + let currentSlide = getCurrentSlide(container); + console.log(currentSlide[0]); + // Array.from(currentSlide).map(e=>console.log(e)) + //let activeSlides = activeSlides(container); + expect(currentSlide.props()["data-index"]).toEqual(0); + // expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([ + // -1, + // 0, + // 1 + // ]); + // expect(beautify_html(slider.html())).toMatchSnapshot(); + }); + // test("Activity test", () => { + // const slider = mount(); + // let currentSlide = slider.find("div.slick-current"); + // let activeSlides = slider.find("div.slick-active"); + // expect(currentSlide.props()["data-index"]).toEqual(0); + // expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([ + // -1, + // 0, + // 1 + // ]); + + // clickNext(slider); + + // currentSlide = slider.find("div.slick-current"); + // activeSlides = slider.find("div.slick-active"); + // expect(currentSlide.props()["data-index"]).toEqual(1); + // expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([ + // 0, + // 1, + // 2 + // ]); + + // expect(beautify_html(slider.html())).toMatchSnapshot(); + // }); +}); diff --git a/examples/__tests__/SimpleSlider.test.js b/examples/__tests__/SimpleSlider.test.js index faac1e299..582fd1e84 100644 --- a/examples/__tests__/SimpleSlider.test.js +++ b/examples/__tests__/SimpleSlider.test.js @@ -1,7 +1,17 @@ import React from "react"; import SimpleSlider from "../SimpleSlider"; import { render, fireEvent, waitFor, screen } from "@testing-library/react"; -import { clickNext } from "../../test-utils"; +import { html as beautify_html } from "js-beautify"; +import { + activeSlide, + clickNext, + clickPrevious, + hasClass, + getActiveSlides, + getActiveSlidesCount, + getActiveSlidesText, + getButtons +} from "../../test-utils"; describe("SimpleSlider example", () => { it("should have 13 slides (1(preclone) + 6(actual) + 6(postclone))", function() { @@ -27,6 +37,7 @@ describe("SimpleSlider example", () => { }); it("should have 1 active dot", function() { const { container } = render(); + expect(container.querySelectorAll(".slick-dots .slick-active").length).toBe( 1 ); @@ -52,4 +63,58 @@ describe("SimpleSlider example", () => { container.querySelectorAll(".slick-dots")[0].children[1] ).toHaveClass("slick-active"); }); + it("should goto last slide when prev button is clicked", function() { + const { container } = render(); + clickPrevious(container); + expect( + container.querySelectorAll(".slick-slide.slick-active")[0].textContent + ).toBe("6"); + expect(container.querySelectorAll(".slick-dots .slick-active").length).toBe( + 1 + ); + expect( + container.querySelectorAll(".slick-dots")[0].children[5] + ).toHaveClass("slick-active"); + }); + it("should goto 4th slide when 4th dot is clicked", function() { + const { container } = render(); + fireEvent( + container.querySelectorAll(".slick-dots button")[3], + new MouseEvent("click", { + bubbles: true, + cancelable: true + }) + ); + expect(getActiveSlidesText(container)[0]).toEqual("4"); + expect(getActiveSlidesCount(container)).toEqual(1); + expect(hasClass(getButtons(container)[3], "slick-active")).toEqual(true); + }); +}); + +describe("Simple Slider Snapshots", function() { + it("slider initial state", function() { + const { container } = render(); + expect(beautify_html(toString(container))).toMatchSnapshot(); + }); + it("click on next button", function() { + const { container } = render(); + clickNext(container); + expect(beautify_html(toString(container))).toMatchSnapshot(); + }); + it("click on prev button", function() { + const { container } = render(); + clickPrevious(container); + expect(beautify_html(toString(container))).toMatchSnapshot(); + }); + it("click on 3rd dot", function() { + const { container } = render(); + fireEvent( + container.querySelectorAll(".slick-dots button")[2], + new MouseEvent("click", { + bubbles: true, + cancelable: true + }) + ); + expect(beautify_html(toString(container))).toMatchSnapshot(); + }); }); diff --git a/examples/__tests__/__snapshots__/CentreMode.test.js.snap b/examples/__tests__/__snapshots__/CentreMode.test.js.snap new file mode 100644 index 000000000..0a8ce7eb4 --- /dev/null +++ b/examples/__tests__/__snapshots__/CentreMode.test.js.snap @@ -0,0 +1,3 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`CenterMode Tests Counting test 1`] = `"[object Undefined]"`; diff --git a/examples/__tests__/__snapshots__/SimpleSlider.test.js.snap b/examples/__tests__/__snapshots__/SimpleSlider.test.js.snap new file mode 100644 index 000000000..a041ca679 --- /dev/null +++ b/examples/__tests__/__snapshots__/SimpleSlider.test.js.snap @@ -0,0 +1,9 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Simple Slider Snapshots click on 3rd dot 1`] = `"[object Undefined]"`; + +exports[`Simple Slider Snapshots click on next button 1`] = `"[object Undefined]"`; + +exports[`Simple Slider Snapshots click on prev button 1`] = `"[object Undefined]"`; + +exports[`Simple Slider Snapshots slider initial state 1`] = `"[object Undefined]"`; diff --git a/test-utils.js b/test-utils.js index 923d9d53b..10590d637 100644 --- a/test-utils.js +++ b/test-utils.js @@ -12,6 +12,29 @@ export function getActiveSlidesCount(container) { return container.querySelectorAll(".slick-slide.slick-active").length; } +export function getCurrentSlide(container) { + return container.querySelectorAll(".slick-current"); +} + +export function getButtons(container) { + return container.querySelectorAll(".slick-dots")[0].children; +} + +export function hasClass(element, classname) { + if (element.className != undefined) { + return element.className == classname; + } + return false; +} +export function activeSlides(container) { + return container.querySelectorAll(".slick-dots .slick-active"); +} +export function activeSlide(container) { + return Array.from( + container.querySelectorAll(".slick-dots .slick-active")[0].children + ).map(e => parseInt(e.textContent) - 1)[0]; +} + export function getActiveSlides(container) { return container.querySelectorAll(".slick-slide.slick-active"); } From c4f6fdea8b374fd3628fdce29e7d13f596559121 Mon Sep 17 00:00:00 2001 From: Pratyush Bhatnagar <38534434+pratyushbh@users.noreply.github.com> Date: Tue, 16 May 2023 16:05:10 +0530 Subject: [PATCH 16/58] migrated all the test of examples from enezyme to react-testing-library --- examples/__tests__/CentreMode.test.js | 60 ++++----- examples/__tests__/Fade.js | 18 +++ examples/__tests__/FocusOnSelect.test.js | 33 +++++ examples/__tests__/MultipleItems.test.js | 89 ++++++++++++++ examples/__tests__/SimpleSlider.test.js | 15 ++- examples/__tests__/SlickGoTo.test.js | 52 ++++++++ examples/__tests__/UnevenSets.test.js | 115 ++++++++++++++++++ .../__snapshots__/CentreMode.test.js.snap | 4 + .../__snapshots__/FocusOnSelect.test.js.snap | 5 + .../__snapshots__/MultipleItems.test.js.snap | 19 +++ .../__snapshots__/UnevenSets.test.js.snap | 13 ++ examples/__tests__/sample.test.js | 40 ++++++ test-utils.js | 16 ++- 13 files changed, 435 insertions(+), 44 deletions(-) create mode 100644 examples/__tests__/Fade.js create mode 100644 examples/__tests__/FocusOnSelect.test.js create mode 100644 examples/__tests__/MultipleItems.test.js create mode 100644 examples/__tests__/SlickGoTo.test.js create mode 100644 examples/__tests__/UnevenSets.test.js create mode 100644 examples/__tests__/__snapshots__/FocusOnSelect.test.js.snap create mode 100644 examples/__tests__/__snapshots__/MultipleItems.test.js.snap create mode 100644 examples/__tests__/__snapshots__/UnevenSets.test.js.snap create mode 100644 examples/__tests__/sample.test.js diff --git a/examples/__tests__/CentreMode.test.js b/examples/__tests__/CentreMode.test.js index a12a6faf4..3a3b687b2 100644 --- a/examples/__tests__/CentreMode.test.js +++ b/examples/__tests__/CentreMode.test.js @@ -1,13 +1,14 @@ import React from "react"; import CenterMode from "../CenterMode"; -import { render, fireEvent, waitFor, screen } from "@testing-library/react"; +import { render } from "@testing-library/react"; import { html as beautify_html } from "js-beautify"; import { activeSlides, getActiveSlidesCount, getClonesCount, getCurrentSlide, - getSlidesCount + getSlidesCount, + clickNext } from "../../test-utils"; describe("CenterMode Tests", () => { @@ -24,39 +25,30 @@ describe("CenterMode Tests", () => { test("Positioning test", () => { const { container } = render(); let currentSlide = getCurrentSlide(container); - console.log(currentSlide[0]); - // Array.from(currentSlide).map(e=>console.log(e)) - //let activeSlides = activeSlides(container); - expect(currentSlide.props()["data-index"]).toEqual(0); - // expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([ - // -1, - // 0, - // 1 - // ]); - // expect(beautify_html(slider.html())).toMatchSnapshot(); + let activeslides = activeSlides(container); + expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(0); + expect( + Array.from(activeslides).map(e => parseInt(e.getAttribute("data-index"))) + ).toEqual([-1, 0, 1]); + expect(beautify_html(toString(container))).toMatchSnapshot(); }); - // test("Activity test", () => { - // const slider = mount(); - // let currentSlide = slider.find("div.slick-current"); - // let activeSlides = slider.find("div.slick-active"); - // expect(currentSlide.props()["data-index"]).toEqual(0); - // expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([ - // -1, - // 0, - // 1 - // ]); - - // clickNext(slider); + test("Activity test", () => { + const { container } = render(); + let currentSlide = getCurrentSlide(container); + let activeslides = activeSlides(container); + expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(0); + expect( + Array.from(activeslides).map(e => parseInt(e.getAttribute("data-index"))) + ).toEqual([-1, 0, 1]); + clickNext(container); - // currentSlide = slider.find("div.slick-current"); - // activeSlides = slider.find("div.slick-active"); - // expect(currentSlide.props()["data-index"]).toEqual(1); - // expect(activeSlides.map(slide => slide.props()["data-index"])).toEqual([ - // 0, - // 1, - // 2 - // ]); + currentSlide = getCurrentSlide(container); + activeslides = activeSlides(container); + expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(1); + expect( + Array.from(activeslides).map(e => parseInt(e.getAttribute("data-index"))) + ).toEqual([0, 1, 2]); - // expect(beautify_html(slider.html())).toMatchSnapshot(); - // }); + expect(beautify_html(toString(container))).toMatchSnapshot(); + }); }); diff --git a/examples/__tests__/Fade.js b/examples/__tests__/Fade.js new file mode 100644 index 000000000..2181ede70 --- /dev/null +++ b/examples/__tests__/Fade.js @@ -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(); + 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); + }); +}); diff --git a/examples/__tests__/FocusOnSelect.test.js b/examples/__tests__/FocusOnSelect.test.js new file mode 100644 index 000000000..3fd2e1291 --- /dev/null +++ b/examples/__tests__/FocusOnSelect.test.js @@ -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(); + 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(); + }); +}); diff --git a/examples/__tests__/MultipleItems.test.js b/examples/__tests__/MultipleItems.test.js new file mode 100644 index 000000000..b1d8ca4bd --- /dev/null +++ b/examples/__tests__/MultipleItems.test.js @@ -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(); + 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(); + expect(getActiveSlidesCount(container)).toEqual(3); + expect(beautify_html(toString(container))).toMatchSnapshot(); + }); + it("should have 3 dots", function() { + const { container } = render(); + expect(getButtonsLength(container)).toEqual(3); + expect(beautify_html(toString(container))).toMatchSnapshot(); + }); + it("should show first 3 slides", function() { + const { container } = render(); + 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(); + 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(); + 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(); + 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(); + 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(); + fireEvent( + getButtons(container)[2], + new MouseEvent("click", { + bubbles: true, + cancelable: true + }) + ); + expect(getActiveSlidesText(container)).toEqual(["7", "8", "9"]); + expect(beautify_html(toString(container))).toMatchSnapshot(); + }); +}); diff --git a/examples/__tests__/SimpleSlider.test.js b/examples/__tests__/SimpleSlider.test.js index 582fd1e84..1834184b7 100644 --- a/examples/__tests__/SimpleSlider.test.js +++ b/examples/__tests__/SimpleSlider.test.js @@ -10,7 +10,8 @@ import { getActiveSlides, getActiveSlidesCount, getActiveSlidesText, - getButtons + getButtons, + getButtonsListItem } from "../../test-utils"; describe("SimpleSlider example", () => { @@ -27,7 +28,11 @@ describe("SimpleSlider example", () => { expect(container.querySelectorAll(".slick-slide.slick-active").length).toBe( 1 ); - expect(activeSlide(container)).toBe(0); + expect( + Array.from(activeSlide(container).children).map( + e => parseInt(e.textContent) - 1 + )[0] + ).toBe(0); }); it("should have 6 dots", function() { const { container } = render(); @@ -87,7 +92,9 @@ describe("SimpleSlider example", () => { ); expect(getActiveSlidesText(container)[0]).toEqual("4"); expect(getActiveSlidesCount(container)).toEqual(1); - expect(hasClass(getButtons(container)[3], "slick-active")).toEqual(true); + expect(hasClass(getButtonsListItem(container)[3], "slick-active")).toEqual( + true + ); }); }); @@ -109,7 +116,7 @@ describe("Simple Slider Snapshots", function() { it("click on 3rd dot", function() { const { container } = render(); fireEvent( - container.querySelectorAll(".slick-dots button")[2], + getButtons(container)[2], new MouseEvent("click", { bubbles: true, cancelable: true diff --git a/examples/__tests__/SlickGoTo.test.js b/examples/__tests__/SlickGoTo.test.js new file mode 100644 index 000000000..8f0cd74a6 --- /dev/null +++ b/examples/__tests__/SlickGoTo.test.js @@ -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(); + 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(); + 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(); + 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(); + 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" + ); + }); +}); diff --git a/examples/__tests__/UnevenSets.test.js b/examples/__tests__/UnevenSets.test.js new file mode 100644 index 000000000..4d5937d67 --- /dev/null +++ b/examples/__tests__/UnevenSets.test.js @@ -0,0 +1,115 @@ +import React from "react"; +import { render, fireEvent } from "@testing-library/react"; +import UnevenSetsFinite from "../UnevenSetsFinite"; +import UnevenSetsInfinite from "../UnevenSetsInfinite"; +import { html as beautify_html } from "js-beautify"; +import { + activeSlides, + clickNext, + getActiveSlidesCount, + getButtonsLength, + getClonesCount, + getCurrentSlide, + getSlidesCount +} from "../../test-utils"; + +describe("UnevenSets Finite", () => { + test("Counting test", () => { + const { container } = render(); + let totalSlides = getSlidesCount(container); + let clonedSlides = getClonesCount(container); + let activeSlides = getActiveSlidesCount(container); + let dots = getButtonsLength(container); + expect(totalSlides).toEqual(6); + expect(clonedSlides).toEqual(0); + expect(activeSlides).toEqual(4); + expect(dots).toEqual(2); + expect(beautify_html(toString(container))).toMatchSnapshot(); + }); + test("Positioning test", () => { + const { container } = render(); + let currentSlide = getCurrentSlide(container); + let activeslides = activeSlides(container); + expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(0); + expect( + Array.from(activeslides).map(slide => + parseInt(slide.getAttribute("data-index")) + ) + ).toEqual([0, 1, 2, 3]); + expect(beautify_html(toString(container))).toMatchSnapshot(); + }); + test("Activity test", () => { + const { container } = render(); + let currentSlide = getCurrentSlide(container); + let activeslides = activeSlides(container); + expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(0); + expect( + Array.from(activeslides).map(slide => + parseInt(slide.getAttribute("data-index")) + ) + ).toEqual([0, 1, 2, 3]); + + clickNext(container); + + currentSlide = getCurrentSlide(container); + activeslides = activeSlides(container); + expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(4); + expect( + Array.from(activeslides).map(slide => + parseInt(slide.getAttribute("data-index")) + ) + ).toEqual([2, 3, 4, 5]); + + expect(beautify_html(toString(container))).toMatchSnapshot(); + }); +}); + +describe("UnevenSets Infinite", () => { + test("Counting test", () => { + const { container } = render(); + let totalSlides = getSlidesCount(container); + let clonedSlides = getClonesCount(container); + let activeSlides = getActiveSlidesCount(container); + let dots = getButtonsLength(container); + expect(totalSlides).toEqual(16); + expect(clonedSlides).toEqual(10); + expect(activeSlides).toEqual(4); + expect(dots).toEqual(2); + expect(beautify_html(toString(container))).toMatchSnapshot(); + }); + test("Positioning test", () => { + const { container } = render(); + let currentSlide = getCurrentSlide(container); + let activeslides = activeSlides(container); + expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(0); + expect( + Array.from(activeslides).map(slide => + parseInt(slide.getAttribute("data-index")) + ) + ).toEqual([0, 1, 2, 3]); + expect(beautify_html(toString(container))).toMatchSnapshot(); + }); + test("Activity test", () => { + const { container } = render(); + let currentSlide = getCurrentSlide(container); + let activeslides = activeSlides(container); + expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(0); + expect( + Array.from(activeslides).map(slide => + parseInt(slide.getAttribute("data-index")) + ) + ).toEqual([0, 1, 2, 3]); + + clickNext(container); + + currentSlide = getCurrentSlide(container); + activeslides = activeSlides(container); + expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(4); + expect( + Array.from(activeslides).map(slide => + parseInt(slide.getAttribute("data-index")) + ) + ).toEqual([4, 5, 6, 7]); + expect(beautify_html(toString(container))).toMatchSnapshot(); + }); +}); diff --git a/examples/__tests__/__snapshots__/CentreMode.test.js.snap b/examples/__tests__/__snapshots__/CentreMode.test.js.snap index 0a8ce7eb4..e8d2091b9 100644 --- a/examples/__tests__/__snapshots__/CentreMode.test.js.snap +++ b/examples/__tests__/__snapshots__/CentreMode.test.js.snap @@ -1,3 +1,7 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`CenterMode Tests Activity test 1`] = `"[object Undefined]"`; + exports[`CenterMode Tests Counting test 1`] = `"[object Undefined]"`; + +exports[`CenterMode Tests Positioning test 1`] = `"[object Undefined]"`; diff --git a/examples/__tests__/__snapshots__/FocusOnSelect.test.js.snap b/examples/__tests__/__snapshots__/FocusOnSelect.test.js.snap new file mode 100644 index 000000000..c4ccc9821 --- /dev/null +++ b/examples/__tests__/__snapshots__/FocusOnSelect.test.js.snap @@ -0,0 +1,5 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`FocusOnSelect Tests Activity Test 1`] = `"[object Undefined]"`; + +exports[`FocusOnSelect Tests Activity Test 2`] = `"[object Undefined]"`; diff --git a/examples/__tests__/__snapshots__/MultipleItems.test.js.snap b/examples/__tests__/__snapshots__/MultipleItems.test.js.snap new file mode 100644 index 000000000..e58a31874 --- /dev/null +++ b/examples/__tests__/__snapshots__/MultipleItems.test.js.snap @@ -0,0 +1,19 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Multiple Items should have 3 active slides 1`] = `"[object Undefined]"`; + +exports[`Multiple Items should have 3 dots 1`] = `"[object Undefined]"`; + +exports[`Multiple Items should have 9 actual slides and (3(pre) + 9(post)) clone slides 1`] = `"[object Undefined]"`; + +exports[`Multiple Items should show first 3 slides 1`] = `"[object Undefined]"`; + +exports[`Multiple Items should show last 3 slides when last dot is clicked 1`] = `"[object Undefined]"`; + +exports[`Multiple Items should show last 3 slides when previous button is clicked 1`] = `"[object Undefined]"`; + +exports[`Multiple Items should show slides first 3 slides when first dot is clicked 1`] = `"[object Undefined]"`; + +exports[`Multiple Items should show slides from 4 to 6 when middle dot is clicked 1`] = `"[object Undefined]"`; + +exports[`Multiple Items should show slides from 4 to 6 when next button is clicked 1`] = `"[object Undefined]"`; diff --git a/examples/__tests__/__snapshots__/UnevenSets.test.js.snap b/examples/__tests__/__snapshots__/UnevenSets.test.js.snap new file mode 100644 index 000000000..dd3433336 --- /dev/null +++ b/examples/__tests__/__snapshots__/UnevenSets.test.js.snap @@ -0,0 +1,13 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`UnevenSets Finite Activity test 1`] = `"[object Undefined]"`; + +exports[`UnevenSets Finite Counting test 1`] = `"[object Undefined]"`; + +exports[`UnevenSets Finite Positioning test 1`] = `"[object Undefined]"`; + +exports[`UnevenSets Infinite Activity test 1`] = `"[object Undefined]"`; + +exports[`UnevenSets Infinite Counting test 1`] = `"[object Undefined]"`; + +exports[`UnevenSets Infinite Positioning test 1`] = `"[object Undefined]"`; diff --git a/examples/__tests__/sample.test.js b/examples/__tests__/sample.test.js new file mode 100644 index 000000000..d2d276e62 --- /dev/null +++ b/examples/__tests__/sample.test.js @@ -0,0 +1,40 @@ +import React from "react"; +import { fireEvent, render } from "@testing-library/react"; + +export default class Counter extends React.Component { + constructor(props) { + super(props); + this.state = { + count: 0 + }; + } + render() { + return ( + + ); + } +} + +describe("sample counter test", function() { + it("mutliple counts", function() { + const { container } = render(); + const button = container.getElementsByTagName("Button")[0]; + fireEvent( + button, + new MouseEvent("click", { + bubbles: true, + cancelable: true + }) + ); + fireEvent( + button, + new MouseEvent("click", { + bubbles: true, + cancelable: true + }) + ); + expect(button.textContent).toEqual("Count 2"); + }); +}); diff --git a/test-utils.js b/test-utils.js index 10590d637..3b8c773e1 100644 --- a/test-utils.js +++ b/test-utils.js @@ -13,13 +13,19 @@ export function getActiveSlidesCount(container) { } export function getCurrentSlide(container) { - return container.querySelectorAll(".slick-current"); + return container.querySelector(".slick-current"); } export function getButtons(container) { - return container.querySelectorAll(".slick-dots")[0].children; + return container.querySelectorAll(".slick-dots button"); } +export function getButtonsListItem(container) { + return container.querySelectorAll(".slick-dots")[0].children; +} +export function getButtonsLength(container) { + return container.querySelectorAll(".slick-dots")[0].children.length; +} export function hasClass(element, classname) { if (element.className != undefined) { return element.className == classname; @@ -27,12 +33,10 @@ export function hasClass(element, classname) { return false; } export function activeSlides(container) { - return container.querySelectorAll(".slick-dots .slick-active"); + return container.querySelectorAll(".slick-slide.slick-active"); } export function activeSlide(container) { - return Array.from( - container.querySelectorAll(".slick-dots .slick-active")[0].children - ).map(e => parseInt(e.textContent) - 1)[0]; + return container.querySelector(".slick-slide.slick-active"); } export function getActiveSlides(container) { From 338201fffb048e0b1221f916abdd7caed241d1d2 Mon Sep 17 00:00:00 2001 From: Pratyush Bhatnagar <38534434+pratyushbh@users.noreply.github.com> Date: Thu, 18 May 2023 17:17:40 +0530 Subject: [PATCH 17/58] migrated all the tests to testing-library/react and removed Snapshots --- __test__/SimpleSlider.test.js | 46 +++++ __test__/afterChange.test.js | 58 ++++++ __test__/arrows.js | 73 ++++++++ __test__/beforeChange.test.js | 57 ++++++ __test__/jQSlickUtils.js | 133 +++++++++++++ __test__/lazyLoad.test.js | 67 +++++++ __test__/mount/centerMode.test.js | 82 +++++++++ __test__/mount/lazyLoad.test.js | 80 ++++++++ __test__/mount/live.test.js | 77 ++++++++ __test__/mount/simple.test.js | 80 ++++++++ __test__/observations.json | 54 ++++++ __test__/reactSlickUtils.js | 104 +++++++++++ __test__/sliderStyles.test.js | 44 +++++ __test__/testUtils.js | 174 ++++++++++++++++++ examples/__tests__/CentreMode.test.js | 6 +- examples/__tests__/FocusOnSelect.test.js | 4 +- examples/__tests__/MultipleItems.test.js | 18 +- examples/__tests__/SimpleSlider.test.js | 10 +- examples/__tests__/UnevenSets.test.js | 23 ++- .../__snapshots__/CentreMode.test.js.snap | 7 - .../__snapshots__/FocusOnSelect.test.js.snap | 5 - .../__snapshots__/MultipleItems.test.js.snap | 19 -- .../__snapshots__/SimpleSlider.test.js.snap | 9 - .../__snapshots__/UnevenSets.test.js.snap | 13 -- test-utils.js | 9 +- 25 files changed, 1173 insertions(+), 79 deletions(-) create mode 100644 __test__/SimpleSlider.test.js create mode 100644 __test__/afterChange.test.js create mode 100644 __test__/arrows.js create mode 100644 __test__/beforeChange.test.js create mode 100644 __test__/jQSlickUtils.js create mode 100644 __test__/lazyLoad.test.js create mode 100644 __test__/mount/centerMode.test.js create mode 100644 __test__/mount/lazyLoad.test.js create mode 100644 __test__/mount/live.test.js create mode 100644 __test__/mount/simple.test.js create mode 100644 __test__/observations.json create mode 100644 __test__/reactSlickUtils.js create mode 100644 __test__/sliderStyles.test.js create mode 100644 __test__/testUtils.js delete mode 100644 examples/__tests__/__snapshots__/CentreMode.test.js.snap delete mode 100644 examples/__tests__/__snapshots__/FocusOnSelect.test.js.snap delete mode 100644 examples/__tests__/__snapshots__/MultipleItems.test.js.snap delete mode 100644 examples/__tests__/__snapshots__/SimpleSlider.test.js.snap delete mode 100644 examples/__tests__/__snapshots__/UnevenSets.test.js.snap diff --git a/__test__/SimpleSlider.test.js b/__test__/SimpleSlider.test.js new file mode 100644 index 000000000..f0f7b7932 --- /dev/null +++ b/__test__/SimpleSlider.test.js @@ -0,0 +1,46 @@ +// includes tests of +// SimpleSlider, MultipleItems +import { testSlider } from "./testUtils"; + +describe("SimpleSlider with combinations of possibilities", function() { + // try around several possibilities + let _noOfSlides = [2, 5, 12]; + let _slidesToShow = [2, 5, 10]; + let _slidesToScroll = [1, 2, 3, 10]; + if (true) { + // for switching real quick to lesser/easier tests for simplicity + _noOfSlides = [5]; + _slidesToShow = [2]; + _slidesToScroll = [1, 2]; + } + + for (let noOfSlides of _noOfSlides) { + for (let slidesToShow of _slidesToShow) { + for (let slidesToScroll of _slidesToScroll) { + // following restrictions may not be 100% correct, and there may be more restrictions + if (slidesToShow > noOfSlides || slidesToScroll > slidesToShow) { + continue; + } + if (noOfSlides === slidesToShow) { + // temporary, jquery slick disables arrows in this case, so the tests fail + continue; + } + if (slidesToShow === slidesToScroll) { + // temporary, active-class is not being assigned properly, so tests fail + continue; + } + const settings1 = { + infinite: true, + speed: 0, + noOfSlides, + slidesToShow, + slidesToScroll, + useCSS: false + }; + test(`Test with settings => noOfSlides: ${noOfSlides}, slidesToShow: ${slidesToShow}, slidesToScroll: ${slidesToScroll}`, function() { + testSlider(settings1); + }); + } + } + } +}); diff --git a/__test__/afterChange.test.js b/__test__/afterChange.test.js new file mode 100644 index 000000000..d3998459f --- /dev/null +++ b/__test__/afterChange.test.js @@ -0,0 +1,58 @@ +import React from "react"; +import { render, fireEvent } from "@testing-library/react"; +import Slider from "../src/index"; +import { + activeSlide, + clickNext, + clickPrevious, + getCurrentSlide +} from "../test-utils"; + +class SliderWithAfterChange extends React.Component { + constructor(props) { + super(props); + this.state = { + currentSlide: null + }; + this.afterChange = this.afterChange.bind(this); + } + + afterChange(currentSlide) { + console.log(currentSlide, "afterChange"); + this.setState({ + currentSlide + }); + } + render() { + return ( + +
slide1
+
slide2
+
slide3
+
slide4
+
+ ); + } +} + +test("fake test", () => { + expect(1).toBe(1); +}); +describe("After change Slider", function() { + it("should render", function() { + const { container } = render(); + clickNext(container); + setTimeout(() => { + expect(activeSlide(container).textContent).toEqual("slide2"); + }, 1000); + clickNext(container); + setTimeout(() => { + console.log(activeSlide(container).textContent); + expect(activeSlide(container).textContent).toEqual("slide3"); + }, 1000); + clickPrevious(container); + setTimeout(() => { + expect(activeSlide(container).textContent).toEqual("slide2"); + }, 1000); + }); +}); diff --git a/__test__/arrows.js b/__test__/arrows.js new file mode 100644 index 000000000..8ed7ae31a --- /dev/null +++ b/__test__/arrows.js @@ -0,0 +1,73 @@ +/** + * Arrow component tests + */ + +sinon.stub(console, "error"); + +import { render } from "@testing-library/react"; +import React from "react"; +import sinon from "sinon"; + +import { NextArrow, PrevArrow } from "../src/arrows"; + +function CustomArrow(props) { + return ( + + ); +} + +describe("Previous arrows", () => { + it("should render arrow", () => { + const { container } = render(); + expect(Array.from(container.getElementsByTagName("button"))).toHaveLength( + 1 + ); + }); + + it("should not result in errors", () => { + render(); + + expect(console.error.called).toBe(false); + }); + + // it('should pass slide data to custom arrow', () => { + // let elAttributes; + // let arr = + + // const {container}= render(); + + // 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 { container } = render(); + expect(Array.from(container.getElementsByTagName("button"))).toHaveLength( + 1 + ); + }); + + // it('should not result in errors', () => { + // render(); + + // expect(console.error.called).toBe(false); + // }); + + // it('should pass slide data to custom arrow', () => { + // let elAttributes; + // let arr = + + // const {container} = render(); + + // elAttributes =(x)=> container.querySelectorAll('.sample')[0].getAttribute(x); + // expect(elAttributes('data-currentslide')).toBe('6'); + // expect(elAttributes('data-slidecount')).toBe('9'); + // }); +}); diff --git a/__test__/beforeChange.test.js b/__test__/beforeChange.test.js new file mode 100644 index 000000000..b54a130a6 --- /dev/null +++ b/__test__/beforeChange.test.js @@ -0,0 +1,57 @@ +import React from "react"; +import { render } from "@testing-library/react"; +import Slider from "../src/index"; +import { + activeSlide, + clickNext, + clickPrevious, + getCurrentSlide +} from "../test-utils"; + +class SliderWithBeforeChange extends React.Component { + constructor(props) { + super(props); + this.state = { + currentSlide: null, + nextSlide: null + }; + this.beforeChange = this.beforeChange.bind(this); + } + beforeChange(currentSlide, nextSlide) { + this.setState({ + currentSlide, + nextSlide + }); + } + render() { + return ( + +
slide1
+
slide2
+
slide3
+
slide4
+
+ ); + } +} + +describe("Slider", function() { + it("should render", function() { + const { container } = render(); + clickNext(container); + expect(activeSlide(container).textContent).toEqual("slide2"); + console.log( + parseInt(getCurrentSlide(container).getAttribute("data-index")) + ); + clickNext(container); + expect(activeSlide(container).textContent).toEqual("slide3"); + console.log( + parseInt(getCurrentSlide(container).getAttribute("data-index")) + ); + clickPrevious(container); + expect(activeSlide(container).textContent).toEqual("slide2"); + console.log( + parseInt(getCurrentSlide(container).getAttribute("data-index")) + ); + }); +}); diff --git a/__test__/jQSlickUtils.js b/__test__/jQSlickUtils.js new file mode 100644 index 000000000..e8d2ff77b --- /dev/null +++ b/__test__/jQSlickUtils.js @@ -0,0 +1,133 @@ +// this is for fetching details after initializing react and jquery slicks +// and compare those details to see if things are going different + +import { + createSliderReact, + createJQuerySliderChildren, + activeSlideInLastTransition +} from "./testUtils"; +import $ from "jquery"; +import * as slickCarousel from "slick-carousel"; +import util from "util"; +import js_beautify, { html as html_beautify } from "js-beautify"; + +// simulates actions from given actions object +// takes document from the scope from where it's called +function simulateActions(actions) { + if (actions.clickNext) { + for (let click = 0; click < actions.clickNext; click++) { + $(".slick-next").click(); + } + } + if (actions.clickPrev) { + for (let click = 0; click < actions.clickPrev; click++) { + $(".slick-prev").click(); + } + } + if (actions.clickSequence) { + for (let click of actions.clickSequence) { + if (click === "n") { + $(".slick-next").click(); + } else if (click === "p") { + $(".slick-prev").click(); + } else { + // that's right, you can't even write n/p properly + } + } + } +} + +// takes an object of keys and returns those details +/* Possible keys can be one of the following + currentSlide(index and value), activeSlides(index and value), + allSlides(index and value), clonedSlides(index and value) + */ +function fetchDetails(keys) { + let details = {}; + let currentSlide = null, + activeSlides = [], + allSlides = [], + clonedSlides = [], + visibleSlides = []; + for (let slide of $("div.slick-slide")) { + const slideObj = { + index: $(slide).attr("data-slick-index"), + value: $(slide) + .find("div") + .find("div") + .find("h3") + .text() + }; + allSlides.push(slideObj); + if ($(slide).hasClass("slick-current")) { + currentSlide = slideObj.index; + } + if ($(slide).hasClass("slick-active")) { + activeSlides.push(slideObj); + } + if ($(slide).hasClass("slick-cloned")) { + clonedSlides.push(slideObj); + } + if ($(slide).attr("aria-hidden") == "false") { + visibleSlides.push(slideObj); + } + } + if (keys.currentSlide) { + details.currentSlide = currentSlide; + } + if (keys.activeSlides) { + details.activeSlides = activeSlides; + } + if (keys.allSlides) { + details.allSlides = allSlides; + } + if (keys.clonedSlides) { + details.clonedSlides = clonedSlides; + } + if (keys.visibleSlides) { + details.visibleSlides = visibleSlides; + } + return details; +} + +// creates a jQuery slick with given settings and +// performs the given actions +// returns the given keys +export function getJQuerySlickDetails(settings, actions, keys) { + // create new slider + document.body.innerHTML = ` +
+ ${createJQuerySliderChildren(settings.noOfSlides)} +
+ `; + $(".regular.slider").slick({ + ...settings + }); + simulateActions(actions); + // console.log(html_beautify($('.regular.slider').html())) + return fetchDetails(keys); +} + +const settings = { + infinite: true, + noOfSlides: 5, + slidesToShow: 3, + slidesToScroll: 2, + useCSS: false, + speed: 0 +}; +const actions = { + clickNext: 2, + clickPrev: 1, + clickSequence: ["n", "p", "n"] +}; +const keys = { + activeSlides: true, + visibleSlides: true, + allSlides: true +}; + +test("testing getJQuerySlickDetails utility", () => { + const details = getJQuerySlickDetails(settings, actions, keys); + expect(details.activeSlides).toEqual(details.visibleSlides); +}); diff --git a/__test__/lazyLoad.test.js b/__test__/lazyLoad.test.js new file mode 100644 index 000000000..1ce8491d0 --- /dev/null +++ b/__test__/lazyLoad.test.js @@ -0,0 +1,67 @@ +import { render } from "@testing-library/react"; +import assign from "object-assign"; +import { getRequiredLazySlides } from "../src/utils/innerSliderUtils"; +import { + createInnerSliderWrapper, + clickNext, + clickPrev, + tryAllConfigs +} from "./testUtils"; + +// const testSettings = settings => { +// let {container} = createInnerSliderWrapper(settings); +// for (let click = 0; click < settings.noOfSlides + 2; click++) { +// let lazyLoadedList = slider.state().lazyLoadedList; +// let expectedLazyLoadedList = getRequiredLazySlides( +// assign({}, slider.props(), slider.state()) +// ); +// expectedLazyLoadedList.forEach(slide => { +// expect(lazyLoadedList.indexOf(slide) >= 0).toEqual(true); +// }); +// clickNext(slider); +// } + +// slider = createInnerSliderWrapper(settings); +// for (let click = 0; click < settings.noOfSlides + 2; click++) { +// let lazyLoadedList = slider.state().lazyLoadedList; +// let expectedLazyLoadedList = getRequiredLazySlides( +// assign({}, slider.props(), slider.state()) +// ); +// expectedLazyLoadedList.forEach(slide => { +// expect(lazyLoadedList.indexOf(slide) >= 0).toEqual(true); +// }); +// clickPrev(slider); +// } + +// slider = createInnerSliderWrapper(settings); +// for (let click = 0; click < settings.noOfSlides + 2; click++) { +// let lazyLoadedList = slider.state().lazyLoadedList; +// lazyLoadedList.forEach(slideIndex => { +// expect( +// slider.find(`[data-index=${slideIndex}]`).props().children !== undefined +// ).toBe(true); +// }); +// } +// }; + +// describe("LazyLoad test", () => { +// let settings = { +// lazyLoad: true, +// useCSS: false, +// speed: 0, +// noOfSlides: [7, 8], +// initialSlide: [0, 5], +// slidesToShow: [1, 3, 4], +// slidesToScroll: [1, 3], +// centerMode: [true, false] +// }; +// let settingsList = []; +// tryAllConfigs(settings, settingsList); +// // shuffle the list +// settingsList.sort(() => 0.5 - Math.random()); +// settingsList.forEach((settings, index) => { +// if (Math.random() < 0.5) { +// test(`Testing config no. ${index}`, () => testSettings(settings)); +// } +// }); +// }); diff --git a/__test__/mount/centerMode.test.js b/__test__/mount/centerMode.test.js new file mode 100644 index 000000000..07873dc19 --- /dev/null +++ b/__test__/mount/centerMode.test.js @@ -0,0 +1,82 @@ +import { getJQuerySlickDetails } from "../jQSlickUtils"; +import { getReactSlickDetails } from "../reactSlickUtils"; + +let settings = { + infinite: true, + speed: 0, + useCSS: false, + noOfSlides: 5, + slidesToShow: 3, + slidesToScroll: 1, + centerMode: true +}; +let actions = { + clickNext: 0, + clickPrev: 0, + clickSequence: [] +}; +let keys = { + currentSlide: true, + activeSlides: true, + clonedSlides: true, + allSlides: true +}; + +const testsUtil = (settings, actions, keys) => { + const jqDetails = getJQuerySlickDetails(settings, actions, keys); + const reactDetails = getReactSlickDetails(settings, actions, keys); + console.log(reactDetails, jqDetails); + test("checking current slide jQuery vs react", () => { + //currentSlide of react is 1 times more than currentSlide of JQuery + expect(parseInt(reactDetails.currentSlide) - 1).toEqual( + parseInt(jqDetails.currentSlide) + ); + }); + test("checking active slides jQuery vs react", () => { + expect(reactDetails.activeSlides).toEqual(jqDetails.activeSlides); + }); + + // Following two tests fail + test("checking cloned slides jQuery vs react", () => { + expect(reactDetails.clonedSlides.map(slide => slide.index)).toEqual( + jqDetails.clonedSlides.map(slide => slide.index) + ); + }); + test("checking all slides jQuery vs react", () => { + expect(reactDetails.allSlides.map(slide => slide.index)).toEqual( + jqDetails.allSlides.map(slide => slide.index) + ); + }); +}; + +describe("InnerSlider component tests: Part 1", () => { + testsUtil(settings, actions, keys); +}); +describe("InnerSlider component tests: Part 2", () => { + settings.slidesToScroll = 2; + testsUtil(settings, actions, keys); +}); +describe("InnerSlider component tests: Part 3", () => { + actions.clickNext = 2; + testsUtil(settings, actions, keys); +}); +describe("InnerSlider component tests: Part 4", () => { + actions.clickPrev = 2; + testsUtil(settings, actions, keys); +}); +describe("InnerSlider component tests: Part 5", () => { + actions.clickNext = 6; + testsUtil(settings, actions, keys); +}); +describe("InnerSlider component tests: Part 6", () => { + actions.clickPrev = 6; + testsUtil(settings, actions, keys); +}); +describe("InnerSlider component tests: Part 7", () => { + actions.clickSequence = ["n", "n", "n", "n", "n", "n", "p", "p", "p"]; + testsUtil(settings, actions, keys); +}); +describe("InnerSlider component tests: Part 8", () => { + actions.clickSequence = ["p", "p", "p", "p", "p", "p", "n", "n", "n"]; + testsUtil(settings, actions, keys); +}); diff --git a/__test__/mount/lazyLoad.test.js b/__test__/mount/lazyLoad.test.js new file mode 100644 index 000000000..8376a7933 --- /dev/null +++ b/__test__/mount/lazyLoad.test.js @@ -0,0 +1,80 @@ +import { getJQuerySlickDetails } from "../jQSlickUtils"; +import { getReactSlickDetails } from "../reactSlickUtils"; + +let settings = { + infinite: true, + speed: 0, + useCSS: false, + lazyLoad: true, + noOfSlides: 5, + slidesToShow: 3, + slidesToScroll: 1 +}; +let actions = { + clickNext: 0, + clickPrev: 0, + clickSequence: [] +}; +let keys = { + currentSlide: true, + activeSlides: true, + clonedSlides: true, + allSlides: true +}; + +const testsUtil = (settings, actions, keys) => { + const jqDetails = getJQuerySlickDetails(settings, actions, keys); + const reactDetails = getReactSlickDetails(settings, actions, keys); + test.skip("checking current slide jQuery vs react", () => { + expect(parseInt(reactDetails.currentSlide) - 1).toEqual( + parseInt(jqDetails.currentSlide) + ); + }); + test.skip("checking active slides jQuery vs react", () => { + expect(reactDetails.activeSlides).toEqual(jqDetails.activeSlides); + }); + + // Following two tests fail + test("checking cloned slides jQuery vs react", () => { + expect(reactDetails.clonedSlides.map(slide => slide.index)).toEqual( + jqDetails.clonedSlides.map(slide => slide.index) + ); + }); + test("checking all slides jQuery vs react", () => { + expect(reactDetails.allSlides.map(slide => slide.index)).toEqual( + jqDetails.allSlides.map(slide => slide.index) + ); + }); +}; + +describe("InnerSlider component tests with lazyload: Part 1", () => { + testsUtil(settings, actions, keys); +}); +describe("InnerSlider component tests with lazyload: Part 2", () => { + settings.slidesToScroll = 2; + testsUtil(settings, actions, keys); +}); +describe("InnerSlider component tests with lazyload: Part 3", () => { + actions.clickNext = 2; + testsUtil(settings, actions, keys); +}); +describe("InnerSlider component tests with lazyload: Part 4", () => { + actions.clickPrev = 2; + testsUtil(settings, actions, keys); +}); +describe("InnerSlider component tests with lazyload: Part 5", () => { + actions.clickNext = 6; + testsUtil(settings, actions, keys); +}); +describe("InnerSlider component tests with lazyload: Part 6", () => { + actions.clickPrev = 6; + testsUtil(settings, actions, keys); +}); +describe("InnerSlider component tests with lazyload: Part 7", () => { + actions.clickSequence = ["n", "n", "n", "n", "n", "n", "p", "p", "p"]; + testsUtil(settings, actions, keys); +}); +describe("InnerSlider component tests with lazyload: Part 8", () => { + actions.clickSequence = ["p", "p", "p", "p", "p", "p", "n", "n", "n"]; + testsUtil(settings, actions, keys); +}); diff --git a/__test__/mount/live.test.js b/__test__/mount/live.test.js new file mode 100644 index 000000000..069a457d9 --- /dev/null +++ b/__test__/mount/live.test.js @@ -0,0 +1,77 @@ +import { getJQuerySlickDetails } from "../jQSlickUtils"; +import { getReactSlickDetails } from "../reactSlickUtils"; + +describe("live testing module", () => { + let settings = { + infinite: true, + speed: 0, + useCSS: false, + noOfSlides: 5, + slidesToShow: 3, + slidesToScroll: 1 + // centerMode: true, + }; + let actions = { + clickNext: 0, + clickPrev: 0, + clickSequence: [] + }; + let keys = { + // currentSlide: true, + // activeSlides: true, + clonedSlides: true + // allSlides: true, + }; + let reactDetails = getReactSlickDetails(settings, actions, keys); + let jqueryDetails = getJQuerySlickDetails(settings, actions, keys); + + // for(let noOfSlides of [5, 12]){ + // for (let slidesToShow of [1, 11, 12]){ + // for (let slidesToScroll of [1, 2, 11, 12]){ + + // for(let noOfSlides of [2, 3, 5, 6, 12]){ + // for (let slidesToShow of [1, 2, 3, 5, 11, 12]){ + // for (let slidesToScroll of [1, 2, 3, 5, 11, 12]){ + // if(noOfSlides < slidesToShow || noOfSlides < slidesToScroll || slidesToShow < slidesToScroll){ + // continue; + // } + // settings.noOfSlides = noOfSlides + // settings.slidesToShow = slidesToShow + // settings.slidesToScroll = slidesToScroll + // const jqueryDetails = getJQuerySlickDetails(settings, actions, keys) + // const reactDetails = getReactSlickDetails(settings, actions, keys) + // // test('number of cloned slides', () => { + // // expect(jqueryDetails.clonedSlides.filter(slide => slide.index < 0).length).toEqual( + // // noOfSlides === slidesToShow ? 0 : (settings.centerMode ? slidesToShow+1 : slidesToShow) + // // ) + // // expect(jqueryDetails.clonedSlides.filter(slide => slide.index >= 0).length).toEqual( + // // noOfSlides === slidesToShow ? 0 : noOfSlides + // // ) + // // }) + + // test('number of cloned slides, react vs jquery', () => { + // expect(reactDetails.clonedSlides.filter(slide => slide.index < 0).length).toEqual( + // jqueryDetails.clonedSlides.filter(slide => slide.index < 0).length + // ) + // expect(reactDetails.clonedSlides.filter(slide => slide.index >= 0).length).toEqual( + // jqueryDetails.clonedSlides.filter(slide => slide.index >= 0).length + // ) + // }) + + // // console.log( + // // 'settings:', settings, '\n', + // // 'pre:', jqueryDetails.clonedSlides.filter(slide => slide.index < 0).length, + // // 'post:', jqueryDetails.clonedSlides.filter(slide => slide.index >= 0).length + // // ) + // // console.log( + // // 'settings2:', settings.noOfSlides, '\n', + // // 'details2:', reactDetails.clonedSlides + // // .filter(slide => slide.index > 0).length + // // ) + // } + // } + // } + test("fake test", () => { + expect(1).toBe(1); + }); +}); diff --git a/__test__/mount/simple.test.js b/__test__/mount/simple.test.js new file mode 100644 index 000000000..84257bad6 --- /dev/null +++ b/__test__/mount/simple.test.js @@ -0,0 +1,80 @@ +import { getJQuerySlickDetails } from "../jQSlickUtils"; +import { getReactSlickDetails } from "../reactSlickUtils"; + +let settings = { + infinite: true, + speed: 0, + useCSS: false, + noOfSlides: 5, + slidesToShow: 3, + slidesToScroll: 1 +}; +let actions = { + clickNext: 0, + clickPrev: 0, + clickSequence: [] +}; +let keys = { + currentSlide: true, + activeSlides: true, + clonedSlides: true, + allSlides: true +}; + +const testsUtil = (settings, actions, keys) => { + const jqDetails = getJQuerySlickDetails(settings, actions, keys); + const reactDetails = getReactSlickDetails(settings, actions, keys); + test("checking current slide jQuery vs react", () => { + //currentSlide of react is 1 times more than currentSlide of JQuery + expect(parseInt(reactDetails.currentSlide) - 1).toEqual( + parseInt(jqDetails.currentSlide) + ); + }); + test("checking active slides jQuery vs react", () => { + expect(reactDetails.activeSlides).toEqual(jqDetails.activeSlides); + }); + + // Following two tests fail + test("checking cloned slides jQuery vs react", () => { + expect(reactDetails.clonedSlides.map(slide => slide.index)).toEqual( + jqDetails.clonedSlides.map(slide => slide.index) + ); + }); + test("checking all slides jQuery vs react", () => { + expect(reactDetails.allSlides.map(slide => slide.index)).toEqual( + jqDetails.allSlides.map(slide => slide.index) + ); + }); +}; + +describe("InnerSlider component tests: Part 1", () => { + testsUtil(settings, actions, keys); +}); +describe("InnerSlider component tests: Part 2", () => { + settings.slidesToScroll = 2; + testsUtil(settings, actions, keys); +}); +describe("InnerSlider component tests: Part 3", () => { + actions.clickNext = 2; + testsUtil(settings, actions, keys); +}); +describe("InnerSlider component tests: Part 4", () => { + actions.clickPrev = 2; + testsUtil(settings, actions, keys); +}); +describe("InnerSlider component tests: Part 5", () => { + actions.clickNext = 6; + testsUtil(settings, actions, keys); +}); +describe("InnerSlider component tests: Part 6", () => { + actions.clickPrev = 6; + testsUtil(settings, actions, keys); +}); +describe("InnerSlider component tests: Part 7", () => { + actions.clickSequence = ["n", "n", "n", "n", "n", "n", "p", "p", "p"]; + testsUtil(settings, actions, keys); +}); +describe("InnerSlider component tests: Part 8", () => { + actions.clickSequence = ["p", "p", "p", "p", "p", "p", "p", "n", "n", "n"]; + testsUtil(settings, actions, keys); +}); diff --git a/__test__/observations.json b/__test__/observations.json new file mode 100644 index 000000000..42e93a7c2 --- /dev/null +++ b/__test__/observations.json @@ -0,0 +1,54 @@ +{ + "jQueryTest": [ + { + "observation": "Clicks on arrows are not working properly", + "possibleCause": "Animation effects are taking effects somehow", + "solutions": [ + { + "description": "set useCSS property to false", + "status": "did not work" + }, + { + "description": "set speed property to 0", + "status": "worked, now the clicks are working as of now" + } + ] + }, + { + "observation": "arrows are disabled when slidesToShow are equal to noOfSlides", + "status": "causes few tests to fail" + }, + { + "observation": "tests are very slow", + "possibleCause": "synchronous click event simulation and slow DOM api", + "status": "not tried yet" + } + ], + "reactTest": [ + { + "observation": "Clicks on arrows are not working properly", + "possibleCause": "Animation effects are taking effects somehow", + "solutions": [ + { + "description": "set useCSS property to false", + "status": "worked, now the clicks are working as of now" + } + ] + } + ], + "misc": [ + { + "observation": "In case of reverse scrolling, slick-active class is not being assigned properly.", + "example": { + "settings": { + "noOfSlides": 5, + "slidesToShow": 2, + "slidesToScroll": 2 + }, + "jqueryBehaviour": "after one prev click, current-slide is 5th and active-class is assigned to slide 4th and 5th while the same are displayed in frame", + "reactBehaviour": "after one prev click, current-slide is 5th and active-class is assigned to slide 5th and 1st(cloned) while 4th and 5th are displayed in frame", + "status": "several tests are failing due to this property" + } + } + ] +} diff --git a/__test__/reactSlickUtils.js b/__test__/reactSlickUtils.js new file mode 100644 index 000000000..aac2caf5c --- /dev/null +++ b/__test__/reactSlickUtils.js @@ -0,0 +1,104 @@ +import { + clickNext, + clickPrevious, + getSlides, + getCurrentSlide, + hasClass, + getClonesCount +} from "../test-utils"; +import { createInnerSliderWrapper } from "./testUtils"; + +// given slider and actions objects, and simulates given actions +function simulateActions(slider, actions) { + if (actions.clickNext) { + for (let click = 0; click < actions.clickNext; click++) { + clickNext(slider); + } + } + if (actions.clickPrev) { + for (let click = 0; click < actions.clickPrev; click++) { + clickPrevious(slider); + } + } + if (actions.clickSequence) { + for (let click of actions.clickSequence) { + if (click === "n") { + clickNext(slider); + } else if (click === "p") { + clickPrevious(slider); + } else { + // not a valid action for now + } + } + } + // console.log('after simulating actions, state of slider:', slider.state()) +} + +function fetchDetails(container, keys) { + let details = { ...fetchDOMDetails(container, keys) }; + if (keys.currentSlide) { + details.currentSlide = getCurrentSlide(container).textContent; + } + return details; +} + +function fetchDOMDetails(slider, keys) { + let details = {}; + let currentSlide = null, + activeSlides = [], + allSlides = [], + clonedSlides = [], + visibleSlides = []; // currently no way to find these + //Array.from(getSlides(slider)).forEach(e=>console.log(Array.from(e.getElementsByTagName("h3")).length)); + Array.from(getSlides(slider)).forEach((slide, index) => { + const slideObj = { + index: slide.getAttribute("data-index"), + value: + Array.from(slide.getElementsByTagName("h3")).length === 1 + ? slide.querySelector("h3").textContent + : "..." + }; + allSlides.push(slideObj); + if (hasClass(slide, "slick-current")) { + currentSlide = slideObj; + } + if (hasClass(slide, "slick-active")) { + activeSlides.push(slideObj); + } + if (hasClass(slide, "slick-cloned")) { + clonedSlides.push(slideObj); + } + }); + if (keys.currentSlide) { + details.currentSlide = currentSlide; + } + if (keys.activeSlides) { + details.activeSlides = activeSlides; + } + if (keys.allSlides) { + details.allSlides = allSlides; + } + if (keys.clonedSlides) { + details.clonedSlides = clonedSlides; + } + if (keys.visibleSlides) { + details.visibleSlides = visibleSlides; + } + return details; +} + +export function getReactSlickDetails(settings, actions, keys) { + const slider = createInnerSliderWrapper(settings); + simulateActions(slider, actions); + return fetchDetails(slider, keys); +} + +/* +settings: [...sliderProps, noOfSlides], +actions: [clickNext, clickPrev, clickSequence], +keys: [currentSlide, activeSlides, clonedSlides, allSlides, visibleSlides] +*/ + +test("fake test", () => { + expect(1).toBe(1); +}); diff --git a/__test__/sliderStyles.test.js b/__test__/sliderStyles.test.js new file mode 100644 index 000000000..46167d56f --- /dev/null +++ b/__test__/sliderStyles.test.js @@ -0,0 +1,44 @@ +import assign from "object-assign"; +import { getRequiredLazySlides } from "../src/utils/innerSliderUtils"; +import { + createInnerSliderWrapper, + clickNext, + clickPrev, + tryAllConfigs, + actualTrackLeft, + testTrackLeft +} from "./testUtils"; +import { getTrackLeft } from "../src/utils/innerSliderUtils"; + +const testSettings = settings => { + let slider = createInnerSliderWrapper(settings); + for (let click = 0; click < settings.noOfSlides + 2; click++) { + testTrackLeft(slider); + clickNext(slider); + } + slider = createInnerSliderWrapper(settings); + for (let click = 0; click < settings.noOfSlides + 2; click++) { + testTrackLeft(slider); + clickPrev(slider); + } +}; + +describe("Slider Styles Tests", () => { + let settings = { + useCSS: false, + speed: 0, + centerMode: [true, false], + noOfSlides: [7, 8], + initialSlide: [0, 5], + slidesToShow: [1, 3, 4] + }; + let settingsList = []; + tryAllConfigs(settings, settingsList); + // shuffle the list + settingsList.sort(() => 0.5 - Math.random()); + settingsList.forEach((settings, index) => { + // if (Math.random() < 0.5) { + // test(`Testing config no. ${index}`, () => testSettings(settings)); + // } + }); +}); diff --git a/__test__/testUtils.js b/__test__/testUtils.js new file mode 100644 index 000000000..e667c7103 --- /dev/null +++ b/__test__/testUtils.js @@ -0,0 +1,174 @@ +import React from "react"; +import $ from "jquery"; +import assign from "object-assign"; +import { render } from "@testing-library/react"; +import Slider from "../src/slider"; +import { InnerSlider } from "../src/inner-slider"; +import defaultProps from "../src/default-props"; +import * as slickCarousel from "slick-carousel"; // defining slick in global environment +import { getTrackLeft } from "../src/utils/innerSliderUtils"; +import { + activeSlides, + getActiveSlidesCount, + clickNext, + clickPrevious +} from "../test-utils"; + +// finds active slide number in the last transition in the forward direction +export function activeSlideInLastTransition( + noOfSlides, + slidesToShow, + slidesToScroll +) { + let currentSlide = 0; + while (currentSlide < noOfSlides) { + currentSlide += slidesToScroll; + } + return currentSlide - slidesToScroll; +} + +// create jsx-form children for react slider +export function createReactSliderChildren(noOfSlides) { + return Array.from(Array(noOfSlides).keys()).map(i => ( +
+

{i + 1}

+
+ )); +} + +// create a react-slider with given noOfSlides and other props +// variable widths are ignored for now for simplicity +export function createReactSlider({ noOfSlides, ...props }) { + return {createReactSliderChildren(noOfSlides)}; +} + +// create a react inner-slider with given noOfSlides and other props +// performs most operations like the ones when mounted inside Slider component +export function createInnerSlider({ noOfSlides, ...settings }) { + if (settings.centerMode) { + settings.slidesToScroll = 1; // always scroll by one when centerMode is enabled + } + settings = assign({}, defaultProps, settings); + const children = React.Children.toArray( + createReactSliderChildren(noOfSlides) + ); + return {children}; +} + +export function createInnerSliderWrapper(settings) { + return render(createInnerSlider(settings)).container; +} + +// creates a dom string, containing children of slick children +export function createJQuerySliderChildren(noOfSlides) { + let children = []; + for (let i = 0; i < noOfSlides; i++) { + children.push(`

${i + 1}

`); + } + return children.join(""); +} + +// performs the very basic tests while clicking next or prev +export function testSliderScroll({ direction, ...settings }) { + const { noOfSlides, slidesToShow, slidesToScroll, initialSlide } = settings; + // initialize react slider + const { container } = render(createReactSlider(settings)); + // initialize jquery slider + document.body.innerHTML = ` +
+ ${createJQuerySliderChildren(noOfSlides)} +
+ `; + $(".regular.slider").slick({ + ...settings + }); + // console.log('setings:', settings) + + let expectedSlideIndex = initialSlide || 0; + for (let click = 0; click < 2 * noOfSlides + 2; click++) { + let activeslides = activeSlides(container); + let $activeSlides = $(".regular.slider").find("div.slick-active"); + expect(getActiveSlidesCount(container)).toEqual(slidesToShow || 1); + expect($activeSlides.length).toEqual(slidesToShow || 1); + let firstActiveSlide = activeslides[0]; + let $firstActiveSlide = $activeSlides.first(); + // console.log('classes', $firstActiveSlide.attr('data-slick-index')) + // console.warn('currentSlide:', firstActiveSlide.prop('data-index'), 'expected slide', expectedSlideIndex) + expect(parseInt(firstActiveSlide.getAttribute("data-index"))).toEqual( + expectedSlideIndex % noOfSlides + ); + expect(parseInt($firstActiveSlide.attr("data-slick-index"))).toEqual( + expectedSlideIndex % noOfSlides + ); + if (direction === "next") { + // click the next arrow button + clickNext(container); + $("button.slick-next").click(); + expectedSlideIndex += slidesToScroll || 1; + if (expectedSlideIndex >= noOfSlides) { + expectedSlideIndex = 0; + } + } else { + // click on the prev arrow button + clickPrevious(container); + $("button.slick-prev").click(); + expectedSlideIndex -= slidesToScroll || 1; + if (expectedSlideIndex < 0) { + expectedSlideIndex = activeSlideInLastTransition( + noOfSlides, + slidesToShow, + slidesToScroll + ); + } + } + } +} + +// function to run tests on a slider, +// scrolls slider to the right by clicking right arrow several times +// scrolls slider to the left by clicking left arrow several times +export function testSlider(settings) { + const settings1 = { direction: "next", ...settings }; + const settings2 = { direction: "prev", ...settings }; + testSliderScroll(settings1); + testSliderScroll(settings2); +} + +export const tryAllConfigs = (settings, settingsList) => { + let leaf = true; + for (let key of Object.keys(settings)) { + if (Array.isArray(settings[key])) { + leaf = false; + for (let val of settings[key]) { + tryAllConfigs({ ...settings, [key]: val }, settingsList); + } + } + } + if (leaf) { + if ( + settingsList + .map(setting => JSON.stringify(setting)) + .indexOf(JSON.stringify(settings)) < 0 + ) { + settingsList.push(settings); + } + } +}; + +export const actualTrackLeft = container => + container + .querySelector(".slick-track") + .style.transform.match(/translate3d\((\d+)px/i)[1]; + +export const testTrackLeft = container => { + let trackLeft = parseInt(actualTrackLeft(container)); + let spec = assign({}, wrapper.props(), wrapper.state(), { + slideIndex: wrapper.state().currentSlide, + trackRef: null + }); + let expectedTrackLeft = getTrackLeft(spec); + expect(trackLeft).toEqual(parseInt(expectedTrackLeft)); +}; +test("fake test", () => { + expect(1).toBe(1); +}); diff --git a/examples/__tests__/CentreMode.test.js b/examples/__tests__/CentreMode.test.js index 3a3b687b2..309501a36 100644 --- a/examples/__tests__/CentreMode.test.js +++ b/examples/__tests__/CentreMode.test.js @@ -20,7 +20,7 @@ describe("CenterMode Tests", () => { expect(totalSlides).toEqual(16); expect(clonedSlides).toEqual(10); expect(activeSlides).toEqual(3); - expect(beautify_html(toString(container))).toMatchSnapshot(); + //expect(beautify_html(toString(container))).toMatchSnapshot(); }); test("Positioning test", () => { const { container } = render(); @@ -30,7 +30,7 @@ describe("CenterMode Tests", () => { expect( Array.from(activeslides).map(e => parseInt(e.getAttribute("data-index"))) ).toEqual([-1, 0, 1]); - expect(beautify_html(toString(container))).toMatchSnapshot(); + //expect(beautify_html(toString(container))).toMatchSnapshot(); }); test("Activity test", () => { const { container } = render(); @@ -49,6 +49,6 @@ describe("CenterMode Tests", () => { Array.from(activeslides).map(e => parseInt(e.getAttribute("data-index"))) ).toEqual([0, 1, 2]); - expect(beautify_html(toString(container))).toMatchSnapshot(); + // expect(beautify_html(toString(container))).toMatchSnapshot(); }); }); diff --git a/examples/__tests__/FocusOnSelect.test.js b/examples/__tests__/FocusOnSelect.test.js index 3fd2e1291..6b307c22e 100644 --- a/examples/__tests__/FocusOnSelect.test.js +++ b/examples/__tests__/FocusOnSelect.test.js @@ -16,7 +16,7 @@ describe("FocusOnSelect Tests", () => { expect( parseInt(getCurrentSlide(container).getAttribute("data-index")) ).toEqual(0); - expect(beautify_html(toString(container))).toMatchSnapshot(); + // expect(beautify_html(toString(container))).toMatchSnapshot(); Array.from(container.getElementsByClassName("slick-slide")).map(e => e.getAttribute("data-index") == "2" ? fireEvent( @@ -28,6 +28,6 @@ describe("FocusOnSelect Tests", () => { expect( parseInt(getCurrentSlide(container).getAttribute("data-index")) ).toEqual(2); - expect(beautify_html(toString(container))).toMatchSnapshot(); + //expect(beautify_html(toString(container))).toMatchSnapshot(); }); }); diff --git a/examples/__tests__/MultipleItems.test.js b/examples/__tests__/MultipleItems.test.js index b1d8ca4bd..2cf97b70b 100644 --- a/examples/__tests__/MultipleItems.test.js +++ b/examples/__tests__/MultipleItems.test.js @@ -21,34 +21,34 @@ describe("Multiple Items", function() { const { container } = render(); expect(getSlidesCount(container)).toEqual(21); expect(getClonesCount(container)).toEqual(12); - expect(beautify_html(toString(container))).toMatchSnapshot(); + //expect(beautify_html(toString(container))).toMatchSnapshot(); }); it("should have 3 active slides", function() { const { container } = render(); expect(getActiveSlidesCount(container)).toEqual(3); - expect(beautify_html(toString(container))).toMatchSnapshot(); + // expect(beautify_html(toString(container))).toMatchSnapshot(); }); it("should have 3 dots", function() { const { container } = render(); expect(getButtonsLength(container)).toEqual(3); - expect(beautify_html(toString(container))).toMatchSnapshot(); + // expect(beautify_html(toString(container))).toMatchSnapshot(); }); it("should show first 3 slides", function() { const { container } = render(); expect(getActiveSlidesText(container)).toEqual(["1", "2", "3"]); - expect(beautify_html(toString(container))).toMatchSnapshot(); + // expect(beautify_html(toString(container))).toMatchSnapshot(); }); it("should show slides from 4 to 6 when next button is clicked", function() { const { container } = render(); clickNext(container); expect(getActiveSlidesText(container)).toEqual(["4", "5", "6"]); - expect(beautify_html(toString(container))).toMatchSnapshot(); + // expect(beautify_html(toString(container))).toMatchSnapshot(); }); it("should show last 3 slides when previous button is clicked", function() { const { container } = render(); clickPrevious(container); expect(getActiveSlidesText(container)).toEqual(["7", "8", "9"]); - expect(beautify_html(toString(container))).toMatchSnapshot(); + // expect(beautify_html(toString(container))).toMatchSnapshot(); }); it("should show slides first 3 slides when first dot is clicked", function() { const { container } = render(); @@ -60,7 +60,7 @@ describe("Multiple Items", function() { }) ); expect(getActiveSlidesText(container)).toEqual(["1", "2", "3"]); - expect(beautify_html(toString(container))).toMatchSnapshot(); + // expect(beautify_html(toString(container))).toMatchSnapshot(); }); it("should show slides from 4 to 6 when middle dot is clicked", function() { const { container } = render(); @@ -72,7 +72,7 @@ describe("Multiple Items", function() { }) ); expect(getActiveSlidesText(container)).toEqual(["4", "5", "6"]); - expect(beautify_html(toString(container))).toMatchSnapshot(); + // expect(beautify_html(toString(container))).toMatchSnapshot(); }); it("should show last 3 slides when last dot is clicked", function() { const { container } = render(); @@ -84,6 +84,6 @@ describe("Multiple Items", function() { }) ); expect(getActiveSlidesText(container)).toEqual(["7", "8", "9"]); - expect(beautify_html(toString(container))).toMatchSnapshot(); + // expect(beautify_html(toString(container))).toMatchSnapshot(); }); }); diff --git a/examples/__tests__/SimpleSlider.test.js b/examples/__tests__/SimpleSlider.test.js index 1834184b7..b39d4a23f 100644 --- a/examples/__tests__/SimpleSlider.test.js +++ b/examples/__tests__/SimpleSlider.test.js @@ -16,7 +16,7 @@ import { describe("SimpleSlider example", () => { it("should have 13 slides (1(preclone) + 6(actual) + 6(postclone))", function() { - const { container } = render(); + const { container } = render(); expect(container.getElementsByClassName("slick-slide").length).toBe(13); }); it("should have 7 clone slides", function() { @@ -101,17 +101,17 @@ describe("SimpleSlider example", () => { describe("Simple Slider Snapshots", function() { it("slider initial state", function() { const { container } = render(); - expect(beautify_html(toString(container))).toMatchSnapshot(); + // expect(beautify_html(toString(container))).toMatchSnapshot(); }); it("click on next button", function() { const { container } = render(); clickNext(container); - expect(beautify_html(toString(container))).toMatchSnapshot(); + //expect(beautify_html(toString(container))).toMatchSnapshot(); }); it("click on prev button", function() { const { container } = render(); clickPrevious(container); - expect(beautify_html(toString(container))).toMatchSnapshot(); + // expect(beautify_html(toString(container))).toMatchSnapshot(); }); it("click on 3rd dot", function() { const { container } = render(); @@ -122,6 +122,6 @@ describe("Simple Slider Snapshots", function() { cancelable: true }) ); - expect(beautify_html(toString(container))).toMatchSnapshot(); + // expect(beautify_html(toString(container))).toMatchSnapshot(); }); }); diff --git a/examples/__tests__/UnevenSets.test.js b/examples/__tests__/UnevenSets.test.js index 4d5937d67..a775026cb 100644 --- a/examples/__tests__/UnevenSets.test.js +++ b/examples/__tests__/UnevenSets.test.js @@ -24,7 +24,7 @@ describe("UnevenSets Finite", () => { expect(clonedSlides).toEqual(0); expect(activeSlides).toEqual(4); expect(dots).toEqual(2); - expect(beautify_html(toString(container))).toMatchSnapshot(); + // expect(beautify_html(toString(container))).toMatchSnapshot(); }); test("Positioning test", () => { const { container } = render(); @@ -36,7 +36,7 @@ describe("UnevenSets Finite", () => { parseInt(slide.getAttribute("data-index")) ) ).toEqual([0, 1, 2, 3]); - expect(beautify_html(toString(container))).toMatchSnapshot(); + //expect(beautify_html(toString(container))).toMatchSnapshot(); }); test("Activity test", () => { const { container } = render(); @@ -60,7 +60,18 @@ describe("UnevenSets Finite", () => { ) ).toEqual([2, 3, 4, 5]); - expect(beautify_html(toString(container))).toMatchSnapshot(); + clickNext(container); + + currentSlide = getCurrentSlide(container); + activeslides = activeSlides(container); + expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(4); + expect( + Array.from(activeslides).map(slide => + parseInt(slide.getAttribute("data-index")) + ) + ).toEqual([2, 3, 4, 5]); + + // expect(beautify_html(toString(container))).toMatchSnapshot(); }); }); @@ -75,7 +86,7 @@ describe("UnevenSets Infinite", () => { expect(clonedSlides).toEqual(10); expect(activeSlides).toEqual(4); expect(dots).toEqual(2); - expect(beautify_html(toString(container))).toMatchSnapshot(); + // expect(beautify_html(toString(container))).toMatchSnapshot(); }); test("Positioning test", () => { const { container } = render(); @@ -87,7 +98,7 @@ describe("UnevenSets Infinite", () => { parseInt(slide.getAttribute("data-index")) ) ).toEqual([0, 1, 2, 3]); - expect(beautify_html(toString(container))).toMatchSnapshot(); + // expect(beautify_html(toString(container))).toMatchSnapshot(); }); test("Activity test", () => { const { container } = render(); @@ -110,6 +121,6 @@ describe("UnevenSets Infinite", () => { parseInt(slide.getAttribute("data-index")) ) ).toEqual([4, 5, 6, 7]); - expect(beautify_html(toString(container))).toMatchSnapshot(); + // expect(beautify_html(toString(container))).toMatchSnapshot(); }); }); diff --git a/examples/__tests__/__snapshots__/CentreMode.test.js.snap b/examples/__tests__/__snapshots__/CentreMode.test.js.snap deleted file mode 100644 index e8d2091b9..000000000 --- a/examples/__tests__/__snapshots__/CentreMode.test.js.snap +++ /dev/null @@ -1,7 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`CenterMode Tests Activity test 1`] = `"[object Undefined]"`; - -exports[`CenterMode Tests Counting test 1`] = `"[object Undefined]"`; - -exports[`CenterMode Tests Positioning test 1`] = `"[object Undefined]"`; diff --git a/examples/__tests__/__snapshots__/FocusOnSelect.test.js.snap b/examples/__tests__/__snapshots__/FocusOnSelect.test.js.snap deleted file mode 100644 index c4ccc9821..000000000 --- a/examples/__tests__/__snapshots__/FocusOnSelect.test.js.snap +++ /dev/null @@ -1,5 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`FocusOnSelect Tests Activity Test 1`] = `"[object Undefined]"`; - -exports[`FocusOnSelect Tests Activity Test 2`] = `"[object Undefined]"`; diff --git a/examples/__tests__/__snapshots__/MultipleItems.test.js.snap b/examples/__tests__/__snapshots__/MultipleItems.test.js.snap deleted file mode 100644 index e58a31874..000000000 --- a/examples/__tests__/__snapshots__/MultipleItems.test.js.snap +++ /dev/null @@ -1,19 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Multiple Items should have 3 active slides 1`] = `"[object Undefined]"`; - -exports[`Multiple Items should have 3 dots 1`] = `"[object Undefined]"`; - -exports[`Multiple Items should have 9 actual slides and (3(pre) + 9(post)) clone slides 1`] = `"[object Undefined]"`; - -exports[`Multiple Items should show first 3 slides 1`] = `"[object Undefined]"`; - -exports[`Multiple Items should show last 3 slides when last dot is clicked 1`] = `"[object Undefined]"`; - -exports[`Multiple Items should show last 3 slides when previous button is clicked 1`] = `"[object Undefined]"`; - -exports[`Multiple Items should show slides first 3 slides when first dot is clicked 1`] = `"[object Undefined]"`; - -exports[`Multiple Items should show slides from 4 to 6 when middle dot is clicked 1`] = `"[object Undefined]"`; - -exports[`Multiple Items should show slides from 4 to 6 when next button is clicked 1`] = `"[object Undefined]"`; diff --git a/examples/__tests__/__snapshots__/SimpleSlider.test.js.snap b/examples/__tests__/__snapshots__/SimpleSlider.test.js.snap deleted file mode 100644 index a041ca679..000000000 --- a/examples/__tests__/__snapshots__/SimpleSlider.test.js.snap +++ /dev/null @@ -1,9 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`Simple Slider Snapshots click on 3rd dot 1`] = `"[object Undefined]"`; - -exports[`Simple Slider Snapshots click on next button 1`] = `"[object Undefined]"`; - -exports[`Simple Slider Snapshots click on prev button 1`] = `"[object Undefined]"`; - -exports[`Simple Slider Snapshots slider initial state 1`] = `"[object Undefined]"`; diff --git a/examples/__tests__/__snapshots__/UnevenSets.test.js.snap b/examples/__tests__/__snapshots__/UnevenSets.test.js.snap deleted file mode 100644 index dd3433336..000000000 --- a/examples/__tests__/__snapshots__/UnevenSets.test.js.snap +++ /dev/null @@ -1,13 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`UnevenSets Finite Activity test 1`] = `"[object Undefined]"`; - -exports[`UnevenSets Finite Counting test 1`] = `"[object Undefined]"`; - -exports[`UnevenSets Finite Positioning test 1`] = `"[object Undefined]"`; - -exports[`UnevenSets Infinite Activity test 1`] = `"[object Undefined]"`; - -exports[`UnevenSets Infinite Counting test 1`] = `"[object Undefined]"`; - -exports[`UnevenSets Infinite Positioning test 1`] = `"[object Undefined]"`; diff --git a/test-utils.js b/test-utils.js index 3b8c773e1..d2ee2616a 100644 --- a/test-utils.js +++ b/test-utils.js @@ -4,6 +4,10 @@ export function getSlidesCount(container) { return container.getElementsByClassName("slick-slide").length; } +export function getSlides(container) { + return container.getElementsByClassName("slick-slide"); +} + export function getClonesCount(container) { return container.getElementsByClassName("slick-cloned").length; } @@ -28,10 +32,13 @@ export function getButtonsLength(container) { } export function hasClass(element, classname) { if (element.className != undefined) { - return element.className == classname; + return element.classList.contains(classname); } return false; } +export function getCurrentSlideIdState(container) { + return parseInt(getCurrentSlide(container).getAttribute("data-index")) + 1; +} export function activeSlides(container) { return container.querySelectorAll(".slick-slide.slick-active"); } From 83423c8e0fd0121ab207eb2d08199f60684d6cb2 Mon Sep 17 00:00:00 2001 From: Pratyush Bhatnagar <38534434+pratyushbh@users.noreply.github.com> Date: Fri, 19 May 2023 13:16:54 +0530 Subject: [PATCH 18/58] removed the console logs --- __test__/beforeChange.test.js | 9 --------- __test__/mount/centerMode.test.js | 1 - __test__/mount/lazyLoad.test.js | 1 + examples/__tests__/MultipleItems.test.js | 12 +++++++++++- test-utils.js | 5 +++++ 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/__test__/beforeChange.test.js b/__test__/beforeChange.test.js index b54a130a6..acda7b266 100644 --- a/__test__/beforeChange.test.js +++ b/__test__/beforeChange.test.js @@ -40,18 +40,9 @@ describe("Slider", function() { const { container } = render(); clickNext(container); expect(activeSlide(container).textContent).toEqual("slide2"); - console.log( - parseInt(getCurrentSlide(container).getAttribute("data-index")) - ); clickNext(container); expect(activeSlide(container).textContent).toEqual("slide3"); - console.log( - parseInt(getCurrentSlide(container).getAttribute("data-index")) - ); clickPrevious(container); expect(activeSlide(container).textContent).toEqual("slide2"); - console.log( - parseInt(getCurrentSlide(container).getAttribute("data-index")) - ); }); }); diff --git a/__test__/mount/centerMode.test.js b/__test__/mount/centerMode.test.js index 07873dc19..a5bfb4988 100644 --- a/__test__/mount/centerMode.test.js +++ b/__test__/mount/centerMode.test.js @@ -25,7 +25,6 @@ let keys = { const testsUtil = (settings, actions, keys) => { const jqDetails = getJQuerySlickDetails(settings, actions, keys); const reactDetails = getReactSlickDetails(settings, actions, keys); - console.log(reactDetails, jqDetails); test("checking current slide jQuery vs react", () => { //currentSlide of react is 1 times more than currentSlide of JQuery expect(parseInt(reactDetails.currentSlide) - 1).toEqual( diff --git a/__test__/mount/lazyLoad.test.js b/__test__/mount/lazyLoad.test.js index 8376a7933..2aa6445df 100644 --- a/__test__/mount/lazyLoad.test.js +++ b/__test__/mount/lazyLoad.test.js @@ -26,6 +26,7 @@ const testsUtil = (settings, actions, keys) => { const jqDetails = getJQuerySlickDetails(settings, actions, keys); const reactDetails = getReactSlickDetails(settings, actions, keys); test.skip("checking current slide jQuery vs react", () => { + //currentSlide of react is 1 times more than currentSlide of JQuery expect(parseInt(reactDetails.currentSlide) - 1).toEqual( parseInt(jqDetails.currentSlide) ); diff --git a/examples/__tests__/MultipleItems.test.js b/examples/__tests__/MultipleItems.test.js index 2cf97b70b..1adc83daa 100644 --- a/examples/__tests__/MultipleItems.test.js +++ b/examples/__tests__/MultipleItems.test.js @@ -6,13 +6,16 @@ import { activeSlides, clickNext, clickPrevious, + getActiveButton, getActiveSlidesCount, getActiveSlidesText, getButtons, getButtonsLength, + getButtonsListItem, getClonesCount, getCurrentSlide, - getSlidesCount + getSlidesCount, + hasClass } from "../../test-utils"; import MultipleItems from "../MultipleItems"; @@ -35,18 +38,22 @@ describe("Multiple Items", function() { }); it("should show first 3 slides", function() { const { container } = render(); + expect(getActiveButton(container)).toEqual(["1"]); 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(); clickNext(container); + // Array.from(container.querySelectorAll(".slick-current")).map(e=>console.log(e.textContent)) + expect(getActiveButton(container)).toEqual(["2"]); 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(); clickPrevious(container); + expect(getActiveButton(container)).toEqual(["3"]); expect(getActiveSlidesText(container)).toEqual(["7", "8", "9"]); // expect(beautify_html(toString(container))).toMatchSnapshot(); }); @@ -59,6 +66,7 @@ describe("Multiple Items", function() { cancelable: true }) ); + expect(getActiveButton(container)).toEqual(["1"]); expect(getActiveSlidesText(container)).toEqual(["1", "2", "3"]); // expect(beautify_html(toString(container))).toMatchSnapshot(); }); @@ -71,6 +79,7 @@ describe("Multiple Items", function() { cancelable: true }) ); + expect(getActiveButton(container)).toEqual(["2"]); expect(getActiveSlidesText(container)).toEqual(["4", "5", "6"]); // expect(beautify_html(toString(container))).toMatchSnapshot(); }); @@ -83,6 +92,7 @@ describe("Multiple Items", function() { cancelable: true }) ); + expect(getActiveButton(container)).toEqual(["3"]); expect(getActiveSlidesText(container)).toEqual(["7", "8", "9"]); // expect(beautify_html(toString(container))).toMatchSnapshot(); }); diff --git a/test-utils.js b/test-utils.js index d2ee2616a..bd83f7e7a 100644 --- a/test-utils.js +++ b/test-utils.js @@ -36,6 +36,11 @@ export function hasClass(element, classname) { } return false; } +export function getActiveButton(container) { + return Array.from( + container.querySelectorAll(".slick-dots .slick-active button") + ).map(e => e.textContent); +} export function getCurrentSlideIdState(container) { return parseInt(getCurrentSlide(container).getAttribute("data-index")) + 1; } From b03b477f29c195902086ab0ca05648807b57003a Mon Sep 17 00:00:00 2001 From: akiran Date: Sun, 21 May 2023 09:51:59 +0530 Subject: [PATCH 19/58] renamed few test utils --- __test__/afterChange.test.js | 9 ++++----- __test__/beforeChange.test.js | 8 ++++---- __test__/testUtils.js | 4 ++-- examples/__tests__/CentreMode.test.js | 8 ++++---- examples/__tests__/Fade.js | 8 ++++---- examples/__tests__/SimpleSlider.test.js | 4 ++-- examples/__tests__/SlickGoTo.test.js | 6 +++--- examples/__tests__/UnevenSets.test.js | 16 ++++++++-------- test-utils.js | 16 ++++++++-------- 9 files changed, 39 insertions(+), 40 deletions(-) diff --git a/__test__/afterChange.test.js b/__test__/afterChange.test.js index d3998459f..5485ec9d9 100644 --- a/__test__/afterChange.test.js +++ b/__test__/afterChange.test.js @@ -2,7 +2,7 @@ import React from "react"; import { render, fireEvent } from "@testing-library/react"; import Slider from "../src/index"; import { - activeSlide, + getActiveSlide, clickNext, clickPrevious, getCurrentSlide @@ -43,16 +43,15 @@ describe("After change Slider", function() { const { container } = render(); clickNext(container); setTimeout(() => { - expect(activeSlide(container).textContent).toEqual("slide2"); + expect(getActiveSlide(container).textContent).toEqual("slide2"); }, 1000); clickNext(container); setTimeout(() => { - console.log(activeSlide(container).textContent); - expect(activeSlide(container).textContent).toEqual("slide3"); + expect(getActiveSlide(container).textContent).toEqual("slide3"); }, 1000); clickPrevious(container); setTimeout(() => { - expect(activeSlide(container).textContent).toEqual("slide2"); + expect(getActiveSlide(container).textContent).toEqual("slide2"); }, 1000); }); }); diff --git a/__test__/beforeChange.test.js b/__test__/beforeChange.test.js index acda7b266..9e283d36a 100644 --- a/__test__/beforeChange.test.js +++ b/__test__/beforeChange.test.js @@ -2,7 +2,7 @@ import React from "react"; import { render } from "@testing-library/react"; import Slider from "../src/index"; import { - activeSlide, + getActiveSlide, clickNext, clickPrevious, getCurrentSlide @@ -39,10 +39,10 @@ describe("Slider", function() { it("should render", function() { const { container } = render(); clickNext(container); - expect(activeSlide(container).textContent).toEqual("slide2"); + expect(getActiveSlide(container).textContent).toEqual("slide2"); clickNext(container); - expect(activeSlide(container).textContent).toEqual("slide3"); + expect(getActiveSlide(container).textContent).toEqual("slide3"); clickPrevious(container); - expect(activeSlide(container).textContent).toEqual("slide2"); + expect(getActiveSlide(container).textContent).toEqual("slide2"); }); }); diff --git a/__test__/testUtils.js b/__test__/testUtils.js index e667c7103..9778d34f4 100644 --- a/__test__/testUtils.js +++ b/__test__/testUtils.js @@ -8,7 +8,7 @@ import defaultProps from "../src/default-props"; import * as slickCarousel from "slick-carousel"; // defining slick in global environment import { getTrackLeft } from "../src/utils/innerSliderUtils"; import { - activeSlides, + getActiveSlides, getActiveSlidesCount, clickNext, clickPrevious @@ -86,7 +86,7 @@ export function testSliderScroll({ direction, ...settings }) { let expectedSlideIndex = initialSlide || 0; for (let click = 0; click < 2 * noOfSlides + 2; click++) { - let activeslides = activeSlides(container); + let activeslides = getActiveSlides(container); let $activeSlides = $(".regular.slider").find("div.slick-active"); expect(getActiveSlidesCount(container)).toEqual(slidesToShow || 1); expect($activeSlides.length).toEqual(slidesToShow || 1); diff --git a/examples/__tests__/CentreMode.test.js b/examples/__tests__/CentreMode.test.js index 309501a36..d2c3c5191 100644 --- a/examples/__tests__/CentreMode.test.js +++ b/examples/__tests__/CentreMode.test.js @@ -3,7 +3,7 @@ import CenterMode from "../CenterMode"; import { render } from "@testing-library/react"; import { html as beautify_html } from "js-beautify"; import { - activeSlides, + getActiveSlides, getActiveSlidesCount, getClonesCount, getCurrentSlide, @@ -25,7 +25,7 @@ describe("CenterMode Tests", () => { test("Positioning test", () => { const { container } = render(); let currentSlide = getCurrentSlide(container); - let activeslides = activeSlides(container); + let activeslides = getActiveSlides(container); expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(0); expect( Array.from(activeslides).map(e => parseInt(e.getAttribute("data-index"))) @@ -35,7 +35,7 @@ describe("CenterMode Tests", () => { test("Activity test", () => { const { container } = render(); let currentSlide = getCurrentSlide(container); - let activeslides = activeSlides(container); + let activeslides = getActiveSlides(container); expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(0); expect( Array.from(activeslides).map(e => parseInt(e.getAttribute("data-index"))) @@ -43,7 +43,7 @@ describe("CenterMode Tests", () => { clickNext(container); currentSlide = getCurrentSlide(container); - activeslides = activeSlides(container); + activeslides = getActiveSlides(container); expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(1); expect( Array.from(activeslides).map(e => parseInt(e.getAttribute("data-index"))) diff --git a/examples/__tests__/Fade.js b/examples/__tests__/Fade.js index 2181ede70..038f9c403 100644 --- a/examples/__tests__/Fade.js +++ b/examples/__tests__/Fade.js @@ -1,18 +1,18 @@ import React from "react"; import { render } from "@testing-library/react"; import Fade from "../Fade"; -import { activeSlide, clickNext, clickPrevious } from "../../test-utils"; +import { getActiveSlide, clickNext, clickPrevious } from "../../test-utils"; describe("Fade", () => { it("should change slides when clicked on next & prev buttons", () => { const { container } = render(); - let activeslide = activeSlide(container); + let activeslide = getActiveSlide(container); expect(parseInt(activeslide.getAttribute("data-index"))).toEqual(0); clickNext(container); - activeslide = activeSlide(container); + activeslide = getActiveSlide(container); expect(parseInt(activeslide.getAttribute("data-index"))).toEqual(1); clickPrevious(container); - activeslide = activeSlide(container); + activeslide = getActiveSlide(container); expect(parseInt(activeslide.getAttribute("data-index"))).toEqual(0); }); }); diff --git a/examples/__tests__/SimpleSlider.test.js b/examples/__tests__/SimpleSlider.test.js index b39d4a23f..edfbca4fa 100644 --- a/examples/__tests__/SimpleSlider.test.js +++ b/examples/__tests__/SimpleSlider.test.js @@ -3,7 +3,7 @@ import SimpleSlider from "../SimpleSlider"; import { render, fireEvent, waitFor, screen } from "@testing-library/react"; import { html as beautify_html } from "js-beautify"; import { - activeSlide, + getActiveSlide, clickNext, clickPrevious, hasClass, @@ -29,7 +29,7 @@ describe("SimpleSlider example", () => { 1 ); expect( - Array.from(activeSlide(container).children).map( + Array.from(getActiveSlide(container).children).map( e => parseInt(e.textContent) - 1 )[0] ).toBe(0); diff --git a/examples/__tests__/SlickGoTo.test.js b/examples/__tests__/SlickGoTo.test.js index 8f0cd74a6..9234ff3b9 100644 --- a/examples/__tests__/SlickGoTo.test.js +++ b/examples/__tests__/SlickGoTo.test.js @@ -10,7 +10,7 @@ describe.skip("SlickGoTo", () => { target: { value: 1 } }); let currentImg = Array.from( - activeSlide(container).getElementsByTagName("img") + getActiveSlide(container).getElementsByTagName("img") )[0]; expect(currentImg.getAttribute("src")).toEqual( "/img/react-slick/abstract02.jpg" @@ -22,7 +22,7 @@ describe.skip("SlickGoTo", () => { target: { value: "1" } }); let currentImg = Array.from( - activeSlide(container).getElementsByTagName("img") + getActiveSlide(container).getElementsByTagName("img") )[0]; expect(currentImg.getAttribute("src")).toEqual( "/img/react-slick/abstract02.jpg" @@ -34,7 +34,7 @@ describe.skip("SlickGoTo", () => { target: { value: 0 } }); let currentImg = Array.from( - activeSlide(container).getElementsByTagName("img") + getActiveSlide(container).getElementsByTagName("img") )[0]; expect(currentImg.getAttribute("src")).toEqual( "/img/react-slick/abstract01.jpg" diff --git a/examples/__tests__/UnevenSets.test.js b/examples/__tests__/UnevenSets.test.js index a775026cb..eff2f9dcf 100644 --- a/examples/__tests__/UnevenSets.test.js +++ b/examples/__tests__/UnevenSets.test.js @@ -4,7 +4,7 @@ import UnevenSetsFinite from "../UnevenSetsFinite"; import UnevenSetsInfinite from "../UnevenSetsInfinite"; import { html as beautify_html } from "js-beautify"; import { - activeSlides, + getActiveSlides, clickNext, getActiveSlidesCount, getButtonsLength, @@ -29,7 +29,7 @@ describe("UnevenSets Finite", () => { test("Positioning test", () => { const { container } = render(); let currentSlide = getCurrentSlide(container); - let activeslides = activeSlides(container); + let activeslides = getActiveSlides(container); expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(0); expect( Array.from(activeslides).map(slide => @@ -41,7 +41,7 @@ describe("UnevenSets Finite", () => { test("Activity test", () => { const { container } = render(); let currentSlide = getCurrentSlide(container); - let activeslides = activeSlides(container); + let activeslides = getActiveSlides(container); expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(0); expect( Array.from(activeslides).map(slide => @@ -52,7 +52,7 @@ describe("UnevenSets Finite", () => { clickNext(container); currentSlide = getCurrentSlide(container); - activeslides = activeSlides(container); + activeslides = getActiveSlides(container); expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(4); expect( Array.from(activeslides).map(slide => @@ -63,7 +63,7 @@ describe("UnevenSets Finite", () => { clickNext(container); currentSlide = getCurrentSlide(container); - activeslides = activeSlides(container); + activeslides = getActiveSlides(container); expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(4); expect( Array.from(activeslides).map(slide => @@ -91,7 +91,7 @@ describe("UnevenSets Infinite", () => { test("Positioning test", () => { const { container } = render(); let currentSlide = getCurrentSlide(container); - let activeslides = activeSlides(container); + let activeslides = getActiveSlides(container); expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(0); expect( Array.from(activeslides).map(slide => @@ -103,7 +103,7 @@ describe("UnevenSets Infinite", () => { test("Activity test", () => { const { container } = render(); let currentSlide = getCurrentSlide(container); - let activeslides = activeSlides(container); + let activeslides = getActiveSlides(container); expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(0); expect( Array.from(activeslides).map(slide => @@ -114,7 +114,7 @@ describe("UnevenSets Infinite", () => { clickNext(container); currentSlide = getCurrentSlide(container); - activeslides = activeSlides(container); + activeslides = getActiveSlides(container); expect(parseInt(currentSlide.getAttribute("data-index"))).toEqual(4); expect( Array.from(activeslides).map(slide => diff --git a/test-utils.js b/test-utils.js index bd83f7e7a..71286463f 100644 --- a/test-utils.js +++ b/test-utils.js @@ -41,13 +41,13 @@ export function getActiveButton(container) { container.querySelectorAll(".slick-dots .slick-active button") ).map(e => e.textContent); } -export function getCurrentSlideIdState(container) { - return parseInt(getCurrentSlide(container).getAttribute("data-index")) + 1; -} -export function activeSlides(container) { - return container.querySelectorAll(".slick-slide.slick-active"); -} -export function activeSlide(container) { +// export function getCurrentSlideIdState(container) { +// return parseInt(getCurrentSlide(container).getAttribute("data-index")) + 1; +// } +// export function activeSlides(container) { +// return container.querySelectorAll(".slick-slide.slick-active"); +// } +export function getActiveSlide(container) { return container.querySelector(".slick-slide.slick-active"); } @@ -56,7 +56,7 @@ export function getActiveSlides(container) { } export function getActiveSlidesText(container) { - const slides = activeSlides(container); + const slides = getActiveSlides(container); return Array.from(slides).map(e => e.textContent); } From e6b231a2eb83363471c4a41e9dcf86a3c1a36c48 Mon Sep 17 00:00:00 2001 From: akiran Date: Sun, 21 May 2023 10:01:24 +0530 Subject: [PATCH 20/58] fix current slide issue --- __test__/afterChange.test.js | 3 --- __test__/mount/centerMode.test.js | 5 +---- __test__/mount/lazyLoad.test.js | 5 +---- __test__/mount/simple.test.js | 5 +---- __test__/reactSlickUtils.js | 5 ++++- 5 files changed, 7 insertions(+), 16 deletions(-) diff --git a/__test__/afterChange.test.js b/__test__/afterChange.test.js index 5485ec9d9..949b0d1cc 100644 --- a/__test__/afterChange.test.js +++ b/__test__/afterChange.test.js @@ -35,9 +35,6 @@ class SliderWithAfterChange extends React.Component { } } -test("fake test", () => { - expect(1).toBe(1); -}); describe("After change Slider", function() { it("should render", function() { const { container } = render(); diff --git a/__test__/mount/centerMode.test.js b/__test__/mount/centerMode.test.js index a5bfb4988..aab6601d5 100644 --- a/__test__/mount/centerMode.test.js +++ b/__test__/mount/centerMode.test.js @@ -26,10 +26,7 @@ const testsUtil = (settings, actions, keys) => { const jqDetails = getJQuerySlickDetails(settings, actions, keys); const reactDetails = getReactSlickDetails(settings, actions, keys); test("checking current slide jQuery vs react", () => { - //currentSlide of react is 1 times more than currentSlide of JQuery - expect(parseInt(reactDetails.currentSlide) - 1).toEqual( - parseInt(jqDetails.currentSlide) - ); + expect(reactDetails.currentSlide).toEqual(parseInt(jqDetails.currentSlide)); }); test("checking active slides jQuery vs react", () => { expect(reactDetails.activeSlides).toEqual(jqDetails.activeSlides); diff --git a/__test__/mount/lazyLoad.test.js b/__test__/mount/lazyLoad.test.js index 2aa6445df..33674a794 100644 --- a/__test__/mount/lazyLoad.test.js +++ b/__test__/mount/lazyLoad.test.js @@ -26,10 +26,7 @@ const testsUtil = (settings, actions, keys) => { const jqDetails = getJQuerySlickDetails(settings, actions, keys); const reactDetails = getReactSlickDetails(settings, actions, keys); test.skip("checking current slide jQuery vs react", () => { - //currentSlide of react is 1 times more than currentSlide of JQuery - expect(parseInt(reactDetails.currentSlide) - 1).toEqual( - parseInt(jqDetails.currentSlide) - ); + expect(reactDetails.currentSlide).toEqual(parseInt(jqDetails.currentSlide)); }); test.skip("checking active slides jQuery vs react", () => { expect(reactDetails.activeSlides).toEqual(jqDetails.activeSlides); diff --git a/__test__/mount/simple.test.js b/__test__/mount/simple.test.js index 84257bad6..f1facd598 100644 --- a/__test__/mount/simple.test.js +++ b/__test__/mount/simple.test.js @@ -25,10 +25,7 @@ const testsUtil = (settings, actions, keys) => { const jqDetails = getJQuerySlickDetails(settings, actions, keys); const reactDetails = getReactSlickDetails(settings, actions, keys); test("checking current slide jQuery vs react", () => { - //currentSlide of react is 1 times more than currentSlide of JQuery - expect(parseInt(reactDetails.currentSlide) - 1).toEqual( - parseInt(jqDetails.currentSlide) - ); + expect(reactDetails.currentSlide).toEqual(parseInt(jqDetails.currentSlide)); }); test("checking active slides jQuery vs react", () => { expect(reactDetails.activeSlides).toEqual(jqDetails.activeSlides); diff --git a/__test__/reactSlickUtils.js b/__test__/reactSlickUtils.js index aac2caf5c..9daa3c85a 100644 --- a/__test__/reactSlickUtils.js +++ b/__test__/reactSlickUtils.js @@ -37,7 +37,10 @@ function simulateActions(slider, actions) { function fetchDetails(container, keys) { let details = { ...fetchDOMDetails(container, keys) }; if (keys.currentSlide) { - details.currentSlide = getCurrentSlide(container).textContent; + // details.currentSlide = getCurrentSlide(container).textContent; + details.currentSlide = parseInt( + getCurrentSlide(container).getAttribute("data-index") + ); } return details; } From e45defbc7b7fd7f79ede7170ebe22bb28f3d964c Mon Sep 17 00:00:00 2001 From: akiran Date: Sun, 21 May 2023 10:09:18 +0530 Subject: [PATCH 21/58] added a comment --- __test__/mount/simple.test.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/__test__/mount/simple.test.js b/__test__/mount/simple.test.js index f1facd598..9b9001f78 100644 --- a/__test__/mount/simple.test.js +++ b/__test__/mount/simple.test.js @@ -71,6 +71,9 @@ describe("InnerSlider component tests: Part 7", () => { actions.clickSequence = ["n", "n", "n", "n", "n", "n", "p", "p", "p"]; testsUtil(settings, actions, keys); }); + +//TODO: old tests used this sequence `actions.clickSequence = ["p", "p", "p", "p", "p", "p", "n", "n", "n"];` +// Debug why tests failing with that sequence describe("InnerSlider component tests: Part 8", () => { actions.clickSequence = ["p", "p", "p", "p", "p", "p", "p", "n", "n", "n"]; testsUtil(settings, actions, keys); From 9c52885895f081e88356c179a048f81ec139ae08 Mon Sep 17 00:00:00 2001 From: akiran Date: Tue, 23 May 2023 12:44:25 +0530 Subject: [PATCH 22/58] Fixed 2231: Move build script from prepublish -> prepublishOnly --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 95be2dfe2..eea87e83a 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "build-dev": "gulp clean && gulp copy && webpack", "lib": "babel ./src --out-dir ./lib", "build": "npm run lib && gulp dist", - "prepublish": "npm run build", + "prepublishOnly": "npm run build", "lint": "eslint src", "gen": "node examples/scripts/generateExampleConfigs.js && node examples/scripts/generateExamples.js && xdg-open docs/jquery.html", "precommit": "lint-staged", From f880fba175b443c00bdb82aaa1616e570666aa09 Mon Sep 17 00:00:00 2001 From: Pratyush Bhatnagar <38534434+pratyushbh@users.noreply.github.com> Date: Thu, 25 May 2023 16:11:58 +0530 Subject: [PATCH 23/58] wrote the tests of #1874 that came out to be successful --- examples/SimpleSlider.js | 1 + examples/__tests__/SimpleSlider.test.js | 26 ++++++++++++++++--------- src/inner-slider.js | 6 ++++-- 3 files changed, 22 insertions(+), 11 deletions(-) diff --git a/examples/SimpleSlider.js b/examples/SimpleSlider.js index 013344162..92d10fbca 100644 --- a/examples/SimpleSlider.js +++ b/examples/SimpleSlider.js @@ -7,6 +7,7 @@ export default class SimpleSlider extends Component { dots: true, infinite: true, speed: 500, + initialSlide: 2, slidesToShow: 1, slidesToScroll: 1 }; diff --git a/examples/__tests__/SimpleSlider.test.js b/examples/__tests__/SimpleSlider.test.js index edfbca4fa..6e5ac8540 100644 --- a/examples/__tests__/SimpleSlider.test.js +++ b/examples/__tests__/SimpleSlider.test.js @@ -11,7 +11,8 @@ import { getActiveSlidesCount, getActiveSlidesText, getButtons, - getButtonsListItem + getButtonsListItem, + getCurrentSlide } from "../../test-utils"; describe("SimpleSlider example", () => { @@ -23,7 +24,14 @@ describe("SimpleSlider example", () => { const { container } = render(); expect(container.getElementsByClassName("slick-cloned").length).toBe(7); }); - it("should have 1 active slide", function() { + it("should have 1 current slide(When initialSlide is 2)", function() { + const { container } = render(); + expect( + container.querySelectorAll(".slick-slide.slick-current").length + ).toBe(1); + expect(parseInt(getCurrentSlide(container).textContent) - 1).toBe(2); + }); + it("should have 1 active slide(When initialSlide is 2)", function() { const { container } = render(); expect(container.querySelectorAll(".slick-slide.slick-active").length).toBe( 1 @@ -32,7 +40,7 @@ describe("SimpleSlider example", () => { Array.from(getActiveSlide(container).children).map( e => parseInt(e.textContent) - 1 )[0] - ).toBe(0); + ).toBe(2); }); it("should have 6 dots", function() { const { container } = render(); @@ -55,30 +63,30 @@ describe("SimpleSlider example", () => { const { container } = render(); expect(container.getElementsByClassName("slick-next").length).toBe(1); }); - it("should got to second slide when next button is clicked", function() { + it("should got to next slide when next button is clicked", function() { const { container } = render(); clickNext(container); expect( container.querySelectorAll(".slick-slide.slick-active")[0].textContent - ).toBe("2"); + ).toBe("4"); expect(container.querySelectorAll(".slick-dots .slick-active").length).toBe( 1 ); expect( - container.querySelectorAll(".slick-dots")[0].children[1] + container.querySelectorAll(".slick-dots")[0].children[3] ).toHaveClass("slick-active"); }); - it("should goto last slide when prev button is clicked", function() { + it("should goto previous slide when prev button is clicked", function() { const { container } = render(); clickPrevious(container); expect( container.querySelectorAll(".slick-slide.slick-active")[0].textContent - ).toBe("6"); + ).toBe("2"); expect(container.querySelectorAll(".slick-dots .slick-active").length).toBe( 1 ); expect( - container.querySelectorAll(".slick-dots")[0].children[5] + container.querySelectorAll(".slick-dots")[0].children[1] ).toHaveClass("slick-active"); }); it("should goto 4th slide when 4th dot is clicked", function() { diff --git a/src/inner-slider.js b/src/inner-slider.js index 79b9dc987..aba39da9d 100644 --- a/src/inner-slider.js +++ b/src/inner-slider.js @@ -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 = []; @@ -304,7 +305,8 @@ export class InnerSlider extends React.Component { }; checkImagesLoad = () => { let images = - (this.list && this.list.querySelectorAll && + (this.list && + this.list.querySelectorAll && this.list.querySelectorAll(".slick-slide img")) || []; let imagesCount = images.length, @@ -316,7 +318,7 @@ export class InnerSlider extends React.Component { image.onclick = () => image.parentNode.focus(); } else { const prevClickHandler = image.onclick; - image.onclick = (e) => { + image.onclick = e => { prevClickHandler(e); image.parentNode.focus(); }; From f5bb03067d419762a906937dd41f768b769cc609 Mon Sep 17 00:00:00 2001 From: Pratyush Bhatnagar <38534434+pratyushbh@users.noreply.github.com> Date: Tue, 30 May 2023 16:36:44 +0530 Subject: [PATCH 24/58] Converted the examples to Functional component and created new SliderComponent in root test folder to test slider with various settings at a single place --- __test__/SliderComponent.js | 33 +++ __test__/SliderComponent.test.js | 292 ++++++++++++++++++++++++ examples/AdaptiveHeight.js | 79 ++++--- examples/AppendDots.js | 111 +++++---- examples/AsNavFor.js | 139 ++++++----- examples/AutoPlay.js | 78 +++---- examples/AutoPlayMethods.js | 104 ++++----- examples/CenterMode.js | 72 +++--- examples/CustomArrows.js | 72 +++--- examples/CustomPaging.js | 74 +++--- examples/CustomSlides.js | 62 +++-- examples/DynamicSlides.js | 82 +++---- examples/Fade.js | 64 +++--- examples/FocusOnSelect.js | 72 +++--- examples/LazyLoad.js | 62 ++--- examples/MultipleItems.js | 90 ++++---- examples/MultipleRows.js | 138 +++++------ examples/PauseOnHover.js | 74 +++--- examples/PreviousNextMethods.js | 99 ++++---- examples/Resizable.js | 134 +++++------ examples/Responsive.js | 136 +++++------ examples/Rtl.js | 76 +++--- examples/SimpleSlider.js | 74 +++--- examples/SlickGoTo.js | 93 ++++---- examples/SlideChangeHooks.js | 107 ++++----- examples/SwipeToSlide.js | 98 ++++---- examples/UnevenSetsFinite.js | 72 +++--- examples/UnevenSetsInfinite.js | 72 +++--- examples/VariableWidth.js | 76 +++--- examples/VerticalMode.js | 84 +++---- examples/VerticalSwipeToSlide.js | 86 +++---- examples/__tests__/SimpleSlider.test.js | 16 +- 32 files changed, 1605 insertions(+), 1316 deletions(-) create mode 100644 __test__/SliderComponent.js create mode 100644 __test__/SliderComponent.test.js diff --git a/__test__/SliderComponent.js b/__test__/SliderComponent.js new file mode 100644 index 000000000..54ec971f0 --- /dev/null +++ b/__test__/SliderComponent.js @@ -0,0 +1,33 @@ +import React from "react"; +import Slider from "../src/slider"; + +function SliderComponent(props) { + const { settings } = props; + return ( +
+

Slider

+ +
+

1

+
+
+

2

+
+
+

3

+
+
+

4

+
+
+

5

+
+
+

6

+
+
+
+ ); +} + +export default SliderComponent; diff --git a/__test__/SliderComponent.test.js b/__test__/SliderComponent.test.js new file mode 100644 index 000000000..b53bc9c8d --- /dev/null +++ b/__test__/SliderComponent.test.js @@ -0,0 +1,292 @@ +import React from "react"; +import SliderComponent from "./SliderComponent"; +import { render, fireEvent } from "@testing-library/react"; +import { + getActiveSlide, + clickNext, + clickPrevious, + hasClass, + getActiveSlides, + getActiveSlidesCount, + getActiveSlidesText, + getButtons, + getButtonsListItem, + getCurrentSlide +} from "../test-utils"; + +describe("SliderComponent Tests with different settings", () => { + it("(SimpleSliderTest) should have 13 slides (1(preclone) + 6(actual) + 6(postclone))", function() { + const settings = { + dots: true, + infinite: true, + speed: 500, + slidesToShow: 1, + slidesToScroll: 1 + }; + const { container } = render(); + expect(container.getElementsByClassName("slick-slide").length).toBe(13); + }); + it("(SimpleSliderTest) should have 7 clone slides", function() { + const settings = { + dots: true, + infinite: true, + speed: 500, + slidesToShow: 1, + slidesToScroll: 1 + }; + const { container } = render(); + expect(container.getElementsByClassName("slick-cloned").length).toBe(7); + }); + it("(SimpleSliderTest) should have 1 current slide", function() { + const settings = { + dots: true, + infinite: true, + speed: 500, + slidesToShow: 1, + slidesToScroll: 1 + }; + const { container } = render(); + expect( + container.querySelectorAll(".slick-slide.slick-current").length + ).toBe(1); + expect(parseInt(getCurrentSlide(container).textContent) - 1).toBe(0); + }); + it("(SimpleSliderTest) should have 1 active slide", function() { + const settings = { + dots: true, + infinite: true, + speed: 500, + slidesToShow: 1, + slidesToScroll: 1 + }; + const { container } = render(); + expect(container.querySelectorAll(".slick-slide.slick-active").length).toBe( + 1 + ); + expect( + Array.from(getActiveSlide(container).children).map( + e => parseInt(e.textContent) - 1 + )[0] + ).toBe(0); + }); + it("(SimpleSliderTest) should have 1 current slide(When initialSlide is 2)", function() { + const settings = { + dots: true, + infinite: true, + speed: 500, + slidesToShow: 1, + slidesToScroll: 1, + initialSlide: 2 + }; + const { container } = render(); + expect( + container.querySelectorAll(".slick-slide.slick-current").length + ).toBe(1); + expect(parseInt(getCurrentSlide(container).textContent) - 1).toBe(2); + }); + it("(SimpleSliderTest) should have 1 active slide(When initialSlide is 2)", function() { + const settings = { + dots: true, + infinite: true, + speed: 500, + slidesToShow: 1, + slidesToScroll: 1, + initialSlide: 2 + }; + const { container } = render(); + expect(container.querySelectorAll(".slick-slide.slick-active").length).toBe( + 1 + ); + expect( + Array.from(getActiveSlide(container).children).map( + e => parseInt(e.textContent) - 1 + )[0] + ).toBe(2); + expect( + Array.from(getActiveSlide(container).children).map( + e => parseInt(e.textContent) - 1 + )[0] + ).toBe(2); + }); + it("(SimpleSliderTest) should have 6 dots", function() { + const settings = { + dots: true, + infinite: true, + speed: 500, + slidesToShow: 1, + slidesToScroll: 1 + }; + const { container } = render(); + expect( + container.getElementsByClassName("slick-dots")[0].children.length + ).toBe(6); + }); + it("(SimpleSliderTest) should have 1 active dot", function() { + const settings = { + dots: true, + infinite: true, + speed: 500, + slidesToShow: 1, + slidesToScroll: 1 + }; + const { container } = render(); + + expect(container.querySelectorAll(".slick-dots .slick-active").length).toBe( + 1 + ); + }); + it("(SimpleSliderTest) should have a prev arrow", function() { + const settings = { + dots: true, + infinite: true, + speed: 500, + slidesToShow: 1, + slidesToScroll: 1 + }; + const { container } = render(); + expect(container.getElementsByClassName("slick-prev").length).toBe(1); + }); + it("(SimpleSliderTest) should have a next arrow", function() { + const settings = { + dots: true, + infinite: true, + speed: 500, + slidesToShow: 1, + slidesToScroll: 1 + }; + const { container } = render(); + expect(container.getElementsByClassName("slick-next").length).toBe(1); + }); + it("(SimpleSliderTest) should got to next slide when next button is clicked", function() { + const settings = { + dots: true, + infinite: true, + speed: 500, + slidesToShow: 1, + slidesToScroll: 1 + }; + const { container } = render(); + clickNext(container); + expect( + container.querySelectorAll(".slick-slide.slick-active")[0].textContent + ).toBe("2"); + expect(container.querySelectorAll(".slick-dots .slick-active").length).toBe( + 1 + ); + expect( + container.querySelectorAll(".slick-dots")[0].children[1] + ).toHaveClass("slick-active"); + }); + it("(SimpleSliderTest) should goto previous slide when prev button is clicked", function() { + const settings = { + dots: true, + infinite: true, + speed: 500, + slidesToShow: 1, + slidesToScroll: 1 + }; + const { container } = render(); + clickPrevious(container); + expect( + container.querySelectorAll(".slick-slide.slick-active")[0].textContent + ).toBe("6"); + expect(container.querySelectorAll(".slick-dots .slick-active").length).toBe( + 1 + ); + expect( + container.querySelectorAll(".slick-dots")[0].children[5] + ).toHaveClass("slick-active"); + }); + it("(SimpleSliderTest) should got to next slide when next button is clicked (when intialSlide is equal to 2)", function() { + const settings = { + dots: true, + infinite: true, + speed: 500, + slidesToShow: 1, + slidesToScroll: 1, + initialSlide: 2 + }; + const { container } = render(); + clickNext(container); + expect( + container.querySelectorAll(".slick-slide.slick-active")[0].textContent + ).toBe("4"); + expect(container.querySelectorAll(".slick-dots .slick-active").length).toBe( + 1 + ); + expect( + container.querySelectorAll(".slick-dots")[0].children[3] + ).toHaveClass("slick-active"); + }); + it("(SimpleSliderTest) should goto previous slide when prev button is clicked (when intialSlide is equal to 2)", function() { + const settings = { + dots: true, + infinite: true, + speed: 500, + slidesToShow: 1, + slidesToScroll: 1, + initialSlide: 2 + }; + const { container } = render(); + clickPrevious(container); + expect( + container.querySelectorAll(".slick-slide.slick-active")[0].textContent + ).toBe("2"); + expect(container.querySelectorAll(".slick-dots .slick-active").length).toBe( + 1 + ); + expect( + container.querySelectorAll(".slick-dots")[0].children[1] + ).toHaveClass("slick-active"); + }); + it("(SimpleSliderTest) should goto 4th slide when 4th dot is clicked", function() { + const settings = { + dots: true, + infinite: true, + speed: 500, + slidesToShow: 1, + slidesToScroll: 1 + }; + const { container } = render(); + fireEvent( + container.querySelectorAll(".slick-dots button")[3], + new MouseEvent("click", { + bubbles: true, + cancelable: true + }) + ); + expect(getActiveSlidesText(container)[0]).toEqual("4"); + expect(getActiveSlidesCount(container)).toEqual(1); + expect(hasClass(getButtonsListItem(container)[3], "slick-active")).toEqual( + true + ); + }); +}); + +// describe("Simple Slider Snapshots", function() { +// it("slider initial state", function() { +// const { container } = render(); +// // expect(beautify_html(toString(container))).toMatchSnapshot(); +// }); +// it("click on next button", function() { +// const { container } = render(); +// clickNext(container); +// //expect(beautify_html(toString(container))).toMatchSnapshot(); +// }); +// it("click on prev button", function() { +// const { container } = render(); +// clickPrevious(container); +// // expect(beautify_html(toString(container))).toMatchSnapshot(); +// }); +// it("click on 3rd dot", function() { +// const { container } = render(); +// fireEvent( +// getButtons(container)[2], +// new MouseEvent("click", { +// bubbles: true, +// cancelable: true +// }) +// ); +// // expect(beautify_html(toString(container))).toMatchSnapshot(); +// }); +//}); diff --git a/examples/AdaptiveHeight.js b/examples/AdaptiveHeight.js index 8db8e6b13..4f24ca3ad 100644 --- a/examples/AdaptiveHeight.js +++ b/examples/AdaptiveHeight.js @@ -1,45 +1,44 @@ import React from "react"; import Slider from "../src/slider"; -const AdaptiveHeight = () => { - - const settings = { - className: "", - dots: true, - infinite: true, - slidesToShow: 1, - slidesToScroll: 1, - adaptiveHeight: true - }; - - return ( -
-

Adaptive height

- -
-

1

-
-
-

2

-

Hello

-
-
-

3

-

See ....

-

Height is adaptive

-
-
-

4

-
-
-

5

-
-
-

6

-
-
-
- ); - } +function AdaptiveHeight() { + const settings = { + className: "", + dots: true, + infinite: true, + slidesToShow: 1, + slidesToScroll: 1, + adaptiveHeight: true + }; + + return ( +
+

Adaptive height

+ +
+

1

+
+
+

2

+

Hello

+
+
+

3

+

See ....

+

Height is adaptive

+
+
+

4

+
+
+

5

+
+
+

6

+
+
+
+ ); +} export default AdaptiveHeight; diff --git a/examples/AppendDots.js b/examples/AppendDots.js index f9001ecc5..57f8ccb39 100644 --- a/examples/AppendDots.js +++ b/examples/AppendDots.js @@ -1,61 +1,60 @@ -import React, { Component } from "react"; +import React from "react"; import Slider from "../src/slider"; -export default class AppendDots extends Component { - render() { - const settings = { - dots: true, - infinite: true, - speed: 500, - slidesToShow: 1, - slidesToScroll: 1, - appendDots: dots => ( -
-
    {dots}
+function AppendDots() { + const settings = { + dots: true, + infinite: true, + speed: 500, + slidesToShow: 1, + slidesToScroll: 1, + appendDots: dots => ( +
+
    {dots}
+
+ ), + customPaging: i => ( +
+ {i + 1} +
+ ) + }; + return ( +
+

Append Dots

+ +
+

1

- ), - customPaging: i => ( -
- {i + 1} +
+

2

- ) - }; - return ( -
-

Append Dots

- -
-

1

-
-
-

2

-
-
-

3

-
-
-

4

-
-
-

5

-
-
-

6

-
-
-
- ); - } +
+

3

+
+
+

4

+
+
+

5

+
+
+

6

+
+ +
+ ); } +export default AppendDots; diff --git a/examples/AsNavFor.js b/examples/AsNavFor.js index caacb2be8..cab4c1a9a 100644 --- a/examples/AsNavFor.js +++ b/examples/AsNavFor.js @@ -1,78 +1,69 @@ -import React, { Component } from "react"; +import React, { useState, useEffect, useRef } from "react"; import Slider from "../src/slider"; -export default class AsNavFor extends Component { - constructor(props) { - super(props); - this.state = { - nav1: null, - nav2: null - }; - } +function AsNavFor(props) { + const [nav1, setNav1] = useState(null); + const [nav2, setNav2] = useState(null); + let sliderRef1 = useRef(null); + let sliderRef2 = useRef(null); - componentDidMount() { - this.setState({ - nav1: this.slider1, - nav2: this.slider2 - }); - } - - render() { - return ( -
-

Slider Syncing (AsNavFor)

-

First Slider

- (this.slider1 = slider)} - > -
-

1

-
-
-

2

-
-
-

3

-
-
-

4

-
-
-

5

-
-
-

6

-
-
-

Second Slider

- (this.slider2 = slider)} - slidesToShow={3} - swipeToSlide={true} - focusOnSelect={true} - > -
-

1

-
-
-

2

-
-
-

3

-
-
-

4

-
-
-

5

-
-
-

6

-
-
-
- ); - } + useEffect(() => { + setNav1(sliderRef1); + setNav2(sliderRef2); + }, []); + return ( +
+

Slider Syncing (AsNavFor)

+

First Slider

+ (sliderRef1 = slider)}> +
+

1

+
+
+

2

+
+
+

3

+
+
+

4

+
+
+

5

+
+
+

6

+
+
+

Second Slider

+ (sliderRef2 = slider)} + slidesToShow={3} + swipeToSlide={true} + focusOnSelect={true} + > +
+

1

+
+
+

2

+
+
+

3

+
+
+

4

+
+
+

5

+
+
+

6

+
+
+
+ ); } + +export default AsNavFor; diff --git a/examples/AutoPlay.js b/examples/AutoPlay.js index 73e99d577..452ea8659 100644 --- a/examples/AutoPlay.js +++ b/examples/AutoPlay.js @@ -1,42 +1,42 @@ -import React, { Component } from "react"; +import React from "react"; import Slider from "../src/slider"; -export default class AutoPlay extends Component { - render() { - const settings = { - dots: true, - infinite: true, - slidesToShow: 3, - slidesToScroll: 1, - autoplay: true, - speed: 2000, - autoplaySpeed: 2000, - cssEase: "linear" - }; - return ( -
-

Auto Play

- -
-

1

-
-
-

2

-
-
-

3

-
-
-

4

-
-
-

5

-
-
-

6

-
-
-
- ); - } +function AutoPlay() { + const settings = { + dots: true, + infinite: true, + slidesToShow: 3, + slidesToScroll: 1, + autoplay: true, + speed: 2000, + autoplaySpeed: 2000, + cssEase: "linear" + }; + return ( +
+

Auto Play

+ +
+

1

+
+
+

2

+
+
+

3

+
+
+

4

+
+
+

5

+
+
+

6

+
+
+
+ ); } + +export default AutoPlay; diff --git a/examples/AutoPlayMethods.js b/examples/AutoPlayMethods.js index 0fdd86346..c6b4d635d 100644 --- a/examples/AutoPlayMethods.js +++ b/examples/AutoPlayMethods.js @@ -1,59 +1,55 @@ -import React, { Component } from "react"; +import React, { useRef } from "react"; import Slider from "../src/slider"; -export default class AutoPlayMethods extends Component { - constructor(props) { - super(props); - this.play = this.play.bind(this); - this.pause = this.pause.bind(this); - } - play() { - this.slider.slickPlay(); - } - pause() { - this.slider.slickPause(); - } - render() { - const settings = { - dots: true, - infinite: true, - slidesToShow: 3, - slidesToScroll: 1, - autoplay: true, - autoplaySpeed: 2000 - }; - return ( -
-

Auto Play & Pause with buttons

- (this.slider = slider)} {...settings}> -
-

1

-
-
-

2

-
-
-

3

-
-
-

4

-
-
-

5

-
-
-

6

-
-
-
- - +function AutoPlayMethods(props) { + let sliderRef = useRef(null); + const play = () => { + sliderRef.slickPlay(); + }; + const pause = () => { + sliderRef.slickPause(); + }; + + const settings = { + dots: true, + infinite: true, + slidesToShow: 3, + slidesToScroll: 1, + autoplay: true, + autoplaySpeed: 2000 + }; + return ( +
+

Auto Play {"&"} Pause with buttons

+ (sliderRef = slider)} {...settings}> +
+

1

+
+
+

2

+
+
+

3

+
+
+

4

+
+
+

5

+
+
+

6

+
+
+ +
- ); - } +
+ ); } +export default AutoPlayMethods; diff --git a/examples/CenterMode.js b/examples/CenterMode.js index e67816700..101df61ca 100644 --- a/examples/CenterMode.js +++ b/examples/CenterMode.js @@ -1,40 +1,40 @@ import React, { Component } from "react"; import Slider from "../src/slider"; -export default class CenterMode extends Component { - render() { - const settings = { - className: "center", - centerMode: true, - infinite: true, - centerPadding: "60px", - slidesToShow: 3, - speed: 500 - }; - return ( -
-

Center Mode

- -
-

1

-
-
-

2

-
-
-

3

-
-
-

4

-
-
-

5

-
-
-

6

-
-
-
- ); - } +function CenterMode() { + const settings = { + className: "center", + centerMode: true, + infinite: true, + centerPadding: "60px", + slidesToShow: 3, + speed: 500 + }; + return ( +
+

Center Mode

+ +
+

1

+
+
+

2

+
+
+

3

+
+
+

4

+
+
+

5

+
+
+

6

+
+
+
+ ); } + +export default CenterMode; diff --git a/examples/CustomArrows.js b/examples/CustomArrows.js index 8f85b86e5..fbd3582ca 100644 --- a/examples/CustomArrows.js +++ b/examples/CustomArrows.js @@ -23,40 +23,40 @@ function SamplePrevArrow(props) { ); } -export default class CustomArrows extends Component { - render() { - const settings = { - dots: true, - infinite: true, - slidesToShow: 3, - slidesToScroll: 1, - nextArrow: , - prevArrow: - }; - return ( -
-

Custom Arrows

- -
-

1

-
-
-

2

-
-
-

3

-
-
-

4

-
-
-

5

-
-
-

6

-
-
-
- ); - } +function CustomArrows() { + const settings = { + dots: true, + infinite: true, + slidesToShow: 3, + slidesToScroll: 1, + nextArrow: , + prevArrow: + }; + return ( +
+

Custom Arrows

+ +
+

1

+
+
+

2

+
+
+

3

+
+
+

4

+
+
+

5

+
+
+

6

+
+
+
+ ); } + +export default CustomArrows; diff --git a/examples/CustomPaging.js b/examples/CustomPaging.js index 3d369689e..66e53ea72 100644 --- a/examples/CustomPaging.js +++ b/examples/CustomPaging.js @@ -2,41 +2,41 @@ import React, { Component } from "react"; import Slider from "../src/slider"; import { baseUrl } from "./config"; -export default class CenterMode extends Component { - render() { - const settings = { - customPaging: function(i) { - return ( - - - - ); - }, - dots: true, - dotsClass: "slick-dots slick-thumb", - infinite: true, - speed: 500, - slidesToShow: 1, - slidesToScroll: 1 - }; - return ( -
-

Custom Paging

- -
- -
-
- -
-
- -
-
- -
-
-
- ); - } +function CustomPaging() { + const settings = { + customPaging: function(i) { + return ( + + + + ); + }, + dots: true, + dotsClass: "slick-dots slick-thumb", + infinite: true, + speed: 500, + slidesToShow: 1, + slidesToScroll: 1 + }; + return ( +
+

Custom Paging

+ +
+ +
+
+ +
+
+ +
+
+ +
+
+
+ ); } + +export default CustomPaging; diff --git a/examples/CustomSlides.js b/examples/CustomSlides.js index cbf5f2c6d..da4ee51d3 100644 --- a/examples/CustomSlides.js +++ b/examples/CustomSlides.js @@ -1,38 +1,36 @@ import React, { Component } from "react"; import Slider from "../src/slider"; -class CustomSlide extends Component { - render() { - const { index, ...props } = this.props; - return ( -
-

{index}

-
- ); - } +function CustomSlide(props) { + const { index, ...props } = props; + return ( +
+

{index}

+
+ ); } -export default class SimpleSlider extends Component { - render() { - const settings = { - dots: true, - infinite: true, - speed: 500, - slidesToShow: 1, - slidesToScroll: 1 - }; - return ( -
-

Custom Slides

- - - - - - - - -
- ); - } +function SimpleSlider() { + const settings = { + dots: true, + infinite: true, + speed: 500, + slidesToShow: 1, + slidesToScroll: 1 + }; + return ( +
+

Custom Slides

+ + + + + + + + +
+ ); } + +export default SimpleSlider; diff --git a/examples/DynamicSlides.js b/examples/DynamicSlides.js index e0e405476..a69859fff 100644 --- a/examples/DynamicSlides.js +++ b/examples/DynamicSlides.js @@ -1,45 +1,45 @@ -import React, { Component } from "react"; +import React, { useState } from "react"; import Slider from "../src/slider"; -export default class DynamicSlides extends Component { - constructor(props) { - super(props); - this.state = { - slides: [1, 2, 3, 4, 5, 6] - }; - this.click = this.click.bind(this); - } - click() { - const { slides } = this.state; - this.setState({ - slides: - slides.length === 6 ? [1, 2, 3, 4, 5, 6, 7, 8, 9] : [1, 2, 3, 4, 5, 6] - }); - } - render() { - const settings = { - dots: true, - infinite: true, - speed: 500, - slidesToShow: 3, - slidesToScroll: 3 - }; - return ( -
-

Dynamic slides

- - - {this.state.slides.map(function(slide) { - return ( -
-

{slide}

-
- ); - })} -
-
+function DynamicSlides(props) { + const [slides, setSlides] = useState([1, 2, 3, 4, 5, 6]); + const handleClick = () => { + setSlides( + slides.length === 6 ? [1, 2, 3, 4, 5, 6, 7, 8, 9] : [1, 2, 3, 4, 5, 6] ); - } + }; + // click() { + // const { slides } = this.state; + // this.setState({ + // slides: + // slides.length === 6 ? [1, 2, 3, 4, 5, 6, 7, 8, 9] : [1, 2, 3, 4, 5, 6] + // }); + // } + const settings = { + dots: true, + infinite: true, + speed: 500, + slidesToShow: 3, + slidesToScroll: 3, + ...props + }; + return ( +
+

Dynamic slides

+ + + {slides.map(slide => { + return ( +
+

{slide}

+
+ ); + })} +
+
+ ); } + +export default DynamicSlides; diff --git a/examples/Fade.js b/examples/Fade.js index e4ae2c961..ff75f45bf 100644 --- a/examples/Fade.js +++ b/examples/Fade.js @@ -1,36 +1,36 @@ -import React, { Component } from "react"; +import React from "react"; import Slider from "../src/slider"; import { baseUrl } from "./config"; -export default class Fade extends Component { - render() { - const settings = { - dots: true, - fade: true, - infinite: true, - speed: 500, - slidesToShow: 1, - slidesToScroll: 1, - waitForAnimate: false - }; - return ( -
-

Fade

- -
- -
-
- -
-
- -
-
- -
-
-
- ); - } +function Fade() { + const settings = { + dots: true, + fade: true, + infinite: true, + speed: 500, + slidesToShow: 1, + slidesToScroll: 1, + waitForAnimate: false + }; + return ( +
+

Fade

+ +
+ +
+
+ +
+
+ +
+
+ +
+
+
+ ); } + +export default Fade; diff --git a/examples/FocusOnSelect.js b/examples/FocusOnSelect.js index 42eab9d60..07f8fbc72 100644 --- a/examples/FocusOnSelect.js +++ b/examples/FocusOnSelect.js @@ -1,40 +1,40 @@ import React, { Component } from "react"; import Slider from "../src/slider"; -export default class FocusOnSelect extends Component { - render() { - const settings = { - focusOnSelect: true, - infinite: true, - slidesToShow: 3, - slidesToScroll: 1, - speed: 500 - }; - return ( -
-

FocusOnSelect

-
Click on any slide to select and make it current slide
- -
-

1

-
-
-

2

-
-
-

3

-
-
-

4

-
-
-

5

-
-
-

6

-
-
-
- ); - } +function FocusOnSelect() { + const settings = { + focusOnSelect: true, + infinite: true, + slidesToShow: 3, + slidesToScroll: 1, + speed: 500 + }; + return ( +
+

FocusOnSelect

+
Click on any slide to select and make it current slide
+ +
+

1

+
+
+

2

+
+
+

3

+
+
+

4

+
+
+

5

+
+
+

6

+
+
+
+ ); } + +export default FocusOnSelect; diff --git a/examples/LazyLoad.js b/examples/LazyLoad.js index d5ecfeb74..d4b80d726 100644 --- a/examples/LazyLoad.js +++ b/examples/LazyLoad.js @@ -2,35 +2,35 @@ import React, { Component } from "react"; import Slider from "../src/slider"; import { baseUrl } from "./config"; -export default class LazyLoad extends Component { - render() { - const settings = { - dots: true, - lazyLoad: true, - infinite: true, - speed: 500, - slidesToShow: 1, - slidesToScroll: 1, - initialSlide: 2 - }; - return ( -
-

Lazy Load

- -
- -
-
- -
-
- -
-
- -
-
-
- ); - } +function LazyLoad() { + const settings = { + dots: true, + lazyLoad: true, + infinite: true, + speed: 500, + slidesToShow: 1, + slidesToScroll: 1, + initialSlide: 2 + }; + return ( +
+

Lazy Load

+ +
+ +
+
+ +
+
+ +
+
+ +
+
+
+ ); } + +export default LazyLoad; diff --git a/examples/MultipleItems.js b/examples/MultipleItems.js index a23c8793b..2634fdd93 100644 --- a/examples/MultipleItems.js +++ b/examples/MultipleItems.js @@ -1,48 +1,48 @@ -import React, { Component } from "react"; +import React from "react"; import Slider from "../src/slider"; -export default class MultipleItems extends Component { - render() { - const settings = { - dots: true, - infinite: true, - speed: 500, - slidesToShow: 3, - slidesToScroll: 3 - }; - return ( -
-

Multiple items

- -
-

1

-
-
-

2

-
-
-

3

-
-
-

4

-
-
-

5

-
-
-

6

-
-
-

7

-
-
-

8

-
-
-

9

-
-
-
- ); - } +function MultipleItems() { + const settings = { + dots: true, + infinite: true, + speed: 500, + slidesToShow: 3, + slidesToScroll: 3 + }; + return ( +
+

Multiple items

+ +
+

1

+
+
+

2

+
+
+

3

+
+
+

4

+
+
+

5

+
+
+

6

+
+
+

7

+
+
+

8

+
+
+

9

+
+
+
+ ); } + +export default MultipleItems; diff --git a/examples/MultipleRows.js b/examples/MultipleRows.js index 4b56b4cbd..a36a5eb3d 100644 --- a/examples/MultipleRows.js +++ b/examples/MultipleRows.js @@ -1,72 +1,72 @@ -import React, { Component } from "react"; +import React from "react"; import Slider from "../src/slider"; -export default class MultipleRows extends Component { - render() { - const settings = { - className: "center", - centerMode: true, - infinite: true, - centerPadding: "60px", - slidesToShow: 3, - speed: 500, - rows: 2, - slidesPerRow: 2 - }; - return ( -
-

Multiple Rows

- -
-

1

-
-
-

2

-
-
-

3

-
-
-

4

-
-
-

5

-
-
-

6

-
-
-

7

-
-
-

8

-
-
-

9

-
-
-

10

-
-
-

11

-
-
-

12

-
-
-

13

-
-
-

14

-
-
-

15

-
-
-

16

-
-
-
- ); - } +function MultipleRows() { + const settings = { + className: "center", + centerMode: true, + infinite: true, + centerPadding: "60px", + slidesToShow: 3, + speed: 500, + rows: 2, + slidesPerRow: 2 + }; + return ( +
+

Multiple Rows

+ +
+

1

+
+
+

2

+
+
+

3

+
+
+

4

+
+
+

5

+
+
+

6

+
+
+

7

+
+
+

8

+
+
+

9

+
+
+

10

+
+
+

11

+
+
+

12

+
+
+

13

+
+
+

14

+
+
+

15

+
+
+

16

+
+
+
+ ); } + +export default MultipleRows; diff --git a/examples/PauseOnHover.js b/examples/PauseOnHover.js index 16b4d2660..97aa2dbfb 100644 --- a/examples/PauseOnHover.js +++ b/examples/PauseOnHover.js @@ -1,41 +1,41 @@ import React, { Component } from "react"; import Slider from "../src/slider"; -export default class PauseOnHover extends Component { - render() { - var settings = { - dots: true, - infinite: true, - slidesToShow: 3, - slidesToScroll: 1, - autoplay: true, - autoplaySpeed: 2000, - pauseOnHover: true - }; - return ( -
-

Pause On Hover

- -
-

1

-
-
-

2

-
-
-

3

-
-
-

4

-
-
-

5

-
-
-

6

-
-
-
- ); - } +function PauseOnHover() { + var settings = { + dots: true, + infinite: true, + slidesToShow: 3, + slidesToScroll: 1, + autoplay: true, + autoplaySpeed: 2000, + pauseOnHover: true + }; + return ( +
+

Pause On Hover

+ +
+

1

+
+
+

2

+
+
+

3

+
+
+

4

+
+
+

5

+
+
+

6

+
+
+
+ ); } + +export default PauseOnHover; diff --git a/examples/PreviousNextMethods.js b/examples/PreviousNextMethods.js index e3a0ead73..4d7b04913 100644 --- a/examples/PreviousNextMethods.js +++ b/examples/PreviousNextMethods.js @@ -1,58 +1,55 @@ -import React, { Component } from "react"; +import React, { useRef } from "react"; import Slider from "../src/slider"; -export default class PreviousNextMethods extends Component { - constructor(props) { - super(props); - this.next = this.next.bind(this); - this.previous = this.previous.bind(this); - } - next() { +function PreviousNextMethods(props) { + const sliderRef = useRef(null); + const next = () => { this.slider.slickNext(); - } - previous() { + }; + const previous = () => { this.slider.slickPrev(); - } - render() { - const settings = { - dots: true, - infinite: true, - speed: 500, - slidesToShow: 1, - slidesToScroll: 1 - }; - return ( -
-

Previous and Next methods

- (this.slider = c)} {...settings}> -
-

1

-
-
-

2

-
-
-

3

-
-
-

4

-
-
-

5

-
-
-

6

-
-
-
- - + }; + const settings = { + dots: true, + infinite: true, + speed: 500, + slidesToShow: 1, + slidesToScroll: 1, + ...props + }; + return ( +
+

Previous and Next methods

+ (sliderRef = slider)} {...settings}> +
+

1

+
+

2

+
+
+

3

+
+
+

4

+
+
+

5

+
+
+

6

+
+
+
+ +
- ); - } +
+ ); } + +export default PreviousNextMethods; diff --git a/examples/Resizable.js b/examples/Resizable.js index d7747fa91..e5be1bfa5 100644 --- a/examples/Resizable.js +++ b/examples/Resizable.js @@ -1,83 +1,61 @@ -import React, { Component } from "react"; +import React, { useState } from "react"; import Slider from "../src/slider"; -export default class Resizable extends Component { - state = { - display: true, - width: 600 +function Resizable() { + const [display, setDisplay] = useState(true); + const [width, setWidth] = useState(600); + + const settings = { + dots: true, + infinite: true, + speed: 500, + slidesToShow: 3, + slidesToScroll: 1 }; - render() { - const settings = { - dots: true, - infinite: true, - speed: 500, - slidesToShow: 3, - slidesToScroll: 1 - }; - return ( -
-

Resizable Collapsible

- - - -
- -
-

1

-
-
-

2

-
-
-

3

-
-
-

4

-
-
-

5

-
-
-

6

-
-
-
+ return ( +
+

Resizable Collapsible

+ + + +
+ +
+

1

+
+
+

2

+
+
+

3

+
+
+

4

+
+
+

5

+
+
+

6

+
+
- ); - } +
+ ); } + +export default Resizable; diff --git a/examples/Responsive.js b/examples/Responsive.js index efa606229..3e8abeb9c 100644 --- a/examples/Responsive.js +++ b/examples/Responsive.js @@ -1,72 +1,72 @@ -import React, { Component } from "react"; +import React from "react"; import Slider from "../src/slider"; -export default class Responsive extends Component { - render() { - var settings = { - dots: true, - infinite: false, - speed: 500, - slidesToShow: 4, - slidesToScroll: 4, - initialSlide: 0, - responsive: [ - { - breakpoint: 1024, - settings: { - slidesToShow: 3, - slidesToScroll: 3, - infinite: true, - dots: true - } - }, - { - breakpoint: 600, - settings: { - slidesToShow: 2, - slidesToScroll: 2, - initialSlide: 2 - } - }, - { - breakpoint: 480, - settings: { - slidesToShow: 1, - slidesToScroll: 1 - } +function Responsive() { + var settings = { + dots: true, + infinite: false, + speed: 500, + slidesToShow: 4, + slidesToScroll: 4, + initialSlide: 0, + responsive: [ + { + breakpoint: 1024, + settings: { + slidesToShow: 3, + slidesToScroll: 3, + infinite: true, + dots: true } - ] - }; - return ( -
-

Responsive

- -
-

1

-
-
-

2

-
-
-

3

-
-
-

4

-
-
-

5

-
-
-

6

-
-
-

7

-
-
-

8

-
-
-
- ); - } + }, + { + breakpoint: 600, + settings: { + slidesToShow: 2, + slidesToScroll: 2, + initialSlide: 2 + } + }, + { + breakpoint: 480, + settings: { + slidesToShow: 1, + slidesToScroll: 1 + } + } + ] + }; + return ( +
+

Responsive

+ +
+

1

+
+
+

2

+
+
+

3

+
+
+

4

+
+
+

5

+
+
+

6

+
+
+

7

+
+
+

8

+
+
+
+ ); } + +export default Responsive; diff --git a/examples/Rtl.js b/examples/Rtl.js index e72edc5d6..a1473bcd5 100644 --- a/examples/Rtl.js +++ b/examples/Rtl.js @@ -1,41 +1,41 @@ -import React, { Component } from "react"; +import React from "react"; import Slider from "../src/slider"; -export default class Rtl extends Component { - render() { - const settings = { - dots: true, - infinite: true, - slidesToShow: 3, - slidesToScroll: 1, - autoplay: true, - autoplaySpeed: 2000, - rtl: true - }; - return ( -
-

Right to Left

- -
-

1

-
-
-

2

-
-
-

3

-
-
-

4

-
-
-

5

-
-
-

6

-
-
-
- ); - } +function Rtl() { + const settings = { + dots: true, + infinite: true, + slidesToShow: 3, + slidesToScroll: 1, + autoplay: true, + autoplaySpeed: 2000, + rtl: true + }; + return ( +
+

Right to Left

+ +
+

1

+
+
+

2

+
+
+

3

+
+
+

4

+
+
+

5

+
+
+

6

+
+
+
+ ); } + +export default Rtl; diff --git a/examples/SimpleSlider.js b/examples/SimpleSlider.js index 92d10fbca..ee06df7a3 100644 --- a/examples/SimpleSlider.js +++ b/examples/SimpleSlider.js @@ -1,40 +1,40 @@ -import React, { Component } from "react"; +import React from "react"; import Slider from "../src/slider"; -export default class SimpleSlider extends Component { - render() { - const settings = { - dots: true, - infinite: true, - speed: 500, - initialSlide: 2, - slidesToShow: 1, - slidesToScroll: 1 - }; - return ( -
-

Single Item

- -
-

1

-
-
-

2

-
-
-

3

-
-
-

4

-
-
-

5

-
-
-

6

-
-
-
- ); - } +function SimpleSlider(props) { + const settings = { + dots: true, + infinite: true, + speed: 500, + slidesToShow: 1, + slidesToScroll: 1, + ...props + }; + return ( +
+

Single Item

+ +
+

1

+
+
+

2

+
+
+

3

+
+
+

4

+
+
+

5

+
+
+

6

+
+
+
+ ); } + +export default SimpleSlider; diff --git a/examples/SlickGoTo.js b/examples/SlickGoTo.js index f5c49840a..07ef3c1f9 100644 --- a/examples/SlickGoTo.js +++ b/examples/SlickGoTo.js @@ -1,50 +1,53 @@ -import React, { Component } from "react"; +import React, { useState, useRef } from "react"; import Slider from "../src/slider"; import { baseUrl } from "./config"; -export default class SlickGoTo extends React.Component { - state = { - slideIndex: 0, - updateCount: 0 +function SlickGoTo(props) { + const [slideIndex, setSlideIndex] = useState(0); + const [updateCount, setUpdateCount] = useState(0); + let sliderRef = useRef(null); + const settings = { + dots: false, + infinite: true, + speed: 500, + slidesToShow: 1, + slidesToScroll: 1, + afterChange: () => setUpdateCount(updateCount + 1), + beforeChange: (current, next) => setSlideIndex(next), + ...props }; - - render() { - const settings = { - dots: false, - infinite: true, - speed: 500, - slidesToShow: 1, - slidesToScroll: 1, - afterChange: () => - this.setState(state => ({ updateCount: state.updateCount + 1 })), - beforeChange: (current, next) => this.setState({ slideIndex: next }) - }; - return ( -
-

Slick Go To

-

Total updates: {this.state.updateCount}

- this.slider.slickGoTo(e.target.value)} - value={this.state.slideIndex} - type="range" - min={0} - max={3} - /> - (this.slider = slider)} {...settings}> -
- -
-
- -
-
- -
-
- -
-
-
- ); - } + return ( +
+

Slick Go To

+

Total updates: {updateCount}

+ sliderRef.slickGoTo(e.target.value)} + value={slideIndex} + type="range" + min={0} + max={3} + /> + { + sliderRef = slider; + }} + {...settings} + > +
+ +
+
+ +
+
+ +
+
+ +
+
+
+ ); } + +export default SlickGoTo; diff --git a/examples/SlideChangeHooks.js b/examples/SlideChangeHooks.js index 9f8b31753..9e6a6a85f 100644 --- a/examples/SlideChangeHooks.js +++ b/examples/SlideChangeHooks.js @@ -1,56 +1,59 @@ -import React, { Component } from "react"; +import React, { useState } from "react"; import Slider from "../src/slider"; -export default class SlideChangeHooks extends Component { - state = { - oldSlide: 0, - activeSlide: 0, - activeSlide2: 0 +function SlideChangeHooks() { + const [oldSlide, setOldSlide] = useState(0); + const [activeSlide, setActiveSlide] = useState(0); + const [activeSlide2, setActiveSlide2] = useState(0); + + const settings = { + dots: true, + infinite: true, + speed: 1000, + slidesToShow: 1, + slidesToScroll: 1, + beforeChange: (current, next) => { + setOldSlide(current); + setActiveSlide(next); + }, + afterChange: current => setActiveSlide2(current) }; - render() { - const settings = { - dots: true, - infinite: true, - speed: 1000, - slidesToShow: 1, - slidesToScroll: 1, - beforeChange: (current, next) => - this.setState({ oldSlide: current, activeSlide: next }), - afterChange: current => this.setState({ activeSlide2: current }) - }; - return ( -
-

beforeChange and afterChange hooks

-

- BeforeChange => oldSlide: {this.state.oldSlide} -

-

- BeforeChange => activeSlide: {this.state.activeSlide} -

-

- AfterChange => activeSlide: {this.state.activeSlide2} -

- -
-

1

-
-
-

2

-
-
-

3

-
-
-

4

-
-
-

5

-
-
-

6

-
-
-
- ); - } + return ( +
+

beforeChange and afterChange hooks

+

+ BeforeChange {"=>"} oldSlide: {this.state.oldSlide} +

+

+ BeforeChange {"=>"} activeSlide:{" "} + {this.state.activeSlide} +

+

+ AfterChange {"=>"} activeSlide:{" "} + {this.state.activeSlide2} +

+ +
+

1

+
+
+

2

+
+
+

3

+
+
+

4

+
+
+

5

+
+
+

6

+
+
+
+ ); } + +export default SlideChangeHooks; diff --git a/examples/SwipeToSlide.js b/examples/SwipeToSlide.js index 2e51db349..855e4a629 100644 --- a/examples/SwipeToSlide.js +++ b/examples/SwipeToSlide.js @@ -1,53 +1,53 @@ import React, { Component } from "react"; import Slider from "../src/slider"; -export default class SwipeToSlide extends Component { - render() { - const settings = { - className: "center", - infinite: true, - centerPadding: "60px", - slidesToShow: 5, - swipeToSlide: true, - afterChange: function(index) { - console.log( - `Slider Changed to: ${index + 1}, background: #222; color: #bada55` - ); - } - }; - return ( -
-

Swipe To Slide

- -
-

1

-
-
-

2

-
-
-

3

-
-
-

4

-
-
-

5

-
-
-

6

-
-
-

7

-
-
-

8

-
-
-

9

-
-
-
- ); - } +function SwipeToSlide() { + const settings = { + className: "center", + infinite: true, + centerPadding: "60px", + slidesToShow: 5, + swipeToSlide: true, + afterChange: function(index) { + console.log( + `Slider Changed to: ${index + 1}, background: #222; color: #bada55` + ); + } + }; + return ( +
+

Swipe To Slide

+ +
+

1

+
+
+

2

+
+
+

3

+
+
+

4

+
+
+

5

+
+
+

6

+
+
+

7

+
+
+

8

+
+
+

9

+
+
+
+ ); } + +export default SwipeToSlide; diff --git a/examples/UnevenSetsFinite.js b/examples/UnevenSetsFinite.js index d465209b6..08e574b47 100644 --- a/examples/UnevenSetsFinite.js +++ b/examples/UnevenSetsFinite.js @@ -1,39 +1,39 @@ -import React, { Component } from "react"; +import React from "react"; import Slider from "../src/slider"; -export default class UnevenSetsFinite extends Component { - render() { - var settings = { - dots: true, - infinite: false, - speed: 500, - slidesToScroll: 4, - slidesToShow: 4 - }; - return ( -
-

Uneven sets (finite)

- -
-

1

-
-
-

2

-
-
-

3

-
-
-

4

-
-
-

5

-
-
-

6

-
-
-
- ); - } +function UnevenSetsFinite() { + var settings = { + dots: true, + infinite: false, + speed: 500, + slidesToScroll: 4, + slidesToShow: 4 + }; + return ( +
+

Uneven sets (finite)

+ +
+

1

+
+
+

2

+
+
+

3

+
+
+

4

+
+
+

5

+
+
+

6

+
+
+
+ ); } + +export default UnevenSetsFinite; diff --git a/examples/UnevenSetsInfinite.js b/examples/UnevenSetsInfinite.js index 7e00a43a7..9f7295fbe 100644 --- a/examples/UnevenSetsInfinite.js +++ b/examples/UnevenSetsInfinite.js @@ -1,39 +1,39 @@ -import React, { Component } from "react"; +import React from "react"; import Slider from "../src/slider"; -export default class UnevenSetsInfinite extends Component { - render() { - var settings = { - dots: true, - infinite: true, - speed: 500, - slidesToScroll: 4, - slidesToShow: 4 - }; - return ( -
-

Uneven sets (infinite)

- -
-

1

-
-
-

2

-
-
-

3

-
-
-

4

-
-
-

5

-
-
-

6

-
-
-
- ); - } +function UnevenSetsInfinite() { + var settings = { + dots: true, + infinite: true, + speed: 500, + slidesToScroll: 4, + slidesToShow: 4 + }; + return ( +
+

Uneven sets (infinite)

+ +
+

1

+
+
+

2

+
+
+

3

+
+
+

4

+
+
+

5

+
+
+

6

+
+
+
+ ); } + +export default UnevenSetsInfinite; diff --git a/examples/VariableWidth.js b/examples/VariableWidth.js index 9289c2258..e8f7baaa0 100644 --- a/examples/VariableWidth.js +++ b/examples/VariableWidth.js @@ -1,41 +1,41 @@ -import React, { Component } from "react"; +import React from "react"; import Slider from "../src/slider"; -export default class VariableWidth extends Component { - render() { - const settings = { - className: "slider variable-width", - dots: true, - infinite: true, - centerMode: true, - slidesToShow: 1, - slidesToScroll: 1, - variableWidth: true - }; - return ( -
-

Variable width

- -
-

100

-
-
-

200

-
-
-

75

-
-
-

300

-
-
-

225

-
-
-

175

-
-
-
- ); - } +function VariableWidth() { + const settings = { + className: "slider variable-width", + dots: true, + infinite: true, + centerMode: true, + slidesToShow: 1, + slidesToScroll: 1, + variableWidth: true + }; + return ( +
+

Variable width

+ +
+

100

+
+
+

200

+
+
+

75

+
+
+

300

+
+
+

225

+
+
+

175

+
+
+
+ ); } + +export default VariableWidth; diff --git a/examples/VerticalMode.js b/examples/VerticalMode.js index fc54c8585..b138a4180 100644 --- a/examples/VerticalMode.js +++ b/examples/VerticalMode.js @@ -1,46 +1,46 @@ import React, { Component } from "react"; import Slider from "../src/slider"; -export default class VerticalMode extends Component { - render() { - const settings = { - dots: true, - infinite: true, - slidesToShow: 3, - slidesToScroll: 1, - vertical: true, - verticalSwiping: true, - beforeChange: function(currentSlide, nextSlide) { - console.log("before change", currentSlide, nextSlide); - }, - afterChange: function(currentSlide) { - console.log("after change", currentSlide); - } - }; - return ( -
-

Vertical Mode

- -
-

1

-
-
-

2

-
-
-

3

-
-
-

4

-
-
-

5

-
-
-

6

-
-
-
- ); - } +function VerticalMode() { + const settings = { + dots: true, + infinite: true, + slidesToShow: 3, + slidesToScroll: 1, + vertical: true, + verticalSwiping: true, + beforeChange: function(currentSlide, nextSlide) { + console.log("before change", currentSlide, nextSlide); + }, + afterChange: function(currentSlide) { + console.log("after change", currentSlide); + } + }; + return ( +
+

Vertical Mode

+ +
+

1

+
+
+

2

+
+
+

3

+
+
+

4

+
+
+

5

+
+
+

6

+
+
+
+ ); } + +export default VerticalMode; diff --git a/examples/VerticalSwipeToSlide.js b/examples/VerticalSwipeToSlide.js index 36ed22d84..a7c8c2b3a 100644 --- a/examples/VerticalSwipeToSlide.js +++ b/examples/VerticalSwipeToSlide.js @@ -1,47 +1,47 @@ import React, { Component } from "react"; import Slider from "../src/slider"; -export default class VerticalSwipeToSlide extends Component { - render() { - const settings = { - dots: true, - infinite: true, - slidesToShow: 3, - slidesToScroll: 1, - vertical: true, - verticalSwiping: true, - swipeToSlide: true, - beforeChange: function(currentSlide, nextSlide) { - console.log("before change", currentSlide, nextSlide); - }, - afterChange: function(currentSlide) { - console.log("after change", currentSlide); - } - }; - return ( -
-

Vertical Mode with Swipe To Slide

- -
-

1

-
-
-

2

-
-
-

3

-
-
-

4

-
-
-

5

-
-
-

6

-
-
-
- ); - } +function VerticalSwipeToSlide() { + const settings = { + dots: true, + infinite: true, + slidesToShow: 3, + slidesToScroll: 1, + vertical: true, + verticalSwiping: true, + swipeToSlide: true, + beforeChange: function(currentSlide, nextSlide) { + console.log("before change", currentSlide, nextSlide); + }, + afterChange: function(currentSlide) { + console.log("after change", currentSlide); + } + }; + return ( +
+

Vertical Mode with Swipe To Slide

+ +
+

1

+
+
+

2

+
+
+

3

+
+
+

4

+
+
+

5

+
+
+

6

+
+
+
+ ); } + +export default VerticalSwipeToSlide; diff --git a/examples/__tests__/SimpleSlider.test.js b/examples/__tests__/SimpleSlider.test.js index 6e5ac8540..71402cbbb 100644 --- a/examples/__tests__/SimpleSlider.test.js +++ b/examples/__tests__/SimpleSlider.test.js @@ -24,14 +24,14 @@ describe("SimpleSlider example", () => { const { container } = render(); expect(container.getElementsByClassName("slick-cloned").length).toBe(7); }); - it("should have 1 current slide(When initialSlide is 2)", function() { + it("should have 1 current slide", function() { const { container } = render(); expect( container.querySelectorAll(".slick-slide.slick-current").length ).toBe(1); - expect(parseInt(getCurrentSlide(container).textContent) - 1).toBe(2); + expect(parseInt(getCurrentSlide(container).textContent) - 1).toBe(0); }); - it("should have 1 active slide(When initialSlide is 2)", function() { + it("should have 1 active slide", function() { const { container } = render(); expect(container.querySelectorAll(".slick-slide.slick-active").length).toBe( 1 @@ -40,7 +40,7 @@ describe("SimpleSlider example", () => { Array.from(getActiveSlide(container).children).map( e => parseInt(e.textContent) - 1 )[0] - ).toBe(2); + ).toBe(0); }); it("should have 6 dots", function() { const { container } = render(); @@ -68,12 +68,12 @@ describe("SimpleSlider example", () => { clickNext(container); expect( container.querySelectorAll(".slick-slide.slick-active")[0].textContent - ).toBe("4"); + ).toBe("2"); expect(container.querySelectorAll(".slick-dots .slick-active").length).toBe( 1 ); expect( - container.querySelectorAll(".slick-dots")[0].children[3] + container.querySelectorAll(".slick-dots")[0].children[1] ).toHaveClass("slick-active"); }); it("should goto previous slide when prev button is clicked", function() { @@ -81,12 +81,12 @@ describe("SimpleSlider example", () => { clickPrevious(container); expect( container.querySelectorAll(".slick-slide.slick-active")[0].textContent - ).toBe("2"); + ).toBe("6"); expect(container.querySelectorAll(".slick-dots .slick-active").length).toBe( 1 ); expect( - container.querySelectorAll(".slick-dots")[0].children[1] + container.querySelectorAll(".slick-dots")[0].children[5] ).toHaveClass("slick-active"); }); it("should goto 4th slide when 4th dot is clicked", function() { From 882a01db022aaefbff0b4f58ce64d5f309c9773f Mon Sep 17 00:00:00 2001 From: akiran Date: Mon, 5 Jun 2023 08:26:53 +0530 Subject: [PATCH 25/58] added node options to run docs --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index eea87e83a..6425e7f7d 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,8 @@ "lib" ], "scripts": { - "start": "gulp server", - "demo": "SINGLE_DEMO=true gulp server", + "start": "NODE_OPTIONS=--openssl-legacy-provider gulp server", + "demo": "SINGLE_DEMO=true NODE_OPTIONS=--openssl-legacy-provider gulp server", "build-dev": "gulp clean && gulp copy && webpack", "lib": "babel ./src --out-dir ./lib", "build": "npm run lib && gulp dist", From e1e766ff3b73fb26c0d8e430a7254b27d3edb6f6 Mon Sep 17 00:00:00 2001 From: akiran Date: Mon, 5 Jun 2023 08:37:10 +0530 Subject: [PATCH 26/58] remove other changes --- __test__/SliderComponent.js | 33 ---- __test__/SliderComponent.test.js | 292 ------------------------------- src/inner-slider.js | 1 - 3 files changed, 326 deletions(-) delete mode 100644 __test__/SliderComponent.js delete mode 100644 __test__/SliderComponent.test.js diff --git a/__test__/SliderComponent.js b/__test__/SliderComponent.js deleted file mode 100644 index 54ec971f0..000000000 --- a/__test__/SliderComponent.js +++ /dev/null @@ -1,33 +0,0 @@ -import React from "react"; -import Slider from "../src/slider"; - -function SliderComponent(props) { - const { settings } = props; - return ( -
-

Slider

- -
-

1

-
-
-

2

-
-
-

3

-
-
-

4

-
-
-

5

-
-
-

6

-
-
-
- ); -} - -export default SliderComponent; diff --git a/__test__/SliderComponent.test.js b/__test__/SliderComponent.test.js deleted file mode 100644 index b53bc9c8d..000000000 --- a/__test__/SliderComponent.test.js +++ /dev/null @@ -1,292 +0,0 @@ -import React from "react"; -import SliderComponent from "./SliderComponent"; -import { render, fireEvent } from "@testing-library/react"; -import { - getActiveSlide, - clickNext, - clickPrevious, - hasClass, - getActiveSlides, - getActiveSlidesCount, - getActiveSlidesText, - getButtons, - getButtonsListItem, - getCurrentSlide -} from "../test-utils"; - -describe("SliderComponent Tests with different settings", () => { - it("(SimpleSliderTest) should have 13 slides (1(preclone) + 6(actual) + 6(postclone))", function() { - const settings = { - dots: true, - infinite: true, - speed: 500, - slidesToShow: 1, - slidesToScroll: 1 - }; - const { container } = render(); - expect(container.getElementsByClassName("slick-slide").length).toBe(13); - }); - it("(SimpleSliderTest) should have 7 clone slides", function() { - const settings = { - dots: true, - infinite: true, - speed: 500, - slidesToShow: 1, - slidesToScroll: 1 - }; - const { container } = render(); - expect(container.getElementsByClassName("slick-cloned").length).toBe(7); - }); - it("(SimpleSliderTest) should have 1 current slide", function() { - const settings = { - dots: true, - infinite: true, - speed: 500, - slidesToShow: 1, - slidesToScroll: 1 - }; - const { container } = render(); - expect( - container.querySelectorAll(".slick-slide.slick-current").length - ).toBe(1); - expect(parseInt(getCurrentSlide(container).textContent) - 1).toBe(0); - }); - it("(SimpleSliderTest) should have 1 active slide", function() { - const settings = { - dots: true, - infinite: true, - speed: 500, - slidesToShow: 1, - slidesToScroll: 1 - }; - const { container } = render(); - expect(container.querySelectorAll(".slick-slide.slick-active").length).toBe( - 1 - ); - expect( - Array.from(getActiveSlide(container).children).map( - e => parseInt(e.textContent) - 1 - )[0] - ).toBe(0); - }); - it("(SimpleSliderTest) should have 1 current slide(When initialSlide is 2)", function() { - const settings = { - dots: true, - infinite: true, - speed: 500, - slidesToShow: 1, - slidesToScroll: 1, - initialSlide: 2 - }; - const { container } = render(); - expect( - container.querySelectorAll(".slick-slide.slick-current").length - ).toBe(1); - expect(parseInt(getCurrentSlide(container).textContent) - 1).toBe(2); - }); - it("(SimpleSliderTest) should have 1 active slide(When initialSlide is 2)", function() { - const settings = { - dots: true, - infinite: true, - speed: 500, - slidesToShow: 1, - slidesToScroll: 1, - initialSlide: 2 - }; - const { container } = render(); - expect(container.querySelectorAll(".slick-slide.slick-active").length).toBe( - 1 - ); - expect( - Array.from(getActiveSlide(container).children).map( - e => parseInt(e.textContent) - 1 - )[0] - ).toBe(2); - expect( - Array.from(getActiveSlide(container).children).map( - e => parseInt(e.textContent) - 1 - )[0] - ).toBe(2); - }); - it("(SimpleSliderTest) should have 6 dots", function() { - const settings = { - dots: true, - infinite: true, - speed: 500, - slidesToShow: 1, - slidesToScroll: 1 - }; - const { container } = render(); - expect( - container.getElementsByClassName("slick-dots")[0].children.length - ).toBe(6); - }); - it("(SimpleSliderTest) should have 1 active dot", function() { - const settings = { - dots: true, - infinite: true, - speed: 500, - slidesToShow: 1, - slidesToScroll: 1 - }; - const { container } = render(); - - expect(container.querySelectorAll(".slick-dots .slick-active").length).toBe( - 1 - ); - }); - it("(SimpleSliderTest) should have a prev arrow", function() { - const settings = { - dots: true, - infinite: true, - speed: 500, - slidesToShow: 1, - slidesToScroll: 1 - }; - const { container } = render(); - expect(container.getElementsByClassName("slick-prev").length).toBe(1); - }); - it("(SimpleSliderTest) should have a next arrow", function() { - const settings = { - dots: true, - infinite: true, - speed: 500, - slidesToShow: 1, - slidesToScroll: 1 - }; - const { container } = render(); - expect(container.getElementsByClassName("slick-next").length).toBe(1); - }); - it("(SimpleSliderTest) should got to next slide when next button is clicked", function() { - const settings = { - dots: true, - infinite: true, - speed: 500, - slidesToShow: 1, - slidesToScroll: 1 - }; - const { container } = render(); - clickNext(container); - expect( - container.querySelectorAll(".slick-slide.slick-active")[0].textContent - ).toBe("2"); - expect(container.querySelectorAll(".slick-dots .slick-active").length).toBe( - 1 - ); - expect( - container.querySelectorAll(".slick-dots")[0].children[1] - ).toHaveClass("slick-active"); - }); - it("(SimpleSliderTest) should goto previous slide when prev button is clicked", function() { - const settings = { - dots: true, - infinite: true, - speed: 500, - slidesToShow: 1, - slidesToScroll: 1 - }; - const { container } = render(); - clickPrevious(container); - expect( - container.querySelectorAll(".slick-slide.slick-active")[0].textContent - ).toBe("6"); - expect(container.querySelectorAll(".slick-dots .slick-active").length).toBe( - 1 - ); - expect( - container.querySelectorAll(".slick-dots")[0].children[5] - ).toHaveClass("slick-active"); - }); - it("(SimpleSliderTest) should got to next slide when next button is clicked (when intialSlide is equal to 2)", function() { - const settings = { - dots: true, - infinite: true, - speed: 500, - slidesToShow: 1, - slidesToScroll: 1, - initialSlide: 2 - }; - const { container } = render(); - clickNext(container); - expect( - container.querySelectorAll(".slick-slide.slick-active")[0].textContent - ).toBe("4"); - expect(container.querySelectorAll(".slick-dots .slick-active").length).toBe( - 1 - ); - expect( - container.querySelectorAll(".slick-dots")[0].children[3] - ).toHaveClass("slick-active"); - }); - it("(SimpleSliderTest) should goto previous slide when prev button is clicked (when intialSlide is equal to 2)", function() { - const settings = { - dots: true, - infinite: true, - speed: 500, - slidesToShow: 1, - slidesToScroll: 1, - initialSlide: 2 - }; - const { container } = render(); - clickPrevious(container); - expect( - container.querySelectorAll(".slick-slide.slick-active")[0].textContent - ).toBe("2"); - expect(container.querySelectorAll(".slick-dots .slick-active").length).toBe( - 1 - ); - expect( - container.querySelectorAll(".slick-dots")[0].children[1] - ).toHaveClass("slick-active"); - }); - it("(SimpleSliderTest) should goto 4th slide when 4th dot is clicked", function() { - const settings = { - dots: true, - infinite: true, - speed: 500, - slidesToShow: 1, - slidesToScroll: 1 - }; - const { container } = render(); - fireEvent( - container.querySelectorAll(".slick-dots button")[3], - new MouseEvent("click", { - bubbles: true, - cancelable: true - }) - ); - expect(getActiveSlidesText(container)[0]).toEqual("4"); - expect(getActiveSlidesCount(container)).toEqual(1); - expect(hasClass(getButtonsListItem(container)[3], "slick-active")).toEqual( - true - ); - }); -}); - -// describe("Simple Slider Snapshots", function() { -// it("slider initial state", function() { -// const { container } = render(); -// // expect(beautify_html(toString(container))).toMatchSnapshot(); -// }); -// it("click on next button", function() { -// const { container } = render(); -// clickNext(container); -// //expect(beautify_html(toString(container))).toMatchSnapshot(); -// }); -// it("click on prev button", function() { -// const { container } = render(); -// clickPrevious(container); -// // expect(beautify_html(toString(container))).toMatchSnapshot(); -// }); -// it("click on 3rd dot", function() { -// const { container } = render(); -// fireEvent( -// getButtons(container)[2], -// new MouseEvent("click", { -// bubbles: true, -// cancelable: true -// }) -// ); -// // expect(beautify_html(toString(container))).toMatchSnapshot(); -// }); -//}); diff --git a/src/inner-slider.js b/src/inner-slider.js index aba39da9d..b477bc2d1 100644 --- a/src/inner-slider.js +++ b/src/inner-slider.js @@ -35,7 +35,6 @@ 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 = []; From 45e92f0db50fb92e7128be09e9b2d82c17ed15e7 Mon Sep 17 00:00:00 2001 From: akiran Date: Mon, 5 Jun 2023 09:02:38 +0530 Subject: [PATCH 27/58] fixed some issues with component changes --- examples/CustomSlides.js | 4 ++-- examples/PreviousNextMethods.js | 13 +++++++++---- examples/SlideChangeHooks.js | 8 +++----- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/examples/CustomSlides.js b/examples/CustomSlides.js index da4ee51d3..07450e8b2 100644 --- a/examples/CustomSlides.js +++ b/examples/CustomSlides.js @@ -2,9 +2,9 @@ import React, { Component } from "react"; import Slider from "../src/slider"; function CustomSlide(props) { - const { index, ...props } = props; + const { index, ...otherProps } = props; return ( -
+

{index}

); diff --git a/examples/PreviousNextMethods.js b/examples/PreviousNextMethods.js index 4d7b04913..7eeeb33e3 100644 --- a/examples/PreviousNextMethods.js +++ b/examples/PreviousNextMethods.js @@ -2,12 +2,12 @@ import React, { useRef } from "react"; import Slider from "../src/slider"; function PreviousNextMethods(props) { - const sliderRef = useRef(null); + let sliderRef = useRef(null); const next = () => { - this.slider.slickNext(); + sliderRef.slickNext(); }; const previous = () => { - this.slider.slickPrev(); + sliderRef.slickPrev(); }; const settings = { dots: true, @@ -20,7 +20,12 @@ function PreviousNextMethods(props) { return (

Previous and Next methods

- (sliderRef = slider)} {...settings}> + { + sliderRef = slider; + }} + {...settings} + >

1

diff --git a/examples/SlideChangeHooks.js b/examples/SlideChangeHooks.js index 9e6a6a85f..cf3ca7938 100644 --- a/examples/SlideChangeHooks.js +++ b/examples/SlideChangeHooks.js @@ -22,15 +22,13 @@ function SlideChangeHooks() {

beforeChange and afterChange hooks

- BeforeChange {"=>"} oldSlide: {this.state.oldSlide} + BeforeChange {"=>"} oldSlide: {oldSlide}

- BeforeChange {"=>"} activeSlide:{" "} - {this.state.activeSlide} + BeforeChange {"=>"} activeSlide: {activeSlide}

- AfterChange {"=>"} activeSlide:{" "} - {this.state.activeSlide2} + AfterChange {"=>"} activeSlide: {activeSlide2}

From 76b833f0b76546478a384e6cf697249896e45245 Mon Sep 17 00:00:00 2001 From: akiran Date: Fri, 19 Jan 2024 13:43:33 +0530 Subject: [PATCH 28/58] added an empty prettierrc file to use default prettier config --- .prettierrc | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .prettierrc diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 000000000..e69de29bb From bb355c2a97212e0954c7e624b414fd5422da3785 Mon Sep 17 00:00:00 2001 From: akiran Date: Fri, 19 Jan 2024 22:26:42 +0530 Subject: [PATCH 29/58] added react-slick alias in webpack for examples --- examples/AdaptiveHeight.js | 2 +- examples/AppendDots.js | 2 +- examples/AsNavFor.js | 2 +- examples/AutoPlay.js | 2 +- examples/AutoPlayMethods.js | 2 +- examples/CenterMode.js | 2 +- examples/CustomArrows.js | 3 ++- examples/CustomPaging.js | 2 +- examples/CustomSlides.js | 2 +- examples/DynamicSlides.js | 2 +- examples/Fade.js | 2 +- examples/FocusOnSelect.js | 2 +- examples/LazyLoad.js | 2 +- examples/MultipleItems.js | 2 +- examples/MultipleRows.js | 2 +- examples/PauseOnHover.js | 2 +- examples/PreviousNextMethods.js | 2 +- examples/Resizable.js | 2 +- examples/Responsive.js | 2 +- examples/Rtl.js | 2 +- examples/SimpleSlider.js | 2 +- examples/SlickGoTo.js | 2 +- examples/SlideChangeHooks.js | 2 +- examples/SwipeToSlide.js | 2 +- examples/UnevenSetsFinite.js | 2 +- examples/UnevenSetsInfinite.js | 2 +- examples/VariableWidth.js | 2 +- examples/VerticalMode.js | 2 +- examples/VerticalSwipeToSlide.js | 2 +- webpack.config.js | 5 ++++- 30 files changed, 34 insertions(+), 30 deletions(-) diff --git a/examples/AdaptiveHeight.js b/examples/AdaptiveHeight.js index 4f24ca3ad..5b0faa85b 100644 --- a/examples/AdaptiveHeight.js +++ b/examples/AdaptiveHeight.js @@ -1,5 +1,5 @@ import React from "react"; -import Slider from "../src/slider"; +import Slider from "react-slick"; function AdaptiveHeight() { const settings = { diff --git a/examples/AppendDots.js b/examples/AppendDots.js index 57f8ccb39..ab467e6bf 100644 --- a/examples/AppendDots.js +++ b/examples/AppendDots.js @@ -1,5 +1,5 @@ import React from "react"; -import Slider from "../src/slider"; +import Slider from "react-slick"; function AppendDots() { const settings = { diff --git a/examples/AsNavFor.js b/examples/AsNavFor.js index cab4c1a9a..739b89ae8 100644 --- a/examples/AsNavFor.js +++ b/examples/AsNavFor.js @@ -1,5 +1,5 @@ import React, { useState, useEffect, useRef } from "react"; -import Slider from "../src/slider"; +import Slider from "react-slick"; function AsNavFor(props) { const [nav1, setNav1] = useState(null); diff --git a/examples/AutoPlay.js b/examples/AutoPlay.js index 452ea8659..2cb6eb5d5 100644 --- a/examples/AutoPlay.js +++ b/examples/AutoPlay.js @@ -1,5 +1,5 @@ import React from "react"; -import Slider from "../src/slider"; +import Slider from "react-slick"; function AutoPlay() { const settings = { diff --git a/examples/AutoPlayMethods.js b/examples/AutoPlayMethods.js index c6b4d635d..ab902f8c0 100644 --- a/examples/AutoPlayMethods.js +++ b/examples/AutoPlayMethods.js @@ -1,5 +1,5 @@ import React, { useRef } from "react"; -import Slider from "../src/slider"; +import Slider from "react-slick"; function AutoPlayMethods(props) { let sliderRef = useRef(null); diff --git a/examples/CenterMode.js b/examples/CenterMode.js index 101df61ca..de1fd16e9 100644 --- a/examples/CenterMode.js +++ b/examples/CenterMode.js @@ -1,5 +1,5 @@ import React, { Component } from "react"; -import Slider from "../src/slider"; +import Slider from "react-slick"; function CenterMode() { const settings = { diff --git a/examples/CustomArrows.js b/examples/CustomArrows.js index fbd3582ca..f3e0b02d4 100644 --- a/examples/CustomArrows.js +++ b/examples/CustomArrows.js @@ -1,7 +1,8 @@ import React, { Component } from "react"; -import Slider from "../src/slider"; +import Slider from "react-slick"; function SampleNextArrow(props) { + console.log(props); const { className, style, onClick } = props; return (
Date: Sat, 20 Jan 2024 22:27:28 +0530 Subject: [PATCH 30/58] running single demo on different port --- gulpfile.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gulpfile.js b/gulpfile.js index b0351b5a4..2859e2b9f 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -9,7 +9,7 @@ var opn = require("opn"); var UglifyJsPlugin = require("uglifyjs-webpack-plugin"); -const DEV_PORT = 8080; +const DEV_PORT = process.env.DEV_PORT || 8080; gulp.task("clean", function() { return del(["./build/*"]); diff --git a/package.json b/package.json index 6425e7f7d..8395727b9 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ ], "scripts": { "start": "NODE_OPTIONS=--openssl-legacy-provider gulp server", - "demo": "SINGLE_DEMO=true NODE_OPTIONS=--openssl-legacy-provider gulp server", + "demo": "SINGLE_DEMO=true DEV_PORT=8000 NODE_OPTIONS=--openssl-legacy-provider gulp server", "build-dev": "gulp clean && gulp copy && webpack", "lib": "babel ./src --out-dir ./lib", "build": "npm run lib && gulp dist", From 3669b0a44b0d26a97dc3612ea7ff1ed7dbcfda82 Mon Sep 17 00:00:00 2001 From: rjsdnql123 Date: Thu, 25 Jan 2024 00:41:37 +0900 Subject: [PATCH 31/58] Fix: If the element (DOM element) and the value of 'slidesToShow' are the same, and 'infinite' is set to true, swipe should be possible. --- src/slider.js | 2 +- src/track.js | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/slider.js b/src/slider.js index 65d63a4b5..82c91a912 100644 --- a/src/slider.js +++ b/src/slider.js @@ -198,7 +198,7 @@ export default class Slider extends React.Component { if (settings === "unslick") { const className = "regular slider " + (this.props.className || ""); return
{children}
; - } else if (newChildren.length <= settings.slidesToShow) { + } else if (newChildren.length <= settings.slidesToShow && !settings.infinite) { settings.unslick = true; } return ( diff --git a/src/track.js b/src/track.js index f8924c826..2378d048d 100644 --- a/src/track.js +++ b/src/track.js @@ -138,8 +138,7 @@ const renderSlides = spec => { if (spec.infinite && spec.fade === false) { let preCloneNo = childrenCount - index; if ( - preCloneNo <= getPreClones(spec) && - childrenCount !== spec.slidesToShow + preCloneNo <= getPreClones(spec) ) { key = -preCloneNo; if (key >= startIndex) { @@ -164,7 +163,6 @@ const renderSlides = spec => { ); } - if (childrenCount !== spec.slidesToShow) { key = childrenCount + index; if (key < endIndex) { child = elem; @@ -186,7 +184,6 @@ const renderSlides = spec => { } }) ); - } } }); From 5b2e405eb5b1efe47afadcf9fa891f8303f7ad4b Mon Sep 17 00:00:00 2001 From: akiran Date: Thu, 25 Jan 2024 10:03:07 +0530 Subject: [PATCH 32/58] added tests for #1813 --- {__test__ => __tests__}/SimpleSlider.test.js | 0 {__test__ => __tests__}/afterChange.test.js | 0 {__test__ => __tests__}/arrows.js | 0 {__test__ => __tests__}/beforeChange.test.js | 0 {__test__ => __tests__}/jQSlickUtils.js | 0 {__test__ => __tests__}/lazyLoad.test.js | 0 .../mount/centerMode.test.js | 0 .../mount/lazyLoad.test.js | 0 {__test__ => __tests__}/mount/live.test.js | 0 {__test__ => __tests__}/mount/simple.test.js | 0 {__test__ => __tests__}/observations.json | 0 {__test__ => __tests__}/reactSlickUtils.js | 0 __tests__/regression/fix-1813.js | 196 ++++++++++++++++++ {__test__ => __tests__}/sliderStyles.test.js | 0 {__test__ => __tests__}/testUtils.js | 0 docs/single-demo.js | 4 +- 16 files changed, 199 insertions(+), 1 deletion(-) rename {__test__ => __tests__}/SimpleSlider.test.js (100%) rename {__test__ => __tests__}/afterChange.test.js (100%) rename {__test__ => __tests__}/arrows.js (100%) rename {__test__ => __tests__}/beforeChange.test.js (100%) rename {__test__ => __tests__}/jQSlickUtils.js (100%) rename {__test__ => __tests__}/lazyLoad.test.js (100%) rename {__test__ => __tests__}/mount/centerMode.test.js (100%) rename {__test__ => __tests__}/mount/lazyLoad.test.js (100%) rename {__test__ => __tests__}/mount/live.test.js (100%) rename {__test__ => __tests__}/mount/simple.test.js (100%) rename {__test__ => __tests__}/observations.json (100%) rename {__test__ => __tests__}/reactSlickUtils.js (100%) create mode 100644 __tests__/regression/fix-1813.js rename {__test__ => __tests__}/sliderStyles.test.js (100%) rename {__test__ => __tests__}/testUtils.js (100%) diff --git a/__test__/SimpleSlider.test.js b/__tests__/SimpleSlider.test.js similarity index 100% rename from __test__/SimpleSlider.test.js rename to __tests__/SimpleSlider.test.js diff --git a/__test__/afterChange.test.js b/__tests__/afterChange.test.js similarity index 100% rename from __test__/afterChange.test.js rename to __tests__/afterChange.test.js diff --git a/__test__/arrows.js b/__tests__/arrows.js similarity index 100% rename from __test__/arrows.js rename to __tests__/arrows.js diff --git a/__test__/beforeChange.test.js b/__tests__/beforeChange.test.js similarity index 100% rename from __test__/beforeChange.test.js rename to __tests__/beforeChange.test.js diff --git a/__test__/jQSlickUtils.js b/__tests__/jQSlickUtils.js similarity index 100% rename from __test__/jQSlickUtils.js rename to __tests__/jQSlickUtils.js diff --git a/__test__/lazyLoad.test.js b/__tests__/lazyLoad.test.js similarity index 100% rename from __test__/lazyLoad.test.js rename to __tests__/lazyLoad.test.js diff --git a/__test__/mount/centerMode.test.js b/__tests__/mount/centerMode.test.js similarity index 100% rename from __test__/mount/centerMode.test.js rename to __tests__/mount/centerMode.test.js diff --git a/__test__/mount/lazyLoad.test.js b/__tests__/mount/lazyLoad.test.js similarity index 100% rename from __test__/mount/lazyLoad.test.js rename to __tests__/mount/lazyLoad.test.js diff --git a/__test__/mount/live.test.js b/__tests__/mount/live.test.js similarity index 100% rename from __test__/mount/live.test.js rename to __tests__/mount/live.test.js diff --git a/__test__/mount/simple.test.js b/__tests__/mount/simple.test.js similarity index 100% rename from __test__/mount/simple.test.js rename to __tests__/mount/simple.test.js diff --git a/__test__/observations.json b/__tests__/observations.json similarity index 100% rename from __test__/observations.json rename to __tests__/observations.json diff --git a/__test__/reactSlickUtils.js b/__tests__/reactSlickUtils.js similarity index 100% rename from __test__/reactSlickUtils.js rename to __tests__/reactSlickUtils.js diff --git a/__tests__/regression/fix-1813.js b/__tests__/regression/fix-1813.js new file mode 100644 index 000000000..4dafd8602 --- /dev/null +++ b/__tests__/regression/fix-1813.js @@ -0,0 +1,196 @@ +//Test fix of #1813: In infinite mode, when slidesToShow equal to the length of slides, infinite functionality is not working. + +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 +} from "../../test-utils"; + +function MultipleItems() { + const settings = { + dots: true, + infinite: true, + speed: 500, + slidesToShow: 9, + slidesToScroll: 3 + }; + return ( +
+

Multiple items

+ +
+

1

+
+
+

2

+
+
+

3

+
+
+

4

+
+
+

5

+
+
+

6

+
+
+

7

+
+
+

8

+
+
+

9

+
+
+
+ ); +} + +describe("Multiple Items with slidesToShow = slides count in infinite mode", function() { + it("should have 9 actual slides and (9(pre) + 9(post)) clone slides", function() { + //Todo: Need to fix extra clones + const { container } = render(); + expect(getSlidesCount(container)).toEqual(27); + expect(getClonesCount(container)).toEqual(18); + }); + it("should have 9 active slides", function() { + const { container } = render(); + expect(getActiveSlidesCount(container)).toEqual(9); + }); + it("should have 3 dots", function() { + const { container } = render(); + expect(getButtonsLength(container)).toEqual(3); + }); + it("should show first 9 slides", function() { + const { container } = render(); + expect(getActiveButton(container)).toEqual(["1"]); + expect(getActiveSlidesText(container)).toEqual([ + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9" + ]); + }); + it("should show slides from 4 when next button is clicked", function() { + const { container } = render(); + clickNext(container); + expect(getActiveButton(container)).toEqual(["2"]); + expect(getActiveSlidesText(container)).toEqual([ + "4", + "5", + "6", + "7", + "8", + "9", + "1", + "2", + "3" + ]); + }); + it("should show slides from 7 when previous button is clicked", function() { + const { container } = render(); + clickPrevious(container); + expect(getActiveButton(container)).toEqual(["3"]); + expect(getActiveSlidesText(container)).toEqual([ + "7", + "8", + "9", + "1", + "2", + "3", + "4", + "5", + "6" + ]); + }); + it("should show slides first 9 slides when first dot is clicked", function() { + const { container } = render(); + fireEvent( + getButtons(container)[0], + new MouseEvent("click", { + bubbles: true, + cancelable: true + }) + ); + expect(getActiveButton(container)).toEqual(["1"]); + expect(getActiveSlidesText(container)).toEqual([ + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9" + ]); + }); + it("should show slides from 4 when middle dot is clicked", function() { + const { container } = render(); + fireEvent( + getButtons(container)[1], + new MouseEvent("click", { + bubbles: true, + cancelable: true + }) + ); + expect(getActiveButton(container)).toEqual(["2"]); + expect(getActiveSlidesText(container)).toEqual([ + "4", + "5", + "6", + "7", + "8", + "9", + "1", + "2", + "3" + ]); + }); + it("should show slides from 7 when last dot is clicked", function() { + const { container } = render(); + fireEvent( + getButtons(container)[2], + new MouseEvent("click", { + bubbles: true, + cancelable: true + }) + ); + expect(getActiveButton(container)).toEqual(["3"]); + expect(getActiveSlidesText(container)).toEqual([ + "7", + "8", + "9", + "1", + "2", + "3", + "4", + "5", + "6" + ]); + }); +}); diff --git a/__test__/sliderStyles.test.js b/__tests__/sliderStyles.test.js similarity index 100% rename from __test__/sliderStyles.test.js rename to __tests__/sliderStyles.test.js diff --git a/__test__/testUtils.js b/__tests__/testUtils.js similarity index 100% rename from __test__/testUtils.js rename to __tests__/testUtils.js diff --git a/docs/single-demo.js b/docs/single-demo.js index 48880e398..81d7213e8 100644 --- a/docs/single-demo.js +++ b/docs/single-demo.js @@ -3,6 +3,7 @@ import React from "react"; import ReactDOM from "react-dom"; import Slider from "../src/slider"; +import MultipleItems from "../examples/MultipleItems"; function SimpleSlider() { const settings = { dots: true, @@ -41,7 +42,8 @@ function SimpleSlider() { function App() { return (
- + {/* */} +
); } From ff0cd50c596348bb1b424470b1b80ffd6b641562 Mon Sep 17 00:00:00 2001 From: akiran Date: Thu, 25 Jan 2024 10:06:15 +0530 Subject: [PATCH 33/58] release 0.30.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8395727b9..9518a536e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-slick", - "version": "0.29.0", + "version": "0.30.0", "description": " React port of slick carousel", "main": "./lib", "files": [ From 891f399cbb6c86e26ca850f608313390da8cf0b6 Mon Sep 17 00:00:00 2001 From: akiran Date: Thu, 25 Jan 2024 10:14:01 +0530 Subject: [PATCH 34/58] added node options to fix build issue --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9518a536e..c7537de36 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "demo": "SINGLE_DEMO=true DEV_PORT=8000 NODE_OPTIONS=--openssl-legacy-provider gulp server", "build-dev": "gulp clean && gulp copy && webpack", "lib": "babel ./src --out-dir ./lib", - "build": "npm run lib && gulp dist", + "build": "NODE_OPTIONS=--openssl-legacy-provider npm run lib && NODE_OPTIONS=--openssl-legacy-provider gulp dist", "prepublishOnly": "npm run build", "lint": "eslint src", "gen": "node examples/scripts/generateExampleConfigs.js && node examples/scripts/generateExamples.js && xdg-open docs/jquery.html", From 358d8c04740d20891e1b0bdae6a47d5022af4dc6 Mon Sep 17 00:00:00 2001 From: akiran Date: Thu, 25 Jan 2024 14:55:36 +0530 Subject: [PATCH 35/58] created a generic slider component for tests --- __tests__/TestComponents.js | 13 +++++++ .../{fix-1813.js => fix-1813.test.js} | 36 ++----------------- 2 files changed, 15 insertions(+), 34 deletions(-) create mode 100644 __tests__/TestComponents.js rename __tests__/regression/{fix-1813.js => fix-1813.test.js} (87%) diff --git a/__tests__/TestComponents.js b/__tests__/TestComponents.js new file mode 100644 index 000000000..ebd75589e --- /dev/null +++ b/__tests__/TestComponents.js @@ -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 => ( +
{item + 1}
+ )); + return {slides}; +} + +test("fake test", () => { + expect(1).toBe(1); +}); diff --git a/__tests__/regression/fix-1813.js b/__tests__/regression/fix-1813.test.js similarity index 87% rename from __tests__/regression/fix-1813.js rename to __tests__/regression/fix-1813.test.js index 4dafd8602..0618f8527 100644 --- a/__tests__/regression/fix-1813.js +++ b/__tests__/regression/fix-1813.test.js @@ -20,6 +20,7 @@ import { getSlidesCount, hasClass } from "../../test-utils"; +import { GenericSliderComponent } from "../TestComponents"; function MultipleItems() { const settings = { @@ -29,40 +30,7 @@ function MultipleItems() { slidesToShow: 9, slidesToScroll: 3 }; - return ( -
-

Multiple items

- -
-

1

-
-
-

2

-
-
-

3

-
-
-

4

-
-
-

5

-
-
-

6

-
-
-

7

-
-
-

8

-
-
-

9

-
-
-
- ); + return ; } describe("Multiple Items with slidesToShow = slides count in infinite mode", function() { From dbae660a0ecf13da13961c6a205353ef9843fd01 Mon Sep 17 00:00:00 2001 From: akiran Date: Thu, 25 Jan 2024 17:59:38 +0530 Subject: [PATCH 36/58] fixed #1874: slick-current is always on first slide despite initialSlide != 0 --- __tests__/regression/fix-1813.test.js | 7 +------ __tests__/regression/fix-1874.test.js | 25 +++++++++++++++++++++++++ src/inner-slider.js | 1 + test-utils.js | 5 +++++ 4 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 __tests__/regression/fix-1874.test.js diff --git a/__tests__/regression/fix-1813.test.js b/__tests__/regression/fix-1813.test.js index 0618f8527..5b4722259 100644 --- a/__tests__/regression/fix-1813.test.js +++ b/__tests__/regression/fix-1813.test.js @@ -2,11 +2,8 @@ import React from "react"; import { render, fireEvent } from "@testing-library/react"; -import Slider from "../../src/index"; import { - activeSlide, - activeSlides, clickNext, clickPrevious, getActiveButton, @@ -14,11 +11,9 @@ import { getActiveSlidesText, getButtons, getButtonsLength, - getButtonsListItem, getClonesCount, getCurrentSlide, - getSlidesCount, - hasClass + getSlidesCount } from "../../test-utils"; import { GenericSliderComponent } from "../TestComponents"; diff --git a/__tests__/regression/fix-1874.test.js b/__tests__/regression/fix-1874.test.js new file mode 100644 index 000000000..67f9c1502 --- /dev/null +++ b/__tests__/regression/fix-1874.test.js @@ -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(); + expect(getCurrentSlideContent(container)).toEqual("1"); + clickNext(container); + expect(getCurrentSlideContent(container)).toEqual("2"); + }); + + it("currentSlide is 2 when initialSlide is 2", function() { + const { container } = render( + + ); + expect(getCurrentSlideContent(container)).toEqual("3"); + clickNext(container); + expect(getCurrentSlideContent(container)).toEqual("4"); + }); +}); diff --git a/src/inner-slider.js b/src/inner-slider.js index b477bc2d1..aba39da9d 100644 --- a/src/inner-slider.js +++ b/src/inner-slider.js @@ -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 = []; diff --git a/test-utils.js b/test-utils.js index 71286463f..265b79bfb 100644 --- a/test-utils.js +++ b/test-utils.js @@ -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"); } From 9d96291f41f34e4df3988da9b7be99391d10d974 Mon Sep 17 00:00:00 2001 From: akiran Date: Thu, 25 Jan 2024 22:22:41 +0530 Subject: [PATCH 37/58] Fixed #2315 --- .prettierrc | 1 + src/slider.js | 9 ++++++--- src/utils/innerSliderUtils.js | 25 ++++++++++++++++++++----- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/.prettierrc b/.prettierrc index e69de29bb..cbc61f68e 100644 --- a/.prettierrc +++ b/.prettierrc @@ -0,0 +1 @@ +trailingComma: none \ No newline at end of file diff --git a/src/slider.js b/src/slider.js index 82c91a912..36225013e 100644 --- a/src/slider.js +++ b/src/slider.js @@ -4,7 +4,7 @@ import React from "react"; import { InnerSlider } from "./inner-slider"; import json2mq from "json2mq"; import defaultProps from "./default-props"; -import { canUseDOM } from "./utils/innerSliderUtils"; +import { canUseDOM, filterSettings } from "./utils/innerSliderUtils"; const enquire = canUseDOM() && require("enquire.js"); export default class Slider extends React.Component { @@ -198,14 +198,17 @@ export default class Slider extends React.Component { if (settings === "unslick") { const className = "regular slider " + (this.props.className || ""); return
{children}
; - } else if (newChildren.length <= settings.slidesToShow && !settings.infinite) { + } else if ( + newChildren.length <= settings.slidesToShow && + !settings.infinite + ) { settings.unslick = true; } return ( {newChildren} diff --git a/src/utils/innerSliderUtils.js b/src/utils/innerSliderUtils.js index c06029d0a..98a37e917 100644 --- a/src/utils/innerSliderUtils.js +++ b/src/utils/innerSliderUtils.js @@ -1,4 +1,5 @@ import React from "react"; +import defaultProps from "../default-props"; export function clamp(number, lowerBound, upperBound) { return Math.max(lowerBound, Math.min(number, upperBound)); @@ -6,10 +7,10 @@ export function clamp(number, lowerBound, upperBound) { export const safePreventDefault = event => { const passiveEvents = ["onTouchStart", "onTouchMove", "onWheel"]; - if(!passiveEvents.includes(event._reactName)) { + if (!passiveEvents.includes(event._reactName)) { event.preventDefault(); } -} +}; export const getOnDemandLazySlides = spec => { let onDemandSlides = []; @@ -386,9 +387,12 @@ export const swipeMove = (e, spec) => { let touchSwipeLength = touchObject.swipeLength; if (!infinite) { if ( - (currentSlide === 0 && (swipeDirection === "right" || swipeDirection === "down")) || - (currentSlide + 1 >= dotCount && (swipeDirection === "left" || swipeDirection === "up")) || - (!canGoNext(spec) && (swipeDirection === "left" || swipeDirection === "up")) + (currentSlide === 0 && + (swipeDirection === "right" || swipeDirection === "down")) || + (currentSlide + 1 >= dotCount && + (swipeDirection === "left" || swipeDirection === "up")) || + (!canGoNext(spec) && + (swipeDirection === "left" || swipeDirection === "up")) ) { touchSwipeLength = touchObject.swipeLength * edgeFriction; if (edgeDragged === false && onEdge) { @@ -849,3 +853,14 @@ export const canUseDOM = () => window.document && window.document.createElement ); + +export const validSettings = Object.keys(defaultProps); + +export function filterSettings(settings) { + return validSettings.reduce((acc, settingName) => { + if (settings.hasOwnProperty(settingName)) { + acc[settingName] = settings[settingName]; + } + return acc; + }, {}); +} From 27870b7d007bf6db869f14a51a0c07c254bb49b7 Mon Sep 17 00:00:00 2001 From: akiran Date: Fri, 26 Jan 2024 18:38:53 +0530 Subject: [PATCH 38/58] Test for #2315 --- __tests__/regression/fix-2315.test.js | 35 +++++++++++++++++++++++++++ package.json | 3 ++- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 __tests__/regression/fix-2315.test.js diff --git a/__tests__/regression/fix-2315.test.js b/__tests__/regression/fix-2315.test.js new file mode 100644 index 000000000..193cf464f --- /dev/null +++ b/__tests__/regression/fix-2315.test.js @@ -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 ( +
+ + +
+ ); +} + +describe("State change in parent component of slider", () => { + it("Slider shoud work afer clicking on Increment button", function() { + const { container } = render(); + 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); + }); +}); diff --git a/package.json b/package.json index c7537de36..1f8760f50 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,8 @@ "gen": "node examples/scripts/generateExampleConfigs.js && node examples/scripts/generateExamples.js && xdg-open docs/jquery.html", "precommit": "lint-staged", "test": "jest", - "test-watch": "jest --watch" + "test-watch": "jest --watch", + "clear-jest": "jest --clearCache" }, "author": "Kiran Abburi", "license": "MIT", From 8c9488f369390994addf76bf32d435edfe8e4e89 Mon Sep 17 00:00:00 2001 From: akiran Date: Fri, 26 Jan 2024 19:34:45 +0530 Subject: [PATCH 39/58] check of NaN in props change detection --- src/inner-slider.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/inner-slider.js b/src/inner-slider.js index aba39da9d..e6efb784b 100644 --- a/src/inner-slider.js +++ b/src/inner-slider.js @@ -134,7 +134,8 @@ export class InnerSlider extends React.Component { } if ( typeof prevProps[key] === "object" || - typeof prevProps[key] === "function" + typeof prevProps[key] === "function" || + isNaN(prevProps[key]) ) { continue; } From 02629d5dbbc7c71ec8ec6a0e485137a63a652f7e Mon Sep 17 00:00:00 2001 From: akiran Date: Fri, 26 Jan 2024 19:44:52 +0530 Subject: [PATCH 40/58] added tests for filterSettings util --- __tests__/utils/filterSettings.test.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 __tests__/utils/filterSettings.test.js diff --git a/__tests__/utils/filterSettings.test.js b/__tests__/utils/filterSettings.test.js new file mode 100644 index 000000000..fa431b195 --- /dev/null +++ b/__tests__/utils/filterSettings.test.js @@ -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 + }); + }); +}); From 250f078424f70f648a1f299b13de0689efe7f6f1 Mon Sep 17 00:00:00 2001 From: akiran Date: Fri, 26 Jan 2024 21:42:37 +0530 Subject: [PATCH 41/58] release 0.30.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1f8760f50..cf3fa0548 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-slick", - "version": "0.30.0", + "version": "0.30.1", "description": " React port of slick carousel", "main": "./lib", "files": [ From 0a66bd73f0a6fa0f763a7d8be4ecdedb94a22847 Mon Sep 17 00:00:00 2001 From: akiran Date: Fri, 26 Jan 2024 22:09:25 +0530 Subject: [PATCH 42/58] updated instructions for css loading --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index c5e654e5b..d56d2ee72 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ npm install slick-carousel // Import css files import "slick-carousel/slick/slick.css"; import "slick-carousel/slick/slick-theme.css"; +// Copy `slick-carousel/slick/fonts` into your static assets folder and make sure the fonts are loadable by css request ``` or add cdn link in your html @@ -46,6 +47,13 @@ or add cdn link in your html /> ``` +or copy `slick-carousel/slick` folder into your static assets folder and link to css + +```html + + +``` + ### [PlayGround](https://codesandbox.io/s/ppwkk5l6xx) ### Example @@ -111,7 +119,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) From 1bd9c093fec4fbd133ecaeef0e476cc715910682 Mon Sep 17 00:00:00 2001 From: akiran Date: Fri, 26 Jan 2024 22:31:07 +0530 Subject: [PATCH 43/58] updated readme --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index d56d2ee72..4f5168d48 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,6 @@ npm install slick-carousel // Import css files import "slick-carousel/slick/slick.css"; import "slick-carousel/slick/slick-theme.css"; -// Copy `slick-carousel/slick/fonts` into your static assets folder and make sure the fonts are loadable by css request ``` or add cdn link in your html From 7710dc9e44c76068b7c1a64b8e74c59cc758c085 Mon Sep 17 00:00:00 2001 From: Jorrit Schippers Date: Fri, 2 Feb 2024 10:22:05 +0100 Subject: [PATCH 44/58] Move testing dependency to devDependencies --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cf3fa0548..a17f26a3f 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "@babel/preset-react": "^7.0.0", "@testing-library/jest-dom": "^5.16.4", "@testing-library/react": "^13.3.0", + "@testing-library/user-event": "^14.3.0", "autoprefixer": "^7.1.2", "babel-core": "^7.0.0-bridge.0", "babel-jest": "^24.8.0", @@ -82,7 +83,6 @@ "why-did-you-update": "^0.1.1" }, "dependencies": { - "@testing-library/user-event": "^14.3.0", "classnames": "^2.2.5", "enquire.js": "^2.1.6", "json2mq": "^0.2.0", From 013f424e0adcef81da05af055edd6d34d3b45a23 Mon Sep 17 00:00:00 2001 From: akiran Date: Sat, 3 Feb 2024 09:36:57 +0530 Subject: [PATCH 45/58] moved scripts from examples to docs --- {examples => docs}/scripts/generateExampleConfigs.js | 0 {examples => docs}/scripts/generateExamples.js | 0 package.json | 2 +- 3 files changed, 1 insertion(+), 1 deletion(-) rename {examples => docs}/scripts/generateExampleConfigs.js (100%) rename {examples => docs}/scripts/generateExamples.js (100%) diff --git a/examples/scripts/generateExampleConfigs.js b/docs/scripts/generateExampleConfigs.js similarity index 100% rename from examples/scripts/generateExampleConfigs.js rename to docs/scripts/generateExampleConfigs.js diff --git a/examples/scripts/generateExamples.js b/docs/scripts/generateExamples.js similarity index 100% rename from examples/scripts/generateExamples.js rename to docs/scripts/generateExamples.js diff --git a/package.json b/package.json index a17f26a3f..6ab3c5320 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "build": "NODE_OPTIONS=--openssl-legacy-provider npm run lib && NODE_OPTIONS=--openssl-legacy-provider gulp dist", "prepublishOnly": "npm run build", "lint": "eslint src", - "gen": "node examples/scripts/generateExampleConfigs.js && node examples/scripts/generateExamples.js && xdg-open docs/jquery.html", + "gen": "node docs/scripts/generateExampleConfigs.js && node docs/scripts/generateExamples.js && xdg-open docs/jquery.html", "precommit": "lint-staged", "test": "jest", "test-watch": "jest --watch", From 5a99cd1a7464f221d8119c9438729c514ed42f25 Mon Sep 17 00:00:00 2001 From: akiran Date: Sat, 3 Feb 2024 09:42:18 +0530 Subject: [PATCH 46/58] examples config to docs --- {examples => docs}/config.js | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {examples => docs}/config.js (100%) diff --git a/examples/config.js b/docs/config.js similarity index 100% rename from examples/config.js rename to docs/config.js From c0fde5ee0db0d65f1e1cfe6b09ee2eb94a73e3e0 Mon Sep 17 00:00:00 2001 From: akiran Date: Sat, 3 Feb 2024 13:37:05 +0530 Subject: [PATCH 47/58] cleanup examples --- examples/AdaptiveHeight.js | 1 - examples/AppendDots.js | 1 - examples/AsNavFor.js | 2 +- examples/AutoPlay.js | 1 - examples/AutoPlayMethods.js | 2 +- examples/CenterMode.js | 1 - examples/CustomArrows.js | 2 -- examples/CustomPaging.js | 1 - examples/CustomSlides.js | 3 +-- examples/DynamicSlides.js | 13 ++----------- examples/Fade.js | 1 - examples/FocusOnSelect.js | 1 - examples/LazyLoad.js | 1 - examples/MultipleItems.js | 1 - examples/MultipleRows.js | 1 - examples/PauseOnHover.js | 1 - examples/PreviousNextMethods.js | 6 ++---- examples/Responsive.js | 1 - examples/SimpleSlider.js | 6 ++---- examples/SlickGoTo.js | 6 ++---- examples/SwipeToSlide.js | 1 - examples/UnevenSetsFinite.js | 1 - examples/UnevenSetsInfinite.js | 1 - examples/VariableWidth.js | 1 - examples/VerticalMode.js | 1 - examples/VerticalSwipeToSlide.js | 1 - {docs => examples}/config.js | 0 27 files changed, 11 insertions(+), 47 deletions(-) rename {docs => examples}/config.js (100%) diff --git a/examples/AdaptiveHeight.js b/examples/AdaptiveHeight.js index 5b0faa85b..e0e920aab 100644 --- a/examples/AdaptiveHeight.js +++ b/examples/AdaptiveHeight.js @@ -13,7 +13,6 @@ function AdaptiveHeight() { return (
-

Adaptive height

1

diff --git a/examples/AppendDots.js b/examples/AppendDots.js index ab467e6bf..192f9613d 100644 --- a/examples/AppendDots.js +++ b/examples/AppendDots.js @@ -33,7 +33,6 @@ function AppendDots() { }; return (
-

Append Dots

1

diff --git a/examples/AsNavFor.js b/examples/AsNavFor.js index 739b89ae8..0676e39d5 100644 --- a/examples/AsNavFor.js +++ b/examples/AsNavFor.js @@ -1,7 +1,7 @@ import React, { useState, useEffect, useRef } from "react"; import Slider from "react-slick"; -function AsNavFor(props) { +function AsNavFor() { const [nav1, setNav1] = useState(null); const [nav2, setNav2] = useState(null); let sliderRef1 = useRef(null); diff --git a/examples/AutoPlay.js b/examples/AutoPlay.js index 2cb6eb5d5..b2f1601f7 100644 --- a/examples/AutoPlay.js +++ b/examples/AutoPlay.js @@ -14,7 +14,6 @@ function AutoPlay() { }; return (
-

Auto Play

1

diff --git a/examples/AutoPlayMethods.js b/examples/AutoPlayMethods.js index ab902f8c0..ddfd9d08f 100644 --- a/examples/AutoPlayMethods.js +++ b/examples/AutoPlayMethods.js @@ -1,7 +1,7 @@ import React, { useRef } from "react"; import Slider from "react-slick"; -function AutoPlayMethods(props) { +function AutoPlayMethods() { let sliderRef = useRef(null); const play = () => { sliderRef.slickPlay(); diff --git a/examples/CenterMode.js b/examples/CenterMode.js index de1fd16e9..5ec5e5aee 100644 --- a/examples/CenterMode.js +++ b/examples/CenterMode.js @@ -12,7 +12,6 @@ function CenterMode() { }; return (
-

Center Mode

1

diff --git a/examples/CustomArrows.js b/examples/CustomArrows.js index f3e0b02d4..343b8f2db 100644 --- a/examples/CustomArrows.js +++ b/examples/CustomArrows.js @@ -2,7 +2,6 @@ import React, { Component } from "react"; import Slider from "react-slick"; function SampleNextArrow(props) { - console.log(props); const { className, style, onClick } = props; return (
-

Custom Arrows

1

diff --git a/examples/CustomPaging.js b/examples/CustomPaging.js index f594d0732..038428fe6 100644 --- a/examples/CustomPaging.js +++ b/examples/CustomPaging.js @@ -20,7 +20,6 @@ function CustomPaging() { }; return (
-

Custom Paging

diff --git a/examples/CustomSlides.js b/examples/CustomSlides.js index 87e09d966..ada9f1048 100644 --- a/examples/CustomSlides.js +++ b/examples/CustomSlides.js @@ -10,7 +10,7 @@ function CustomSlide(props) { ); } -function SimpleSlider() { +function CustomSlides() { const settings = { dots: true, infinite: true, @@ -20,7 +20,6 @@ function SimpleSlider() { }; return (
-

Custom Slides

diff --git a/examples/DynamicSlides.js b/examples/DynamicSlides.js index d8cb61f8a..40520e384 100644 --- a/examples/DynamicSlides.js +++ b/examples/DynamicSlides.js @@ -1,31 +1,22 @@ import React, { useState } from "react"; import Slider from "react-slick"; -function DynamicSlides(props) { +function DynamicSlides() { const [slides, setSlides] = useState([1, 2, 3, 4, 5, 6]); const handleClick = () => { setSlides( slides.length === 6 ? [1, 2, 3, 4, 5, 6, 7, 8, 9] : [1, 2, 3, 4, 5, 6] ); }; - // click() { - // const { slides } = this.state; - // this.setState({ - // slides: - // slides.length === 6 ? [1, 2, 3, 4, 5, 6, 7, 8, 9] : [1, 2, 3, 4, 5, 6] - // }); - // } const settings = { dots: true, infinite: true, speed: 500, slidesToShow: 3, - slidesToScroll: 3, - ...props + slidesToScroll: 3 }; return (
-

Dynamic slides

diff --git a/examples/Fade.js b/examples/Fade.js index 9835e5b2a..185ef54f2 100644 --- a/examples/Fade.js +++ b/examples/Fade.js @@ -14,7 +14,6 @@ function Fade() { }; return (
-

Fade

diff --git a/examples/FocusOnSelect.js b/examples/FocusOnSelect.js index b9a3cd506..da8236c16 100644 --- a/examples/FocusOnSelect.js +++ b/examples/FocusOnSelect.js @@ -11,7 +11,6 @@ function FocusOnSelect() { }; return (
-

FocusOnSelect

Click on any slide to select and make it current slide
diff --git a/examples/LazyLoad.js b/examples/LazyLoad.js index a2f0e3f84..51dde030d 100644 --- a/examples/LazyLoad.js +++ b/examples/LazyLoad.js @@ -14,7 +14,6 @@ function LazyLoad() { }; return (
-

Lazy Load

diff --git a/examples/MultipleItems.js b/examples/MultipleItems.js index 2a88a6991..f68457ca5 100644 --- a/examples/MultipleItems.js +++ b/examples/MultipleItems.js @@ -11,7 +11,6 @@ function MultipleItems() { }; return (
-

Multiple items

1

diff --git a/examples/MultipleRows.js b/examples/MultipleRows.js index 4145db102..c61561136 100644 --- a/examples/MultipleRows.js +++ b/examples/MultipleRows.js @@ -14,7 +14,6 @@ function MultipleRows() { }; return (
-

Multiple Rows

1

diff --git a/examples/PauseOnHover.js b/examples/PauseOnHover.js index cc633d6ce..b95e848a8 100644 --- a/examples/PauseOnHover.js +++ b/examples/PauseOnHover.js @@ -13,7 +13,6 @@ function PauseOnHover() { }; return (
-

Pause On Hover

1

diff --git a/examples/PreviousNextMethods.js b/examples/PreviousNextMethods.js index 263749cdd..661135602 100644 --- a/examples/PreviousNextMethods.js +++ b/examples/PreviousNextMethods.js @@ -1,7 +1,7 @@ import React, { useRef } from "react"; import Slider from "react-slick"; -function PreviousNextMethods(props) { +function PreviousNextMethods() { let sliderRef = useRef(null); const next = () => { sliderRef.slickNext(); @@ -14,12 +14,10 @@ function PreviousNextMethods(props) { infinite: true, speed: 500, slidesToShow: 1, - slidesToScroll: 1, - ...props + slidesToScroll: 1 }; return (
-

Previous and Next methods

{ sliderRef = slider; diff --git a/examples/Responsive.js b/examples/Responsive.js index 0f06a9d22..7ace6acee 100644 --- a/examples/Responsive.js +++ b/examples/Responsive.js @@ -38,7 +38,6 @@ function Responsive() { }; return (
-

Responsive

1

diff --git a/examples/SimpleSlider.js b/examples/SimpleSlider.js index 9b982d42b..80c20e8bc 100644 --- a/examples/SimpleSlider.js +++ b/examples/SimpleSlider.js @@ -1,18 +1,16 @@ import React from "react"; import Slider from "react-slick"; -function SimpleSlider(props) { +function SimpleSlider() { const settings = { dots: true, infinite: true, speed: 500, slidesToShow: 1, - slidesToScroll: 1, - ...props + slidesToScroll: 1 }; return (
-

Single Item

1

diff --git a/examples/SlickGoTo.js b/examples/SlickGoTo.js index 73944963f..8d01ac86b 100644 --- a/examples/SlickGoTo.js +++ b/examples/SlickGoTo.js @@ -2,7 +2,7 @@ import React, { useState, useRef } from "react"; import Slider from "react-slick"; import { baseUrl } from "./config"; -function SlickGoTo(props) { +function SlickGoTo() { const [slideIndex, setSlideIndex] = useState(0); const [updateCount, setUpdateCount] = useState(0); let sliderRef = useRef(null); @@ -13,12 +13,10 @@ function SlickGoTo(props) { slidesToShow: 1, slidesToScroll: 1, afterChange: () => setUpdateCount(updateCount + 1), - beforeChange: (current, next) => setSlideIndex(next), - ...props + beforeChange: (current, next) => setSlideIndex(next) }; return (
-

Slick Go To

Total updates: {updateCount}

sliderRef.slickGoTo(e.target.value)} diff --git a/examples/SwipeToSlide.js b/examples/SwipeToSlide.js index 345ee926e..61ab07b90 100644 --- a/examples/SwipeToSlide.js +++ b/examples/SwipeToSlide.js @@ -16,7 +16,6 @@ function SwipeToSlide() { }; return (
-

Swipe To Slide

1

diff --git a/examples/UnevenSetsFinite.js b/examples/UnevenSetsFinite.js index 9a59abc20..ad43d2e92 100644 --- a/examples/UnevenSetsFinite.js +++ b/examples/UnevenSetsFinite.js @@ -11,7 +11,6 @@ function UnevenSetsFinite() { }; return (
-

Uneven sets (finite)

1

diff --git a/examples/UnevenSetsInfinite.js b/examples/UnevenSetsInfinite.js index ae48ec86c..91cb5a295 100644 --- a/examples/UnevenSetsInfinite.js +++ b/examples/UnevenSetsInfinite.js @@ -11,7 +11,6 @@ function UnevenSetsInfinite() { }; return (
-

Uneven sets (infinite)

1

diff --git a/examples/VariableWidth.js b/examples/VariableWidth.js index 81a040a1c..b15728ff0 100644 --- a/examples/VariableWidth.js +++ b/examples/VariableWidth.js @@ -13,7 +13,6 @@ function VariableWidth() { }; return (
-

Variable width

100

diff --git a/examples/VerticalMode.js b/examples/VerticalMode.js index 82d756c84..894f53b73 100644 --- a/examples/VerticalMode.js +++ b/examples/VerticalMode.js @@ -18,7 +18,6 @@ function VerticalMode() { }; return (
-

Vertical Mode

1

diff --git a/examples/VerticalSwipeToSlide.js b/examples/VerticalSwipeToSlide.js index 96c21efeb..9f7977307 100644 --- a/examples/VerticalSwipeToSlide.js +++ b/examples/VerticalSwipeToSlide.js @@ -19,7 +19,6 @@ function VerticalSwipeToSlide() { }; return (
-

Vertical Mode with Swipe To Slide

1

diff --git a/docs/config.js b/examples/config.js similarity index 100% rename from docs/config.js rename to examples/config.js From e06967c8b11851a4970915c64df6f78964ed94ab Mon Sep 17 00:00:00 2001 From: akiran Date: Mon, 5 Feb 2024 20:13:19 +0530 Subject: [PATCH 48/58] Added slider-container class to examples --- examples/AdaptiveHeight.js | 2 +- examples/AppendDots.js | 2 +- examples/AsNavFor.js | 2 +- examples/AutoPlay.js | 2 +- examples/AutoPlayMethods.js | 2 +- examples/CenterMode.js | 2 +- examples/CustomArrows.js | 2 +- examples/CustomPaging.js | 2 +- examples/CustomSlides.js | 4 ++-- examples/DynamicSlides.js | 2 +- examples/Fade.js | 2 +- examples/FocusOnSelect.js | 2 +- examples/LazyLoad.js | 2 +- examples/MultipleItems.js | 2 +- examples/MultipleRows.js | 2 +- examples/PauseOnHover.js | 2 +- examples/PreviousNextMethods.js | 2 +- examples/Resizable.js | 2 +- examples/Responsive.js | 2 +- examples/Rtl.js | 2 +- examples/SimpleSlider.js | 2 +- examples/SlickGoTo.js | 2 +- examples/SlideChangeHooks.js | 2 +- examples/SwipeToSlide.js | 2 +- examples/UnevenSetsFinite.js | 2 +- examples/UnevenSetsInfinite.js | 2 +- examples/VariableWidth.js | 2 +- examples/VerticalMode.js | 2 +- examples/VerticalSwipeToSlide.js | 2 +- examples/config.js | 10 ++++++---- 30 files changed, 36 insertions(+), 34 deletions(-) diff --git a/examples/AdaptiveHeight.js b/examples/AdaptiveHeight.js index e0e920aab..665c6c12c 100644 --- a/examples/AdaptiveHeight.js +++ b/examples/AdaptiveHeight.js @@ -12,7 +12,7 @@ function AdaptiveHeight() { }; return ( -
+

1

diff --git a/examples/AppendDots.js b/examples/AppendDots.js index 192f9613d..91f285b52 100644 --- a/examples/AppendDots.js +++ b/examples/AppendDots.js @@ -32,7 +32,7 @@ function AppendDots() { ) }; return ( -
+

1

diff --git a/examples/AsNavFor.js b/examples/AsNavFor.js index 0676e39d5..18cf09847 100644 --- a/examples/AsNavFor.js +++ b/examples/AsNavFor.js @@ -12,7 +12,7 @@ function AsNavFor() { setNav2(sliderRef2); }, []); return ( -
+

Slider Syncing (AsNavFor)

First Slider

(sliderRef1 = slider)}> diff --git a/examples/AutoPlay.js b/examples/AutoPlay.js index b2f1601f7..32520d0cc 100644 --- a/examples/AutoPlay.js +++ b/examples/AutoPlay.js @@ -13,7 +13,7 @@ function AutoPlay() { cssEase: "linear" }; return ( -
+

1

diff --git a/examples/AutoPlayMethods.js b/examples/AutoPlayMethods.js index ddfd9d08f..573c8d5a9 100644 --- a/examples/AutoPlayMethods.js +++ b/examples/AutoPlayMethods.js @@ -19,7 +19,7 @@ function AutoPlayMethods() { autoplaySpeed: 2000 }; return ( -
+

Auto Play {"&"} Pause with buttons

(sliderRef = slider)} {...settings}>
diff --git a/examples/CenterMode.js b/examples/CenterMode.js index 5ec5e5aee..291abafc9 100644 --- a/examples/CenterMode.js +++ b/examples/CenterMode.js @@ -11,7 +11,7 @@ function CenterMode() { speed: 500 }; return ( -
+

1

diff --git a/examples/CustomArrows.js b/examples/CustomArrows.js index 343b8f2db..d32dfec60 100644 --- a/examples/CustomArrows.js +++ b/examples/CustomArrows.js @@ -33,7 +33,7 @@ function CustomArrows() { prevArrow: }; return ( -
+

1

diff --git a/examples/CustomPaging.js b/examples/CustomPaging.js index 038428fe6..01a5d2b4a 100644 --- a/examples/CustomPaging.js +++ b/examples/CustomPaging.js @@ -19,7 +19,7 @@ function CustomPaging() { slidesToScroll: 1 }; return ( -
+
diff --git a/examples/CustomSlides.js b/examples/CustomSlides.js index ada9f1048..01d67c883 100644 --- a/examples/CustomSlides.js +++ b/examples/CustomSlides.js @@ -19,7 +19,7 @@ function CustomSlides() { slidesToScroll: 1 }; return ( -
+
@@ -32,4 +32,4 @@ function CustomSlides() { ); } -export default SimpleSlider; +export default CustomSlides; diff --git a/examples/DynamicSlides.js b/examples/DynamicSlides.js index 40520e384..bc5fcd67f 100644 --- a/examples/DynamicSlides.js +++ b/examples/DynamicSlides.js @@ -16,7 +16,7 @@ function DynamicSlides() { slidesToScroll: 3 }; return ( -
+
diff --git a/examples/Fade.js b/examples/Fade.js index 185ef54f2..a932c0766 100644 --- a/examples/Fade.js +++ b/examples/Fade.js @@ -13,7 +13,7 @@ function Fade() { waitForAnimate: false }; return ( -
+
diff --git a/examples/FocusOnSelect.js b/examples/FocusOnSelect.js index da8236c16..d75964608 100644 --- a/examples/FocusOnSelect.js +++ b/examples/FocusOnSelect.js @@ -10,7 +10,7 @@ function FocusOnSelect() { speed: 500 }; return ( -
+
Click on any slide to select and make it current slide
diff --git a/examples/LazyLoad.js b/examples/LazyLoad.js index 51dde030d..19c62ce9b 100644 --- a/examples/LazyLoad.js +++ b/examples/LazyLoad.js @@ -13,7 +13,7 @@ function LazyLoad() { initialSlide: 2 }; return ( -
+
diff --git a/examples/MultipleItems.js b/examples/MultipleItems.js index f68457ca5..138c48b3f 100644 --- a/examples/MultipleItems.js +++ b/examples/MultipleItems.js @@ -10,7 +10,7 @@ function MultipleItems() { slidesToScroll: 3 }; return ( -
+

1

diff --git a/examples/MultipleRows.js b/examples/MultipleRows.js index c61561136..833ccd5e7 100644 --- a/examples/MultipleRows.js +++ b/examples/MultipleRows.js @@ -13,7 +13,7 @@ function MultipleRows() { slidesPerRow: 2 }; return ( -
+

1

diff --git a/examples/PauseOnHover.js b/examples/PauseOnHover.js index b95e848a8..11ca6d656 100644 --- a/examples/PauseOnHover.js +++ b/examples/PauseOnHover.js @@ -12,7 +12,7 @@ function PauseOnHover() { pauseOnHover: true }; return ( -
+

1

diff --git a/examples/PreviousNextMethods.js b/examples/PreviousNextMethods.js index 661135602..e0ab6093f 100644 --- a/examples/PreviousNextMethods.js +++ b/examples/PreviousNextMethods.js @@ -17,7 +17,7 @@ function PreviousNextMethods() { slidesToScroll: 1 }; return ( -
+
{ sliderRef = slider; diff --git a/examples/Resizable.js b/examples/Resizable.js index 1c3553912..24029b21d 100644 --- a/examples/Resizable.js +++ b/examples/Resizable.js @@ -13,7 +13,7 @@ function Resizable() { slidesToScroll: 1 }; return ( -
+

Resizable Collapsible