Merge pull request #10937 from jibees/10900-white-label-remove-ofn-navigation-for-small-width-screens

[White Label] Remove ofn navigation for small width screens as well when option is activated
This commit is contained in:
Konrad
2023-06-09 16:28:22 +02:00
committed by GitHub
6 changed files with 145 additions and 49 deletions

View File

@@ -7,14 +7,15 @@
= 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"}
- [*1..7].each do |menu_number|
- menu_name = "menu_#{menu_number}"
- if ContentConfig[menu_name].present?
%li.li-menu
%a{href: t("#{menu_name}_url") }
%span.nav-primary
%i{class: ContentConfig["#{menu_name}_icon_name"]}
= t "#{menu_name}_title"
- unless @hide_ofn_navigation
- [*1..7].each do |menu_number|
- menu_name = "menu_#{menu_number}"
- if ContentConfig[menu_name].present?
%li.li-menu
%a{href: t("#{menu_name}_url") }
%span.nav-primary
%i{class: ContentConfig["#{menu_name}_icon_name"]}
= t "#{menu_name}_title"
- if OpenFoodNetwork::I18nConfig.selectable_locales.count > 1
%li.language-switcher.li-menu

View File

@@ -1,14 +1,26 @@
# frozen_string_literal: true
module UIComponentHelper
def browse_as_medium
Capybara.current_session.current_window
.resize_to(1024, 768)
def browse_as_small(&block)
browse_with_window_size(640, 480, &block)
end
def browse_as_large
def browse_as_medium(&block)
browse_with_window_size(1024, 768, &block)
end
def browse_as_default(&block)
browse_with_window_size(1280, 800)
block&.call
end
def browse_with_window_size(width, height, &block)
Capybara.current_session.current_window
.resize_to(1280, 800)
.resize_to(width, height)
return unless block
block.call
browse_as_default
end
def click_login_button

View File

@@ -24,9 +24,8 @@ describe "Authentication" do
before do
visit root_path
end
describe "as large" do
describe "with default large screen" do
before do
browse_as_large
open_login_modal
end
@@ -173,12 +172,8 @@ describe "Authentication" do
end
describe "as medium" do
before do
browse_as_medium
end
after do
browse_as_large
end
around { |example| browse_as_medium { example.run } }
it "showing login" do
open_off_canvas
open_login_modal

View File

@@ -100,7 +100,6 @@ describe 'Multilingual' do
end
describe "using the language switcher UI" do
before { browse_as_large }
context "when there is only one language available" do
before do
allow(ENV).to receive(:[]).and_call_original

View File

