Modifications to the spec to avoid using wait_for_ajax

This commit is contained in:
iagirre
2018-02-14 08:57:48 +01:00
parent e2a91c6cc8
commit d02b3e0486

View File

@@ -947,91 +947,104 @@ feature 'Admin budget investments' do
end end
context "Mark as visible to valuators" do context "Mark as visible to valuators" do
let(:group) { create(:budget_group, budget: @budget) } let(:valuator) { create(:valuator) }
let(:admin) { create(:administrator) }
let(:group) { create(:budget_group, budget: budget) }
let(:heading) { create(:budget_heading, group: group) } let(:heading) { create(:budget_heading, group: group) }
let(:investment1) { create(:budget_investment, heading: heading) }
let(:investment2) { create(:budget_investment, heading: heading) }
scenario "Mark as visible to valuator", :js do scenario "Mark as visible to valuator", :js do
valuator = create(:valuator)
investment1 = create(:budget_investment, heading: heading, administrator_id: @admin.id)
investment2 = create(:budget_investment, heading: heading, administrator_id: @admin.id)
investment1.valuators << valuator investment1.valuators << valuator
investment2.valuators << valuator investment2.valuators << valuator
investment1.update(administrator: admin)
investment2.update(administrator: admin)
visit admin_budget_budget_investments_path(@budget) visit admin_budget_budget_investments_path(budget)
within('#filter-subnav') { click_link 'Under valuation' } within('#filter-subnav') { click_link 'Under valuation' }
within("#budget_investment_#{investment1.id}") do within("#budget_investment_#{investment1.id}") do
check "budget_investment_visible_to_valuators" check "budget_investment_visible_to_valuators"
end end
wait_for_ajax visit admin_budget_budget_investments_path(budget)
within('#filter-subnav') { click_link 'Under valuation' }
login_as(valuator.user) within("#budget_investment_#{investment1.id}") do
visit valuation_root_path expect(find("#budget_investment_visible_to_valuators")).to be_checked
end
end
within "#budget_#{@budget.id}" do scenario "Shows the correct investments to valuators" do
investment1.update(visible_to_valuators: true)
investment2.update(visible_to_valuators: false)
investment1.valuators << valuator
investment2.valuators << valuator
investment1.update(administrator: admin)
investment2.update(administrator: admin)
login_as(valuator.user.reload)
visit root_path
click_link "Admin"
click_link "Valuation"
within "#budget_#{budget.id}" do
click_link "Evaluate" click_link "Evaluate"
end end
expect(page).to have_content investment1.title expect(page).to have_content investment1.title
expect(page).not_to have_content investment2.title expect(page).not_to have_content investment2.title
end end
scenario "Unmark as visible to valuator", :js do scenario "Unmark as visible to valuator", :js do
valuator = create(:valuator) Setting['feature.budgets.valuators_allowed'] = true
investment1 = create(:budget_investment, heading: heading, visible_to_valuators: true, administrator_id: @admin.id)
investment2 = create(:budget_investment, heading: heading, visible_to_valuators: true, administrator_id: @admin.id)
investment1.valuators << valuator investment1.valuators << valuator
investment2.valuators << valuator investment2.valuators << valuator
investment1.update(administrator: admin)
investment2.update(administrator: admin)
visit admin_budget_budget_investments_path(@budget) visit admin_budget_budget_investments_path(budget)
within('#filter-subnav') { click_link 'Under valuation' } within('#filter-subnav') { click_link 'Under valuation' }
within("#budget_investment_#{investment1.id}") do within("#budget_investment_#{investment1.id}") do
uncheck "budget_investment_visible_to_valuators" uncheck "budget_investment_visible_to_valuators"
end end
wait_for_ajax visit admin_budget_budget_investments_path(budget)
within('#filter-subnav') { click_link 'Under valuation' }
login_as(valuator.user) within("#budget_investment_#{investment1.id}") do
visit valuation_root_path expect(find("#budget_investment_visible_to_valuators")).not_to be_checked
within "#budget_#{@budget.id}" do
click_link "Evaluate"
end end
expect(page).not_to have_content investment1.title
expect(page).to have_content investment2.title
end end
scenario "Showing the valuating checkbox" do scenario "Showing the valuating checkbox" do
investment1 = create(:budget_investment, heading: heading, visible_to_valuators: true, administrator_id: @admin.id) investment1 = create(:budget_investment, budget: budget, visible_to_valuators: true)
investment2 = create(:budget_investment, heading: heading, visible_to_valuators: false, administrator_id: @admin.id) investment2 = create(:budget_investment, budget: budget, visible_to_valuators: false)
investment1.valuators << create(:valuator) investment1.valuators << create(:valuator)
investment2.valuators << create(:valuator) investment2.valuators << create(:valuator)
investment2.valuators << create(:valuator)
investment1.update(administrator: create(:administrator))
investment2.update(administrator: create(:administrator))
visit admin_budget_budget_investments_path(@budget) visit admin_budget_budget_investments_path(budget)
within('#filter-subnav') do
expect(page).not_to have_link "All"
expect(page).to have_content "All"
end
expect(page).not_to have_css("#budget_investment_visible_to_valuators")
expect(page).not_to have_css("#budget_investment_visible_to_valuators") expect(page).not_to have_css("#budget_investment_visible_to_valuators")
within('#filter-subnav') { click_link 'Under valuation' } within('#filter-subnav') { click_link 'Under valuation' }
within("#budget_investment_#{investment1.id}") do within("#budget_investment_#{investment1.id}") do
valuating_checkbox = find("#budget_investment_visible_to_valuators") valuating_checkbox = find('#budget_investment_visible_to_valuators')
expect(valuating_checkbox).to be_checked expect(valuating_checkbox).to be_checked
end end
within("#budget_investment_#{investment2.id}") do within("#budget_investment_#{investment2.id}") do
valuating_checkbox = find("#budget_investment_visible_to_valuators") valuating_checkbox = find('#budget_investment_visible_to_valuators')
expect(valuating_checkbox).not_to be_checked expect(valuating_checkbox).not_to be_checked
end end
end end