Skip to content
This repository was archived by the owner on Feb 20, 2018. It is now read-only.

Commit bff4d9f

Browse files
committed
Update test
1 parent 84d26ce commit bff4d9f

File tree

7 files changed

+154
-148
lines changed

7 files changed

+154
-148
lines changed

.travis.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
language: node_js
22

33
node_js:
4-
- '4.2.2'
4+
- '7'
5+
6+
addons:
7+
apt:
8+
packages:
9+
- xvfb
10+
11+
before_install:
12+
- export DISPLAY=':99.0'
13+
- Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
514

615
install:
716
- npm i
817

918
script:
10-
- 'npm test'
19+
- 'npm test'

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Animation menu component for React.
44

55
[![Build Status](https://img.shields.io/travis/bokuweb/react-motion-menu.svg?style=flat-square)](https://travis-ci.org/bokuweb/react-motion-menu)
66
[![Version](https://img.shields.io/npm/v/react-motion-menu.svg?style=flat-square)](https://www.npmjs.com/package/react-motion-menu)
7-
[![License](http://img.shields.io/npm/l/object.assign.svg?style=flast-square)](https://github.com/bokuweb/react-motion-menu#license)
7+
[![License](http://img.shields.io/npm/l/object.assign.svg?style=flat-square)](https://github.com/bokuweb/react-motion-menu#license)
88

99
## Demo
1010

karma.conf.js

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
1-
// Karma configuration
2-
// Generated on Fri Sep 25 2015 15:55:15 GMT+0900 (東京 (標準時))
3-
4-
module.exports = function(config) {
1+
module.exports = (config) => {
52
config.set({
63

7-
// base path that will be used to resolve all patterns (eg. files, exclude)
84
basePath: '',
95

10-
// frameworks to use
11-
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
126
frameworks: ['mocha', 'browserify'],
137

14-
// list of files / patterns to load in the browser
158
files: [
16-
'./node_modules/babel-polyfill/dist/polyfill.js',
17-
'test/*.js'
9+
'test/**/*.js',
1810
],
1911

2012
// list of files to exclude
@@ -26,14 +18,22 @@ module.exports = function(config) {
2618
extensions: ['.js'],
2719
transform: [
2820
require('babelify').configure({
29-
plugins: ['babel-plugin-espower']
30-
})
31-
]
21+
plugins: ['babel-plugin-espower'],
22+
}),
23+
],
24+
configure: (bundle) => {
25+
bundle.on('prebundle', () => {
26+
bundle.external('react/addons');
27+
bundle.external('react/lib/ReactContext');
28+
bundle.external('react/lib/ExecutionEnvironment');
29+
});
30+
},
3231
},
32+
3333
// preprocess matching files before serving them to the browser
3434
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
3535
preprocessors: {
36-
'test/*.js': ['browserify']
36+
'test/**/*.js': ['browserify'],
3737
},
3838

3939

@@ -50,9 +50,7 @@ module.exports = function(config) {
5050
// enable / disable colors in the output (reporters and logs)
5151
colors: true,
5252

53-
5453
// level of logging
55-
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
5654
logLevel: config.LOG_INFO,
5755

5856

@@ -62,11 +60,15 @@ module.exports = function(config) {
6260

6361
// start these browsers
6462
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
65-
browsers: ['PhantomJS'],
63+
browsers: ['Nightmare'],
6664

65+
nightmareOptions: {
66+
width: '800px',
67+
height: '600px',
68+
},
6769

6870
// Continuous Integration mode
6971
// if true, Karma captures browsers, runs the tests and exits
70-
singleRun: true
71-
})
72-
}
72+
singleRun: true,
73+
});
74+
};

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"build:example": "browserify --extension=js -o docs/dist/bundle.js docs/src/index.js",
99
"lint": "eslint ./src",
1010
"styleguide": "styleguidist build",
11-
"test": "karma start"
11+
"test:watch": "karma start --auto-watch --no-single-run",
12+
"test": "npm run lint && karma start"
1213
},
1314
"repository": {
1415
"type": "git",
@@ -41,13 +42,12 @@
4142
"babel-preset-stage-2": "^6.18.0",
4243
"babelify": "7.3.0",
4344
"browserify": "^13.3.0",
45+
"enzyme": "^2.7.0",
4446
"eslint": "^3.13.0",
4547
"eslint-config-airbnb": "^13.0.0",
4648
"eslint-plugin-import": "^2.1.0",
4749
"eslint-plugin-jsx-a11y": "^2.2.3",
4850
"eslint-plugin-react": "^6.6.0",
49-
"expect": "^1.20.2",
50-
"expect-jsx": "^3.0.0",
5151
"flow-bin": "^0.37.4",
5252
"karma": "^1.3.0",
5353
"karma-browserify": "5.1.0",

test/test-button.js

Lines changed: 26 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,37 @@
11
import React from 'react';
2-
import ReactDOM from 'react-dom';
3-
import { Motion } from 'react-motion';
4-
import TestUtils, {createRenderer} from 'react-addons-test-utils';
5-
import Button from '../src/button';
6-
import expect from 'expect';
7-
import expectJSX from 'expect-jsx';
82
import assert from 'power-assert';
9-
10-
expect.extend(expectJSX);
3+
import { spy } from 'sinon';
4+
import { mount, shallow } from 'enzyme';
5+
import MenuButton from '../src/button';
116

127
describe('Button Component test', () => {
138

14-
it ('Should call onclick callback, when button clicked', (done) => {
15-
const onClick = () => {
16-
assert.ok(true);
17-
done();
18-
}
19-
const button = TestUtils.renderIntoDocument(<Button onClick={onClick} />);
20-
const div = TestUtils.scryRenderedDOMComponentsWithTag(button, 'div');
21-
TestUtils.Simulate.click(ReactDOM.findDOMNode(div[0]));
22-
});
23-
24-
it ('Should style set to button component', (done) => {
25-
const button = TestUtils.renderIntoDocument(<Button width={80} height={120} customStyle={{color: "red"}} />);
26-
const div = TestUtils.scryRenderedDOMComponentsWithTag(button, 'div');
27-
assert.equal(div[0].style.color, 'red');
28-
assert.equal(div[0].style.position, 'absolute');
29-
assert.equal(div[0].style.width, '80px');
30-
assert.equal(div[0].style.height, '120px');
31-
done();
32-
});
33-
34-
it ('Should text set to button component', (done) => {
35-
const button = TestUtils.renderIntoDocument(<Button>dummy</Button>);
36-
const div = TestUtils.scryRenderedDOMComponentsWithTag(button, 'div');
37-
assert.equal(div[0].textContent, 'dummy');
38-
done();
9+
it('should mount button component without error', () => {
10+
mount(
11+
<MenuButton x={0} y={0} onClick={() => {}}>
12+
<div>sample</div>
13+
</MenuButton>,
14+
);
3915
});
4016

41-
it ('Should x, y position set to button component', (done) => {
42-
const button = TestUtils.renderIntoDocument(<Button x={80} y={120} />);
43-
const div = TestUtils.scryRenderedDOMComponentsWithTag(button, 'div');
44-
assert.equal(div[0].style.WebkitTransform, 'translate3d(80px, 120px, 0px) scaleX(1) scaleY(1)');
45-
done();
17+
it('should x, y position set to button component', () => {
18+
const button = mount(
19+
<MenuButton x={10} y={20} onClick={() => {}}>
20+
<div>sample</div>
21+
</MenuButton>,
22+
);
23+
assert.equal(button.getDOMNode().style.transform, 'translate3d(10px, 20px, 0px) scaleX(1) scaleY(1)');
24+
assert.equal(button.getDOMNode().style.position, 'absolute');
4625
});
4726

48-
afterEach(done => {
49-
ReactDOM.unmountComponentAtNode(document.body);
50-
document.body.innerHTML = "";
51-
setTimeout(done);
27+
it('should call onClick when button clicked', () => {
28+
const onClick = spy();
29+
const button = mount(
30+
<MenuButton x={10} y={20} onClick={onClick}>
31+
<div>sample</div>
32+
</MenuButton>,
33+
);
34+
button.simulate('click');
35+
assert.equal(onClick.callCount, 1);
5236
});
5337
});

test/test-item.js

Lines changed: 43 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,99 +1,62 @@
11
import React from 'react';
2-
import ReactDOM from 'react-dom';
3-
import {Motion} from 'react-motion';
4-
import TestUtils, {createRenderer} from 'react-addons-test-utils';
5-
import Item from '../src/item';
6-
import expect from 'expect';
7-
import expectJSX from 'expect-jsx';
82
import assert from 'power-assert';
3+
import { spy } from 'sinon';
4+
import { mount, shallow } from 'enzyme';
5+
import MenuItem from '../src/item';
96

10-
expect.extend(expectJSX);
7+
describe('Item Component test', function () {
118

12-
describe('Item Component test', () => {
13-
let renderer = createRenderer();
14-
console.log(renderer);
15-
it ('Should Item rendered Motion component with initial state value', (done) => {
9+
this.timeout(10000);
1610

17-
renderer.render(<Item direction='vertical' x={100} y={100} />)
18-
const actualElement = renderer.getRenderOutput();
19-
let expectedElement = (
20-
<Motion style={{scaleX: {config: [1500, 100], val: 0}, scaleY: {config: [1500, 100], val: 0}, x: 100, y: {config: [1500, 50], val: 100}}} />
11+
it('should mount item component without error', () => {
12+
mount(
13+
<MenuItem x={0} y={0} name="sample">
14+
<div>sample</div>
15+
</MenuItem>,
2116
);
22-
expect(actualElement).toEqualJSX(expectedElement);
23-
done();
2417
});
2518

26-
it ('Should Item rendered Motion component with expected value, when set vertical and call start()', (done) => {
27-
renderer.render(<Item direction='vertical' x={100} y={200} distance={50} />);
28-
renderer._instance._instance.start()
29-
setTimeout(() => {
30-
const actualElement = renderer.getRenderOutput();
31-
let expectedElement = (
32-
<Motion style={{scaleX: {config: [1500, 150], val: 0.7}, scaleY: {config: [1500, 150], val: 1.6}, x: 100, y: {config: [1500, 100], val: 250}}} />
33-
);
34-
expect(actualElement).toEqualJSX(expectedElement);
35-
}, 60);
19+
it('should call onOpenAnimationEnd callback, when opend', (done) => {
20+
const onOpenAnimationEnd = spy();
21+
const wrapper = shallow(
22+
<MenuItem x={0} y={0} name="sample" onOpenAnimationEnd={onOpenAnimationEnd}>
23+
<div>sample</div>
24+
</MenuItem>,
25+
);
26+
wrapper.instance().start();
3627
setTimeout(() => {
37-
const actualElement = renderer.getRenderOutput();
38-
let expectedElement = (
39-
<Motion style={{scaleX: {config: [1500, 18], val: 1}, scaleY: {config: [1500, 18], val: 1}, x: 100, y: {config: [1500, 100], val: 250}}} />
40-
);
41-
expect(actualElement).toEqualJSX(expectedElement);
28+
assert.equal(onOpenAnimationEnd.callCount, 1);
29+
assert.equal(onOpenAnimationEnd.getCall(0).args[0], 'sample');
4230
done();
43-
}, 100);
31+
}, 200);
4432
});
4533

46-
it ('Should Item rendered Motion component with expected value, when set vertical and call start()', (done) => {
47-
renderer.render(<Item direction='horizontal' x={100} y={200} distance={50} />);
48-
renderer._instance._instance.start()
49-
setTimeout(() => {
50-
const actualElement = renderer.getRenderOutput();
51-
let expectedElement = (
52-
<Motion style={{scaleX: {config: [1500, 150], val: 1.6}, scaleY: {config: [1500, 150], val: 0.7}, y: 200, x: {config: [1500, 100], val: 150}}} />
53-
);
54-
expect(actualElement).toEqualJSX(expectedElement);
55-
}, 60);
34+
it('should call onOpenAnimationEnd callback, when opend', (done) => {
35+
const wrapper = mount(
36+
<MenuItem x={10} y={20} name="sample">
37+
<div>sample</div>
38+
</MenuItem>,
39+
);
40+
wrapper.instance().start();
5641
setTimeout(() => {
57-
const actualElement = renderer.getRenderOutput();
58-
let expectedElement = (
59-
<Motion style={{scaleX: {config: [1500, 18], val: 1}, scaleY: {config: [1500, 18], val: 1}, y: 200, x: {config: [1500, 100], val: 150}}} />
60-
);
61-
expect(actualElement).toEqualJSX(expectedElement);
62-
done();
63-
}, 100);
64-
});
65-
66-
it ('Should call onOpenAnimationEnd callback, when call start()', (done) => {
67-
const onOpenAnimationEnd = () => {
68-
console.log('open animation end');
42+
assert.equal(wrapper.getDOMNode().style.transform, 'translate3d(10px, 20px, 0px) scaleX(1) scaleY(1)');
6943
done();
70-
}
71-
renderer.render(<Item direction='vertical' x={100} y={200} distance={50} onOpenAnimationEnd={onOpenAnimationEnd}/>);
72-
renderer._instance._instance.start();
44+
}, 3000);
7345
});
7446

75-
it ('Should call onCloseAnimationEnd callback, when call reverse()', (done) => {
76-
const onOpenAnimationEnd = () => {
77-
console.log('open animation end');
78-
renderer._instance._instance.reverse();
79-
};
80-
const onCloseAnimationEnd = () => {
81-
console.log('close animation end');
47+
it('should call onCloseAnimationEnd callback, when closed', (done) => {
48+
const onCloseAnimationEnd = spy();
49+
const wrapper = shallow(
50+
<MenuItem x={0} y={0} name="sample" onCloseAnimationEnd={onCloseAnimationEnd}>
51+
<div>sample</div>
52+
</MenuItem>,
53+
);
54+
wrapper.instance().start();
55+
wrapper.instance().reverse();
56+
setTimeout(() => {
57+
assert.equal(onCloseAnimationEnd.callCount, 1);
58+
assert.equal(onCloseAnimationEnd.getCall(0).args[0], 'sample');
8259
done();
83-
};
84-
renderer.render(<Item direction='vertical' x={100} y={200} distance={50}
85-
onOpenAnimationEnd={onOpenAnimationEnd}
86-
onCloseAnimationEnd={onCloseAnimationEnd} />);
87-
renderer._instance._instance.start();
88-
});
89-
90-
afterEach(done => {
91-
renderer = null;
92-
renderer = createRenderer();
93-
ReactDOM.unmountComponentAtNode(document.body);
94-
document.body.innerHTML = "";
95-
setTimeout(done);
60+
}, 200);
9661
});
9762
});
98-
99-

0 commit comments

Comments
 (0)