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.

Store selector test

Damian Kaczmarczyk2e63018aeaf3
diff --git a/backend/app/assets/stylesheets/spree/backend/components/_sidebar.scss b/backend/app/assets/stylesheets/spree/backend/components/_sidebar.scss
index a67572a05d..0e9ab67ae1 100644
--- a/backend/app/assets/stylesheets/spree/backend/components/_sidebar.scss
+++ b/backend/app/assets/stylesheets/spree/backend/components/_sidebar.scss
@@ -10,7 +10,7 @@ aside#main-sidebar {
transition: 0.3s ease;
z-index: 1041;
- .stores_select {
+ .store_select {
width: 100%;
border: none;
background: none;
diff --git a/backend/app/helpers/spree/admin/stores_helper.rb b/backend/app/helpers/spree/admin/stores_helper.rb
index 6b3bee43d7..e2ef73042f 100644
--- a/backend/app/helpers/spree/admin/stores_helper.rb
+++ b/backend/app/helpers/spree/admin/stores_helper.rb
@@ -14,7 +14,7 @@ module Spree
end
def stores_select()
- collection_select(nil, nil, @stores, :formatted_url, :name, { selected: current_store.formatted_url, prompt: "Select store" }, { onchange: "window.location.href=`${this.value}/admin`", id: "stores_select", class: "stores_select" })
+ collection_select(nil, nil, @stores, :formatted_url, :name, { selected: current_store.formatted_url, prompt: "Select store" }, { onchange: "window.location.href=`${this.value}/admin`", id: "store_select", class: "stores_select" })
end
end
end
diff --git a/backend/app/views/spree/admin/shared/_store_switcher.html.erb b/backend/app/views/spree/admin/shared/_store_switcher.html.erb
index 67ecd8314c..d77fd0b256 100644
--- a/backend/app/views/spree/admin/shared/_store_switcher.html.erb
+++ b/backend/app/views/spree/admin/shared/_store_switcher.html.erb
@@ -1,5 +1,5 @@
<% if can?(:admin, current_store) %>
<div class="d-block border-top p-3 mt-3">
- <%= stores_select%>
+ <%= stores_select %>
</div>
<% end %>
diff --git a/backend/spec/features/admin/store_selector_spec.rb b/backend/spec/features/admin/store_selector_spec.rb
new file mode 100644
index 0000000000..59976d7889
--- /dev/null
+++ b/backend/spec/features/admin/store_selector_spec.rb
@@ -0,0 +1,19 @@
+require 'spec_helper'
+
+describe 'Admin store selector', type: :feature, js: true do
+ stub_authorization!
+
+ let!(:admin_user) { create(:admin_user) }
+
+ let!(:store) { create(:store, url: "www.example1.com") }
+
+ before do
+ visit spree.admin_path
+ end
+
+ it "should allow to change the url to the seleted store" do
+ expect(current_url).not_to include("#{store.formatted_url}")
+ find("select#store_select").find(:xpath, 'option[2]').select_option
+ expect(current_url).to eq "#{store.formatted_url}/admin"
+ end
+end
\ No newline at end of file