Skip to content

Commit

Permalink
feat: make FA form error messaging more descript (openedx#34247)
Browse files Browse the repository at this point in the history
* feat: make FA form error messaging more descript

* chore: quality

* fix: split up tests

* fix: make test more specific

* chore: fix comment typo

* chore: fix comment typo
  • Loading branch information
christopappas authored Feb 16, 2024
1 parent 4d1d82d commit 6353bb2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
return FormView.extend({
el: '.financial-assistance-wrapper',
events: {
'click .js-submit-form': 'submitForm'
'click .js-submit-form': 'submitForm',
'ajaxError': 'handleAjaxError'
},
tpl: formViewTpl,
fieldTpl: formFieldTpl,
Expand Down Expand Up @@ -101,6 +102,12 @@

if (error.status === 0) {
msg = gettext('An error has occurred. Check your Internet connection and try again.');
} else if (error.status === 403) {
txt = [
'You must confirm your email to complete registration before applying for financial assistance.',
'If you continue to have issues please contact support.'
],
msg = gettext(txt.join(' '));
}

this.errors = [HtmlUtils.joinHtml(
Expand Down Expand Up @@ -155,6 +162,12 @@
});
}
}
},

// this.model.save() makes an ajax call, which, when it errors,
// should have an error message displayed on the banner on the page
handleAjaxError: function (event, request, settings, thrownError) {
this.saveError(request);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,11 @@ define([
expect(view.$('.js-success-message').length).toEqual(1);
};

failedSubmission = function() {
failedSubmission = function(statusCode) {
expect(view.$('.js-success-message').length).toEqual(0);
expect(view.$formFeedback.find('.' + view.formErrorsJsHook).length).toEqual(0);
validSubmission();
view.model.trigger('error', {status: 500});
view.model.trigger('error', {status: statusCode});
expect(view.$('.js-success-message').length).toEqual(0);
expect(view.$formFeedback.find('.' + view.formErrorsJsHook).length).toEqual(1);
};
Expand Down Expand Up @@ -166,7 +166,12 @@ define([
});

it('should submit the form and show an error message if content is valid and API returns error', function() {
failedSubmission();
failedSubmission(500);
});

it('should submit the form and show an error message if content is valid and API returns 403 error', function() {
failedSubmission(403);
expect(view.$('.message-copy').text()).toContain('You must confirm your email');
});

it('should allow form resubmission after a front end validation failure', function() {
Expand All @@ -176,7 +181,7 @@ define([
});

it('should allow form resubmission after an API error is returned', function() {
failedSubmission();
failedSubmission(500);
successfulSubmission();
});

Expand Down

0 comments on commit 6353bb2

Please sign in to comment.