diff --git a/app/javascript/controllers/conditional_question_controller.js b/app/javascript/controllers/conditional_question_controller.js index d84b5cc5e..5a87a7b90 100644 --- a/app/javascript/controllers/conditional_question_controller.js +++ b/app/javascript/controllers/conditional_question_controller.js @@ -7,10 +7,15 @@ export default class extends Controller { let conditional_for = JSON.parse(this.element.dataset.info); Object.entries(conditional_for).forEach(([key, values]) => { + let el = document.getElementById(key + "_div"); if(values.includes(selected)) { - document.getElementById(key + "_div").style.display = "block" + el.style.display = "block"; } else { - document.getElementById(key + "_div").style.display = "none" + el.style.display = "none"; + let buttons = document.getElementsByName(key) + Object.entries(buttons).forEach(([idx, button]) => { + button.checked = false; + }); } }); } diff --git a/spec/features/case_log_spec.rb b/spec/features/case_log_spec.rb index 9af07b634..75368a5a3 100644 --- a/spec/features/case_log_spec.rb +++ b/spec/features/case_log_spec.rb @@ -106,10 +106,15 @@ RSpec.describe "Test Features" do it "shows conditional questions if the required answer is selected and hides it again when a different answer option is selected", js: true do visit("/case_logs/#{id}/armed_forces") - find(:xpath, "//label[@for='armed-forces-0-field']").click + # Someting about our styling makes the selenium webdriver think the actual radio buttons are not visible so we allow label click here + choose("armed-forces-0-field", allow_label_click: true) expect(page).to have_selector("#armed_forces_injured_div") - find(:xpath, "//label[@for='armed-forces-2-field']").click + choose("armed-forces-injured-1-field", allow_label_click: true) + expect(find_field("armed-forces-injured-1-field", visible: false).checked?).to be_truthy + choose("armed-forces-2-field", allow_label_click: true) expect(page).not_to have_selector("#armed_forces_injured_div") + choose("armed-forces-0-field", allow_label_click: true) + expect(find_field("armed-forces-injured-1-field", visible: false).checked?).to be_falsey end end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index afda6c5df..726c09017 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -7,7 +7,7 @@ abort("The Rails environment is running in production mode!") if Rails.env.produ require "rspec/rails" require "capybara/rspec" -# Uncomment to run `js: true specs` with visible browser interaction +# Comment to run `js: true specs` with visible browser interaction Capybara.javascript_driver = :selenium_headless # Add additional requires below this line. Rails is not loaded until this point!