When there is a white_label_logo_link pref. use it!

+ update spec as well

 + use an an helper to get the main logo link for a shopfront

Co-Authored-By: Maikel <maikel@email.org.au>
This commit is contained in:
Jean-Baptiste Bellet
2023-03-20 16:27:01 +01:00
committed by Konrad
parent 679fcc0114
commit b1de28eeea
3 changed files with 65 additions and 1 deletions

View File

@@ -87,4 +87,10 @@ module EnterprisesHelper
main_app.producers_url
end
end
def main_logo_link(enterprise)
return enterprise.white_label_logo_link if enterprise&.white_label_logo_link.present?
main_app.root_path
end
end

View File

@@ -2,7 +2,7 @@
%section.top-bar-section
%ul.nav-logo
%li.ofn-logo
%a{href: main_app.root_path}
%a{href: main_logo_link(@white_label_distributor)}
- if @white_label_logo&.variable?
= image_tag @white_label_distributor.white_label_logo_url(:default)
- else

View File

@@ -228,6 +228,11 @@ describe 'White label setting' do
it "does not show the OFN logo on shop page" do
expect(page).not_to have_selector "img[src*='/default_images/ofn-logo.png']"
end
it "links the logo to the default URL" do
within ".nav-logo .ofn-logo" do
expect(page).to have_selector "a[href='/']"
end
end
end
context "on shop page" do
@@ -267,6 +272,59 @@ describe 'White label setting' do
it_behaves_like "shows/hide the right logos"
end
context "and a link on this logo" do
before do
distributor.update_attribute(:white_label_logo_link, "https://www.example.com")
end
shared_examples "shows the right link on the logo" do
it "shows the white label logo link" do
within ".nav-logo .ofn-logo" do
expect(page).to_not have_selector "a[href='/']"
expect(page).to have_selector "a[href*='https://www.example.com']"
end
end
end
context "on shop page" do
before do
visit main_app.enterprise_shop_path(distributor)
end
it_behaves_like "shows the right link on the logo"
end
context "on cart page" do
before do
order.update_attribute(:state, 'cart')
order.line_items << create(:line_item, variant: product.variants.first)
set_order(order)
visit main_app.cart_path
end
it_behaves_like "shows the right link on the logo"
end
context "on checkout page" do
before do
order.update_attribute(:state, 'cart')
order.line_items << create(:line_item, variant: product.variants.first)
set_order(order)
visit checkout_path
end
it_behaves_like "shows the right link on the logo"
end
context "on order confirmation page" do
before do
visit order_path(complete_order, order_token: complete_order.token)
end
it_behaves_like "shows the right link on the logo"
end
end
end
end
end