Files
nairobi/spec/components/admin/budgets/links_component_spec.rb
Javi Martín 0cc3f04096 Don't show preview link for budgets with results
We currently don't have any links in the public area pointing to past
budgets, so having links in the admin section to both the budget and its
results seemed a bit redundant. We're going to add more links to the
budget actions soon, so we need to make room for them; otherwise we'll
have too many.

We're also changing the "Preview" text for a published budget. Since the
budget is already public, we aren't previewing it anymore but simply
viewing it.

And, to be consistent with the "See results" link, we're opening the
"Preview" link in the current tab. Opening links in a new tab is
generally a bad idea because takes control away from users, breaks the
back button and makes navigation particularly hard on mobile browsers.
It could be argued that in this case it's useful when users are editing
the budget in one tab and previewing it in another one, so we might add
this behavior back as long as we make it clear that the link opens in a
new tab [1].

[1] https://www.nngroup.com/articles/new-browser-windows-and-tabs/
2021-10-25 18:01:47 +02:00

82 lines
2.3 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
end