Skip to content

Commit

Permalink
Increase test coverage (#451)
Browse files Browse the repository at this point in the history
* Migrate to jest and increase test coverage

* Remove not used methods from Carousel

* Generate lcov report

* Add coverage badge

* Fix CI config

* Update yarn.lock

* Update test/unit/carousel.test.js

Co-Authored-By: piotr-s-brainhub <piotr.sroczkowski@brainhub.pl>

* toEqual(true) -> toBeTruthy();

* Update test/unit/carousel.test.js

Co-Authored-By: piotr-s-brainhub <piotr.sroczkowski@brainhub.pl>

* Update test/unit/carousel.test.js

Co-Authored-By: piotr-s-brainhub <piotr.sroczkowski@brainhub.pl>

* Update test/unit/carousel.test.js

Co-Authored-By: piotr-s-brainhub <piotr.sroczkowski@brainhub.pl>

* Update test/unit/carousel.test.js

Co-Authored-By: piotr-s-brainhub <piotr.sroczkowski@brainhub.pl>

* Update test/unit/carousel.test.js

Co-Authored-By: piotr-s-brainhub <piotr.sroczkowski@brainhub.pl>

* Update test/unit/carousel.test.js

Co-Authored-By: piotr-s-brainhub <piotr.sroczkowski@brainhub.pl>

* Update test/unit/carousel.test.js

Co-Authored-By: piotr-s-brainhub <piotr.sroczkowski@brainhub.pl>

* Update test/unit/carousel.test.js

Co-Authored-By: piotr-s-brainhub <piotr.sroczkowski@brainhub.pl>

* Update test/unit/carousel.test.js

Co-Authored-By: piotr-s-brainhub <piotr.sroczkowski@brainhub.pl>

* Update test/unit/carousel.test.js

Co-Authored-By: piotr-s-brainhub <piotr.sroczkowski@brainhub.pl>

* Update test/unit/carousel.test.js

Co-Authored-By: piotr-s-brainhub <piotr.sroczkowski@brainhub.pl>

* Update test/unit/carousel.test.js

Co-Authored-By: piotr-s-brainhub <piotr.sroczkowski@brainhub.pl>

* Update test/unit/carousel.test.js

Co-Authored-By: piotr-s-brainhub <piotr.sroczkowski@brainhub.pl>

* Update test/unit/carousel.test.js

Co-Authored-By: piotr-s-brainhub <piotr.sroczkowski@brainhub.pl>

* Update test/unit/carousel.test.js

Co-Authored-By: piotr-s-brainhub <piotr.sroczkowski@brainhub.pl>

* Update test/unit/carousel.test.js

Co-Authored-By: piotr-s-brainhub <piotr.sroczkowski@brainhub.pl>

* Update test/unit/carousel.test.js

Co-Authored-By: piotr-s-brainhub <piotr.sroczkowski@brainhub.pl>

* Update test/unit/carousel.test.js

Co-authored-by: piotr-s-brainhub <piotr.sroczkowski@brainhub.pl>

* Update test/unit/carousel.test.js

Co-authored-by: piotr-s-brainhub <piotr.sroczkowski@brainhub.pl>

* Update test/unit/carousel.test.js

Co-authored-by: piotr-s-brainhub <piotr.sroczkowski@brainhub.pl>

* Update test/unit/carousel.test.js

Co-authored-by: piotr-s-brainhub <piotr.sroczkowski@brainhub.pl>

Co-authored-by: piotr-s-brainhub <piotr.sroczkowski@brainhub.pl>
  • Loading branch information
RobertHebel and piotr-s-brainhub authored Apr 30, 2020
1 parent 5a4a2dd commit df5c6e3
Show file tree
Hide file tree
Showing 11 changed files with 1,521 additions and 541 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- checkout
- run: yarn install --non-interactive
- run: yarn lint
- run: yarn test:unit:coverage:ci
- run: yarn test:unit:coverage
- run:
name: Generate coveralls config
command: "echo repo_token: $COVERALLS_REPO_TOKEN > ./.coveralls.yml"
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com)
[![Renovate enabled](https://img.shields.io/badge/renovate-enabled-brightgreen.svg)](https://renovatebot.com/)

[![Coveralls github](https://img.shields.io/coveralls/github/brainhubeu/react-carousel.svg)](https://coveralls.io/github/brainhubeu/react-carousel?branch=master)
[![Downloads](https://img.shields.io/npm/dm/@brainhubeu/react-carousel?color=blue)](https://www.npmjs.com/package/@brainhubeu/react-carousel)
[![Activity](https://img.shields.io/github/commit-activity/m/brainhubeu/react-carousel.svg)](https://github.com/brainhubeu/react-carousel/commits/master)
[![Minified](https://img.shields.io/bundlephobia/min/@brainhubeu/react-carousel?label=minified)](https://www.npmjs.com/package/@brainhubeu/react-carousel)
Expand Down
13 changes: 13 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
testEnvironment: 'node',
testMatch: ['<rootDir>/test/unit/**.test.js'],
moduleNameMapper: { '\\.(css|scss)$': '<rootDir>/test/unit/__mocks__/styleMock.js' },
setupFilesAfterEnv: [
'<rootDir>/jest.setup.js',
],
coverageReporters: [
'text',
['lcov', {
projectRoot: './',
}]],
};
4 changes: 4 additions & 0 deletions jest.setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { configure } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';

configure({ adapter: new Adapter() });
9 changes: 3 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
"build": "node tools/build.js",
"cypress:open": "cypress open",
"cypress:run": "cypress run",
"test:unit": "mocha tools/testSetup.js \"./test/unit/*.js\" --exit",
"test:unit": "jest",
"test:e2e": "start-server-and-test start-test-app http://localhost:8000 cypress:run",
"test-dockerized:e2e": "docker-compose -f ./docker-compose.e2e.yml up --build --exit-code-from e2e-test",
"test:unit:coverage": "nyc --reporter=text-summary yarn test:unit",
"test:unit:coverage:ci": "nyc --reporter=lcov --reporter=text-summary yarn test:unit",
"test:unit:coverage": "yarn jest --coverage",
"start-test-app": "yarn --cwd docs-www develop",
"precommit": "npm run lint"
},
Expand Down Expand Up @@ -59,9 +58,9 @@
"html-webpack-plugin": "^4.2.0",
"husky": "^4.2.5",
"isparta": "^4.1.1",
"jest": "^25.4.0",
"jsdom": "^16.2.2",
"lodash": "^4.17.15",
"mocha": "^7.1.1",
"node-sass": "^4.13.1",
"nyc": "^15.0.1",
"postcss-loader": "^3.0.0",
Expand All @@ -71,8 +70,6 @@
"react-test-renderer": "^16.13.1",
"rimraf": "3.0.2",
"sass-loader": "^8.0.2",
"sinon": "^9.0.2",
"sinon-chai": "^3.5.0",
"start-server-and-test": "^1.11.0",
"style-loader": "^1.1.4",
"uglifyjs-webpack-plugin": "^2.2.0",
Expand Down
30 changes: 0 additions & 30 deletions src/components/Carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -232,19 +232,6 @@ class Carousel extends Component {
? this.getCurrentSlideIndex() + this.getClonesLeft() * this.getChildren().length
: this.getCurrentSlideIndex();

/* infinite calculations */
getSlidesBounds = (customValue = null) => {
const value = isNil(customValue) ? this.getCurrentValue() : customValue;
const length = this.getChildren().length;
const times = ((value + 1) / length);
const ceil = Math.ceil(times);

return {
low: (ceil - 1) * length,
high: ceil * length - 1,
};
};

getTargetMod = (customValue = null) => {
const value = isNil(customValue) ? this.getCurrentValue() : customValue;
const length = this.getChildren().length;
Expand Down Expand Up @@ -330,23 +317,6 @@ class Carousel extends Component {
}));
};

/**
* Function handling touch move if drag has started. Sets dragOffset in the state.
* @param {event} e event
*/
onTouchMove = e => {
if (Math.abs(this.state.dragOffset) > this.props.minDraggableOffset) {
e.preventDefault();
e.stopPropagation();
}
const { changedTouches } = e;
if (this.state.dragStart !== null) {
this.setState(previousState => ({
dragOffset: this.getProp('rtl') ? previousState.dragStart - changedTouches[0].pageX : changedTouches[0].pageX - previousState.dragStart,
}));
}
};

/**
* Function handling end of touch or mouse drag. If drag was long it changes current slide to the nearest one,
* if drag was short (or it was just a click) it changes slide to the clicked (or touched) one.
Expand Down
8 changes: 0 additions & 8 deletions test/.eslintrc

This file was deleted.

1 change: 1 addition & 0 deletions test/unit/__mocks__/styleMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = {};
Loading

0 comments on commit df5c6e3

Please sign in to comment.