Merge pull request #4920 from consul/budget_results_tests

Fix flaky budget results tests
This commit is contained in:
Javi Martín
2022-08-25 15:32:39 +02:00
committed by GitHub
2 changed files with 47 additions and 48 deletions

View File

@@ -83,5 +83,20 @@ describe Budget::Result do
expect(heading.investments.winners.pluck(:ballot_lines_count)).to match_array([900, 800, 700])
end
end
context "budget with the hide money option" do
before { budget.update!(voting_style: "approval", hide_money: true) }
it "does not take the price into account" do
create(:budget_investment, :selected, heading: heading, price: 100, ballot_lines_count: 500)
create(:budget_investment, :incompatible, heading: heading, price: 300, ballot_lines_count: 800)
create(:budget_investment, :selected, heading: heading, price: 800, ballot_lines_count: 700)
create(:budget_investment, :selected, heading: heading, price: 500, ballot_lines_count: 600)
Budget::Result.new(budget, heading).calculate_winners
expect(heading.investments.winners.pluck(:ballot_lines_count)).to match_array([700, 600, 500])
end
end
end
end

View File

@@ -5,12 +5,12 @@ describe "Results" do
let(:group) { create(:budget_group, budget: budget) }
let(:heading) { create(:budget_heading, group: group, price: 1000) }
let!(:investment1) { create(:budget_investment, :selected, heading: heading, price: 200, ballot_lines_count: 900) }
let!(:investment2) { create(:budget_investment, :selected, heading: heading, price: 300, ballot_lines_count: 800) }
let!(:investment3) { create(:budget_investment, :incompatible, heading: heading, price: 500, ballot_lines_count: 700) }
let!(:investment4) { create(:budget_investment, :selected, heading: heading, price: 600, ballot_lines_count: 600) }
before do
create(:budget_investment, :selected, title: "First selected", heading: heading, price: 200, ballot_lines_count: 900)
create(:budget_investment, :selected, title: "Second selected", heading: heading, price: 300, ballot_lines_count: 800)
create(:budget_investment, :incompatible, title: "Incompatible investment", heading: heading, price: 500, ballot_lines_count: 700)
create(:budget_investment, :selected, title: "Exceeding price", heading: heading, price: 600, ballot_lines_count: 600)
Budget::Result.new(budget, heading).calculate_winners
end
@@ -39,67 +39,44 @@ describe "Results" do
expect(page).to have_selector("a.is-active", text: heading.name)
within("#budget-investments-compatible") do
expect(page).to have_content investment1.title
expect(page).to have_content investment2.title
expect(page).not_to have_content investment3.title
expect(page).not_to have_content investment4.title
expect(page).to have_content "First selected"
expect(page).to have_content "Second selected"
expect(page).not_to have_content "Incompatible investment"
expect(page).not_to have_content "Exceeding price"
expect(investment1.title).to appear_before(investment2.title)
expect("First selected").to appear_before("Second selected")
end
end
scenario "Show non winner & incomaptible investments" do
scenario "Show non winner & incompatible investments" do
visit budget_path(budget)
click_link "See results"
click_link "Show all"
within("#budget-investments-compatible") do
expect(page).to have_content investment1.title
expect(page).to have_content investment2.title
expect(page).to have_content investment4.title
expect(page).to have_content "First selected"
expect(page).to have_content "Second selected"
expect(page).to have_content "Exceeding price"
expect(investment1.title).to appear_before(investment2.title)
expect(investment2.title).to appear_before(investment4.title)
expect("First selected").to appear_before("Second selected")
expect("Second selected").to appear_before("Exceeding price")
end
within("#budget-investments-incompatible") do
expect(page).to have_content investment3.title
expect(page).to have_content "Incompatible"
end
end
scenario "Does not show price and available budget when hide money" do
budget.update!(voting_style: "approval", hide_money: true)
visit budget_path(budget)
click_link "See results"
expect(page).to have_content investment1.title
expect(page).to have_content investment2.title
expect(page).not_to have_content investment1.price
expect(page).not_to have_content investment2.price
expect(page).not_to have_content "Price"
expect(page).not_to have_content "Available budget"
expect(page).not_to have_content ""
end
scenario "Does not have in account the price on hide money budgets" do
budget.update!(voting_style: "approval", hide_money: true)
heading.update!(price: 0)
inv1 = create(:budget_investment, :selected, heading: heading, price: 2000, ballot_lines_count: 1000)
inv2 = create(:budget_investment, :selected, heading: heading, price: 5000, ballot_lines_count: 1000)
Budget::Result.new(budget, heading).calculate_winners
visit budget_path(budget)
click_link "See results"
expect(page).to have_content inv1.title
expect(page).to have_content inv2.title
expect(page).not_to have_content inv1.price
expect(page).not_to have_content inv2.price
visit budget_results_path(budget)
expect(page).not_to have_content "Price"
expect(page).not_to have_content "Available budget"
expect(page).not_to have_content ""
within("tr", text: "First selected") { expect(page).not_to have_content 200 }
within("tr", text: "Second selected") { expect(page).not_to have_content 300 }
end
scenario "Does not raise error if budget (slug or id) is not found" do
@@ -122,7 +99,7 @@ describe "Results" do
expect(page).to have_selector("a.is-active", text: heading.name)
within("#budget-investments-compatible") do
expect(page).to have_content investment1.title
expect(page).to have_content "First selected"
end
end
@@ -133,7 +110,7 @@ describe "Results" do
visit budget_results_path(budget)
within("#budget-investments-compatible") do
expect(page).to have_content investment1.title
expect(page).to have_content "First selected"
expect(page).not_to have_content other_investment.title
end
end
@@ -149,12 +126,19 @@ describe "Results" do
end
scenario "No incompatible investments" do
investment3.incompatible = false
investment3.save!
Budget::Investment.incompatible.first.update!(incompatible: false, title: "Compatible investment")
visit budget_path(budget)
click_link "See results"
expect(page).to have_content "First selected"
expect(page).to have_content "Second selected"
expect(page).to have_content "Compatible investment"
expect(page).not_to have_content "Exceeding price"
click_link "Show all"
expect(page).to have_content "Exceeding price"
expect(page).not_to have_content "Incompatibles"
end
end