From abe63e5b045ed590f728770002345913eb8d1376 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Mon, 5 Jun 2023 12:08:43 +0200 Subject: [PATCH 1/8] Add context for visiting a path --- spec/system/consumer/white_label_spec.rb | 33 +++++++++++++++++------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/spec/system/consumer/white_label_spec.rb b/spec/system/consumer/white_label_spec.rb index a4b46b5428..0a031e527f 100644 --- a/spec/system/consumer/white_label_spec.rb +++ b/spec/system/consumer/white_label_spec.rb @@ -30,19 +30,34 @@ describe 'White label setting' do let(:ofn_navigation) { 'ul.nav-main-menu' } 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 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 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 end end From daaeca88e8febc5708a93d059738b91657cce2cc Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Mon, 5 Jun 2023 12:09:10 +0200 Subject: [PATCH 2/8] Add some helpers to test mobile views --- spec/support/request/ui_component_helper.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/support/request/ui_component_helper.rb b/spec/support/request/ui_component_helper.rb index 1f618cfcaa..5d850de34c 100644 --- a/spec/support/request/ui_component_helper.rb +++ b/spec/support/request/ui_component_helper.rb @@ -1,11 +1,21 @@ # frozen_string_literal: true module UIComponentHelper + def browser_as_small + Capybara.current_session.current_window + .resize_to(640, 480) + end + def browse_as_medium Capybara.current_session.current_window .resize_to(1024, 768) end + def browse_as_default + Capybara.current_session.current_window + .resize_to(1200, 800) + end + def browse_as_large Capybara.current_session.current_window .resize_to(1280, 800) From 5c3e07db5283c354582ecddc2dd8915b41818462 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Mon, 5 Jun 2023 12:09:44 +0200 Subject: [PATCH 3/8] Test that OFN navigation is on mobile views as well --- spec/system/consumer/white_label_spec.rb | 30 ++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/spec/system/consumer/white_label_spec.rb b/spec/system/consumer/white_label_spec.rb index 0a031e527f..dbd0913fca 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,6 +30,29 @@ describe 'White label setting' do let(:ofn_navigation) { 'ul.nav-main-menu' } + shared_examples "does not hides the OFN navigation for mobile view as well" do + context "mobile view" do + before do + browser_as_small + end + + after do + browse_as_default + end + + 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 context "for shop path" do before do @@ -38,6 +62,8 @@ describe 'White label setting' do it "does not hide the OFN navigation" do expect(page).to have_selector ofn_navigation end + + it_behaves_like "does not hides the OFN navigation for mobile view as well" end context "for cart path" do @@ -48,6 +74,8 @@ describe 'White label setting' do it "does not hide the OFN navigation" do expect(page).to have_selector ofn_navigation end + + it_behaves_like "does not hides the OFN navigation for mobile view as well" end context "for root path" do @@ -58,6 +86,8 @@ describe 'White label setting' do it "does not hide the OFN navigation" do expect(page).to have_selector ofn_navigation end + + it_behaves_like "does not hides the OFN navigation for mobile view as well" end end From a8b85a65e9ea932a6dd9b7dd920d6bd41b90bd68 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Mon, 5 Jun 2023 12:20:08 +0200 Subject: [PATCH 4/8] Add context for visiting a path --- spec/system/consumer/white_label_spec.rb | 59 +++++++++++++++++------- 1 file changed, 42 insertions(+), 17 deletions(-) diff --git a/spec/system/consumer/white_label_spec.rb b/spec/system/consumer/white_label_spec.rb index dbd0913fca..674f5c75c7 100644 --- a/spec/system/consumer/white_label_spec.rb +++ b/spec/system/consumer/white_label_spec.rb @@ -98,14 +98,24 @@ 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 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 end end @@ -123,16 +133,26 @@ 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 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 end end @@ -155,9 +175,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 From 7dc8c4b891f4ef7d741103c489c0c1efb7cc4b63 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Mon, 5 Jun 2023 14:44:57 +0200 Subject: [PATCH 5/8] Hide OFN navigation also on small width screens --- .../shared/menu/_offcanvas_menu.html.haml | 17 +++++----- spec/system/consumer/white_label_spec.rb | 31 +++++++++++++++++++ 2 files changed, 40 insertions(+), 8 deletions(-) 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/system/consumer/white_label_spec.rb b/spec/system/consumer/white_label_spec.rb index 674f5c75c7..0f8c6bbc79 100644 --- a/spec/system/consumer/white_label_spec.rb +++ b/spec/system/consumer/white_label_spec.rb @@ -30,6 +30,29 @@ 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 + before do + browser_as_small + end + + after do + browse_as_default + end + + 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 hides the OFN navigation for mobile view as well" do context "mobile view" do before do @@ -106,6 +129,8 @@ describe 'White label setting' do 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 context "for root path" do @@ -116,6 +141,8 @@ describe 'White label setting' do 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 hides the OFN navigation for mobile view as well" end end @@ -141,6 +168,8 @@ describe 'White label setting' do 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 context "for checkout path" do @@ -153,6 +182,8 @@ describe 'White label setting' do 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 From 241b307762f5d5d89e93563c47e11a7aa69be573 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 8 Jun 2023 11:34:05 +1000 Subject: [PATCH 6/8] Fix typos --- spec/support/request/ui_component_helper.rb | 2 +- spec/system/consumer/white_label_spec.rb | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/support/request/ui_component_helper.rb b/spec/support/request/ui_component_helper.rb index 5d850de34c..ba2f997d64 100644 --- a/spec/support/request/ui_component_helper.rb +++ b/spec/support/request/ui_component_helper.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true module UIComponentHelper - def browser_as_small + def browse_as_small Capybara.current_session.current_window .resize_to(640, 480) end diff --git a/spec/system/consumer/white_label_spec.rb b/spec/system/consumer/white_label_spec.rb index 0f8c6bbc79..083b89256e 100644 --- a/spec/system/consumer/white_label_spec.rb +++ b/spec/system/consumer/white_label_spec.rb @@ -33,7 +33,7 @@ describe 'White label setting' do shared_examples "hides the OFN navigation for mobile view as well" do context "mobile view" do before do - browser_as_small + browse_as_small end after do @@ -53,10 +53,10 @@ describe 'White label setting' do end end - shared_examples "does not hides the OFN navigation for mobile view as well" do + shared_examples "does not hide the OFN navigation for mobile view as well" do context "mobile view" do before do - browser_as_small + browse_as_small end after do @@ -86,7 +86,7 @@ describe 'White label setting' do expect(page).to have_selector ofn_navigation end - it_behaves_like "does not hides the OFN navigation for mobile view as well" + it_behaves_like "does not hide the OFN navigation for mobile view as well" end context "for cart path" do @@ -98,7 +98,7 @@ describe 'White label setting' do expect(page).to have_selector ofn_navigation end - it_behaves_like "does not hides the OFN navigation for mobile view as well" + it_behaves_like "does not hide the OFN navigation for mobile view as well" end context "for root path" do @@ -110,7 +110,7 @@ describe 'White label setting' do expect(page).to have_selector ofn_navigation end - it_behaves_like "does not hides the OFN navigation for mobile view as well" + it_behaves_like "does not hide the OFN navigation for mobile view as well" end end @@ -142,7 +142,7 @@ describe 'White label setting' do expect(page).to have_selector ofn_navigation end - it_behaves_like "does not hides the OFN navigation for mobile view as well" + it_behaves_like "does not hide the OFN navigation for mobile view as well" end end From 7cf68cd33b54c02f2e093d9ef21ba6309532ed09 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 8 Jun 2023 11:59:56 +1000 Subject: [PATCH 7/8] Ensure that specs restore default window size --- spec/support/request/ui_component_helper.rb | 28 +++++++++++++-------- spec/system/consumer/authentication_spec.rb | 11 +++----- spec/system/consumer/multilingual_spec.rb | 3 ++- spec/system/consumer/white_label_spec.rb | 16 ++---------- 4 files changed, 25 insertions(+), 33 deletions(-) diff --git a/spec/support/request/ui_component_helper.rb b/spec/support/request/ui_component_helper.rb index ba2f997d64..989efa40a0 100644 --- a/spec/support/request/ui_component_helper.rb +++ b/spec/support/request/ui_component_helper.rb @@ -1,24 +1,30 @@ # frozen_string_literal: true module UIComponentHelper - def browse_as_small - Capybara.current_session.current_window - .resize_to(640, 480) + def browse_as_small(&block) + browse_with_window_size(640, 480, &block) end - def browse_as_medium - Capybara.current_session.current_window - .resize_to(1024, 768) + def browse_as_medium(&block) + browse_with_window_size(1024, 768, &block) end - def browse_as_default - Capybara.current_session.current_window - .resize_to(1200, 800) + def browse_as_default(&block) + browse_with_window_size(1200, 800) + block&.call end - def browse_as_large + def browse_as_large(&block) + browse_with_window_size(1280, 800, &block) + 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..a1ca62e60d 100644 --- a/spec/system/consumer/authentication_spec.rb +++ b/spec/system/consumer/authentication_spec.rb @@ -25,8 +25,9 @@ describe "Authentication" do visit root_path end describe "as large" do + around { |example| browse_as_large { example.run } } + before do - browse_as_large open_login_modal end @@ -173,12 +174,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..556b59b893 100644 --- a/spec/system/consumer/multilingual_spec.rb +++ b/spec/system/consumer/multilingual_spec.rb @@ -100,7 +100,8 @@ describe 'Multilingual' do end describe "using the language switcher UI" do - before { browse_as_large } + around { |example| browse_as_large { example.run } } + 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 083b89256e..e4e66b41a3 100644 --- a/spec/system/consumer/white_label_spec.rb +++ b/spec/system/consumer/white_label_spec.rb @@ -32,13 +32,7 @@ describe 'White label setting' do shared_examples "hides the OFN navigation for mobile view as well" do context "mobile view" do - before do - browse_as_small - end - - after do - browse_as_default - end + around { |example| browse_as_small { example.run } } it "hides OFN navigation" do find("a.left-off-canvas-toggle").click @@ -55,13 +49,7 @@ describe 'White label setting' do shared_examples "does not hide the OFN navigation for mobile view as well" do context "mobile view" do - before do - browse_as_small - end - - after do - browse_as_default - end + around { |example| browse_as_small { example.run } } it "does not hide OFN navigation" do find("a.left-off-canvas-toggle").click From 4ecbbae55e112f086c4a98313fa85d2d3b2efef7 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Thu, 8 Jun 2023 12:04:10 +1000 Subject: [PATCH 8/8] Adapt large browser window as default We were really close to that anyway. It simplifies the code a bit. --- spec/support/request/ui_component_helper.rb | 6 +----- spec/system/consumer/authentication_spec.rb | 4 +--- spec/system/consumer/multilingual_spec.rb | 2 -- spec/system/support/cuprite_setup.rb | 2 +- 4 files changed, 3 insertions(+), 11 deletions(-) diff --git a/spec/support/request/ui_component_helper.rb b/spec/support/request/ui_component_helper.rb index 989efa40a0..ee7aedfbfe 100644 --- a/spec/support/request/ui_component_helper.rb +++ b/spec/support/request/ui_component_helper.rb @@ -10,14 +10,10 @@ module UIComponentHelper end def browse_as_default(&block) - browse_with_window_size(1200, 800) + browse_with_window_size(1280, 800) block&.call end - def browse_as_large(&block) - browse_with_window_size(1280, 800, &block) - end - def browse_with_window_size(width, height, &block) Capybara.current_session.current_window .resize_to(width, height) diff --git a/spec/system/consumer/authentication_spec.rb b/spec/system/consumer/authentication_spec.rb index a1ca62e60d..a9b1dbe3a6 100644 --- a/spec/system/consumer/authentication_spec.rb +++ b/spec/system/consumer/authentication_spec.rb @@ -24,9 +24,7 @@ describe "Authentication" do before do visit root_path end - describe "as large" do - around { |example| browse_as_large { example.run } } - + describe "with default large screen" do before do open_login_modal end diff --git a/spec/system/consumer/multilingual_spec.rb b/spec/system/consumer/multilingual_spec.rb index 556b59b893..66a94431fc 100644 --- a/spec/system/consumer/multilingual_spec.rb +++ b/spec/system/consumer/multilingual_spec.rb @@ -100,8 +100,6 @@ describe 'Multilingual' do end describe "using the language switcher UI" do - around { |example| browse_as_large { example.run } } - context "when there is only one language available" do before do allow(ENV).to receive(:[]).and_call_original 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,