Skip to content

Commit

Permalink
Merge pull request #44 from fga-eps-mds/release/v0.2.0
Browse files Browse the repository at this point in the history
Release/v0.2.0
  • Loading branch information
byronkamal authored Nov 28, 2019
2 parents 45a3c85 + e7c9c0f commit e7b6686
Show file tree
Hide file tree
Showing 85 changed files with 1,993 additions and 473 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ jobs:
name: "Tests"
script:
# run lint and tests
- yarn quality-check
# - yarn quality-check
- yarn test -u --coverage
- ./node_modules/.bin/codecov -t ${CODECOV_TOKEN}

- stage: "Deploy stage"
Expand Down
26 changes: 6 additions & 20 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
coverage:
precision: 2
round: down
range: "70...100"

status:
project: yes
patch: no
changes: no

parsers:
gcov:
branch_detection:
conditional: yes
loop: yes
method: no
macro: no

comment:
layout: "header, diff"
behavior: default
require_changes: no
project:
default:
target: auto
threshold: 3%
base: auto
patch: off
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
"eject": "react-scripts eject",
"quality-check": "npm run lint && CI=true npm test --watchAll"
},
"jest": {
"collectCoverageFrom": [
"!src/serviceWorker.js"
]
},
"eslintConfig": {
"extends": "react-app"
},
Expand Down
86 changes: 58 additions & 28 deletions src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React from 'react';
import io from 'socket.io-client';

import { Router, Route, Redirect, Switch } from 'react-router-dom';
import PropTypes from 'prop-types';
import { isAuthenticated, isRootUser } from './Services/authentication';
Expand All @@ -13,10 +15,13 @@ import CadastroAtletas from './Views/Dashboard/Admin/CadastroAtletas';
import Ranking from './Views/Dashboard/Admin/Ranking';

import Bancas from './Views/Dashboard/Judge/Bancas';
import Votacao from './Views/Dashboard/Judge/Votacao';

import './App.css';
import EditarCoordenador from './Views/Dashboard/Admin/EditarCoordenador';

import SocketContext from './socket-context';

