Browse Source

CLDC-2041 Display all errors for the page (#2840)

* Display all errors for the page

* Fix world

* Update the test

---------

Co-authored-by: Rachael Booth <Rachael.Booth@softwire.com>
pull/2880/head
kosiakkatrina 2 months ago committed by GitHub
parent
commit
9c41d0cca3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 1
      app/controllers/form_controller.rb
  2. 29
      spec/requests/form_controller_spec.rb

1
app/controllers/form_controller.rb

@ -32,6 +32,7 @@ class FormController < ApplicationController
pages_requiring_update = pages_requiring_update(shown_page_ids_with_unanswered_questions_before_update)
redirect_to(successful_redirect_path(pages_requiring_update))
else
@log.valid? if mandatory_questions_with_no_response.any?
mandatory_questions_with_no_response.map do |question|
@log.errors.add question.id.to_sym, question.unanswered_error_message, category: :not_answered
end

29
spec/requests/form_controller_spec.rb

@ -744,6 +744,35 @@ RSpec.describe FormController, type: :request do
end
end
context "with invalid multiple question answers" do
let(:page) { Capybara::Node::Simple.new(response.body) }
let(:page_id) { "rent" }
let(:params) do
{
id: lettings_log.id,
lettings_log: {
page: page_id,
"period" => 10,
"supcharg" => 1_000_000,
},
}
end
before do
allow(Rails.logger).to receive(:info)
end
it "shows not answered and invalid answer errors at the same time" do
post "/lettings-logs/#{lettings_log.id}/#{page_id.dasherize}", params: params
follow_redirect!
expect(page).to have_content("There is a problem")
expect(page).to have_content("Support Charge must be between 0 and 300.")
expect(page).to have_content("You must answer basic rent.")
expect(page).to have_content("You must answer personal service charge.")
expect(page).to have_content("You must answer service charge.")
end
end
context "with invalid organisation answers" do
let(:page) { Capybara::Node::Simple.new(response.body) }
let(:managing_organisation) { create(:organisation) }

Loading…
Cancel
Save