From 274bef0b8f89999819678a35857b3754af024855 Mon Sep 17 00:00:00 2001 From: Ben Baumann <34001723+benbaumann95@users.noreply.github.com> Date: Wed, 23 Oct 2024 12:25:56 +0100 Subject: [PATCH] Only validate for reporting type if present on application type --- app/models/planning_application.rb | 3 ++- config/locales/en.yml | 4 ++-- .../validating/reporting_spec.rb | 22 +++++++++++++++---- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/app/models/planning_application.rb b/app/models/planning_application.rb index 5e40924980..bc9f6858d9 100644 --- a/app/models/planning_application.rb +++ b/app/models/planning_application.rb @@ -79,6 +79,7 @@ class WithdrawOrCancelError < RuntimeError; end delegate :consultee_consultation_feature? delegate :publicity_consultation_feature? delegate :prior_approval? + delegate :selected_reporting_types? end delegate :reviewer_group_email, to: :local_authority @@ -203,7 +204,7 @@ class WithdrawOrCancelError < RuntimeError; end with_options on: :reporting_types do validate :regulation_present, if: :regulation? - validates :reporting_type, presence: true + validates :reporting_type, presence: true, if: :selected_reporting_types? end def regulation_present diff --git a/config/locales/en.yml b/config/locales/en.yml index c18e91a5df..42dc1e82e3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1840,11 +1840,11 @@ en: reporting_types: form: legislation: Legislation - no_applicable_reporting_types: No applicable reporting types + no_applicable_reporting_types: No applicable reporting types. Please configure them for the application type if they are required. read_more: Read more guidance on GOV.UK (opens in a new tab) update: failure: Please select a development type for reporting - success: Planning application's development type for reporting was successfully selected + success: Planning application's reporting details were successfully updated. sitemaps: update: error: Something went wrong. Please contact support. diff --git a/spec/system/planning_applications/validating/reporting_spec.rb b/spec/system/planning_applications/validating/reporting_spec.rb index be3d497b5d..bf5effb9bf 100644 --- a/spec/system/planning_applications/validating/reporting_spec.rb +++ b/spec/system/planning_applications/validating/reporting_spec.rb @@ -44,7 +44,7 @@ click_button "Save and mark as complete" within(".govuk-notification-banner--notice") do - expect(page).to have_content("Planning application's development type for reporting was successfully selected") + expect(page).to have_content("Planning application's reporting details were successfully updated") end within("#reporting-details-task") do @@ -64,6 +64,20 @@ expect(page).to have_content "Please select a development type for reporting" end + context "when no reporting type for the application type exists" do + let!(:planning_application) do + create(:planning_application, :planning_permission, :not_started, local_authority: default_local_authority) + end + + it "I can save and mark as complete" do + click_link "Add reporting details" + expect(page).to have_content("No applicable reporting types. Please configure them for the application type if they are required.") + click_button "Save and mark as complete" + + expect(page).to have_content "Planning application's reporting details were successfully updated" + end + end + it "shows errors when Yes or No is not selected for whether the local authority is carrying out the works proposed" do click_link "Add reporting details" page.find(:xpath, '//*[@id="planning-application-regulation-true-field"]').click @@ -85,7 +99,7 @@ click_button "Save and mark as complete" within(".govuk-notification-banner--notice") do - expect(page).to have_content("Planning application's development type for reporting was successfully selected") + expect(page).to have_content("Planning application's reporting details were successfully updated") end within("#reporting-details-task") do @@ -109,7 +123,7 @@ click_button "Save and mark as complete" within(".govuk-notification-banner--notice") do - expect(page).to have_content("Planning application's development type for reporting was successfully selected") + expect(page).to have_content("Planning application's reporting details were successfully updated") end within("#reporting-details-task") do @@ -134,7 +148,7 @@ click_button "Save and mark as complete" within(".govuk-notification-banner--notice") do - expect(page).to have_content("Planning application's development type for reporting was successfully selected") + expect(page).to have_content("Planning application's reporting details were successfully updated") end within("#reporting-details-task") do