Browse Source
* 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 copypull/2508/head
kosiakkatrina
6 months ago
committed by
GitHub
15 changed files with 766 additions and 8 deletions
@ -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 |
@ -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 |
@ -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> |
@ -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> |
@ -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> |
@ -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…
Reference in new issue