Browse Source

feat: further linking behaviour with routes and referrers, don't add new location automatically to new schemes

pull/1034/head
natdeanlewissoftwire 4 years ago
parent
commit
d66616a60f
  1. 40
      app/controllers/locations_controller.rb
  2. 2
      app/controllers/schemes_controller.rb
  3. 12
      app/helpers/check_answers_helper.rb
  4. 14
      app/helpers/locations_helper.rb
  5. 11
      app/helpers/tab_nav_helper.rb
  6. 6
      app/views/locations/availability.erb
  7. 8
      app/views/locations/check_answers.html.erb
  8. 4
      app/views/locations/index.html.erb
  9. 13
      app/views/locations/local_authority.html.erb
  10. 6
      app/views/locations/mobility_standards.html.erb
  11. 10
      app/views/locations/name.html.erb
  12. 11
      app/views/locations/postcode.html.erb
  13. 6
      app/views/locations/type_of_unit.html.erb
  14. 6
      app/views/locations/units.html.erb
  15. 47
      app/views/schemes/check_answers.html.erb
  16. 28
      spec/features/schemes_spec.rb

40
app/controllers/locations_controller.rb

@ -15,13 +15,9 @@ class LocationsController < ApplicationController
end end
def new def new
@location = if params[:referrer] == "new_scheme" && @scheme.locations.present? @location = Location.new(scheme: @scheme)
@scheme.locations.first
else
Location.new(scheme: @scheme)
end
@location.save! @location.save!
redirect_to scheme_location_postcode_path(@scheme, @location, referrer: params[:referrer]) redirect_to scheme_location_postcode_path(@scheme, @location, route: params[:route])
end end
def postcode def postcode
@ -32,11 +28,11 @@ class LocationsController < ApplicationController
if @location.valid?(:postcode) if @location.valid?(:postcode)
@location.save! @location.save!
if @location.location_code.blank? || @location.location_admin_district.blank? if @location.location_code.blank? || @location.location_admin_district.blank?
redirect_to scheme_location_local_authority_path(@scheme, @location, referrer: params[:referrer]) redirect_to scheme_location_local_authority_path(@scheme, @location, route: params[:route], referrer: params[:referrer])
elsif params[:referrer] == "check_answers" elsif params[:referrer] == "check_answers"
redirect_to scheme_location_check_answers_path(@scheme, @location) redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route])
else else
redirect_to scheme_location_name_path(@scheme, @location, referrer: params[:referrer]) redirect_to scheme_location_name_path(@scheme, @location, route: params[:route])
end end
else else
render :postcode, status: :unprocessable_entity render :postcode, status: :unprocessable_entity
@ -50,10 +46,10 @@ class LocationsController < ApplicationController
@location.location_code = Location.local_authorities.key(params[:location][:location_admin_district]) @location.location_code = Location.local_authorities.key(params[:location][:location_admin_district])
if @location.valid?(:location_admin_district) if @location.valid?(:location_admin_district)
@location.save! @location.save!
if params[:referrer] == "check_answers" if params[:referrer] == "check_answers" || params[:referrer] == "check_local_authority"
redirect_to scheme_location_check_answers_path(@scheme, @location) redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route])
else else
redirect_to scheme_location_name_path(@scheme, @location, referrer: params[:referrer]) redirect_to scheme_location_name_path(@scheme, @location, route: params[:route])
end end
else else
render :local_authority, status: :unprocessable_entity render :local_authority, status: :unprocessable_entity
@ -68,11 +64,11 @@ class LocationsController < ApplicationController
@location.save! @location.save!
case params[:referrer] case params[:referrer]
when "check_answers" when "check_answers"
redirect_to scheme_location_check_answers_path(@scheme, @location) redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route])
when "details" when "details"
redirect_to scheme_location_path(@scheme, @location) redirect_to scheme_location_path(@scheme, @location)
else else
redirect_to scheme_location_units_path(@scheme, @location, referrer: params[:referrer]) redirect_to scheme_location_units_path(@scheme, @location, route: params[:route])
end end
else else
render :name, status: :unprocessable_entity render :name, status: :unprocessable_entity
@ -86,9 +82,9 @@ class LocationsController < ApplicationController
if @location.valid?(:units) if @location.valid?(:units)
@location.save! @location.save!
if params[:referrer] == "check_answers" if params[:referrer] == "check_answers"
redirect_to scheme_location_check_answers_path(@scheme, @location) redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route])
else else
redirect_to scheme_location_type_of_unit_path(@scheme, @location, referrer: params[:referrer]) redirect_to scheme_location_type_of_unit_path(@scheme, @location, route: params[:route])
end end
else else
render :units, status: :unprocessable_entity render :units, status: :unprocessable_entity
@ -102,9 +98,9 @@ class LocationsController < ApplicationController
if @location.valid?(:type_of_unit) if @location.valid?(:type_of_unit)
@location.save! @location.save!
if params[:referrer] == "check_answers" if params[:referrer] == "check_answers"
redirect_to scheme_location_check_answers_path(@scheme, @location) redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route])
else else
redirect_to scheme_location_mobility_standards_path(@scheme, @location, referrer: params[:referrer]) redirect_to scheme_location_mobility_standards_path(@scheme, @location, route: params[:route])
end end
else else
render :type_of_unit, status: :unprocessable_entity render :type_of_unit, status: :unprocessable_entity
@ -118,9 +114,9 @@ class LocationsController < ApplicationController
if @location.valid?(:mobility_type) if @location.valid?(:mobility_type)
@location.save! @location.save!
if params[:referrer] == "check_answers" if params[:referrer] == "check_answers"
redirect_to scheme_location_check_answers_path(@scheme, @location) redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route])
else else
redirect_to scheme_location_availability_path(@scheme, @location, referrer: params[:referrer]) redirect_to scheme_location_availability_path(@scheme, @location, route: params[:route])
end end
else else
render :mobility_standards, status: :unprocessable_entity render :mobility_standards, status: :unprocessable_entity
@ -138,7 +134,7 @@ class LocationsController < ApplicationController
@location.startdate = Time.zone.local(year.to_i, month.to_i, day.to_i) @location.startdate = Time.zone.local(year.to_i, month.to_i, day.to_i)
if @location.valid?(:startdate) if @location.valid?(:startdate)
@location.save! @location.save!
redirect_to scheme_location_check_answers_path(@scheme, @location, referrer: params[:referrer]) redirect_to scheme_location_check_answers_path(@scheme, @location, route: params[:route])
else else
render :availability, status: :unprocessable_entity render :availability, status: :unprocessable_entity
end end
@ -157,6 +153,8 @@ class LocationsController < ApplicationController
def check_answers def check_answers
if params[:location].present? if params[:location].present?
@location.confirmed = true
@location.save!
flash[:notice] = "#{@location.postcode} #{@location.startdate < Time.zone.now ? 'has been' : 'will be'} added to this scheme" flash[:notice] = "#{@location.postcode} #{@location.startdate < Time.zone.now ? 'has been' : 'will be'} added to this scheme"
redirect_to scheme_locations_path(@scheme) redirect_to scheme_locations_path(@scheme)
end end

