Browse Source

spec uses subsection with 2 questions on page

pull/25/head
MadeTech Dushan 3 years ago
parent
commit
9ca0063ac0
  1. 17
      app/helpers/check_answers_helper.rb
  2. 2
      app/views/form/check_answers.html.erb
  3. 8
      spec/features/case_log_spec.rb
  4. 10
      spec/helpers/check_answers_helper_spec.rb

17
app/helpers/check_answers_helper.rb

@ -13,10 +13,19 @@ module CheckAnswersHelper
end end
def create_next_missing_question_link(case_log_id, subsection_pages, case_log) def create_next_missing_question_link(case_log_id, subsection_pages, case_log)
empty_question = subsection_pages.keys.find{|x| case_log[x].blank? } pages_to_fill_in = []
subsection_pages.each do |page_title, page_info|
url = "/case_logs/#{case_log_id}/#{empty_question}" page_info["questions"].any? { |q| case_log["q"].blank?}
link_to('Answer the missing questions', url, class: "govuk-link").html_safe 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 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 end

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

@ -1,6 +1,6 @@
<%= turbo_frame_tag "case_log_form", target: "_top" do %> <%= turbo_frame_tag "case_log_form", target: "_top" do %>
<h1 class="govuk-heading-l">Check the answers you gave for household characteristics</h1> <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> <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) %> <%= create_next_missing_question_link(case_log["id"], subsection_pages, case_log) %>
<% subsection_pages.each do |page, page_info| %> <% subsection_pages.each do |page, page_info| %>
<% page_info["questions"].each do |question_title, question_info| %> <% page_info["questions"].each do |question_title, question_info| %>

8
spec/features/case_log_spec.rb

@ -158,11 +158,11 @@ RSpec.describe "Test Features" do
end end
it "should have a link pointing to the next empty question if some questions are answered" do 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") visit("/case_logs/#{empty_case_log.id}/income_and_benefits/check_answers")
expect(page).to have_content('You answered 1 of 7 questions') 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}/tenant_age") expect(page).to have_link('Answer the missing questions', href: "/case_logs/#{empty_case_log.id}/net_income")
end end
end end
end end

10
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) expect(get_answered_questions_total(subsection_pages, case_log)).to equal(1)
end end
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 end

Loading…
Cancel
Save