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
Better testing of Admin store switcher
Damian Legawieca4cde81df077
diff --git a/backend/app/helpers/spree/admin/stores_helper.rb b/backend/app/helpers/spree/admin/stores_helper.rbindex 7a9eeda6c8..0efc3705df 100644--- a/backend/app/helpers/spree/admin/stores_helper.rb+++ b/backend/app/helpers/spree/admin/stores_helper.rb@@ -22,7 +22,7 @@ module Spreeicon = svg_icon name: 'circle.svg', width: '18', height: '18'end- link_to icon + store.unique_name, store.formatted_url + request.path,+ link_to icon + store.unique_name, url_for(host: store.formatted_url),class: "#{classes} text-dark p-3 dropdown-item", id: store.codeendenddiff --git a/backend/spec/features/admin/orders/listing_spec.rb b/backend/spec/features/admin/orders/listing_spec.rbindex e9f692b971..65a7b43fea 100644--- a/backend/spec/features/admin/orders/listing_spec.rb+++ b/backend/spec/features/admin/orders/listing_spec.rb@@ -3,7 +3,7 @@ require 'spec_helper'describe 'Orders Listing', type: :feature dostub_authorization!- let(:other_store) { create(:store, url: 'another-store.lvh.me') }+ let(:other_store) { create(:store, name: 'Other Store', url: "another-store.lvh.me") }let(:order1) docreate :order_with_line_items,@@ -84,20 +84,27 @@ describe 'Orders Listing', type: :feature doendend- describe 'switching store' do- before do- Capybara.app_host = 'http://another-store.lvh.me'+ describe 'switching store', js: true do+ it 'shows orders from the current store only' do+ expect(page).to have_content('R100')+ expect(page).to have_content('R200')+visit spree.admin_orders_path- end- after { Capybara.app_host = nil }+ Capybara.app_host = 'http://another-store.lvh.me'++ find('a#storeSelectorDropdown').click+ within('.dropdown-menu') { click_link other_store.unique_name }++ expect(current_url).to match('another-store.lvh.me')- it 'shows orders from the current store only' doexpect(page).to have_content('R300')expect(page).to have_content('R400')expect(page).not_to have_content('R100')expect(page).not_to have_content('R200')++ Capybara.app_host = nilendenddiff --git a/backend/spec/features/admin/store_selector_spec.rb b/backend/spec/features/admin/store_selector_spec.rbindex e274e8955d..654a956e3b 100644--- a/backend/spec/features/admin/store_selector_spec.rb+++ b/backend/spec/features/admin/store_selector_spec.rb@@ -7,6 +7,7 @@ describe 'Admin store switcher', type: :feature, js: true dolet!(:store_one) { Spree::Store.default }let!(:store_two) { create(:store, url: 'www.example-one.com') }let!(:store_three) { create(:store, url: 'www.example-two.com') }+ let(:port) { Capybara.current_session.server.port }context 'on the orders page of admin' dobefore do@@ -16,9 +17,9 @@ describe 'Admin store switcher', type: :feature, js: true doit 'allows to change the url to the seleted store and returns you to orders page' dofind('a#storeSelectorDropdown').click- expect(page).to have_selector(:css, "a[href='#{store_one.formatted_url}/admin/orders']")- expect(page).to have_selector(:css, "a[href='#{store_two.formatted_url}/admin/orders']")- expect(page).to have_selector(:css, "a[href='#{store_three.formatted_url}/admin/orders']")+ expect(page).to have_selector(:css, "a[href*='#{store_one.formatted_url}:#{port}/admin/orders']")+ expect(page).to have_selector(:css, "a[href*='#{store_two.formatted_url}:#{port}/admin/orders']")+ expect(page).to have_selector(:css, "a[href*='#{store_three.formatted_url}:#{port}/admin/orders']")endend@@ -30,9 +31,9 @@ describe 'Admin store switcher', type: :feature, js: true doit 'allows to change the store store and returns you to products page' dofind('a#storeSelectorDropdown').click- expect(page).to have_selector(:css, "a[href='#{store_one.formatted_url}/admin/products']")- expect(page).to have_selector(:css, "a[href='#{store_two.formatted_url}/admin/products']")- expect(page).to have_selector(:css, "a[href='#{store_three.formatted_url}/admin/products']")+ expect(page).to have_selector(:css, "a[href*='#{store_one.formatted_url}:#{port}/admin/products']")+ expect(page).to have_selector(:css, "a[href*='#{store_two.formatted_url}:#{port}/admin/products']")+ expect(page).to have_selector(:css, "a[href*='#{store_three.formatted_url}:#{port}/admin/products']")endendenddiff --git a/core/app/models/spree/store.rb b/core/app/models/spree/store.rbindex 5616c3c39b..e60077dc67 100644--- a/core/app/models/spree/store.rb+++ b/core/app/models/spree/store.rb@@ -98,7 +98,7 @@ module Spree@formatted_url ||= if url.match(/http:\/\/|https:\/\//)urlelse- Rails.env.development? ? "http://#{url}" : "https://#{url}"+ Rails.env.development? || Rails.env.test? ? "http://#{url}" : "https://#{url}"endenddiff --git a/frontend/spec/helpers/store_helper_spec.rb b/frontend/spec/helpers/store_helper_spec.rbindex 5a840e6681..9f714a20bf 100644--- a/frontend/spec/helpers/store_helper_spec.rb+++ b/frontend/spec/helpers/store_helper_spec.rb@@ -40,8 +40,8 @@ module Spreeenddescribe '#store_link' do- it { expect(store_link(eu_store)).to eq('<a href="https://eu.spreecommerce.org">Deutsch (DE) (€)</a>') }- it { expect(store_link(eu_store, class: 'some-class')).to eq('<a class="some-class" href="https://eu.spreecommerce.org">Deutsch (DE) (€)</a>') }+ it { expect(store_link(eu_store)).to eq('<a href="http://eu.spreecommerce.org">Deutsch (DE) (€)</a>') }+ it { expect(store_link(eu_store, class: 'some-class')).to eq('<a class="some-class" href="http://eu.spreecommerce.org">Deutsch (DE) (€)</a>') }it { expect { store_link(nil) }.not_to raise_error }end