mirror of
https://github.com/ansible/awx.git
synced 2026-03-25 04:45:03 -02:30
Merge pull request #8468 from nixocio/ui_issue_8453
Fix username as a required field Reviewed-by: https://github.com/apps/softwarefactory-project-zuul
This commit is contained in:
@@ -68,11 +68,9 @@ function UserFormFields({ user, i18n }) {
|
|||||||
name="username"
|
name="username"
|
||||||
type="text"
|
type="text"
|
||||||
validate={
|
validate={
|
||||||
!ldapUser && externalAccount === null
|
!ldapUser && !externalAccount ? required(null, i18n) : () => undefined
|
||||||
? required(null, i18n)
|
|
||||||
: () => undefined
|
|
||||||
}
|
}
|
||||||
isRequired={!ldapUser && externalAccount === null}
|
isRequired={!ldapUser && !externalAccount}
|
||||||
/>
|
/>
|
||||||
<FormField
|
<FormField
|
||||||
id="user-email"
|
id="user-email"
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ describe('<UserForm />', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
test('password fields are required on add', async () => {
|
test('fields required on add', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
wrapper = mountWithContexts(
|
wrapper = mountWithContexts(
|
||||||
<UserForm handleSubmit={jest.fn()} handleCancel={jest.fn()} />
|
<UserForm handleSubmit={jest.fn()} handleCancel={jest.fn()} />
|
||||||
@@ -105,6 +105,26 @@ describe('<UserForm />', () => {
|
|||||||
expect(passwordFields.length).toBe(2);
|
expect(passwordFields.length).toBe(2);
|
||||||
expect(passwordFields.at(0).prop('isRequired')).toBe(true);
|
expect(passwordFields.at(0).prop('isRequired')).toBe(true);
|
||||||
expect(passwordFields.at(1).prop('isRequired')).toBe(true);
|
expect(passwordFields.at(1).prop('isRequired')).toBe(true);
|
||||||
|
|
||||||
|
expect(wrapper.find('FormField[label="Username"]').prop('isRequired')).toBe(
|
||||||
|
true
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('username field is required on edit', async () => {
|
||||||
|
await act(async () => {
|
||||||
|
wrapper = mountWithContexts(
|
||||||
|
<UserForm
|
||||||
|
user={{ ...mockData, external_account: '', auth: [] }}
|
||||||
|
handleSubmit={jest.fn()}
|
||||||
|
handleCancel={jest.fn()}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(wrapper.find('FormField[label="Username"]').prop('isRequired')).toBe(
|
||||||
|
true
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('password fields are not required on edit', async () => {
|
test('password fields are not required on edit', async () => {
|
||||||
@@ -125,6 +145,40 @@ describe('<UserForm />', () => {
|
|||||||
expect(passwordFields.at(1).prop('isRequired')).toBe(false);
|
expect(passwordFields.at(1).prop('isRequired')).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('username should not be required for external accounts', async () => {
|
||||||
|
await act(async () => {
|
||||||
|
wrapper = mountWithContexts(
|
||||||
|
<UserForm
|
||||||
|
user={mockData}
|
||||||
|
handleSubmit={jest.fn()}
|
||||||
|
handleCancel={jest.fn()}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
expect(wrapper.find('FormField[label="Username"]').prop('isRequired')).toBe(
|
||||||
|
false
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('username should not be required for ldap accounts', async () => {
|
||||||
|
await act(async () => {
|
||||||
|
wrapper = mountWithContexts(
|
||||||
|
<UserForm
|
||||||
|
user={{
|
||||||
|
...mockData,
|
||||||
|
ldap_dn:
|
||||||
|
'uid=binduser,cn=users,cn=accounts,dc=lan,dc=example,dc=com',
|
||||||
|
}}
|
||||||
|
handleSubmit={jest.fn()}
|
||||||
|
handleCancel={jest.fn()}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
});
|
||||||
|
expect(wrapper.find('FormField[label="Username"]').prop('isRequired')).toBe(
|
||||||
|
false
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test('password fields are not displayed for social/ldap login', async () => {
|
test('password fields are not displayed for social/ldap login', async () => {
|
||||||
await act(async () => {
|
await act(async () => {
|
||||||
wrapper = mountWithContexts(
|
wrapper = mountWithContexts(
|
||||||
|
|||||||
Reference in New Issue
Block a user