Browse Source

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
pull/442/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
5f77e64b84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      app/controllers/form_controller.rb
  2. 2
      app/views/form/_check_answers_table.html.erb
  3. 22
      spec/features/form/check_answers_page_spec.rb

9
app/controllers/form_controller.rb

@ -8,7 +8,9 @@ class FormController < ApplicationController
@page = @case_log.form.get_page(params[:case_log][:page]) @page = @case_log.form.get_page(params[:case_log][:page])
responses_for_page = responses_for_page(@page) responses_for_page = responses_for_page(@page)
if @case_log.update(responses_for_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) redirect_to(case_logs_path)
else else
redirect_path = @case_log.form.next_page_redirect_path(@page, @case_log) redirect_path = @case_log.form.next_page_redirect_path(@page, @case_log)
@ -88,4 +90,9 @@ private
def find_resource_by_named_id def find_resource_by_named_id
@case_log = current_user.case_logs.find_by(id: params[:case_log_id]) @case_log = current_user.case_logs.find_by(id: params[:case_log_id])
end 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 end

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

@ -9,6 +9,6 @@
<% end %> <% end %>
</dd> </dd>
<dd class="govuk-summary-list__actions"> <dd class="govuk-summary-list__actions">
<%= 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 %>
</dd> </dd>
</div> </div>

22
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" # 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 # This way only the links in the table will get picked up
it "has an answer link for questions missing an answer" do 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: /Answer (?!the missing questions)/, count: 5
assert_selector "a", text: "Change", count: 0 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 end
it "has a change link for answered questions" do 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") visit("/logs/#{empty_case_log.id}/#{subsection}/check-answers")
assert_selector "a", text: /Answer (?!the missing questions)/, count: 4 assert_selector "a", text: /Answer (?!the missing questions)/, count: 4
assert_selector "a", text: "Change", count: 1 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 end
it "updates the change/answer link when answers get updated" do 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") visit("/logs/#{empty_case_log.id}/household-needs/check-answers")
assert_selector "a", text: /Answer (?!the missing questions)/, count: 3 assert_selector "a", text: /Answer (?!the missing questions)/, count: 3
assert_selector "a", text: "Change", count: 2 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 end
it "does not display conditional questions that were not visited" do it "does not display conditional questions that were not visited" do
@ -127,6 +127,20 @@ RSpec.describe "Form Check Answers Page" do
end end
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 context "when the user wants to bypass the tasklist page from check answers" do
let(:section_completed_case_log) do let(:section_completed_case_log) do
FactoryBot.create( FactoryBot.create(

Loading…
Cancel
Save