Adapt heading step to single and multiple budget mode
Co-Authored-By: decabeza <alberto@decabeza.es>
This commit is contained in:
committed by
Javi Martín
parent
9fcae141a6
commit
e3510fc29d
@@ -1,3 +1,7 @@
|
||||
class Admin::BudgetsWizard::BaseComponent < ApplicationComponent
|
||||
delegate :single_heading?, :url_params, to: :helpers
|
||||
|
||||
def budget_mode
|
||||
helpers.budget_mode || "multiple"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -12,7 +12,11 @@ class Admin::BudgetsWizard::Headings::CreationStepComponent < ApplicationCompone
|
||||
end
|
||||
|
||||
def form_path
|
||||
admin_budgets_wizard_budget_group_headings_path(heading.group.budget, heading.group)
|
||||
if heading.persisted?
|
||||
admin_budgets_wizard_budget_group_heading_path(heading.group.budget, heading.group, heading)
|
||||
else
|
||||
admin_budgets_wizard_budget_group_headings_path(heading.group.budget, heading.group)
|
||||
end
|
||||
end
|
||||
|
||||
def next_step_path
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
<%= render Admin::Budgets::HelpComponent.new("budget_headings") %>
|
||||
<%= render Admin::BudgetsWizard::CreationTimelineComponent.new("headings") %>
|
||||
|
||||
<%= render Admin::BudgetsWizard::Headings::GroupSwitcherComponent.new(group) %>
|
||||
<%= render Admin::BudgetHeadings::HeadingsComponent.new(headings) %>
|
||||
<% unless single_heading? %>
|
||||
<%= render Admin::BudgetsWizard::Headings::GroupSwitcherComponent.new(group) %>
|
||||
<%= render Admin::BudgetHeadings::HeadingsComponent.new(headings) %>
|
||||
<% end %>
|
||||
<%= render Admin::BudgetsWizard::Headings::CreationStepComponent.new(new_heading) %>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<%= back_link_to back_link_path, t("admin.budgets_wizard.phases.back") %>
|
||||
<%= back_link_to back_link_path, back_link_text %>
|
||||
|
||||
<%= header %>
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class Admin::BudgetsWizard::Phases::IndexComponent < ApplicationComponent
|
||||
class Admin::BudgetsWizard::Phases::IndexComponent < Admin::BudgetsWizard::BaseComponent
|
||||
include Header
|
||||
attr_reader :budget
|
||||
|
||||
@@ -13,6 +13,10 @@ class Admin::BudgetsWizard::Phases::IndexComponent < ApplicationComponent
|
||||
private
|
||||
|
||||
def back_link_path
|
||||
admin_budgets_wizard_budget_group_headings_path(budget, budget.groups.first)
|
||||
admin_budgets_wizard_budget_group_headings_path(budget, budget.groups.first, url_params)
|
||||
end
|
||||
|
||||
def back_link_text
|
||||
t("admin.budgets_wizard.phases.#{budget_mode}.back")
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,13 +4,21 @@ class Admin::BudgetsWizard::HeadingsController < Admin::BudgetsWizard::BaseContr
|
||||
before_action :load_headings, only: [:index, :create]
|
||||
|
||||
def index
|
||||
@heading = @group.headings.new
|
||||
if single_heading?
|
||||
@heading = @group.headings.first_or_initialize
|
||||
else
|
||||
@heading = @group.headings.new
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def headings_index
|
||||
admin_budgets_wizard_budget_group_headings_path(@budget, @group)
|
||||
if single_heading?
|
||||
admin_budgets_wizard_budget_budget_phases_path(@budget, url_params)
|
||||
else
|
||||
admin_budgets_wizard_budget_group_headings_path(@budget, @group, url_params)
|
||||
end
|
||||
end
|
||||
|
||||
def new_action
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class Admin::BudgetsWizard::PhasesController < Admin::BaseController
|
||||
class Admin::BudgetsWizard::PhasesController < Admin::BudgetsWizard::BaseController
|
||||
include Admin::BudgetPhasesActions
|
||||
|
||||
def index
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
|
||||
<%= render "shared/errors", resource: heading %>
|
||||
|
||||
<%= render Admin::BudgetsWizard::ModelFieldComponent.new %>
|
||||
|
||||
<%= f.translatable_fields do |translations_form| %>
|
||||
<div class="small-12 medium-6 column end">
|
||||
<%= translations_form.text_field :name, maxlength: 50 %>
|
||||
@@ -35,6 +37,10 @@
|
||||
</div>
|
||||
|
||||
<div class="clear">
|
||||
<%= f.submit t("admin.budget_headings.form.#{action}"), class: "button hollow" %>
|
||||
<% if respond_to?(:single_heading?) && single_heading? %>
|
||||
<%= f.submit t("admin.budgets_wizard.headings.continue"), class: "button success" %>
|
||||
<% else %>
|
||||
<%= f.submit t("admin.budget_headings.form.#{action}"), class: "button hollow" %>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
@@ -330,8 +330,11 @@ en:
|
||||
title: "<strong>Single heading</strong> budget"
|
||||
title: "Participatory budget type"
|
||||
phases:
|
||||
back: "Go back to headings"
|
||||
continue: "Finish"
|
||||
multiple:
|
||||
back: "Go back to headings"
|
||||
single:
|
||||
back: "Go back to edit heading"
|
||||
update_all:
|
||||
notice: "Phases configured successfully"
|
||||
milestones:
|
||||
|
||||
@@ -330,8 +330,11 @@ es:
|
||||
title: "Presupuesto de <strong>partida única</strong>"
|
||||
title: Tipo de presupuesto participativo
|
||||
phases:
|
||||
back: "Volver a partidas"
|
||||
continue: "Finalizar"
|
||||
multiple:
|
||||
back: "Volver a partidas"
|
||||
single:
|
||||
back: "Volver a editar partida"
|
||||
update_all:
|
||||
notice: "Fases configuradas con éxito"
|
||||
milestones:
|
||||
|
||||
@@ -118,6 +118,29 @@ describe "Budgets wizard, headings step", :admin do
|
||||
expect(page).to have_css ".creation-timeline"
|
||||
expect(page).to have_css "td", exact_text: "Heading without typos"
|
||||
end
|
||||
|
||||
scenario "update heading in single heading budget" do
|
||||
visit admin_budgets_wizard_budget_group_headings_path(budget, group, mode: "single")
|
||||
fill_in "Heading name", with: "Heading wiht typo"
|
||||
fill_in "Money amount", with: "300000"
|
||||
click_button "Continue to phases"
|
||||
|
||||
expect(page).to have_content "Heading created successfully"
|
||||
|
||||
click_link "Go back to edit heading"
|
||||
|
||||
expect(page).to have_field "Heading name", with: "Heading wiht typo"
|
||||
|
||||
fill_in "Heading name", with: "Heading without typos"
|
||||
click_button "Continue to phases"
|
||||
|
||||
expect(page).to have_content "Heading updated successfully"
|
||||
|
||||
visit admin_budget_group_headings_path(budget, group)
|
||||
|
||||
expect(page).to have_content "There is 1 heading"
|
||||
within("tbody tr") { expect(page).to have_content "Heading without typos" }
|
||||
end
|
||||
end
|
||||
|
||||
describe "Destroy" do
|
||||
|
||||
@@ -15,6 +15,12 @@ describe "Budgets creation wizard", :admin do
|
||||
click_button "Continue to headings"
|
||||
|
||||
expect(page).to have_content "Group created successfully"
|
||||
|
||||
fill_in "Heading name", with: "One and only heading"
|
||||
fill_in "Money amount", with: "1000000"
|
||||
click_button "Continue to phases"
|
||||
|
||||
expect(page).to have_css ".budget-phases-table"
|
||||
end
|
||||
|
||||
scenario "Creation of a multiple-headings budget by steps" do
|
||||
@@ -47,5 +53,38 @@ describe "Budgets creation wizard", :admin do
|
||||
|
||||
expect(page).to have_content "Showing headings from the All city group"
|
||||
expect(page).to have_content "There are no headings."
|
||||
|
||||
click_button "Add new heading"
|
||||
fill_in "Heading name", with: "All city"
|
||||
fill_in "Money amount", with: "1000000"
|
||||
click_button "Create new heading"
|
||||
|
||||
expect(page).to have_content "Heading created successfully!"
|
||||
within("table") { expect(page).to have_content "All city" }
|
||||
expect(page).not_to have_content "There are no headings."
|
||||
|
||||
click_link "Manage headings from the Districts group."
|
||||
expect(page).to have_content "There are no headings."
|
||||
|
||||
click_button "Add new heading"
|
||||
fill_in "Heading name", with: "North"
|
||||
fill_in "Money amount", with: "500000"
|
||||
click_button "Create new heading"
|
||||
|
||||
expect(page).to have_content "Heading created successfully!"
|
||||
within("table") { expect(page).to have_content "North" }
|
||||
expect(page).not_to have_content "There are no headings."
|
||||
|
||||
click_button "Add new heading"
|
||||
fill_in "Heading name", with: "South"
|
||||
fill_in "Money amount", with: "500000"
|
||||
click_button "Create new heading"
|
||||
|
||||
expect(page).to have_content "Heading created successfully!"
|
||||
within("table") { expect(page).to have_content "South" }
|
||||
|
||||
click_link "Continue to phases"
|
||||
|
||||
expect(page).to have_css ".budget-phases-table"
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user