From d119b1a4f3a5a8a4820df8a74c85ce33ba84830f Mon Sep 17 00:00:00 2001 From: Kat Date: Mon, 11 Dec 2023 12:23:34 +0000 Subject: [PATCH] Allow editing locations --- app/controllers/locations_controller.rb | 8 +++++++ app/models/scheme.rb | 1 + .../locations/mobility_standards.html.erb | 3 +++ app/views/locations/postcode.html.erb | 3 +++ app/views/locations/show.html.erb | 4 ++++ app/views/locations/type_of_unit.html.erb | 3 +++ app/views/locations/units.html.erb | 3 +++ app/views/schemes/check_answers.html.erb | 2 +- app/views/schemes/show.html.erb | 21 ++++++++++++++++++- spec/features/schemes_spec.rb | 18 ++++++++-------- spec/requests/schemes_controller_spec.rb | 21 ++++++------------- 11 files changed, 61 insertions(+), 26 deletions(-) diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index 83e90c373..b84185b51 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -40,6 +40,8 @@ class LocationsController < ApplicationController redirect_to scheme_location_local_authority_path(@scheme, @location, route: params[:route], referrer: params[:referrer]) elsif return_to_check_your_answers? redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route]) + elsif params[:referrer] == "details" + redirect_to scheme_location_path(@scheme, @location) else redirect_to scheme_location_name_path(@scheme, @location, route: params[:route]) end @@ -88,6 +90,8 @@ class LocationsController < ApplicationController if @location.save(context: :units) if return_to_check_your_answers? redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route]) + elsif params[:referrer] == "details" + redirect_to scheme_location_path(@scheme, @location) else redirect_to scheme_location_type_of_unit_path(@scheme, @location, route: params[:route]) end @@ -103,6 +107,8 @@ class LocationsController < ApplicationController if @location.save(context: :type_of_unit) if return_to_check_your_answers? redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route]) + elsif params[:referrer] == "details" + redirect_to scheme_location_path(@scheme, @location) else redirect_to scheme_location_mobility_standards_path(@scheme, @location, route: params[:route]) end @@ -118,6 +124,8 @@ class LocationsController < ApplicationController if @location.save(context: :mobility_type) if return_to_check_your_answers? redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route]) + elsif params[:referrer] == "details" + redirect_to scheme_location_path(@scheme, @location) else redirect_to scheme_location_availability_path(@scheme, @location, route: params[:route]) end diff --git a/app/models/scheme.rb b/app/models/scheme.rb index 1598b31d3..1a75aae8b 100644 --- a/app/models/scheme.rb +++ b/app/models/scheme.rb @@ -188,6 +188,7 @@ class Scheme < ApplicationRecord [ { name: "Scheme code", value: id_to_display, id: "id" }, { name: "Name", value: service_name, id: "service_name", edit: true }, + { name: "Status", value: status, id: "status" }, { name: "Confidential information", value: sensitive, id: "sensitive", edit: true }, { name: "Type of scheme", value: scheme_type, id: "scheme_type", edit: true }, { name: "Registered under Care Standards Act 2000", value: registered_under_care_act, id: "registered_under_care_act", edit: true }, diff --git a/app/views/locations/mobility_standards.html.erb b/app/views/locations/mobility_standards.html.erb index da08f8bfa..a5ed77f49 100644 --- a/app/views/locations/mobility_standards.html.erb +++ b/app/views/locations/mobility_standards.html.erb @@ -24,6 +24,9 @@ <% if params[:referrer] == "check_answers" %> <%= f.govuk_submit "Save changes" %> <%= govuk_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location, route: params[:route]), secondary: true %> + <% elsif params[:referrer] == "details" %> + <%= f.govuk_submit "Save changes" %> + <%= govuk_link_to "Cancel", scheme_location_path(@scheme, @location), secondary: true %> <% else %> <%= f.govuk_submit "Save and continue" %> <%= govuk_link_to "Skip for now", scheme_location_availability_path(@scheme, @location), secondary: true %> diff --git a/app/views/locations/postcode.html.erb b/app/views/locations/postcode.html.erb index fe0505926..5e17c17d5 100644 --- a/app/views/locations/postcode.html.erb +++ b/app/views/locations/postcode.html.erb @@ -26,6 +26,9 @@ <% if params[:referrer] == "check_answers" %> <%= f.govuk_submit "Save changes" %> <%= govuk_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location, route: params[:route]), secondary: true %> + <% elsif params[:referrer] == "details" %> + <%= f.govuk_submit "Save changes" %> + <%= govuk_link_to "Cancel", scheme_location_path(@scheme, @location), secondary: true %> <% else %> <%= f.govuk_submit "Save and continue" %> <%= govuk_link_to "Skip for now", scheme_location_name_path(@scheme, @location), secondary: true %> diff --git a/app/views/locations/show.html.erb b/app/views/locations/show.html.erb index 5d6044f06..f4371213c 100644 --- a/app/views/locations/show.html.erb +++ b/app/views/locations/show.html.erb @@ -19,7 +19,11 @@ <% row.key { attr[:name] } %> <% row.value { attr[:attribute].eql?("status") ? status_tag_from_resource(@location) : details_html(attr) } %> <% if LocationPolicy.new(current_user, @location).update? %> + <% row.action(text: "Change", href: scheme_location_postcode_path(@scheme, @location, referrer: "details")) if attr[:attribute] == "postcode" && current_user.support? %> <% row.action(text: "Change", href: scheme_location_name_path(@scheme, @location, referrer: "details")) if attr[:attribute] == "name" %> + <% row.action(text: "Change", href: scheme_location_units_path(@scheme, @location, referrer: "details")) if attr[:attribute] == "units" && current_user.support? %> + <% row.action(text: "Change", href: scheme_location_type_of_unit_path(@scheme, @location, referrer: "details")) if attr[:attribute] == "type_of_unit" && current_user.support? %> + <% row.action(text: "Change", href: scheme_location_mobility_standards_path(@scheme, @location, referrer: "details")) if attr[:attribute] == "mobility_standards" && current_user.support? %> <% end %> <% end %> <% end %> diff --git a/app/views/locations/type_of_unit.html.erb b/app/views/locations/type_of_unit.html.erb index 45b76ef67..cb7b3db41 100644 --- a/app/views/locations/type_of_unit.html.erb +++ b/app/views/locations/type_of_unit.html.erb @@ -23,6 +23,9 @@ <% if params[:referrer] == "check_answers" %> <%= f.govuk_submit "Save changes" %> <%= govuk_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location, route: params[:route]), secondary: true %> + <% elsif params[:referrer] == "details" %> + <%= f.govuk_submit "Save changes" %> + <%= govuk_link_to "Cancel", scheme_location_path(@scheme, @location), secondary: true %> <% else %> <%= f.govuk_submit "Save and continue" %> <%= govuk_link_to "Skip for now", scheme_location_mobility_standards_path(@scheme, @location), secondary: true %> diff --git a/app/views/locations/units.html.erb b/app/views/locations/units.html.erb index 12365adbb..cf71ef11a 100644 --- a/app/views/locations/units.html.erb +++ b/app/views/locations/units.html.erb @@ -23,6 +23,9 @@ <% if params[:referrer] == "check_answers" %> <%= f.govuk_submit "Save changes" %> <%= govuk_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location, route: params[:route]), secondary: true %> + <% elsif params[:referrer] == "details" %> + <%= f.govuk_submit "Save changes" %> + <%= govuk_link_to "Cancel", scheme_location_path(@scheme, @location), secondary: true %> <% else %> <%= f.govuk_submit "Save and continue" %> <%= govuk_link_to "Skip for now", scheme_location_type_of_unit_path(@scheme, @location), secondary: true %> diff --git a/app/views/schemes/check_answers.html.erb b/app/views/schemes/check_answers.html.erb index 25a7fd221..1020f5d62 100644 --- a/app/views/schemes/check_answers.html.erb +++ b/app/views/schemes/check_answers.html.erb @@ -9,7 +9,7 @@

