Skip to content

Commit

Permalink
Dashboard Login - Should be checked the error validation on handleSub…
Browse files Browse the repository at this point in the history
…mit (#31)
  • Loading branch information
wellitonSouza authored and Luis Felipe Furlan Cruz committed Jan 27, 2021
1 parent 517cb2e commit 73ae625
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"real time": "Tempo Real",
"historic": "Histórico",
"last": "Últimos",
"records": "No. Records",
"records": "No. Registros",
"order": "Ordem",
"select an option": "Selecione uma opção",
"last minutes": "Últimos minutos",
Expand Down
2 changes: 0 additions & 2 deletions src/js/views/login/View.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ const LoginView = ({ location, history }) => {
});
history.push('/dashboard');
} catch ({ message }) {
// TODO: Handle the exception more appropriately
console.error(message);
setHasError(true);
setMsgError(
message.indexOf('404') !== -1 ? 'networkError' : 'loginError',
Expand Down
47 changes: 47 additions & 0 deletions src/js/views/login/login.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Alert from '@material-ui/lab/Alert';
import { render, fireEvent, act } from '@testing-library/react';
import * as api from 'APIs/index';
import { mount } from 'enzyme';
import { Authentication } from 'Services';

import Login, { LoginForm } from './View';

Expand Down Expand Up @@ -53,6 +54,52 @@ describe('Login', () => {
expect(wrapper.find(LoginForm).find(Alert)).toHaveLength(1);
});

it('shoud be able to simple render Network error', async () => {
jest.spyOn(Authentication, 'login').mockImplementationOnce(() => {
throw new Error('404');
});

const wrapper = mount(<Login />);

const userField = wrapper.find('input[name="user"]').first();
await updateFormikField(userField, 'user', 'user123456');

const passwordField = wrapper.find('input[name="password"]').first();
await updateFormikField(passwordField, 'password', 'password123456');

const htmlForm = wrapper.find('form');

await submitFormikForm(htmlForm);

wrapper.update();
expect(wrapper.find(LoginForm).find(Alert).at(0).text()).toEqual(
'login:networkError',
);
});

it('shoud be able to simple render Login Error', async () => {
jest.spyOn(Authentication, 'login').mockImplementationOnce(() => {
throw new Error('Erro ao efetuar login');
});

const wrapper = mount(<Login />);

const userField = wrapper.find('input[name="user"]').first();
await updateFormikField(userField, 'user', 'user123456');

const passwordField = wrapper.find('input[name="password"]').first();
await updateFormikField(passwordField, 'password', 'password123456');

const htmlForm = wrapper.find('form');

await submitFormikForm(htmlForm);

wrapper.update();
expect(wrapper.find(LoginForm).find(Alert).at(0).text()).toEqual(
'login:loginError',
);
});

it('shoud be able to simple render', () => {
const { container } = render(<Login />);
expect(container).toBeInTheDocument();
Expand Down

0 comments on commit 73ae625

Please sign in to comment.