Browse Source

Cldc 1307 supported housing scheme locations (#669)

* failing test for having service and location tabs on the show page

* links on the page

* asking for locations in the link

* created locations

* linked locations to schemes

* locations migration and model

* testing seeing locations

* rubocop

* failing feature to see locations on the page

* route to locations

* controller action plus other bits

* added facatory and view for locations

* supported housing to schemes

* supported housing to schemes - part 2

* supported housing to schemes - part 3

* correct route

* controller test for locations

* added view for locations

* correct and compact view for locations

* testing all attributes on the page

* testing heading

* testing title

* refactored views

* refactored views

* fixed county

* testing pagination

* testing and coding pagy bits for locations

* testing and coding pagy bits for locations page 2

* added tests for support user

* small refactoring of before actions and tests for 401 and 404

* small refactoring

* Trigger WF

* simplified return

* fixing spec failures

* fixed names

* testing back link

* oops

* required changes from comments

* required changes from comments

* renums

* fixed failing tests

* typo

* Managing agent to by

* tests for scheme_items
pull/670/head
J G 3 years ago committed by GitHub
parent
commit
0c4a81ea7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      app/components/primary_navigation_component.rb
  2. 18
      app/controllers/schemes_controller.rb
  3. 21
      app/helpers/navigation_items_helper.rb
  4. 20
      app/models/location.rb
  5. 5
      app/models/scheme.rb
  6. 6
      app/views/organisations/schemes.html.erb
  7. 4
      app/views/schemes/_scheme_list.html.erb
  8. 6
      app/views/schemes/index.html.erb
  9. 41
      app/views/schemes/locations.html.erb
  10. 12
      app/views/schemes/show.html.erb
  11. 8
      config/routes.rb
  12. 17
      db/migrate/20220614124115_create_locations.rb
  13. 18
      db/schema.rb
  14. 40
      db/seeds.rb
  15. 8
      spec/components/primary_navigation_component_spec.rb
  16. 13
      spec/factories/location.rb
  17. 2
      spec/factories/scheme.rb
  18. 61
      spec/features/schemes_spec.rb
  19. 85
      spec/helpers/navigation_items_helper_spec.rb
  20. 2
      spec/helpers/tab_nav_helper_spec.rb
  21. 26
      spec/requests/organisations_controller_spec.rb
  22. 235
      spec/requests/schemes_controller_spec.rb

2
app/components/primary_navigation_component.rb

@ -3,7 +3,7 @@ class PrimaryNavigationComponent < ViewComponent::Base
def initialize(items:) def initialize(items:)
@items = items @items = items
FeatureToggle.supported_housing_schemes_enabled? ? @items : @items.reject! { |nav_item| nav_item.text.include?("Supported housing") } FeatureToggle.supported_housing_schemes_enabled? ? @items : @items.reject! { |nav_item| nav_item.text.include?("Schemes") }
super super
end end

18
app/controllers/schemes_controller.rb

@ -3,10 +3,11 @@ class SchemesController < ApplicationController
include Modules::SearchFilter include Modules::SearchFilter
before_action :authenticate_user! before_action :authenticate_user!
before_action :find_resource, except: %i[index]
before_action :authenticate_scope! before_action :authenticate_scope!
def index def index
redirect_to supported_housing_organisation_path(current_user.organisation) unless current_user.support? redirect_to schemes_organisation_path(current_user.organisation) unless current_user.support?
all_schemes = Scheme.all all_schemes = Scheme.all
@pagy, @schemes = pagy(filtered_collection(all_schemes, search_term)) @pagy, @schemes = pagy(filtered_collection(all_schemes, search_term))
@ -16,7 +17,12 @@ class SchemesController < ApplicationController
def show def show
@scheme = Scheme.find_by(id: params[:id]) @scheme = Scheme.find_by(id: params[:id])
render_not_found and return unless (current_user.organisation == @scheme.organisation) || current_user.support? end
def locations
@scheme = Scheme.find_by(id: params[:id])
@pagy, @locations = pagy(@scheme.locations)
@total_count = @scheme.locations.size
end end
private private
@ -25,7 +31,15 @@ private
params["search"] params["search"]
end end
def find_resource
@scheme = Scheme.find_by(id: params[:id])
end
def authenticate_scope! def authenticate_scope!
head :unauthorized and return unless current_user.data_coordinator? || current_user.support? head :unauthorized and return unless current_user.data_coordinator? || current_user.support?
if %w[show locations].include?(action_name) && !((current_user.organisation == @scheme.organisation) || current_user.support?)
render_not_found and return
end
end end
end end

21
app/helpers/navigation_items_helper.rb

@ -7,12 +7,12 @@ module NavigationItemsHelper
NavigationItem.new("Organisations", organisations_path, organisations_current?(path)), NavigationItem.new("Organisations", organisations_path, organisations_current?(path)),
NavigationItem.new("Users", "/users", users_current?(path)), NavigationItem.new("Users", "/users", users_current?(path)),
NavigationItem.new("Logs", case_logs_path, logs_current?(path)), NavigationItem.new("Logs", case_logs_path, logs_current?(path)),
NavigationItem.new("Supported housing", "/supported-housing", supported_housing_current?(path)), NavigationItem.new("Schemes", "/schemes", supported_housing_schemes_current?(path)),
] ]
elsif current_user.data_coordinator? elsif current_user.data_coordinator?
[ [
NavigationItem.new("Logs", case_logs_path, logs_current?(path)), NavigationItem.new("Logs", case_logs_path, logs_current?(path)),
NavigationItem.new("Supported housing", "/supported-housing", subnav_supported_housing_path?(path)), NavigationItem.new("Schemes", "/schemes", subnav_supported_housing_schemes_path?(path)),
NavigationItem.new("Users", users_organisation_path(current_user.organisation), subnav_users_path?(path)), NavigationItem.new("Users", users_organisation_path(current_user.organisation), subnav_users_path?(path)),
NavigationItem.new("About your organisation", "/organisations/#{current_user.organisation.id}", subnav_details_path?(path)), NavigationItem.new("About your organisation", "/organisations/#{current_user.organisation.id}", subnav_details_path?(path)),
] ]
@ -28,12 +28,19 @@ module NavigationItemsHelper
def secondary_items(path, current_organisation_id) def secondary_items(path, current_organisation_id)
[ [
NavigationItem.new("Logs", "/organisations/#{current_organisation_id}/logs", subnav_logs_path?(path)), NavigationItem.new("Logs", "/organisations/#{current_organisation_id}/logs", subnav_logs_path?(path)),
NavigationItem.new("Supported housing", "/organisations/#{current_organisation_id}/supported-housing", subnav_supported_housing_path?(path)), NavigationItem.new("Schemes", "/organisations/#{current_organisation_id}/schemes", subnav_supported_housing_schemes_path?(path)),
NavigationItem.new("Users", "/organisations/#{current_organisation_id}/users", subnav_users_path?(path)), NavigationItem.new("Users", "/organisations/#{current_organisation_id}/users", subnav_users_path?(path)),
NavigationItem.new("About this organisation", "/organisations/#{current_organisation_id}", subnav_details_path?(path)), NavigationItem.new("About this organisation", "/organisations/#{current_organisation_id}", subnav_details_path?(path)),
] ]
end end
def scheme_items(path, current_scheme_id, title)
[
NavigationItem.new("Scheme", "/schemes/#{current_scheme_id}", !path.include?("locations")),
NavigationItem.new(title, "/schemes/#{current_scheme_id}/locations", path.include?("locations")),
]
end
private private
def logs_current?(path) def logs_current?(path)
@ -44,16 +51,16 @@ private
path == "/users" || path.include?("/users/") path == "/users" || path.include?("/users/")
end end
def supported_housing_current?(path) def supported_housing_schemes_current?(path)
path == "/supported-housing" || path.include?("/supported-housing/") path == "/schemes" || path.include?("/schemes/")
end end
def organisations_current?(path) def organisations_current?(path)
path == "/organisations" || path.include?("/organisations/") path == "/organisations" || path.include?("/organisations/")
end end
def subnav_supported_housing_path?(path) def subnav_supported_housing_schemes_path?(path)
path.include?("/organisations") && path.include?("/supported-housing") || path.include?("/supported-housing/") path.include?("/organisations") && path.include?("/schemes") || path.include?("/schemes/")
end end
def subnav_users_path?(path) def subnav_users_path?(path)