export function PrivateRoute({ component: Component, ...rest }) {
const hasAuth = isAuthenticated();

Expand All @@ -33,13 +38,12 @@ PrivateRoute.propTypes = {
component: PropTypes.node.isRequired,
};

function AdminPages(props) {
export function AdminPages(props) {
const { history } = props;

return (
<Page history={history}>
<Switch>
<Route path="/cadastro/dashboard" component={Bancas} />
<PrivateRoute path="/cadastro/home" component={Home} />
<PrivateRoute
exact
Expand All @@ -50,73 +54,99 @@ function AdminPages(props) {
path="/cadastro/editar-banca/:idBanca"
component={CadastroBancas}
/>
<PrivateRoute
path="/cadastro/arbitros/form/:idArbitro"
component={CadastroArbitrosForm}
/>
<PrivateRoute
path="/cadastro/arbitros/form"
component={CadastroArbitrosForm}
/>
<PrivateRoute path="/cadastro/arbitros" component={CadastroArbitros} />
<PrivateRoute
path="/cadastro/atletas/form"
path="/cadastro/atletas/form/:idAtleta"
component={CadastroAtletaForm}
/>
<PrivateRoute
path="/cadastro/atletas"
component={CadastroAtletas}
/>
<PrivateRoute
path="/ranking"
component={Ranking}
path="/cadastro/atletas/form"
component={CadastroAtletaForm}
/>
<PrivateRoute path="/cadastro/atletas" component={CadastroAtletas} />

<PrivateRoute path="/ranking" component={Ranking} />
<Route path="/cadastro/editar-perfil" component={EditarCoordenador} />
<Redirect to="/cadastro/home" />
</Switch>
</Page>
);
}
AdminPages.propTypes = {
history: PropTypes.objectOf(PropTypes.any).isRequired,
};

function JudgeRoutes() {
export function JudgeRoutes() {
return (
<Page>
<PrivateRoute
path="/judge/home"
component={() => <h1>Home do Juíz</h1>}
/>
<Redirect to="/judge/home" />
<PrivateRoute path="/judge/dashboard" component={Bancas} />
<PrivateRoute path="/judge/votacao" component={Votacao} />
<Redirect to="/judge/dashboard" />
</Page>
);
}

function renderRoutes() {
if (isRootUser) {
return <Route path="/cadastro" component={AdminPages} />;
if (isRootUser()) {
return (
<>
<Route path="/" component={AdminPages} />
</>
);
}

if (isRootUser === false) {
if (isRootUser() === false) {
return <Route path="/judge" component={JudgeRoutes} />;
}

return <Redirect to="/" />;
}

const socket = (() => {
const jwtToken = localStorage.getItem('jwt-token');

return io(process.env.REACT_APP_API_URL, {
query: { token: jwtToken ? jwtToken.split(' ')[1] : '' },
});
})();

window.onstorage = (e) => {
if (e.key === 'jwt-token') {
socket.disconnect();
socket.socket.options.query = {
token: e.newValue ? e.newValue.split(' ')[1] : '',
};
socket.socket.connect();
}
};

function App(props) {
const { history } = props;

return (
<Router history={history}>
<Switch>
<Route path="/" exact component={Login} />
{renderRoutes()}
<Redirect to="/" />
</Switch>
</Router>
<SocketContext.Provider value={socket}>
<Router history={history}>
<Switch>
<Route path="/" exact component={Login} />
{renderRoutes()}
<Redirect to="/" />
</Switch>
</Router>
</SocketContext.Provider>
);
}

export default App;

AdminPages.propTypes = {
history: PropTypes.objectOf(PropTypes.any).isRequired,
};

App.propTypes = {
history: PropTypes.objectOf(PropTypes.any).isRequired,
};
28 changes: 28 additions & 0 deletions src/App.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import { shallow } from 'enzyme';
import App, { AdminPages, JudgeRoutes, PrivateRoute } from './App';

describe('App', () => {
test('definition', () => {
const mockProps = {};
const wrapper = shallow(<App {...mockProps} />);
expect(wrapper).toBeDefined();
});

test('AdminPages', () => {
const mockProps = { props: {} };
const wrapper = shallow(<AdminPages {...mockProps} />);
expect(wrapper).toBeDefined();
});

test('JudgeRoutes', () => {
const mockProps = {};
const wrapper = shallow(<JudgeRoutes {...mockProps} />);
expect(wrapper).toBeDefined();
});

test('PrivateRoute', () => {
const wrapper = shallow(<PrivateRoute />);
expect(wrapper).toBeDefined();
});
});
22 changes: 22 additions & 0 deletions src/Components/Card/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import { Icon, Divider } from 'antd';
import PropTypes from 'prop-types';
import { Container, CardContent } from './styles';

const Card = ({ title, icon, route }) => (
<Container>
<CardContent to={`/cadastro/${route}`}>
<Icon type={icon} />
<Divider type="vertical" />
{title}
</CardContent>
</Container>
);

export default Card;

Card.propTypes = {
title: PropTypes.string.isRequired,
icon: PropTypes.string.isRequired,
route: PropTypes.string.isRequired,
};
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import styled from 'styled-components';
import { Link } from 'react-router-dom';
import colors from '../../../../Constants/colors';
import colors from '../../Constants/colors';

export const Wrapper = styled.div`
export const Container = styled.div`
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: column;
justify-content: space-between;
padding: 30px 0;
`;

export const OptionCard = styled(Link)`
export const CardContent = styled(Link)`
margin: auto;
display: flex;
width: 49%;
width: 65%;
min-width: 230px;
align-items: column;
justify-content: center;
box-shadow: 0 0 6px lightGrey;
padding: 30px;
Expand Down
28 changes: 28 additions & 0 deletions src/Components/Countdown/Countdown.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React, { useContext, useEffect, useState } from 'react';

import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
import { faStopwatch } from '@fortawesome/free-solid-svg-icons';
import SocketContext from '../../socket-context';

export default function Countdown() {
const socket = useContext(SocketContext);
const [secondsRemaining, setSecondsRemaining] = useState(0);

useEffect(() => {
socket.on('voteTimer', (voteSocket) => {
const { timeRemaining } = voteSocket;
setSecondsRemaining(timeRemaining);
});
}, [socket]);

return (
<>
<FontAwesomeIcon icon={faStopwatch} />
<b>
{' '}
{Math.floor(secondsRemaining / 60)}:
{(secondsRemaining % 60).toString().padStart(2, '0')}
</b>
</>
);
}
3 changes: 3 additions & 0 deletions src/Components/Countdown/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import Countdown from './Countdown';

export default Countdown;
19 changes: 19 additions & 0 deletions src/Components/DataEntry/DatePicker/DatePicker.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import { shallow } from 'enzyme';
import DatePicker from './DatePicker';

describe('DatePicker', () => {
const mockProps = {
form: {
touched: false,
errors: {},
},
field: { name: 'field' },
type: 'password',
};
const wrapper = shallow(<DatePicker {...mockProps} />);

it('Deve estar definida', () => {
expect(wrapper).toBeDefined();
});
});
12 changes: 12 additions & 0 deletions src/Components/DataEntry/FieldWithIcon/FieldWithIcon.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import { shallow } from 'enzyme';
import FieldWithIcon from './FieldWithIcon';

describe('FieldWithIcon', () => {
const mockProps = {};
const wrapper = shallow(<FieldWithIcon {...mockProps} />);

it('Deve estar definida', () => {
expect(wrapper).toBeDefined();
});
});
2 changes: 1 addition & 1 deletion src/Components/DataEntry/InputNumber/InputNumber.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default function InputNumber(props) {
<Form.Item
label={label}
validateStatus={
touched[field.name] && errors[field.name]
touched && errors[field.name]
? 'error'
: null
}
Expand Down
2 changes: 1 addition & 1 deletion src/Components/DataEntry/Select/Select.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function InputNumber(props) {
<Form.Item
label={label}
validateStatus={
touched[field.name] && errors[field.name]
touched && errors[field.name]
? 'error'
: null
}
Expand Down
19 changes: 19 additions & 0 deletions src/Components/DataEntry/Select/Select.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import { shallow } from 'enzyme';
import Select from './Select';

describe('Select', () => {
const mockProps = {
form: {
touched: false,
errors: {},
},
field: { name: 'field' },
type: 'password',
};
const wrapper = shallow(<Select {...mockProps} />);

it('Deve estar definida', () => {
expect(wrapper).toBeDefined();
});
});
Loading

0 comments on commit e7b6686

Please sign in to comment.