mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
remove group tabs from shop view when there are no groups
This commit is contained in:
@@ -20,12 +20,27 @@ module ShopHelper
|
||||
)
|
||||
end
|
||||
|
||||
def shop_tabs
|
||||
def base_shop_tabs(column_sizes)
|
||||
[
|
||||
{ name: 'about', title: t(:shopping_tabs_about, distributor: current_distributor.name), cols: 6 },
|
||||
{ name: 'producers', title: t(:label_producers), cols: 2 },
|
||||
{ name: 'contact', title: t(:shopping_tabs_contact), cols: 2 },
|
||||
{ name: 'groups', title: t(:label_groups), cols: 2 },
|
||||
{ name: 'about', cols: column_sizes[0],
|
||||
title: t(:shopping_tabs_about, distributor: current_distributor.name) },
|
||||
{ name: 'producers', cols: column_sizes[1],
|
||||
title: t(:label_producers) },
|
||||
{ name: 'contact', cols: column_sizes[2],
|
||||
title: t(:shopping_tabs_contact) }
|
||||
]
|
||||
end
|
||||
|
||||
def tabs_with_groups
|
||||
tabs = base_shop_tabs([6, 2, 2])
|
||||
tabs << { name: 'groups', title: t(:label_groups), cols: 2 }
|
||||
end
|
||||
|
||||
def tabs_without_groups
|
||||
base_shop_tabs([4, 4, 4])
|
||||
end
|
||||
|
||||
def shop_tabs
|
||||
current_distributor.groups.present? ? tabs_with_groups : tabs_without_groups
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,4 +7,46 @@ describe ShopHelper, type: :helper do
|
||||
|
||||
expect(helper.order_cycles_name_and_pickup_times([o1])).to eq([[helper.pickup_time(o1), o1.id]])
|
||||
end
|
||||
|
||||
describe "shop_tabs" do
|
||||
context "distributor with groups" do
|
||||
let(:group) { create(:enterprise_group) }
|
||||
let(:distributor) { create(:distributor_enterprise, groups: [group]) }
|
||||
let(:expectation) {
|
||||
[
|
||||
{ name: 'about', title: t(:shopping_tabs_about, distributor: distributor.name), cols: 6 },
|
||||
{ name: 'producers', title: t(:label_producers), cols: 2 },
|
||||
{ name: 'contact', title: t(:shopping_tabs_contact), cols: 2 },
|
||||
{ name: 'groups', title: t(:label_groups), cols: 2 }
|
||||
]
|
||||
}
|
||||
|
||||
before do
|
||||
allow(helper).to receive(:current_distributor).and_return distributor
|
||||
end
|
||||
|
||||
it "should return the groups tab" do
|
||||
expect(helper.shop_tabs).to eq(expectation)
|
||||
end
|
||||
end
|
||||
|
||||
context "distributor without groups" do
|
||||
let(:distributor) { create(:distributor_enterprise) }
|
||||
let(:expectation) {
|
||||
[
|
||||
{ name: 'about', title: t(:shopping_tabs_about, distributor: distributor.name), cols: 4 },
|
||||
{ name: 'producers', title: t(:label_producers), cols: 4 },
|
||||
{ name: 'contact', title: t(:shopping_tabs_contact), cols: 4 }
|
||||
]
|
||||
}
|
||||
|
||||
before do
|
||||
allow(helper).to receive(:current_distributor).and_return distributor
|
||||
end
|
||||
|
||||
it "should not return the groups tab" do
|
||||
expect(helper.shop_tabs).to eq(expectation)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user