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.
29 lines
905 B
Ruby
29 lines
905 B
Ruby
require "rails_helper"
|
|
|
|
describe Admin::BudgetPhases::ToggleEnabledComponent, controller: Admin::BaseController do
|
|
let(:phase) { create(:budget).phases.informing }
|
|
let(:component) { Admin::BudgetPhases::ToggleEnabledComponent.new(phase) }
|
|
|
|
it "is pressed when the phase is enabled" do
|
|
phase.update!(enabled: true)
|
|
|
|
render_inline component
|
|
|
|
expect(page).to have_button count: 1
|
|
expect(page).to have_button exact_text: "Yes"
|
|
expect(page).to have_button "Enable Information phase"
|
|
expect(page).to have_css "button[aria-pressed='true']"
|
|
end
|
|
|
|
it "is not pressed when the phase is disabled" do
|
|
phase.update!(enabled: false)
|
|
|
|
render_inline component
|
|
|
|
expect(page).to have_button count: 1
|
|
expect(page).to have_button exact_text: "No"
|
|
expect(page).to have_button "Enable Information phase"
|
|
expect(page).to have_css "button[aria-pressed='false']"
|
|
end
|
|
end
|