Files
nairobi/spec/components/admin/budgets/links_component_spec.rb
Javi Martín 8bb55f0d45 Add link to investments from the admin budget page
Since managing investments is a very common action, with this link
administrators won't have to go back to the index page to manage
investments; they can access it from either the budgets index page or
the budget page.

Since now the links we've got on the budget page are similar to the ones
we've got in the index page table, we're styling them in a similar way.

We're also fixing a small typo en the investments path; it works exactly
the same way as it used to, but passing `budget` instead of `budget_id:
budget.id` is shorter and more consistent with what we do in other
places.
2021-10-25 18:34:19 +02:00

101 lines
2.8 KiB
Ruby

require "rails_helper"
describe Admin::Budgets::LinksComponent, controller: Admin::BaseController do
before { sign_in(create(:administrator).user) }
describe "see results link" do
let(:budget) { create(:budget, :finished) }
let(:component) { Admin::Budgets::LinksComponent.new(budget) }
it "is shown for budgets with results enabled" do
budget.update!(results_enabled: true)
render_inline component
expect(page).to have_link "See results"
expect(page).not_to have_link "Preview results"
end
it "is not shown for budgets with results disabled" do
budget.update!(results_enabled: false)
render_inline component
expect(page).not_to have_link "See results"
expect(page).not_to have_link "Preview results"
end
context "after calculating winners" do
let(:budget) { create(:budget, :with_winner) }
it "is shown as a preview link after finishing the process" do
budget.update!(phase: "finished", results_enabled: false)
render_inline component
expect(page).to have_link "Preview results"
expect(page).not_to have_link "See results"
end
it "is shown as a preview link after balloting has finished" do
budget.update!(phase: "reviewing_ballots", results_enabled: false)
render_inline component
expect(page).to have_link "Preview results"
expect(page).not_to have_link "See results"
expect(page).not_to have_link "View"
expect(page).not_to have_link "Preview"
end
it "is not shown while balloting" do
budget.update!(phase: "balloting", results_enabled: true)
render_inline component
expect(page).not_to have_link "Preview results"
expect(page).not_to have_link "See results"
end
end
end
describe "preview/view link" do
it "shows a link to preview an unpublished budget" do
budget = create(:budget, :drafting)
render_inline Admin::Budgets::LinksComponent.new(budget)
expect(page).to have_link "Preview"
expect(page).not_to have_link "View"
end
it "shows a link to view a published budget" do
budget = create(:budget, :informing)
render_inline Admin::Budgets::LinksComponent.new(budget)
expect(page).to have_link "View"
expect(page).not_to have_link "Preview"
end
end
describe "investments link" do
let(:budget) { create(:budget) }
let(:component) { Admin::Budgets::LinksComponent.new(budget) }
it "is shown for budgets with investments" do
create(:budget_investment, budget: budget)
render_inline component
expect(page).to have_link "Investment projects"
end
it "is not shown for budgets without investments" do
render_inline component
expect(page).not_to have_link "Investment projects"
end
end
end