Skip to content

Commit fe058cd

Browse files
committed
Record whether regulations 3 and 4 apply for reporting purposes
1 parent 07d6f6b commit fe058cd

File tree

12 files changed

+236
-83
lines changed

12 files changed

+236
-83
lines changed

app/controllers/planning_applications/validation/reporting_types_controller.rb

+18-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,24 @@ def update
3030
private
3131

3232
def reporting_type_params
33-
params[:planning_application] ? params.require(:planning_application).permit(:reporting_type) : params.permit(:reporting_type)
33+
(params[:planning_application] ? params.require(:planning_application) : params)
34+
.permit(:reporting_type).to_h.merge(regulation_3:, regulation_4:)
35+
end
36+
37+
def regulation_3
38+
regulation_params == "true" && regulation_3_params == "true"
39+
end
40+
41+
def regulation_4
42+
regulation_params == "true" && regulation_3_params == "false"
43+
end
44+
45+
def regulation_params
46+
params[:planning_application][:regulation]
47+
end
48+
49+
def regulation_3_params
50+
params[:planning_application][:regulation_3]
3451
end
3552
end
3653
end

app/helpers/reporting_type_helper.rb

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# frozen_string_literal: true
2+
3+
module ReportingTypeHelper
4+
def reporting_radio_button_disabled?(status, params)
5+
status.reporting_type_status == :complete && params.blank?
6+
end
7+
end

app/views/api/v1/planning_applications/_show.json.jbuilder

+3-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ json.extract! planning_application,
3030
:target_date,
3131
:withdrawn_at,
3232
:work_status,
33-
:boundary_geojson
33+
:boundary_geojson,
34+
:regulation_3,
35+
:regulation_4
3436
if planning_application.site_notices.any?
3537
json.site_notice_content planning_application.site_notices.order(:created_at).last.content
3638
end

app/views/planning_applications/validation/reporting_types/_form.html.erb

+20-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<%= form.govuk_radio_buttons_fieldset(:reporting_type, legend: {size: "m"}) do %>
55
<% if @planning_application.application_type.selected_reporting_types? %>
66
<% @planning_application.application_type.selected_reporting_types.each do |reporting_type| %>
7-
<%= form.govuk_radio_button(:reporting_type, reporting_type.code, label: {text: reporting_type.full_description}) do %>
7+
<%= 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 %>
88
<% if reporting_type.guidance? %>
99
<%= render FormattedContentComponent.new(text: reporting_type.guidance, classname: "govuk-hint") %>
1010
<% if reporting_type.guidance_link? %>
@@ -22,7 +22,24 @@
2222
<% end %>
2323
<% end %>
2424

25-
<%= form.govuk_submit(t("form_actions.save_and_mark_as_complete")) do %>
26-
<%= back_link %>
25+
<%= form.govuk_radio_buttons_fieldset(:regulation, legend: {size: "m", text: "Is the local planning authority the owner of this land?"}) do %>
26+
<%= 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 %>
27+
<%= form.govuk_radio_buttons_fieldset(:regulation, legend: {size: "s", text: "Is the local planning authority carrying out the works proposed?"}) do %>
28+
<%= 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 %>
29+
<%= form.govuk_radio_button :regulation_3, false, label: {text: "No"}, disabled: reporting_radio_button_disabled?(@planning_application, params[:edit]), checked: @planning_application.regulation_4 %>
30+
<% end %>
31+
<% end %>
32+
<%= 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 %>
33+
<% end %>
34+
35+
<% if @planning_application.reporting_type_status != :complete || params[:edit].present? %>
36+
<%= form.govuk_submit(t("form_actions.save_and_mark_as_complete")) do %>
37+
<%= govuk_link_to "Back", planning_application_validation_tasks_path(@planning_application), class: "govuk-button govuk-button--secondary" %>
38+
<% end %>
39+
<% else %>
40+
<div class="govuk-button-group">
41+
<%= govuk_link_to "Back", planning_application_validation_tasks_path(@planning_application), class: "govuk-button govuk-button--secondary" %>
42+
<%= govuk_link_to "Edit reporting details", edit_planning_application_validation_reporting_type_path(@planning_application, edit: true), class: "govuk-body" %>
43+
</div>
2744
<% end %>
2845
<% end %>
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
<% content_for :page_title do %>
2-
Development type - <%= t("page_title") %>
2+
Reporting details - <%= t("page_title") %>
33
<% end %>
44

