diff --git a/app/components/check_answers_summary_list_card_component.html.erb b/app/components/check_answers_summary_list_card_component.html.erb index 4a26b8c8d..aa2b0e4e5 100644 --- a/app/components/check_answers_summary_list_card_component.html.erb +++ b/app/components/check_answers_summary_list_card_component.html.erb @@ -35,8 +35,8 @@ <% if @log.collection_period_open_for_editing? %> <% row.with_action( - text: question.action_text(log), - href: action_href(question, log), + text: question.action_text(log, correcting_hard_validation: @correcting_hard_validation), + href: action_href(question, log, correcting_hard_validation: @correcting_hard_validation), visually_hidden_text: question.check_answer_label.to_s.downcase, ) %> <% end %> diff --git a/app/components/check_answers_summary_list_card_component.rb b/app/components/check_answers_summary_list_card_component.rb index 205a8516e..952266aa3 100644 --- a/app/components/check_answers_summary_list_card_component.rb +++ b/app/components/check_answers_summary_list_card_component.rb @@ -1,10 +1,11 @@ class CheckAnswersSummaryListCardComponent < ViewComponent::Base attr_reader :questions, :log, :user - def initialize(questions:, log:, user:) + def initialize(questions:, log:, user:, correcting_hard_validation: false) @questions = questions @log = log @user = user + @correcting_hard_validation = correcting_hard_validation super end @@ -28,9 +29,13 @@ class CheckAnswersSummaryListCardComponent < ViewComponent::Base "Person #{question.check_answers_card_number}" end - def action_href(question, log) - referrer = question.displayed_as_answered?(log) ? "check_answers" : "check_answers_new_answer" - send("#{log.model_name.param_key}_#{question.page.id}_path", log, referrer:) + 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"]) + 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:) + end end private diff --git a/app/controllers/check_your_errors_controller.rb b/app/controllers/check_your_errors_controller.rb new file mode 100644 index 000000000..ca5e23349 --- /dev/null +++ b/app/controllers/check_your_errors_controller.rb @@ -0,0 +1,23 @@ +class CheckYourErrorsController < ApplicationController + include DuplicateLogsHelper + + before_action :authenticate_user! + before_action :find_resource_by_named_id + + def index + return render_not_found unless @log + + related_question_ids = params[:related_question_ids] + @questions = @log.form.questions.select { |q| related_question_ids.include?(q.id.to_s) } + end + +private + + def find_resource_by_named_id + @log = if params[:sales_log_id].present? + current_user.sales_logs.visible.find_by(id: params[:sales_log_id]) + else + current_user.lettings_logs.visible.find_by(id: params[:lettings_log_id]) + end + end +end diff --git a/app/models/form/question.rb b/app/models/form/question.rb index aa019c1c6..7637b1acd 100644 --- a/app/models/form/question.rb +++ b/app/models/form/question.rb @@ -111,8 +111,10 @@ class Form::Question end end - def action_text(log) - displayed_as_answered?(log) ? "Change" : "Answer" + def action_text(log, correcting_hard_validation: false) + return "Answer" unless displayed_as_answered?(log) + + correcting_hard_validation ? "Clear" : "Change" end def displayed_as_answered?(log) diff --git a/app/views/check_your_errors/index.html.erb b/app/views/check_your_errors/index.html.erb new file mode 100644 index 000000000..4e304c5c6 --- /dev/null +++ b/app/views/check_your_errors/index.html.erb @@ -0,0 +1,16 @@ +
+
+

+ + Make sure these answers are correct: + + + <%= govuk_link_to "Clear all", lettings_log_confirm_clear_all_answers_path(@log, related_question_ids: request.query_parameters["related_question_ids"] , original_question_id: request.query_parameters["original_question_id"])%> + +

+ + <%= render CheckAnswersSummaryListCardComponent.new(questions: @questions, log: @log, user: current_user, correcting_hard_validation: true) %> + + <%= govuk_button_link_to "Confirm and continue", "/" %> +
+
diff --git a/config/routes.rb b/config/routes.rb index 5361f5733..9cc8f4e15 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -212,6 +212,9 @@ Rails.application.routes.draw do get "delete-confirmation", to: "lettings_logs#delete_confirmation" get "duplicate-logs", to: "duplicate_logs#show" get "delete-duplicates", to: "duplicate_logs#delete_duplicates" + get "check-your-errors", to: "check_your_errors#index" + get "confirm-clear-answer", to: "check_your_errors#confirm_clear_answer" + get "confirm-clear-all-answers", to: "check_your_errors#confirm_clear_all_answers" collection do get "csv-download", to: "lettings_logs#download_csv" diff --git a/spec/requests/check_your_errors_controller_spec.rb b/spec/requests/check_your_errors_controller_spec.rb new file mode 100644 index 000000000..b11592f60 --- /dev/null +++ b/spec/requests/check_your_errors_controller_spec.rb @@ -0,0 +1,56 @@ +require "rails_helper" + +RSpec.describe CheckYourErrorsController, type: :request do + let(:page) { Capybara::Node::Simple.new(response.body) } + let(:user) { create(:user, :data_coordinator) } + let(:lettings_log) { create(:lettings_log, :duplicate, assigned_to: user) } + + describe "check your errors page" do + context "when user is not signed in" do + it "redirects to sign in page" do + get "/lettings-logs/#{lettings_log.id}/check-your-errors" + expect(response).to redirect_to("/account/sign-in") + end + end + + context "when the user is from different organisation" do + let(:other_user) { create(:user) } + + before do + sign_in other_user + end + + it "renders page not found" do + get "/lettings-logs/#{lettings_log.id}/check-your-errors" + expect(response).to have_http_status(:not_found) + end + end + + context "when user is signed in" do + context "with multiple error fields" 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" + 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") + end + end + end + end + + describe "confirm clear answer page" do + end + + describe "confirm clear all answers page" do + end + + describe "clear answer" do + end + + describe "clear all answers" do + end +end