2
app/controllers/schemes_controller.rb

@ -229,7 +229,7 @@ private
when "secondary-client-group" when "secondary-client-group"
scheme_support_path(@scheme) scheme_support_path(@scheme)
when "support" when "support"
new_scheme_location_path(@scheme, referrer: "new_scheme") scheme_check_answers_path(@scheme)
when "details" when "details"
if @scheme.arrangement_type_before_type_cast == "D" if @scheme.arrangement_type_before_type_cast == "D"
scheme_primary_client_group_path(@scheme) scheme_primary_client_group_path(@scheme)

12
app/helpers/check_answers_helper.rb

@ -16,18 +16,6 @@ module CheckAnswersHelper
!scheme.confirmed? || editable_attributes.include?(attribute_name) !scheme.confirmed? || editable_attributes.include?(attribute_name)
end end
def get_location_change_link_href_postcode(scheme, location)
if location.confirmed?
scheme_location_path(scheme_id: scheme.id, id: location.id)
else
edit_scheme_location_path(scheme_id: scheme.id, id: location.id)
end
end
def get_location_change_link_href_location_admin_district(scheme, location)
scheme_location_edit_local_authority_path(scheme_id: scheme.id, location_id: location.id)
end
def any_questions_have_summary_card_number?(subsection, lettings_log) def any_questions_have_summary_card_number?(subsection, lettings_log)
subsection.applicable_questions(lettings_log).map(&:check_answers_card_number).compact.length.positive? subsection.applicable_questions(lettings_log).map(&:check_answers_card_number).compact.length.positive?
end end