20
app/models/location.rb

@ -0,0 +1,20 @@
class Location < ApplicationRecord
belongs_to :scheme
WHEELCHAIR_ADAPTATIONS = {
no: 0,
yes: 1,
}.freeze
enum wheelchair_adaptation: WHEELCHAIR_ADAPTATIONS
def display_attributes
[
{ name: "Location code ", value: location_code, suffix: false },
{ name: "Postcode", value: postcode, suffix: county },
{ name: "Type of unit", value: type_of_unit, suffix: false },
{ name: "Type of building", value: type_of_building, suffix: false },
{ name: "Wheelchair adaptation", value: wheelchair_adaptation, suffix: false },
]
end
end

5
app/models/scheme.rb

@ -1,5 +1,6 @@
class Scheme < ApplicationRecord class Scheme < ApplicationRecord
belongs_to :organisation belongs_to :organisation
has_many :locations
scope :search_by_code, ->(code) { where("code ILIKE ?", "%#{code}%") } scope :search_by_code, ->(code) { where("code ILIKE ?", "%#{code}%") }
scope :search_by_service_name, ->(name) { where("service_name ILIKE ?", "%#{name}%") } scope :search_by_service_name, ->(name) { where("service_name ILIKE ?", "%#{name}%") }
@ -66,8 +67,8 @@ class Scheme < ApplicationRecord
{ name: "Service code", value: code }, { name: "Service code", value: code },
{ name: "Name", value: service_name }, { name: "Name", value: service_name },
{ name: "Confidential information", value: sensitive_display }, { name: "Confidential information", value: sensitive_display },
{ name: "Managing agent", value: organisation.name }, { name: "Managing by", value: organisation.name },
{ name: "Type of service", value: scheme_type_display }, { name: "Type of scheme", value: scheme_type_display },
{ name: "Registered under Care Standards Act 2000", value: registered_under_care_act_display }, { name: "Registered under Care Standards Act 2000", value: registered_under_care_act_display },
{ name: "Total number of units", value: total_units }, { name: "Total number of units", value: total_units },
{ name: "Primary client group", value: primary_client_group_display }, { name: "Primary client group", value: primary_client_group_display },

6
app/views/organisations/schemes.html.erb

@ -1,9 +1,9 @@
<% item_label = format_label(@pagy.count, "scheme") %> <% item_label = format_label(@pagy.count, "scheme") %>
<% title = format_title(@searched, "Supported housing services", current_user, item_label, @pagy.count, @organisation.name) %> <% title = format_title(@searched, "Supported housing schemes", current_user, item_label, @pagy.count, @organisation.name) %>
<% content_for :title, title %> <% content_for :title, title %>
<%= render partial: "organisations/headings", locals: current_user.support? ? { main: @organisation.name, sub: nil } : { main: "Supported housing services", sub: current_user.organisation.name } %> <%= render partial: "organisations/headings", locals: current_user.support? ? { main: @organisation.name, sub: nil } : { main: "Schemes", sub: current_user.organisation.name } %>
<% if current_user.support? %> <% if current_user.support? %>
<%= render SubNavigationComponent.new( <%= render SubNavigationComponent.new(
@ -11,7 +11,7 @@
) %> ) %>
<% end %> <% end %>
<h2 class="govuk-visually-hidden">Supported housing services</h2> <h2 class="govuk-visually-hidden">Supported housing schemes</h2>
<%= render SearchComponent.new(current_user:, search_label: "Search by service name or code", value: @searched) %> <%= render SearchComponent.new(current_user:, search_label: "Search by service name or code", value: @searched) %>

4
app/views/schemes/_scheme_list.html.erb

