1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 15:21:13 +03:00

add 'has' prefix to error booleans

This commit is contained in:
Jake McDermott 2019-06-21 12:01:29 -04:00
parent c3823771a7
commit 9dda5404a0
4 changed files with 31 additions and 31 deletions

View File

@ -48,7 +48,7 @@ class App extends Component {
version: null,
isAboutModalOpen: false,
isNavOpen,
configError: false,
hasConfigError: false,
};
this.handleLogout = this.handleLogout.bind(this);
@ -81,7 +81,7 @@ class App extends Component {
}
handleConfigErrorClose () {
this.setState({ configError: false });
this.setState({ hasConfigError: false });
}
async loadConfig () {
@ -92,7 +92,7 @@ class App extends Component {
this.setState({ ansible_version, custom_virtualenvs, version, me });
} catch (err) {
this.setState({ configError: true });
this.setState({ hasConfigError: true });
}
}
@ -104,7 +104,7 @@ class App extends Component {
isNavOpen,
me,
version,
configError,
hasConfigError,
} = this.state;
const {
i18n,
@ -170,7 +170,7 @@ class App extends Component {
onClose={this.handleAboutClose}
/>
<AlertModal
isOpen={configError}
isOpen={hasConfigError}
variant="danger"
title={i18n._(t`Error!`)}
onClose={this.handleConfigErrorClose}

View File

@ -32,7 +32,7 @@ class JobList extends Component {
this.state = {
hasContentLoading: true,
hasContentError: false,
deletionError: false,
hasDeletionError: false,
selected: [],
jobs: [],
itemCount: 0,
@ -56,7 +56,7 @@ class JobList extends Component {
}
handleDeleteErrorClose () {
this.setState({ deletionError: false });
this.setState({ hasDeletionError: false });
}
handleSelectAll (isSelected) {
@ -76,11 +76,11 @@ class JobList extends Component {
async handleDelete () {
const { selected } = this.state;
this.setState({ hasContentLoading: true, deletionError: false });
this.setState({ hasContentLoading: true, hasDeletionError: false });
try {
await Promise.all(selected.map(({ id }) => UnifiedJobsAPI.destroy(id)));
} catch (err) {
this.setState({ deletionError: true });
this.setState({ hasDeletionError: true });
} finally {
await this.loadJobs();
}
@ -109,7 +109,7 @@ class JobList extends Component {
const {
hasContentError,
hasContentLoading,
deletionError,
hasDeletionError,
jobs,
itemCount,
selected,
@ -166,7 +166,7 @@ class JobList extends Component {
/>
</Card>
<AlertModal
isOpen={deletionError}
isOpen={hasDeletionError}
variant="danger"
title={i18n._(t`Error!`)}
onClose={this.handleDeleteErrorClose}

View File

@ -25,8 +25,8 @@ class AWXLogin extends Component {
this.state = {
username: '',
password: '',
authenticationError: false,
validationError: false,
hasAuthError: false,
hasValidationError: false,
isAuthenticating: false,
isLoading: true,
logo: null,
@ -66,16 +66,16 @@ class AWXLogin extends Component {
return;
}
this.setState({ authenticationError: false, isAuthenticating: true });
this.setState({ hasAuthError: false, isAuthenticating: true });
try {
// note: if authentication is successful, the appropriate cookie will be set automatically
// and isAuthenticated() (the source of truth) will start returning true.
await RootAPI.login(username, password);
} catch (err) {
if (err && err.response && err.response.status === 401) {
this.setState({ validationError: true });
this.setState({ hasValidationError: true });
} else {
this.setState({ authenticationError: true });
this.setState({ hasAuthError: true });
}
} finally {
this.setState({ isAuthenticating: false });
@ -83,17 +83,17 @@ class AWXLogin extends Component {
}
handleChangeUsername (value) {
this.setState({ username: value, validationError: false });
this.setState({ username: value, hasValidationError: false });
}
handleChangePassword (value) {
this.setState({ password: value, validationError: false });
this.setState({ password: value, hasValidationError: false });
}
render () {
const {
authenticationError,
validationError,
hasAuthError,
hasValidationError,
username,
password,
isLoading,
@ -115,7 +115,7 @@ class AWXLogin extends Component {
}
let helperText;
if (validationError) {
if (hasValidationError) {
helperText = i18n._(t`Invalid username or password. Please try again.`);
} else {
helperText = i18n._(t`There was a problem signing in. Please try again.`);
@ -129,15 +129,15 @@ class AWXLogin extends Component {
textContent={loginInfo}
>
<LoginForm
className={(authenticationError || validationError) ? 'pf-m-error' : ''}
className={(hasAuthError || hasValidationError) ? 'pf-m-error' : ''}
usernameLabel={i18n._(t`Username`)}
passwordLabel={i18n._(t`Password`)}
showHelperText={(authenticationError || validationError)}
showHelperText={(hasAuthError || hasValidationError)}
helperText={helperText}
usernameValue={username}
passwordValue={password}
isValidUsername={!validationError}
isValidPassword={!validationError}
isValidUsername={!hasValidationError}
isValidPassword={!hasValidationError}
onChangeUsername={this.handleChangeUsername}
onChangePassword={this.handleChangePassword}
onLoginButtonClick={this.handleLoginButtonClick}

View File

@ -60,7 +60,7 @@ describe('<Login />', () => {
} = await findChildren(loginWrapper);
expect(usernameInput.props().value).toBe('');
expect(passwordInput.props().value).toBe('');
expect(awxLogin.state('validationError')).toBe(false);
expect(awxLogin.state('hasValidationError')).toBe(false);
expect(submitButton.props().isDisabled).toBe(false);
done();
});
@ -126,14 +126,14 @@ describe('<Login />', () => {
submitButton.simulate('click');
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('username') === 'invalid');
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('password') === 'invalid');
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('validationError') === true);
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('hasValidationError') === true);
await waitForElement(loginWrapper, formError, (el) => el.length === 1);
usernameInput.props().onChange({ currentTarget: { value: 'dsarif' } });
passwordInput.props().onChange({ currentTarget: { value: 'freneticpny' } });
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('username') === 'dsarif');
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('password') === 'freneticpny');
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('validationError') === false);
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('hasValidationError') === false);
await waitForElement(loginWrapper, formError, (el) => el.length === 0);
done();
@ -151,16 +151,16 @@ describe('<Login />', () => {
RootAPI.login.mockRejectedValueOnce({ response: { status: 500 } });
submitButton.simulate('click');
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('authenticationError') === true);
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('hasAuthError') === true);
usernameInput.props().onChange({ currentTarget: { value: 'sgrimes' } });
passwordInput.props().onChange({ currentTarget: { value: 'ovid' } });
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('username') === 'sgrimes');
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('password') === 'ovid');
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('authenticationError') === true);
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('hasAuthError') === true);
submitButton.simulate('click');
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('authenticationError') === false);
await waitForElement(loginWrapper, 'AWXLogin', (el) => el.state('hasAuthError') === false);
done();
});