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.

Add tests for new helper method.

Matthew Kennedy44992dc1f37b
diff --git a/frontend/spec/helpers/navigation_helper_spec.rb b/frontend/spec/helpers/navigation_helper_spec.rb
index 76905a1122..0e92e36bc1 100644
--- a/frontend/spec/helpers/navigation_helper_spec.rb
+++ b/frontend/spec/helpers/navigation_helper_spec.rb
@@ -30,5 +30,48 @@ module Spree
it { expect(should_render_internationalization_dropdown?).to be_falsey }
end
end
+
+ describe '#spree_nav_link_tag' do
+ let(:store) { create(:store) }
+ let(:menu) { create(:menu, store: store) }
+ let(:locale_param) { 'en' }
+
+ include Spree::CurrencyHelper
+ include Spree::LocaleHelper
+
+ context 'when link is passed with no arguments' do
+ let(:menu_item) { create(:menu_item, menu: menu, destination: 'https://my-website.com') }
+
+ it 'returns the link destination with no unexpected attributes' do
+ expect(spree_nav_link_tag(menu_item)).to eq('<a href="https://my-website.com">Link To Somewhere</a>')
+ end
+ end
+
+ context 'when link is passed with setting to open in a new window' do
+ let(:menu_item) { create(:menu_item, menu: menu, destination: 'https://my-website.com', new_window: true) }
+
+ it 'returns the link destination with target="_blank" rel="noopener noreferrer"' do
+ expect(spree_nav_link_tag(menu_item)).to eq('<a target="_blank" rel="noopener noreferrer" href="https://my-website.com">Link To Somewhere</a>')
+ end
+ end
+
+ context 'when link is passed with setting to open in a new window, and passed custom attributes' do
+ let(:menu_item) { create(:menu_item, menu: menu, destination: 'https://my-website.com', new_window: true) }
+
+ it 'returns the link destination with target="_blank" rel="noopener noreferrer"' do
+ expect(spree_nav_link_tag(menu_item, { class: 'custom-class', id: 'custonId', target: '_not_so_blank', rel: 'related', data: 'custom-data', aria: 'custom-aria' })).
+ to eq('<a target="_not_so_blank" rel="related" class="custom-class" id="custonId" data="custom-data" aria="custom-aria" href="https://my-website.com">Link To Somewhere</a>')
+ end
+ end
+
+ context 'when passed a block' do
+ let(:menu_item) { create(:menu_item, menu: menu, destination: 'https://my-website.com', new_window: true) }
+
+ it 'returns the link containing the contents of the block' do
+ expect(spree_nav_link_tag(menu_item) { content_tag :span, 'Hello' }).
+ to eq('<a target="_blank" rel="noopener noreferrer" href="https://my-website.com"><span>Hello</span></a>')
+ end
+ end
+ end
end
end