@ -14,10 +14,10 @@
<% row.cell(header: true, text: "Code", html_attributes: { <% row.cell(header: true, text: "Code", html_attributes: {
scope: "col", scope: "col",
}) %> }) %>
<% row.cell(header: true, text: "Service", html_attributes: { <% row.cell(header: true, text: "Scheme", html_attributes: {
scope: "col", scope: "col",
}) %> }) %>
<% row.cell(header: true, text: "Managing agent", html_attributes: { <% row.cell(header: true, text: "Managed by", html_attributes: {
scope: "col", scope: "col",
}) %> }) %>
<% row.cell(header: true, text: "Created", html_attributes: { <% row.cell(header: true, text: "Created", html_attributes: {

6
app/views/schemes/index.html.erb

@ -1,11 +1,11 @@
<% item_label = format_label(@pagy.count, "scheme") %> <% item_label = format_label(@pagy.count, "scheme") %>
<% title = format_title(@searched, "Supported housing services", current_user, item_label, @pagy.count, nil) %> <% title = format_title(@searched, "Supported housing schemes", current_user, item_label, @pagy.count, nil) %>
<% content_for :title, title %> <% content_for :title, title %>
<%= render partial: "organisations/headings", locals: current_user.support? ? { main: "Supported housing services", sub: nil } : { main: "Supported housing services", sub: current_user.organisation.name } %> <%= render partial: "organisations/headings", locals: current_user.support? ? { main: "Supported housing schemes", sub: nil } : { main: "Supported housing schemes", sub: current_user.organisation.name } %>
<h2 class="govuk-visually-hidden">Supported housing services</h2> <h2 class="govuk-visually-hidden">Supported housing schemes</h2>
<%= render SearchComponent.new(current_user:, search_label: "Search by service name or code", value: @searched) %> <%= render SearchComponent.new(current_user:, search_label: "Search by service name or code", value: @searched) %>

41
app/views/schemes/locations.html.erb

@ -0,0 +1,41 @@
<% title = @scheme.service_name %>
<% content_for :title, title %>
<%= govuk_back_link(href: request.referer.to_s) %>
<%= render partial: "organisations/headings", locals: { main: @scheme.service_name, sub: nil } %>
<%= render SubNavigationComponent.new(items: scheme_items(request.path, @scheme.id, @scheme.locations.count.eql?(1) ? "1 location" : "#{@scheme.locations.count} locations")) %>
<div class="govuk-grid-row">
<div class="govuk-grid-column-three-quarters">
<% @locations.each do |location| %>
<section class="x-govuk-summary-card govuk-!-margin-bottom-6">
<header class="x-govuk-summary-card__header">
<h2 class="x-govuk-summary-card__title">
<%= "#{location.address_line1}, #{location.address_line2}" %>
</h2>
</header>
<div class="x-govuk-summary-card__body">
<dl class="govuk-summary-list">
<% location.display_attributes.each do |attribute| %>
<div class="govuk-summary-list__row">
<dt class="govuk-summary-list__key">
<%= attribute[:name] %>
</dt>
<dd class="govuk-summary-list__value app-!-font-tabular">
<span class="govuk-!-margin-right-4"><%= attribute[:value] %></span>
<% if attribute[:suffix] %>
<span class="govuk-!-font-weight-regular app-!-colour-muted"><%= attribute[:suffix] %></span>
<% end %>
</dd>
</div>
<% end %>
</dl>
</div>
</section>
<% end %>
</div>
</div>
<%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "locations" } %>

12
app/views/schemes/show.html.erb

@ -1,17 +1,21 @@
<% title = @scheme.service_name %> <% title = @scheme.service_name %>
<% content_for :title, title %> <% content_for :title, title %>
<%= govuk_back_link(href: request.referer.to_s) %>
<%= render partial: "organisations/headings", locals: { main: @scheme.service_name, sub: nil } %> <%= render partial: "organisations/headings", locals: { main: @scheme.service_name, sub: nil } %>
<%= render SubNavigationComponent.new(items: scheme_items(request.path, @scheme.id, @scheme.locations.count.eql?(1) ? "1 location" : "#{@scheme.locations.count} locations")) %>
<div class="govuk-grid-row"> <div class="govuk-grid-row">
<div class="govuk-grid-column-two-thirds"> <div class="govuk-grid-column-two-thirds">
<%= govuk_summary_list do |summary_list| %> <%= govuk_summary_list do |summary_list| %>
<% @scheme.display_attributes.each do |attr| %> <% @scheme.display_attributes.each do |attr| %>
<%= summary_list.row do |row| %> <%= summary_list.row do |row| %>
<% row.key { attr[:name].to_s.humanize } %> <% row.key { attr[:name].eql?("Registered under Care Standards Act 2000") ? "Registered under Care Standards Act 2000" : attr[:name].to_s.humanize } %>
<% row.value { details_html(attr) } %> <% row.value { details_html(attr) } %>
<% end %>
<% end %> <% end %>
<% end %>
<% end %> <% end %>
</div> </div>
</div> </div>

8
config/routes.rb

@ -35,7 +35,11 @@ Rails.application.routes.draw do
get "edit/password", to: "users#edit_password" get "edit/password", to: "users#edit_password"
end end
resources :schemes, path: "/supported-housing", only: %i[index show] resources :schemes, only: %i[index show] do
member do
get "locations", to: "schemes#locations"
end
end
resources :users do resources :users do
member do member do
@ -50,7 +54,7 @@ Rails.application.routes.draw do
get "users", to: "organisations#users" get "users", to: "organisations#users"
get "users/invite", to: "users/account#new" get "users/invite", to: "users/account#new"
get "logs", to: "organisations#logs" get "logs", to: "organisations#logs"
get "supported-housing", to: "organisations#schemes" get "schemes", to: "organisations#schemes"
end end
end end

17
db/migrate/20220614124115_create_locations.rb

@ -0,0 +1,17 @@
class CreateLocations < ActiveRecord::Migration[7.0]
def change
create_table :locations do |t|
t.string :location_code
t.string :postcode
t.string :type_of_unit
t.string :type_of_building
t.integer :wheelchair_adaptation
t.references :scheme, null: false, foreign_key: true
t.string :address_line1
t.string :address_line2
t.string :county
t.timestamps
end
end
end

18
db/schema.rb

@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema[7.0].define(version: 2022_06_13_094847) do ActiveRecord::Schema[7.0].define(version: 2022_06_14_124115) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -230,6 +230,21 @@ ActiveRecord::Schema[7.0].define(version: 2022_06_13_094847) do
t.index ["start_year", "lettype", "beds", "la"], name: "index_la_rent_ranges_on_start_year_and_lettype_and_beds_and_la", unique: true t.index ["start_year", "lettype", "beds", "la"], name: "index_la_rent_ranges_on_start_year_and_lettype_and_beds_and_la", unique: true
end end
create_table "locations", force: :cascade do |t|
t.string "location_code"
t.string "postcode"
t.string "type_of_unit"
t.string "type_of_building"
t.integer "wheelchair_adaptation"
t.bigint "scheme_id", null: false
t.string "address_line1"
t.string "address_line2"
t.string "county"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["scheme_id"], name: "index_locations_on_scheme_id"
end
create_table "logs_exports", force: :cascade do |t| create_table "logs_exports", force: :cascade do |t|
t.datetime "created_at", default: -> { "CURRENT_TIMESTAMP" } t.datetime "created_at", default: -> { "CURRENT_TIMESTAMP" }
t.datetime "started_at", null: false t.datetime "started_at", null: false
@ -347,5 +362,6 @@ ActiveRecord::Schema[7.0].define(version: 2022_06_13_094847) do
t.index ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id" t.index ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id"
end end
add_foreign_key "locations", "schemes"
add_foreign_key "schemes", "organisations" add_foreign_key "schemes", "organisations"
end end

40
db/seeds.rb

@ -70,7 +70,7 @@ unless Rails.env.test?
end end
if Rails.env.development? && Scheme.count.zero? if Rails.env.development? && Scheme.count.zero?
Scheme.create!( scheme1 = Scheme.create!(
code: "S878", code: "S878",
service_name: "Beulahside Care", service_name: "Beulahside Care",
sensitive: 0, sensitive: 0,
@ -85,7 +85,7 @@ unless Rails.env.test?
created_at: Time.zone.now, created_at: Time.zone.now,
) )
Scheme.create!( scheme2 = Scheme.create!(
code: "S312", code: "S312",
service_name: "Abdullahview Point", service_name: "Abdullahview Point",
sensitive: 0, sensitive: 0,
@ -114,6 +114,42 @@ unless Rails.env.test?
organisation: dummy_org, organisation: dummy_org,
created_at: Time.zone.now, created_at: Time.zone.now,
) )
Location.create!(
scheme: scheme1,
location_code: "S254-CU193AA",
postcode: "CU19 3AA",
address_line1: "Rectory Road",
address_line2: "North Chaim",
type_of_unit: "Self-contained flat or bedsit",
type_of_building: "Purpose-built",
county: "Mid Sussex",
wheelchair_adaptation: 0,
)
Location.create!(
scheme: scheme1,
location_code: "S254-DM250DC",
postcode: "DM25 0DC",
address_line1: "Smithy Lane",
address_line2: "North Kellieworth",
type_of_unit: "Self-contained flat or bedsit with common facilities",
type_of_building: "Converted from previous residential or non-residential property",
county: "Fife",
wheelchair_adaptation: 1,
)
Location.create!(
scheme: scheme2,
location_code: "S254-YX130WP",
postcode: "YX13 0WP",
address_line1: "Smithy Lane",
address_line2: "East Darwin",
type_of_unit: "Shared house or hostel",
type_of_building: "Converted from previous residential or non-residential property",
county: "Rochford",
wheelchair_adaptation: 1,
)
end end
pp "Seeded 3 dummy schemes" pp "Seeded 3 dummy schemes"

8
spec/components/primary_navigation_component_spec.rb

@ -6,7 +6,7 @@ RSpec.describe PrimaryNavigationComponent, type: :component do
NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", true), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", true),
NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", false),
NavigationItemsHelper::NavigationItem.new("Logs ", "/logs", false), NavigationItemsHelper::NavigationItem.new("Logs ", "/logs", false),
NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false),
] ]
end end
@ -36,7 +36,7 @@ RSpec.describe PrimaryNavigationComponent, type: :component do
expect(result.text).to include("Organisations") expect(result.text).to include("Organisations")
expect(result.text).to include("Users") expect(result.text).to include("Users")
expect(result.text).to include("Logs") expect(result.text).to include("Logs")
expect(result.text).to include("Supported housing") expect(result.text).to include("Schemes")
end end
end end
@ -45,9 +45,9 @@ RSpec.describe PrimaryNavigationComponent, type: :component do
allow(Rails.env).to receive(:production?).and_return(true) allow(Rails.env).to receive(:production?).and_return(true)
end end
it "doesn't render supported housing" do it "doesn't render schemes" do
result = render_inline(described_class.new(items:)) result = render_inline(described_class.new(items:))
expect(result.text).not_to include("Supported housing") expect(result.text).not_to include("Schemes")
end end
end end
end end

