From 0c4a81ea7a8e2715bf81d9fd81b371010dc00f6f Mon Sep 17 00:00:00 2001 From: J G <7750475+moarpheus@users.noreply.github.com> Date: Thu, 16 Jun 2022 06:26:41 +0100 Subject: [PATCH] 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 --- .../primary_navigation_component.rb | 2 +- app/controllers/schemes_controller.rb | 18 +- app/helpers/navigation_items_helper.rb | 21 +- app/models/location.rb | 20 ++ app/models/scheme.rb | 5 +- app/views/organisations/schemes.html.erb | 6 +- app/views/schemes/_scheme_list.html.erb | 4 +- app/views/schemes/index.html.erb | 6 +- app/views/schemes/locations.html.erb | 41 +++ app/views/schemes/show.html.erb | 12 +- config/routes.rb | 8 +- db/migrate/20220614124115_create_locations.rb | 17 ++ db/schema.rb | 18 +- db/seeds.rb | 40 ++- .../primary_navigation_component_spec.rb | 8 +- spec/factories/location.rb | 13 + spec/factories/scheme.rb | 2 +- spec/features/schemes_spec.rb | 61 ++++- spec/helpers/navigation_items_helper_spec.rb | 85 +++++-- spec/helpers/tab_nav_helper_spec.rb | 2 +- .../requests/organisations_controller_spec.rb | 26 +- spec/requests/schemes_controller_spec.rb | 235 ++++++++++++++++-- 22 files changed, 547 insertions(+), 103 deletions(-) create mode 100644 app/models/location.rb create mode 100644 app/views/schemes/locations.html.erb create mode 100644 db/migrate/20220614124115_create_locations.rb create mode 100644 spec/factories/location.rb diff --git a/app/components/primary_navigation_component.rb b/app/components/primary_navigation_component.rb index 466c6979c..82a12e447 100644 --- a/app/components/primary_navigation_component.rb +++ b/app/components/primary_navigation_component.rb @@ -3,7 +3,7 @@ class PrimaryNavigationComponent < ViewComponent::Base def initialize(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 end diff --git a/app/controllers/schemes_controller.rb b/app/controllers/schemes_controller.rb index d9dccab5d..e97a08e4b 100644 --- a/app/controllers/schemes_controller.rb +++ b/app/controllers/schemes_controller.rb @@ -3,10 +3,11 @@ class SchemesController < ApplicationController include Modules::SearchFilter before_action :authenticate_user! + before_action :find_resource, except: %i[index] before_action :authenticate_scope! 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 @pagy, @schemes = pagy(filtered_collection(all_schemes, search_term)) @@ -16,7 +17,12 @@ class SchemesController < ApplicationController def show @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 private @@ -25,7 +31,15 @@ private params["search"] end + def find_resource + @scheme = Scheme.find_by(id: params[:id]) + end + def authenticate_scope! 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 diff --git a/app/helpers/navigation_items_helper.rb b/app/helpers/navigation_items_helper.rb index 369428053..dbaf64296 100644 --- a/app/helpers/navigation_items_helper.rb +++ b/app/helpers/navigation_items_helper.rb @@ -7,12 +7,12 @@ module NavigationItemsHelper NavigationItem.new("Organisations", organisations_path, organisations_current?(path)), NavigationItem.new("Users", "/users", users_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? [ 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("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) [ 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("About this organisation", "/organisations/#{current_organisation_id}", subnav_details_path?(path)), ] 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 def logs_current?(path) @@ -44,16 +51,16 @@ private path == "/users" || path.include?("/users/") end - def supported_housing_current?(path) - path == "/supported-housing" || path.include?("/supported-housing/") + def supported_housing_schemes_current?(path) + path == "/schemes" || path.include?("/schemes/") end def organisations_current?(path) path == "/organisations" || path.include?("/organisations/") end - def subnav_supported_housing_path?(path) - path.include?("/organisations") && path.include?("/supported-housing") || path.include?("/supported-housing/") + def subnav_supported_housing_schemes_path?(path) + path.include?("/organisations") && path.include?("/schemes") || path.include?("/schemes/") end def subnav_users_path?(path) diff --git a/app/models/location.rb b/app/models/location.rb new file mode 100644 index 000000000..76e3e577e --- /dev/null +++ b/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 diff --git a/app/models/scheme.rb b/app/models/scheme.rb index 096706018..fb996a509 100644 --- a/app/models/scheme.rb +++ b/app/models/scheme.rb @@ -1,5 +1,6 @@ class Scheme < ApplicationRecord belongs_to :organisation + has_many :locations scope :search_by_code, ->(code) { where("code ILIKE ?", "%#{code}%") } scope :search_by_service_name, ->(name) { where("service_name ILIKE ?", "%#{name}%") } @@ -66,8 +67,8 @@ class Scheme < ApplicationRecord { name: "Service code", value: code }, { name: "Name", value: service_name }, { name: "Confidential information", value: sensitive_display }, - { name: "Managing agent", value: organisation.name }, - { name: "Type of service", value: scheme_type_display }, + { name: "Managing by", value: organisation.name }, + { name: "Type of scheme", value: scheme_type_display }, { name: "Registered under Care Standards Act 2000", value: registered_under_care_act_display }, { name: "Total number of units", value: total_units }, { name: "Primary client group", value: primary_client_group_display }, diff --git a/app/views/organisations/schemes.html.erb b/app/views/organisations/schemes.html.erb index b28d9c306..ac64a6a07 100644 --- a/app/views/organisations/schemes.html.erb +++ b/app/views/organisations/schemes.html.erb @@ -1,9 +1,9 @@ <% 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 %> -<%= 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? %> <%= render SubNavigationComponent.new( @@ -11,7 +11,7 @@ ) %> <% end %> -

Supported housing services

+

Supported housing schemes

<%= render SearchComponent.new(current_user:, search_label: "Search by service name or code", value: @searched) %> diff --git a/app/views/schemes/_scheme_list.html.erb b/app/views/schemes/_scheme_list.html.erb index 8d6ef7a72..c610610e2 100644 --- a/app/views/schemes/_scheme_list.html.erb +++ b/app/views/schemes/_scheme_list.html.erb @@ -14,10 +14,10 @@ <% row.cell(header: true, text: "Code", html_attributes: { scope: "col", }) %> - <% row.cell(header: true, text: "Service", html_attributes: { + <% row.cell(header: true, text: "Scheme", html_attributes: { scope: "col", }) %> - <% row.cell(header: true, text: "Managing agent", html_attributes: { + <% row.cell(header: true, text: "Managed by", html_attributes: { scope: "col", }) %> <% row.cell(header: true, text: "Created", html_attributes: { diff --git a/app/views/schemes/index.html.erb b/app/views/schemes/index.html.erb index b96e7bdc3..7d2ae2530 100644 --- a/app/views/schemes/index.html.erb +++ b/app/views/schemes/index.html.erb @@ -1,11 +1,11 @@ <% 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 %> -<%= 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 } %> -

Supported housing services

+

Supported housing schemes

<%= render SearchComponent.new(current_user:, search_label: "Search by service name or code", value: @searched) %> diff --git a/app/views/schemes/locations.html.erb b/app/views/schemes/locations.html.erb new file mode 100644 index 000000000..3a3f13125 --- /dev/null +++ b/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")) %> + +
+
+ <% @locations.each do |location| %> +
+
+

+ <%= "#{location.address_line1}, #{location.address_line2}" %> +

+
+
+
+ <% location.display_attributes.each do |attribute| %> +
+
+ <%= attribute[:name] %> +
+
+ <%= attribute[:value] %> + <% if attribute[:suffix] %> + <%= attribute[:suffix] %> + <% end %> +
+
+ <% end %> +
+
+
+ <% end %> +
+
+ +<%== render partial: "pagy/nav", locals: { pagy: @pagy, item_name: "locations" } %> diff --git a/app/views/schemes/show.html.erb b/app/views/schemes/show.html.erb index bb883d0e9..dd1ceda70 100644 --- a/app/views/schemes/show.html.erb +++ b/app/views/schemes/show.html.erb @@ -1,17 +1,21 @@ <% 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")) %> +
<%= govuk_summary_list do |summary_list| %> <% @scheme.display_attributes.each do |attr| %> - <%= summary_list.row do |row| %> - <% row.key { attr[:name].to_s.humanize } %> - <% row.value { details_html(attr) } %> - <% end %> + <%= summary_list.row do |row| %> + <% 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) } %> <% end %> + <% end %> <% end %>
diff --git a/config/routes.rb b/config/routes.rb index 3e4492127..01efc2623 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -35,7 +35,11 @@ Rails.application.routes.draw do get "edit/password", to: "users#edit_password" 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 member do @@ -50,7 +54,7 @@ Rails.application.routes.draw do get "users", to: "organisations#users" get "users/invite", to: "users/account#new" get "logs", to: "organisations#logs" - get "supported-housing", to: "organisations#schemes" + get "schemes", to: "organisations#schemes" end end diff --git a/db/migrate/20220614124115_create_locations.rb b/db/migrate/20220614124115_create_locations.rb new file mode 100644 index 000000000..e74ba019a --- /dev/null +++ b/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 diff --git a/db/schema.rb b/db/schema.rb index 6a4e5f2ea..d83363804 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # 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 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 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| t.datetime "created_at", default: -> { "CURRENT_TIMESTAMP" } 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" end + add_foreign_key "locations", "schemes" add_foreign_key "schemes", "organisations" end diff --git a/db/seeds.rb b/db/seeds.rb index ad1fc1ac4..fdf9d6172 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -70,7 +70,7 @@ unless Rails.env.test? end if Rails.env.development? && Scheme.count.zero? - Scheme.create!( + scheme1 = Scheme.create!( code: "S878", service_name: "Beulahside Care", sensitive: 0, @@ -85,7 +85,7 @@ unless Rails.env.test? created_at: Time.zone.now, ) - Scheme.create!( + scheme2 = Scheme.create!( code: "S312", service_name: "Abdullahview Point", sensitive: 0, @@ -114,6 +114,42 @@ unless Rails.env.test? organisation: dummy_org, 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 pp "Seeded 3 dummy schemes" diff --git a/spec/components/primary_navigation_component_spec.rb b/spec/components/primary_navigation_component_spec.rb index 9a3c91d09..dcab43c31 100644 --- a/spec/components/primary_navigation_component_spec.rb +++ b/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("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Logs ", "/logs", false), - NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", false), + NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), ] end @@ -36,7 +36,7 @@ RSpec.describe PrimaryNavigationComponent, type: :component do expect(result.text).to include("Organisations") expect(result.text).to include("Users") expect(result.text).to include("Logs") - expect(result.text).to include("Supported housing") + expect(result.text).to include("Schemes") end end @@ -45,9 +45,9 @@ RSpec.describe PrimaryNavigationComponent, type: :component do allow(Rails.env).to receive(:production?).and_return(true) end - it "doesn't render supported housing" do + it "doesn't render schemes" do 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 diff --git a/spec/factories/location.rb b/spec/factories/location.rb new file mode 100644 index 000000000..7afaeb11c --- /dev/null +++ b/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 diff --git a/spec/factories/scheme.rb b/spec/factories/scheme.rb index 6c3537146..d4f2c1cfb 100644 --- a/spec/factories/scheme.rb +++ b/spec/factories/scheme.rb @@ -1,7 +1,7 @@ FactoryBot.define do factory :scheme do 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) } registered_under_care_act { Faker::Number.within(range: 0..1) } support_type { Faker::Number.within(range: 0..6) } diff --git a/spec/features/schemes_spec.rb b/spec/features/schemes_spec.rb index f772a24c8..46ee351e0 100644 --- a/spec/features/schemes_spec.rb +++ b/spec/features/schemes_spec.rb @@ -1,6 +1,6 @@ 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 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) } @@ -25,13 +25,13 @@ RSpec.describe "Supported housing scheme Features" do click_button("Submit") end - it "displays the link to the supported housing" do - expect(page).to have_link("Supported housing", href: "/supported-housing") + it "displays the link to the schemes" do + expect(page).to have_link("Schemes", href: "/schemes") end - context "when I click Supported housing" do + context "when I click schemes" do before do - click_link "Supported housing", href: "/supported-housing" + click_link "Schemes", href: "/schemes" end it "shows list of schemes" do @@ -99,9 +99,9 @@ RSpec.describe "Supported housing scheme Features" do click_button("Submit") end - context "when I visit supported housing page" do + context "when I visit schemes page" do before do - visit("supported-housing") + visit("schemes") end it "shows list of links to schemes" do @@ -112,8 +112,10 @@ RSpec.describe "Supported housing scheme Features" do end context "when I click to see individual scheme" do + let(:scheme) { schemes.first } + before do - click_link(schemes.first.service_name) + click_link(scheme.service_name) end 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.intended_stay_display) 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 diff --git a/spec/helpers/navigation_items_helper_spec.rb b/spec/helpers/navigation_items_helper_spec.rb index 52ad582c5..90a96017b 100644 --- a/spec/helpers/navigation_items_helper_spec.rb +++ b/spec/helpers/navigation_items_helper_spec.rb @@ -12,7 +12,7 @@ RSpec.describe NavigationItemsHelper do let(:expected_navigation_items) do [ 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("About your organisation", organisation_path, false), ] @@ -27,7 +27,7 @@ RSpec.describe NavigationItemsHelper do let(:expected_navigation_items) do [ 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("About your organisation", organisation_path, false), ] @@ -42,7 +42,7 @@ RSpec.describe NavigationItemsHelper do let(:expected_navigation_items) do [ 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("About your organisation", organisation_path, true), ] @@ -57,7 +57,7 @@ RSpec.describe NavigationItemsHelper do let(:expected_navigation_items) do [ 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("About your organisation", organisation_path, false), ] @@ -72,7 +72,7 @@ RSpec.describe NavigationItemsHelper do let(:expected_navigation_items) do [ 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("About your organisation", organisation_path, false), ] @@ -87,14 +87,14 @@ RSpec.describe NavigationItemsHelper do let(:expected_navigation_items) do [ 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("About your organisation", organisation_path, false), ] end - it "returns navigation items with supported housing item set as current" do - expect(primary_items("/supported-housing/1", current_user)).to eq(expected_navigation_items) + it "returns navigation items with Schemes item set as current" do + expect(primary_items("/schemes/1", current_user)).to eq(expected_navigation_items) end end end @@ -108,7 +108,7 @@ RSpec.describe NavigationItemsHelper do NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Logs", "/logs", true), - NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", false), + NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), ] end @@ -123,7 +123,7 @@ RSpec.describe NavigationItemsHelper do NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", true), NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false), - NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", false), + NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), ] end @@ -138,7 +138,7 @@ RSpec.describe NavigationItemsHelper do NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false), - NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", false), + NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), ] end @@ -147,18 +147,18 @@ RSpec.describe NavigationItemsHelper do 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 [ NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false), - NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", true), + NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", true), ] end 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 @@ -168,7 +168,7 @@ RSpec.describe NavigationItemsHelper do NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", true), NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false), - NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", false), + NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), ] end @@ -183,12 +183,43 @@ RSpec.describe NavigationItemsHelper do NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", false), NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false), - NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", true), + NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", true), ] end - it "returns navigation items with supported housing item set as current" do - expect(primary_items("/supported-housing/1", current_user)).to eq(expected_navigation_items) + let(:expected_scheme_items) do + [ + 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 @@ -200,14 +231,14 @@ RSpec.describe NavigationItemsHelper do NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", true), NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false), - NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", false), + NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), ] end let(:expected_secondary_navigation_items) do [ 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("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("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false), - NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", false), + NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), ] end let(:expected_secondary_navigation_items) do [ 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("About this organisation", "/organisations/#{current_user.organisation.id}", false), ] @@ -246,20 +277,20 @@ RSpec.describe NavigationItemsHelper do end 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 [ NavigationItemsHelper::NavigationItem.new("Organisations", "/organisations", true), NavigationItemsHelper::NavigationItem.new("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false), - NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", false), + NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), ] end let(:expected_secondary_navigation_items) do [ 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("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("Users", "/users", false), NavigationItemsHelper::NavigationItem.new("Logs", "/logs", false), - NavigationItemsHelper::NavigationItem.new("Supported housing", "/supported-housing", false), + NavigationItemsHelper::NavigationItem.new("Schemes", "/schemes", false), ] end let(:expected_secondary_navigation_items) do [ 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("About this organisation", "/organisations/#{current_user.organisation.id}", true), ] diff --git a/spec/helpers/tab_nav_helper_spec.rb b/spec/helpers/tab_nav_helper_spec.rb index 59d4170b7..7ec36f974 100644 --- a/spec/helpers/tab_nav_helper_spec.rb +++ b/spec/helpers/tab_nav_helper_spec.rb @@ -21,7 +21,7 @@ RSpec.describe TabNavHelper do describe "#scheme_cell" do it "returns the scheme link service name and primary user group separated by a newline character" do - expected_html = "#{scheme.service_name}\nScheme #{scheme.primary_client_group_display}" + expected_html = "#{scheme.service_name}\nScheme #{scheme.primary_client_group_display}" expect(scheme_cell(scheme)).to match(expected_html) end end diff --git a/spec/requests/organisations_controller_spec.rb b/spec/requests/organisations_controller_spec.rb index cd976453d..9179ec3b3 100644 --- a/spec/requests/organisations_controller_spec.rb +++ b/spec/requests/organisations_controller_spec.rb @@ -31,8 +31,8 @@ RSpec.describe OrganisationsController, type: :request do expect(response).to redirect_to("/account/sign-in") end - it "does not let you see supported housing list" do - get "/organisations/#{organisation.id}/supported-housing", headers: headers, params: {} + it "does not let you see schemes list" do + get "/organisations/#{organisation.id}/schemes", headers: headers, params: {} expect(response).to redirect_to("/account/sign-in") end end @@ -48,11 +48,11 @@ RSpec.describe OrganisationsController, type: :request do before do allow(user).to receive(:need_two_factor_authentication?).and_return(false) sign_in user - get "/organisations/#{organisation.id}/supported-housing", headers:, params: {} + get "/organisations/#{organisation.id}/schemes", headers:, params: {} end it "has page heading" do - expect(page).to have_content("Supported housing services") + expect(page).to have_content("Schemes") end it "shows a search bar" do @@ -60,7 +60,7 @@ RSpec.describe OrganisationsController, type: :request do end it "has hidden accebility field with description" do - expected_field = "

Supported housing services

" + expected_field = "

Supported housing schemes

" expect(CGI.unescape_html(response.body)).to include(expected_field) end @@ -77,7 +77,7 @@ RSpec.describe OrganisationsController, type: :request do before do 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 it "returns matching results" do @@ -104,19 +104,19 @@ RSpec.describe OrganisationsController, type: :request do before do sign_in user - get "/organisations/#{organisation.id}/supported-housing", headers:, params: {} + get "/organisations/#{organisation.id}/schemes", headers:, params: {} end it "has page heading" do - expect(page).to have_content("Supported housing services") + expect(page).to have_content("Schemes") end it "shows a search bar" do expect(page).to have_field("search", type: "search") end - it "has hidden accebility field with description" do - expected_field = "

Supported housing services

" + it "has hidden accessibility field with description" do + expected_field = "

Supported housing schemes

" expect(CGI.unescape_html(response.body)).to include(expected_field) end @@ -131,7 +131,7 @@ RSpec.describe OrganisationsController, type: :request do let!(:unauthorised_organisation) { FactoryBot.create(:organisation) } before do - get "/organisations/#{unauthorised_organisation.id}/supported-housing", headers:, params: {} + get "/organisations/#{unauthorised_organisation.id}/schemes", headers:, params: {} end it "returns not found 404 from org details route" do @@ -144,7 +144,7 @@ RSpec.describe OrganisationsController, type: :request do let(:search_param) { "CODE321" } before do - get "/organisations/#{organisation.id}/supported-housing?search=#{search_param}" + get "/organisations/#{organisation.id}/schemes?search=#{search_param}" end it "returns matching results" do @@ -159,7 +159,7 @@ RSpec.describe OrganisationsController, type: :request do end 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 diff --git a/spec/requests/schemes_controller_spec.rb b/spec/requests/schemes_controller_spec.rb index 4d5c248d5..a7d907573 100644 --- a/spec/requests/schemes_controller_spec.rb +++ b/spec/requests/schemes_controller_spec.rb @@ -10,7 +10,7 @@ RSpec.describe SchemesController, type: :request do describe "#index" do context "when not signed in" do it "redirects to the sign in page" do - get "/supported-housing" + get "/schemes" expect(response).to redirect_to("/account/sign-in") end end @@ -20,7 +20,7 @@ RSpec.describe SchemesController, type: :request do before do sign_in user - get "/supported-housing" + get "/schemes" end it "returns 401 unauthorized" do @@ -34,12 +34,12 @@ RSpec.describe SchemesController, type: :request do before do sign_in user - get "/supported-housing" + get "/schemes" end it "redirects to the organisation schemes path" do follow_redirect! - expect(path).to match("/organisations/#{user.organisation.id}/supported-housing") + expect(path).to match("/organisations/#{user.organisation.id}/schemes") end end @@ -47,11 +47,11 @@ RSpec.describe SchemesController, type: :request do before do allow(user).to receive(:need_two_factor_authentication?).and_return(false) sign_in user - get "/supported-housing" + get "/schemes" end it "has page heading" do - expect(page).to have_content("Supported housing services") + expect(page).to have_content("Schemes") end it "shows all schemes" do @@ -65,7 +65,7 @@ RSpec.describe SchemesController, type: :request do end 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 it "shows the total organisations count" do @@ -73,7 +73,7 @@ RSpec.describe SchemesController, type: :request do end it "has hidden accebility field with description" do - expected_field = "

Supported housing services

" + expected_field = "

Supported housing schemes

" expect(CGI.unescape_html(response.body)).to include(expected_field) end @@ -86,7 +86,7 @@ RSpec.describe SchemesController, type: :request do context "when on the first page" do before do - get "/supported-housing" + get "/schemes" end it "shows the total schemes count" do @@ -98,7 +98,7 @@ RSpec.describe SchemesController, type: :request do end 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 it "has pagination links" do @@ -111,7 +111,7 @@ RSpec.describe SchemesController, type: :request do context "when on the second page" do before do - get "/supported-housing?page=2" + get "/schemes?page=2" end it "shows the total schemes count" do @@ -130,7 +130,7 @@ RSpec.describe SchemesController, type: :request do end 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 @@ -140,7 +140,7 @@ RSpec.describe SchemesController, type: :request do let(:search_param) { "CODE321" } before do - get "/supported-housing?search=#{search_param}" + get "/schemes?search=#{search_param}" end it "returns matching results" do @@ -155,7 +155,7 @@ RSpec.describe SchemesController, type: :request do end 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 @@ -166,7 +166,7 @@ RSpec.describe SchemesController, type: :request do context "when not signed in" 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") end end @@ -176,7 +176,7 @@ RSpec.describe SchemesController, type: :request do before do sign_in user - get "/supported-housing/#{specific_scheme.id}" + get "/schemes/#{specific_scheme.id}" end it "returns 401 unauthorized" do @@ -194,7 +194,7 @@ RSpec.describe SchemesController, type: :request do end 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.service_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) 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) } 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) end end @@ -225,7 +225,7 @@ RSpec.describe SchemesController, type: :request do before do allow(user).to receive(:need_two_factor_authentication?).and_return(false) sign_in user - get "/supported-housing/#{specific_scheme.id}" + get "/schemes/#{specific_scheme.id}" end it "has page heading" do @@ -246,4 +246,199 @@ RSpec.describe SchemesController, type: :request do 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 1 to 20 of #{locations.count} 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 21 to 25 of #{locations.count} 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 1 to 20 of #{locations.count} 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 21 to 25 of #{locations.count} 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