Browse Source

PR comments

pull/29/head
baarkerlounger 4 years ago
parent
commit
b103374db2
  1. 4
      app/helpers/conditional_questions_helper.rb
  2. 6
      app/javascript/controllers/conditional_question_controller.js
  3. 2
      spec/features/case_log_spec.rb
  4. 2
      spec/helpers/conditional_questions_helper_spec.rb

4
app/helpers/conditional_questions_helper.rb

@ -1,7 +1,7 @@
module ConditionalQuestionsHelper module ConditionalQuestionsHelper
def conditional_questions_for_page(page) def conditional_questions_for_page(page)
page["questions"].values.map do |question| page["questions"].values.map { |question|
question["conditional_for"] question["conditional_for"]
end.compact.map(&:keys).flatten }.compact.map(&:keys).flatten
end end
end end

6
app/javascript/controllers/conditional_question_controller.js

@ -11,11 +11,11 @@ export default class extends Controller {
let conditional_for = JSON.parse(this.element.dataset.info) let conditional_for = JSON.parse(this.element.dataset.info)
Object.entries(conditional_for).forEach(([key, values]) => { Object.entries(conditional_for).forEach(([key, values]) => {
let el = document.getElementById(key + "_div") let div = document.getElementById(key + "_div")
if(values.includes(selected)) { if(values.includes(selected)) {
el.style.display = "block" div.style.display = "block"
} else { } else {
el.style.display = "none" div.style.display = "none"
let buttons = document.getElementsByName(key) let buttons = document.getElementsByName(key)
Object.entries(buttons).forEach(([idx, button]) => { Object.entries(buttons).forEach(([idx, button]) => {
button.checked = false; button.checked = false;

2
spec/features/case_log_spec.rb

@ -228,7 +228,7 @@ 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 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") visit("/case_logs/#{id}/armed_forces")
# Someting about our styling makes the selenium webdriver think the actual radio buttons are not visible so we allow label click here # Something about our styling makes the selenium webdriver think the actual radio buttons are not visible so we allow label click here
choose("armed-forces-yes-a-regular-field", allow_label_click: true) choose("armed-forces-yes-a-regular-field", allow_label_click: true)
expect(page).to have_selector("#armed_forces_injured_div") expect(page).to have_selector("#armed_forces_injured_div")
choose("armed-forces-injured-no-field", allow_label_click: true) choose("armed-forces-injured-no-field", allow_label_click: true)

2
spec/helpers/conditional_questions_helper_spec.rb

@ -6,7 +6,7 @@ RSpec.describe ConditionalQuestionsHelper do
let(:page) { form.all_pages[page_key] } let(:page) { form.all_pages[page_key] }
describe "conditional questions for page" do describe "conditional questions for page" do
let(:conditional_pages) { ["armed_forces_active", "armed_forces_injured"] } let(:conditional_pages) { %w[armed_forces_active armed_forces_injured] }
it "returns the question keys of all conditional questions on the given page" do it "returns the question keys of all conditional questions on the given page" do
expect(conditional_questions_for_page(page)).to eq(conditional_pages) expect(conditional_questions_for_page(page)).to eq(conditional_pages)

Loading…
Cancel
Save