13
spec/factories/location.rb

@ -0,0 +1,13 @@
FactoryBot.define do
factory :location do
location_code { Faker::Name.initials(number: 10) }
postcode { Faker::Address.postcode }
address_line1 { Faker::Address.street_name }
address_line2 { Faker::Address.city }
type_of_unit { Faker::Lorem.word }
type_of_building { Faker::Lorem.word }
wheelchair_adaptation { 0 }
county { Faker::Address.state }
scheme
end
end

2
spec/factories/scheme.rb

@ -1,7 +1,7 @@
FactoryBot.define do FactoryBot.define do
factory :scheme do factory :scheme do
code { Faker::Name.initials(number: 4) } code { Faker::Name.initials(number: 4) }
service_name { Faker::Name.name_with_middle } service_name { Faker::Name.name }
sensitive { Faker::Number.within(range: 0..1) } sensitive { Faker::Number.within(range: 0..1) }
registered_under_care_act { Faker::Number.within(range: 0..1) } registered_under_care_act { Faker::Number.within(range: 0..1) }
support_type { Faker::Number.within(range: 0..6) } support_type { Faker::Number.within(range: 0..6) }

61
spec/features/schemes_spec.rb

@ -1,6 +1,6 @@
require "rails_helper" require "rails_helper"
RSpec.describe "Supported housing scheme Features" do RSpec.describe "Schemes scheme Features" do
context "when viewing list of schemes" do context "when viewing list of schemes" do
context "when I am signed as a support user and there are schemes in the database" do context "when I am signed as a support user and there are schemes in the database" do
let(:user) { FactoryBot.create(:user, :support, last_sign_in_at: Time.zone.now) } let(:user) { FactoryBot.create(:user, :support, last_sign_in_at: Time.zone.now) }
@ -25,13 +25,13 @@ RSpec.describe "Supported housing scheme Features" do
click_button("Submit") click_button("Submit")
end end
it "displays the link to the supported housing" do it "displays the link to the schemes" do
expect(page).to have_link("Supported housing", href: "/supported-housing") expect(page).to have_link("Schemes", href: "/schemes")
end end
context "when I click Supported housing" do context "when I click schemes" do
before do before do
click_link "Supported housing", href: "/supported-housing" click_link "Schemes", href: "/schemes"
end end
it "shows list of schemes" do it "shows list of schemes" do
@ -99,9 +99,9 @@ RSpec.describe "Supported housing scheme Features" do
click_button("Submit") click_button("Submit")
end end
context "when I visit supported housing page" do context "when I visit schemes page" do
before do before do
visit("supported-housing") visit("schemes")
end end
it "shows list of links to schemes" do it "shows list of links to schemes" do
@ -112,8 +112,10 @@ RSpec.describe "Supported housing scheme Features" do
end end
context "when I click to see individual scheme" do context "when I click to see individual scheme" do
let(:scheme) { schemes.first }
before do before do
click_link(schemes.first.service_name) click_link(scheme.service_name)
end end
it "shows me details about the selected scheme" do it "shows me details about the selected scheme" do
@ -128,6 +130,49 @@ RSpec.describe "Supported housing scheme Features" do
expect(page).to have_content(schemes.first.support_type_display) expect(page).to have_content(schemes.first.support_type_display)
expect(page).to have_content(schemes.first.intended_stay_display) expect(page).to have_content(schemes.first.intended_stay_display)
end end
context "when I click to go back" do
before do
visit("schemes")
click_link(scheme.service_name)
end
it "shows list of links to schemes" do
click_on("Back")
schemes.each do |scheme|
expect(page).to have_link(scheme.service_name)
expect(page).to have_content(scheme.primary_client_group_display)
end
end
end
context "when there are locations that belong to the selected scheme" do
let!(:schemes) { FactoryBot.create_list(:scheme, 5) }
let(:scheme) { schemes.first }
let!(:locations) { FactoryBot.create_list(:location, 3, scheme:) }
before do
visit("schemes")
click_link(scheme.service_name)
end
it "shows service and locations tab" do
expect(page).to have_link("Scheme")
expect(page).to have_link("#{scheme.locations.count} locations")
end
context "when I click locations link" do
before do
click_link("#{scheme.locations.count} locations")
end
it "shows details of those locations" do
locations.each do |location|
expect(page).to have_content(location.location_code)
end
end
end
end
end end
end end
end end

85
spec/helpers/navigation_items_helper_spec.rb

