Use a switch to toggle visibility to valuators
Using a checkbox wasn't very intuitive because checkboxes are
checked/unchecked when clicked on even if there's an error in the
request. Usually, when checkboxes appear on a form, they don't send any
information to the server unless we click a button to send the form.
So we're using a switch instead of a checkbox, like we did to
enable/disable phases in commit 46d8bc4f0.
Note that, since we've got two switches that match the default
`dom_id(record) .toggle-switch` selector, we need to find a way to
differentiate them. We're adding the `form_class` option for that.
Also note that we're now using a separate action and removing the
JavaScript in the `update` action which assumed that AJAX requests to
this action were always related to updating the `visible_to_valuators`
attribute.
This commit is contained in:
@@ -1,9 +1,21 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Admin::BudgetInvestments::ToggleVisibleToValuatorsComponent, :admin do
|
||||
it "uses a JSON request to update visible to valuators" do
|
||||
render_inline Admin::BudgetInvestments::ToggleVisibleToValuatorsComponent.new(create(:budget_investment))
|
||||
describe "aria-pressed attribute" do
|
||||
it "is true for investments visible to valuators" do
|
||||
investment = create(:budget_investment, :visible_to_valuators)
|
||||
|
||||
expect(page).to have_css "form[action$='json'] input[name$='[visible_to_valuators]']"
|
||||
render_inline Admin::BudgetInvestments::ToggleVisibleToValuatorsComponent.new(investment)
|
||||
|
||||
expect(page).to have_css "[aria-pressed=true]"
|
||||
end
|
||||
|
||||
it "is true for investments invisible to valuators" do
|
||||
investment = create(:budget_investment, :invisible_to_valuators)
|
||||
|
||||
render_inline Admin::BudgetInvestments::ToggleVisibleToValuatorsComponent.new(investment)
|
||||
|
||||
expect(page).to have_css "[aria-pressed=false]"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user