Commit ecc72d69 authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '327638-fix-status-checks-resubmission-on-server-validation-errors' into 'master'

Fix status checks resubmission on server validation errors bug

See merge request gitlab-org/gitlab!62705
parents 50dadc62 d3043c4e
...@@ -49,23 +49,30 @@ export default { ...@@ -49,23 +49,30 @@ export default {
}, },
computed: { computed: {
isValid() { isValid() {
return this.nameState && this.urlState && this.branchesState; return this.isValidName && this.isValidUrl && this.isValidBranches;
},
isValidBranches() {
return this.branches.every((branch) => isEqual(branch, ANY_BRANCH) || isNumber(branch?.id));
},
isValidName() {
return Boolean(this.name);
},
isValidUrl() {
return Boolean(this.url) && isSafeURL(this.url);
}, },
branchesState() { branchesState() {
return !this.showValidation || this.checkBranchesValidity(this.branches); return !this.showValidation || this.isValidBranches;
}, },
nameState() { nameState() {
return ( return (
!this.showValidation || !this.showValidation ||
(this.checkNameValidity(this.name) && (this.isValidName && !this.serverValidationErrors.includes(NAME_TAKEN_SERVER_ERROR))
!this.serverValidationErrors.includes(NAME_TAKEN_SERVER_ERROR))
); );
}, },
urlState() { urlState() {
return ( return (
!this.showValidation || !this.showValidation ||
(this.checkUrlValidity(this.url) && (this.isValidUrl && !this.serverValidationErrors.includes(URL_TAKEN_SERVER_ERROR))
!this.serverValidationErrors.includes(URL_TAKEN_SERVER_ERROR))
); );
}, },
invalidNameMessage() { invalidNameMessage() {
...@@ -105,15 +112,6 @@ export default { ...@@ -105,15 +112,6 @@ export default {
this.branchesApiFailed = hasErrored; this.branchesApiFailed = hasErrored;
}, },
checkBranchesValidity(branches) {
return branches.every((branch) => isEqual(branch, ANY_BRANCH) || isNumber(branch?.id));
},
checkNameValidity(name) {
return Boolean(name);
},
checkUrlValidity(url) {
return Boolean(url) && isSafeURL(url);
},
}, },
i18n: { i18n: {
form: { form: {
......
...@@ -109,11 +109,19 @@ describe('Status checks form', () => { ...@@ -109,11 +109,19 @@ describe('Status checks form', () => {
it('shows the serverValidationErrors if given', async () => { it('shows the serverValidationErrors if given', async () => {
createWrapper({ createWrapper({
serverValidationErrors: [NAME_TAKEN_SERVER_ERROR, URL_TAKEN_SERVER_ERROR], serverValidationErrors: [NAME_TAKEN_SERVER_ERROR, URL_TAKEN_SERVER_ERROR],
statusCheck,
}); });
await findForm().trigger('submit'); await findForm().trigger('submit');
expect(wrapper.emitted('submit')).toBe(undefined); expect(wrapper.emitted('submit')).toContainEqual([
{
branches: statusCheck.protectedBranches,
name: statusCheck.name,
url: statusCheck.externalUrl,
},
]);
expect(inputsAreValid()).toBe(false); expect(inputsAreValid()).toBe(false);
expect(findNameValidation().props('invalidFeedback')).toBe('Name is already taken.'); expect(findNameValidation().props('invalidFeedback')).toBe('Name is already taken.');
expect(findUrlValidation().props('invalidFeedback')).toBe( expect(findUrlValidation().props('invalidFeedback')).toBe(
......
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