@ -12,7 +12,7 @@ RSpec.describe NavigationItemsHelper do
let(:expected_navigation_items) do let(:expected_navigation_items) do
[ [
NavigationItemsHelper::NavigationItem.new("Logs", "/logs", true), NavigationItemsHelper::NavigationItem.new("Logs", "/logs", true),
NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false),
NavigationItemsHelper::NavigationItem.new("Users", users_path, false), NavigationItemsHelper::NavigationItem.new("Users", users_path, false),
NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false), NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false),
] ]
@ -27,7 +27,7 @@ RSpec.describe NavigationItemsHelper do
let(:expected_navigation_items) do let(:expected_navigation_items) do
[ [
NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false), NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false),
NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false),
NavigationItemsHelper::NavigationItem.new("Users", users_path, true), NavigationItemsHelper::NavigationItem.new("Users", users_path, true),
NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false), NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false),
] ]
@ -42,7 +42,7 @@ RSpec.describe NavigationItemsHelper do
let(:expected_navigation_items) do let(:expected_navigation_items) do
[ [
NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false), NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false),
NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false),
NavigationItemsHelper::NavigationItem.new("Users", users_path, false), NavigationItemsHelper::NavigationItem.new("Users", users_path, false),
NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, true), NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, true),
] ]
@ -57,7 +57,7 @@ RSpec.describe NavigationItemsHelper do
let(:expected_navigation_items) do let(:expected_navigation_items) do
[ [
NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false), NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false),
NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false),
NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false),
NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false), NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false),
] ]
@ -72,7 +72,7 @@ RSpec.describe NavigationItemsHelper do
let(:expected_navigation_items) do let(:expected_navigation_items) do
[ [
NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false), NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false),
NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false),
NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", true), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", true),
NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false), NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false),
] ]
@ -87,14 +87,14 @@ RSpec.describe NavigationItemsHelper do
let(:expected_navigation_items) do let(:expected_navigation_items) do
[ [
NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false), NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false),
NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", true), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", true),
NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false),
NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false), NavigationItemsHelper::NavigationItem.new("About your organisation", organisation_path, false),
] ]
end end
it "returns navigation items with supported housing item set as current" do it "returns navigation items with Schemes item set as current" do
expect(primary_items("/supported-housing/1", current_user)).to eq(expected_navigation_items) expect(primary_items("/schemes/1", current_user)).to eq(expected_navigation_items)
end end
end end
end end
@ -108,7 +108,7 @@ RSpec.describe NavigationItemsHelper do
NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false),
NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", false),
NavigationItemsHelper::NavigationItem.new("Logs", "/logs", true), NavigationItemsHelper::NavigationItem.new("Logs", "/logs", true),
NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false),
] ]
end end
@ -123,7 +123,7 @@ RSpec.describe NavigationItemsHelper do
NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false),
NavigationItemsHelper::NavigationItem.new("Users", "/users", true), NavigationItemsHelper::NavigationItem.new("Users", "/users", true),
NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false), NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false),
NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false),
] ]
end end
@ -138,7 +138,7 @@ RSpec.describe NavigationItemsHelper do
NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false),
NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", false),
NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false), NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false),
NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false),
] ]
end end
@ -147,18 +147,18 @@ RSpec.describe NavigationItemsHelper do
end end
end end
context "when the user is on the supported housing page" do context "when the user is on the Schemes page" do
let(:expected_navigation_items) do let(:expected_navigation_items) do
[ [
NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false),
NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", false),
NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false), NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false),
NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", true), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", true),
] ]
end end
it "returns navigation items with the users item set as current" do it "returns navigation items with the users item set as current" do
expect(primary_items("/supported-housing", current_user)).to eq(expected_navigation_items) expect(primary_items("/schemes", current_user)).to eq(expected_navigation_items)
end end
end end
@ -168,7 +168,7 @@ RSpec.describe NavigationItemsHelper do
NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false),
NavigationItemsHelper::NavigationItem.new("Users", "/users", true), NavigationItemsHelper::NavigationItem.new("Users", "/users", true),
NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false), NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false),
NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false),
] ]
end end
@ -183,12 +183,43 @@ RSpec.describe NavigationItemsHelper do
NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false),
NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", false),
NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false), NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false),
NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", true), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", true),
] ]
end end
it "returns navigation items with supported housing item set as current" do let(:expected_scheme_items) do
expect(primary_items("/supported-housing/1", current_user)).to eq(expected_navigation_items) [
NavigationItemsHelper::NavigationItem.new("Scheme", "/schemes/1", true),
NavigationItemsHelper::NavigationItem.new("1 location", "/schemes/1/locations", false),
]
end
it "returns navigation items with Schemes item set as current" do
expect(primary_items("/schemes/1", current_user)).to eq(expected_navigation_items)
expect(scheme_items("/schemes/1", 1, "1 location")).to eq(expected_scheme_items)
end
end
context "when the user is on the scheme locations page" do
let(:expected_navigation_items) do
[
NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false),
NavigationItemsHelper::NavigationItem.new("Users", "/users", false),
NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false),
NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", true),
]
end
let(:expected_scheme_items) do
[
NavigationItemsHelper::NavigationItem.new("Scheme", "/schemes/1", false),
NavigationItemsHelper::NavigationItem.new("1 location", "/schemes/1/locations", true),
]
end
it "returns navigation items with Schemes item set as current" do
expect(primary_items("/schemes/1/locations", current_user)).to eq(expected_navigation_items)
expect(scheme_items("/schemes/1/locations", 1, "1 location")).to eq(expected_scheme_items)
end end
end end
@ -200,14 +231,14 @@ RSpec.describe NavigationItemsHelper do
NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", true), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", true),
NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", false),
NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false), NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false),
NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false),
] ]
end end
let(:expected_secondary_navigation_items) do let(:expected_secondary_navigation_items) do
[ [
NavigationItemsHelper::NavigationItem.new("Logs", "/organisations/#{current_user.organisation.id}/logs", true), NavigationItemsHelper::NavigationItem.new("Logs", "/organisations/#{current_user.organisation.id}/logs", true),
NavigationItemsHelper::NavigationItem.new("Supported housing", "/organisations/#{current_user.organisation.id}/supported-housing", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/organisations/#{current_user.organisation.id}/schemes", false),
NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false),
NavigationItemsHelper::NavigationItem.new("About this organisation", "/organisations/#{current_user.organisation.id}", false), NavigationItemsHelper::NavigationItem.new("About this organisation", "/organisations/#{current_user.organisation.id}", false),
] ]
@ -226,14 +257,14 @@ RSpec.describe NavigationItemsHelper do
NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", true), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", true),
NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", false),
NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false), NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false),
NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false),
] ]
end end
let(:expected_secondary_navigation_items) do let(:expected_secondary_navigation_items) do
[ [
NavigationItemsHelper::NavigationItem.new("Logs", "/organisations/#{current_user.organisation.id}/logs", false), NavigationItemsHelper::NavigationItem.new("Logs", "/organisations/#{current_user.organisation.id}/logs", false),
NavigationItemsHelper::NavigationItem.new("Supported housing", "/organisations/#{current_user.organisation.id}/supported-housing", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/organisations/#{current_user.organisation.id}/schemes", false),
NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", true), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", true),
NavigationItemsHelper::NavigationItem.new("About this organisation", "/organisations/#{current_user.organisation.id}", false), NavigationItemsHelper::NavigationItem.new("About this organisation", "/organisations/#{current_user.organisation.id}", false),
] ]
@ -246,20 +277,20 @@ RSpec.describe NavigationItemsHelper do
end end
context "when the user is on organisation schemes page" do context "when the user is on organisation schemes page" do
let(:required_sub_path) { "supported-housing" } let(:required_sub_path) { "schemes" }
let(:expected_navigation_items) do let(:expected_navigation_items) do
[ [
NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", true), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", true),
NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", false),
NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false), NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false),
NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false),
] ]
end end
let(:expected_secondary_navigation_items) do let(:expected_secondary_navigation_items) do
[ [
NavigationItemsHelper::NavigationItem.new("Logs", "/organisations/#{current_user.organisation.id}/logs", false), NavigationItemsHelper::NavigationItem.new("Logs", "/organisations/#{current_user.organisation.id}/logs", false),
NavigationItemsHelper::NavigationItem.new("Supported housing", "/organisations/#{current_user.organisation.id}/supported-housing", true), NavigationItemsHelper::NavigationItem.new("Schemes", "/organisations/#{current_user.organisation.id}/schemes", true),
NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false),
NavigationItemsHelper::NavigationItem.new("About this organisation", "/organisations/#{current_user.organisation.id}", false), NavigationItemsHelper::NavigationItem.new("About this organisation", "/organisations/#{current_user.organisation.id}", false),
] ]
@ -278,14 +309,14 @@ RSpec.describe NavigationItemsHelper do
NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", true), NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", true),
NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", false),
NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false), NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false),
NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false),
] ]
end end
let(:expected_secondary_navigation_items) do let(:expected_secondary_navigation_items) do
[ [
NavigationItemsHelper::NavigationItem.new("Logs", "/organisations/#{current_user.organisation.id}/logs", false), NavigationItemsHelper::NavigationItem.new("Logs", "/organisations/#{current_user.organisation.id}/logs", false),
NavigationItemsHelper::NavigationItem.new("Supported housing", "/organisations/#{current_user.organisation.id}/supported-housing", false), NavigationItemsHelper::NavigationItem.new("Schemes", "/organisations/#{current_user.organisation.id}/schemes", false),
NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false), NavigationItemsHelper::NavigationItem.new("Users", "/organisations/#{current_user.organisation.id}/users", false),
NavigationItemsHelper::NavigationItem.new("About this organisation", "/organisations/#{current_user.organisation.id}", true), NavigationItemsHelper::NavigationItem.new("About this organisation", "/organisations/#{current_user.organisation.id}", true),
] ]

