Use a switch to enable/disable budget phases

In the past it would have been confusing to add a way to directly
enable/disable a phase in the phases table because it was in the middle
of the form. So we would have had next to each other controls that don't
do anything until the form is sent and controls which modify the
database immediately. That's why we couldn't add the checkboxes we used
when using the wizard.

Now the phases aren't on the same page as the budget form, so we can
edit them independently. We're using a switch, so it's consistent with
the way we enable/disable features. We could have used checkboxes, but
with checkboxes, users expect they aren't changing anything until they
click on a button to send the form, so we'd have to add a button, and it
might be missed since we're going to add "buttons" for headings and
groups to this page which won't send a form but will be links.

Since we're changing the element with JavaScript after an AJAX call, we
need a way to find the button we're changing. The easiest way is adding
an ID attribute to all admin actions buttons/links.
This commit is contained in:
Javi Martín
2021-08-23 02:23:09 +02:00
parent 349dbb74d7
commit 46d8bc4f0e
17 changed files with 137 additions and 89 deletions

View File

@@ -16,6 +16,31 @@ describe Admin::ActionComponent do
end
end
describe "HTML id" do
it "is not rendered for non-ActiveModel records" do
render_inline Admin::ActionComponent.new(:edit, double, path: "/")
expect(page).not_to have_css "[id]"
end
it "includes an id based on the model and the action by default" do
record = double(model_name: double(param_key: "computer"), to_key: [1])
render_inline Admin::ActionComponent.new(:edit, record, path: "/")
expect(page).to have_css "a.edit-link#edit_computer_1"
end
it "can be overwritten" do
record = double(model_name: double(param_key: "computer"), to_key: [1])
render_inline Admin::ActionComponent.new(:edit, record, path: "/", id: "my_id")
expect(page).to have_css "a.edit-link#my_id"
expect(page).not_to have_css "#edit_computer_1"
end
end
describe "aria-label attribute" do
it "is not rendered by default" do
record = double(human_name: "Stay home")