diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb index 5941800aa..ec123db72 100644 --- a/app/helpers/check_answers_helper.rb +++ b/app/helpers/check_answers_helper.rb @@ -13,10 +13,19 @@ module CheckAnswersHelper end def create_next_missing_question_link(case_log_id, subsection_pages, case_log) - empty_question = subsection_pages.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 + pages_to_fill_in = [] + subsection_pages.each do |page_title, page_info| + page_info["questions"].any? { |q| case_log["q"].blank?} + pages_to_fill_in << page_title + end + url = "/case_logs/#{case_log_id}/#{pages_to_fill_in.first}" + 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 + end + questions.count + end end diff --git a/app/views/form/check_answers.html.erb b/app/views/form/check_answers.html.erb index a4404472f..503a6c700 100644 --- a/app/views/form/check_answers.html.erb +++ b/app/views/form/check_answers.html.erb @@ -1,6 +1,6 @@ <%= turbo_frame_tag "case_log_form", target: "_top" do %>
You answered <%= get_answered_questions_total(subsection_pages, case_log) %> of <%= subsection_pages.count %> questions
+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) %> <% subsection_pages.each do |page, page_info| %> <% page_info["questions"].each do |question_title, question_info| %> diff --git a/spec/features/case_log_spec.rb b/spec/features/case_log_spec.rb index 2af4c5433..ca520ce65 100644 --- a/spec/features/case_log_spec.rb +++ b/spec/features/case_log_spec.rb @@ -158,11 +158,11 @@ RSpec.describe "Test Features" do 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) + fill_in_number_question(empty_case_log.id, "net_income", 18000) - 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") + visit("/case_logs/#{empty_case_log.id}/income_and_benefits/check_answers") + 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 end end diff --git a/spec/helpers/check_answers_helper_spec.rb b/spec/helpers/check_answers_helper_spec.rb index 598fc9564..b85640bad 100644 --- a/spec/helpers/check_answers_helper_spec.rb +++ b/spec/helpers/check_answers_helper_spec.rb @@ -15,4 +15,14 @@ RSpec.describe CheckAnswersHelper do expect(get_answered_questions_total(subsection_pages, case_log)).to equal(1) end end + + describe "Get total number of questions" do + let!(:case_log) { FactoryBot.create(:case_log) } + @form = Form.new(2021, 2022) + subsection_pages = @form.pages_for_subsection("income_and_benefits") + + it "returns the total number of questions for a subsection" do + expect(get_total_number_of_questions(subsection_pages)).to eq(4) + end + end end