mirror of
https://github.com/ansible/awx.git
synced 2026-01-21 06:28:01 -03:30
working commit LoginPage.jsx tests
This commit is contained in:
parent
fba1a5b71a
commit
cfb89f1e31
49
__tests__/tests/LoginPage.test.jsx
Normal file
49
__tests__/tests/LoginPage.test.jsx
Normal file
@ -0,0 +1,49 @@
|
||||
import React from 'react';
|
||||
import { MemoryRouter } from 'react-router-dom';
|
||||
import { shallow, mount } from 'enzyme';
|
||||
import LoginPage from '../../src/pages/Login';
|
||||
import api from '../../src/api';
|
||||
import Dashboard from '../../src/pages/Dashboard';
|
||||
|
||||
describe('<LoginPage />', () => {
|
||||
let loginWrapper, usernameInput, passwordInput, errorTextArea, submitButton;
|
||||
|
||||
beforeEach(() => {
|
||||
loginWrapper = mount(<MemoryRouter><LoginPage /></MemoryRouter>);
|
||||
usernameInput = loginWrapper.find('.pf-c-form__group#username TextInput');
|
||||
passwordInput = loginWrapper.find('.pf-c-form__group#password TextInput');
|
||||
errorTextArea = loginWrapper.find('.pf-c-form__helper-text.pf-m-error');
|
||||
submitButton = loginWrapper.find('Button[type="submit"]');
|
||||
});
|
||||
|
||||
test('initially renders without crashing', () => {
|
||||
expect(loginWrapper.length).toBe(1);
|
||||
expect(usernameInput.length).toBe(1);
|
||||
expect(passwordInput.length).toBe(1);
|
||||
expect(errorTextArea.length).toBe(1);
|
||||
expect(submitButton.length).toBe(1);
|
||||
});
|
||||
|
||||
// initially renders empty username and password fields
|
||||
// as well as state.username and state.password to empty strings
|
||||
// initially sets state.error and state.loading to false
|
||||
|
||||
// on unmount, unmount is set to true
|
||||
|
||||
// typing into username and password fields (if the component is not unmounting)
|
||||
// set state.username and state.password, as well as set state.error to empty string
|
||||
// this is done through the handleUsernameChange and handlePasswordChange functions
|
||||
// which both call safeSetState
|
||||
|
||||
// when the submit Button is clicked, as long as it is not disabled (through state.loading
|
||||
// being set tp true), state.loading is set to true (through safeSetState)
|
||||
// api.login is called with param 1 username and param 2 password based on state
|
||||
|
||||
// if api.login returns an error, the state.error should be set to LOGIN_ERROR_MESSAGE
|
||||
// if the error object returned has response.status set to 401.
|
||||
|
||||
// regardless of error or not, after api.login returns state.loading should be set to false
|
||||
// via safeSetState
|
||||
|
||||
// QUESTION: if api.login is valid, how does redirect happen?
|
||||
});
|
||||
@ -63,9 +63,9 @@ class LoginPage extends Component {
|
||||
const { username, password, loading, error } = this.state;
|
||||
const { logo, loginInfo } = this.props;
|
||||
|
||||
if (api.isAuthenticated()) {
|
||||
return (<Redirect to="/" />);
|
||||
}
|
||||
// if (api.isAuthenticated()) {
|
||||
// return (<Redirect to="/" />);
|
||||
// }
|
||||
|
||||
return (
|
||||
<Login
|
||||
@ -97,7 +97,7 @@ class LoginPage extends Component {
|
||||
onChange={this.handleUsernameChange}
|
||||
/>
|
||||
</div>
|
||||
<div className="pf-c-form__group">
|
||||
<div className="pf-c-form__group" id="password">>
|
||||
<label className="pf-c-form__label" htmlFor="pw">
|
||||
Password
|
||||
<span className="pf-c-form__label__required" aria-hidden="true">*</span>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user