Scheme

<% @scheme.check_details_attributes.each do |attr| %> - <%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: current_user.support? ? scheme_details_path(@scheme, check_answers: true) : scheme_edit_name_path(@scheme) } %> + <%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: current_user.support? ? scheme_details_path(@scheme, check_answers: true) : scheme_edit_name_path(@scheme) } unless attr[:name] == "Status" %> <% end %> <% @scheme.check_primary_client_attributes.each do |attr| %> diff --git a/app/views/schemes/show.html.erb b/app/views/schemes/show.html.erb index 213df690b..8bf0647c3 100644 --- a/app/views/schemes/show.html.erb +++ b/app/views/schemes/show.html.erb @@ -21,7 +21,19 @@

Scheme

<% @scheme.check_details_attributes.each do |attr| %> - <%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: current_user.support? ? scheme_details_path(@scheme, check_answers: true) : scheme_edit_name_path(scheme_id: @scheme.id) } %> + <% if attr[:name] == "Status" %> +
+
Status
+
+ <%= details_html({ name: "Status", value: status_tag_from_resource(@scheme), id: "status" }) %> + <% if @scheme.confirmed? && @scheme.locations.confirmed.none? && LocationPolicy.new(current_user, @scheme.locations.new).create? %> + Complete this scheme by adding a location using the <%= govuk_link_to("‘locations’ tab", scheme_locations_path(@scheme)) %>. + <% end %> +
+
+ <% else %> + <%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: current_user.support? ? scheme_details_path(@scheme, check_answers: true) : scheme_edit_name_path(scheme_id: @scheme.id) } %> + <% end %> <% end %> <% @scheme.check_primary_client_attributes.each do |attr| %> @@ -41,6 +53,13 @@ <% @scheme.check_support_attributes.each do |attr| %> <%= render partial: "scheme_summary_list_row", locals: { scheme: @scheme, attribute: attr, change_link: scheme_support_path(@scheme, check_answers: true) } %> <% end %> + +
+
Availability
+
+ <%= details_html({ name: "Availability", value: scheme_availability(@scheme), id: "availability" }) %> +
+
diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index 242c40353..c2c84f94b 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -377,9 +377,9 @@ RSpec.describe "Schemes scheme Features" do expect(page).to have_content("has been added") end - it "does not let you edit the saved location" do + it "lets you edit the saved location" do click_link "AA1 2AA" - expect(page).not_to have_link(nil, href: /postcode/) + expect(page).to have_link("Change", href: /postcode/) end end @@ -607,7 +607,7 @@ RSpec.describe "Schemes scheme Features" do it "displays changed location" do click_link "AA1 2AA" - click_link "Change" + click_link("Change", href: "/schemes/#{scheme.id}/locations/#{location.id}/name?referrer=details", match: :first) fill_in with: "new name" click_button "Save changes" expect(page).to have_content "AA1 2AA" @@ -864,10 +864,10 @@ RSpec.describe "Schemes scheme Features" do expect(page).to have_content("Active") end - it "only allows to edit the location name" do - assert_selector "a", text: "Change", count: 1 + it "only allows to edit the location name, postcode, unit, unit type and mobility standards" do + assert_selector "a", text: "Change", count: 5 - click_link("Change") + click_link("Change", href: "/schemes/#{scheme.id}/locations/#{location.id}/name?referrer=details", match: :first) expect(page).to have_content "What is the name of this location?" end @@ -889,7 +889,7 @@ RSpec.describe "Schemes scheme Features" do context "and I change the location name" do before do - click_link("Change") + click_link("Change", href: "/schemes/#{scheme.id}/locations/#{location.id}/name?referrer=details", match: :first) end it "returns to locations check your answers page and shows the new name" do @@ -1008,9 +1008,9 @@ RSpec.describe "Schemes scheme Features" do expect(page).to have_content("has been added") end - it "does not let you edit the saved location" do + it "lets you edit the saved location" do click_link "AA1 2AA" - expect(page).not_to have_link(nil, href: /postcode/) + expect(page).to have_link("Change", href: /postcode/) end end diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index 0abeb92ae..6e00eb733 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/spec/requests/schemes_controller_spec.rb @@ -1832,12 +1832,9 @@ RSpec.describe SchemesController, type: :request do get "/schemes/#{scheme.id}/primary-client-group" end - it "redirects to a view scheme page" do - follow_redirect! + it "allows editing the primary client group" do expect(response).to have_http_status(:ok) - expect(path).to match("/schemes/#{scheme.id}") - expect(page).to have_content(scheme.service_name) - assert_select "a", text: /Change/, count: 3 + expect(path).to match("/schemes/#{scheme.id}/primary-client-group") end end end @@ -1912,12 +1909,9 @@ RSpec.describe SchemesController, type: :request do get "/schemes/#{scheme.id}/confirm-secondary-client-group" end - it "redirects to a view scheme page" do - follow_redirect! + it "allows updating secondary client group" do expect(response).to have_http_status(:ok) - expect(path).to match("/schemes/#{scheme.id}") - expect(page).to have_content(scheme.service_name) - assert_select "a", text: /Change/, count: 3 + expect(path).to match("/schemes/#{scheme.id}/confirm-secondary-client-group") end end end @@ -1992,12 +1986,9 @@ RSpec.describe SchemesController, type: :request do get "/schemes/#{scheme.id}/secondary-client-group" end - it "redirects to a view scheme page" do - follow_redirect! + it "allows editing secondary client group" do expect(response).to have_http_status(:ok) - expect(path).to match("/schemes/#{scheme.id}") - expect(page).to have_content(scheme.service_name) - assert_select "a", text: /Change/, count: 3 + expect(path).to match("/schemes/#{scheme.id}/secondary-client-group") end end