2
spec/helpers/tab_nav_helper_spec.rb

@ -21,7 +21,7 @@ RSpec.describe TabNavHelper do
describe "#scheme_cell" do describe "#scheme_cell" do
it "returns the scheme link service name and primary user group separated by a newline character" do it "returns the scheme link service name and primary user group separated by a newline character" do
expected_html = "<a class=\"govuk-link\" href=\"/supported-housing\">#{scheme.service_name}</a>\n<span class=\"govuk-visually-hidden\">Scheme </span><span class=\"govuk-!-font-weight-regular app-!-colour-muted\">#{scheme.primary_client_group_display}</span>" expected_html = "<a class=\"govuk-link\" href=\"/schemes\">#{scheme.service_name}</a>\n<span class=\"govuk-visually-hidden\">Scheme </span><span class=\"govuk-!-font-weight-regular app-!-colour-muted\">#{scheme.primary_client_group_display}</span>"
expect(scheme_cell(scheme)).to match(expected_html) expect(scheme_cell(scheme)).to match(expected_html)
end end
end end

26
spec/requests/organisations_controller_spec.rb

@ -31,8 +31,8 @@ RSpec.describe OrganisationsController, type: :request do
expect(response).to redirect_to("/account/sign-in") expect(response).to redirect_to("/account/sign-in")
end end
it "does not let you see supported housing list" do it "does not let you see schemes list" do
get "/organisations/#{organisation.id}/supported-housing", headers: headers, params: {} get "/organisations/#{organisation.id}/schemes", headers: headers, params: {}
expect(response).to redirect_to("/account/sign-in") expect(response).to redirect_to("/account/sign-in")
end end
end end
@ -48,11 +48,11 @@ RSpec.describe OrganisationsController, type: :request do
before do before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false) allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in user sign_in user
get "/organisations/#{organisation.id}/supported-housing", headers:, params: {} get "/organisations/#{organisation.id}/schemes", headers:, params: {}
end end
it "has page heading" do it "has page heading" do
expect(page).to have_content("Supported housing services") expect(page).to have_content("Schemes")
end end
it "shows a search bar" do it "shows a search bar" do
@ -60,7 +60,7 @@ RSpec.describe OrganisationsController, type: :request do
end end
it "has hidden accebility field with description" do it "has hidden accebility field with description" do
expected_field = "<h2 class=\"govuk-visually-hidden\">Supported housing services</h2>" expected_field = "<h2 class=\"govuk-visually-hidden\">Supported housing schemes</h2>"
expect(CGI.unescape_html(response.body)).to include(expected_field) expect(CGI.unescape_html(response.body)).to include(expected_field)
end end
@ -77,7 +77,7 @@ RSpec.describe OrganisationsController, type: :request do
before do before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false) allow(user).to receive(:need_two_factor_authentication?).and_return(false)
get "/organisations/#{organisation.id}/supported-housing?search=#{search_param}" get "/organisations/#{organisation.id}/schemes?search=#{search_param}"
end end
it "returns matching results" do it "returns matching results" do
@ -104,19 +104,19 @@ RSpec.describe OrganisationsController, type: :request do
before do before do
sign_in user sign_in user
get "/organisations/#{organisation.id}/supported-housing", headers:, params: {} get "/organisations/#{organisation.id}/schemes", headers:, params: {}
end end
it "has page heading" do it "has page heading" do
expect(page).to have_content("Supported housing services") expect(page).to have_content("Schemes")
end end
it "shows a search bar" do it "shows a search bar" do
expect(page).to have_field("search", type: "search") expect(page).to have_field("search", type: "search")
end end
it "has hidden accebility field with description" do it "has hidden accessibility field with description" do
expected_field = "<h2 class=\"govuk-visually-hidden\">Supported housing services</h2>" expected_field = "<h2 class=\"govuk-visually-hidden\">Supported housing schemes</h2>"
expect(CGI.unescape_html(response.body)).to include(expected_field) expect(CGI.unescape_html(response.body)).to include(expected_field)
end end
@ -131,7 +131,7 @@ RSpec.describe OrganisationsController, type: :request do
let!(:unauthorised_organisation) { FactoryBot.create(:organisation) } let!(:unauthorised_organisation) { FactoryBot.create(:organisation) }
before do before do
get "/organisations/#{unauthorised_organisation.id}/supported-housing", headers:, params: {} get "/organisations/#{unauthorised_organisation.id}/schemes", headers:, params: {}
end end
it "returns not found 404 from org details route" do it "returns not found 404 from org details route" do
@ -144,7 +144,7 @@ RSpec.describe OrganisationsController, type: :request do
let(:search_param) { "CODE321" } let(:search_param) { "CODE321" }
before do before do
get "/organisations/#{organisation.id}/supported-housing?search=#{search_param}" get "/organisations/#{organisation.id}/schemes?search=#{search_param}"
end end
it "returns matching results" do it "returns matching results" do
@ -159,7 +159,7 @@ RSpec.describe OrganisationsController, type: :request do
end end
it "has search in the title" do it "has search in the title" do
expect(page).to have_title("Supported housing services (1 scheme matching ‘#{search_param}’) - Submit social housing lettings and sales data (CORE) - GOV.UK") expect(page).to have_title("Supported housing schemes (1 scheme matching ‘#{search_param}’) - Submit social housing lettings and sales data (CORE) - GOV.UK")
end end
end end
end end

