From 1074311cfa232035f3e51e8e9bf04b59599bf86f Mon Sep 17 00:00:00 2001 From: Kat Date: Mon, 1 Aug 2022 09:39:10 +0100 Subject: [PATCH] Display banners and redirect to check answers after editing location name --- app/controllers/locations_controller.rb | 2 +- app/controllers/schemes_controller.rb | 9 +++++-- app/helpers/check_answers_helper.rb | 3 ++- spec/features/schemes_spec.rb | 34 ++++++++++++++++-------- spec/requests/schemes_controller_spec.rb | 20 +++----------- 5 files changed, 36 insertions(+), 32 deletions(-) diff --git a/app/controllers/locations_controller.rb b/app/controllers/locations_controller.rb index de8a2d835..b88b895fb 100644 --- a/app/controllers/locations_controller.rb +++ b/app/controllers/locations_controller.rb @@ -56,7 +56,7 @@ class LocationsController < ApplicationController when "edit" location_params[:add_another_location] == "Yes" ? redirect_to(new_location_path(@location.scheme)) : redirect_to(scheme_check_answers_path(@scheme, anchor: "locations")) when "edit-name" - redirect_to(locations_path(@scheme)) + redirect_to(scheme_check_answers_path(@scheme, anchor: "locations")) end else render :edit, status: :unprocessable_entity diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index fe9454c4b..df616837a 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -7,7 +7,6 @@ class SchemesController < ApplicationController before_action :authenticate_scope! def index - flash[:notice] = "#{Scheme.find(params[:scheme_id].to_i).service_name} has been created." if params[:scheme_id] redirect_to schemes_organisation_path(current_user.organisation) unless current_user.support? all_schemes = Scheme.all.order("service_name ASC") @@ -52,11 +51,17 @@ class SchemesController < ApplicationController check_answers = params[:scheme][:check_answers] page = params[:scheme][:page] + scheme_previously_confirmed = @scheme.confirmed? validation_errors scheme_params if @scheme.errors.empty? && @scheme.update(scheme_params) if scheme_params[:confirmed] == "true" - @scheme.locations.each {|location| location.update!(confirmed:true)} + @scheme.locations.each { |location| location.update!(confirmed: true) } + flash[:notice] = if scheme_previously_confirmed + "#{@scheme.service_name} has been updated." + else + "#{@scheme.service_name} has been created." + end redirect_to scheme_path(@scheme) elsif check_answers if confirm_secondary_page? page diff --git a/app/helpers/check_answers_helper.rb b/app/helpers/check_answers_helper.rb index 580a62111..f5233d33a 100644 --- a/app/helpers/check_answers_helper.rb +++ b/app/helpers/check_answers_helper.rb @@ -13,7 +13,7 @@ module CheckAnswersHelper def can_change_scheme_answer?(attribute_name, scheme) editable_attributes = current_user.support? ? ["Name", "Confidential information", "Housing stock owned by"] : ["Name", "Confidential information"] - !scheme.confirmed? || editable_attributes.include?(attribute_name) + !scheme.confirmed? || editable_attributes.include?(attribute_name) end def get_location_change_link_href(scheme, location) @@ -23,6 +23,7 @@ module CheckAnswersHelper "/schemes/#{scheme.id}/locations/#{location.id}/edit" end end + private def answered_questions_count(subsection, case_log, current_user) diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index e704fbe91..7c9456076 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -285,16 +285,20 @@ RSpec.describe "Schemes scheme Features" do end it "allows you to edit the newly added location" do - click_link 'Locations' - expect(page).to have_link(nil , href: /edit/) + click_link "Locations" + expect(page).to have_link(nil, href: /edit/) end context "when you click save" do - xit "takes you to view location tab and displays a banner" do + xit "takes you to view location tab" do click_button "Save" expect(page.current_url.split("/").last).to eq("locations") + end + + it "displays a updated banner" do + click_button "Save" expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success") - expect(page).to have_content("updated") + expect(page).to have_content("has been updated") end it "does not let you edit the saved location" do @@ -584,11 +588,12 @@ RSpec.describe "Schemes scheme Features" do end it "adds scheme to the list of schemes" do + expect(page).to have_content "#{scheme.service_name} has been created." + click_link "Schemes" expect(page).to have_content "Supported housing schemes" expect(page).to have_content scheme.id_to_display expect(page).to have_content scheme.service_name expect(page).to have_content scheme.owning_organisation.name - expect(page).to have_content "#{scheme.service_name} has been created." end end @@ -732,6 +737,13 @@ RSpec.describe "Schemes scheme Features" do expect(page).to have_current_path("/schemes/#{scheme.id}/check-answers") assert_selector "a", text: "Change", count: 3 end + + it "lets me save the scheme" do + click_button "Save" + expect(page).to have_current_path("/schemes/#{scheme.id}") + expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success") + expect(page).to have_content("has been updated") + end end end @@ -772,10 +784,10 @@ RSpec.describe "Schemes scheme Features" do click_button "Save and continue" end - it "returns to locations page and shows the new name" do + it "returns to locations check your answers page and shows the new name" do expect(page).to have_content location.id expect(page).to have_content "NewName" - expect(page).to have_current_path("/schemes/#{scheme.id}/locations") + expect(page.current_url.split("/").last).to eq("check-answers#locations") end end end @@ -858,8 +870,8 @@ RSpec.describe "Schemes scheme Features" do click_link("Scheme") end - it "does not let you change details other than the name" do - assert_selector "a", text: "Change", count: 1 + it "does not let you change details other than the name, Confidential information and Housing stock owned by" do + assert_selector "a", text: "Change", count: 3 end end end @@ -873,7 +885,6 @@ RSpec.describe "Schemes scheme Features" do context "when I am signed in as a data coordinator" do let(:user) { FactoryBot.create(:user, :data_coordinator, last_sign_in_at: Time.zone.now) } let!(:schemes) { FactoryBot.create_list(:scheme, 5, owning_organisation_id: user.organisation_id) } - let!(:scheme_to_search) { FactoryBot.create(:scheme) } before do visit("/logs") @@ -890,9 +901,9 @@ RSpec.describe "Schemes scheme Features" do context "when I click to see individual scheme" do let(:scheme) { schemes.first } - let!(:location) { FactoryBot.create(:location, scheme:) } before do + FactoryBot.create(:location, scheme:) click_link(scheme.service_name) end @@ -919,6 +930,7 @@ RSpec.describe "Schemes scheme Features" do end end end + context "when selecting a scheme" do let!(:user) { FactoryBot.create(:user, :data_coordinator, last_sign_in_at: Time.zone.now) } let!(:schemes) { FactoryBot.create_list(:scheme, 5, owning_organisation: user.organisation, managing_organisation: user.organisation, arrangement_type: "The same organisation that owns the housing stock") } diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index 876100727..90034974c 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/spec/requests/schemes_controller_spec.rb @@ -37,14 +37,6 @@ RSpec.describe SchemesController, type: :request do get "/schemes" end - context "when params scheme_id is present" do - it "shows a success banner" do - get "/schemes", params: { scheme_id: schemes.first.id } - follow_redirect! - expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success") - end - end - it "redirects to the organisation schemes path" do follow_redirect! expect(path).to match("/organisations/#{user.organisation.id}/schemes") @@ -93,13 +85,6 @@ RSpec.describe SchemesController, type: :request do expect(CGI.unescape_html(response.body)).to match("#{schemes.count} total schemes") end - context "when params scheme_id is present" do - it "shows a success banner" do - get "/schemes", params: { scheme_id: schemes.first.id } - expect(page).to have_css(".govuk-notification-banner.govuk-notification-banner--success") - end - end - context "when paginating over 20 results" do let(:total_schemes_count) { Scheme.count } @@ -885,9 +870,10 @@ RSpec.describe SchemesController, type: :request do context "when signed in as a support" do let(:user) { FactoryBot.create(:user, :support) } let(:scheme_to_update) { FactoryBot.create(:scheme, owning_organisation: user.organisation, confirmed: nil) } - let!(:location) { FactoryBot.create(:location, scheme: scheme_to_update )} + # let!(:location) { FactoryBot.create(:location, scheme: scheme_to_update) } before do + FactoryBot.create(:location, scheme: scheme_to_update) allow(user).to receive(:need_two_factor_authentication?).and_return(false) sign_in user patch "/schemes/#{scheme_to_update.id}", params: @@ -945,7 +931,7 @@ RSpec.describe SchemesController, type: :request do let(:params) { { scheme: { page: "check-answers", confirmed: "true" } } } it "marks the scheme as confirmed" do - expect(scheme_to_update.reload.confirmed?).to eq(true) + expect(scheme_to_update.reload.confirmed?).to eq(true) end it "marks all the scheme locations as confirmed" do