+ <% all_questions_with_errors = all_questions_affected_by_errors(@log) %>
<% remove_other_page_errors(@log, @page) %>
<%= f.govuk_error_summary %>
@@ -70,6 +71,12 @@
<%= f.hidden_field :interruption_page_id, value: @interruption_page_id %>
<%= f.hidden_field :interruption_page_referrer_type, value: @interruption_page_referrer_type %>
+ <% if all_questions_with_errors.count > 1 %>
+
+ <%= check_your_errors_link(@log, all_questions_with_errors, @page.id) %>
+
+ <% end %>
+
<% if !@page.interruption_screen? %>
<%= f.govuk_submit submit_button_text(@page, request.query_parameters["referrer"]) %>
diff --git a/spec/features/form/page_routing_spec.rb b/spec/features/form/page_routing_spec.rb
index 8ee63de03..0a0b7307f 100644
--- a/spec/features/form/page_routing_spec.rb
+++ b/spec/features/form/page_routing_spec.rb
@@ -119,6 +119,16 @@ RSpec.describe "Form Page Routing" do
expect(find_field("lettings_log[startdate(2i)]").value).to eq(nil)
expect(find_field("lettings_log[startdate(1i)]").value).to eq(nil)
end
+
+ it "does not show see all related answers link if only 1 field has an error" do
+ visit("/lettings-logs/#{id}/tenancy-start-date")
+ fill_in("lettings_log[startdate(1i)]", with: "202")
+ fill_in("lettings_log[startdate(2i)]", with: "32")
+ fill_in("lettings_log[startdate(3i)]", with: "0")
+ click_button("Save and continue")
+
+ expect(page).not_to have_link("See all related answers")
+ end
end
end
@@ -262,4 +272,21 @@ RSpec.describe "Form Page Routing" do
end
end
end
+
+ describe "composite validations" do
+ context "when error is added to multiple fields" do
+ before do
+ lettings_log.update(needstype: 1, declaration: 1, ecstat1: 10, hhmemb: 2, net_income_known: 0, incfreq: 1, earnings: 1000)
+ end
+
+ it "does shows see all related answers link" do
+ visit("/lettings-logs/#{id}/income-amount")
+ fill_in("lettings-log-earnings-field", with: "100000")
+ click_button("Save and continue")
+
+ expect(page).to have_current_path("/lettings-logs/#{id}/income-amount")
+ expect(page).to have_link("See all related answers", href: "/lettings-logs/#{id}/check-your-errors?original_page_id=income_amount&related_question_ids%5B%5D=earnings&related_question_ids%5B%5D=hhmemb&related_question_ids%5B%5D=ecstat1&related_question_ids%5B%5D=ecstat2")
+ end
+ end
+ end
end
diff --git a/spec/requests/check_your_errors_controller_spec.rb b/spec/requests/check_your_errors_controller_spec.rb
index 7f219ba47..6914192ed 100644
--- a/spec/requests/check_your_errors_controller_spec.rb
+++ b/spec/requests/check_your_errors_controller_spec.rb
@@ -30,13 +30,13 @@ RSpec.describe CheckYourErrorsController, type: :request do
context "with multiple error fields and answered questions" do
before do
sign_in user
- get "/lettings-logs/#{lettings_log.id}/check-your-errors?related_question_ids[]=startdate&related_question_ids[]=needstype&original_question_id=startdate"
+ get "/lettings-logs/#{lettings_log.id}/check-your-errors?related_question_ids[]=startdate&related_question_ids[]=needstype&original_page_id=tenancy_start_date"
end
it "displays correct clear links" do
- expect(page).to have_link("Clear", href: "/lettings-logs/#{lettings_log.id}/confirm-clear-answer?original_question_id=startdate&question_id=startdate&related_question_ids%5B%5D=startdate&related_question_ids%5B%5D=needstype")
- expect(page).to have_link("Clear", href: "/lettings-logs/#{lettings_log.id}/confirm-clear-answer?original_question_id=startdate&question_id=needstype&related_question_ids%5B%5D=startdate&related_question_ids%5B%5D=needstype")
- expect(page).to have_link("Clear all", href: "/lettings-logs/#{lettings_log.id}/confirm-clear-all-answers?original_question_id=startdate&related_question_ids%5B%5D=startdate&related_question_ids%5B%5D=needstype")
+ expect(page).to have_link("Clear", href: "/lettings-logs/#{lettings_log.id}/confirm-clear-answer?original_page_id=tenancy_start_date&question_id=startdate&related_question_ids%5B%5D=startdate&related_question_ids%5B%5D=needstype")
+ expect(page).to have_link("Clear", href: "/lettings-logs/#{lettings_log.id}/confirm-clear-answer?original_page_id=tenancy_start_date&question_id=needstype&related_question_ids%5B%5D=startdate&related_question_ids%5B%5D=needstype")
+ expect(page).to have_link("Clear all", href: "/lettings-logs/#{lettings_log.id}/confirm-clear-all-answers?original_page_id=tenancy_start_date&related_question_ids%5B%5D=startdate&related_question_ids%5B%5D=needstype")
end
end
@@ -44,12 +44,12 @@ RSpec.describe CheckYourErrorsController, type: :request do
before do
lettings_log.update!(needstype: nil, startdate: nil)
sign_in user
- get "/lettings-logs/#{lettings_log.id}/check-your-errors?related_question_ids[]=startdate&related_question_ids[]=needstype&original_question_id=startdate"
+ get "/lettings-logs/#{lettings_log.id}/check-your-errors?related_question_ids[]=startdate&related_question_ids[]=needstype&original_page_id=tenancy_start_date"
end
it "displays correct clear links" do
- expect(page).to have_link("Answer", href: "/lettings-logs/#{lettings_log.id}/needs-type?original_question_id=startdate&referrer=check_your_errors&related_question_ids%5B%5D=startdate&related_question_ids%5B%5D=needstype")
- expect(page).to have_link("Answer", href: "/lettings-logs/#{lettings_log.id}/tenancy-start-date?original_question_id=startdate&referrer=check_your_errors&related_question_ids%5B%5D=startdate&related_question_ids%5B%5D=needstype")
+ expect(page).to have_link("Answer", href: "/lettings-logs/#{lettings_log.id}/needs-type?original_page_id=tenancy_start_date&referrer=check_your_errors&related_question_ids%5B%5D=startdate&related_question_ids%5B%5D=needstype")
+ expect(page).to have_link("Answer", href: "/lettings-logs/#{lettings_log.id}/tenancy-start-date?original_page_id=tenancy_start_date&referrer=check_your_errors&related_question_ids%5B%5D=startdate&related_question_ids%5B%5D=needstype")
end
end
end