235
spec/requests/schemes_controller_spec.rb

@ -10,7 +10,7 @@ RSpec.describe SchemesController, type: :request do
describe "#index" do describe "#index" do
context "when not signed in" do context "when not signed in" do
it "redirects to the sign in page" do it "redirects to the sign in page" do
get "/supported-housing" get "/schemes"
expect(response).to redirect_to("/account/sign-in") expect(response).to redirect_to("/account/sign-in")
end end
end end
@ -20,7 +20,7 @@ RSpec.describe SchemesController, type: :request do
before do before do
sign_in user sign_in user
get "/supported-housing" get "/schemes"
end end
it "returns 401 unauthorized" do it "returns 401 unauthorized" do
@ -34,12 +34,12 @@ RSpec.describe SchemesController, type: :request do
before do before do
sign_in user sign_in user
get "/supported-housing" get "/schemes"
end end
it "redirects to the organisation schemes path" do it "redirects to the organisation schemes path" do
follow_redirect! follow_redirect!
expect(path).to match("/organisations/#{user.organisation.id}/supported-housing") expect(path).to match("/organisations/#{user.organisation.id}/schemes")
end end
end end
@ -47,11 +47,11 @@ RSpec.describe SchemesController, type: :request do
before do before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false) allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in user sign_in user
get "/supported-housing" get "/schemes"
end end
it "has page heading" do it "has page heading" do
expect(page).to have_content("Supported housing services") expect(page).to have_content("Schemes")
end end
it "shows all schemes" do it "shows all schemes" do
@ -65,7 +65,7 @@ RSpec.describe SchemesController, type: :request do
end end
it "has correct title" do it "has correct title" do
expect(page).to have_title("Supported housing services - Submit social housing lettings and sales data (CORE) - GOV.UK") expect(page).to have_title("Supported housing schemes - Submit social housing lettings and sales data (CORE) - GOV.UK")
end end
it "shows the total organisations count" do it "shows the total organisations count" do
@ -73,7 +73,7 @@ RSpec.describe SchemesController, type: :request do
end end
it "has hidden accebility field with description" do it "has hidden accebility field with description" do
expected_field = "<h2 class=\"govuk-visually-hidden\">Supported housing services</h2>" expected_field = "<h2 class=\"govuk-visually-hidden\">Supported housing schemes</h2>"
expect(CGI.unescape_html(response.body)).to include(expected_field) expect(CGI.unescape_html(response.body)).to include(expected_field)
end end
@ -86,7 +86,7 @@ RSpec.describe SchemesController, type: :request do
context "when on the first page" do context "when on the first page" do
before do before do
get "/supported-housing" get "/schemes"
end end
it "shows the total schemes count" do it "shows the total schemes count" do
@ -98,7 +98,7 @@ RSpec.describe SchemesController, type: :request do
end end
it "has correct page 1 of 2 title" do it "has correct page 1 of 2 title" do
expect(page).to have_title("Supported housing services (page 1 of 2) - Submit social housing lettings and sales data (CORE) - GOV.UK") expect(page).to have_title("Supported housing schemes (page 1 of 2) - Submit social housing lettings and sales data (CORE) - GOV.UK")
end end
it "has pagination links" do it "has pagination links" do
@ -111,7 +111,7 @@ RSpec.describe SchemesController, type: :request do
context "when on the second page" do context "when on the second page" do
before do before do
get "/supported-housing?page=2" get "/schemes?page=2"
end end
it "shows the total schemes count" do it "shows the total schemes count" do
@ -130,7 +130,7 @@ RSpec.describe SchemesController, type: :request do
end end
it "has correct page 1 of 2 title" do it "has correct page 1 of 2 title" do
expect(page).to have_title("Supported housing services (page 2 of 2) - Submit social housing lettings and sales data (CORE) - GOV.UK") expect(page).to have_title("Supported housing schemes (page 2 of 2) - Submit social housing lettings and sales data (CORE) - GOV.UK")
end end
end end
end end
@ -140,7 +140,7 @@ RSpec.describe SchemesController, type: :request do
let(:search_param) { "CODE321" } let(:search_param) { "CODE321" }
before do before do
get "/supported-housing?search=#{search_param}" get "/schemes?search=#{search_param}"
end end
it "returns matching results" do it "returns matching results" do
@ -155,7 +155,7 @@ RSpec.describe SchemesController, type: :request do
end end
it "has search in the title" do it "has search in the title" do
expect(page).to have_title("Supported housing services (1 scheme matching ‘#{search_param}’) - Submit social housing lettings and sales data (CORE) - GOV.UK") expect(page).to have_title("Supported housing schemes (1 scheme matching ‘#{search_param}’) - Submit social housing lettings and sales data (CORE) - GOV.UK")
end end
end end
end end
@ -166,7 +166,7 @@ RSpec.describe SchemesController, type: :request do
context "when not signed in" do context "when not signed in" do
it "redirects to the sign in page" do it "redirects to the sign in page" do
get "/supported-housing/#{specific_scheme.id}" get "/schemes/#{specific_scheme.id}"
expect(response).to redirect_to("/account/sign-in") expect(response).to redirect_to("/account/sign-in")
end end
end end
@ -176,7 +176,7 @@ RSpec.describe SchemesController, type: :request do
before do before do
sign_in user sign_in user
get "/supported-housing/#{specific_scheme.id}" get "/schemes/#{specific_scheme.id}"
end end
it "returns 401 unauthorized" do it "returns 401 unauthorized" do
@ -194,7 +194,7 @@ RSpec.describe SchemesController, type: :request do
end end
it "has page heading" do it "has page heading" do
get "/supported-housing/#{specific_scheme.id}" get "/schemes/#{specific_scheme.id}"
expect(page).to have_content(specific_scheme.code) expect(page).to have_content(specific_scheme.code)
expect(page).to have_content(specific_scheme.service_name) expect(page).to have_content(specific_scheme.service_name)
expect(page).to have_content(specific_scheme.organisation.name) expect(page).to have_content(specific_scheme.organisation.name)
@ -211,11 +211,11 @@ RSpec.describe SchemesController, type: :request do
expect(page).to have_content(specific_scheme.intended_stay_display) expect(page).to have_content(specific_scheme.intended_stay_display)
end end
context "when coordinator attempts to see scheme belogning to a different organisation" do context "when coordinator attempts to see scheme belonging to a different organisation" do
let!(:specific_scheme) { FactoryBot.create(:scheme) } let!(:specific_scheme) { FactoryBot.create(:scheme) }
it "returns 404 not found" do it "returns 404 not found" do
get "/supported-housing/#{specific_scheme.id}" get "/schemes/#{specific_scheme.id}"
expect(response).to have_http_status(:not_found) expect(response).to have_http_status(:not_found)
end end
end end
@ -225,7 +225,7 @@ RSpec.describe SchemesController, type: :request do
before do before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false) allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in user sign_in user
get "/supported-housing/#{specific_scheme.id}" get "/schemes/#{specific_scheme.id}"
end end
it "has page heading" do it "has page heading" do
@ -246,4 +246,199 @@ RSpec.describe SchemesController, type: :request do
end end
end end
end end
describe "#locations" do
let(:specific_scheme) { schemes.first }
context "when not signed in" do
it "redirects to the sign in page" do
get "/schemes/#{specific_scheme.id}/locations"
expect(response).to redirect_to("/account/sign-in")
end
end
context "when signed in as a data provider user" do
let(:user) { FactoryBot.create(:user) }
before do
sign_in user
get "/schemes/#{specific_scheme.id}/locations"
end
it "returns 401 unauthorized" do
request
expect(response).to have_http_status(:unauthorized)
end
end
context "when signed in as a data coordinator user" do
let(:user) { FactoryBot.create(:user, :data_coordinator) }
let!(:scheme) { FactoryBot.create(:scheme, organisation: user.organisation) }
let!(:locations) { FactoryBot.create_list(:location, 3, scheme:) }
before do
sign_in user
get "/schemes/#{scheme.id}/locations"
end
context "when coordinator attempts to see scheme belonging to a different organisation" do
let!(:specific_scheme) { FactoryBot.create(:scheme) }
before do
FactoryBot.create(:location, scheme: specific_scheme)
end
it "returns 404 not found" do
get "/schemes/#{specific_scheme.id}/locations"
expect(response).to have_http_status(:not_found)
end
end
it "shows scheme" do
locations.each do |location|
expect(page).to have_content(location.location_code)
expect(page).to have_content(location.postcode)
expect(page).to have_content(location.county)
expect(page).to have_content(location.type_of_unit)
expect(page).to have_content(location.type_of_building)
expect(page).to have_content(location.wheelchair_adaptation)
expect(page).to have_content(location.address_line1)
expect(page).to have_content(location.address_line2)
end
end
it "has page heading" do
expect(page).to have_content(scheme.service_name)
end
it "has correct title" do
expect(page).to have_title("#{scheme.service_name} - Submit social housing lettings and sales data (CORE) - GOV.UK")
end
context "when paginating over 20 results" do
let!(:locations) { FactoryBot.create_list(:location, 25, scheme:) }
context "when on the first page" do
before do
get "/schemes/#{scheme.id}/locations"
end
it "shows which schemes are being shown on the current page" do
expect(CGI.unescape_html(response.body)).to match("Showing <b>1</b> to <b>20</b> of <b>#{locations.count}</b> locations")
end
it "has correct page 1 of 2 title" do
expect(page).to have_title("#{scheme.service_name} (page 1 of 2) - Submit social housing lettings and sales data (CORE) - GOV.UK")
end
it "has pagination links" do
expect(page).to have_content("Previous")
expect(page).not_to have_link("Previous")
expect(page).to have_content("Next")
expect(page).to have_link("Next")
end
end
context "when on the second page" do
before do
get "/schemes/#{scheme.id}/locations?page=2"
end
it "shows which schemes are being shown on the current page" do
expect(CGI.unescape_html(response.body)).to match("Showing <b>21</b> to <b>25</b> of <b>#{locations.count}</b> locations")
end
it "has correct page 1 of 2 title" do
expect(page).to have_title("#{scheme.service_name} (page 2 of 2) - Submit social housing lettings and sales data (CORE) - GOV.UK")
end
it "has pagination links" do
expect(page).to have_content("Previous")
expect(page).to have_link("Previous")
expect(page).to have_content("Next")
expect(page).not_to have_link("Next")
end
end
end
end
context "when signed in as a support user" do
let(:user) { FactoryBot.create(:user, :support) }
let!(:scheme) { FactoryBot.create(:scheme) }
let!(:locations) { FactoryBot.create_list(:location, 3, scheme:) }
before do
allow(user).to receive(:need_two_factor_authentication?).and_return(false)
sign_in user
get "/schemes/#{scheme.id}/locations"
end
it "shows scheme" do
locations.each do |location|
expect(page).to have_content(location.location_code)
expect(page).to have_content(location.postcode)
expect(page).to have_content(location.county)
expect(page).to have_content(location.type_of_unit)
expect(page).to have_content(location.type_of_building)
expect(page).to have_content(location.wheelchair_adaptation)
expect(page).to have_content(location.address_line1)
expect(page).to have_content(location.address_line2)
end
end
it "has page heading" do
expect(page).to have_content(scheme.service_name)
end
it "has correct title" do
expect(page).to have_title("#{scheme.service_name} - Submit social housing lettings and sales data (CORE) - GOV.UK")
end
context "when paginating over 20 results" do
let!(:locations) { FactoryBot.create_list(:location, 25, scheme:) }
context "when on the first page" do
before do
get "/schemes/#{scheme.id}/locations"
end
it "shows which schemes are being shown on the current page" do
expect(CGI.unescape_html(response.body)).to match("Showing <b>1</b> to <b>20</b> of <b>#{locations.count}</b> locations")
end
it "has correct page 1 of 2 title" do
expect(page).to have_title("#{scheme.service_name} (page 1 of 2) - Submit social housing lettings and sales data (CORE) - GOV.UK")
end
it "has pagination links" do
expect(page).to have_content("Previous")
expect(page).not_to have_link("Previous")
expect(page).to have_content("Next")
expect(page).to have_link("Next")
end
end
context "when on the second page" do
before do
get "/schemes/#{scheme.id}/locations?page=2"
end
it "shows which schemes are being shown on the current page" do
expect(CGI.unescape_html(response.body)).to match("Showing <b>21</b> to <b>25</b> of <b>#{locations.count}</b> locations")
end
it "has correct page 1 of 2 title" do
expect(page).to have_title("#{scheme.service_name} (page 2 of 2) - Submit social housing lettings and sales data (CORE) - GOV.UK")
end
it "has pagination links" do
expect(page).to have_content("Previous")
expect(page).to have_link("Previous")
expect(page).to have_content("Next")
expect(page).not_to have_link("Next")
end
end
end
end
end
end end

Loading…
Cancel
Save