14
app/helpers/locations_helper.rb

@ -56,19 +56,19 @@ module LocationsHelper
def location_edit_path(location, page) def location_edit_path(location, page)
case page case page
when "postcode" when "postcode"
scheme_location_postcode_path(location.scheme, location, referrer: "check_answers") scheme_location_postcode_path(location.scheme, location, referrer: "check_answers", route: params[:route])
when "name" when "name"
scheme_location_name_path(location.scheme, location, referrer: "check_answers") scheme_location_name_path(location.scheme, location, referrer: "check_answers", route: params[:route])
when "location_admin_district" when "location_admin_district"
scheme_location_local_authority_path(location.scheme, location, referrer: "check_answers") scheme_location_local_authority_path(location.scheme, location, referrer: "check_local_authority", route: params[:route])
when "units" when "units"
scheme_location_units_path(location.scheme, location, referrer: "check_answers") scheme_location_units_path(location.scheme, location, referrer: "check_answers", route: params[:route])
when "type_of_unit" when "type_of_unit"
scheme_location_type_of_unit_path(location.scheme, location, referrer: "check_answers") scheme_location_type_of_unit_path(location.scheme, location, referrer: "check_answers", route: params[:route])
when "mobility_standards" when "mobility_standards"
scheme_location_mobility_standards_path(location.scheme, location, referrer: "check_answers") scheme_location_mobility_standards_path(location.scheme, location, referrer: "check_answers", route: params[:route])
when "availability" when "availability"
scheme_location_availability_path(location.scheme, location, referrer: "check_answers") scheme_location_availability_path(location.scheme, location, referrer: "check_answers", route: params[:route])
end end
end end

11
app/helpers/tab_nav_helper.rb

@ -11,17 +11,6 @@ module TabNavHelper
[govuk_link_to(link_text, link, method: :patch), "<span class=\"govuk-visually-hidden\">Location </span><span class=\"govuk-!-font-weight-regular app-!-colour-muted\">#{location.name}</span>"].join("\n") [govuk_link_to(link_text, link, method: :patch), "<span class=\"govuk-visually-hidden\">Location </span><span class=\"govuk-!-font-weight-regular app-!-colour-muted\">#{location.name}</span>"].join("\n")
end end
def location_cell_location_admin_district(location, link)
la = location.location_admin_district
if location.confirmed?
la
elsif la
govuk_link_to(la, link, method: :patch)
else
govuk_link_to("Select local authority", link, method: :patch)
end
end
def scheme_cell(scheme) def scheme_cell(scheme)
link_text = scheme.service_name link_text = scheme.service_name
link = scheme.confirmed? ? scheme : scheme_check_answers_path(scheme) link = scheme.confirmed? ? scheme : scheme_check_answers_path(scheme)

6
app/views/locations/availability.erb

