diff --git a/app/views/locations/check_answers.html.erb b/app/views/locations/check_answers.html.erb index 63a48d4d5..3f31841a8 100644 --- a/app/views/locations/check_answers.html.erb +++ b/app/views/locations/check_answers.html.erb @@ -45,3 +45,7 @@ <%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %> <% end %> + +<% if LocationPolicy.new(current_user, @location).delete? %> + <%= delete_location_link(@location) %> +<% end %> diff --git a/spec/requests/locations_controller_spec.rb b/spec/requests/locations_controller_spec.rb index cc238015f..e0b5e0456 100644 --- a/spec/requests/locations_controller_spec.rb +++ b/spec/requests/locations_controller_spec.rb @@ -1405,6 +1405,23 @@ RSpec.describe LocationsController, type: :request do expect(page).to have_content("Check your answers") end + context "with an active location" do + it "does not render delete this location" do + expect(location.status).to eq(:active) + expect(page).not_to have_link("Delete this location", href: "/schemes/#{scheme.id}/locations/#{location.id}/delete-confirmation") + end + end + + context "with an incomplete location" do + it "renders delete this location" do + location.update!(units: nil) + get "/schemes/#{scheme.id}/locations/#{location.id}/check-answers" + + expect(location.reload.status).to eq(:incomplete) + expect(page).to have_link("Delete this location", href: "/schemes/#{scheme.id}/locations/#{location.id}/delete-confirmation") + end + end + context "when location is confirmed" do let(:params) { { location: { confirmed: true } } }