From f0665b08623a0f8a6daf620aec41dba5c308c110 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Bellet Date: Wed, 24 May 2023 17:01:36 +0200 Subject: [PATCH] Add custom tab on shop --- app/helpers/shop_helper.rb | 10 +++++++ app/views/shopping_shared/_tabs.html.haml | 5 +++- .../shopping_shared/tabs/_custom.html.haml | 3 ++ spec/system/consumer/white_label_spec.rb | 28 +++++++++++++++++++ 4 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 app/views/shopping_shared/tabs/_custom.html.haml diff --git a/app/helpers/shop_helper.rb b/app/helpers/shop_helper.rb index 03aaaf148e..469316ae01 100644 --- a/app/helpers/shop_helper.rb +++ b/app/helpers/shop_helper.rb @@ -27,9 +27,19 @@ module ShopHelper { 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: show_groups_tabs? }, + custom_tab, ].select{ |tab| tab[:show] } end + def custom_tab + { + name: current_distributor.custom_tab&.title&.parameterize, + title: current_distributor.custom_tab&.title, + show: current_distributor.custom_tab.present?, + custom: true, + } + end + def shop_tab_names shop_tabs.map { |tab| tab[:name] } end diff --git a/app/views/shopping_shared/_tabs.html.haml b/app/views/shopping_shared/_tabs.html.haml index b8c0a8ab8f..299ad71567 100644 --- a/app/views/shopping_shared/_tabs.html.haml +++ b/app/views/shopping_shared/_tabs.html.haml @@ -12,4 +12,7 @@ - shop_tabs.each do |tab| %div{id: "#{tab[:name]}_panel", "data-tabs-and-panels-target": "panel #{'default' if tab[:default]}" } .page-view - = render "shopping_shared/tabs/#{tab[:name]}" + - if tab[:custom] + = render "shopping_shared/tabs/custom", order: @order + - else + = render "shopping_shared/tabs/#{tab[:name]}" diff --git a/app/views/shopping_shared/tabs/_custom.html.haml b/app/views/shopping_shared/tabs/_custom.html.haml new file mode 100644 index 0000000000..5c6cf17465 --- /dev/null +++ b/app/views/shopping_shared/tabs/_custom.html.haml @@ -0,0 +1,3 @@ +.content + .row + = @distributor.custom_tab.content diff --git a/spec/system/consumer/white_label_spec.rb b/spec/system/consumer/white_label_spec.rb index cf2471f61f..2629a47cbe 100644 --- a/spec/system/consumer/white_label_spec.rb +++ b/spec/system/consumer/white_label_spec.rb @@ -352,4 +352,32 @@ describe 'White label setting' do end end end + + context "manage the custom tab preference" do + context "when the distributor has a custom tab" do + let(:custom_tab) { create(:custom_tab) } + + before do + distributor.update(custom_tab: custom_tab) + visit main_app.enterprise_shop_path(distributor) + end + + it "shows the custom tab on shop page" do + expect(page).to have_selector(".tab-buttons .page", count: 5) + expect(page).to have_content custom_tab.title + end + + it "shows the custom tab content when clicking on tab title" do + click_link custom_tab.title + expect(page).to have_content custom_tab.content + end + end + + context "when the distributor has no custom tab" do + it "does not show the custom tab on shop page" do + visit main_app.enterprise_shop_path(distributor) + expect(page).to have_selector(".tab-buttons .page", count: 4) + end + end + end end