From b1de28eeea21fdea67c7410374ad4f9e38db5878 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Mon, 20 Mar 2023 16:27:01 +0100 Subject: [PATCH] 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 --- app/helpers/enterprises_helper.rb | 6 +++ app/views/shared/menu/_large_menu.html.haml | 2 +- spec/system/consumer/white_label_spec.rb | 58 +++++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) diff --git a/app/helpers/enterprises_helper.rb b/app/helpers/enterprises_helper.rb index 2f60c848b4..21d07f27b3 100644 --- a/app/helpers/enterprises_helper.rb +++ b/app/helpers/enterprises_helper.rb @@ -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 diff --git a/app/views/shared/menu/_large_menu.html.haml b/app/views/shared/menu/_large_menu.html.haml index cfb7aa0640..b9a6cb3b7a 100644 --- a/app/views/shared/menu/_large_menu.html.haml +++ b/app/views/shared/menu/_large_menu.html.haml @@ -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 diff --git a/spec/system/consumer/white_label_spec.rb b/spec/system/consumer/white_label_spec.rb index 5aa11d7998..a7ddcc283f 100644 --- a/spec/system/consumer/white_label_spec.rb +++ b/spec/system/consumer/white_label_spec.rb @@ -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