@ -3,11 +3,11 @@
<% content_for :before_content do %> <% content_for :before_content do %>
<%= govuk_back_link( <%= govuk_back_link(
text: "Back", text: "Back",
href: params[:referrer] == "check_answers" ? scheme_location_check_answers_path(@scheme, @location) : scheme_location_mobility_standards_path(@scheme, @location, referrer: params[:referrer]), href: params[:referrer] == "check_answers" ? scheme_location_check_answers_path(@scheme, @location, route: params[:route]) : scheme_location_mobility_standards_path(@scheme, @location, route: params[:route]),
) %> ) %>
<% end %> <% end %>
<%= form_for(@location, method: :patch, url: scheme_location_availability_path(@scheme, @location, referrer: params[:referrer])) do |f| %> <%= form_for(@location, method: :patch, url: scheme_location_availability_path(@scheme, @location, route: params[:route], referrer: params[:referrer])) do |f| %>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<%= f.govuk_error_summary %> <%= f.govuk_error_summary %>
@ -22,7 +22,7 @@
<div class="govuk-button-group"> <div class="govuk-button-group">
<% if params[:referrer] == "check_answers" %> <% if params[:referrer] == "check_answers" %>
<%= f.govuk_submit "Save changes" %> <%= f.govuk_submit "Save changes" %>
<%= govuk_button_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location), secondary: true %> <%= govuk_button_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location, route: params[:route]), secondary: true %>
<% else %> <% else %>
<%= f.govuk_submit "Save and continue" %> <%= f.govuk_submit "Save and continue" %>
<%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %> <%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %>

8
app/views/locations/check_answers.html.erb

@ -4,9 +4,7 @@
<% content_for :before_content do %> <% content_for :before_content do %>
<%= govuk_back_link( <%= govuk_back_link(
text: "Back", text: "Back",
href: case params[:referrer] href: case params[:route]
when "new_scheme"
scheme_location_availability_path(@scheme, @location, referrer: params[:referrer])
when "locations" when "locations"
scheme_locations_path(@scheme) scheme_locations_path(@scheme)
else else
@ -15,7 +13,7 @@
) %> ) %>
<% end %> <% end %>
<%= form_for(@location, method: :patch, url: scheme_location_check_answers_path(@scheme, @location)) do |f| %> <%= form_for(@location, method: :patch, url: scheme_location_check_answers_path(@scheme, @location, route: params[:route])) do |f| %>
<%= render partial: "organisations/headings", locals: { main: "Check your answers", sub: "Add a location to #{@scheme.service_name}" } %> <%= render partial: "organisations/headings", locals: { main: "Check your answers", sub: "Add a location to #{@scheme.service_name}" } %>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
@ -35,7 +33,7 @@
details_html(attr) details_html(attr)
end %> end %>
<% end %> <% end %>
<% row.action(text: "Change", href: location_edit_path(@location, attr[:attribute])) unless attr[:name] == "Status" %> <% row.action(text: attr[:value].blank? || (attr[:attribute] == "availability" && @location.startdate.blank?) ? "Answer" : "Change", href: location_edit_path(@location, attr[:attribute])) unless attr[:attribute] == "status" %>
<% end %> <% end %>
<% end %> <% end %>
<% end %> <% end %>

4
app/views/locations/index.html.erb

