Files
nairobi/spec/components/admin/budgets/links_component_spec.rb
Javi Martín 1b407b0702 Move budget ballot actions to admin budget page
The buttons to create polls associated with a budget were too prominent,
appearing on the table as if they were as used as the link to manage
investments. Most CONSUL installations don't use physical booths, and
would probably wonder what that button is about.

We're moving it to a more discrete place, at the bottom of the budget
page. This way we can also split the action in two: on budgets not
having a poll, we display the button in a not-so-accessible position (at
the bottom of the page), since this button will only be used once per
budget at most. Once the poll has been created, it means this feature is
going to be used, so we display a link to manage ballots more
prominently at the top of the page. If the budget has finished the final
voting stage without creating a poll, we don't show either the link or
the button because this feature can no longer be used.

We're also adding some texts indicating what this feature is about,
since it's probably one of the least understood features in CONSUL
(probably because the interface is very confusing... but that's a
different story).

Since now from the budget page we can access every feature related to
the budget, we can remove the "preview" action from the budgets index
table, since this feature isn't that useful for budgets once they're
published.

Now the budgets table doesn't take as much space as it used to, although
it's still too wide to be handled properly on devices with a small
screen.
2021-10-25 18:34:19 +02:00

121 lines
3.4 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
describe "ballots link" do
let(:budget) { create(:budget) }
let(:component) { Admin::Budgets::LinksComponent.new(budget) }
it "is rendered for budgets with polls" do
budget.poll = create(:poll, budget: budget)
path = Rails.application.routes.url_helpers.admin_poll_booth_assignments_path(budget.poll)
render_inline component
expect(page).to have_link "Ballots", href: path
end
it "is not rendered for budgets without polls" do
render_inline component
expect(page).not_to have_link "Ballots"
end
end
end