Browse Source

Update scheme back link paths

pull/2802/head
Kat 7 months ago
parent
commit
6ae69e0ac8
  1. 17
      app/helpers/schemes_helper.rb
  2. 2
      app/views/schemes/confirm_secondary.html.erb
  3. 2
      app/views/schemes/details.html.erb
  4. 8
      app/views/schemes/primary_client_group.html.erb
  5. 2
      app/views/schemes/secondary_client_group.html.erb
  6. 2
      app/views/schemes/support.html.erb
  7. 67
      spec/requests/schemes_controller_spec.rb

17
app/helpers/schemes_helper.rb

@ -93,6 +93,23 @@ 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"
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| %>

67
spec/requests/schemes_controller_spec.rb

@ -1951,6 +1951,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"
@ -2028,6 +2039,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"
@ -2105,6 +2127,17 @@ 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 "when attempting to access secondary-client-group scheme page for another organisation" do
before do
get "/schemes/#{another_scheme.id}/secondary-client-group"
@ -2174,7 +2207,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
@ -2187,6 +2220,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"
@ -2349,6 +2403,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