From 0bec7562a09bb863776e6bc51346ba472af87c45 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Tue, 25 Apr 2023 17:22:42 +0200 Subject: [PATCH] When `hide_groups_tab` is set to false, do not display group in shopfront Co-Authored-By: Maikel --- app/helpers/shop_helper.rb | 8 ++++++- spec/system/consumer/white_label_spec.rb | 30 ++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/app/helpers/shop_helper.rb b/app/helpers/shop_helper.rb index 2f19c1d227..04709faf5d 100644 --- a/app/helpers/shop_helper.rb +++ b/app/helpers/shop_helper.rb @@ -24,7 +24,7 @@ module ShopHelper { name: 'about', title: t(:shopping_tabs_about), show: true }, { name: 'producers', title: t(:shopping_tabs_producers), show: true }, { name: 'contact', title: t(:shopping_tabs_contact), show: true }, - { name: 'groups', title: t(:shopping_tabs_groups), show: current_distributor.groups.any? }, + { name: 'groups', title: t(:shopping_tabs_groups), show: show_groups_tabs? }, ].select{ |tab| tab[:show] } end @@ -52,4 +52,10 @@ module ShopHelper true end + + private + + def show_groups_tabs? + !current_distributor.hide_groups_tab? && current_distributor.groups.any? + end end diff --git a/spec/system/consumer/white_label_spec.rb b/spec/system/consumer/white_label_spec.rb index 317a196d96..a4b46b5428 100644 --- a/spec/system/consumer/white_label_spec.rb +++ b/spec/system/consumer/white_label_spec.rb @@ -157,6 +157,36 @@ describe 'White label setting' do it_behaves_like "does not hide the OFN navigation" end + + context "manage hide_groups_tab preference when distributor belongs to a group" do + let(:group) { create(:enterprise_group) } + + before do + distributor.groups << group + end + + context "when the preference is set to true" do + before do + distributor.update_attribute(:hide_groups_tab, true) + end + + it "hides the groups tab" do + visit main_app.enterprise_shop_path(distributor) + expect(page).to have_no_selector "a[href='#groups']" + end + end + + context "when the preference is set to false" do + before do + distributor.update_attribute(:hide_groups_tab, false) + end + + it "shows the groups tab" do + visit main_app.enterprise_shop_path(distributor) + expect(page).to have_selector "a[href='#groups']" + end + end + end end context "manage the white_label_logo preference" do