From 5f77e64b8420f9b0fc1eb9d9716746e1bcb641ea Mon Sep 17 00:00:00 2001
From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com>
Date: Thu, 31 Mar 2022 14:18:08 +0100
Subject: [PATCH] CLDC-1086: Change answer page routing (#439)
* Route back to the check answers if answer is changed from check answers page
* Remove redundant column
* Change field value in the test
* update test description
---
app/controllers/form_controller.rb | 9 +++++++-
app/views/form/_check_answers_table.html.erb | 2 +-
spec/features/form/check_answers_page_spec.rb | 22 +++++++++++++++----
3 files changed, 27 insertions(+), 6 deletions(-)
diff --git a/app/controllers/form_controller.rb b/app/controllers/form_controller.rb
index 95da341fc..b24632b31 100644
--- a/app/controllers/form_controller.rb
+++ b/app/controllers/form_controller.rb
@@ -8,7 +8,9 @@ class FormController < ApplicationController
@page = @case_log.form.get_page(params[:case_log][:page])
responses_for_page = responses_for_page(@page)
if @case_log.update(responses_for_page)
- if @case_log.form.is_last_question?(@page, @case_log.form.subsection_for_page(@page), @case_log)
+ if is_referrer_check_answers?
+ redirect_to(send("case_log_#{@case_log.form.subsection_for_page(@page).id}_check_answers_path", @case_log))
+ elsif @case_log.form.is_last_question?(@page, @case_log.form.subsection_for_page(@page), @case_log)
redirect_to(case_logs_path)
else
redirect_path = @case_log.form.next_page_redirect_path(@page, @case_log)
@@ -88,4 +90,9 @@ private
def find_resource_by_named_id
@case_log = current_user.case_logs.find_by(id: params[:case_log_id])
end
+
+ def is_referrer_check_answers?
+ referrer = request.headers["HTTP_REFERER"].presence || ""
+ referrer.present? && CGI.parse(referrer.split("?")[-1]).present? && CGI.parse(referrer.split("?")[-1])["referrer"][0] == "check_answers"
+ end
end
diff --git a/app/views/form/_check_answers_table.html.erb b/app/views/form/_check_answers_table.html.erb
index 4a2b7183a..ae22a0c14 100644
--- a/app/views/form/_check_answers_table.html.erb
+++ b/app/views/form/_check_answers_table.html.erb
@@ -9,6 +9,6 @@
<% end %>
- <%= govuk_link_to(question.update_answer_link_name(@case_log), "/logs/#{@case_log.id}/#{question.page.id.to_s.dasherize}").html_safe %>
+ <%= govuk_link_to(question.update_answer_link_name(@case_log), "/logs/#{@case_log.id}/#{question.page.id.to_s.dasherize}?referrer=check_answers").html_safe %>
diff --git a/spec/features/form/check_answers_page_spec.rb b/spec/features/form/check_answers_page_spec.rb
index 6ef6d7d3b..34125ee41 100644
--- a/spec/features/form/check_answers_page_spec.rb
+++ b/spec/features/form/check_answers_page_spec.rb
@@ -71,10 +71,10 @@ RSpec.describe "Form Check Answers Page" do
# Regex explanation: match the string "Answer" but not if it's follow by "the missing questions"
# This way only the links in the table will get picked up
it "has an answer link for questions missing an answer" do
- visit("/logs/#{empty_case_log.id}/#{subsection}/check-answers")
+ visit("/logs/#{empty_case_log.id}/#{subsection}/check-answers?referrer=check_answers")
assert_selector "a", text: /Answer (?!the missing questions)/, count: 5
assert_selector "a", text: "Change", count: 0
- expect(page).to have_link("Answer", href: "/logs/#{empty_case_log.id}/person-1-age")
+ expect(page).to have_link("Answer", href: "/logs/#{empty_case_log.id}/person-1-age?referrer=check_answers")
end
it "has a change link for answered questions" do
@@ -82,7 +82,7 @@ RSpec.describe "Form Check Answers Page" do
visit("/logs/#{empty_case_log.id}/#{subsection}/check-answers")
assert_selector "a", text: /Answer (?!the missing questions)/, count: 4
assert_selector "a", text: "Change", count: 1
- expect(page).to have_link("Change", href: "/logs/#{empty_case_log.id}/person-1-age")
+ expect(page).to have_link("Change", href: "/logs/#{empty_case_log.id}/person-1-age?referrer=check_answers")
end
it "updates the change/answer link when answers get updated" do
@@ -95,7 +95,7 @@ RSpec.describe "Form Check Answers Page" do
visit("/logs/#{empty_case_log.id}/household-needs/check-answers")
assert_selector "a", text: /Answer (?!the missing questions)/, count: 3
assert_selector "a", text: "Change", count: 2
- expect(page).to have_link("Change", href: "/logs/#{empty_case_log.id}/accessibility-requirements")
+ expect(page).to have_link("Change", href: "/logs/#{empty_case_log.id}/accessibility-requirements?referrer=check_answers")
end
it "does not display conditional questions that were not visited" do
@@ -127,6 +127,20 @@ RSpec.describe "Form Check Answers Page" do
end
end
+ context "when the user changes their answer from check answer page" do
+ it "routes back to check answers" do
+ visit("/logs/#{empty_case_log.id}/accessibility-requirements")
+ check("case-log-accessibility-requirements-housingneeds-c-field")
+ click_button("Save and continue")
+ visit("/logs/#{empty_case_log.id}/household-needs/check-answers")
+ first("a", text: /Change/).click
+ uncheck("case-log-accessibility-requirements-housingneeds-c-field")
+ check("case-log-accessibility-requirements-housingneeds-b-field")
+ click_button("Save and continue")
+ expect(page).to have_current_path("/logs/#{empty_case_log.id}/household-needs/check-answers")
+ end
+ end
+
context "when the user wants to bypass the tasklist page from check answers" do
let(:section_completed_case_log) do
FactoryBot.create(