Add custom tab on shop

This commit is contained in:
Jean-Baptiste Bellet
2023-05-24 17:01:36 +02:00
parent 916b2313ab
commit f0665b0862
4 changed files with 45 additions and 1 deletions

View File

@@ -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

View File

@@ -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]}"

View File

@@ -0,0 +1,3 @@
.content
.row
= @distributor.custom_tab.content

View File

@@ -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