Skip to content

Commit

Permalink
Record whether regulations 3 and 4 apply for reporting purposes
Browse files Browse the repository at this point in the history
  • Loading branch information
cdccollins committed May 1, 2024
1 parent 07d6f6b commit fe058cd
Show file tree
Hide file tree
Showing 12 changed files with 236 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions app/helpers/reporting_type_helper.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion app/views/api/v1/planning_applications/_show.json.jbuilder
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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? %>
Expand All @@ -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 %>
<div class="govuk-button-group">
<%= 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" %>
</div>
<% end %>
<% end %>
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<% content_for :page_title do %>
Development type - <%= t("page_title") %>
Reporting details - <%= t("page_title") %>
<% end %>

<%= render(
partial: "planning_applications/validation/validation_requests/validation_requests_breadcrumbs",
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" %>
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<% end %>
<li id="development-type-for-reporting-task" class="app-task-list__item">
<span class="app-task-list__task-name">
<%= 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) %>
</span>

<%= render(
Expand Down
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions public/api/docs/v1/swagger_doc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
165 changes: 165 additions & 0 deletions spec/system/planning_applications/validating/reporting_spec.rb
Original file line number Diff line number Diff line change
@@ -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

This file was deleted.

Loading

0 comments on commit fe058cd

Please sign in to comment.