".html_safe
+ end
+ end
end
diff --git a/app/views/form/page.html.erb b/app/views/form/page.html.erb
index 6d2d1888d..6e2ecac5c 100644
--- a/app/views/form/page.html.erb
+++ b/app/views/form/page.html.erb
@@ -14,11 +14,7 @@
<%= form_with action: '/case_logs', method: "next_page", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<% page_info["questions"].map do |question_key, question| %>
- <% if conditional_questions_for_page(page_info).include?(question_key) %>
-
style="display:none;">
- <% else %>
-
>
- <% end %>
+ <%= display_question_key_div(page_info, question_key)%>
<%= render partial: "form/#{question["type"]}_question", locals: { question_key: question_key, question: question, f: f } %>
<% end %>
diff --git a/spec/helpers/conditional_questions_helper_spec.rb b/spec/helpers/conditional_questions_helper_spec.rb
index c6b9d9008..889c237cd 100644
--- a/spec/helpers/conditional_questions_helper_spec.rb
+++ b/spec/helpers/conditional_questions_helper_spec.rb
@@ -12,4 +12,17 @@ RSpec.describe ConditionalQuestionsHelper do
expect(conditional_questions_for_page(page)).to eq(conditional_pages)
end
end
+
+ describe "display question key div" do
+ let(:question_key) { "armed_forces" }
+ let(:conditional_question_key) { "armed_forces_injured" }
+
+ it "returns a non visible div for conditional questions" do
+ expect(display_question_key_div(page, conditional_question_key)).to match("style='display:none;'")
+ end
+
+ it "returns a visible div for conditional questions" do
+ expect(display_question_key_div(page, question_key)).not_to match("style='display:none;'")
+ end
+ end
end