diff --git a/app/controllers/planning_applications/validation/reporting_types_controller.rb b/app/controllers/planning_applications/validation/reporting_types_controller.rb index bb51015672..1daf90e327 100644 --- a/app/controllers/planning_applications/validation/reporting_types_controller.rb +++ b/app/controllers/planning_applications/validation/reporting_types_controller.rb @@ -30,7 +30,24 @@ def update private def reporting_type_params - params[:planning_application] ? params.require(:planning_application).permit(:reporting_type) : params.permit(:reporting_type) + (params[:planning_application] ? params.require(:planning_application) : params) + .permit(:reporting_type).to_h.merge(regulation_3:, regulation_4:) + end + + def regulation_3 + regulation_params == "true" && regulation_3_params == "true" + end + + def regulation_4 + regulation_params == "true" && regulation_3_params == "false" + end + + def regulation_params + params[:planning_application][:regulation] + end + + def regulation_3_params + params[:planning_application][:regulation_3] end end end diff --git a/app/helpers/reporting_type_helper.rb b/app/helpers/reporting_type_helper.rb new file mode 100644 index 0000000000..72ad9020aa --- /dev/null +++ b/app/helpers/reporting_type_helper.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +module ReportingTypeHelper + def reporting_radio_button_disabled?(status, params) + status.reporting_type_status == :complete && params.blank? + end +end diff --git a/app/views/api/v1/planning_applications/_show.json.jbuilder b/app/views/api/v1/planning_applications/_show.json.jbuilder index 85ac6e2357..e7d860c224 100644 --- a/app/views/api/v1/planning_applications/_show.json.jbuilder +++ b/app/views/api/v1/planning_applications/_show.json.jbuilder @@ -30,7 +30,9 @@ json.extract! planning_application, :target_date, :withdrawn_at, :work_status, - :boundary_geojson + :boundary_geojson, + :regulation_3, + :regulation_4 if planning_application.site_notices.any? json.site_notice_content planning_application.site_notices.order(:created_at).last.content end diff --git a/app/views/planning_applications/validation/reporting_types/_form.html.erb b/app/views/planning_applications/validation/reporting_types/_form.html.erb index 8bf67ab620..8bcbb97713 100644 --- a/app/views/planning_applications/validation/reporting_types/_form.html.erb +++ b/app/views/planning_applications/validation/reporting_types/_form.html.erb @@ -4,7 +4,7 @@ <%= form.govuk_radio_buttons_fieldset(:reporting_type, legend: {size: "m"}) do %> <% if @planning_application.application_type.selected_reporting_types? %> <% @planning_application.application_type.selected_reporting_types.each do |reporting_type| %> - <%= form.govuk_radio_button(:reporting_type, reporting_type.code, label: {text: reporting_type.full_description}) do %> + <%= form.govuk_radio_button(:reporting_type, reporting_type.code, label: {text: reporting_type.full_description}, disabled: reporting_radio_button_disabled?(@planning_application, params[:edit])) do %> <% if reporting_type.guidance? %> <%= render FormattedContentComponent.new(text: reporting_type.guidance, classname: "govuk-hint") %> <% if reporting_type.guidance_link? %> @@ -22,7 +22,24 @@ <% end %> <% end %> - <%= form.govuk_submit(t("form_actions.save_and_mark_as_complete")) do %> - <%= back_link %> + <%= form.govuk_radio_buttons_fieldset(:regulation, legend: {size: "m", text: "Is the local planning authority the owner of this land?"}) do %> + <%= form.govuk_radio_button :regulation, true, label: {text: "Yes"}, link_errors: true, disabled: reporting_radio_button_disabled?(@planning_application, params[:edit]), checked: @planning_application.regulation_3 || @planning_application.regulation_4 do %> + <%= form.govuk_radio_buttons_fieldset(:regulation, legend: {size: "s", text: "Is the local planning authority carrying out the works proposed?"}) do %> + <%= form.govuk_radio_button :regulation_3, true, label: {text: "Yes"}, link_errors: true, disabled: reporting_radio_button_disabled?(@planning_application, params[:edit]), checked: @planning_application.regulation_3 %> + <%= form.govuk_radio_button :regulation_3, false, label: {text: "No"}, disabled: reporting_radio_button_disabled?(@planning_application, params[:edit]), checked: @planning_application.regulation_4 %> + <% end %> + <% end %> + <%= form.govuk_radio_button :regulation, false, label: {text: "No"}, disabled: reporting_radio_button_disabled?(@planning_application, params[:edit]), checked: !@planning_application.regulation_3 && !@planning_application.regulation_4 %> + <% end %> + + <% if @planning_application.reporting_type_status != :complete || params[:edit].present? %> + <%= form.govuk_submit(t("form_actions.save_and_mark_as_complete")) do %> + <%= govuk_link_to "Back", planning_application_validation_tasks_path(@planning_application), class: "govuk-button govuk-button--secondary" %> + <% end %> + <% else %> +
+ <%= govuk_link_to "Back", planning_application_validation_tasks_path(@planning_application), class: "govuk-button govuk-button--secondary" %> + <%= govuk_link_to "Edit reporting details", edit_planning_application_validation_reporting_type_path(@planning_application, edit: true), class: "govuk-body" %> +
<% end %> <% end %> diff --git a/app/views/planning_applications/validation/reporting_types/edit.html.erb b/app/views/planning_applications/validation/reporting_types/edit.html.erb index b59b60d3ea..6e6a1f98c5 100644 --- a/app/views/planning_applications/validation/reporting_types/edit.html.erb +++ b/app/views/planning_applications/validation/reporting_types/edit.html.erb @@ -1,5 +1,5 @@ <% content_for :page_title do %> - Development type - <%= t("page_title") %> + Reporting details - <%= t("page_title") %> <% end %> <%= render( @@ -7,11 +7,11 @@ locals: {planning_application: @planning_application} ) %> -<% content_for :title, "Development type" %> +<% content_for :title, "Reporting details" %> <%= render( partial: "shared/proposal_header", - locals: {heading: "Select development type for reporting"} + locals: {heading: "Add reporting details"} ) %> <%= render "form" %> diff --git a/app/views/planning_applications/validation/tasks/_application_details.html.erb b/app/views/planning_applications/validation/tasks/_application_details.html.erb index 19bed06a7d..1706fb1b8a 100644 --- a/app/views/planning_applications/validation/tasks/_application_details.html.erb +++ b/app/views/planning_applications/validation/tasks/_application_details.html.erb @@ -43,7 +43,7 @@ <% end %>
  • - <%= govuk_link_to "Select development type for reporting", edit_planning_application_validation_reporting_type_path(@planning_application) %> + <%= govuk_link_to "Add reporting details", edit_planning_application_validation_reporting_type_path(@planning_application) %> <%= render( diff --git a/db/migrate/20240430102131_add_regulation3_and_regulation4_to_planning_application.rb b/db/migrate/20240430102131_add_regulation3_and_regulation4_to_planning_application.rb new file mode 100644 index 0000000000..e5a2f30677 --- /dev/null +++ b/db/migrate/20240430102131_add_regulation3_and_regulation4_to_planning_application.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +class AddRegulation3AndRegulation4ToPlanningApplication < ActiveRecord::Migration[7.1] + def change + safety_assured { + change_table :planning_applications, bulk: true do |t| + t.boolean :regulation_3, default: false, null: false + t.boolean :regulation_4, default: false, null: false + end + } + end +end diff --git a/db/schema.rb b/db/schema.rb index bf0a909d44..f210534f43 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2024_04_26_131939) do +ActiveRecord::Schema[7.1].define(version: 2024_04_30_102131) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" enable_extension "postgis" @@ -677,6 +677,8 @@ t.geography "neighbour_boundary_geojson", limit: {:srid=>4326, :type=>"geometry_collection", :geographic=>true} t.string "documents_status", default: "not_started", null: false t.datetime "in_committee_at" + t.boolean "regulation_3", default: false, null: false + t.boolean "regulation_4", default: false, null: false t.index "lower((reference)::text)", name: "ix_planning_applications_on_lower_reference" t.index "to_tsvector('english'::regconfig, description)", name: "index_planning_applications_on_description", using: :gin t.index ["api_user_id"], name: "ix_planning_applications_on_api_user_id" diff --git a/public/api/docs/v1/swagger_doc.yaml b/public/api/docs/v1/swagger_doc.yaml index 1ec86bf9f9..86d0df14d8 100644 --- a/public/api/docs/v1/swagger_doc.yaml +++ b/public/api/docs/v1/swagger_doc.yaml @@ -74,6 +74,8 @@ paths: result_description: 'Based on the information you have provided, we do not think this is eligible for a Lawful Development Certificate' result_override: This was my reason for rejecting the result make_public: true + regulation_3: false + regulation_4: false boundary_geojson: type: Feature geometry: diff --git a/spec/system/planning_applications/validating/reporting_spec.rb b/spec/system/planning_applications/validating/reporting_spec.rb new file mode 100644 index 0000000000..430b9d1344 --- /dev/null +++ b/spec/system/planning_applications/validating/reporting_spec.rb @@ -0,0 +1,165 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe "Reporting validation task" do + let!(:default_local_authority) { create(:local_authority, :default) } + let!(:assessor) { create(:user, :assessor, local_authority: default_local_authority) } + let!(:reporting_type) { create(:reporting_type, :ldc) } + + let!(:planning_application) do + create(:planning_application, :not_started, local_authority: default_local_authority) + end + + before do + sign_in assessor + visit "/planning_applications/#{planning_application.id}/validation/tasks" + end + + context "when application is not started" do + it "I can see that reporting type is not started" do + expect(page).to have_link( + "Add reporting details", + href: "/planning_applications/#{planning_application.id}/validation/reporting_type/edit" + ) + click_link "Add reporting details" + + expect(page).to have_content("Add reporting details") + + expect(page).to have_content("Select development type") + + click_link "Back" + + within("#development-type-for-reporting-task") do + expect(page).to have_selector(".govuk-tag", text: "Not started") + end + end + + it "I can select the development type for reporting" do + click_link "Add reporting details" + + expect(page).to have_content("Add reporting details") + + choose "Q26 – Certificates of lawful development" + + expect(page).to have_content("Includes both existing & proposed applications") + + 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") + end + + within("#development-type-for-reporting-task") do + expect(page).to have_selector(".govuk-tag", text: "Completed") + end + + expect(page).to have_link( + "Add reporting details", + href: "/planning_applications/#{planning_application.id}/validation/reporting_type/edit" + ) + end + + it "shows errors when a development type for reporting is not selected" do + click_link "Add reporting details" + + click_button "Save and mark as complete" + + expect(page).to have_content "Please select a development type for reporting" + end + + it "I can report whether regulation 3 applies" do + click_link "Add reporting details" + + expect(page).to have_content("Add reporting details") + + choose "Q26 – Certificates of lawful development" + + expect(page).to have_content("Includes both existing & proposed applications") + + # Radios within radios makes finding 'yes' complicated + page.find(:xpath, '//*[@id="planning-application-regulation-true-field"]').click + page.find(:xpath, '//*[@id="planning-application-regulation-3-true-field"]').click + + 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") + end + + within("#development-type-for-reporting-task") do + expect(page).to have_selector(".govuk-tag", text: "Completed") + end + + expect(planning_application.reload.regulation_3).to be true + expect(planning_application.reload.regulation_4).to be false + end + + it "I can report whether regulation 4 applies" do + click_link "Add reporting details" + + expect(page).to have_content("Add reporting details") + + choose "Q26 – Certificates of lawful development" + + expect(page).to have_content("Includes both existing & proposed applications") + + # Radios within radios makes finding 'yes' complicated + page.find(:xpath, '//*[@id="planning-application-regulation-true-field"]').click + page.find(:xpath, '//*[@id="planning-application-regulation-3-field"]').click + + 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") + end + + within("#development-type-for-reporting-task") do + expect(page).to have_selector(".govuk-tag", text: "Completed") + end + + expect(planning_application.reload.regulation_3).to be false + expect(planning_application.reload.regulation_4).to be true + end + + it "I can edit the regulations" do + click_link "Add reporting details" + + expect(page).to have_content("Add reporting details") + + choose "Q26 – Certificates of lawful development" + + expect(page).to have_content("Includes both existing & proposed applications") + + # Radios within radios makes finding 'yes' complicated + page.find(:xpath, '//*[@id="planning-application-regulation-true-field"]').click + page.find(:xpath, '//*[@id="planning-application-regulation-3-field"]').click + + 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") + end + + within("#development-type-for-reporting-task") do + expect(page).to have_selector(".govuk-tag", text: "Completed") + click_link "Add reporting details" + end + + expect(page).not_to have_content "Save and mark as complete" + + click_link "Edit reporting details" + + page.find(:xpath, '//*[@id="planning-application-regulation-field"]').click + + click_button "Save and mark as complete" + + within("#development-type-for-reporting-task") do + expect(page).to have_selector(".govuk-tag", text: "Completed") + end + + expect(planning_application.reload.regulation_3).to be false + expect(planning_application.reload.regulation_4).to be false + end + end +end diff --git a/spec/system/planning_applications/validating/reporting_type_spec.rb b/spec/system/planning_applications/validating/reporting_type_spec.rb deleted file mode 100644 index 16ec2151d7..0000000000 --- a/spec/system/planning_applications/validating/reporting_type_spec.rb +++ /dev/null @@ -1,71 +0,0 @@ -# frozen_string_literal: true - -require "rails_helper" - -RSpec.describe "Reporting type validation task" do - let!(:default_local_authority) { create(:local_authority, :default) } - let!(:assessor) { create(:user, :assessor, local_authority: default_local_authority) } - let!(:reporting_type) { create(:reporting_type, :ldc) } - - let!(:planning_application) do - create(:planning_application, :invalidated, local_authority: default_local_authority) - end - - before do - sign_in assessor - visit "/planning_applications/#{planning_application.id}/validation/tasks" - end - - context "when application is not started" do - it "I can see that reporting type is not started" do - expect(page).to have_link( - "Select development type for reporting", - href: "/planning_applications/#{planning_application.id}/validation/reporting_type/edit" - ) - click_link "Select development type for reporting" - - expect(page).to have_content("Select development type for reporting") - - expect(page).to have_content("Select development type") - - click_link "Back" - - within("#development-type-for-reporting-task") do - expect(page).to have_selector(".govuk-tag", text: "Not started") - end - end - - it "I can select the development type for reporting" do - click_link "Select development type for reporting" - - expect(page).to have_content("Select development type for reporting") - - choose "Q26 – Certificates of lawful development" - - expect(page).to have_content("Includes both existing & proposed applications") - - 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") - end - - within("#development-type-for-reporting-task") do - expect(page).to have_selector(".govuk-tag", text: "Completed") - end - - expect(page).to have_link( - "Select development type for reporting", - href: "/planning_applications/#{planning_application.id}/validation/reporting_type/edit" - ) - end - - it "shows errors when a development type for reporting is not selected" do - click_link "Select development type for reporting" - - click_button "Save and mark as complete" - - expect(page).to have_content "Please select a development type for reporting" - end - end -end diff --git a/spec/system/planning_applications/validating/validation_tasks_index_spec.rb b/spec/system/planning_applications/validating/validation_tasks_index_spec.rb index d8a2029400..9b4c0f283a 100644 --- a/spec/system/planning_applications/validating/validation_tasks_index_spec.rb +++ b/spec/system/planning_applications/validating/validation_tasks_index_spec.rb @@ -88,7 +88,7 @@ within("#development-type-for-reporting-task") do expect(page).to have_link( - "Select development type for reporting", + "Add reporting details", href: edit_planning_application_validation_reporting_type_path(planning_application) ) within(".govuk-tag--grey") do @@ -254,7 +254,7 @@ within("#development-type-for-reporting-task") do expect(page).to have_link( - "Select development type for reporting", + "Add reporting details", href: edit_planning_application_validation_reporting_type_path(planning_application) ) within(".govuk-tag--grey") do