55
<%= render(
66
partial: "planning_applications/validation/validation_requests/validation_requests_breadcrumbs",
77
locals: {planning_application: @planning_application}
88
) %>
99

10-
<% content_for :title, "Development type" %>
10+
<% content_for :title, "Reporting details" %>
1111

1212
<%= render(
1313
partial: "shared/proposal_header",
14-
locals: {heading: "Select development type for reporting"}
14+
locals: {heading: "Add reporting details"}
1515
) %>
1616

1717
<%= render "form" %>

app/views/planning_applications/validation/tasks/_application_details.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
<% end %>
4444
<li id="development-type-for-reporting-task" class="app-task-list__item">
4545
<span class="app-task-list__task-name">
46-
<%= govuk_link_to "Select development type for reporting", edit_planning_application_validation_reporting_type_path(@planning_application) %>
46+
<%= govuk_link_to "Add reporting details", edit_planning_application_validation_reporting_type_path(@planning_application) %>
4747
</span>
4848

4949
<%= render(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# frozen_string_literal: true
2+
3+
class AddRegulation3AndRegulation4ToPlanningApplication < ActiveRecord::Migration[7.1]
4+
def change
5+
safety_assured {
6+
change_table :planning_applications, bulk: true do |t|
7+
t.boolean :regulation_3, default: false, null: false
8+
t.boolean :regulation_4, default: false, null: false
9+
end
10+
}
11+
end
12+
end

db/schema.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.1].define(version: 2024_04_26_131939) do
13+
ActiveRecord::Schema[7.1].define(version: 2024_04_30_102131) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "plpgsql"
1616
enable_extension "postgis"
@@ -677,6 +677,8 @@
677677
t.geography "neighbour_boundary_geojson", limit: {:srid=>4326, :type=>"geometry_collection", :geographic=>true}
678678
t.string "documents_status", default: "not_started", null: false
679679
t.datetime "in_committee_at"
680+
t.boolean "regulation_3", default: false, null: false
681+
t.boolean "regulation_4", default: false, null: false
680682
t.index "lower((reference)::text)", name: "ix_planning_applications_on_lower_reference"
681683
t.index "to_tsvector('english'::regconfig, description)", name: "index_planning_applications_on_description", using: :gin
682684
t.index ["api_user_id"], name: "ix_planning_applications_on_api_user_id"

