diff --git a/app/components/admin/budgets/index_component.html.erb b/app/components/admin/budgets/index_component.html.erb
index d59fb2c58..fa4d60d4b 100644
--- a/app/components/admin/budgets/index_component.html.erb
+++ b/app/components/admin/budgets/index_component.html.erb
@@ -14,6 +14,7 @@
| <%= t("admin.budgets.index.table_name") %> |
<%= t("admin.budgets.index.table_phase") %> |
+ <%= t("admin.budgets.index.table_budget_type") %> |
<%= t("admin.budgets.index.table_duration") %> |
<%= t("admin.actions.actions") %> |
@@ -29,6 +30,7 @@
<%= budget.current_phase.name %>
<%= phase_progress_text(budget) %>
+ <%= type(budget) %> |
<%= dates(budget) %>
<%= duration(budget) %>
diff --git a/app/components/admin/budgets/index_component.rb b/app/components/admin/budgets/index_component.rb
index 58203a206..53f1d5d6f 100644
--- a/app/components/admin/budgets/index_component.rb
+++ b/app/components/admin/budgets/index_component.rb
@@ -26,6 +26,16 @@ class Admin::Budgets::IndexComponent < ApplicationComponent
budget.phases.enabled.order(:id).pluck(:kind).index(budget.phase) || -1
end
+ def type(budget)
+ if budget.single_heading?
+ t("admin.budgets.index.type_single")
+ elsif budget.headings.blank?
+ t("admin.budgets.index.type_pending")
+ else
+ t("admin.budgets.index.type_multiple")
+ end
+ end
+
def dates(budget)
Admin::Budgets::DurationComponent.new(budget).dates
end
diff --git a/app/models/budget.rb b/app/models/budget.rb
index f17b38f59..a1ee86954 100644
--- a/app/models/budget.rb
+++ b/app/models/budget.rb
@@ -162,6 +162,10 @@ class Budget < ApplicationRecord
current_phase&.balloting_or_later?
end
+ def single_heading?
+ groups.one? && headings.one?
+ end
+
def heading_price(heading)
heading_ids.include?(heading.id) ? heading.price : -1
end
diff --git a/config/locales/en/admin.yml b/config/locales/en/admin.yml
index 0ca710f60..647ad90fd 100644
--- a/config/locales/en/admin.yml
+++ b/config/locales/en/admin.yml
@@ -79,12 +79,16 @@ en:
open: Open
finished: Finished
budget_investments: Manage projects
+ table_budget_type: "Type"
table_completed: Completed
table_draft: "Draft"
table_duration: "Duration"
table_name: Name
table_phase: Phase
table_phase_progress: "(%{current_phase_number}/%{total_phases})"
+ type_multiple: "Multiple headings"
+ type_pending: "Pending: No headings yet"
+ type_single: "Single heading"
edit_groups: Edit headings groups
edit_budget: Edit budget
admin_ballots: Admin ballots
diff --git a/config/locales/es/admin.yml b/config/locales/es/admin.yml
index e164ad910..7971a0665 100644
--- a/config/locales/es/admin.yml
+++ b/config/locales/es/admin.yml
@@ -79,12 +79,16 @@ es:
open: Abiertos
finished: Terminados
budget_investments: Gestionar proyectos de gasto
+ table_budget_type: "Tipo"
table_completed: Completado
table_draft: "Borrador"
table_duration: "Duración"
table_name: Nombre
table_phase: Fase
table_phase_progress: "(%{current_phase_number}/%{total_phases})"
+ type_multiple: "Múltiples partidas"
+ type_pending: "Pendiente: Aún no hay partidas"
+ type_single: "Partida única"
edit_groups: Editar grupos de partidas
edit_budget: Editar presupuesto
admin_ballots: Gestionar urnas
diff --git a/spec/components/admin/budgets/index_component_spec.rb b/spec/components/admin/budgets/index_component_spec.rb
index c8e94ed6a..e55a30cc7 100644
--- a/spec/components/admin/budgets/index_component_spec.rb
+++ b/spec/components/admin/budgets/index_component_spec.rb
@@ -7,21 +7,54 @@ describe Admin::Budgets::IndexComponent, type: :component do
allow_any_instance_of(Admin::BudgetsController).to receive(:current_filter).and_return("all")
end
- it "displays current phase zero for budgets with no current phase" do
- budget = create(:budget, :accepting, name: "Not enabled phase")
- budget.phases.accepting.update!(enabled: false)
+ describe "#phase_progress_text" do
+ it "displays current phase zero for budgets with no current phase" do
+ budget = create(:budget, :accepting, name: "Not enabled phase")
+ budget.phases.accepting.update!(enabled: false)
- render_inline Admin::Budgets::IndexComponent.new(Budget.page(1))
+ render_inline Admin::Budgets::IndexComponent.new(Budget.page(1))
- expect(page.find("tr", text: "Not enabled phase")).to have_content "0/8"
+ expect(page.find("tr", text: "Not enabled phase")).to have_content "0/8"
+ end
+
+ it "displays phase zero out of zero for budgets with no enabled phases" do
+ budget = create(:budget, name: "Without phases")
+ budget.phases.each { |phase| phase.update!(enabled: false) }
+
+ render_inline Admin::Budgets::IndexComponent.new(Budget.page(1))
+
+ expect(page.find("tr", text: "Without phases")).to have_content "0/0"
+ end
end
- it "displays phase zero out of zero for budgets with no enabled phases" do
- budget = create(:budget, name: "Without phases")
- budget.phases.each { |phase| phase.update!(enabled: false) }
+ describe "#type" do
+ let(:budget) { create(:budget, name: "With type") }
- render_inline Admin::Budgets::IndexComponent.new(Budget.page(1))
+ it "displays 'single heading' for budgets with one heading" do
+ create(:budget_heading, budget: budget)
- expect(page.find("tr", text: "Without phases")).to have_content "0/0"
+ render_inline Admin::Budgets::IndexComponent.new(Budget.page(1))
+
+ expect(page.find("thead")).to have_content "Type"
+ expect(page.find("tr", text: "With type")).to have_content "Single heading"
+ end
+
+ it "displays 'multiple headings' for budgets with multiple headings" do
+ 2.times { create(:budget_heading, budget: budget) }
+
+ render_inline Admin::Budgets::IndexComponent.new(Budget.page(1))
+
+ expect(page.find("thead")).to have_content "Type"
+ expect(page.find("tr", text: "With type")).to have_content "Multiple headings"
+ end
+
+ it "displays 'pending: no headings yet' for budgets without headings" do
+ create(:budget, name: "Without headings")
+
+ render_inline Admin::Budgets::IndexComponent.new(Budget.page(1))
+
+ expect(page.find("thead")).to have_content "Type"
+ expect(page.find("tr", text: "Without headings")).to have_content "Pending: No headings yet"
+ end
end
end
diff --git a/spec/models/budget_spec.rb b/spec/models/budget_spec.rb
index bbe5835f1..75c2e0234 100644
--- a/spec/models/budget_spec.rb
+++ b/spec/models/budget_spec.rb
@@ -447,4 +447,43 @@ describe Budget do
expect(Valuator.count).to be 1
end
end
+
+ describe "#single_heading?" do
+ it "returns false for budgets with no groups nor headings" do
+ expect(create(:budget).single_heading?).to be false
+ end
+
+ it "returns false for budgets with one group and no headings" do
+ create(:budget_group, budget: budget)
+
+ expect(budget.single_heading?).to be false
+ end
+
+ it "returns false for budgets with multiple groups and one heading" do
+ 2.times { create(:budget_group, budget: budget) }
+ create(:budget_heading, group: budget.groups.last)
+
+ expect(budget.single_heading?).to be false
+ end
+
+ it "returns false for budgets with one group and multiple headings" do
+ group = create(:budget_group, budget: budget)
+ 2.times { create(:budget_heading, group: group) }
+
+ expect(budget.single_heading?).to be false
+ end
+
+ it "returns false for budgets with one group and multiple headings" do
+ 2.times { create(:budget_group, budget: budget) }
+ 2.times { create(:budget_heading, group: budget.groups.sample) }
+
+ expect(budget.single_heading?).to be false
+ end
+
+ it "returns true for budgets with one group and one heading" do
+ create(:budget_heading, group: create(:budget_group, budget: budget))
+
+ expect(budget.single_heading?).to be true
+ end
+ end
end
diff --git a/spec/system/admin/budgets_spec.rb b/spec/system/admin/budgets_spec.rb
index 9ea8780d2..b7c2b9395 100644
--- a/spec/system/admin/budgets_spec.rb
+++ b/spec/system/admin/budgets_spec.rb
@@ -30,8 +30,10 @@ describe "Admin budgets", :admin do
budget = create(:budget, :accepting)
visit admin_budgets_path
- expect(page).to have_content budget.name
- expect(page).to have_content "Accepting projects"
+ within "tr", text: budget.name do
+ expect(page).to have_content "Accepting projects"
+ expect(page).to have_content "Pending: No headings yet"
+ end
end
scenario "Filters by phase" do
|