Commit 4abb1f05 authored by Alexander Turinske's avatar Alexander Turinske

Wrap disabled form groups in a disabled parent

- instead of disabling form groups individually,
  this wraps them in a parent form group and
  conditionally disables that.
- update tests
parent 998b460e
...@@ -274,7 +274,8 @@ export default { ...@@ -274,7 +274,8 @@ export default {
</ul> </ul>
</gl-alert> </gl-alert>
<gl-form-group :disabled="isPolicyProfile" :label="s__('DastProfiles|Profile name')"> <gl-form-group data-testid="dast-scanner-parent-group" :disabled="isPolicyProfile">
<gl-form-group :label="s__('DastProfiles|Profile name')">
<gl-form-input <gl-form-input
v-model="form.profileName.value" v-model="form.profileName.value"
class="mw-460" class="mw-460"
...@@ -285,7 +286,7 @@ export default { ...@@ -285,7 +286,7 @@ export default {
<hr class="gl-border-gray-100" /> <hr class="gl-border-gray-100" />
<gl-form-group :disabled="isPolicyProfile"> <gl-form-group>
<template #label> <template #label>
{{ s__('DastProfiles|Scan mode') }} {{ s__('DastProfiles|Scan mode') }}
<tooltip-icon :title="i18n.tooltips.scanMode" /> <tooltip-icon :title="i18n.tooltips.scanMode" />
...@@ -301,7 +302,6 @@ export default { ...@@ -301,7 +302,6 @@ export default {
<div class="row"> <div class="row">
<gl-form-group <gl-form-group
class="col-md-6 mb-0" class="col-md-6 mb-0"
:disabled="isPolicyProfile"
:state="form.spiderTimeout.state" :state="form.spiderTimeout.state"
:invalid-feedback="form.spiderTimeout.feedback" :invalid-feedback="form.spiderTimeout.feedback"
> >
...@@ -329,7 +329,6 @@ export default { ...@@ -329,7 +329,6 @@ export default {
<gl-form-group <gl-form-group
class="col-md-6 mb-0" class="col-md-6 mb-0"
:disabled="isPolicyProfile"
:state="form.targetTimeout.state" :state="form.targetTimeout.state"
:invalid-feedback="form.targetTimeout.feedback" :invalid-feedback="form.targetTimeout.feedback"
> >
...@@ -359,7 +358,7 @@ export default { ...@@ -359,7 +358,7 @@ export default {
<hr class="gl-border-gray-100" /> <hr class="gl-border-gray-100" />
<div class="row"> <div class="row">
<gl-form-group class="col-md-6 mb-0" :disabled="isPolicyProfile"> <gl-form-group class="col-md-6 mb-0">
<template #label> <template #label>
{{ s__('DastProfiles|AJAX spider') }} {{ s__('DastProfiles|AJAX spider') }}
<tooltip-icon :title="i18n.tooltips.ajaxSpider" /> <tooltip-icon :title="i18n.tooltips.ajaxSpider" />
...@@ -369,7 +368,7 @@ export default { ...@@ -369,7 +368,7 @@ export default {
}}</gl-form-checkbox> }}</gl-form-checkbox>
</gl-form-group> </gl-form-group>
<gl-form-group class="col-md-6 mb-0" :disabled="isPolicyProfile"> <gl-form-group class="col-md-6 mb-0">
<template #label> <template #label>
{{ s__('DastProfiles|Debug messages') }} {{ s__('DastProfiles|Debug messages') }}
<tooltip-icon :title="i18n.tooltips.debugMessage" /> <tooltip-icon :title="i18n.tooltips.debugMessage" />
...@@ -379,6 +378,7 @@ export default { ...@@ -379,6 +378,7 @@ export default {
}}</gl-form-checkbox> }}</gl-form-checkbox>
</gl-form-group> </gl-form-group>
</div> </div>
</gl-form-group>
<hr class="gl-border-gray-100" /> <hr class="gl-border-gray-100" />
......
...@@ -82,7 +82,8 @@ export default { ...@@ -82,7 +82,8 @@ export default {
<template> <template>
<section> <section>
<gl-form-group :disabled="disabled" :label="s__('DastProfiles|Authentication')"> <gl-form-group data-testid="dast-site-auth-parent-group" :disabled="disabled">
<gl-form-group :label="s__('DastProfiles|Authentication')">
<gl-form-checkbox v-model="form.fields.enabled.value" data-testid="auth-enable-checkbox">{{ <gl-form-checkbox v-model="form.fields.enabled.value" data-testid="auth-enable-checkbox">{{
s__('DastProfiles|Enable Authentication') s__('DastProfiles|Enable Authentication')
}}</gl-form-checkbox> }}</gl-form-checkbox>
...@@ -90,7 +91,6 @@ export default { ...@@ -90,7 +91,6 @@ export default {
<div v-if="form.fields.enabled.value" data-testid="auth-form"> <div v-if="form.fields.enabled.value" data-testid="auth-form">
<div class="row"> <div class="row">
<gl-form-group <gl-form-group
:disabled="disabled"
:label="s__('DastProfiles|Authentication URL')" :label="s__('DastProfiles|Authentication URL')"
:invalid-feedback="form.fields.url.feedback" :invalid-feedback="form.fields.url.feedback"
class="col-md-6" class="col-md-6"
...@@ -107,7 +107,6 @@ export default { ...@@ -107,7 +107,6 @@ export default {
</div> </div>
<div class="row"> <div class="row">
<gl-form-group <gl-form-group
:disabled="disabled"
:label="s__('DastProfiles|Username')" :label="s__('DastProfiles|Username')"
:invalid-feedback="form.fields.username.feedback" :invalid-feedback="form.fields.username.feedback"
class="col-md-6" class="col-md-6"
...@@ -123,7 +122,6 @@ export default { ...@@ -123,7 +122,6 @@ export default {
/> />
</gl-form-group> </gl-form-group>
<gl-form-group <gl-form-group
:disabled="disabled"
:label="s__('DastProfiles|Password')" :label="s__('DastProfiles|Password')"
:invalid-feedback="form.fields.password.feedback" :invalid-feedback="form.fields.password.feedback"
class="col-md-6" class="col-md-6"
...@@ -142,7 +140,6 @@ export default { ...@@ -142,7 +140,6 @@ export default {
</div> </div>
<div class="row"> <div class="row">
<gl-form-group <gl-form-group
:disabled="disabled"
:label="s__('DastProfiles|Username form field')" :label="s__('DastProfiles|Username form field')"
:invalid-feedback="form.fields.usernameField.feedback" :invalid-feedback="form.fields.usernameField.feedback"
class="col-md-6" class="col-md-6"
...@@ -157,7 +154,6 @@ export default { ...@@ -157,7 +154,6 @@ export default {
/> />
</gl-form-group> </gl-form-group>
<gl-form-group <gl-form-group
:disabled="disabled"
:label="s__('DastProfiles|Password form field')" :label="s__('DastProfiles|Password form field')"
:invalid-feedback="form.fields.passwordField.feedback" :invalid-feedback="form.fields.passwordField.feedback"
class="col-md-6" class="col-md-6"
...@@ -173,5 +169,6 @@ export default { ...@@ -173,5 +169,6 @@ export default {
</gl-form-group> </gl-form-group>
</div> </div>
</div> </div>
</gl-form-group>
</section> </section>
</template> </template>
...@@ -274,8 +274,8 @@ export default { ...@@ -274,8 +274,8 @@ export default {
</ul> </ul>
</gl-alert> </gl-alert>
<gl-form-group data-testid="dast-site-parent-group" :disabled="isPolicyProfile">
<gl-form-group <gl-form-group
:disabled="isPolicyProfile"
:label="s__('DastProfiles|Profile name')" :label="s__('DastProfiles|Profile name')"
:invalid-feedback="form.fields.profileName.feedback" :invalid-feedback="form.fields.profileName.feedback"
> >
...@@ -294,7 +294,6 @@ export default { ...@@ -294,7 +294,6 @@ export default {
<hr class="gl-border-gray-100" /> <hr class="gl-border-gray-100" />
<gl-form-group <gl-form-group
:disabled="isPolicyProfile"
data-testid="target-url-input-group" data-testid="target-url-input-group"
:invalid-feedback="form.fields.targetUrl.feedback" :invalid-feedback="form.fields.targetUrl.feedback"
:label="s__('DastProfiles|Target URL')" :label="s__('DastProfiles|Target URL')"
...@@ -313,7 +312,6 @@ export default { ...@@ -313,7 +312,6 @@ export default {
<div v-if="glFeatures.securityDastSiteProfilesAdditionalFields" class="row"> <div v-if="glFeatures.securityDastSiteProfilesAdditionalFields" class="row">
<gl-form-group <gl-form-group
:disabled="isPolicyProfile"
:label="s__('DastProfiles|Excluded URLs (Optional)')" :label="s__('DastProfiles|Excluded URLs (Optional)')"
:invalid-feedback="form.fields.excludedUrls.feedback" :invalid-feedback="form.fields.excludedUrls.feedback"
class="col-md-6" class="col-md-6"
...@@ -338,11 +336,7 @@ export default { ...@@ -338,11 +336,7 @@ export default {
}}</gl-form-text> }}</gl-form-text>
</gl-form-group> </gl-form-group>
<gl-form-group <gl-form-group :invalid-feedback="form.fields.requestHeaders.feedback" class="col-md-6">
:disabled="isPolicyProfile"
:invalid-feedback="form.fields.requestHeaders.feedback"
class="col-md-6"
>
<template #label> <template #label>
{{ i18n.requestHeaders.label }} {{ i18n.requestHeaders.label }}
<tooltip-icon :title="i18n.requestHeaders.tooltip" /> <tooltip-icon :title="i18n.requestHeaders.tooltip" />
...@@ -363,6 +357,7 @@ export default { ...@@ -363,6 +357,7 @@ export default {
}}</gl-form-text> }}</gl-form-text>
</gl-form-group> </gl-form-group>
</div> </div>
</gl-form-group>
<dast-site-auth-section <dast-site-auth-section
v-if="glFeatures.securityDastSiteProfilesAdditionalFields" v-if="glFeatures.securityDastSiteProfilesAdditionalFields"
......
import { GlForm, GlFormGroup, GlModal } from '@gitlab/ui'; import { GlForm, GlModal } from '@gitlab/ui';
import { within } from '@testing-library/dom'; import { within } from '@testing-library/dom';
import { mount, shallowMount } from '@vue/test-utils'; import { mount, shallowMount } from '@vue/test-utils';
import merge from 'lodash/merge'; import merge from 'lodash/merge';
...@@ -40,7 +40,7 @@ describe('DAST Scanner Profile', () => { ...@@ -40,7 +40,7 @@ describe('DAST Scanner Profile', () => {
const withinComponent = () => within(wrapper.element); const withinComponent = () => within(wrapper.element);
const findByTestId = (testId) => wrapper.find(`[data-testid="${testId}"`); const findByTestId = (testId) => wrapper.find(`[data-testid="${testId}"`);
const findAllFormGroups = () => wrapper.findAllComponents(GlFormGroup); const findParentFormGroup = () => findByTestId('dast-scanner-parent-group');
const findForm = () => wrapper.find(GlForm); const findForm = () => wrapper.find(GlForm);
const findProfileNameInput = () => findByTestId('profile-name-input'); const findProfileNameInput = () => findByTestId('profile-name-input');
const findSpiderTimeoutInput = () => findByTestId('spider-timeout-input'); const findSpiderTimeoutInput = () => findByTestId('spider-timeout-input');
...@@ -294,9 +294,7 @@ describe('DAST Scanner Profile', () => { ...@@ -294,9 +294,7 @@ describe('DAST Scanner Profile', () => {
}); });
it('should enable all form groups', () => { it('should enable all form groups', () => {
expect( expect(findParentFormGroup().attributes('disabled')).toBe(undefined);
findAllFormGroups().wrappers.every((w) => w.attributes('disabled') === undefined),
).toBe(true);
}); });
it('should show the policy profile alert', () => { it('should show the policy profile alert', () => {
...@@ -318,9 +316,7 @@ describe('DAST Scanner Profile', () => { ...@@ -318,9 +316,7 @@ describe('DAST Scanner Profile', () => {
}); });
it('should disable all form groups', () => { it('should disable all form groups', () => {
expect(findAllFormGroups().wrappers.every((w) => w.attributes('disabled') === 'true')).toBe( expect(findParentFormGroup().attributes('disabled')).toBe('true');
true,
);
}); });
it('should disable the save button', () => { it('should disable the save button', () => {
......
import { GlFormCheckbox, GlFormGroup } from '@gitlab/ui'; import { GlFormCheckbox } from '@gitlab/ui';
import { mount, shallowMount } from '@vue/test-utils'; import { mount, shallowMount } from '@vue/test-utils';
import DastSiteAuthSection from 'ee/security_configuration/dast_site_profiles_form/components/dast_site_auth_section.vue'; import DastSiteAuthSection from 'ee/security_configuration/dast_site_profiles_form/components/dast_site_auth_section.vue';
import { extendedWrapper } from 'helpers/vue_test_utils_helper'; import { extendedWrapper } from 'helpers/vue_test_utils_helper';
...@@ -25,7 +25,7 @@ describe('DastSiteAuthSection', () => { ...@@ -25,7 +25,7 @@ describe('DastSiteAuthSection', () => {
wrapper.destroy(); wrapper.destroy();
}); });
const findAllFormGroups = () => wrapper.findAllComponents(GlFormGroup); const findParentFormGroup = () => wrapper.findByTestId('dast-site-auth-parent-group');
const findByNameAttribute = (name) => wrapper.find(`[name="${name}"]`); const findByNameAttribute = (name) => wrapper.find(`[name="${name}"]`);
const findAuthForm = () => wrapper.findByTestId('auth-form'); const findAuthForm = () => wrapper.findByTestId('auth-form');
const findAuthCheckbox = () => wrapper.find(GlFormCheckbox); const findAuthCheckbox = () => wrapper.find(GlFormCheckbox);
...@@ -121,18 +121,14 @@ describe('DastSiteAuthSection', () => { ...@@ -121,18 +121,14 @@ describe('DastSiteAuthSection', () => {
describe('when profile does not come from a policy', () => { describe('when profile does not come from a policy', () => {
it('should enable all form groups', () => { it('should enable all form groups', () => {
createComponent({ mountFn: shallowMount, fields: { enabled: true } }); createComponent({ mountFn: shallowMount, fields: { enabled: true } });
expect( expect(findParentFormGroup().attributes('disabled')).toBe(undefined);
findAllFormGroups().wrappers.every((w) => w.attributes('disabled') === undefined),
).toBe(true);
}); });
}); });
describe('when profile does comes from a policy', () => { describe('when profile does comes from a policy', () => {
it('should disable all form groups', () => { it('should disable all form groups', () => {
createComponent({ mountFn: shallowMount, disabled: true, fields: { enabled: true } }); createComponent({ mountFn: shallowMount, disabled: true, fields: { enabled: true } });
expect(findAllFormGroups().wrappers.every((w) => w.attributes('disabled') === 'true')).toBe( expect(findParentFormGroup().attributes('disabled')).toBe('true');
true,
);
}); });
}); });
}); });
......
import { GlForm, GlFormGroup, GlModal } from '@gitlab/ui'; import { GlForm, GlModal } from '@gitlab/ui';
import { within } from '@testing-library/dom'; import { within } from '@testing-library/dom';
import { createLocalVue, mount, shallowMount } from '@vue/test-utils'; import { createLocalVue, mount, shallowMount } from '@vue/test-utils';
import merge from 'lodash/merge'; import merge from 'lodash/merge';
...@@ -46,7 +46,7 @@ describe('DastSiteProfileForm', () => { ...@@ -46,7 +46,7 @@ describe('DastSiteProfileForm', () => {
const withinComponent = () => within(wrapper.element); const withinComponent = () => within(wrapper.element);
const findForm = () => wrapper.findComponent(GlForm); const findForm = () => wrapper.findComponent(GlForm);
const findAllFormGroups = () => wrapper.findAllComponents(GlFormGroup); const findParentFormGroup = () => wrapper.findByTestId('dast-site-parent-group');
const findAuthSection = () => wrapper.findComponent(DastSiteAuthSection); const findAuthSection = () => wrapper.findComponent(DastSiteAuthSection);
const findCancelModal = () => wrapper.findComponent(GlModal); const findCancelModal = () => wrapper.findComponent(GlModal);
const findByNameAttribute = (name) => wrapper.find(`[name="${name}"]`); const findByNameAttribute = (name) => wrapper.find(`[name="${name}"]`);
...@@ -346,9 +346,7 @@ describe('DastSiteProfileForm', () => { ...@@ -346,9 +346,7 @@ describe('DastSiteProfileForm', () => {
}); });
it('should enable all form groups', () => { it('should enable all form groups', () => {
expect( expect(findParentFormGroup().attributes('disabled')).toBe(undefined);
findAllFormGroups().wrappers.every((w) => w.attributes('disabled') === undefined),
).toBe(true);
}); });
it('should show the policy profile alert', () => { it('should show the policy profile alert', () => {
...@@ -370,9 +368,7 @@ describe('DastSiteProfileForm', () => { ...@@ -370,9 +368,7 @@ describe('DastSiteProfileForm', () => {
}); });
it('should disable all form groups', () => { it('should disable all form groups', () => {
expect(findAllFormGroups().wrappers.every((w) => w.attributes('disabled') === 'true')).toBe( expect(findParentFormGroup().attributes('disabled')).toBe('true');
true,
);
}); });
it('should disable the save button', () => { it('should disable the save button', () => {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment