Browse Source

Add check answers helper, display number of questions answered and a link to the next unanswered question

pull/25/head
Kat 3 years ago committed by MadeTech Dushan
parent
commit
a436a6cae2
  1. 23
      app/helpers/check_answers_helper.rb
  2. 9
      app/views/form/check_answers.html.erb
  3. 18
      spec/features/case_log_spec.rb

23
app/helpers/check_answers_helper.rb

@ -0,0 +1,23 @@
module CheckAnswersHelper
def get_answered_questions_total(subsection_pages, case_log)
questions = []
subsection_pages.keys.each do |page|
questions << page
end
return questions.count {|question| !(case_log[question].blank?)}
end
def create_update_answer_link(case_log_answer, case_log_id, page)
link_name = case_log_answer.blank? ? "Answer" : "Change"
link_to(link_name, "/case_logs/#{case_log_id}/#{page}", class: "govuk-link").html_safe
end
def create_next_missing_question_link(case_log_id, subsections, case_log)
empty_question = subsections.keys.find{|x| case_log[x].blank? }
url = "/case_logs/#{case_log_id}/#{empty_question}"
link_to('Answer the missing questions', url, class: "govuk-link").html_safe
end
end

9
app/views/form/check_answers.html.erb

@ -1,5 +1,7 @@
<%= turbo_frame_tag "case_log_form", target: "_top" do %>
<h1 class="govuk-heading-l">Check the answers you gave for household characteristics</h1>
<p>You answered <%= get_answered_questions_total(subsection_pages, case_log) %> of <%= subsection_pages.count %> questions</p>
<%= create_next_missing_question_link(case_log_id, subsection_pages, case_log) %>
<% subsection_pages.each do |page, page_info| %>
<dl class="govuk-summary-list govuk-!-margin-bottom-9">
<div class="govuk-summary-list__row">
@ -10,11 +12,7 @@
<%= case_log[page] %>
</dd>
<dd class="govuk-summary-list__actions">
<% if case_log[page].blank? %>
<%= link_to "Answer", "/case_logs/#{case_log_id}/#{page}", class: "govuk-link" %>
<% else %>
<%= link_to "Change", "/case_logs/#{case_log_id}/#{page}", class: "govuk-link" %>
<% end %>
<%= create_update_answer_link(case_log[page], case_log_id, page)%>
</dd>
</div>
</dl>
@ -23,3 +21,4 @@
<%= f.govuk_submit "Save and continue" %>
<% end %>
<% end %>

18
spec/features/case_log_spec.rb

@ -138,7 +138,7 @@ RSpec.describe "Test Features" do
it "should have an answer link for questions missing an answer" do
visit("case_logs/#{empty_case_log.id}/#{subsection}/check_answers")
assert_selector "a", text: "Answer", count: 7
assert_selector "a", text: /Answer\z/, count: 7
assert_selector "a", text: "Change", count: 0
expect(page).to have_link('Answer', href: "/case_logs/#{empty_case_log.id}/tenant_age")
end
@ -146,10 +146,24 @@ RSpec.describe "Test Features" do
it "should have a change link for answered questions" do
fill_in_number_question(empty_case_log.id, "tenant_age", 28)
visit("/case_logs/#{empty_case_log.id}/#{subsection}/check_answers")
assert_selector "a", text: "Answer", count: 6
assert_selector "a", text: /Answer\z/, count: 6
assert_selector "a", text: "Change", count: 1
expect(page).to have_link('Change', href: "/case_logs/#{empty_case_log.id}/tenant_age")
end
it "should have a link pointing to the first question if no questions are answered" do
visit("/case_logs/#{empty_case_log.id}/#{subsection}/check_answers")
expect(page).to have_content('You answered 0 of 7 questions')
expect(page).to have_link('Answer the missing questions', href: "/case_logs/#{empty_case_log.id}/tenant_code")
end
it "should have a link pointing to the next empty question if some questions are answered" do
fill_in_number_question(empty_case_log.id, "tenant_code", 0)
visit("/case_logs/#{empty_case_log.id}/#{subsection}/check_answers")
expect(page).to have_content('You answered 1 of 7 questions')
expect(page).to have_link('Answer the missing questions', href: "/case_logs/#{empty_case_log.id}/tenant_age")
end
end
end
end

Loading…
Cancel
Save