Browse Source

CLDC-3465 Update hard validations flow (#2472)

* Add check your errors page with clear links

* Update answer links

* Link to check your errors page

* Refactor check errors page

* Allow clearing answers

* Update styling and lint

* Add routing for sales

* lint

* Update page routing test

* Remove unused code

* CLDC-3465 Handle additional errors (#2480)

* Keep check errors query params

* Add success banner

* Update confirm and continue button

* CLDC-3465 Allow clearing all error questions (#2483)

* Allow clearing all error questions

* Update setup question link

* Update clear all to ignore setup questions

* Update correct_validation_action_href

* Extract some vriables

* CLDC-3465 Do not display non persisted values in check errors page (#2484)

* Do not display non persisted values on check_errors page

* Remove govuk button styling from link

* Update warning message

* Update copy
pull/2508/head
kosiakkatrina 6 months ago committed by GitHub
parent
commit
0f4bc32d6e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      app/components/check_answers_summary_list_card_component.html.erb
  2. 13
      app/components/check_answers_summary_list_card_component.rb
  3. 37
      app/controllers/check_errors_controller.rb
  4. 62
      app/controllers/form_controller.rb
  5. 8
      app/frontend/styles/_button.scss
  6. 11
      app/helpers/check_errors_helper.rb
  7. 4
      app/helpers/form_page_error_helper.rb
  8. 6
      app/models/form/question.rb
  9. 32
      app/views/check_errors/confirm_clear_all_answers.html.erb
  10. 31
      app/views/check_errors/confirm_clear_answer.html.erb
  11. 66
      app/views/form/check_errors.html.erb
  12. 12
      app/views/form/page.html.erb
  13. 4
      config/routes.rb
  14. 27
      spec/features/form/page_routing_spec.rb
  15. 455
      spec/requests/check_errors_controller_spec.rb

4
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: correct_validation_action_href(question, log, applicable_questions.map(&:id), @correcting_hard_validation),
visually_hidden_text: question.check_answer_label.to_s.downcase,
) %>
<% end %>

13
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
@ -33,6 +34,16 @@ class CheckAnswersSummaryListCardComponent < ViewComponent::Base
send("#{log.model_name.param_key}_#{question.page.id}_path", log, referrer:)
end
def correct_validation_action_href(question, log, _related_question_ids, correcting_hard_validation)
return action_href(question, log) unless correcting_hard_validation
if question.displayed_as_answered?(log)
send("#{log.model_name.param_key}_confirm_clear_answer_path", log, question_id: question.id)
else
send("#{log.model_name.param_key}_#{question.page.id}_path", log, referrer: "check_errors", related_question_ids: request.query_parameters["related_question_ids"], original_page_id: request.query_parameters["original_page_id"])
end
end
private
def unanswered_value(question)

37
app/controllers/check_errors_controller.rb

@ -0,0 +1,37 @@
class CheckErrorsController < ApplicationController
include DuplicateLogsHelper
before_action :authenticate_user!
before_action :find_resource_by_named_id
def confirm_clear_answer
return render_not_found unless @log
@related_question_ids = params[@log.model_name.param_key].keys.reject { |id| id == "page_id" }
@page = @log.form.get_page(params[@log.model_name.param_key]["page_id"])
if params["clear_all"]
@questions_to_clear = @related_question_ids.map { |id|
question = @log.form.get_question(id, @log)
next if question.subsection.id == "setup"
question.page.questions.map(&:id)
}.flatten.compact
render :confirm_clear_all_answers
else
question_id = @related_question_ids.find { |id| !params[id].nil? }
@question = @log.form.get_question(question_id, @log)
end
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

62
app/controllers/form_controller.rb

@ -9,6 +9,8 @@ class FormController < ApplicationController
def submit_form
if @log
@page = form.get_page(params[@log.model_name.param_key][:page])
return render_check_errors_page if params["check_errors"]
shown_page_ids_with_unanswered_questions_before_update = @page.subsection.pages
.select { |page| page.routed_to?(@log, current_user) }
.select { |page| page.has_unanswered_questions?(@log) }
@ -30,7 +32,8 @@ class FormController < ApplicationController
mandatory_questions_with_no_response.map do |question|
@log.errors.add question.id.to_sym, question.unanswered_error_message, category: :not_answered
end
Rails.logger.info "User triggered validation(s) on: #{@log.errors.map(&:attribute).join(', ')}"
error_attributes = @log.errors.map(&:attribute)
Rails.logger.info "User triggered validation(s) on: #{error_attributes.join(', ')}"
@subsection = form.subsection_for_page(@page)
restore_error_field_values(@page&.questions)
render "form/page"
@ -64,12 +67,23 @@ class FormController < ApplicationController
@interruption_page_referrer_type = from_referrer_query("referrer")
end
if adding_answer_from_check_errors_page?
@related_question_ids = request.params["related_question_ids"]
@original_page_id = request.params["original_page_id"]
@check_errors = true
end
if @log
page_id = request.path.split("/")[-1].underscore
@page = form.get_page(page_id)
@subsection = form.subsection_for_page(@page)
if @page.routed_to?(@log, current_user) || is_referrer_type?("interruption_screen")
if @page.routed_to?(@log, current_user) || is_referrer_type?("interruption_screen") || adding_answer_from_check_errors_page?
if updated_answer_from_check_errors_page?
@questions = request.params["related_question_ids"].map { |id| @log.form.get_question(id, @log) }
render "form/check_errors"
else
render "form/page"
end
else
redirect_to @log.lettings? ? lettings_log_path(@log) : sales_log_path(@log)
end
@ -213,6 +227,20 @@ private
return send("#{@log.class.name.underscore}_#{previous_interruption_screen_page_id}_path", @log, { referrer: previous_interruption_screen_referrer, original_log_id: original_duplicate_log_id_from_query }.compact)
end
if params[@log.model_name.param_key]["check_errors"]
@page = form.get_page(params[@log.model_name.param_key]["page"])
flash[:notice] = "You have successfully updated #{@page.questions.map(&:check_answer_label).to_sentence}"
original_page_id = params[@log.model_name.param_key]["original_page_id"]
related_question_ids = params[@log.model_name.param_key]["related_question_ids"].split(" ")
return send("#{@log.class.name.underscore}_#{original_page_id}_path", @log, { check_errors: true, related_question_ids: }.compact)
end
if params["referrer"] == "check_errors"
@page = form.get_page(params[@log.model_name.param_key]["page"])
flash[:notice] = "You have successfully updated #{@page.questions.map(&:check_answer_label).to_sentence}"
return send("#{@log.class.name.underscore}_#{params['original_page_id']}_path", @log, { check_errors: true, related_question_ids: params["related_question_ids"] }.compact)
end
is_new_answer_from_check_answers = is_referrer_type?("check_answers_new_answer")
redirect_path = form.next_page_redirect_path(@page, @log, current_user, ignore_answered: is_new_answer_from_check_answers)
referrer = is_new_answer_from_check_answers ? "check_answers_new_answer" : nil
@ -374,4 +402,34 @@ private
true
end
def render_check_errors_page
if params[@log.model_name.param_key]["clear_question_ids"].present?
question_ids = params[@log.model_name.param_key]["clear_question_ids"].split(" ")
question_ids.each do |question_id|
question = @log.form.get_question(question_id, @log)
next if question.subsection.id == "setup"
question.page.questions.map(&:id).each { |id| @log[id] = nil }
end
@log.save!
@questions = params[@log.model_name.param_key].keys.reject { |id| %w[clear_question_ids page].include?(id) }.map { |id| @log.form.get_question(id, @log) }
else
responses_for_page = responses_for_page(@page)
@log.assign_attributes(responses_for_page)
@log.valid?
@log.reload
error_attributes = @log.errors.map(&:attribute)
@questions = @log.form.questions.select { |q| error_attributes.include?(q.id.to_sym) }
end
render "form/check_errors"
end
def adding_answer_from_check_errors_page?
request.params["referrer"] == "check_errors"
end
def updated_answer_from_check_errors_page?
params["check_errors"]
end
end

8
app/frontend/styles/_button.scss

@ -29,3 +29,11 @@ $app-button-inverse-hover-background-colour: govuk-tint($app-button-inverse-fore
background-color: $app-button-inverse-hover-background-colour;
box-shadow: inset 0 0 0 2px $govuk-focus-colour;
}
.submit-button-link {
background: none;
border: none;
color: #1d70b8;
text-decoration: underline;
cursor: pointer;
}

11
app/helpers/check_errors_helper.rb

@ -0,0 +1,11 @@
module CheckErrorsHelper
include GovukLinkHelper
def check_errors_answer_text(question, log)
question.displayed_as_answered?(log) ? "Change" : "Answer"
end
def check_errors_answer_link(log, question, page, applicable_questions)
send("#{log.model_name.param_key}_#{question.page.id}_path", log, referrer: "check_errors", original_page_id: page.id, related_question_ids: applicable_questions.map(&:id))
end
end

4
app/helpers/form_page_error_helper.rb

@ -3,4 +3,8 @@ module FormPageErrorHelper
other_page_error_ids = lettings_log.errors.map(&:attribute) - page.questions.map { |q| q.id.to_sym }.concat([:base])
other_page_error_ids.each { |id| lettings_log.errors.delete(id) }
end
def all_questions_affected_by_errors(log)
log.errors.map(&:attribute) - [:base]
end
end

6
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)

32
app/views/check_errors/confirm_clear_all_answers.html.erb

@ -0,0 +1,32 @@
<% content_for :before_content do %>
<% content_for :title, "Are you sure you want to clear all?" %>
<% end %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<h1 class="govuk-heading-xl">
<%= content_for(:title) %>
</h1>
<p class="govuk-body">You've selected <%= @questions_to_clear.count %> answers to clear</p>
<%= govuk_warning_text(text: "Dependent answers related to this question may also get cleared. You will not be able to undo this action") %>
<%= form_with model: @log, url: send("#{@log.model_name.param_key}_#{@page.id}_path", @log), method: "post", local: true do |f| %>
<% @related_question_ids.each do |id| %>
<%= f.hidden_field id, value: @log[id] %>
<% end %>
<%= f.hidden_field :clear_question_ids, value: @questions_to_clear %>
<%= f.hidden_field :page, value: @page.id %>
<div class="govuk-button-group">
<%= f.govuk_submit "Confirm and continue", name: "check_errors" %>
<%= govuk_button_link_to(
"Cancel",
"javascript:history.back()",
secondary: true,
) %>
</div>
<% end %>
</div>
</div>

31
app/views/check_errors/confirm_clear_answer.html.erb

@ -0,0 +1,31 @@
<% content_for :before_content do %>
<% content_for :title, "Are you sure you want to clear #{@question.check_answer_label}?" %>
<% end %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<h1 class="govuk-heading-xl">
<%= content_for(:title) %>
</h1>
<%= govuk_warning_text(text: "Dependent answers related to this question may also get cleared. You will not be able to undo this action.") %>
<%= form_with model: @log, url: send("#{@log.model_name.param_key}_#{@page.id}_path", @log), method: "post", local: true do |f| %>
<% @related_question_ids.each do |id| %>
<%= f.hidden_field id, value: @log[id] %>
<% end %>
<%= f.hidden_field :clear_question_ids, value: [@question.id] %>
<%= f.hidden_field :page, value: @page.id %>
<div class="govuk-button-group">
<%= f.govuk_submit "Confirm and continue", name: "check_errors" %>
<%= govuk_button_link_to(
"Cancel",
"javascript:history.back()",
secondary: true,
) %>
</div>
<% end %>
</div>
</div>

66
app/views/form/check_errors.html.erb

@ -0,0 +1,66 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-three-quarters-from-desktop">
<%= form_with model: @log, url: send("#{@log.model_name.param_key}_confirm_clear_answer_path", @log), method: "post", local: true do |f| %>
<%= f.govuk_error_summary %>
<%= f.hidden_field :page_id, value: @page.id %>
<h1 class="govuk-heading-m">
<div class="govuk-grid-row">
<span class="govuk-grid-column-two-thirds">
Make sure these answers are correct:
</span>
<span class="govuk-body govuk-!-text-align-right govuk-grid-column-one-third">
<input type="submit" value="Clear all" class="govuk-body govuk-link submit-button-link" name="clear_all">
</span>
</div>
</h1>
<div class="govuk-summary-card">
<div class="govuk-summary-card__content">
<% applicable_questions = @questions.reject { |q| q.hidden_in_check_answers?(@log, current_user) } %>
<dl class="govuk-summary-list">
<% applicable_questions.each do |question| %>
<%= f.hidden_field question.id, value: @log[question.id] %>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= get_question_label(question) %>
</dt>
<dd class="govuk-summary-list__value">
<%= simple_format(
get_answer_label(question, @log),
wrapper_tag: "span",
class: "govuk-!-margin-right-4",
) %>
<% extra_value = question.get_extra_check_answer_value(@log) %>
<% if extra_value && question.answer_label(@log).present? %>
<%= simple_format(
extra_value,
wrapper_tag: "span",
class: "govuk-!-font-weight-regular app-!-colour-muted",
) %>
<% end %>
<% question.get_inferred_answers(@log).each do |inferred_answer| %>
<span class="govuk-!-font-weight-regular app-!-colour-muted"><%= inferred_answer %></span>
<% end %>
</dd>
<dd class="govuk-summary-list__actions">
<% if !question.displayed_as_answered?(@log) || question.subsection.id == "setup" %>
<%= govuk_link_to check_errors_answer_text(question, @log), check_errors_answer_link(@log, question, @page, applicable_questions) %>
<% else %>
<input type="submit" value="Clear" class="govuk-body govuk-link submit-button-link" name="<%= question.id %>">
<% end %>
</dd>
</div>
<% end %>
</dl>
</div>
</div>
<% end %>
<%= govuk_button_link_to "Confirm and continue", @original_page_id ? send("#{@log.model_name.param_key}_#{@original_page_id}_path", @log) : send("#{@log.model_name.param_key}_#{@page.id}_path", @log) %>
</div>
</div>

12
app/views/form/page.html.erb

@ -16,6 +16,7 @@
<%= form_with model: @log, url: request.original_url, method: "post", local: true do |f| %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds-from-desktop">
<% all_questions_with_errors = all_questions_affected_by_errors(@log) %>
<% remove_other_page_errors(@log, @page) %>
<%= f.govuk_error_summary %>
@ -69,6 +70,17 @@
<%= f.hidden_field :page, value: @page.id %>
<%= f.hidden_field :interruption_page_id, value: @interruption_page_id %>
<%= f.hidden_field :interruption_page_referrer_type, value: @interruption_page_referrer_type %>
<%= f.hidden_field :related_question_ids, value: @related_question_ids %>
<%= f.hidden_field :original_page_id, value: @original_page_id %>
<% if @check_errors %>
<%= f.hidden_field :check_errors, value: @check_errors %>
<% end %>
<% if all_questions_with_errors.count > 1 %>
<div class="govuk-button-group">
<%= f.submit "See all related answers", name: "check_errors", class: "govuk-body govuk-link submit-button-link" %>
</div>
<% end %>
<div class="govuk-button-group">
<% if !@page.interruption_screen? %>

4
config/routes.rb

@ -214,6 +214,8 @@ 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"
post "confirm-clear-answer", to: "check_errors#confirm_clear_answer"
post "confirm-clear-all-answers", to: "check_errors#confirm_clear_all_answers"
collection do
get "csv-download", to: "lettings_logs#download_csv"
@ -284,6 +286,8 @@ Rails.application.routes.draw do
get "delete-confirmation", to: "sales_logs#delete_confirmation"
get "duplicate-logs", to: "duplicate_logs#show"
get "delete-duplicates", to: "duplicate_logs#delete_duplicates"
post "confirm-clear-answer", to: "check_errors#confirm_clear_answer"
post "confirm-clear-all-answers", to: "check_errors#confirm_clear_all_answers"
collection do
get "csv-download", to: "sales_logs#download_csv"

27
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_button("See all related answers")
end
end
end
end

455
spec/requests/check_errors_controller_spec.rb

@ -0,0 +1,455 @@
require "rails_helper"
RSpec.describe CheckErrorsController, type: :request do
let(:page) { Capybara::Node::Simple.new(response.body) }
let(:user) { create(:user, :data_coordinator) }
let(:lettings_log) { create(:lettings_log, :setup_completed, assigned_to: user) }
let(:sales_log) { create(:sales_log, :shared_ownership_setup_complete, assigned_to: user) }
describe "check errors page" do
context "when user is not signed in" do
it "redirects to sign in page for lettings" do
post "/lettings-logs/#{lettings_log.id}/net-income", params: {}
expect(response).to redirect_to("/account/sign-in")
end
it "redirects to sign in page for sales" do
post "/sales-logs/#{sales_log.id}/buyer-1-income", params: {}
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 for lettings" do
post "/lettings-logs/#{lettings_log.id}/net-income", params: {}
expect(response).to have_http_status(:not_found)
end
it "renders page not found for sales" do
post "/sales-logs/#{sales_log.id}/buyer-1-income", params: {}
expect(response).to have_http_status(:not_found)
end
end
context "when user is signed in" do
context "with multiple error fields and answered questions for lettings" do
let(:params) do
{
id: lettings_log.id,
lettings_log: {
page: "income_amount",
earnings: "100000",
incfreq: "1",
},
check_errors: "",
}
end
before do
lettings_log.update!(needstype: 1, declaration: 1, ecstat1: 10, hhmemb: 2, net_income_known: 0, incfreq: nil, earnings: nil)
sign_in user
post "/lettings-logs/#{lettings_log.id}/income-amount", params: params
end
it "displays correct clear links" do
expect(page).to have_selector("input[type=submit][value='Clear']", count: 2)
expect(page).to have_button("Clear all")
end
end
context "with multiple error fields and answered questions for sales" do
let(:params) do
{
id: sales_log.id,
sales_log: {
page: "buyer_1_income",
income1: "100000",
la: "E09000001",
ownershipsch: "1",
},
check_errors: "",
}
end
before do
sales_log.update!(income1: 1000, la: "E09000001")
sign_in user
post "/sales-logs/#{sales_log.id}/buyer-1-income", params: params
end
it "displays correct clear and change links" do
expect(page.all(:button, value: "Clear").count).to eq(2)
expect(page).to have_link("Change", count: 1)
expect(page).to have_button("Clear all")
end
end
end
end
describe "confirm clear answer page" do
context "when user is not signed in" do
it "redirects to sign in page for lettings" do
post "/lettings-logs/#{lettings_log.id}/confirm-clear-answer", params: {}
expect(response).to redirect_to("/account/sign-in")
end
it "redirects to sign in page for sales" do
post "/sales-logs/#{sales_log.id}/confirm-clear-answer", params: {}
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 for lettings" do
post "/lettings-logs/#{lettings_log.id}/confirm-clear-answer", params: {}
expect(response).to have_http_status(:not_found)
end
it "renders page not found for sales" do
post "/sales-logs/#{sales_log.id}/confirm-clear-answer", params: {}
expect(response).to have_http_status(:not_found)
end
end
context "when user is signed in" do
context "and clearing specific lettings question" do
let(:params) do
{
id: lettings_log.id,
lettings_log: {
earnings: "100000",
incfreq: "1",
hhmemb: "2",
page_id: "income_amount",
},
hhmemb: "",
}
end
before do
sign_in user
post "/lettings-logs/#{lettings_log.id}/confirm-clear-answer", params:
end
it "displays correct clear links" do
expect(page).to have_content("Are you sure you want to clear Number of household members?")
expect(page).to have_content("Dependent answers related to this question may also get cleared. You will not be able to undo this action.")
expect(page).to have_link("Cancel")
expect(page).to have_button("Confirm and continue")
end
end
context "and clearing specific sales question" do
let(:params) do
{
id: sales_log.id,
sales_log: {
income1: "100000",
la: "E09000001",
ownershipsch: "1",
page_id: "buyer_1_income",
},
income1: "",
}
end
before do
sign_in user
post "/sales-logs/#{sales_log.id}/confirm-clear-answer", params:
end
it "displays correct clear links" do
expect(page).to have_content("Are you sure you want to clear Buyer 1’s gross annual income?")
expect(page).to have_content("Dependent answers related to this question may also get cleared. You will not be able to undo this action.")
expect(page).to have_link("Cancel")
expect(page).to have_button("Confirm and continue")
end
end
end
end
describe "confirm clear all answers" do
context "when user is signed in" do
context "and clearing all lettings questions" do
let(:params) do
{
id: lettings_log.id,
clear_all: "Clear all",
lettings_log: {
earnings: "100000",
incfreq: "1",
hhmemb: "2",
page_id: "income_amount",
},
}
end
before do
sign_in user
post "/lettings-logs/#{lettings_log.id}/confirm-clear-answer", params:
end
it "displays correct clear links" do
expect(page).to have_content("Are you sure you want to clear all")
expect(page).to have_content("You've selected 5 answers to clear")
expect(page).to have_content("You will not be able to undo this action")
expect(page).to have_link("Cancel")
expect(page).to have_button("Confirm and continue")
end
end
context "and clearing all sales question" do
let(:params) do
{
id: sales_log.id,
clear_all: "Clear all",
sales_log: {
income1: "100000",
la: "E09000001",
ownershipsch: "1",
page_id: "buyer_1_income",
},
}
end
before do
sign_in user
post "/sales-logs/#{sales_log.id}/confirm-clear-answer", params:
end
it "displays correct clear links" do
expect(page).to have_content("Are you sure you want to clear all")
expect(page).to have_content("You've selected 3 answers to clear")
expect(page).to have_content("You will not be able to undo this action")
expect(page).to have_link("Cancel")
expect(page).to have_button("Confirm and continue")
end
end
end
end
describe "clear answer" do
context "when user is not signed in" do
it "redirects to sign in page for lettings" do
post "/lettings-logs/#{lettings_log.id}/income-amount", params: {}
expect(response).to redirect_to("/account/sign-in")
end
it "redirects to sign in page for sales" do
post "/sales-logs/#{sales_log.id}/buyer-1-income", params: {}
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 for lettings" do
post "/lettings-logs/#{lettings_log.id}/income-amount", params: {}
expect(response).to have_http_status(:not_found)
end
it "renders page not found for sales" do
post "/sales-logs/#{lettings_log.id}/buyer-1-income", params: {}
expect(response).to have_http_status(:not_found)
end
end
context "when user is signed in" do
context "and clearing specific lettings question" do
let(:params) do
{
id: lettings_log.id,
lettings_log: {
earnings: "100000",
incfreq: "1",
hhmemb: "2",
clear_question_ids: "hhmemb",
page: "income_amount",
},
check_errors: "",
}
end
before do
sign_in user
post "/lettings-logs/#{lettings_log.id}/income-amount", params:
end
it "displays correct clear links" do
expect(page).to have_content("Make sure these answers are correct")
expect(page).to have_content("You didn’t answer this question")
expect(page).to have_link("Answer")
expect(lettings_log.reload.earnings).to eq(nil)
end
end
context "and clearing specific sales question" do
let(:params) do
{
id: sales_log.id,
sales_log: {
income1: "100000",
la: "E09000001",
ownershipsch: "1",
clear_question_ids: "income1",
page: "buyer_1_income",
},
check_errors: "",
}
end
before do
sign_in user
post "/sales-logs/#{sales_log.id}/buyer-1-income", params:
end
it "displays correct clear links" do
expect(page).to have_content("Make sure these answers are correct")
expect(page).to have_content("You didn’t answer this question")
expect(page).to have_link("Answer")
expect(sales_log.reload.income1).to eq(nil)
end
end
end
end
describe "answer incomplete question" do
context "when user is signed in" do
context "and answering specific lettings question" do
let(:params) do
{
original_page_id: "household_members",
referrer: "check_errors",
related_question_ids: %w[hhmemb ecstat1 earnings],
lettings_log: {
page: "household_members",
hhmemb: "2",
},
}
end
before do
sign_in user
post "/lettings-logs/#{lettings_log.id}/household-members", params:
end
it "maintains original check_errors data in query params" do
follow_redirect!
expect(request.query_parameters["check_errors"]).to eq("true")
expect(request.query_parameters["related_question_ids"]).to eq(%w[hhmemb ecstat1 earnings])
expect(page).to have_content("You have successfully updated Number of household members")
expect(page).to have_link("Confirm and continue", href: "/lettings-logs/#{lettings_log.id}/household-members")
end
end
context "and answering specific sales question" do
let(:params) do
{
original_page_id: "buyer_1_income",
referrer: "check_errors",
related_question_ids: %w[income1 la ownershipsch],
sales_log: {
page: "buyer_1_income",
income1: "1000",
income1nk: "0",
},
}
end
before do
sign_in user
post "/sales-logs/#{sales_log.id}/buyer-1-income", params:
end
it "maintains original check_errors data in query params" do
follow_redirect!
expect(request.query_parameters["check_errors"]).to eq("true")
expect(request.query_parameters["related_question_ids"]).to eq(%w[income1 la ownershipsch])
expect(page).to have_content("You have successfully updated Buyer 1’s gross annual income known? and Buyer 1’s gross annual income")
expect(page).to have_link("Confirm and continue", href: "/sales-logs/#{sales_log.id}/buyer-1-income")
end
end
end
end
describe "clear all answers" do
context "when user is signed in" do
context "and clearing all lettings question" do
let(:params) do
{
id: lettings_log.id,
lettings_log: {
earnings: "100000",
incfreq: "1",
hhmemb: "2",
clear_question_ids: "earnings incfreq hhmemb",
page: "income_amount",
},
check_errors: "",
}
end
before do
sign_in user
post "/lettings-logs/#{lettings_log.id}/income-amount", params:
end
it "correctly clears the values" do
expect(page).to have_content("Make sure these answers are correct")
expect(page).to have_content("You didn’t answer this question")
expect(page.all(:button, value: "Clear").count).to eq(0)
expect(lettings_log.reload.earnings).to eq(nil)
expect(lettings_log.reload.incfreq).to eq(nil)
expect(lettings_log.reload.hhmemb).to eq(nil)
end
end
context "and clearing all sales question" do
let(:params) do
{
id: sales_log.id,
sales_log: {
income1: "100000",
la: "E09000001",
ownershipsch: "1",
clear_question_ids: "income1 la ownershipsch",
page: "buyer_1_income",
},
check_errors: "",
}
end
before do
sign_in user
post "/sales-logs/#{sales_log.id}/buyer-1-income", params:
end
it "displays correct clear links" do
expect(page).to have_content("Make sure these answers are correct")
expect(page).to have_content("You didn’t answer this question")
expect(page.all(:button, value: "Clear").count).to eq(0)
expect(sales_log.reload.income1).to eq(nil)
expect(sales_log.reload.la).to eq(nil)
expect(sales_log.reload.ownershipsch).not_to eq(nil)
end
end
end
end
end
Loading…
Cancel
Save