refactor: 💡 refactor LDAP form error messaging (#1816)

* refactor: 💡 refactor form error messaging

Refactor LDAP form.  Removed unused field level errors that aren't part
of the API response.

✅ Closes: ICU-10462

* refactor: 💡 Refactor test

Refactor LDAP create and update test.

* Update index.hbs

removed error field-level check for `bind_dn` and `bind_password`

* refactor: 💡 fix linting

fix linting
This commit is contained in:
Devon Anderson authored and GitHub committed 2023-08-04 19:30:41 -04:00
1 parent 18833c9f22
commit de77f8807d
3 files changed
+14 -88

No files matched your search

@@ -25,7 +25,6 @@
<Hds::Form::TextInput::Field
@isOptional={{true}}
@value={{@model.name}}
@isInvalid={{@model.errors.name}}
@type='text'
name='name'
disabled={{form.disabled}}
@@ -34,32 +33,17 @@
>
<F.Label>{{t 'form.name.label'}}</F.Label>
<F.HelperText>{{t 'form.name.help'}}</F.HelperText>
{{#if @model.errors.name}}
<F.Error as |E|>
{{#each @model.errors.name as |error|}}
<E.Message>{{error.message}}</E.Message>
{{/each}}
</F.Error>
{{/if}}
</Hds::Form::TextInput::Field>
<Hds::Form::Textarea::Field
@isOptional={{true}}
@value={{@model.description}}
@isInvalid={{@model.errors.description}}
name='description'
disabled={{form.disabled}}
as |F|
>
<F.Label>{{t 'form.description.label'}}</F.Label>
<F.HelperText>{{t 'form.description.help'}}</F.HelperText>
{{#if @model.errors.description}}
<F.Error as |E|>
{{#each @model.errors.description as |error|}}
<E.Message>{{error.message}}</E.Message>
{{/each}}
</F.Error>
{{/if}}
</Hds::Form::Textarea::Field>
<div class='ldap-section'>
@@ -276,7 +260,6 @@
<Hds::Form::TextInput::Field
@isOptional={{true}}
@value={{@model.bind_dn}}
@isInvalid={{@model.errors.bind_dn}}
@type='text'
name='bind_dn'
disabled={{form.disabled}}
@@ -285,20 +268,12 @@
>
<F.Label>{{t 'resources.auth-method.form.bind_dn.label'}}</F.Label>
<F.HelperText>{{t 'resources.auth-method.form.bind_dn.help'}}</F.HelperText>
{{#if @model.errors.bind_dn}}
<F.Error as |E|>
{{#each @model.errors.bind_dn as |error|}}
<E.Message>{{error.message}}</E.Message>
{{/each}}
</F.Error>
{{/if}}
</Hds::Form::TextInput::Field>
{{#if @model.isNew}}
<Hds::Form::TextInput::Field
@isOptional={{true}}
@value={{@model.bind_password}}
@isInvalid={{@model.errors.bind_password}}
@type='password'
name='bind_password'
disabled={{form.disabled}}
@@ -309,13 +284,6 @@
<F.HelperText>
{{t 'resources.auth-method.form.bind_password.help'}}
</F.HelperText>
{{#if @model.errors.bind_password}}
<F.Error as |E|>
{{#each @model.errors.bind_password as |error|}}
<E.Message>{{error.message}}</E.Message>
{{/each}}
</F.Error>
{{/if}}
</Hds::Form::TextInput::Field>
{{else}}
<Form::Field::SecretInput
@@ -346,7 +314,6 @@
<Hds::Form::TextInput::Field
@isOptional={{true}}
@value={{@model.upn_domain}}
@isInvalid={{@model.errors.upn_domain}}
@type='text'
name='upn_domain'
disabled={{form.disabled}}
@@ -357,13 +324,6 @@
<F.HelperText>{{t
'resources.auth-method.form.upn_domain.help'
}}</F.HelperText>
{{#if @model.errors.upn_domain}}
<F.Error as |E|>
{{#each @model.errors.upn_domain as |error|}}
<E.Message>{{error.message}}</E.Message>
{{/each}}
</F.Error>
{{/if}}
</Hds::Form::TextInput::Field>
<div class='ldap-section'>
@@ -415,7 +375,6 @@
<Hds::Form::TextInput::Field
@isOptional={{true}}
@value={{@model.user_dn}}
@isInvalid={{@model.errors.user_dn}}
@type='text'
name='user_dn'
disabled={{form.disabled}}
@@ -424,19 +383,11 @@
>
<F.Label>{{t 'resources.auth-method.form.user_dn.label'}}</F.Label>
<F.HelperText>{{t 'resources.auth-method.form.user_dn.help'}}</F.HelperText>
{{#if @model.errors.user_dn}}
<F.Error as |E|>
{{#each @model.errors.user_dn as |error|}}
<E.Message>{{error.message}}</E.Message>
{{/each}}
</F.Error>
{{/if}}
</Hds::Form::TextInput::Field>
<Hds::Form::TextInput::Field
@isOptional={{true}}
@value={{@model.user_attr}}
@isInvalid={{@model.errors.user_attr}}
@type='text'
name='user_attr'
disabled={{form.disabled}}
@@ -447,19 +398,11 @@
<F.HelperText>{{t
'resources.auth-method.form.user_attr.help'
}}</F.HelperText>
{{#if @model.errors.user_attr}}
<F.Error as |E|>
{{#each @model.errors.user_attr as |error|}}
<E.Message>{{error.message}}</E.Message>
{{/each}}
</F.Error>
{{/if}}
</Hds::Form::TextInput::Field>
<Hds::Form::TextInput::Field
@isOptional={{true}}
@value={{@model.user_filter}}
@isInvalid={{@model.errors.user_filter}}
@type='text'
name='user_filter'
disabled={{form.disabled}}
@@ -470,13 +413,6 @@
<F.HelperText>{{t
'resources.auth-method.form.user_filter.help'
}}</F.HelperText>
{{#if @model.errors.user_filter}}
<F.Error as |E|>
{{#each @model.errors.user_filter as |error|}}
<E.Message>{{error.message}}</E.Message>
{{/each}}
</F.Error>
{{/if}}
</Hds::Form::TextInput::Field>
<Hds::Form::Fieldset @isOptional={{true}} as |F|>
@@ -633,7 +569,6 @@
<Hds::Form::TextInput::Field
@isOptional={{true}}
@value={{@model.group_attr}}
@isInvalid={{@model.errors.group_attr}}
@type='text'
name='group_attr'
disabled={{form.disabled}}
@@ -644,19 +579,11 @@
<F.HelperText>{{t
'resources.auth-method.form.group_attr.help'
}}</F.HelperText>
{{#if @model.errors.group_attr}}
<F.Error as |E|>
{{#each @model.errors.group_attr as |error|}}
<E.Message>{{error.message}}</E.Message>
{{/each}}
</F.Error>
{{/if}}
</Hds::Form::TextInput::Field>
<Hds::Form::TextInput::Field
@isOptional={{true}}
@value={{@model.group_filter}}
@isInvalid={{@model.errors.group_filter}}
@type='text'
name='group_filter'
disabled={{form.disabled}}
@@ -667,13 +594,6 @@
<F.HelperText>{{t
'resources.auth-method.form.group_filter.help'
}}</F.HelperText>
{{#if @model.errors.group_filter}}
<F.Error as |E|>
{{#each @model.errors.group_filter as |error|}}
<E.Message>{{error.message}}</E.Message>
{{/each}}
</F.Error>
{{/if}}
</Hds::Form::TextInput::Field>
<Hds::Form::Toggle::Field
@@ -26,6 +26,7 @@ module('Acceptance | auth-methods | create', function (hooks) {
const SAVE_BTN_SELECTOR = '.rose-form-actions [type="submit"]';
const CANCEL_BTN_SELECTOR = '.rose-form-actions [type="button"]';
const NAME_INPUT_SELECTOR = '[name="name"]';
const URLS_INPUT_SELECTOR = '[name="urls"]';
const DESC_INPUT_SELECTOR = '[name="description"]';
const MAKE_PRIMARY_SELECTOR =
'.rose-layout-page-actions .rose-dropdown-content [type="button"]:first-child';
@@ -423,8 +424,8 @@ module('Acceptance | auth-methods | create', function (hooks) {
details: {
request_fields: [
{
name: 'name',
description: 'Name is required.',
name: 'urls',
description: 'At least one URL is required.',
},
],
},
@@ -435,10 +436,12 @@ module('Acceptance | auth-methods | create', function (hooks) {
await click(NEW_DROPDOWN_SELECTOR);
await click(`[href="${urls.newLdapAuthMethod}"]`);
await fillIn(NAME_INPUT_SELECTOR, 'new account');
await fillIn(URLS_INPUT_SELECTOR, '');
await click(SAVE_BTN_SELECTOR);
assert.dom(ERROR_MSG_SELECTOR).hasText('The request was invalid.');
assert.dom(FIELD_ERROR_TEXT_SELECTOR).hasText('Name is required.');
assert
.dom(FIELD_ERROR_TEXT_SELECTOR)
.hasText('At least one URL is required.');
});
});
@@ -29,6 +29,7 @@ module('Acceptance | auth methods | update', function (hooks) {
const BUTTON_SELECTOR = '.rose-form-actions [type="button"]';
const SAVE_BTN_SELECTOR = '.rose-form-actions [type="submit"]';
const NAME_INPUT_SELECTOR = '[name="name"]';
const URLS_INPUT_SELECTOR = '[name="urls"]';
const DESC_INPUT_SELECTOR = '[name="description"]';
const ERROR_MSG_SELECTOR = '.rose-notification-body';
const FIELD_ERROR_TEXT_SELECTOR = '.hds-form-error__message';
@@ -338,8 +339,8 @@ module('Acceptance | auth methods | update', function (hooks) {
details: {
request_fields: [
{
name: 'name',
description: 'Name is required.',
name: 'urls',
description: 'scheme in url "" is not either ldap or ldaps',
},
],
},
@@ -350,10 +351,12 @@ module('Acceptance | auth methods | update', function (hooks) {
await click(`[href="${urls.ldapAuthMethod}"]`);
await click(BUTTON_SELECTOR, 'Activate edit mode');
await fillIn(NAME_INPUT_SELECTOR, 'existing auth method');
await fillIn(URLS_INPUT_SELECTOR, '');
await click(SAVE_BTN_SELECTOR);
await a11yAudit();
assert.dom(ERROR_MSG_SELECTOR).hasText('The request was invalid.');
assert.dom(FIELD_ERROR_TEXT_SELECTOR).hasText('Name is required.');
assert
.dom(FIELD_ERROR_TEXT_SELECTOR)
.hasText('scheme in url "" is not either ldap or ldaps');
});
});