Browse Source

Spec initial state

pull/27/head
baarkerlounger 4 years ago
parent
commit
5da6ad08f7
  1. 11
      app/views/form/page.html.erb
  2. 9
      spec/features/case_log_spec.rb

11
app/views/form/page.html.erb

@ -14,14 +14,13 @@
<%= form_with action: '/case_logs', method: "next_page", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %> <%= form_with action: '/case_logs', method: "next_page", builder: GOVUKDesignSystemFormBuilder::FormBuilder do |f| %>
<% page_info["questions"].map do |question_key, question| %> <% page_info["questions"].map do |question_key, question| %>
<div id=<%= "#{question_key}_div" %> >
<%= render partial: "form/#{question["type"]}_question", locals: { question_key: question_key, question: question, f: f } %>
</div>
<% if conditional_questions_for_page(page_info).include?(question_key) %> <% if conditional_questions_for_page(page_info).include?(question_key) %>
<style> <div id=<%= "#{question_key}_div" %> style="display:none;">
<%= "##{question_key}_div" %> { display: none; } <% else %>
</style> <div id=<%= "#{question_key}_div" %> >
<% end %> <% end %>
<%= render partial: "form/#{question["type"]}_question", locals: { question_key: question_key, question: question, f: f } %>
</div>
<% end %> <% end %>
<%= f.hidden_field :previous_page, value: page_key %> <%= f.hidden_field :previous_page, value: page_key %>

9
spec/features/case_log_spec.rb

@ -96,4 +96,13 @@ RSpec.describe "Test Features" do
end end
end end
end end
describe "Conditional questions" do
context "given a page where some questions are only conditionally shown, depending on how you answer the first question" do
it "initially hides conditional questions" do
visit("/case_logs/#{id}/armed_forces")
expect(page).to have_selector("#armed_forces_injured_div", visible: :hidden)
end
end
end
end end

Loading…
Cancel
Save