Group Index scenarios at Valuation Investments spec

Grouping scenarios makes it easier to follow the spec and to know where
to put a new scenario
This commit is contained in:
Bertocq
2018-03-13 20:02:04 +01:00
committed by decabeza
parent 3e75bd4dfd
commit 4329fab627

View File

@@ -25,185 +25,190 @@ feature 'Valuation budget investments' do
expect(page).to have_link "Valuation", href: valuation_root_path expect(page).to have_link "Valuation", href: valuation_root_path
end end
scenario 'Index shows budget investments assigned to current valuator' do feature 'Index' do
investment1 = create(:budget_investment, :visible_to_valuators, budget: budget) scenario 'Index shows budget investments assigned to current valuator' do
investment2 = create(:budget_investment, :visible_to_valuators, budget: budget) investment1 = create(:budget_investment, :visible_to_valuators, budget: budget)
investment2 = create(:budget_investment, :visible_to_valuators, budget: budget)
investment1.valuators << valuator investment1.valuators << valuator
visit valuation_budget_budget_investments_path(budget) visit valuation_budget_budget_investments_path(budget)
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
scenario 'Index shows no budget investment to admins no valuators' do
investment1 = create(:budget_investment, :visible_to_valuators, budget: budget)
investment2 = create(:budget_investment, :visible_to_valuators, budget: budget)
investment1.valuators << valuator
logout
login_as create(:administrator).user
visit valuation_budget_budget_investments_path(budget)
expect(page).not_to have_content(investment1.title)
expect(page).not_to have_content(investment2.title)
end
scenario 'Index orders budget investments by votes' do
investment10 = create(:budget_investment, :visible_to_valuators, budget: budget, cached_votes_up: 10)
investment100 = create(:budget_investment, :visible_to_valuators, budget: budget, cached_votes_up: 100)
investment1 = create(:budget_investment, :visible_to_valuators, budget: budget, cached_votes_up: 1)
investment1.valuators << valuator
investment10.valuators << valuator
investment100.valuators << valuator
visit valuation_budget_budget_investments_path(budget)
expect(investment100.title).to appear_before(investment10.title)
expect(investment10.title).to appear_before(investment1.title)
end
scenario 'Index displays investments paginated' do
per_page = Kaminari.config.default_per_page
(per_page + 2).times do
investment = create(:budget_investment, :visible_to_valuators, budget: budget)
investment.valuators << valuator
end end
visit valuation_budget_budget_investments_path(budget) scenario 'Index shows no budget investment to admins no valuators' do
investment1 = create(:budget_investment, :visible_to_valuators, budget: budget)
investment2 = create(:budget_investment, :visible_to_valuators, budget: budget)
expect(page).to have_css('.budget_investment', count: per_page) investment1.valuators << valuator
within("ul.pagination") do logout
expect(page).to have_content("1") login_as create(:administrator).user
expect(page).to have_content("2") visit valuation_budget_budget_investments_path(budget)
expect(page).not_to have_content("3")
click_link "Next", exact: false expect(page).not_to have_content(investment1.title)
expect(page).not_to have_content(investment2.title)
end end
expect(page).to have_css('.budget_investment', count: 2) scenario 'Index orders budget investments by votes' do
end investment10 = create(:budget_investment, :visible_to_valuators, budget: budget,
cached_votes_up: 10)
investment100 = create(:budget_investment, :visible_to_valuators, budget: budget,
cached_votes_up: 100)
investment1 = create(:budget_investment, :visible_to_valuators, budget: budget,
cached_votes_up: 1)
scenario "Index filtering by heading", :js do investment1.valuators << valuator
group = create(:budget_group, budget: budget) investment10.valuators << valuator
valuating_heading = create(:budget_heading, name: "Only Valuating", group: group) investment100.valuators << valuator
valuating_finished_heading = create(:budget_heading, name: "Valuating&Finished", group: group)
finished_heading = create(:budget_heading, name: "Only Finished", group: group)
create(:budget_investment, :visible_to_valuators, title: "Valuating Investment ONE",
heading: valuating_heading,
group: group,
budget: budget,
valuators: [valuator])
create(:budget_investment, :visible_to_valuators, title: "Valuating Investment TWO",
heading: valuating_finished_heading,
group: group,
budget: budget,
valuators: [valuator])
create(:budget_investment, :visible_to_valuators, :finished, title: "Finished ONE",
heading: valuating_finished_heading,
group: group,
budget: budget,
valuators: [valuator])
create(:budget_investment, :visible_to_valuators, :finished, title: "Finished TWO",
heading: finished_heading,
group: group,
budget: budget,
valuators: [valuator])
visit valuation_budget_budget_investments_path(budget) visit valuation_budget_budget_investments_path(budget)
expect(page).to have_link("Valuating Investment ONE") expect(investment100.title).to appear_before(investment10.title)
expect(page).to have_link("Valuating Investment TWO") expect(investment10.title).to appear_before(investment1.title)
expect(page).not_to have_link("Finished ONE") end
expect(page).not_to have_link("Finished TWO")
expect(page).to have_link('All headings (4)') scenario 'Index displays investments paginated' do
expect(page).to have_link('Only Valuating (1)') per_page = Kaminari.config.default_per_page
expect(page).to have_link('Valuating&Finished (2)') (per_page + 2).times do
expect(page).to have_link('Only Finished (1)') investment = create(:budget_investment, :visible_to_valuators, budget: budget)
investment.valuators << valuator
end
click_link "Only Valuating (1)", exact: false visit valuation_budget_budget_investments_path(budget)
expect(page).to have_link("Valuating Investment ONE")
expect(page).not_to have_link("Valuating Investment TWO")
expect(page).not_to have_link("Finished ONE")
expect(page).not_to have_link("Finished TWO")
click_link 'Valuation finished' expect(page).to have_css('.budget_investment', count: per_page)
expect(page).not_to have_link("Valuating Investment ONE") within("ul.pagination") do
expect(page).not_to have_link("Valuating Investment TWO") expect(page).to have_content("1")
expect(page).not_to have_link("Finished ONE") expect(page).to have_content("2")
expect(page).not_to have_link("Finished TWO") expect(page).not_to have_content("3")
click_link "Next", exact: false
end
click_link "Valuating&Finished (2)", exact: false expect(page).to have_css('.budget_investment', count: 2)
expect(page).not_to have_link("Valuating Investment ONE") end
expect(page).to have_link("Valuating Investment TWO")
expect(page).not_to have_link("Finished ONE")
expect(page).not_to have_link("Finished TWO")
click_link 'Valuation finished' scenario "Index filtering by heading", :js do
expect(page).not_to have_link("Valuating Investment ONE") group = create(:budget_group, budget: budget)
expect(page).not_to have_link("Valuating Investment TWO") valuating_heading = create(:budget_heading, name: "Only Valuating", group: group)
expect(page).to have_link("Finished ONE") valuating_finished_heading = create(:budget_heading, name: "Valuating&Finished", group: group)
expect(page).not_to have_link("Finished TWO") finished_heading = create(:budget_heading, name: "Only Finished", group: group)
create(:budget_investment, :visible_to_valuators, title: "Valuating Investment ONE",
heading: valuating_heading,
group: group,
budget: budget,
valuators: [valuator])
create(:budget_investment, :visible_to_valuators, title: "Valuating Investment TWO",
heading: valuating_finished_heading,
group: group,
budget: budget,
valuators: [valuator])
create(:budget_investment, :visible_to_valuators, :finished, title: "Finished ONE",
heading: valuating_finished_heading,
group: group,
budget: budget,
valuators: [valuator])
create(:budget_investment, :visible_to_valuators, :finished, title: "Finished TWO",
heading: finished_heading,
group: group,
budget: budget,
valuators: [valuator])
click_link "Only Finished (1)", exact: false visit valuation_budget_budget_investments_path(budget)
expect(page).not_to have_link("Valuating Investment ONE")
expect(page).not_to have_link("Valuating Investment TWO")
expect(page).not_to have_link("Finished ONE")
expect(page).not_to have_link("Finished TWO")
click_link 'Valuation finished' expect(page).to have_link("Valuating Investment ONE")
expect(page).not_to have_link("Valuating Investment ONE") expect(page).to have_link("Valuating Investment TWO")
expect(page).not_to have_link("Valuating Investment TWO") expect(page).not_to have_link("Finished ONE")
expect(page).not_to have_link("Finished ONE") expect(page).not_to have_link("Finished TWO")
expect(page).to have_link("Finished TWO")
end
scenario "Current filter is properly highlighted" do expect(page).to have_link('All headings (4)')
filters_links = {'valuating' => 'Under valuation', expect(page).to have_link('Only Valuating (1)')
'valuation_finished' => 'Valuation finished'} expect(page).to have_link('Valuating&Finished (2)')
expect(page).to have_link('Only Finished (1)')
visit valuation_budget_budget_investments_path(budget) click_link "Only Valuating (1)", exact: false
expect(page).to have_link("Valuating Investment ONE")
expect(page).not_to have_link("Valuating Investment TWO")
expect(page).not_to have_link("Finished ONE")
expect(page).not_to have_link("Finished TWO")
expect(page).not_to have_link(filters_links.values.first) click_link 'Valuation finished'
filters_links.keys.drop(1).each { |filter| expect(page).to have_link(filters_links[filter]) } expect(page).not_to have_link("Valuating Investment ONE")
expect(page).not_to have_link("Valuating Investment TWO")
expect(page).not_to have_link("Finished ONE")
expect(page).not_to have_link("Finished TWO")
filters_links.each_pair do |current_filter, link| click_link "Valuating&Finished (2)", exact: false
visit valuation_budget_budget_investments_path(budget, filter: current_filter) expect(page).not_to have_link("Valuating Investment ONE")
expect(page).to have_link("Valuating Investment TWO")
expect(page).not_to have_link("Finished ONE")
expect(page).not_to have_link("Finished TWO")
expect(page).not_to have_link(link) click_link 'Valuation finished'
expect(page).not_to have_link("Valuating Investment ONE")
expect(page).not_to have_link("Valuating Investment TWO")
expect(page).to have_link("Finished ONE")
expect(page).not_to have_link("Finished TWO")
(filters_links.keys - [current_filter]).each do |filter| click_link "Only Finished (1)", exact: false
expect(page).to have_link(filters_links[filter]) expect(page).not_to have_link("Valuating Investment ONE")
expect(page).not_to have_link("Valuating Investment TWO")
expect(page).not_to have_link("Finished ONE")
expect(page).not_to have_link("Finished TWO")
click_link 'Valuation finished'
expect(page).not_to have_link("Valuating Investment ONE")
expect(page).not_to have_link("Valuating Investment TWO")
expect(page).not_to have_link("Finished ONE")
expect(page).to have_link("Finished TWO")
end
scenario "Current filter is properly highlighted" do
filters_links = {'valuating' => 'Under valuation',
'valuation_finished' => 'Valuation finished'}
visit valuation_budget_budget_investments_path(budget)
expect(page).not_to have_link(filters_links.values.first)
filters_links.keys.drop(1).each { |filter| expect(page).to have_link(filters_links[filter]) }
filters_links.each_pair do |current_filter, link|
visit valuation_budget_budget_investments_path(budget, filter: current_filter)
expect(page).not_to have_link(link)
(filters_links.keys - [current_filter]).each do |filter|
expect(page).to have_link(filters_links[filter])
end
end end
end end
end
scenario "Index filtering by valuation status" do scenario "Index filtering by valuation status" do
valuating = create(:budget_investment, :visible_to_valuators, valuating = create(:budget_investment, :visible_to_valuators, budget: budget,
budget: budget, title: "Ongoing valuation") title: "Ongoing valuation")
valuated = create(:budget_investment, :visible_to_valuators, valuated = create(:budget_investment, :visible_to_valuators, budget: budget,
budget: budget, title: "Old idea", valuation_finished: true) title: "Old idea",
valuating.valuators << valuator valuation_finished: true)
valuated.valuators << valuator valuating.valuators << valuator
valuated.valuators << valuator
visit valuation_budget_budget_investments_path(budget) visit valuation_budget_budget_investments_path(budget)
expect(page).to have_content("Ongoing valuation") expect(page).to have_content("Ongoing valuation")
expect(page).not_to have_content("Old idea") expect(page).not_to have_content("Old idea")
visit valuation_budget_budget_investments_path(budget, filter: 'valuating') visit valuation_budget_budget_investments_path(budget, filter: 'valuating')
expect(page).to have_content("Ongoing valuation") expect(page).to have_content("Ongoing valuation")
expect(page).not_to have_content("Old idea") expect(page).not_to have_content("Old idea")
visit valuation_budget_budget_investments_path(budget, filter: 'valuation_finished') visit valuation_budget_budget_investments_path(budget, filter: 'valuation_finished')
expect(page).not_to have_content("Ongoing valuation") expect(page).not_to have_content("Ongoing valuation")
expect(page).to have_content("Old idea") expect(page).to have_content("Old idea")
end
end end
feature 'Show' do feature 'Show' do