Skip to content

Commit 73a41f4

Browse files
Merge pull request #1 from marcoaraujojunior/feature/include_test
Feature/include test
2 parents ba985f0 + 279c9f2 commit 73a41f4

35 files changed

+1555
-157
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
node_modules/**
33
public/dist/**
44
public/css/**
5+
jest/**
6+
coverage/**

.travis.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
language: node_js
2+
node_js:
3+
- "6"
4+
5+
services:
6+
- mongodb
7+
8+
before_script:
9+
- cd /client/
10+
- npm install
11+
12+
script:
13+
- npm run coverage
14+
- codecov
15+
16+
after_success:
17+
- bash <(curl -s https://codecov.io/bash)

app/App.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
3-
import { Router, Route, IndexRoute } from 'react-router'
3+
import { Router, Route, IndexRoute, hashHistory } from 'react-router'
4+
import 'bulma/css/bulma.css'
5+
import 'font-awesome-webpack'
46

5-
import iClientComponent from './components/iClient/iClientComponent';
6-
import HomeComponent from './components/Home/HomeComponent';
7-
import ClientComponent from './components/Client/ClientComponent';
7+
import iClientComponent from 'components/IClient/IClient';
8+
import HomeComponent from 'components/Home/Home';
9+
import ClientComponent from 'components/Client/Client';
10+
import AreaComponent from 'components/Area/Area';
811

912
ReactDOM.render(
10-
<section className="hero is-fullheight is-primary">
11-
<Router>
12-
<Route path="/" component={iClientComponent} >
13-
<IndexRoute component={HomeComponent} />
14-
<Route path="client" component={ClientComponent} />
15-
</Route>
16-
</Router>
17-
</section>,
13+
<Router history={hashHistory} >
14+
<Route path="/" component={iClientComponent} >
15+
<IndexRoute component={HomeComponent} />
16+
<Route path="client" component={ClientComponent} />
17+
<Route path="area" component={AreaComponent} />
18+
<Route path="visit/:id" component={AreaComponent} />
19+
</Route>
20+
</Router>,
1821
document.getElementById('app')
1922
);

app/components/Area/Area.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
import React from 'react';
2+
import { Link } from 'react-router'
3+
4+
import VisitService from 'services/Visit'
5+
6+
import Visit from 'components/Visit/Visit'
7+
import ErrorComponent from 'components/Error/Error'
8+
9+
class Area extends React.Component
10+
{
11+
constructor(props) {
12+
super(props);
13+
this.state = {
14+
areas : [],
15+
error : ''
16+
};
17+
this.generate = this.generate.bind(this);
18+
this.generateError = this.generateError.bind(this);
19+
this.getVisitGroupByArea = this.getVisitGroupByArea.bind(this);
20+
this.getVisitGroupByArea();
21+
}
22+
23+
getVisitGroupByArea() {
24+
VisitService.getGroupByArea().then((response) => {
25+
this.setState({error: ''});
26+
this.setState({
27+
areas: this.generate(response.data.visits)
28+
});
29+
}).catch((error) => {
30+
if (error.response) {
31+
this.setState({error: error.response.data.error});
32+
}
33+
});
34+
}
35+
36+
generateError(error) {
37+
return (
38+
<ErrorComponent error={this.state.error} />
39+
);
40+
}
41+
42+
generate(areas) {
43+
return areas.map((area, key) => {
44+
return (
45+
<div className="area" key={ key }>
46+
<h3 className="title is-3">{area._id}</h3>
47+
<Visit visits={area.visits} />
48+
</div>
49+
);
50+
});
51+
}
52+
53+
render() {
54+
if (this.state.error) {
55+
let error = this.generateError(this.state.error);
56+
return error;
57+
}
58+
return (
59+
<div className="container hello">
60+
{ this.state.areas }
61+
</div>
62+
);
63+
}
64+
}
65+
66+
export default Area;
67+

app/components/Client/ClientComponent.js renamed to app/components/Client/Client.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
11
import React from 'react';
22

3-
import iClientClient from './../../services/iClientClient';
3+
import ClientService from 'services/Client';
4+
import Error from 'components/Error/Error'
45

5-
class ClientComponent extends React.Component{
6+
class Client extends React.Component
7+
{
68
constructor(props) {
79
super(props);
810
this.state = {
9-
clients : []
11+
clients : [],
12+
error : ''
1013
};
1114
this.getClients();
1215
}
1316

1417
getClients() {
15-
iClientClient.getClients().then((response) => {
16-
console.log(response);
18+
ClientService.getClients().then((response) => {
1719
this.setState({clients: response.data.clients});
20+
}).catch((error) => {
21+
this.setState({error: 'Error Found: Trying get client'});
22+
if (error.response) {
23+
this.setState({error: error.response.data.error});
24+
}
1825
});
1926
}
2027

2128
render() {
29+
if (this.state.error) {
30+
return (<Error error={this.state.error} />);
31+
}
2232
const clientList = this.state.clients.map((client, key) => {
2333
return (
24-
<tr>
34+
<tr key={key} >
2535
<td>{ client.name }</td>
2636
<td>{ client.address }</td>
2737
<td>{ client.city }</td>
@@ -52,5 +62,5 @@ class ClientComponent extends React.Component{
5262
}
5363
}
5464

55-
export default ClientComponent;
65+
export default Client;
5666

app/components/Error/Error.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import React from 'react';
2+
3+
const Error = ({error}) => (
4+
error ?
5+
<div className="notification is-danger">
6+
{error}
7+
</div> : null
8+
);
9+
10+
export default Error;
11+

app/components/Home/Home.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import React from 'react';
2+
3+
class Home extends React.Component{
4+
5+
render() {
6+
return (
7+
<div className="hero-body">
8+
<div className="container">
9+
<div className="is-half is-offset-one-quarter">
10+
<h1 className="title has-text-centered is-1">Welcome to IClient</h1>
11+
</div>
12+
</div>
13+
</div>
14+
);
15+
}
16+
}
17+
18+
export default Home;
19+

app/components/Home/HomeComponent.js

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

app/components/IClient/IClient.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from 'react';
2+
3+
import LoginComponent from 'components/Login/Login';
4+
import MenuComponent from 'components/Menu/Menu';
5+
6+
class IClient extends React.Component
7+
{
8+
constructor(props, context) {
9+
super(props, context);
10+
this.handleView = this.handleView.bind(this);
11+
}
12+
13+
handleView() {
14+
return (
15+
<div>
16+
<MenuComponent />
17+
<section className="hero is-fullheight is-primary">
18+
{this.props.children}
19+
</section>
20+
</div>
21+
);
22+
}
23+
24+
render() {
25+
let view = this.handleView();
26+
27+
if (!window.localStorage.getItem('token')) {
28+
view = <LoginComponent />;
29+
}
30+
return (
31+
view
32+
);
33+
}
34+
}
35+
36+
export default IClient;
37+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import React from 'react';
2+
import { Link } from 'react-router'
3+
4+
class LinksApp extends React.Component
5+
{
6+
constructor(props, context) {
7+
super(props, context);
8+
this.generate = this.generate.bind(this);
9+
this.handleClick = this.handleClick.bind(this);
10+
this.state = {
11+
links: this.props.links
12+
};
13+
}
14+
15+
handleClick(e) {
16+
if (this.context.onClick) {
17+
this.context.onClick();
18+
}
19+
}
20+
21+
generate() {
22+
return this.state.links.map((link, index) => {
23+
return (
24+
<Link to={link[0]}
25+
key={index}
26+
className="nav-item is-tab"
27+
onlyActiveOnIndex={true}
28+
activeClassName="is-active"
29+
onClick={this.handleClick}
30+
>
31+
{link[1]}
32+
</Link>
33+
);
34+
});
35+
}
36+
37+
render() {
38+
return (
39+
<span className="nav-right nav-menu is-active">
40+
{this.generate()}
41+
</span>
42+
);
43+
}
44+
}
45+
46+
LinksApp.propTypes = {
47+
links: React.PropTypes.array.isRequired
48+
};
49+
50+
LinksApp.contextTypes = {
51+
onClick: React.PropTypes.func
52+
};
53+
54+
export default LinksApp;
55+

0 commit comments

Comments
 (0)