mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Add custom tab on shop
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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]}"
|
||||
|
||||
3
app/views/shopping_shared/tabs/_custom.html.haml
Normal file
3
app/views/shopping_shared/tabs/_custom.html.haml
Normal file
@@ -0,0 +1,3 @@
|
||||
.content
|
||||
.row
|
||||
= @distributor.custom_tab.content
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user