Files
grecia/spec/components/admin/budget_investments/toggle_selection_component_spec.rb
Javi Martín 463112c2ea Use a switch to toggle investment selection
Just like it happened with proposals, the button to select/deselect an
investment wasn't very intuitive; for example, it wasn't obvious that
pressing a button saying "selected" would deselect the investment.

So we're using a switch control, like we do to enable/disable features
since commit fabe97e50.

Note that we're making the text of the switch smaller than in other
places because the text in the investments table it is also smaller
(we're using `font-size: inherit` for that purpose). That made the
button look weird because we were using rems instead of ems for the
width of the button, so we're adjusting that as well.

Also note we're changing the width of the switch to `6em` instead of
`6.25em` (which would be 100px if 1em is 16px). We're doing so because
we used 100 for the minimum width because it's a round number, so
now we're using another round number.
2024-10-28 13:40:27 +01:00

67 lines
2.6 KiB
Ruby

require "rails_helper"
describe Admin::BudgetInvestments::ToggleSelectionComponent, :admin do
context "open budget" do
let(:budget) { create(:budget) }
it "is not rendered for not-yet-evaluated investments" do
unfeasible_investment = create(:budget_investment, :unfeasible, budget: budget)
feasible_investment = create(:budget_investment, :feasible, budget: budget)
render_inline Admin::BudgetInvestments::ToggleSelectionComponent.new(unfeasible_investment)
expect(page).not_to be_rendered
render_inline Admin::BudgetInvestments::ToggleSelectionComponent.new(feasible_investment)
expect(page).not_to be_rendered
end
it "renders a button to select unselected evaluated investments" do
valuation_finished_investment = create(:budget_investment, :feasible, :finished, budget: budget)
render_inline Admin::BudgetInvestments::ToggleSelectionComponent.new(valuation_finished_investment)
expect(page).to have_button count: 1
expect(page).to have_button exact_text: "No"
expect(page).to have_css "button[aria-pressed='false']"
end
it "renders a button to deselect selected investments" do
selected_investment = create(:budget_investment, :selected, budget: budget)
render_inline Admin::BudgetInvestments::ToggleSelectionComponent.new(selected_investment)
expect(page).to have_button count: 1
expect(page).to have_button exact_text: "Yes"
expect(page).to have_css "button[aria-pressed='true']"
end
end
context "finished budget" do
let(:budget) { create(:budget, :finished) }
it "is not rendered for unselected investments" do
unfeasible_investment = create(:budget_investment, :unfeasible, budget: budget)
feasible_investment = create(:budget_investment, :feasible, budget: budget)
valuation_finished_investment = create(:budget_investment, :feasible, :finished, budget: budget)
render_inline Admin::BudgetInvestments::ToggleSelectionComponent.new(unfeasible_investment)
expect(page).not_to be_rendered
render_inline Admin::BudgetInvestments::ToggleSelectionComponent.new(feasible_investment)
expect(page).not_to be_rendered
render_inline Admin::BudgetInvestments::ToggleSelectionComponent.new(valuation_finished_investment)
expect(page).not_to be_rendered
end
it "renders plain text for selected investments" do
selected_investment = create(:budget_investment, :selected, budget: budget)
render_inline Admin::BudgetInvestments::ToggleSelectionComponent.new(selected_investment)
expect(page).to have_content "Selected"
expect(page).not_to have_button
end
end
end