Add type to budget index table
Co-Authored-By: decabeza <alberto@decabeza.es>
This commit is contained in:
committed by
Javi Martín
parent
51bca66533
commit
17b4fb58c9
@@ -14,6 +14,7 @@
|
||||
<tr>
|
||||
<th><%= t("admin.budgets.index.table_name") %></th>
|
||||
<th><%= t("admin.budgets.index.table_phase") %></th>
|
||||
<th><%= t("admin.budgets.index.table_budget_type") %></th>
|
||||
<th><%= t("admin.budgets.index.table_duration") %></th>
|
||||
<th><%= t("admin.actions.actions") %></th>
|
||||
</tr>
|
||||
@@ -29,6 +30,7 @@
|
||||
<%= budget.current_phase.name %>
|
||||
<small><%= phase_progress_text(budget) %></small>
|
||||
</td>
|
||||
<td><%= type(budget) %></td>
|
||||
<td>
|
||||
<%= dates(budget) %>
|
||||
<%= duration(budget) %>
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -7,6 +7,7 @@ describe Admin::Budgets::IndexComponent, type: :component do
|
||||
allow_any_instance_of(Admin::BudgetsController).to receive(:current_filter).and_return("all")
|
||||
end
|
||||
|
||||
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)
|
||||
@@ -25,3 +26,35 @@ describe Admin::Budgets::IndexComponent, type: :component do
|
||||
expect(page.find("tr", text: "Without phases")).to have_content "0/0"
|
||||
end
|
||||
end
|
||||
|
||||
describe "#type" do
|
||||
let(:budget) { create(:budget, name: "With type") }
|
||||
|
||||
it "displays 'single heading' for budgets with one heading" do
|
||||
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 "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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -30,8 +30,10 @@ describe "Admin budgets", :admin do
|
||||
budget = create(:budget, :accepting)
|
||||
visit admin_budgets_path
|
||||
|
||||
expect(page).to have_content budget.name
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user