Skip to content

Commit

Permalink
Merge pull request #8 from kwl777/react16
Browse files Browse the repository at this point in the history
React16
  • Loading branch information
kwl777 authored Jun 21, 2018
2 parents c0f6921 + 0af285d commit d143ec4
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 107 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ spm_modules
dist
build
assets/**/*.css
coverage
package-lock.json
7 changes: 3 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
<body>
<div id="UXCoreDemo"></div>
<script src="./node_modules/console-polyfill/index.js"></script>
<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="./node_modules/react-dom/dist/react-dom.js"></script>
<script src="./node_modules/babel-polyfill/dist/polyfill.min.js"></script>
<script src="./node_modules/react/umd/react.development.js"></script>
<script src="./node_modules/react-dom/umd/react-dom.development.js"></script>
<script src="./dist/demo.js"></script>
</body>
</html>
13 changes: 6 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,15 @@
"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-addons-test-utils": "15.x",
"react-dom": "15.x",
"react-test-renderer": "15.x",
"react": "16.x",
"react-dom": "16.x",
"react-test-renderer": "16.x",
"uxcore-kuma": "*",
"uxcore-tools": "0.2.x"
"uxcore-tools": "^0.3.0",
"babel-polyfill": "6.x",
"enzyme-adapter-react-16": "1.x"
},
"dependencies": {
"classnames": "^2.1.2",
Expand Down
187 changes: 91 additions & 96 deletions tests/Radiogroup.spec.js
Original file line number Diff line number Diff line change
@@ -1,123 +1,118 @@
import expect from 'expect.js';
import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils, {Simulate} from 'react-addons-test-utils';
import assign from 'object-assign';
import Enzyme, {mount, shallow} from 'enzyme';
import Adapter from 'enzyme-adapter-react-15';
import Enzyme, { mount } from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import Radiogroup from '../src';
import RadiogroupItem from '../src/RadiogroupItem';

Enzyme.configure({adapter: new Adapter()});
Enzyme.configure({ adapter: new Adapter() });

function renderWithProps(someProps) {
const props = {
value: {},
disabled: false
};
const items = [
{disabled: false, value: "apple", text: "苹果"},
{value: "banana", text: "香蕉"},
{value: "orange", text: "橘子"},
];
assign(props, someProps);
let RadiogroupItems = items.map(function (v, i) {
return <RadiogroupItem disabled={v.disabled} value={v.value} text={v.text}/>;
});
const wrapper = mount(<Radiogroup {...props}>
{RadiogroupItems}
</Radiogroup>);
return wrapper;
const props = {
value: {},
disabled: false,
};
const items = [
{ disabled: false, value: 'apple', text: '苹果' },
{ value: 'banana', text: '香蕉' },
{ value: 'orange', text: '橘子' },
];
assign(props, someProps);
let RadiogroupItems = items.map(v => {
return <RadiogroupItem disabled={v.disabled} value={v.value} text={v.text} />;
});
const wrapper = mount(<Radiogroup {...props}>{RadiogroupItems}</Radiogroup>);
return wrapper;
}

function renderWithProps2() {
class Demo extends React.Component {
constructor(props) {
super(props);
this.state = {};
}
class Demo extends React.Component {
constructor(props) {
super(props);
this.state = {};
}

handleChange(value) {
const me = this;
me.setState({
value,
});
}
handleChange(value) {
const me = this;
me.setState({
value,
});
}

render() {
const me = this;
const items = [
{disabled: false, value: "apple", text: "苹果"},
{value: "banana", text: "香蕉"},
{value: "orange", text: "橘子"},
];
let RadiogroupItems = items.map(function (v, i) {
return <RadiogroupItem disabled={v.disabled} value={v.value} text={v.text}/>;
});
render() {
const me = this;
const items = [
{ disabled: false, value: 'apple', text: '苹果' },
{ value: 'banana', text: '香蕉' },
{ value: 'orange', text: '橘子' },
];
let RadiogroupItems = items.map(v => {
return <RadiogroupItem disabled={v.disabled} value={v.value} text={v.text} />;
});

return (<Radiogroup value={me.state.value} onChange={me.handleChange.bind(me)} disabled>
{RadiogroupItems}
</Radiogroup>);
}
return (
<Radiogroup value={me.state.value} onChange={me.handleChange.bind(me)} disabled>
{RadiogroupItems}
</Radiogroup>
);
}
}

return mount(
<Demo/>
);
return mount(<Demo />);
}

function renderWithProps3() {
class Demo extends React.Component {
constructor(props) {
super(props);
this.state = {};
}
// function renderWithProps3() {
// class Demo extends React.Component {
// constructor(props) {
// super(props);
// this.state = {};
// }

handleChange(value) {
const me = this;
me.setState({
value,
});
}
// handleChange(value) {
// const me = this;
// me.setState({
// value,
// });
// }

render() {
const me = this;
const items = [
{disabled: false, value: "apple", text: "苹果"},
{value: "banana", text: "香蕉"},
{value: "orange", text: "橘子"},
];
let RadiogroupItems = items.map(function (v, i) {
return <RadiogroupItem disabled={v.disabled} value={v.value} text={v.text}/>;
});
// render() {
// const me = this;
// const items = [
// { disabled: false, value: 'apple', text: '苹果' },
// { value: 'banana', text: '香蕉' },
// { value: 'orange', text: '橘子' },
// ];
// let RadiogroupItems = items.map(v => {
// return <RadiogroupItem disabled={v.disabled} value={v.value} text={v.text} />;
// });

return (<Radiogroup value={me.state.value} onChange={me.handleChange.bind(me)} disabled>
{RadiogroupItems}
</Radiogroup>);
}
}
// return (
// <Radiogroup value={me.state.value} onChange={me.handleChange.bind(me)} disabled>
// {RadiogroupItems}
// </Radiogroup>
// );
// }
// }

return shallow(
<Demo/>
);
}
// return shallow(<Demo />);
// }

describe('Radiogroup', () => {
describe('render', () => {
it('should render correctly', (done) => {
const wrapper = renderWithProps();
expect(wrapper.find('.kuma-radio-group-item').length).to.be(3);
done();
});
describe('render', () => {
it('should render correctly', done => {
const wrapper = renderWithProps();
expect(wrapper.find('.kuma-radio-group-item').length).to.be(3);
done();
});
});

describe('control', () => {
const wrapper = renderWithProps2();
it('should handle control correctly', (done) => {
wrapper.instance().handleChange("apple");
expect(wrapper.instance().state.value).to.equal("apple");
done();
});
describe('control', () => {
const wrapper = renderWithProps2();
it('should handle control correctly', done => {
wrapper.instance().handleChange('apple');
expect(wrapper.instance().state.value).to.equal('apple');
done();
});

});
});
});

0 comments on commit d143ec4

Please sign in to comment.