@ -52,11 +52,11 @@
<%= table.body do |body| %> <%= table.body do |body| %>
<%= body.row do |row| %> <%= body.row do |row| %>
<% row.cell(text: location.id) %> <% row.cell(text: location.id) %>
<% row.cell(text: simple_format(location_cell_postcode(location, location.confirmed ? scheme_location_path(@scheme, location) : scheme_location_check_answers_path(@scheme, location, referrer: "locations")), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %> <% row.cell(text: simple_format(location_cell_postcode(location, location.confirmed ? scheme_location_path(@scheme, location) : scheme_location_check_answers_path(@scheme, location, route: "locations")), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
<% row.cell(text: location.units) %> <% row.cell(text: location.units) %>
<% row.cell(text: simple_format("<span>#{location.type_of_unit}</span>")) %> <% row.cell(text: simple_format("<span>#{location.type_of_unit}</span>")) %>
<% row.cell(text: location.mobility_type) %> <% row.cell(text: location.mobility_type) %>
<% row.cell(text: simple_format(location_cell_location_admin_district(location, "/schemes/#{@scheme.id}/locations/#{location.id}/edit-local-authority"), wrapper_tag: "div")) %> <% row.cell(text: location.location_admin_district) %>
<% row.cell(text: location.startdate&.to_formatted_s(:govuk_date)) %> <% row.cell(text: location.startdate&.to_formatted_s(:govuk_date)) %>
<% end %> <% end %>
<% end %> <% end %>

13
app/views/locations/local_authority.html.erb

@ -3,11 +3,16 @@
<% content_for :before_content do %> <% content_for :before_content do %>
<%= govuk_back_link( <%= govuk_back_link(
text: "Back", text: "Back",
href: params[:referrer] == "check_answers" ? scheme_location_check_answers_path(@scheme, @location) : scheme_location_postcode_path(@scheme, @location, referrer: params[:referrer]), href: case params[:referrer]
when "check_local_authority"
scheme_location_check_answers_path(@scheme, @location, route: params[:route])
else
scheme_location_postcode_path(@scheme, @location, route: params[:route], referrer: params[:referrer])
end
) %> ) %>
<% end %> <% end %>
<%= form_for(@location, method: :patch, url: scheme_location_local_authority_path(@scheme, @location, referrer: params[:referrer])) do |f| %> <%= form_for(@location, method: :patch, url: scheme_location_local_authority_path(@scheme, @location, route: params[:route], referrer: params[:referrer])) do |f| %>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<%= f.govuk_error_summary %> <%= f.govuk_error_summary %>
@ -22,9 +27,9 @@
"data-controller": %w[conditional-filter accessible-autocomplete] %> "data-controller": %w[conditional-filter accessible-autocomplete] %>
<div class="govuk-button-group"> <div class="govuk-button-group">
<% if params[:referrer] == "check_answers" %> <% if params[:referrer] == "check_answers" || params[:referrer] == "check_local_authority"%>
<%= f.govuk_submit "Save changes" %> <%= f.govuk_submit "Save changes" %>
<%= govuk_button_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location), secondary: true %> <%= govuk_button_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location, route: params[:route]), secondary: true %>
<% else %> <% else %>
<%= f.govuk_submit "Save and continue" %> <%= f.govuk_submit "Save and continue" %>
<%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %> <%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %>

6
app/views/locations/mobility_standards.html.erb

@ -3,11 +3,11 @@
<% content_for :before_content do %> <% content_for :before_content do %>
<%= govuk_back_link( <%= govuk_back_link(
text: "Back", text: "Back",
href: params[:referrer] == "check_answers" ? scheme_location_check_answers_path(@scheme, @location) : scheme_location_type_of_unit_path(@scheme, @location, referrer: params[:referrer]), href: params[:referrer] == "check_answers" ? scheme_location_check_answers_path(@scheme, @location, route: params[:route]) : scheme_location_type_of_unit_path(@scheme, @location, route: params[:route]),
) %> ) %>
<% end %> <% end %>
<%= form_for(@location, method: :patch, url: scheme_location_mobility_standards_path(@scheme, @location, referrer: params[:referrer])) do |f| %> <%= form_for(@location, method: :patch, url: scheme_location_mobility_standards_path(@scheme, @location, route: params[:route], referrer: params[:referrer])) do |f| %>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<%= f.govuk_error_summary %> <%= f.govuk_error_summary %>
@ -24,7 +24,7 @@
<div class="govuk-button-group"> <div class="govuk-button-group">
<% if params[:referrer] == "check_answers" %> <% if params[:referrer] == "check_answers" %>
<%= f.govuk_submit "Save changes" %> <%= f.govuk_submit "Save changes" %>
<%= govuk_button_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location), secondary: true %> <%= govuk_button_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location, route: params[:route]), secondary: true %>
<% else %> <% else %>
<%= f.govuk_submit "Save and continue" %> <%= f.govuk_submit "Save and continue" %>
<%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %> <%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %>

10
app/views/locations/name.html.erb

