Skip to content

Commit e6df609

Browse files
committed
test: add antd testcase
1 parent 43db360 commit e6df609

File tree

22 files changed

+472
-229
lines changed

22 files changed

+472
-229
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ install:
1212
- npm i
1313
script:
1414
- npm run lint
15-
- npm run serve && npm run test
15+
- npm run serve && npm run test:antd
1616
after_script:
1717
- npm install coveralls@2 && cat ./coverage/lcov.info | coveralls

antd-sample/app.jsx

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import 'antd/dist/antd.css';
99
import './app.less';
1010

1111
import fetch from './common/fetch';
12+
import Login from './login.jsx';
1213

1314
import {
1415
Layout,
@@ -22,14 +23,9 @@ import {
2223
const columns = [{
2324
title: 'Name',
2425
dataIndex: 'name',
25-
// specify the condition of filtering result
26-
// here is that finding the name started with `value`
27-
onFilter: (value, record) => record.name.indexOf(value) === 0,
28-
sorter: (a, b) => a.name.length - b.name.length,
2926
}, {
3027
title: 'Age',
3128
dataIndex: 'age',
32-
defaultSortOrder: 'descend',
3329
sorter: (a, b) => a.age - b.age,
3430
}, {
3531
title: 'Address',
@@ -41,27 +37,23 @@ const columns = [{
4137
text: 'New York',
4238
value: 'New York',
4339
}],
44-
filterMultiple: false,
45-
onFilter: (value, record) => record.address.indexOf(value) === 0,
46-
sorter: (a, b) => a.address.length - b.address.length,
4740
}];
4841

49-
function onChange (pagination, filters, sorter) {
50-
console.log('params', pagination, filters, sorter);
51-
}
52-
5342
const Header = Layout.Header;
5443
const Footer = Layout.Footer;
5544
const Content = Layout.Content;
5645

5746
const Option = Select.Option;
5847

48+
const isLogin = location.hash === '#login';
49+
5950
class App extends React.Component {
6051
constructor (props) {
6152
super(props);
6253
this.state = {
6354
loading: true,
6455
dataList: [],
56+
buttonText: 'button',
6557
};
6658
}
6759

@@ -89,23 +81,36 @@ class App extends React.Component {
8981
});
9082
}
9183

84+
onSelectChange(e) {
85+
this.setState({
86+
buttonText: e,
87+
});
88+
}
89+
9290
render () {
91+
if (isLogin) {
92+
return <Login />;
93+
}
9394
return (
9495
<Layout>
9596
<Header className="header"></Header>
9697
<Content style={{ padding: 30 }}>
97-
<Select className="test-list" defaultValue="lucy" style={{ width: 120 }}>
98+
<Select
99+
className="test-list"
100+
defaultValue="lucy"
101+
onChange={this.onSelectChange.bind(this)}
102+
>
98103
<Option value="jack">Jack</Option>
99104
<Option value="lucy">Lucy</Option>
100105
<Option value="disabled" disabled>Disabled</Option>
101106
<Option value="fourth">fourth</Option>
102107
</Select>
103-
<Button onClick={this.doNotification.bind(this)}>A Button</Button>
108+
<Button onClick={this.doNotification.bind(this)}>{this.state.buttonText}</Button>
104109
<Spin
105110
tip="Loading..."
106111
spinning={this.state.loading}
107112
>
108-
<Table columns={columns} dataSource={this.state.dataList} onChange={onChange} />
113+
<Table columns={columns} dataSource={this.state.dataList} />
109114
</Spin>
110115
</Content>
111116
<Footer/>

antd-sample/app.less

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@
33
body {
44
font-family: "ProximaNova-Light", "Avenir Next", -apple-system-body, "Helvetica Neue", "Helvetica", sans-serif;
55
}
6+
7+
.test-list {
8+
width: 120px;
9+
margin: 10px 0;
10+
}

antd-sample/login.jsx

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
'use strict';
2+
3+
import 'intl';
4+
import React from 'react';
5+
6+
import {
7+
Form,
8+
Icon,
9+
Input,
10+
Button,
11+
Checkbox,
12+
} from 'antd';
13+
14+
import './login.less';
15+
16+
class NormalLoginForm extends React.Component {
17+
handleSubmit = (e) => {
18+
e.preventDefault();
19+
this.props.form.validateFields((err, values) => {
20+
if (!err) {
21+
console.log('Received values of form: ', values);
22+
}
23+
});
24+
}
25+
26+
render() {
27+
const { getFieldDecorator } = this.props.form;
28+
return (
29+
<Form onSubmit={this.handleSubmit} className="login-form">
30+
<Form.Item>
31+
{getFieldDecorator('userName', {
32+
rules: [{ required: true, message: 'Please input your username!' }],
33+
})(
34+
<Input accessbilityId="username" prefix={<Icon type="user" style={{ color: 'rgba(0,0,0,.25)' }} />} placeholder="Username" />
35+
)}
36+
</Form.Item>
37+
<Form.Item>
38+
{getFieldDecorator('password', {
39+
rules: [{ required: true, message: 'Please input your Password!' }],
40+
})(
41+
<Input accessbilityId="password" prefix={<Icon type="lock" style={{ color: 'rgba(0,0,0,.25)' }} />} type="password" placeholder="Password" />
42+
)}
43+
</Form.Item>
44+
<Form.Item>
45+
{getFieldDecorator('remember', {
46+
valuePropName: 'checked',
47+
initialValue: true,
48+
})(
49+
<Checkbox>Remember me</Checkbox>
50+
)}
51+
<a className="login-form-forgot" href="">Forgot password</a>
52+
<Button accessbilityId="login" type="primary" htmlType="submit" className="login-form-button">
53+
Log in
54+
</Button>
55+
Or <a href="">register now!</a>
56+
</Form.Item>
57+
</Form>
58+
);
59+
}
60+
}
61+
62+
const WrappedNormalLoginForm = Form.create({ name: 'normal_login' })(NormalLoginForm);
63+
64+
export default class Login extends React.Component {
65+
constructor (props) {
66+
super(props);
67+
this.state = {
68+
};
69+
}
70+
71+
componentWillMount () {
72+
}
73+
74+
render () {
75+
return <WrappedNormalLoginForm />;
76+
}
77+
}

antd-sample/login.less

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@import 'mixin.less';
2+
3+
.login-form {
4+
max-width: 350px;
5+
margin: 0 auto;
6+
margin-top: 15%;
7+
}
8+
9+
.login-form-forgot {
10+
float: right;
11+
}
12+
13+
.login-form-button {
14+
width: 100%;
15+
}

antd-sample/new-page.jsx

Lines changed: 0 additions & 114 deletions
This file was deleted.

antd-sample/new-page.less

Lines changed: 0 additions & 17 deletions
This file was deleted.

app-bootstrap/App.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ class App extends Component {
8282
>
8383
<div className="home">
8484
<h1 style={{
85-
marginTop: '10%'
85+
marginTop: '10%'
8686
}}>{CONSTANTS.TITLE}</h1>
8787
<Button style={{
88-
marginTop: '70%'
88+
marginTop: '70%'
8989
}} onClick={this.logoutHandle.bind(this)}>
9090
List
9191
</Button>
@@ -94,9 +94,9 @@ class App extends Component {
9494
<TabBar.Item
9595
icon={
9696
<div style={{
97-
width: '22px',
98-
height: '22px',
99-
background: `url(./img/[email protected]) center center / 54px 42px no-repeat` }}
97+
width: '22px',
98+
height: '22px',
99+
background: `url(./img/[email protected]) center center / 54px 42px no-repeat` }}
100100
/>
101101
}
102102
selectedIcon={
@@ -114,7 +114,7 @@ class App extends Component {
114114
selectedTab: 'Webview'
115115
});
116116
}}
117-
>
117+
>
118118
webview
119119
</TabBar.Item>
120120
<TabBar.Item
@@ -172,7 +172,7 @@ class App extends Component {
172172
<h1>{CONSTANTS.TITLE}</h1>
173173
<img alt={CONSTANTS.TITLE} src={`./img/avatar.png`} />
174174
<Button style={{
175-
marginTop: '70%'
175+
marginTop: '70%'
176176
}} onClick={this.logoutHandle.bind(this)}>Logout</Button>
177177
</div>
178178
</TabBar.Item>

0 commit comments

Comments
 (0)