Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
Use flashes for displaying frontend errors
Browse files Browse the repository at this point in the history
Allows users to override by replacing the javascript function before
rendering the page.

This is not great, and is being replaced on my js refactor branch, but
it's required for projects now.
  • Loading branch information
Senjai committed May 12, 2017
1 parent 97cf08c commit 62abbe3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/spree/checkout/braintree.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ $(function() {
* submission if tokenization fails, we need to manually re-enable the
* submit button. */
function braintreeError (err) {
alert(err.name + ": " + err.message);
SolidusPaypalBraintree.braintreeErrorHandle(err);
enableSubmit();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
window.SolidusPaypalBraintree = {
APPLE_PAY_API_VERSION: 1,

// Override to provide your own error messages.
braintreeErrorHandle: function(braintreeError) {
var $contentContainer = $("#content");
var $flash = $("<div class='flash error'>" + braintreeError.name + ": " + braintreeError.message + "</div>");
$contentContainer.prepend($flash);

$flash.show().delay(5000).fadeOut(500);
},

fetchToken: function(tokenCallback) {
Spree.ajax({
dataType: 'json',
Expand Down
15 changes: 3 additions & 12 deletions spec/features/braintree_credit_card_checkout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@
# Attempt to submit an empty form once
before(:each) do
expect(page).to have_selector("iframe[type='number']")
message = accept_prompt do
click_button "Save and Continue"
end
click_button "Save and Continue"
expect(message).to eq "BraintreeError: All fields are empty. Cannot tokenize empty card fields."
expect(page).to have_selector("input[type='submit']:enabled")
end
Expand All @@ -76,15 +74,8 @@
it "displays an alert with a meaningful error message" do
expect(page).to have_selector("input[type='submit']:enabled")

# Ensure there are no timing issues with the javascript
aggregate_failures do
5.times do
message = accept_prompt do
click_button "Save and Continue"
end
expect(message).to eq "BraintreeError: All fields are empty. Cannot tokenize empty card fields."
end
end
click_button "Save and Continue"
expect(page).to have_text "BraintreeError: All fields are empty. Cannot tokenize empty card fields."
end
end

Expand Down

0 comments on commit 62abbe3

Please sign in to comment.