@@ -6,6 +6,7 @@ describe 'White label setting' do
include AuthenticationHelper
include ShopWorkflow
include FileHelper
include UIComponentHelper
let!(:distributor) { create(:distributor_enterprise, with_payment_and_shipping: true) }
let!(:shipping_method) { create(:shipping_method, distributors: [distributor]) }
@@ -29,20 +30,75 @@ describe 'White label setting' do
let(:ofn_navigation) { 'ul.nav-main-menu' }
shared_examples "hides the OFN navigation for mobile view as well" do
context "mobile view" do
around { |example| browse_as_small { example.run } }
it "hides OFN navigation" do
find("a.left-off-canvas-toggle").click
within "aside.left-off-canvas-menu" do
expect(page).not_to have_selector "a[href='#{main_app.shops_path}']"
expect(page).not_to have_selector "a[href='#{main_app.map_path}']"
expect(page).not_to have_selector "a[href='#{main_app.producers_path}']"
expect(page).not_to have_selector "a[href='#{main_app.groups_path}']"
expect(page).not_to have_selector "a[href='#{I18n.t('.menu_5_url')}']"
end
end
end
end
shared_examples "does not hide the OFN navigation for mobile view as well" do
context "mobile view" do
around { |example| browse_as_small { example.run } }
it "does not hide OFN navigation" do
find("a.left-off-canvas-toggle").click
within "aside.left-off-canvas-menu" do
expect(page).to have_selector "a[href='#{main_app.shops_path}']"
expect(page).to have_selector "a[href='#{main_app.map_path}']"
expect(page).to have_selector "a[href='#{main_app.producers_path}']"
expect(page).to have_selector "a[href='#{main_app.groups_path}']"
expect(page).to have_selector "a[href='#{I18n.t('.menu_5_url')}']"
end
end
end
end
shared_examples "does not hide the OFN navigation" do
it "does not hide the OFN navigation when visiting the shop" do
visit main_app.enterprise_shop_path(distributor)
expect(page).to have_selector ofn_navigation
context "for shop path" do
before do
visit main_app.enterprise_shop_path(distributor)
end
it "does not hide the OFN navigation" do
expect(page).to have_selector ofn_navigation
end
it_behaves_like "does not hide the OFN navigation for mobile view as well"
end
it "does not hide the OFN navigation when visiting root path" do
visit main_app.root_path
expect(page).to have_selector ofn_navigation
context "for cart path" do
before do
visit main_app.cart_path
end
it "does not hide the OFN navigation" do
expect(page).to have_selector ofn_navigation
end
it_behaves_like "does not hide the OFN navigation for mobile view as well"
end
it "does not hide the OFN navigation when visiting cart path" do
visit main_app.cart_path
expect(page).to have_selector ofn_navigation
context "for root path" do
before do
visit main_app.root_path
end
it "does not hide the OFN navigation" do
expect(page).to have_selector ofn_navigation
end
it_behaves_like "does not hide the OFN navigation for mobile view as well"
end
end
@@ -53,14 +109,28 @@ describe 'White label setting' do
end
shared_examples "hides the OFN navigation when needed only" do
it "hides the OFN navigation when visiting the shop" do
visit main_app.enterprise_shop_path(distributor)
expect(page).to have_no_selector ofn_navigation
context "for shop path" do
before do
visit main_app.enterprise_shop_path(distributor)
end
it "hides the OFN navigation" do
expect(page).to have_no_selector ofn_navigation
end
it_behaves_like "hides the OFN navigation for mobile view as well"
end
it "does not hide the OFN navigation when visiting root path" do
visit main_app.root_path
expect(page).to have_selector ofn_navigation
context "for root path" do
before do
visit main_app.root_path
end
it "does not hide the OFN navigation when visiting root path" do
expect(page).to have_selector ofn_navigation
end
it_behaves_like "does not hide the OFN navigation for mobile view as well"
end
end
@@ -78,16 +148,30 @@ describe 'White label setting' do
shared_examples "hides the OFN navigation when needed only for the checkout" do
it_behaves_like "hides the OFN navigation when needed only"
it "hides the OFN navigation when visiting cart path" do
visit main_app.cart_path
expect(page).to have_no_selector ofn_navigation
context "for cart path" do
before do
visit main_app.cart_path
end
it "hides the OFN navigation" do
expect(page).to have_no_selector ofn_navigation
end
it_behaves_like "hides the OFN navigation for mobile view as well"
end
it "hides the OFN navigation when visiting checkout path" do
visit checkout_path
expect(page).to have_content "Checkout now"
expect(page).to have_content "Order ready for "
expect(page).to have_no_selector ofn_navigation
context "for checkout path" do
before do
visit checkout_path
end
it "hides the OFN navigation" do
expect(page).to have_content "Checkout now"
expect(page).to have_content "Order ready for "
expect(page).to have_no_selector ofn_navigation
end
it_behaves_like "hides the OFN navigation for mobile view as well"
end
end
@@ -110,9 +194,14 @@ describe 'White label setting' do
end
shared_examples "hides the OFN navigation when needed only for the order confirmation" do
it "hides" do
visit order_path(complete_order, order_token: complete_order.token)
expect(page).to have_no_selector ofn_navigation
context "for order confirmation path" do
before do
visit order_path(complete_order, order_token: complete_order.token)
end
it "hides the OFN navigation" do
expect(page).to have_no_selector ofn_navigation
end
end
end

View File

@@ -11,7 +11,7 @@ Capybara.register_driver(:cuprite) do |app|
Capybara::Cuprite::Driver.new(
app,
**{
window_size: [1200, 800],
window_size: [1280, 800],
browser_options: browser_options,
process_timeout: 60,
timeout: 60,