From 4d97d349a1e6c8a5c710d77b920d9ed666265f1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa=20Checa?= Date: Mon, 15 Jan 2018 23:21:04 +0100 Subject: [PATCH] Added tests for alert --- .../features/admin/budget_investments_spec.rb | 44 +++++++++++++++++++ spec/features/emails_spec.rb | 2 +- .../valuation/budget_investments_spec.rb | 2 +- 3 files changed, 46 insertions(+), 2 deletions(-) diff --git a/spec/features/admin/budget_investments_spec.rb b/spec/features/admin/budget_investments_spec.rb index e20ec2b32..627824045 100644 --- a/spec/features/admin/budget_investments_spec.rb +++ b/spec/features/admin/budget_investments_spec.rb @@ -508,6 +508,50 @@ feature 'Admin budget investments' do 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) diff --git a/spec/features/emails_spec.rb b/spec/features/emails_spec.rb index f4bd7e08e..16be1cbf4 100644 --- a/spec/features/emails_spec.rb +++ b/spec/features/emails_spec.rb @@ -396,7 +396,7 @@ feature 'Emails' do 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" diff --git a/spec/features/valuation/budget_investments_spec.rb b/spec/features/valuation/budget_investments_spec.rb index 7bd955e0e..33ab47b8e 100644 --- a/spec/features/valuation/budget_investments_spec.rb +++ b/spec/features/valuation/budget_investments_spec.rb @@ -345,7 +345,7 @@ feature 'Valuation budget investments' do 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)