Display white_label_logo image when hide_ofn_navigation is set to true

for both desktop and mobile view
This commit is contained in:
Jean-Baptiste Bellet
2023-03-17 15:07:41 +01:00
parent 54342254b6
commit f42f513f8c
5 changed files with 131 additions and 10 deletions

View File

@@ -10,5 +10,12 @@ module WhiteLabel
# if the distributor has the hide_ofn_navigation preference set to true
# then we should hide the OFN navigation
@hide_ofn_navigation = distributor.hide_ofn_navigation
# if the distributor has the hide_ofn_navigation preference
# set to false, there is no need to check the white_label_logo preference
return unless @hide_ofn_navigation
@white_label_logo = distributor.white_label_logo
@white_label_distributor = distributor
end
end

View File

@@ -16,7 +16,8 @@ class Enterprise < ApplicationRecord
large: { resize_to_fill: [1200, 260] },
}.freeze
WHITE_LABEL_LOGO_SIZES = {
default: { gravity: "Center", resize: "217x44^", crop: '217x44+0+0' }
default: { gravity: "Center", resize: "217x44^", crop: '217x44+0+0' },
mobile: { gravity: "Center", resize: "75x26^", crop: '75x26+0+0' },
}.freeze
VALID_INSTAGRAM_REGEX = %r{\A[a-zA-Z0-9._]{1,30}([^/-]*)\z}

View File

@@ -3,7 +3,10 @@
%ul.nav-logo
%li.ofn-logo
%a{href: main_app.root_path}
%img{src: ContentConfig.url_for(:logo)}
- if @white_label_logo&.variable?
= image_tag @white_label_distributor.white_label_logo_url(:default)
- else
%img{src: ContentConfig.url_for(:logo)}
%li.powered-by
%img{src: '/favicon.ico'}
%span

View File

@@ -6,7 +6,10 @@
%section.left
.ofn-logo
%a{href: main_app.root_path}
%img{src: ContentConfig.url_for(:logo_mobile), srcset: ContentConfig.url_for(:logo_mobile_svg), width: "75", height: "26"}
- if @white_label_logo&.variable?
= image_tag @white_label_distributor.white_label_logo_url(:mobile)
- else
%img{src: ContentConfig.url_for(:logo_mobile), srcset: ContentConfig.url_for(:logo_mobile_svg), width: "75", height: "26"}
%section.right{"ng-cloak" => true}
%span.cart-span{"ng-class" => "{ dirty: Cart.dirty || Cart.empty(), 'pure-dirty': Cart.dirty }"}

View File

@@ -5,6 +5,7 @@ require 'system_helper'
describe 'White label setting' do
include AuthenticationHelper
include ShopWorkflow
include FileHelper
let!(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) }
let!(:shipping_method) { create(:shipping_method, distributors: [distributor]) }
@@ -18,6 +19,13 @@ describe 'White label setting' do
variants: [product.variants.first])
}
let!(:order) { create(:order, distributor: distributor, order_cycle: order_cycle) }
let(:complete_order) {
create(:order_with_credit_payment,
user: nil,
email: "guest@user.com",
distributor: distributor,
order_cycle: order_cycle)
}
let(:ofn_navigation) { 'ul.nav-main-menu' }
@@ -102,13 +110,6 @@ describe 'White label setting' do
end
context "when the user has a complete order" do
let(:complete_order) {
create(:order_with_credit_payment,
user: nil,
email: "guest@user.com",
distributor: distributor,
order_cycle: order_cycle)
}
before do
set_order(complete_order)
end
@@ -162,6 +163,112 @@ describe 'White label setting' do
it_behaves_like "does not hide the OFN navigation"
end
end
context "manage the white_label_logo preference" do
context "when the distributor has no logo" do
before do
distributor.update_attribute(:hide_ofn_navigation, true)
end
shared_examples "shows/hide the right logos" do
it "shows the OFN logo on shop page" do
expect(page).to have_selector "img[src*='/default_images/ofn-logo.png']"
end
end
context "on shop page" do
before do
visit main_app.enterprise_shop_path(distributor)
end
it_behaves_like "shows/hide the right logos"
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/hide the right logos"
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/hide the right logos"
end
context "on order confirmation page" do
before do
visit order_path(complete_order, order_token: complete_order.token)
end
it_behaves_like "shows/hide the right logos"
end
end
context "when the distributor has a logo" do
before do
distributor.update_attribute(:hide_ofn_navigation, true)
distributor.update white_label_logo: white_logo_file
end
shared_examples "shows/hide the right logos" do
it "shows the white label logo on shop page" do
expect(page).to have_selector "img[src*='/logo-white.png']"
end
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
end
context "on shop page" do
before do
visit main_app.enterprise_shop_path(distributor)
end
it_behaves_like "shows/hide the right logos"
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/hide the right logos"
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/hide the right logos"
end
context "on order confirmation page" do
before do
visit order_path(complete_order, order_token: complete_order.token)
end
it_behaves_like "shows/hide the right logos"
end
end
end
end
context "when the white label feature is deactivated" do