Skip to content

Commit

Permalink
Specs and clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
cdccollins committed Apr 23, 2024
1 parent d8b1f02 commit f7888a6
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 77 deletions.
10 changes: 0 additions & 10 deletions app/assets/stylesheets/_main.scss
Original file line number Diff line number Diff line change
Expand Up @@ -457,13 +457,3 @@ body {
.govuk-\!-text-wrap-balance {
text-wrap: balance;
}

.dashed-box {
padding: 30px;
border: 1px dashed #B1B4B6;
margin-bottom: 30px;

p {
margin-bottom: 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ def index
end

def create
if @planning_application_constraints.create!(constraint_id: params[:constraint_id], identified_by: current_user.name)
@constraint = @planning_application_constraints.new(constraint_id: params[:constraint_id], identified_by: current_user.name)

if @constraint.save!
redirect_to planning_application_validation_constraints_path(@planning_application),
notice: t(".success")
else
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<%= tag.table(class: ["govuk-table", "constraints-table"]) do %>
<%= tag.table(class: ["govuk-table", "#{identifier}-constraints-table"]) do %>
<thead class="govuk-table__head">
<tr class="govuk-table__row">
<th scope="col" class="govuk-table__header">
Expand All @@ -19,14 +19,24 @@
</thead>

<tbody class="govuk-table__body">
<% planning_application_constraints.each do |planning_application_constraint| %>
<%= render(
partial: "row",
locals: {
planning_application_constraint: planning_application_constraint,
show_source: show_source
}
) %>
<% if @planning_application_constraints.any? %>
<% planning_application_constraints.each do |planning_application_constraint| %>
<%= render(
partial: "row",
locals: {
planning_application_constraint: planning_application_constraint,
show_source: show_source
}
) %>
<% end %>
<% else %>
<tr class="govuk-table__row">
<td class="govuk-table__cell" colspan="4" style="border-bottom: none;">
<div class="background-light-grey govuk-!-padding-6">
<p class="govuk-body govuk-!-margin-bottom-0">No constraints have been added or identified</p>
</div>
</td>
</tr>
<% end %>
</tbody>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,15 @@
<div class="govuk-grid-row">
<div class="govuk-grid-column-full">
<h2 class="govuk-heading-m">Identified constraints</h2>
<% if @planning_application_constraints.any? %>
<%= render(
partial: "table",
locals: {
title: "Identified constraints",
planning_application_constraints: @planning_application_constraints,
show_source: true
}
) %>
<% else %>
<div class="dashed-box">
<p class="govuk-body">No constraints have been identified by PlanX</p>
</div>
<% end %>
<%= render(
partial: "table",
locals: {
title: "Identified constraints",
identifier: "identified",
planning_application_constraints: @planning_application_constraints,
show_source: true
}
) %>

<details class="govuk-details" <%= "open" if params[:q].present? %>>
<summary class="govuk-details__summary">
Expand All @@ -55,6 +50,7 @@
partial: "table",
locals: {
title: "",
identifier: "other",
planning_application_constraints: @other_constraints,
show_source: false
}
Expand Down
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@

resource :reporting_type, only: %i[edit update]

resources :constraints, only: %i[index update create destroy]
resources :constraints, only: %i[index create destroy] do
patch :update, on: :collection
end

resource :documents, only: %i[edit update]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,20 @@
expect(page).to have_text("Check the constraints")
end

within("#planx") do
expect(page).to have_text("Constraints suggested by: PlanX (2)")
end
expect(page).to have_text("Identified constraints")

within(".planx-constraints-table") do
within(".identified-constraints-table") do
expect(page).to have_text("Conservation area")
expect(page).to have_text("Listed building outline")
end

within("#accordion-with-other-constraints-sections-heading-1") do
expect(page).to have_text("Other constraints")
end
find("span", text: "Add constraints").click

within(".other-constraints-table") do
expect(page).not_to have_text("Conservation area")
expect(page).not_to have_text("Listed building outline")
end

click_button "Other constraints"

expect(page).to have_link("Back", href: planning_application_validation_tasks_path(planning_application))

click_button "Save and mark as checked"
Expand All @@ -69,75 +63,96 @@
end

context "when adding constraints" do
it "I can check/uncheck constraints" do
within(".planx-constraints-table") do
find_checkbox_by_id("constraint_id_#{planning_application.planning_application_constraints.first.constraint_id}").click
it "I can add/remove constraints" do
within(".identified-constraints-table") do
expect(page).not_to have_link("Remove")
end

click_button "Other constraints"
find("span", text: "Add constraints").click

find_checkbox_by_id("constraint_id_#{Constraint.find_by(type: "monument").id}").click
find_checkbox_by_id("constraint_id_#{Constraint.find_by(type: "nature_asnw").id}").click
within(".other-constraints-table") do
within(row_with_content("Scheduled monument")) do
click_link "Add"
end
end

click_button "Save and mark as checked"
find("span", text: "Add constraints").click

visit "/planning_applications/#{planning_application.id}/validation/constraints"
within(".other-constraints-table") do
within(row_with_content("Special area of conservation")) do
click_link "Add"
end
end

within("#planx") do
expect(page).to have_text("Constraints suggested by: PlanX (2)")
within(".identified-constraints-table") do
expect(page).to have_content "Scheduled monument"
expect(page).to have_content "Special area of conservation"
end

within(".planx-constraints-table") do
click_button "Save and mark as checked"

visit "/planning_applications/#{planning_application.id}/validation/constraints"

within(".identified-constraints-table") do
expect(page).to have_text("Conservation area")
expect(page).to have_text("Listed building outline")
expect(page).to have_text("Scheduled monument")
expect(page).to have_text("Special area of conservation")
end

within("#robert") do
expect(page).to have_text("Constraints suggested by: Robert (2)")
find("span", text: "Add constraints").click

within(".other-constraints-table") do
expect(page).not_to have_text("Conservation area")
expect(page).not_to have_text("Listed building outline")
expect(page).not_to have_text("Scheduled monument")
expect(page).not_to have_text("Special area of conservation")
end

within(".robert-constraints-table") do
expect(page).to have_text("Scheduled monument")
expect(page).to have_text("Ancient woodland")
within(".identified-constraints-table") do
within(row_with_content("Special area of conservation")) do
click_link "Remove"
end
end

within("#accordion-with-other-constraints-sections-heading-1") do
expect(page).to have_text("Other constraints")
within(".identified-constraints-table") do
expect(page).not_to have_text("Special area of conservation")
end

click_button "Other constraints"
find("span", text: "Add constraints").click

within(".other-constraints-table") do
expect(page).not_to have_text("Conservation area")
expect(page).not_to have_text("Listed building outline")
expect(page).not_to have_text("Scheduled monument")
expect(page).not_to have_text("Ancient woodland")
expect(page).to have_text("Special area of conservation")
end

expect(planning_application.planning_application_constraints.active.length).to eq(3)
expect(planning_application.planning_application_constraints.length).to eq(4)

visit "/planning_applications/#{planning_application.id}/audits"

within("#audit_#{Audit.last.id}") do
within("#audit_#{Audit.last.id - 1}") do
expect(page).to have_content("Constraints Checked")
expect(page).to have_content(Audit.last.created_at.strftime("%d-%m-%Y %H:%M"))
end

within("#audit_#{Audit.last.id}") do
expect(page).to have_content("Constraint removed")
expect(page).to have_content(Audit.last.created_at.strftime("%d-%m-%Y %H:%M"))
end
end

context "when there is an error with saving a planning application constraint" do
before do
allow_any_instance_of(PlanningApplicationConstraint).to receive(:save!).and_raise(ActiveRecord::RecordInvalid)
allow_any_instance_of(PlanningApplicationConstraint).to receive(:save!).and_return(false)
end

it "presents an error message to the user and does not persist any updates" do
within(".planx-constraints-table") do
find_checkbox_by_id("constraint_id_#{planning_application.planning_application_constraints.first.constraint_id}").click
end
find("span", text: "Add constraints").click

click_button "Save and mark as checked"
within(".other-constraints-table") do
within(row_with_content("Scheduled monument")) do
click_link "Add"
end
end

expect(page).to have_content("Couldn't update constraints with error: Record invalid. Please contact support.")
expect(page).to have_content("Couldn't add constraint - please contact support.")

planning_application.reload
expect(planning_application.constraints.length).to eq(2)
Expand Down

0 comments on commit f7888a6

Please sign in to comment.