Render investments list in all budgets types

We make this change to unify the index/show budget pages.

This way both single and multiple budgets will render the investments
list component.
This commit is contained in:
taitus
2021-07-26 10:31:12 +02:00
committed by Javi Martín
parent f92796c7fa
commit c6b23bb6fa
6 changed files with 38 additions and 19 deletions

View File

@@ -10,7 +10,7 @@
</section>
<% end %>
<% unless budget.informing? %>
<% if budget.single_heading? && !budget.informing? || investments.any? %>
<div class="row margin-top">
<div class="small-12 medium-6 large-4 small-centered column margin-top">
<%= link_to t("budgets.investments_list.see_all"),

View File

@@ -5,10 +5,6 @@ class Budgets::InvestmentsListComponent < ApplicationComponent
@budget = budget
end
def render?
budget.single_heading?
end
def investments(limit: 9)
case budget.phase
when "accepting", "reviewing"

View File

@@ -18,12 +18,10 @@
<p><%= t("budgets.supports_info.share") %></p>
<% if budget.single_heading? %>
<p>
<a href="#investments_list" class="keep-scrolling" data-smooth-scroll>
<%= t("budgets.supports_info.scrolling") %><br>
</a>
</p>
<% end %>
<p>
<a href="#investments_list" class="keep-scrolling" data-smooth-scroll>
<%= t("budgets.supports_info.scrolling") %><br>
</a>
</p>
</section>
</aside>

View File

@@ -115,15 +115,15 @@ describe Budgets::InvestmentsListComponent, type: :component do
end
end
it "is not rendered for budgets with multiple headings" do
it "is rendered for budgets with multiple headings" do
create(:budget_heading, budget: budget)
Budget::Phase::PHASE_KINDS.each do |phase_name|
(Budget::Phase::PHASE_KINDS - %w[informing finished]).each do |phase_name|
budget.phase = phase_name
render_inline Budgets::InvestmentsListComponent.new(budget)
expect(page.native.inner_html).to be_empty
expect(page).to have_content "List of investments"
end
end
end
@@ -149,5 +149,30 @@ describe Budgets::InvestmentsListComponent, type: :component do
href: budget_investments_path(budget)
end
end
context "budget with multiple headings" do
before { create(:budget_heading, budget: budget) }
it "is not shown in the informing or finished phases" do
%w[informing finished].each do |phase_name|
budget.phase = phase_name
render_inline Budgets::InvestmentsListComponent.new(budget)
expect(page).not_to have_link "See all investments"
end
end
it "is shown in all other phases" do
(Budget::Phase::PHASE_KINDS - %w[informing finished]).each do |phase_name|
budget.phase = phase_name
render_inline Budgets::InvestmentsListComponent.new(budget)
expect(page).to have_link "See all investments",
href: budget_investments_path(budget)
end
end
end
end
end

View File

@@ -16,12 +16,12 @@ describe Budgets::SupportsInfoComponent, type: :component do
expect(page).to have_link "Keep scrolling to see all ideas"
end
it "when budget has multiple headings the link to see all ideas is not rendered" do
it "renders the link to see all ideas when there are multiple headings" do
create_list(:budget_heading, 2, group: group)
render_inline component
expect(page).not_to have_link "Keep scrolling to see all ideas"
expect(page).to have_link "Keep scrolling to see all ideas"
end
it "does not render anything when the budget is not selecting" do

View File

@@ -319,7 +319,7 @@ describe "Budgets" do
href: budget_investments_path(budget)
end
scenario "Do not show investments list when budget has multiple headings" do
scenario "Show investments list when budget has multiple headings" do
budget = create(:budget, phase: "accepting")
group = create(:budget_group, budget: budget)
heading_1 = create(:budget_heading, group: group)
@@ -329,7 +329,7 @@ describe "Budgets" do
visit budget_path(budget)
expect(page).not_to have_css ".investments-list"
expect(page).to have_css ".investments-list"
end
scenario "Show supports info on selecting phase" do