Commit d3043c4e authored by Robert Hunt's avatar Robert Hunt Committed by Jiaan Louw

Fixes a bug where server errors were blocking the form submission

Separates out the state of the input and whether the value of the input
is deemed valid. This allows the form to be resubmitted and if the
server errors are resolved, process the form
parent 7f30efce
...@@ -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: {
......
...@@ -111,11 +111,19 @@ describe('Status checks form', () => { ...@@ -111,11 +111,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