diff --git a/awx/ui_next/src/screens/User/shared/UserForm.jsx b/awx/ui_next/src/screens/User/shared/UserForm.jsx index dbadf2d17a..7d65e7369f 100644 --- a/awx/ui_next/src/screens/User/shared/UserForm.jsx +++ b/awx/ui_next/src/screens/User/shared/UserForm.jsx @@ -68,11 +68,9 @@ function UserFormFields({ user, i18n }) { name="username" type="text" validate={ - !ldapUser && externalAccount === null - ? required(null, i18n) - : () => undefined + !ldapUser && !externalAccount ? required(null, i18n) : () => undefined } - isRequired={!ldapUser && externalAccount === null} + isRequired={!ldapUser && !externalAccount} /> ', () => { }); }); - test('password fields are required on add', async () => { + test('fields required on add', async () => { await act(async () => { wrapper = mountWithContexts( @@ -105,6 +105,26 @@ describe('', () => { expect(passwordFields.length).toBe(2); expect(passwordFields.at(0).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( + + ); + }); + + expect(wrapper.find('FormField[label="Username"]').prop('isRequired')).toBe( + true + ); }); test('password fields are not required on edit', async () => { @@ -125,6 +145,40 @@ describe('', () => { expect(passwordFields.at(1).prop('isRequired')).toBe(false); }); + test('username should not be required for external accounts', async () => { + await act(async () => { + wrapper = mountWithContexts( + + ); + }); + 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( + + ); + }); + expect(wrapper.find('FormField[label="Username"]').prop('isRequired')).toBe( + false + ); + }); + test('password fields are not displayed for social/ldap login', async () => { await act(async () => { wrapper = mountWithContexts(