Browse Source

add spec for all questions answered text

pull/25/head
MadeTech Dushan 3 years ago
parent
commit
0333a1c1ca
  1. 19
      app/helpers/check_answers_helper.rb
  2. 3
      app/views/form/check_answers.html.erb
  3. 17
      spec/features/case_log_spec.rb

19
app/helpers/check_answers_helper.rb

@ -6,6 +6,12 @@ module CheckAnswersHelper
questions.count { |question| case_log[question].present? }
end
def get_total_number_of_questions(subsection_pages)
questions = subsection_pages.values.flat_map do |page|
page["questions"].keys
end
questions.count
end
def create_update_answer_link(case_log_answer, case_log_id, page)
link_name = case_log_answer.blank? ? "Answer" : "Change"
@ -22,10 +28,13 @@ module CheckAnswersHelper
link_to('Answer the missing questions', url, class: "govuk-link").html_safe
end
def get_total_number_of_questions(subsection_pages)
questions = subsection_pages.values.flat_map do |page|
page["questions"].keys
def display_answered_questions_summary(subsection_pages, case_log)
if get_answered_questions_total(subsection_pages, case_log) == get_total_number_of_questions(subsection_pages)
"<p>You answered all the questions</p>".html_safe
else
"<p>You answered #{get_answered_questions_total(subsection_pages, case_log)} of #{get_total_number_of_questions(subsection_pages)} questions</p>
#{create_next_missing_question_link(case_log["id"], subsection_pages, case_log)}".html_safe
end
questions.count
end
end
end

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

@ -1,7 +1,6 @@
<%= 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 <%= get_total_number_of_questions(subsection_pages) %> questions</p>
<%= create_next_missing_question_link(case_log["id"], subsection_pages, case_log) %>
<%= display_answered_questions_summary(subsection_pages, case_log) %>
<% subsection_pages.each do |page, page_info| %>
<% page_info["questions"].each do |question_title, question_info| %>
<%= render partial: 'form/check_answers_table', locals: { question_title: question_title, question_info: question_info, case_log: case_log } %>

17
spec/features/case_log_spec.rb

@ -108,6 +108,17 @@ RSpec.describe "Test Features" do
click_button("Save and continue")
end
def answer_all_questions_in_income_subsection
visit("/case_logs/#{empty_case_log.id}/net_income")
fill_in("net_income", with: 18000)
choose("net-income-frequency-yearly-field")
click_button("Save and continue")
choose("net-income-uc-proportion-all-field")
click_button("Save and continue")
choose("housing-benefit-housing-benefit-but-not-universal-credit-field")
click_button("Save and continue")
end
it "can be visited by URL" do
visit("case_logs/#{id}/#{subsection}/check_answers")
expect(page).to have_content("Check the answers you gave for #{subsection.tr('_', ' ')}")
@ -164,6 +175,12 @@ RSpec.describe "Test Features" do
expect(page).to have_content('You answered 1 of 4 questions')
expect(page).to have_link('Answer the missing questions', href: "/case_logs/#{empty_case_log.id}/net_income")
end
it "should not display the missing answer questions link if all questions are answered" do
answer_all_questions_in_income_subsection
expect(page).to have_content('You answered all the questions')
assert_selector "a", text: "Answer the missing questions", count: 0
end
end
end
end

Loading…
Cancel
Save