Simplify test for budget phases table

Even if the test checked all possibilities, it was hard to understand.
Using `have_table with_cols:` to test the order of the rows and testing
one phase is enabled and has a link to edit it es enough IMHO.
This commit is contained in:
Javi Martín
2021-02-23 00:20:47 +01:00
parent f9ecc583ef
commit 150fb91686

View File

@@ -41,11 +41,11 @@ describe "Admin budgets", :admin do
end
scenario "Displaying budgets" do
budget = create(:budget)
budget = create(:budget, :accepting)
visit admin_budgets_path
expect(page).to have_content(budget.name)
expect(page).to have_content(translated_phase_name(phase_kind: budget.phase))
expect(page).to have_content budget.name
expect(page).to have_content "Accepting projects"
end
scenario "Filters by phase" do
@@ -245,35 +245,43 @@ describe "Admin budgets", :admin do
end
context "Edit" do
let!(:budget) { create(:budget) }
let(:budget) { create(:budget) }
scenario "Show phases table" do
budget.update!(phase: "selecting")
travel_to(Date.new(2015, 7, 15)) do
budget.update!(phase: "selecting")
visit admin_budgets_path
click_link "Edit budget"
visit edit_admin_budget_path(budget)
expect(page).to have_select("budget_phase", selected: "Selecting projects")
expect(page).to have_select "Phase", selected: "Selecting projects"
within "#budget-phases-table" do
Budget::Phase::PHASE_KINDS.each do |phase_kind|
break if phase_kind == Budget::Phase::PHASE_KINDS.last
expect(page).to have_table "budget-phases-table", with_cols: [
[
"Information",
"Accepting projects",
"Reviewing projects",
"Selecting projects Active",
"Valuating projects",
"Publishing projects prices",
"Voting projects",
"Reviewing voting"
],
[
"2015-07-15 - 2015-08-15",
"2015-08-15 - 2015-09-15",
"2015-09-15 - 2015-10-15",
"2015-10-15 - 2015-11-15",
"2015-11-15 - 2015-12-15",
"2015-12-15 - 2016-01-15",
"2016-01-15 - 2016-02-15",
"2016-02-15 - 2016-03-15"
]
]
phase_index = Budget::Phase::PHASE_KINDS.index(phase_kind)
next_phase_kind = Budget::Phase::PHASE_KINDS[phase_index + 1]
next_phase_name = translated_phase_name(phase_kind: next_phase_kind)
expect(translated_phase_name(phase_kind: phase_kind)).to appear_before(next_phase_name)
end
budget.phases.each do |phase|
edit_phase_link = edit_admin_budget_budget_phase_path(budget, phase)
within "#budget_phase_#{phase.id}" do
expect(page).to have_content(translated_phase_name(phase_kind: phase.kind))
expect(page).to have_content("#{phase.starts_at.to_date} - #{phase.ends_at.to_date}")
expect(page).to have_css(".budget-phase-enabled.enabled")
expect(page).to have_link("Edit phase", href: edit_phase_link)
expect(page).to have_content("Active") if phase.current?
within_table "budget-phases-table" do
within "tr", text: "Information" do
expect(page).to have_css ".budget-phase-enabled.enabled"
expect(page).to have_link "Edit phase"
end
end
end
@@ -402,7 +410,3 @@ describe "Admin budgets", :admin do
end
end
end
def translated_phase_name(phase_kind: kind)
I18n.t("budgets.phase.#{phase_kind}")
end