@ -4,14 +4,16 @@
<%= govuk_back_link( <%= govuk_back_link(
text: "Back", text: "Back",
href: if params[:referrer] == "check_answers" href: if params[:referrer] == "check_answers"
scheme_location_check_answers_path(@scheme, @location) scheme_location_check_answers_path(@scheme, @location, route: params[:route])
elsif params[:referrer] == "details"
scheme_location_path(@scheme, @location)
else else
params[:referrer] == "details" ? scheme_location_path(@scheme, @location) : scheme_location_postcode_path(@scheme, @location, referrer: params[:referrer]) scheme_location_postcode_path(@scheme, @location, route: params[:route])
end, end,
) %> ) %>
<% end %> <% end %>
<%= form_for(@location, method: :patch, url: scheme_location_name_path(@scheme, @location, referrer: params[:referrer])) do |f| %> <%= form_for(@location, method: :patch, url: scheme_location_name_path(@scheme, @location, route: params[:route], referrer: params[:referrer])) do |f| %>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<%= f.govuk_error_summary %> <%= f.govuk_error_summary %>
@ -25,7 +27,7 @@
<div class="govuk-button-group"> <div class="govuk-button-group">
<% if params[:referrer] == "check_answers" %> <% if params[:referrer] == "check_answers" %>
<%= f.govuk_submit "Save changes" %> <%= f.govuk_submit "Save changes" %>
<%= govuk_button_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location), secondary: true %> <%= govuk_button_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location, route: params[:route]), secondary: true %>
<% elsif params[:referrer] == "details" %> <% elsif params[:referrer] == "details" %>
<%= f.govuk_submit "Save changes" %> <%= f.govuk_submit "Save changes" %>
<%= govuk_button_link_to "Cancel", scheme_location_path(@scheme, @location), secondary: true %> <%= govuk_button_link_to "Cancel", scheme_location_path(@scheme, @location), secondary: true %>

11
app/views/locations/postcode.html.erb

@ -3,18 +3,15 @@
<% content_for :before_content do %> <% content_for :before_content do %>
<%= govuk_back_link( <%= govuk_back_link(
text: "Back", text: "Back",
href: case params[:referrer] href: if params[:referrer] == "check_answers"
when "check_answers" scheme_location_check_answers_path(@scheme, @location, route: params[:route])
scheme_location_check_answers_path(@scheme, @location)
when "new_scheme"
scheme_support_path(@scheme)
else else
scheme_locations_path(@scheme) scheme_locations_path(@scheme)
end end
) %> ) %>
<% end %> <% end %>
<%= form_for(@location, method: :patch, url: scheme_location_postcode_path(@scheme, @location, referrer: params[:referrer])) do |f| %> <%= form_for(@location, method: :patch, url: scheme_location_postcode_path(@scheme, @location, route: params[:route], referrer: params[:referrer])) do |f| %>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<%= f.govuk_error_summary %> <%= f.govuk_error_summary %>
@ -29,7 +26,7 @@
<div class="govuk-button-group"> <div class="govuk-button-group">
<% if params[:referrer] == "check_answers" %> <% if params[:referrer] == "check_answers" %>
<%= f.govuk_submit "Save changes" %> <%= f.govuk_submit "Save changes" %>
<%= govuk_button_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location), secondary: true %> <%= govuk_button_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location, route: params[:route]), secondary: true %>
<% else %> <% else %>
<%= f.govuk_submit "Save and continue" %> <%= f.govuk_submit "Save and continue" %>
<%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %> <%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %>

6
app/views/locations/type_of_unit.html.erb

@ -3,11 +3,11 @@
<% content_for :before_content do %> <% content_for :before_content do %>
<%= govuk_back_link( <%= govuk_back_link(
text: "Back", text: "Back",
href: params[:referrer] == "check_answers" ? scheme_location_check_answers_path(@scheme, @location) : scheme_location_units_path(@scheme, @location, referrer: params[:referrer]), href: params[:referrer] == "check_answers" ? scheme_location_check_answers_path(@scheme, @location, route: params[:route]) : scheme_location_units_path(@scheme, @location, route: params[:route]),
) %> ) %>
<% end %> <% end %>
<%= form_for(@location, method: :patch, url: scheme_location_type_of_unit_path(@scheme, @location, referrer: params[:referrer])) do |f| %> <%= form_for(@location, method: :patch, url: scheme_location_type_of_unit_path(@scheme, @location, route: params[:route], referrer: params[:referrer])) do |f| %>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<%= f.govuk_error_summary %> <%= f.govuk_error_summary %>
@ -23,7 +23,7 @@
<div class="govuk-button-group"> <div class="govuk-button-group">
<% if params[:referrer] == "check_answers" %> <% if params[:referrer] == "check_answers" %>
<%= f.govuk_submit "Save changes" %> <%= f.govuk_submit "Save changes" %>
<%= govuk_button_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location), secondary: true %> <%= govuk_button_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location, route: params[:route]), secondary: true %>
<% else %> <% else %>
<%= f.govuk_submit "Save and continue" %> <%= f.govuk_submit "Save and continue" %>
<%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %> <%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %>

