From fdca1f660676fb883472c024c9464be93c055d83 Mon Sep 17 00:00:00 2001 From: Rob Harrington Date: Wed, 31 May 2017 14:40:15 +1000 Subject: [PATCH] Adding message about having no saved cards to account/cards UI --- app/assets/stylesheets/darkswarm/account.css.scss | 4 ++++ app/views/spree/users/_cards.html.haml | 6 +++--- app/views/spree/users/_saved_cards.html.haml | 2 +- config/locales/en.yml | 2 ++ spec/features/consumer/account/cards_spec.rb | 15 ++++++++++++++- 5 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/assets/stylesheets/darkswarm/account.css.scss b/app/assets/stylesheets/darkswarm/account.css.scss index 78f8c0dfd9..91cd042d28 100644 --- a/app/assets/stylesheets/darkswarm/account.css.scss +++ b/app/assets/stylesheets/darkswarm/account.css.scss @@ -12,6 +12,10 @@ } } + .saved_cards, .no_cards { + margin-bottom: 1em; + } + .new_card { opacity: 0; -webkit-transition: opacity 0.4s linear; diff --git a/app/views/spree/users/_cards.html.haml b/app/views/spree/users/_cards.html.haml index d0aaeb7d5a..80069c282f 100644 --- a/app/views/spree/users/_cards.html.haml +++ b/app/views/spree/users/_cards.html.haml @@ -2,11 +2,11 @@ .credit_cards{"ng-controller" => "CreditCardsCtrl"} .row .small-12.medium-6.columns - %span{ ng: { hide: 'savedCreditCards.length > 0' } } -   + %h3= t(:saved_cards) .saved_cards{ ng: { show: 'savedCreditCards.length > 0' } } - %h3= t(:saved_cards) = render 'saved_cards' + .no_cards{ ng: { hide: 'savedCreditCards.length > 0' } } + = t(:you_have_no_saved_cards) %button.button.primary{ ng: { click: 'showForm()', hide: 'CreditCard.visible' } } = t(:add_a_card) diff --git a/app/views/spree/users/_saved_cards.html.haml b/app/views/spree/users/_saved_cards.html.haml index 8df81eeeca..d8c710607b 100644 --- a/app/views/spree/users/_saved_cards.html.haml +++ b/app/views/spree/users/_saved_cards.html.haml @@ -10,4 +10,4 @@ %td.expiry{ ng: { bind: '::card.expiry' } } %td.actions %a{"rel" => "nofollow", "data-method" => "delete", "ng-href" => "{{card.delete_link}}" } - Delete + = t(:delete) diff --git a/config/locales/en.yml b/config/locales/en.yml index 84c8f68ecd..196c130e78 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -872,6 +872,7 @@ en: saved_cards: Saved cards add_a_card: Add a Card add_card: Add Card + you_have_no_saved_cards: You haven't saved any cards yet saving_credit_card: Saving credit card... card_has_been_removed: "Your card has been removed (number: %{number})" @@ -1536,6 +1537,7 @@ Please follow the instructions there to make your enterprise visible on the Open edit_order_cycle: "Edit Order Cycle" roles: "Roles" update: "Update" + delete: Delete add_producer_property: "Add producer property" in_progress: "In Progress" started_at: "Started at" diff --git a/spec/features/consumer/account/cards_spec.rb b/spec/features/consumer/account/cards_spec.rb index 48f9019e34..56d760c1f3 100644 --- a/spec/features/consumer/account/cards_spec.rb +++ b/spec/features/consumer/account/cards_spec.rb @@ -4,10 +4,16 @@ feature "Credit Cards", js: true do include AuthenticationWorkflow describe "as a logged in user" do let(:user) { create(:user) } - let!(:card) { create(:credit_card, user_id: user.id) } + let!(:card) { create(:credit_card, user_id: user.id, gateway_customer_profile_id: 'cus_AZNMJ') } before do quick_login_as user + + stub_request(:get, "https://api.stripe.com/v1/customers/cus_AZNMJ"). + to_return(:status => 200, :body => JSON.generate({id: "cus_AZNMJ"})) + + stub_request(:delete, "https://api.stripe.com/v1/customers/cus_AZNMJ"). + to_return(:status => 200, :body => JSON.generate({deleted: true, id: "cus_AZNMJ"})) end it "lists saved cards, shows interface for adding new cards" do @@ -22,10 +28,17 @@ feature "Credit Cards", js: true do expect(page).to have_content card.last_digits end + # Shows the interface for adding a card click_button I18n.t(:add_a_card) expect(page).to have_field 'first_name' expect(page).to have_field 'card_number' expect(page).to have_field 'card_month' + + # Allows deletion of cards + click_link I18n.t(:delete) + + expect(page).to have_content I18n.t(:card_has_been_removed, number: "x-#{card.last_digits}") + expect(page).to have_content I18n.t(:you_have_no_saved_cards) end end end