Skip to content

armgit / spree

Public Imported from GitHub
0

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.

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.rb
index 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 Spree
icon = 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.code
end
end
diff --git a/backend/spec/features/admin/orders/listing_spec.rb b/backend/spec/features/admin/orders/listing_spec.rb
index 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 do
stub_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) do
create :order_with_line_items,
@@ -84,20 +84,27 @@ describe 'Orders Listing', type: :feature do
end
end
- 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' do
expect(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 = nil
end
end
diff --git a/backend/spec/features/admin/store_selector_spec.rb b/backend/spec/features/admin/store_selector_spec.rb
index 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 do
let!(: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' do
before do
@@ -16,9 +17,9 @@ describe 'Admin store switcher', type: :feature, js: true do
it 'allows to change the url to the seleted store and returns you to orders page' do
find('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']")
end
end
@@ -30,9 +31,9 @@ describe 'Admin store switcher', type: :feature, js: true do
it 'allows to change the store store and returns you to products page' do
find('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']")
end
end
end
diff --git a/core/app/models/spree/store.rb b/core/app/models/spree/store.rb
index 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:\/\//)
url
else
- Rails.env.development? ? "http://#{url}" : "https://#{url}"
+ Rails.env.development? || Rails.env.test? ? "http://#{url}" : "https://#{url}"
end
end
diff --git a/frontend/spec/helpers/store_helper_spec.rb b/frontend/spec/helpers/store_helper_spec.rb
index 5a840e6681..9f714a20bf 100644
--- a/frontend/spec/helpers/store_helper_spec.rb
+++ b/frontend/spec/helpers/store_helper_spec.rb
@@ -40,8 +40,8 @@ module Spree
end
describe '#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