add more login page tests

This commit is contained in:
John Mitchell
2018-10-30 15:08:45 -04:00
parent ecd8427a51
commit 7c97989e84
2 changed files with 175 additions and 24 deletions

View File

@@ -42,21 +42,24 @@ class LoginPage extends Component {
handlePasswordChange = value => this.safeSetState({ password: value, error: '' });
handleSubmit = event => {
const { username, password } = this.state;
const { username, password, loading } = this.state;
event.preventDefault();
this.safeSetState({ loading: true });
if (!loading) {
this.safeSetState({ loading: true });
api.login(username, password)
.catch(error => {
if (error.response.status === 401) {
this.safeSetState({ error: LOGIN_ERROR_MESSAGE });
}
})
.finally(() => {
this.safeSetState({ loading: false });
});
api.login(username, password)
.then(() => {
this.safeSetState({ loading: false });
})
.catch(error => {
this.safeSetState({ loading: false });
if (error.response.status === 401) {
this.safeSetState({ error: LOGIN_ERROR_MESSAGE });
}
});
}
}
render () {