Commit 40374ff3 authored by Jacques Erasmus's avatar Jacques Erasmus

Merge branch 'fork-form-remove-auto-selected-visibility-level' into 'master'

Resets visibility level when namespace is changed

See merge request gitlab-org/gitlab!62306
parents 0bd06477 2cc24b3e
...@@ -111,9 +111,7 @@ export default { ...@@ -111,9 +111,7 @@ export default {
required: false, required: false,
skipValidation: true, skipValidation: true,
}), }),
visibility: initFormField({ visibility: initFormField({ value: this.projectVisibility }),
value: this.projectVisibility,
}),
}, },
}; };
return { return {
...@@ -165,12 +163,8 @@ export default { ...@@ -165,12 +163,8 @@ export default {
}, },
watch: { watch: {
// eslint-disable-next-line func-names // eslint-disable-next-line func-names
'form.fields.namespace.value': function (newVal) { 'form.fields.namespace.value': function () {
const { visibility } = newVal; this.form.fields.visibility.value = PRIVATE_VISIBILITY;
if (this.projectAllowedVisibility.includes(visibility)) {
this.form.fields.visibility.value = visibility;
}
}, },
// eslint-disable-next-line func-names // eslint-disable-next-line func-names
'form.fields.name.value': function (newVal) { 'form.fields.name.value': function (newVal) {
......
import { GlFormInputGroup, GlFormInput, GlForm, GlFormRadio } from '@gitlab/ui'; import { GlFormInputGroup, GlFormInput, GlForm, GlFormRadio, GlFormSelect } from '@gitlab/ui';
import { mount, shallowMount } from '@vue/test-utils'; import { mount, shallowMount } from '@vue/test-utils';
import axios from 'axios'; import axios from 'axios';
import AxiosMockAdapter from 'axios-mock-adapter'; import AxiosMockAdapter from 'axios-mock-adapter';
...@@ -89,6 +89,7 @@ describe('ForkForm component', () => { ...@@ -89,6 +89,7 @@ describe('ForkForm component', () => {
axiosMock.restore(); axiosMock.restore();
}); });
const findFormSelect = () => wrapper.find(GlFormSelect);
const findPrivateRadio = () => wrapper.find('[data-testid="radio-private"]'); const findPrivateRadio = () => wrapper.find('[data-testid="radio-private"]');
const findInternalRadio = () => wrapper.find('[data-testid="radio-internal"]'); const findInternalRadio = () => wrapper.find('[data-testid="radio-internal"]');
const findPublicRadio = () => wrapper.find('[data-testid="radio-public"]'); const findPublicRadio = () => wrapper.find('[data-testid="radio-public"]');
...@@ -229,6 +230,37 @@ describe('ForkForm component', () => { ...@@ -229,6 +230,37 @@ describe('ForkForm component', () => {
expect(wrapper.findAll(GlFormRadio)).toHaveLength(3); expect(wrapper.findAll(GlFormRadio)).toHaveLength(3);
}); });
it('resets the visibility to default "private" when the namespace is changed', async () => {
const namespaces = [
{
visibility: 'private',
},
{
visibility: 'internal',
},
{
visibility: 'public',
},
];
mockGetRequest();
createComponent(
{
projectVisibility: 'public',
},
{
namespaces,
},
);
expect(wrapper.vm.form.fields.visibility.value).toBe('public');
findFormSelect().vm.$emit('input', namespaces[1]);
await wrapper.vm.$nextTick();
expect(wrapper.vm.form.fields.visibility.value).toBe('private');
});
it.each` it.each`
project | namespace | privateIsDisabled | internalIsDisabled | publicIsDisabled project | namespace | privateIsDisabled | internalIsDisabled | publicIsDisabled
${'private'} | ${'private'} | ${undefined} | ${'true'} | ${'true'} ${'private'} | ${'private'} | ${undefined} | ${'true'} | ${'true'}
...@@ -324,7 +356,6 @@ describe('ForkForm component', () => { ...@@ -324,7 +356,6 @@ describe('ForkForm component', () => {
await submitForm(); await submitForm();
expect(wrapper.find('[name="visibility"]:checked').exists()).toBe(false);
expect(axios.post).not.toHaveBeenCalled(); expect(axios.post).not.toHaveBeenCalled();
}); });
}); });
......
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