diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb index ec123db72..7bc4cca79 100644 --- a/app/helpers/check_answers_helper.rb +++ b/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) + "
You answered all the questions
".html_safe + else + "You answered #{get_answered_questions_total(subsection_pages, case_log)} of #{get_total_number_of_questions(subsection_pages)} questions
+ #{create_next_missing_question_link(case_log["id"], subsection_pages, case_log)}".html_safe + end - questions.count - end + end end diff --git a/app/views/form/check_answers.html.erb b/app/views/form/check_answers.html.erb index 503a6c700..4ef25a0bf 100644 --- a/app/views/form/check_answers.html.erb +++ b/app/views/form/check_answers.html.erb @@ -1,7 +1,6 @@ <%= turbo_frame_tag "case_log_form", target: "_top" do %>You answered <%= get_answered_questions_total(subsection_pages, case_log) %> of <%= get_total_number_of_questions(subsection_pages) %> questions
- <%= 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 } %> diff --git a/spec/features/case_log_spec.rb b/spec/features/case_log_spec.rb index ca520ce65..82d161ee8 100644 --- a/spec/features/case_log_spec.rb +++ b/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