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.

Fix | add missing :uk svg country icon. (#12953)

Kyryl Ωliinyk9626461595da
diff --git a/storefront/app/helpers/spree/storefront_helper.rb b/storefront/app/helpers/spree/storefront_helper.rb
index 65c555d4e5..e2b106e6bc 100644
--- a/storefront/app/helpers/spree/storefront_helper.rb
+++ b/storefront/app/helpers/spree/storefront_helper.rb
@@ -66,9 +66,16 @@ module Spree
end
def svg_country_icon(country_code)
- country_code = :us if country_code.to_s.downcase == 'en'
- country_code = :jp if country_code.to_s.downcase == 'ja'
- tag.span(class: "fi fi-#{country_code.downcase}")
+ language_to_country = {
+ 'en' => 'us',
+ 'ja' => 'jp',
+ 'uk' => 'ua'
+ }
+
+ normalized_code = country_code.to_s.downcase
+ final_country_code = language_to_country.fetch(normalized_code, normalized_code)
+
+ tag.span(class: "fi fi-#{final_country_code}")
end
def show_account_pane?
diff --git a/storefront/spec/helpers/spree/storefront_helper_spec.rb b/storefront/spec/helpers/spree/storefront_helper_spec.rb
index ef7d3f4832..0120399976 100644
--- a/storefront/spec/helpers/spree/storefront_helper_spec.rb
+++ b/storefront/spec/helpers/spree/storefront_helper_spec.rb
@@ -95,4 +95,22 @@ describe Spree::StorefrontHelper, type: :helper do
end
end
end
+
+ describe '#svg_country_icon' do
+ it 'returns correct flag class for uk language code' do
+ expect(svg_country_icon(['uk', :uk].sample)).to include('fi fi-ua')
+ end
+
+ it 'returns correct flag class for en language code' do
+ expect(svg_country_icon(['en', :en].sample)).to include('fi fi-us')
+ end
+
+ it 'returns correct flag class for ja language code' do
+ expect(svg_country_icon(['ja', :ja].sample)).to include('fi fi-jp')
+ end
+
+ it 'returns correct flag class for unknown language code' do
+ expect(svg_country_icon('fr')).to include('fi fi-fr')
+ end
+ end
end