Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investment valuation finished alert #2324

Merged
merged 4 commits into from
Jan 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/assets/javascripts/application.js
Expand Up @@ -74,6 +74,7 @@
//= require polls
//= require sortable
//= require table_sortable
//= require investment_report_alert

var initialize_modules = function() {
App.Comments.initialize();
Expand Down Expand Up @@ -115,6 +116,7 @@ var initialize_modules = function() {
App.Polls.initialize();
App.Sortable.initialize();
App.TableSortable.initialize();
App.InvestmentReportAlert.initialize();
};

$(function(){
Expand Down
7 changes: 7 additions & 0 deletions app/assets/javascripts/investment_report_alert.js.coffee
@@ -0,0 +1,7 @@
App.InvestmentReportAlert =
initialize: ->
$('#js-investment-report-alert').on 'click', ->
if this.checked && $('#budget_investment_feasibility_unfeasible').is(':checked')
confirm(this.dataset.alert + "\n" + this.dataset.notFeasibleAlert);
else if this.checked
confirm(this.dataset.alert);
6 changes: 5 additions & 1 deletion app/views/valuation/budget_investments/edit.html.erb
Expand Up @@ -79,7 +79,11 @@
<div class="row">
<div class="small-12 medium-8 column">
<%= f.label :valuation_finished do %>
<%= f.check_box :valuation_finished, title: t('valuation.budget_investments.edit.valuation_finished'), label: false %>
<%= f.check_box :valuation_finished,
title: t('valuation.budget_investments.edit.valuation_finished'),
label: false, id: 'js-investment-report-alert',
"data-alert": t("valuation.budget_investments.edit.valuation_finished_alert"),
"data-not-feasible-alert": t("valuation.budget_investments.edit.not_feasible_alert") %>
<span class="checkbox"><%= t("valuation.budget_investments.edit.valuation_finished") %></span>
<% end %>
</div>
Expand Down
4 changes: 3 additions & 1 deletion config/locales/en/valuation.yml
Expand Up @@ -68,6 +68,8 @@ en:
undefined_feasible: Pending
feasible_explanation_html: Feasibility explanation
valuation_finished: Valuation finished
valuation_finished_alert: "Are you sure you want to mark this report as completed? If you do it, it can no longer be modified."
not_feasible_alert: "An email will be sent immediately to the author of the project with the report of unfeasibility."
duration_html: Time scope
internal_comments_html: Internal comments
save: Save changes
Expand Down Expand Up @@ -121,4 +123,4 @@ en:
internal_comments_html: Internal comments
save: Save changes
notice:
valuate: "Dossier updated"
valuate: "Dossier updated"
2 changes: 2 additions & 0 deletions config/locales/es/valuation.yml
Expand Up @@ -68,6 +68,8 @@ es:
undefined_feasible: Sin decidir
feasible_explanation_html: Informe de inviabilidad <small>(en caso de que lo sea, dato p煤blico)</small>
valuation_finished: Informe finalizado
valuation_finished_alert: "驴Est谩s seguro/a de querer marcar este informe como completado? Una vez hecho, no se puede deshacer la acci贸n."
not_feasible_alert: "Un email ser谩 enviado inmediatamente al autor del proyecto con el informe de inviabilidad."
duration_html: Plazo de ejecuci贸n <small>(opcional, dato no p煤blico)</small>
internal_comments_html: Comentarios y observaciones <small>(para responsables internos, dato no p煤blico)</small>
save: Guardar Cambios
Expand Down
44 changes: 44 additions & 0 deletions spec/features/admin/budget_investments_spec.rb
Expand Up @@ -508,6 +508,50 @@
expect(page).not_to have_content "Refugees, Solidarity"
end

scenario "Shows alert when 'Valuation finished' is checked", :js do
budget_investment = create(:budget_investment)

visit admin_budget_budget_investment_path(budget_investment.budget, budget_investment)
click_link 'Edit dossier'

expect(page).to have_content 'Valuation finished'

find_field('budget_investment[valuation_finished]').click

page.accept_confirm("Are you sure you want to mark this report as completed? If you do it, it can no longer be modified.")

expect(page).to have_field('budget_investment[valuation_finished]', checked: true)
end

scenario "Shows alert with unfeasible status when 'Valuation finished' is checked", :js do
budget_investment = create(:budget_investment)

visit admin_budget_budget_investment_path(budget_investment.budget, budget_investment)
click_link 'Edit dossier'

expect(page).to have_content 'Valuation finished'

find_field('budget_investment_feasibility_unfeasible').click
find_field('budget_investment[valuation_finished]').click

page.accept_confirm("Are you sure you want to mark this report as completed? If you do it, it can no longer be modified.\nAn email will be sent immediately to the author of the project with the report of unfeasibility.")

expect(page).to have_field('budget_investment[valuation_finished]', checked: true)
end

scenario "Undoes check in 'Valuation finished' if user clicks 'cancel' on alert", :js do
budget_investment = create(:budget_investment)

visit admin_budget_budget_investment_path(budget_investment.budget, budget_investment)
click_link 'Edit dossier'

dismiss_confirm do
find_field('budget_investment[valuation_finished]').click
end

expect(page).to have_field('budget_investment[valuation_finished]', checked: false)
end

scenario "Errors on update" do
budget_investment = create(:budget_investment)

Expand Down
2 changes: 1 addition & 1 deletion spec/features/emails_spec.rb
Expand Up @@ -396,7 +396,7 @@

choose 'budget_investment_feasibility_unfeasible'
fill_in 'budget_investment_unfeasibility_explanation', with: 'This is not legal as stated in Article 34.9'
check 'budget_investment_valuation_finished'
find_field('budget_investment[valuation_finished]').click
click_button 'Save changes'

expect(page).to have_content "Dossier updated"
Expand Down
2 changes: 1 addition & 1 deletion spec/features/valuation/budget_investments_spec.rb
Expand Up @@ -345,7 +345,7 @@
visit valuation_budget_budget_investment_path(@budget, @investment)
click_link 'Edit dossier'

check 'budget_investment_valuation_finished'
find_field('budget_investment[valuation_finished]').click
click_button 'Save changes'

visit valuation_budget_budget_investments_path(@budget)
Expand Down