Browse Source

Spec initial state

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

9
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| %>
<% if conditional_questions_for_page(page_info).include?(question_key) %>
<div id=<%= "#{question_key}_div" %> style="display:none;">
<% else %>
<div id=<%= "#{question_key}_div" %> > <div id=<%= "#{question_key}_div" %> >
<% end %>
<%= render partial: "form/#{question["type"]}_question", locals: { question_key: question_key, question: question, f: f } %> <%= render partial: "form/#{question["type"]}_question", locals: { question_key: question_key, question: question, f: f } %>
</div> </div>
<% if conditional_questions_for_page(page_info).include?(question_key) %>
<style>
<%= "##{question_key}_div" %> { display: none; }
</style>
<% end %>
<% 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