Skip to content

Commit

Permalink
upgrade react to 15.x
Browse files Browse the repository at this point in the history
  • Loading branch information
buzhou committed Oct 28, 2017
1 parent 509ca58 commit 459e663
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 66 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ spm_modules
.happypack
dist
build
coverage
package-lock.json
assets/**/*.css
15 changes: 12 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ language: node_js

sudo: false

addons:
apt:
packages:
- xvfb

notification:
email:
- wsj7552715@hotmail.com

node_js:
- 4.0.0
- 6.9.0

before_install:
- |
Expand All @@ -17,6 +22,11 @@ before_install:
exit
fi
phantomjs --version
install:
- export DISPLAY=':99.0'
- Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 &
- npm install


script:
- |
Expand All @@ -25,7 +35,6 @@ script:
else
npm run $TEST_TYPE
fi
env:
matrix:
- TEST_TYPE=test
Expand All @@ -34,4 +43,4 @@ env:

matrix:
allow_failures:
- env: "TEST_TYPE=saucelabs"
- env: "TEST_TYPE=saucelabs"
17 changes: 8 additions & 9 deletions demo/PopoverDemo.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const React = require('react');
const Popover = require('../src');

const test = () => {
alert('test');
alert('test'); // eslint-disable-line no-alert
};

const onOk = (cb) => {
Expand Down Expand Up @@ -41,7 +41,6 @@ class Demo extends React.Component {
visible,
});
}
console.log(visible);
}

