Browse Source

CLDC-3361 Update scheme back link paths (#2802)

* Update scheme back link paths

* Correclty route if has other client group changed from no to yes
pull/2852/head^2
kosiakkatrina 1 month ago committed by GitHub
parent
commit
ef49307d9b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 4
      app/controllers/schemes_controller.rb
  2. 18
      app/helpers/schemes_helper.rb
  3. 2
      app/views/schemes/confirm_secondary.html.erb
  4. 2
      app/views/schemes/details.html.erb
  5. 8
      app/views/schemes/primary_client_group.html.erb
  6. 2
      app/views/schemes/secondary_client_group.html.erb
  7. 2
      app/views/schemes/support.html.erb
  8. 74
      spec/requests/schemes_controller_spec.rb

4
app/controllers/schemes_controller.rb

@ -150,7 +150,7 @@ class SchemesController < ApplicationController
@scheme.update!(secondary_client_group: nil) if @scheme.has_other_client_group == "No"
if scheme_params[:confirmed] == "true" || @scheme.confirmed?
if check_answers && should_direct_via_secondary_client_group_page?(page)
redirect_to scheme_secondary_client_group_path(@scheme, referrer: "check-answers")
redirect_to scheme_secondary_client_group_path(@scheme, referrer: "has-other-client-group")
else
@scheme.locations.update!(confirmed: true)
flash[:notice] = if scheme_previously_confirmed
@ -162,7 +162,7 @@ class SchemesController < ApplicationController
end
elsif check_answers
if should_direct_via_secondary_client_group_page?(page)
redirect_to scheme_secondary_client_group_path(@scheme, referrer: "check-answers")
redirect_to scheme_secondary_client_group_path(@scheme, referrer: "has-other-client-group")
else
redirect_to scheme_check_answers_path(@scheme)
end

18
app/helpers/schemes_helper.rb

@ -101,6 +101,24 @@ module SchemesHelper
organisation.owned_schemes.duplicate_sets.any? || organisation.owned_schemes.any? { |scheme| scheme.locations.duplicate_sets.any? }
end
def scheme_back_button_path(scheme, current_page)
return scheme_check_answers_path(scheme) if request.params[:referrer] == "check-answers"
return scheme_confirm_secondary_client_group_path(scheme, referrer: "check-answers") if request.params[:referrer] == "has-other-client-group"
case current_page
when "details"
schemes_path
when "primary_client_group"
scheme_details_path(scheme)
when "confirm_secondary_client_group"
scheme_primary_client_group_path(scheme)
when "secondary_client_group"
scheme_confirm_secondary_client_group_path(scheme)
when "support"
scheme.has_other_client_group == "Yes" ? scheme_secondary_client_group_path(scheme) : scheme_confirm_secondary_client_group_path(scheme)
end
end
private
ActivePeriod = Struct.new(:from, :to)

2
app/views/schemes/confirm_secondary.html.erb

@ -1,7 +1,7 @@
<% content_for :title, "Does this scheme provide for another client group?" %>
<% content_for :before_content do %>
<%= govuk_back_link(href: :back) %>
<%= govuk_back_link(href: scheme_back_button_path(@scheme, "confirm_secondary_client_group")) %>
<% end %>
<%= render partial: "organisations/headings", locals: { main: "Does this scheme provide for another client group?", sub: @scheme.service_name } %>

2
app/views/schemes/details.html.erb

@ -1,7 +1,7 @@
<% content_for :title, "Create a new supported housing scheme" %>
<% content_for :before_content do %>
<%= govuk_back_link(href: :back) %>
<%= govuk_back_link(href: scheme_back_button_path(@scheme, "details")) %>
<% end %>
<%= form_for(@scheme, method: :patch) do |f| %>

8
app/views/schemes/primary_client_group.html.erb

@ -1,13 +1,7 @@
<% content_for :title, "What client group is this scheme intended for?" %>
<% if request.referer&.include?("new") %>
<% back_button_path = scheme_details_path(@scheme) %>
<% else %>
<% back_button_path = :back %>
<% end %>
<% content_for :before_content do %>
<%= govuk_back_link(href: back_button_path) %>
<%= govuk_back_link(href: scheme_back_button_path(@scheme, "primary_client_group")) %>
<% end %>
<%= form_for(@scheme, method: :patch) do |f| %>

2
app/views/schemes/secondary_client_group.html.erb

@ -1,7 +1,7 @@
<% content_for :title, "What is the other client group?" %>
<% content_for :before_content do %>
<%= govuk_back_link(href: :back) %>
<%= govuk_back_link(href: scheme_back_button_path(@scheme, "secondary_client_group")) %>
<% end %>
<%= form_for(@scheme, method: :patch) do |f| %>

2
app/views/schemes/support.html.erb

@ -1,7 +1,7 @@
<% content_for :title, "What support does this scheme provide?" %>
<% content_for :before_content do %>
<%= govuk_back_link(href: :back) %>
<%= govuk_back_link(href: scheme_back_button_path(@scheme, "support")) %>
<% end %>
<%= form_for(@scheme, method: :patch) do |f| %>

74
spec/requests/schemes_controller_spec.rb

@ -2035,6 +2035,17 @@ RSpec.describe SchemesController, type: :request do
expect(page).to have_content("What client group is this scheme intended for?")
end
it "has correct back link" do
expect(page).to have_link("Back", href: "/schemes/#{scheme.id}/details")
end
context "and accessed from check answers" do
it "has correct back link" do
get "/schemes/#{scheme.id}/primary-client-group?referrer=check-answers"
expect(page).to have_link("Back", href: "/schemes/#{scheme.id}/check-answers")
end
end
context "when attempting to access primary-client-group scheme page for another organisation" do
before do
get "/schemes/#{another_scheme.id}/primary-client-group"
@ -2112,6 +2123,17 @@ RSpec.describe SchemesController, type: :request do
expect(page).to have_content("Does this scheme provide for another client group?")
end
it "has correct back link" do
expect(page).to have_link("Back", href: "/schemes/#{scheme.id}/primary-client-group")
end
context "and accessed from check answers" do
it "has correct back link" do
get "/schemes/#{scheme.id}/confirm-secondary-client-group?referrer=check-answers"
expect(page).to have_link("Back", href: "/schemes/#{scheme.id}/check-answers")
end
end
context "when attempting to access confirm-secondary-client-group scheme page for another organisation" do
before do
get "/schemes/#{another_scheme.id}/confirm-secondary-client-group"
@ -2189,6 +2211,24 @@ RSpec.describe SchemesController, type: :request do
expect(page).to have_content("What is the other client group?")
end
it "has correct back link" do
expect(page).to have_link("Back", href: "/schemes/#{scheme.id}/confirm-secondary-client-group")
end
context "and accessed from check answers" do
it "has correct back link" do
get "/schemes/#{scheme.id}/secondary-client-group?referrer=check-answers"
expect(page).to have_link("Back", href: "/schemes/#{scheme.id}/check-answers")
end
end
context "and accessed from has other client group" do
it "has correct back link" do
get "/schemes/#{scheme.id}/secondary-client-group?referrer=has-other-client-group"
expect(page).to have_link("Back", href: "/schemes/#{scheme.id}/confirm-secondary-client-group?referrer=check-answers")
end
end
context "when attempting to access secondary-client-group scheme page for another organisation" do
before do
get "/schemes/#{another_scheme.id}/secondary-client-group"
@ -2258,7 +2298,7 @@ RSpec.describe SchemesController, type: :request do
context "when signed in as a data coordinator" do
let(:user) { create(:user, :data_coordinator) }
let(:scheme) { create(:scheme, owning_organisation: user.organisation, confirmed: nil) }
let(:scheme) { create(:scheme, owning_organisation: user.organisation, confirmed: nil, has_other_client_group: "Yes") }
let(:another_scheme) { create(:scheme, confirmed: nil) }
before do
@ -2271,6 +2311,27 @@ RSpec.describe SchemesController, type: :request do
expect(page).to have_content("What support does this scheme provide?")
end
context "when scheme has secondary client group" do
it "has correct back link" do
expect(page).to have_link("Back", href: "/schemes/#{scheme.id}/secondary-client-group")
end
end
context "when scheme has no secondary client group" do
let(:scheme) { create(:scheme, owning_organisation: user.organisation, confirmed: nil, has_other_client_group: "No") }
it "has correct back link" do
expect(page).to have_link("Back", href: "/schemes/#{scheme.id}/confirm-secondary-client-group")
end
end
context "and accessed from check answers" do
it "has correct back link" do
get "/schemes/#{scheme.id}/support?referrer=check-answers"
expect(page).to have_link("Back", href: "/schemes/#{scheme.id}/check-answers")
end
end
context "when attempting to access secondary-client-group scheme page for another organisation" do
before do
get "/schemes/#{another_scheme.id}/support"
@ -2433,6 +2494,17 @@ RSpec.describe SchemesController, type: :request do
expect(page).to have_content("Create a new supported housing scheme")
end
it "has correct back link" do
expect(page).to have_link("Back", href: "/schemes")
end
context "and accessed from check answers" do
it "has correct back link" do
get "/schemes/#{scheme.id}/details?referrer=check-answers"
expect(page).to have_link("Back", href: "/schemes/#{scheme.id}/check-answers")
end
end
context "when attempting to access check-answers scheme page for another organisation" do
before do
get "/schemes/#{another_scheme.id}/details"

Loading…
Cancel
Save