Skip to content

Commit

Permalink
Merge pull request #1 from marcoaraujojunior/feature/include_test
Browse files Browse the repository at this point in the history
Feature/include test
  • Loading branch information
marcoaraujojunior authored Nov 16, 2016
2 parents ba985f0 + 279c9f2 commit 73a41f4
Show file tree
Hide file tree
Showing 35 changed files with 1,555 additions and 157 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
node_modules/**
public/dist/**
public/css/**
jest/**
coverage/**
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
language: node_js
node_js:
- "6"

services:
- mongodb

before_script:
- cd /client/
- npm install

script:
- npm run coverage
- codecov

after_success:
- bash <(curl -s https://codecov.io/bash)
27 changes: 15 additions & 12 deletions app/App.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Router, Route, IndexRoute } from 'react-router'
import { Router, Route, IndexRoute, hashHistory } from 'react-router'
import 'bulma/css/bulma.css'
import 'font-awesome-webpack'

import iClientComponent from './components/iClient/iClientComponent';
import HomeComponent from './components/Home/HomeComponent';
import ClientComponent from './components/Client/ClientComponent';
import iClientComponent from 'components/IClient/IClient';
import HomeComponent from 'components/Home/Home';
import ClientComponent from 'components/Client/Client';
import AreaComponent from 'components/Area/Area';

ReactDOM.render(
<section className="hero is-fullheight is-primary">
<Router>
<Route path="/" component={iClientComponent} >
<IndexRoute component={HomeComponent} />
<Route path="client" component={ClientComponent} />
</Route>
</Router>
</section>,
<Router history={hashHistory} >
<Route path="/" component={iClientComponent} >
<IndexRoute component={HomeComponent} />
<Route path="client" component={ClientComponent} />
<Route path="area" component={AreaComponent} />
<Route path="visit/:id" component={AreaComponent} />
</Route>
</Router>,
document.getElementById('app')
);
67 changes: 67 additions & 0 deletions app/components/Area/Area.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import React from 'react';
import { Link } from 'react-router'

import VisitService from 'services/Visit'

import Visit from 'components/Visit/Visit'
import ErrorComponent from 'components/Error/Error'

class Area extends React.Component
{
constructor(props) {
super(props);
this.state = {
areas : [],
error : ''
};
this.generate = this.generate.bind(this);
this.generateError = this.generateError.bind(this);
this.getVisitGroupByArea = this.getVisitGroupByArea.bind(this);
this.getVisitGroupByArea();
}

getVisitGroupByArea() {
VisitService.getGroupByArea().then((response) => {
this.setState({error: ''});
this.setState({
areas: this.generate(response.data.visits)
});
}).catch((error) => {
if (error.response) {
this.setState({error: error.response.data.error});
}
});
}

generateError(error) {
return (
<ErrorComponent error={this.state.error} />
);
}

generate(areas) {
return areas.map((area, key) => {
return (
<div className="area" key={ key }>
<h3 className="title is-3">{area._id}</h3>
<Visit visits={area.visits} />
</div>
);
});
}

render() {
if (this.state.error) {
let error = this.generateError(this.state.error);
return error;
}
return (
<div className="container hello">
{ this.state.areas }
</div>
);
}
}

export default Area;

Original file line number Diff line number Diff line change
@@ -1,27 +1,37 @@
import React from 'react';

import iClientClient from './../../services/iClientClient';
import ClientService from 'services/Client';
import Error from 'components/Error/Error'

class ClientComponent extends React.Component{
class Client extends React.Component
{
constructor(props) {
super(props);
this.state = {
clients : []
clients : [],
error : ''
};
this.getClients();
}

getClients() {
iClientClient.getClients().then((response) => {
console.log(response);
ClientService.getClients().then((response) => {
this.setState({clients: response.data.clients});
}).catch((error) => {
this.setState({error: 'Error Found: Trying get client'});
if (error.response) {
this.setState({error: error.response.data.error});
}
});
}

render() {
if (this.state.error) {
return (<Error error={this.state.error} />);
}
const clientList = this.state.clients.map((client, key) => {
return (
<tr>
<tr key={key} >
<td>{ client.name }</td>
<td>{ client.address }</td>
<td>{ client.city }</td>
Expand Down Expand Up @@ -52,5 +62,5 @@ class ClientComponent extends React.Component{
}
}

export default ClientComponent;
export default Client;

11 changes: 11 additions & 0 deletions app/components/Error/Error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';

const Error = ({error}) => (
error ?
<div className="notification is-danger">
{error}
</div> : null
);

export default Error;

19 changes: 19 additions & 0 deletions app/components/Home/Home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';

class Home extends React.Component{

render() {
return (
<div className="hero-body">
<div className="container">
<div className="is-half is-offset-one-quarter">
<h1 className="title has-text-centered is-1">Welcome to IClient</h1>
</div>
</div>
</div>
);
}
}

export default Home;

17 changes: 0 additions & 17 deletions app/components/Home/HomeComponent.js

This file was deleted.

37 changes: 37 additions & 0 deletions app/components/IClient/IClient.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import React from 'react';

import LoginComponent from 'components/Login/Login';
import MenuComponent from 'components/Menu/Menu';

class IClient extends React.Component
{
constructor(props, context) {
super(props, context);
this.handleView = this.handleView.bind(this);
}

handleView() {
return (
<div>
<MenuComponent />
<section className="hero is-fullheight is-primary">
{this.props.children}
</section>
</div>
);
}

render() {
let view = this.handleView();

if (!window.localStorage.getItem('token')) {
view = <LoginComponent />;
}
return (
view
);
}
}

export default IClient;

55 changes: 55 additions & 0 deletions app/components/LinksApp/LinksApp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import React from 'react';
import { Link } from 'react-router'

class LinksApp extends React.Component
{
constructor(props, context) {
super(props, context);
this.generate = this.generate.bind(this);
this.handleClick = this.handleClick.bind(this);
this.state = {
links: this.props.links
};
}

handleClick(e) {
if (this.context.onClick) {
this.context.onClick();
}
}

generate() {
return this.state.links.map((link, index) => {
return (
<Link to={link[0]}
key={index}
className="nav-item is-tab"
onlyActiveOnIndex={true}
activeClassName="is-active"
onClick={this.handleClick}
>
{link[1]}
</Link>
);
});
}

render() {
return (
<span className="nav-right nav-menu is-active">
{this.generate()}
</span>
);
}
}

LinksApp.propTypes = {
links: React.PropTypes.array.isRequired
};

LinksApp.contextTypes = {
onClick: React.PropTypes.func
};

export default LinksApp;

Loading

0 comments on commit 73a41f4

Please sign in to comment.