render() {
Expand All @@ -54,19 +53,19 @@ class Demo extends React.Component {
return (
<div>
<h2>Demo 1. 悬浮弹出</h2>
<div style={{ marginLeft: 300, marginTop: 100 }}>
<div style={{ marginLeft: 60 }}>
<div style={{ marginLeft: '300px', marginTop: '100px' }}>
<div style={{ marginLeft: '60px' }}>
<Popover placement="topLeft" title={'上左'} overlay={overlay} onOk={test}>
<Button>上左</Button>
</Popover>
<Popover placement="top" title={'上边'} overlay={overlay}>
<Button>上边</Button>
<Button style="margin-left:10px;">上边</Button>
</Popover>
<Popover placement="topRight" title={'上右'} overlay={overlay}>
<Button>上右</Button>
<Button style="margin-left:10px;">上右</Button>
</Popover>
</div>
<div style={{ width: 60, float: 'left' }}>
<div style={{ width: '60px', float: 'left' }}>
<Popover placement="leftTop" title={'左上'} overlay={overlay}>
<Button>左上</Button>
</Popover>
Expand All @@ -77,7 +76,7 @@ class Demo extends React.Component {
<Button>左下</Button>
</Popover>
</div>
<div style={{ width: 60, marginLeft: 270 }}>
<div style={{ width: '60px', marginLeft: '270px' }}>
<Popover placement="rightTop" title={'右上'} overlay={overlay}>
<Button>右上</Button>
</Popover>
Expand All @@ -88,7 +87,7 @@ class Demo extends React.Component {
<Button>右下</Button>
</Popover>
</div>
<div style={{ marginLeft: 60, clear: 'both' }}>
<div style={{ marginLeft: '60px', clear: 'both' }}>
<Popover placement="bottomLeft" title={'下左'} overlay={overlay}>
<Button>下左</Button>
</Popover>
Expand Down
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<script src="./node_modules/es5-shim/es5-shim.min.js"></script>
<script src="./node_modules/es5-shim/es5-sham.min.js"></script>
<script src="./node_modules/react/dist/react-with-addons.js"></script>
<script src="http://g.alicdn.com/uxcore/uxcore-lib/react/0.14.0/react-dom.js"></script>
<script src="./node_modules/react-dom/dist/react-dom.js"></script>
<script src="./dist/demo.js"></script>
</body>
</html>
104 changes: 54 additions & 50 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,52 +1,56 @@
{
"name": "uxcore-popover",
"version": "0.5.2",
"description": "uxcore-popover component for uxcore.",
"repository": "https://github.com/uxcore/uxcore-popover.git",
"author": "eternalsky",
"main": "build/index.js",
"scripts": {
"start": "uxcore-tools run start",
"server": "uxcore-tools run server",
"lint": "uxcore-tools run lint",
"build": "uxcore-tools run build",
"test": "uxcore-tools run test",
"coverage": "uxcore-tools run coverage",
"pub": "uxcore-tools run pub",
"dep": "uxcore-tools run dep",
"tnpm-dep": "uxcore-tools run tnpm-dep",
"chrome": "uxcore-tools run chrome",
"browsers": "uxcore-tools run browsers",
"saucelabs": "uxcore-tools run saucelabs",
"update": "uxcore-tools run update"
},
"bugs": {
"url": "http://github.com/uxcore/uxcore-popover/issues"
},
"keywords": [
"react",
"react-component",
"uxcore-popover",
"Popover",
""
],
"devDependencies": {
"console-polyfill": "^0.2.2",
"es5-shim": "^4.5.8",
"expect.js": "~0.3.1",
"kuma-base": "1.x",
"react": "0.14.x",
"react-addons-test-utils": "0.14.x",
"react-dom": "0.14.x",
"uxcore-kuma": "2.x",
"uxcore-tools": "0.2.x"
},
"dependencies": {
"classnames": "^2.1.2",
"object-assign": "^4.0.0",
"rc-tooltip": "~3.3.0",
"uxcore-button": "~0.3.0"
},
"contributors": [],
"license": "MIT"
"name": "uxcore-popover",
"version": "0.5.3",
"description": "uxcore-popover component for uxcore.",
"repository": "https://github.com/uxcore/uxcore-popover.git",
"author": "eternalsky",
"main": "build/index.js",
"scripts": {
"start": "uxcore-tools run start",
"server": "uxcore-tools run server",
"lint": "uxcore-tools run lint",
"build": "uxcore-tools run build",
"test": "uxcore-tools run test",
"coverage": "uxcore-tools run coverage",
"pub": "uxcore-tools run pub",
"dep": "uxcore-tools run dep",
"tnpm-dep": "uxcore-tools run tnpm-dep",
"chrome": "uxcore-tools run chrome",
"browsers": "uxcore-tools run browsers",
"saucelabs": "uxcore-tools run saucelabs",
"update": "uxcore-tools run update",
"tnpm-update": "uxcore-tools run tnpm-update"
},
"bugs": {
"url": "http://github.com/uxcore/uxcore-popover/issues"
},
"keywords": [
"react",
"react-component",
"uxcore-popover",
"Popover",
""
],
"devDependencies": {
"console-polyfill": "^0.2.2",
"enzyme": "^3.0.0",
"enzyme-adapter-react-15": "^1.0.0",
"es5-shim": "^4.5.8",
"expect.js": "~0.3.1",
"kuma-base": "1.x",
"react": "15.x",
"react-dom": "15.x",
"react-test-renderer": "15.x",
"uxcore-kuma": "*",
"uxcore-tools": "0.2.x"
},
"dependencies": {
"classnames": "^2.1.2",
"object-assign": "^4.0.0",
"prop-types": "15.x",
"rc-tooltip": "~3.3.0",
"uxcore-button": "~0.3.0"
},
"contributors": [],
"license": "MIT"
}
4 changes: 3 additions & 1 deletion src/Popover.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ Popover.propTypes = {
prefixCls: React.PropTypes.string,
delay: React.PropTypes.number,
overlayClassName: React.PropTypes.string,
placement: React.PropTypes.oneOf(['top', 'bottom', 'left', 'right', 'topLeft', 'bottomLeft', 'leftTop', 'rightTop', 'topRight', 'bottomRight', 'leftBottom', 'rightBottom']),
placement: React.PropTypes.oneOf(['top', 'bottom', 'left', 'right',
'topLeft', 'bottomLeft', 'leftTop', 'rightTop', 'topRight', 'bottomRight',
'leftBottom', 'rightBottom']),
trigger: React.PropTypes.oneOf(['hover', 'click']),
onOk: React.PropTypes.func,
onCancel: React.PropTypes.func,
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
* All rights reserved.
*/

module.exports = require('./Popover');
module.exports = require('./Popover');
87 changes: 86 additions & 1 deletion tests/Popover.spec.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,94 @@
import expect from 'expect.js';
import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils, { Simulate } from 'react-addons-test-utils';
import TestUtils, { Simulate } from 'react-dom/test-utils';
import Popover from '../src';

describe('Popover', () => {

it('Could be rendered without overlay and with visiable true', function () {
const component = TestUtils.renderIntoDocument(
<Popover
placement="right"
title={'右边'}
prefixCls="unit-test"
showButton={true}
visible={true}
>
<span className="overlay-inner-text">右边</span>
</Popover>
);
expect(component.state.visible).equal(true);
});

it('Could be rendered with visiable false', function () {
let onCancleCalled = false;
let onVisibleChangeCalled = false;
let onOkCalled = false;
const props = {
placement: 'right',
title: '右边',
prefixCls: 'unit-test',
showButton: true,
visible: false,
onCancle: () => {onCancleCalled = true},
onVisibleChange: () => {onVisibleChangeCalled = true},
onOk: (cb) => {
cb();
onOkCalled = true;
}
};
const component = TestUtils.renderIntoDocument(
<Popover
{...props}
>
<span className="overlay-inner-text">右边</span>
</Popover>
);
expect(component.state.visible).equal(false);
component.setState({ ...component.state, visible: true }, () => {
expect(component.state.visible).equal(true);
component.handleOkClick();
component.handleCancelClick();
setTimeout(() => {
expect(onVisibleChangeCalled).equal(true);
expect(onCancleCalled).equal(true);
expect(onOkCalled).equal(true);
}, 200);
component.componentWillReceiveProps({...props, visible: true});
});
});

it('Could be rendered with overlay without visiable', function () {
let onCancleCalled = false;
let onVisibleChangeCalled = false;
let onOkCalled = false;
const overlay = (<div>
<div className="demoContent">
<span>目标删除后将不可恢复,如有子目标将会删除!</span>
</div>
</div>);
const component = TestUtils.renderIntoDocument(
<Popover placement="right" title={'右边'} overlay={overlay}
onCancle = {() => {onCancleCalled = true}}
onVisibleChange = {() => {onVisibleChangeCalled = true}}
onOk = {(cb) => {
cb();
onOkCalled = true;
}}>
<span>右边</span>
</Popover>
);
expect(component.state.visible).equal(false);
component.componentWillReceiveProps({visible: true});
component.handleOkClick();
component.handleCancelClick();
component.handleVisibleChange();
setTimeout(() => {
expect(onVisibleChangeCalled).equal(true);
expect(onCancleCalled).equal(true);
expect(onOkCalled).equal(true);
}, 200);
});

});

0 comments on commit 459e663

Please sign in to comment.