6
app/views/locations/units.html.erb

@ -3,11 +3,11 @@
<% content_for :before_content do %> <% content_for :before_content do %>
<%= govuk_back_link( <%= govuk_back_link(
text: "Back", text: "Back",
href: params[:referrer] == "check_answers" ? scheme_location_check_answers_path(@scheme, @location) : scheme_location_name_path(@scheme, @location, referrer: params[:referrer]), href: params[:referrer] == "check_answers" ? scheme_location_check_answers_path(@scheme, @location, route: params[:route]) : scheme_location_name_path(@scheme, @location, route: params[:route]),
) %> ) %>
<% end %> <% end %>
<%= form_for(@location, method: :patch, url: scheme_location_units_path(@scheme, @location, referrer: params[:referrer])) do |f| %> <%= form_for(@location, method: :patch, url: scheme_location_units_path(@scheme, @location, route: params[:route], referrer: params[:referrer])) do |f| %>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<%= f.govuk_error_summary %> <%= f.govuk_error_summary %>
@ -23,7 +23,7 @@
<div class="govuk-button-group"> <div class="govuk-button-group">
<% if params[:referrer] == "check_answers" %> <% if params[:referrer] == "check_answers" %>
<%= f.govuk_submit "Save changes" %> <%= f.govuk_submit "Save changes" %>
<%= govuk_button_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location), secondary: true %> <%= govuk_button_link_to "Cancel", scheme_location_check_answers_path(@scheme, @location, route: params[:route]), secondary: true %>
<% else %> <% else %>
<%= f.govuk_submit "Save and continue" %> <%= f.govuk_submit "Save and continue" %>
<%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %> <%= govuk_button_link_to "Cancel", scheme_locations_path(@scheme), secondary: true %>

47
app/views/schemes/check_answers.html.erb

@ -33,53 +33,6 @@
<% end %> <% end %>
</dl> </dl>
<% end %> <% end %>
<% component.tab(label: "Locations") do %>
<h2 class="govuk-visually-hidden">Locations</h2>
<%= govuk_table do |table| %>
<%= table.caption(classes: %w[govuk-!-font-size-19 govuk-!-font-weight-regular]) do |caption| %>
<strong><%= @scheme.locations.count %></strong> <%= @scheme.locations.count.eql?(1) ? "location" : "locations" %>
<% end %>
<%= table.head do |head| %>
<%= head.row do |row| %>
<% row.cell(header: true, text: "Code", html_attributes: {
scope: "col",
}) %>
<% row.cell(header: true, text: "Postcode", html_attributes: {
scope: "col",
}) %>
<% row.cell(header: true, text: "Units", html_attributes: {
scope: "col",
}) %>
<% row.cell(header: true, text: "Common unit type", html_attributes: {
scope: "col",
}) %>
<% row.cell(header: true, text: "Mobility type", html_attributes: {
scope: "col",
}) %>
<% row.cell(header: true, text: "Local authority", html_attributes: {
scope: "col",
}) %>
<% row.cell(header: true, text: "Available from", html_attributes: {
scope: "col",
}) %>
<% end %>
<% end %>
<% @scheme.locations.each do |location| %>
<%= table.body do |body| %>
<%= body.row do |row| %>
<% row.cell(text: location.id) %>
<% row.cell(text: simple_format(location_cell_postcode(location, get_location_change_link_href_postcode(@scheme, location)), { class: "govuk-!-font-weight-bold" }, wrapper_tag: "div")) %>
<% row.cell(text: location.units) %>
<% row.cell(text: simple_format("<span>#{location.type_of_unit}</span>")) %>
<% row.cell(text: location.mobility_type) %>
<% row.cell(text: simple_format(location_cell_location_admin_district(location, get_location_change_link_href_location_admin_district(@scheme, location)), wrapper_tag: "div")) %>
<% row.cell(text: location_availability(location)) %>
<% end %>
<% end %>
<% end %>
<% end %>
<%= govuk_button_link_to "Add a location", new_scheme_location_path(scheme_id: @scheme.id), secondary: true %>
<% end %>
<% end %> <% end %>
<%= f.hidden_field :page, value: "check-answers" %> <%= f.hidden_field :page, value: "check-answers" %>
<%= f.hidden_field :confirmed, value: "true" %> <%= f.hidden_field :confirmed, value: "true" %>

