Don't loop over budget phases in system tests

We've already got model tests for that, and we were modifying the
database after a `visit`, since we were doing a loop consisting of
"update!" -> "visit" -> "update!" -> "visit!" -> (...).

Besides, note that the `.kind_or_later("publishing_prices").each` block
wasn't modifying the budget, so it always visited the page under the
same conditions.

So we're simply randomly checking one phase to test that the user
interface works as expected.
This commit is contained in:
Javi Martín
2025-03-14 04:39:12 +01:00
parent f93c85bd2e
commit 2fbba71ffc

View File

@@ -529,10 +529,16 @@ describe "Budget Investments" do
end end
scenario "Order always is random for unfeasible and unselected investments" do scenario "Order always is random for unfeasible and unselected investments" do
Budget::Phase::kind_or_later("valuating").each do |phase| phase = Budget::Phase::kind_or_later("valuating").sample
budget.update!(phase: phase) budget.update!(phase: phase)
visit budget_investments_path(budget, heading_id: heading.id, filter: "unfeasible") filter = if Budget::Phase.kind_or_later("publishing_prices").include?(phase)
"unselected"
else
"unfeasible"
end
visit budget_investments_path(budget, heading_id: heading.id, filter: filter)
within(".submenu") do within(".submenu") do
expect(page).to have_content "random" expect(page).to have_content "random"
@@ -541,17 +547,6 @@ describe "Budget Investments" do
end end
end end
Budget::Phase.kind_or_later("publishing_prices").each do |phase|
visit budget_investments_path(budget, heading_id: heading.id, filter: "unselected")
within(".submenu") do
expect(page).to have_content "random"
expect(page).not_to have_content "price"
expect(page).not_to have_content "highest rated"
end
end
end
def investments_order def investments_order
all(".budget-investment h3").map(&:text) all(".budget-investment h3").map(&:text)
end end
@@ -872,7 +867,7 @@ describe "Budget Investments" do
context "When investment with price is selected" do context "When investment with price is selected" do
scenario "Price & explanation is shown when Budget is on published prices phase" do scenario "Price & explanation is shown when Budget is on published prices phase" do
Budget::Phase::PUBLISHED_PRICES_PHASES.each do |phase| phase = Budget::Phase::PUBLISHED_PRICES_PHASES.sample
budget.update!(phase: phase) budget.update!(phase: phase)
if budget.finished? if budget.finished?
@@ -889,10 +884,9 @@ describe "Budget Investments" do
expect(page).to have_content(investment.formatted_price) expect(page).to have_content(investment.formatted_price)
end end
end
scenario "Price & explanation isn't shown when Budget is not on published prices phase" do scenario "Price & explanation isn't shown when Budget is not on published prices phase" do
(Budget::Phase::PHASE_KINDS - Budget::Phase::PUBLISHED_PRICES_PHASES).each do |phase| phase = (Budget::Phase::PHASE_KINDS - Budget::Phase::PUBLISHED_PRICES_PHASES).sample
budget.update!(phase: phase) budget.update!(phase: phase)
visit budget_investment_path(budget, id: investment.id) visit budget_investment_path(budget, id: investment.id)
@@ -905,7 +899,6 @@ describe "Budget Investments" do
expect(page).not_to have_content(investment.formatted_price) expect(page).not_to have_content(investment.formatted_price)
end end
end end
end
context "When investment with price is unselected" do context "When investment with price is unselected" do
before do before do
@@ -913,7 +906,7 @@ describe "Budget Investments" do
end end
scenario "Price & explanation isn't shown for any Budget's phase" do scenario "Price & explanation isn't shown for any Budget's phase" do
Budget::Phase::PHASE_KINDS.each do |phase| phase = Budget::Phase::PHASE_KINDS.sample
budget.update!(phase: phase) budget.update!(phase: phase)
visit budget_investment_path(budget, id: investment.id) visit budget_investment_path(budget, id: investment.id)
@@ -927,7 +920,6 @@ describe "Budget Investments" do
end end
end end
end end
end
scenario "Can access the community" do scenario "Can access the community" do
Setting["feature.community"] = true Setting["feature.community"] = true