diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb
new file mode 100644
index 000000000..883105de9
--- /dev/null
+++ b/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
diff --git a/app/views/form/check_answers.html.erb b/app/views/form/check_answers.html.erb
index 1c9de803a..8df10dcc8 100644
--- a/app/views/form/check_answers.html.erb
+++ b/app/views/form/check_answers.html.erb
@@ -1,5 +1,7 @@
<%= turbo_frame_tag "case_log_form", target: "_top" do %>
Check the answers you gave for household characteristics
+ You answered <%= get_answered_questions_total(subsection_pages, case_log) %> of <%= subsection_pages.count %> questions
+ <%= create_next_missing_question_link(case_log_id, subsection_pages, case_log) %>
<% subsection_pages.each do |page, page_info| %>
@@ -10,11 +12,7 @@
<%= case_log[page] %>
-
- <% 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)%>
@@ -23,3 +21,4 @@
<%= f.govuk_submit "Save and continue" %>
<% end %>
<% end %>
+
diff --git a/spec/features/case_log_spec.rb b/spec/features/case_log_spec.rb
index 861d9d49e..9f0e5e643 100644
--- a/spec/features/case_log_spec.rb
+++ b/spec/features/case_log_spec.rb
@@ -124,9 +124,9 @@ RSpec.describe "Test Features" do
question_labels = ["Tenant code", "Tenant's age", "Tenant's gender", "Ethnicity", "Nationality", "Work", "Number of Other Household Members"]
question_labels.each do |label|
expect(page).to have_content(label)
- end
+ end
end
-
+
it "should display answers given by the user for the question in the subsection" do
fill_in_number_question(empty_case_log.id, "tenant_age", 28)
choose("tenant-gender-non-binary-field")
@@ -134,22 +134,36 @@ RSpec.describe "Test Features" do
visit("/case_logs/#{empty_case_log.id}/#{subsection}/check_answers")
expect(page).to have_content("28")
expect(page).to have_content("Non-binary")
- end
-
+ end
+
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
- it "should have a change link for answered questions" 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
+ 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