28
spec/features/schemes_spec.rb

@ -258,7 +258,7 @@ RSpec.describe "Schemes scheme Features" do
end end
it "shows the new location form" do it "shows the new location form" do
expect(page).to have_content("Add a location to this scheme") expect(page).to have_content("Add a location to #{scheme.service_name}")
end end
context "when the user completes the new location form" do context "when the user completes the new location form" do
@ -456,7 +456,7 @@ RSpec.describe "Schemes scheme Features" do
end end
it "lets me add location" do it "lets me add location" do
expect(page).to have_content "Add a location to FooBar" expect(page).to have_content "Add a location to #{scheme.service_name}"
end end
it "lets me navigate back to support questions" do it "lets me navigate back to support questions" do
@ -817,7 +817,7 @@ RSpec.describe "Schemes scheme Features" do
assert_selector "a", text: "Change", count: 1 assert_selector "a", text: "Change", count: 1
click_link("Change") click_link("Change")
expect(page).to have_content "Location name for #{location.postcode}" expect(page).to have_content "What is the name of this location?"
end end
it "allows to deactivate a location" do it "allows to deactivate a location" do
@ -843,7 +843,7 @@ RSpec.describe "Schemes scheme Features" do
it "returns to locations check your answers page and shows the new name" do it "returns to locations check your answers page and shows the new name" do
fill_in "location-name-field", with: "NewName" fill_in "location-name-field", with: "NewName"
click_button "Save and continue" click_button "Save changes"
expect(page).to have_content location.postcode expect(page).to have_content location.postcode
expect(page).to have_content "NewName" expect(page).to have_content "NewName"
expect(page).to have_current_path("/schemes/#{scheme.id}/locations/#{location.id}") expect(page).to have_current_path("/schemes/#{scheme.id}/locations/#{location.id}")
@ -909,24 +909,32 @@ RSpec.describe "Schemes scheme Features" do
end end
it "shows the new location form" do it "shows the new location form" do
expect(page).to have_content("Add a location to this scheme") expect(page).to have_content("Add a location to #{scheme.service_name}")
end end
context "when the user completes the new location form" do context "when the user completes the new location form" do
let(:location_name) { "Area 42" } let(:location_name) { "Area 42" }
before do before do
fill_in "Postcode", with: "NW1L 5DP" fill_in with: "NW1L 5DP"
fill_in "Location name (optional)", with: location_name click_button "Save and continue"
fill_in "Total number of units at this location", with: 1 fill_in with: location_name
click_button "Save and continue"
fill_in with: "Adur"
fill_in with: 1
click_button "Save and continue"
choose "Bungalow" choose "Bungalow"
click_button "Save and continue"
choose "location-mobility-type-none-field" choose "location-mobility-type-none-field"
choose "location-add-another-location-no-field" click_button "Save and continue"
fill_in "Day", with: 2
fill_in "Month", with: 2
fill_in "Year", with: 2022
click_button "Save and continue" click_button "Save and continue"
end end
it "shows the check answers page location tab" do it "shows the check answers page location tab" do
expect(page.current_url.split("/").last).to eq("check-answers#locations") expect(page.current_url.split("/").last).to eq("check-answers")
expect(page).to have_content(location_name) expect(page).to have_content(location_name)
end end

Loading…
Cancel
Save