diff --git a/app/views/shared/menu/_offcanvas_menu.html.haml b/app/views/shared/menu/_offcanvas_menu.html.haml index 8f381a6b8c..8c6456c647 100644 --- a/app/views/shared/menu/_offcanvas_menu.html.haml +++ b/app/views/shared/menu/_offcanvas_menu.html.haml @@ -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 diff --git a/spec/support/request/ui_component_helper.rb b/spec/support/request/ui_component_helper.rb index 1f618cfcaa..ee7aedfbfe 100644 --- a/spec/support/request/ui_component_helper.rb +++ b/spec/support/request/ui_component_helper.rb @@ -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 diff --git a/spec/system/consumer/authentication_spec.rb b/spec/system/consumer/authentication_spec.rb index e3dfe2bbfd..a9b1dbe3a6 100644 --- a/spec/system/consumer/authentication_spec.rb +++ b/spec/system/consumer/authentication_spec.rb @@ -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 diff --git a/spec/system/consumer/multilingual_spec.rb b/spec/system/consumer/multilingual_spec.rb index 228c128bc5..66a94431fc 100644 --- a/spec/system/consumer/multilingual_spec.rb +++ b/spec/system/consumer/multilingual_spec.rb @@ -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 diff --git a/spec/system/consumer/white_label_spec.rb b/spec/system/consumer/white_label_spec.rb index 2629a47cbe..0597ff5d68 100644 --- a/spec/system/consumer/white_label_spec.rb +++ b/spec/system/consumer/white_label_spec.rb @@ -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 diff --git a/spec/system/support/cuprite_setup.rb b/spec/system/support/cuprite_setup.rb index bdb7ba433e..d509c6ff9c 100644 --- a/spec/system/support/cuprite_setup.rb +++ b/spec/system/support/cuprite_setup.rb @@ -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,