Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Add specs for payment methods display
Szymon Iwaczfeb479b0ea0c
diff --git a/frontend/spec/features/checkout_spec.rb b/frontend/spec/features/checkout_spec.rbindex 6cdb8902d4..9b1da50cd4 100644--- a/frontend/spec/features/checkout_spec.rb+++ b/frontend/spec/features/checkout_spec.rb@@ -202,17 +202,35 @@ describe 'Checkout', type: :feature, inaccessible: true, js: true doit 'only returns supported payment method of current store' doexpect(page).not_to have_css("#payment_method_#{unsupported_payment.id}", visible: :hidden)end++ it 'shows proper fields when changing payment method' do+ expect(page).to have_css("#payment_method_#{credit_card_payment.id}")+ expect(page).to have_css("#payment_method_#{check_payment.id}", visible: :hidden)++ within('#payment-method-fields') do+ find('label', text: 'Check').click+ end+ expect(page).not_to have_css("#payment_method_#{check_payment.id}")+ expect(page).to have_css("#payment_method_#{credit_card_payment.id}", visible: :hidden)++ within('#payment-method-fields') do+ find('label', text: 'Credit Card').click+ end+ expect(page).to have_css("#payment_method_#{credit_card_payment.id}")+ expect(page).to have_css("#payment_method_#{check_payment.id}", visible: :hidden)+ endendcontext 'user has payment sources', js: true dolet(:bogus) { create(:credit_card_payment_method) }+ let(:check) { create(:check_payment_method) }let(:user) { create(:user) }before docreate(:credit_card, user_id: user.id, payment_method: bogus, gateway_customer_profile_id: 'BGS-WEFWF')order = OrderWalkthrough.up_to(:payment)- allow(order).to receive_messages(available_payment_methods: [bogus])+ allow(order).to receive_messages(available_payment_methods: [bogus, check])allow_any_instance_of(Spree::CheckoutController).to receive_messages(current_order: order)allow_any_instance_of(Spree::CheckoutController).to receive_messages(try_spree_current_user: user)@@ -233,6 +251,40 @@ describe 'Checkout', type: :feature, inaccessible: true, js: true doexpect(page).to have_content(Spree.t(:order_success).gsub(/[[:space:]]+/, ' '))expect(page).to have_current_path(spree.order_path(Spree::Order.last))end++ it 'shows proper fields when changing payment method' do+ # Check if credit card fields with existing card option are visible.+ within('#existing_cards') do+ expect(page).to have_content('****1111, Spree Commerce')+ expect(page).to have_content('Add a new card')+ end++ expect(page).to have_css("#payment_method_#{bogus.id}", visible: :hidden)+ find('span', text: 'Add a new card').click+ expect(page).to have_css("#payment_method_#{bogus.id}")++ # Choose 'Check' and see if credit card fields are hidden.+ within('#payment-method-fields') do+ find('label', text: 'Check').click+ end++ expect(page).to have_css("#payment_method_#{bogus.id}", visible: :hidden)+ expect(page).to have_css("#existing_cards", visible: :hidden)++ # Choose 'Credit Card' and see if credit card fields with existing card option are visible again.+ within('#payment-method-fields') do+ find('label', text: 'Credit Card').click+ end++ within('#existing_cards') do+ expect(page).to have_content('****1111, Spree Commerce')+ expect(page).to have_content('Add a new card')+ end++ expect(page).to have_css("#payment_method_#{bogus.id}", visible: :hidden)+ find('span', text: 'Add a new card').click+ expect(page).to have_css("#payment_method_#{bogus.id}")+ endend# regression for #2921