public/api/docs/v1/swagger_doc.yaml

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ paths:
7474
result_description: 'Based on the information you have provided, we do not think this is eligible for a Lawful Development Certificate'
7575
result_override: This was my reason for rejecting the result
7676
make_public: true
77+
regulation_3: false
78+
regulation_4: false
7779
boundary_geojson:
7880
type: Feature
7981
geometry:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# frozen_string_literal: true
2+
3+
require "rails_helper"
4+
5+
RSpec.describe "Reporting validation task" do
6+
let!(:default_local_authority) { create(:local_authority, :default) }
7+
let!(:assessor) { create(:user, :assessor, local_authority: default_local_authority) }
8+
let!(:reporting_type) { create(:reporting_type, :ldc) }
9+
10+
let!(:planning_application) do
11+
create(:planning_application, :not_started, local_authority: default_local_authority)
12+
end
13+
14+
before do
15+
sign_in assessor
16+
visit "/planning_applications/#{planning_application.id}/validation/tasks"
17+
end
18+
19+
context "when application is not started" do
20+
it "I can see that reporting type is not started" do
21+
expect(page).to have_link(
22+
"Add reporting details",
23+
href: "/planning_applications/#{planning_application.id}/validation/reporting_type/edit"
24+
)
25+
click_link "Add reporting details"
26+
27+
expect(page).to have_content("Add reporting details")
28+
29+
expect(page).to have_content("Select development type")
30+
31+
click_link "Back"
32+
33+
within("#development-type-for-reporting-task") do
34+
expect(page).to have_selector(".govuk-tag", text: "Not started")
35+
end
36+
end
37+
38+
it "I can select the development type for reporting" do
39+
click_link "Add reporting details"
40+
41+
expect(page).to have_content("Add reporting details")
42+
43+
choose "Q26 – Certificates of lawful development"
44+
45+
expect(page).to have_content("Includes both existing & proposed applications")
46+
47+
click_button "Save and mark as complete"
48+
49+
within(".govuk-notification-banner--notice") do
50+
expect(page).to have_content("Planning application's development type for reporting was successfully selected")
51+
end
52+
53+
within("#development-type-for-reporting-task") do
54+
expect(page).to have_selector(".govuk-tag", text: "Completed")
55+
end
56+
57+
expect(page).to have_link(
58+
"Add reporting details",
59+
href: "/planning_applications/#{planning_application.id}/validation/reporting_type/edit"
60+
)
61+
end
62+
63+
it "shows errors when a development type for reporting is not selected" do
64+
click_link "Add reporting details"
65+
66+
click_button "Save and mark as complete"
67+
68+
expect(page).to have_content "Please select a development type for reporting"
69+
end
70+
71+
it "I can report whether regulation 3 applies" do
72+
click_link "Add reporting details"
73+
74+
expect(page).to have_content("Add reporting details")
75+
76+
choose "Q26 – Certificates of lawful development"
77+
78+
expect(page).to have_content("Includes both existing & proposed applications")
79+
80+
# Radios within radios makes finding 'yes' complicated
81+
page.find(:xpath, '//*[@id="planning-application-regulation-true-field"]').click
82+
page.find(:xpath, '//*[@id="planning-application-regulation-3-true-field"]').click
83+
84+
click_button "Save and mark as complete"
85+
86+
within(".govuk-notification-banner--notice") do
87+
expect(page).to have_content("Planning application's development type for reporting was successfully selected")
88+
end
89+
90+
within("#development-type-for-reporting-task") do
91+
expect(page).to have_selector(".govuk-tag", text: "Completed")
92+
end
93+
94+
expect(planning_application.reload.regulation_3).to be true
95+
expect(planning_application.reload.regulation_4).to be false
96+
end
97+
98+
it "I can report whether regulation 4 applies" do
99+
click_link "Add reporting details"
100+
101+
expect(page).to have_content("Add reporting details")
102+
103+
choose "Q26 – Certificates of lawful development"
104+
105+
expect(page).to have_content("Includes both existing & proposed applications")
106+
107+
# Radios within radios makes finding 'yes' complicated
108+
page.find(:xpath, '//*[@id="planning-application-regulation-true-field"]').click
109+
page.find(:xpath, '//*[@id="planning-application-regulation-3-field"]').click
110+
111+
click_button "Save and mark as complete"
112+
113+
within(".govuk-notification-banner--notice") do
114+
expect(page).to have_content("Planning application's development type for reporting was successfully selected")
115+
end
116+
117+
within("#development-type-for-reporting-task") do
118+
expect(page).to have_selector(".govuk-tag", text: "Completed")
119+
end
120+
121+
expect(planning_application.reload.regulation_3).to be false
122+
expect(planning_application.reload.regulation_4).to be true
123+
end
124+
125+
it "I can edit the regulations" do
126+
click_link "Add reporting details"
127+
128+
expect(page).to have_content("Add reporting details")
129+
130+
choose "Q26 – Certificates of lawful development"
131+
132+
expect(page).to have_content("Includes both existing & proposed applications")
133+
134+
# Radios within radios makes finding 'yes' complicated
135+
page.find(:xpath, '//*[@id="planning-application-regulation-true-field"]').click
136+
page.find(:xpath, '//*[@id="planning-application-regulation-3-field"]').click
137+
138+
click_button "Save and mark as complete"
139+
140+
within(".govuk-notification-banner--notice") do
141+
expect(page).to have_content("Planning application's development type for reporting was successfully selected")
142+
end
143+
144+
within("#development-type-for-reporting-task") do
145+
expect(page).to have_selector(".govuk-tag", text: "Completed")
146+
click_link "Add reporting details"
147+
end
148+
149+
expect(page).not_to have_content "Save and mark as complete"
150+
151+
click_link "Edit reporting details"
152+
153+
page.find(:xpath, '//*[@id="planning-application-regulation-field"]').click
154+
155+
click_button "Save and mark as complete"
156+
157+
within("#development-type-for-reporting-task") do
158+
expect(page).to have_selector(".govuk-tag", text: "Completed")
159+
end
160+
161+
expect(planning_application.reload.regulation_3).to be false
162+
expect(planning_application.reload.regulation_4).to be false
163+
end
164+
end
165+
end

spec/system/planning_applications/validating/reporting_type_spec.rb

-71
This file was deleted.

0 commit comments

Comments
 (0)