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
SD-959 add tests
KacperMekarskia5e65b6bb7f4
diff --git a/frontend/app/views/spree/shared/_change_store.html.erb b/frontend/app/views/spree/shared/_change_store.html.erbindex c08238c203..2f12c1c3b4 100644--- a/frontend/app/views/spree/shared/_change_store.html.erb+++ b/frontend/app/views/spree/shared/_change_store.html.erb@@ -1,4 +1,4 @@-<% if stores.size > 1 %>+<% if Spree::Config.allow_currency_change && stores.size > 1 %><li class="change-store"><div class="dropdown navbar-right-dropdown"><button id="stores-button" type="button" data-toggle="dropdown" class="navbar-right-dropdown-toggle" aria-label="<%= Spree.t('nav_bar.change_country')%>">@@ -12,7 +12,7 @@height: 15) %></button>- <div class="dropdown-menu dropdown-menu-right text-right">+ <div id="stores_list" class="dropdown-menu dropdown-menu-right text-right"><% stores.each do |store| %><div class="pl-3 d-flex justify-content-between align-items-center <%= 'active' if store.id == current_store.id %>"><span class="flag-icon flag-icon-<%= store_country_iso(store) %>"></span>diff --git a/frontend/spec/features/main_nav_bar_spec.rb b/frontend/spec/features/main_nav_bar_spec.rbnew file mode 100644index 0000000000..bad7065ab8--- /dev/null+++ b/frontend/spec/features/main_nav_bar_spec.rb@@ -0,0 +1,78 @@+require 'spec_helper'++describe 'Main navigation bar', type: :feature do+ describe 'change store' do+ shared_examples 'change store not available' do+ it 'does not show currency selector button' do+ expect(page).not_to have_button(id: 'stores-button')+ end++ it 'does not render stores list' do+ expect(page).not_to have_selector('div#stores_list')+ end+ end++ context 'when allow_currency_change preference is set to true' do+ let!(:stores) { create_list(:store, stores_number, default_country: create(:country)) }++ before do+ reset_spree_preferences do |config|+ config.allow_currency_change = true+ end++ visit spree.root_path+ end++ context 'when there is one supported currency' do+ let(:stores_number) { 0 }++ it_behaves_like 'change store not available'+ end++ context 'when there are more than one supported currencies' do+ let(:stores_number) { 2 }+ let(:first_store) { stores.first }+ let(:first_store_currency_symbol) { ::Money::Currency.find(first_store.default_currency).symbol }+ let(:first_link_name) { "#{first_store.default_country&.name} (#{first_store_currency_symbol})" }+ let(:first_url) { "//#{first_store.url}" }+ let(:second_store) { stores.second }+ let(:second_store_currency_symbol) { ::Money::Currency.find(second_store.default_currency).symbol }+ let(:second_link_name) { "#{second_store.default_country&.name} (#{first_store_currency_symbol})" }+ let(:second_url) { "//#{second_store.url}" }++ it 'shows currency selector button' do+ within('.change-store') { expect(page).to have_button(id: 'stores-button') }+ end++ it 'currency selector button shows a links list to currencies' do+ within('.change-store') { expect(page).to have_link(first_link_name, href: first_url) }+ within('.change-store') { expect(page).to have_link(second_link_name, href: second_url) }+ end+ end+ end++ context 'when allow_currency_change preference is set to false' do+ let!(:stores) { create_list(:store, stores_number) }++ before do+ reset_spree_preferences do |config|+ config.allow_currency_change = false+ end++ visit spree.root_path+ end++ context 'when there is one supported currency' do+ let(:stores_number) { 0 }++ it_behaves_like 'change store not available'+ end++ context 'when there are more than one supported currencies' do+ let(:stores_number) { 2 }++ it_behaves_like 'change store not available'+ end+ end+ end+end