From 4209fbed036b30bf6478d65f5b038f3e7d26d884 Mon Sep 17 00:00:00 2001 From: Kat Date: Fri, 14 Jun 2024 09:12:41 +0100 Subject: [PATCH] Update answer links --- .../check_answers_summary_list_card_component.rb | 6 +++++- .../requests/check_your_errors_controller_spec.rb | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/components/check_answers_summary_list_card_component.rb b/app/components/check_answers_summary_list_card_component.rb index 952266aa3..463fa3193 100644 --- a/app/components/check_answers_summary_list_card_component.rb +++ b/app/components/check_answers_summary_list_card_component.rb @@ -31,7 +31,11 @@ class CheckAnswersSummaryListCardComponent < ViewComponent::Base def action_href(question, log, correcting_hard_validation: false) if correcting_hard_validation - lettings_log_confirm_clear_answer_path(log, question_id: question.id, related_question_ids: request.query_parameters["related_question_ids"], original_question_id: request.query_parameters["original_question_id"]) + if question.displayed_as_answered?(log) + lettings_log_confirm_clear_answer_path(log, question_id: question.id, related_question_ids: request.query_parameters["related_question_ids"], original_question_id: request.query_parameters["original_question_id"]) + else + send("#{log.model_name.param_key}_#{question.page.id}_path", log, referrer: "check_your_errors", related_question_ids: request.query_parameters["related_question_ids"], original_question_id: request.query_parameters["original_question_id"]) + end else referrer = question.displayed_as_answered?(log) ? "check_answers" : "check_answers_new_answer" send("#{log.model_name.param_key}_#{question.page.id}_path", log, referrer:) diff --git a/spec/requests/check_your_errors_controller_spec.rb b/spec/requests/check_your_errors_controller_spec.rb index b11592f60..7f219ba47 100644 --- a/spec/requests/check_your_errors_controller_spec.rb +++ b/spec/requests/check_your_errors_controller_spec.rb @@ -27,7 +27,7 @@ RSpec.describe CheckYourErrorsController, type: :request do end context "when user is signed in" do - context "with multiple error fields" 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" @@ -39,6 +39,19 @@ RSpec.describe CheckYourErrorsController, type: :request do 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") end end + + context "with multiple error fields and unanswered questions" 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" + 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") + end + end end end