Skip to content

Commit

Permalink
try to add travis and coverals
Browse files Browse the repository at this point in the history
  • Loading branch information
asmyshlyaev177 committed Jul 23, 2018
1 parent 93c5ccc commit acb37b7
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .coveralls.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
service_name: travis-ci
repo_token: tMwxnbannXSXlH4pDZ0UuvqZL2Yg0D3Fm
9 changes: 9 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
sudo: false
language: node_js
node_js:
- "6"
cache:
directories:
- node_modules

script: echo "Running tests against $(node -v)..."
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

![example](/sample.gif)

[![Build Status](https://travis-ci.org/asmyshlyaev177/react-horizontal-scrolling-menu.svg?branch=master)](https://travis-ci.org/asmyshlyaev177/react-horizontal-scrolling-menu)
[![Coverage Status](https://coveralls.io/repos/github/asmyshlyaev177/react-horizontal-scrolling-menu/badge.svg?branch=master)](https://coveralls.io/github/asmyshlyaev177/react-horizontal-scrolling-menu?branch=master)

[Demo](https://asmyshlyaev177.github.io/react-horizontal-scrolling-menu)

This is horizontal scrolling menu component for React.
Expand Down
20 changes: 15 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
"scripts": {
"start": "webpack --env.development --mode development --watch",
"build": "webpack --env.production --mode production",
"test": "jest",
"test:watch": "jest --watch"
"test": "jest --coverage --runInBand --ci && cat coverage/lcov.info | coveralls",
"postbuild": "jest --coverage --cache=false --runInBand --ci --coverageReporters=text-lcov | coveralls",
"test:watch": "jest --watch --cache=false",
"coveralls": "jscoverage lib && YOURPACKAGE_COVERAGE=1 nodeunit --reporter=text-lcov"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -48,12 +50,15 @@
"babel-preset-react": "^6.24.1",
"babel-preset-stage-2": "^6.24.1",
"babel-preset-stage-3": "^6.24.1",
"coveralls": "^3.0.2",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"eslint": "^5.1.0",
"eslint-plugin-react": "^7.10.0",
"jest": "^23.4.0",
"jscoverage": "^0.6.0",
"jsdom": "^11.11.0",
"nodeunit": "^0.11.3",
"prop-types": "^15.6.2",
"react": "^16.4.1",
"react-dom": "^16.4.1",
Expand All @@ -68,11 +73,16 @@
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js",
"\\.(css|less)$": "<rootDir>/__mocks__/styleMock.js"
},
"collectCoverageFrom": [
"src/**.js"
],
"coveragePathIgnorePatterns": [
"/build",
"/node_modules/",
"/examples/",
"/build/",
"jest.js"
]
"jest.js",
"src/index.js"
],
"coverageDirectory": "coverage"
}
}
42 changes: 33 additions & 9 deletions src/scrollMenu.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable no-undef */
/* eslint-disable react/react-in-jsx-scope */
/* eslint-disable no-unused-vars */
import ScrollMenu, { Arrow, innerStyle, InnerWrapper } from './scrollMenu';

import ScrollMenu, { Arrow, innerStyle, InnerWrapper, defaultSetting } from './scrollMenu';

describe('test Arrow', () => {
const props = {
Expand Down Expand Up @@ -354,6 +355,16 @@ describe('functions', () => {
expect(wrapper.instance().getNextItemInd(false, [ ['item2', false], ['item4', false] ]))
.toEqual(4);
});

it('getNextItem fn', () => {
expect(wrapper.instance().getNextItem(items[0][0])).toEqual(items[1]);
expect(wrapper.instance().getNextItem(items[6][0])).toEqual(items[6]);
});
it('getPrevItem fn', () => {
expect(wrapper.instance().getPrevItem(items[1][0])).toEqual(items[0]);
expect(wrapper.instance().getPrevItem(items[3][0])).toEqual(items[2]);
expect(wrapper.instance().getPrevItem(items[0][0])).toEqual(items[0]);
});
});

describe('offsets', () => {
Expand Down Expand Up @@ -428,11 +439,11 @@ describe('functions', () => {
const wrapper = mount(<ScrollMenu {...props} />);
wrapper.setState(prop);

const checkScroll = (alignCenter = false, menuPos = 0) => {
const checkScroll = (alignCenter = false, menuPos = 0, empty = false) => {
wrapper.setState({ menuPos });
wrapper.setProps({ alignCenter });
const visibleItems = wrapper.instance().getVisibleItems({});
const offset = wrapper.instance().getScrollRightOffset(visibleItems, items);
const offset = wrapper.instance().getScrollRightOffset(empty ? [] : visibleItems, items);
return [offset, visibleItems.length];
};

Expand All @@ -452,6 +463,10 @@ describe('functions', () => {
expect(checkScroll(true, 100)).toEqual([80, 1]);
});

it('visibleItems empty use last item', () => {
expect(checkScroll(true, 100, true)).toEqual([130, 1]);
});

});

describe('getScrollLeftOffset fn', () => {
Expand Down Expand Up @@ -568,7 +583,6 @@ describe('functions', () => {
});

describe('dragging', () => {
const wrapper = mount(<ScrollMenu {...props} />);

it('don not drag if dragging disabled', () => {
const wrapper = mount(<ScrollMenu {...props} dragging={false} />);
Expand All @@ -578,6 +592,7 @@ describe('functions', () => {
});

it('handleDragStart', () => {
const wrapper = mount(<ScrollMenu {...props} />);
wrapper.setState({ dragging: false, xPoint: 100 });
wrapper.instance().handleDragStart();

Expand All @@ -587,6 +602,7 @@ describe('functions', () => {
});

it('handleDrag', () => {
const wrapper = mount(<ScrollMenu {...props} />);
const ev = pos => ({ clientX: pos });

wrapper.setState({
Expand All @@ -609,10 +625,15 @@ describe('functions', () => {
expect(checkDrag(-250, 0, 30)).toEqual([-250, 30]);
expect(checkDrag(-50, 30, 35)).toEqual([-45, 35]);
expect(checkDrag(-50, 35, 45)).toEqual([-40, 45]);

expect(checkDrag(50, 55, 5)).toEqual([defaultSetting.translate, 5]);
});

it('handleDragStop', () => {
const wrapper = mount(<ScrollMenu {...props} />);
const ev = point => ({ clientX: point });
const getPoint = jest.fn().mockReturnValue(0);
wrapper.instance().getPoint = getPoint;

wrapper.setState({ dragging: false });
expect(wrapper.instance().handleDragStop(ev)).toEqual(false);
Expand All @@ -628,24 +649,27 @@ describe('functions', () => {
alignCenter: false
});

const checkDrag = (translate, alignCenter, x) => {
const checkDrag = (translate, alignCenter, x, xPoint = 0) => {
wrapper.setState({ xPoint: xPoint });
wrapper.setState({ translate: translate, dragging: true });
wrapper.setProps({ alignCenter: alignCenter });
wrapper.instance().handleDragStop(ev(x));
const { translate: trans, xPoint, dragging } = wrapper.state();
const XPoint = wrapper.instance().getPoint(ev(x));
const { translate: trans, dragging } = wrapper.state();
expect(dragging).toEqual(false);
return [trans, xPoint];
return [trans, XPoint];
};

expect(checkDrag(100, true, 5)).toEqual([10, 0]);
expect(checkDrag(100, false, 5)).toEqual([0, 0]);
expect(checkDrag(-200, true, 5)).toEqual([-165, 0]);
expect(checkDrag(-200, false, 5)).toEqual([-150, 0]);
// TODO must be [-50, 5] WTF
expect(checkDrag(-50, false, 5)).toEqual([-50, 0]);

expect(checkDrag(-50, false, 5, null)).toEqual([-50, 0]);
});

it('get clientX or touch cordinates', () => {
const wrapper = mount(<ScrollMenu {...props} />);
const ev1 = { touches: [25] };
const ev2 = { clientX: 35 };
expect(wrapper.instance().getPoint(ev1)).toEqual(25);
Expand Down

0 comments on commit acb37b7

Please sign in to comment.