Browse Source

CLDC-1249 supported housing scheme (#705)

* Introduce scheme and location pages
* Derive single scheme location
* Reset location when a scheme is changed

Co-authored-by: Dushan Despotovic <dushan@madetech.com>
Co-authored-by: Katrina Kosiak <katrina@madetech.com>
pull/710/head v0.1.24
Stéphane Meny 3 years ago committed by GitHub
parent
commit
805107c413
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 27
      app/frontend/styles/_accessible-autocomplete.scss
  2. 6
      app/models/case_log.rb
  3. 10
      app/models/derived_variables/case_log_variables.rb
  4. 19
      app/models/form/setup/pages/location.rb
  5. 6
      app/models/form/setup/pages/rent_type.rb
  6. 18
      app/models/form/setup/pages/scheme.rb
  7. 38
      app/models/form/setup/questions/location_id.rb
  8. 2
      app/models/form/setup/questions/needs_type.rb
  9. 40
      app/models/form/setup/questions/scheme_id.rb
  10. 2
      app/models/form/setup/subsections/setup.rb
  11. 2
      app/views/schemes/locations.html.erb
  12. 5
      db/migrate/20220630154441_add_location_to_case_log.rb
  13. 8
      db/migrate/20220704135746_rename_location_name.rb
  14. 12
      db/schema.rb
  15. 9
      db/seeds.rb
  16. 3
      spec/factories/location.rb
  17. 4
      spec/features/log_spec.rb
  18. 2
      spec/helpers/tasklist_helper_spec.rb
  19. 17
      spec/models/case_log_spec.rb
  20. 37
      spec/models/form/setup/pages/location_spec.rb
  21. 33
      spec/models/form/setup/pages/scheme_spec.rb
  22. 37
      spec/models/form/setup/questions/location_id_spec.rb
  23. 4
      spec/models/form/setup/questions/needs_type_spec.rb
  24. 58
      spec/models/form/setup/questions/scheme_id_spec.rb
  25. 2
      spec/models/form/setup/subsections/setup_spec.rb
  26. 2
      spec/models/form_handler_spec.rb
  27. 8
      spec/models/form_spec.rb
  28. 6
      spec/requests/schemes_controller_spec.rb

27
app/frontend/styles/_accessible-autocomplete.scss

@ -1,9 +1,27 @@
.autocomplete__wrapper, // Ensure the autocomplete uses the correct typeface
.autocomplete__input, .autocomplete__wrapper {
.autocomplete__hint {
font-family: $govuk-font-family; font-family: $govuk-font-family;
} }
.autocomplete__input {
font-family: inherit;
}
.autocomplete__option__append {
font-weight: bold;
}
.autocomplete__option__hint {
display: block;
color: $govuk-secondary-text-colour;
.autocomplete__option--focused &,
.autocomplete__option:hover & {
color: govuk-colour("white");
}
}
// Style the autocomplete if theres an error
.govuk-form-group--error { .govuk-form-group--error {
.autocomplete__input { .autocomplete__input {
border-color: $govuk-error-colour; border-color: $govuk-error-colour;
@ -15,6 +33,9 @@
} }
.autocomplete__dropdown-arrow-down { .autocomplete__dropdown-arrow-down {
// Ensure dropdown arrow can be clicked
// https://github.com/alphagov/accessible-autocomplete/issues/202
pointer-events: none; pointer-events: none;
// Ensure dropdown arrow can be seen
z-index: 0; z-index: 0;
} }

6
app/models/case_log.rb

@ -24,6 +24,7 @@ class CaseLog < ApplicationRecord
validates_with CaseLogValidator validates_with CaseLogValidator
before_validation :recalculate_start_year!, if: :startdate_changed? before_validation :recalculate_start_year!, if: :startdate_changed?
before_validation :reset_scheme_location!, if: :scheme_changed?
before_validation :process_postcode_changes!, if: :postcode_full_changed? before_validation :process_postcode_changes!, if: :postcode_full_changed?
before_validation :process_previous_postcode_changes!, if: :ppostcode_full_changed? before_validation :process_previous_postcode_changes!, if: :ppostcode_full_changed?
before_validation :reset_invalidated_dependent_fields! before_validation :reset_invalidated_dependent_fields!
@ -36,6 +37,7 @@ class CaseLog < ApplicationRecord
belongs_to :managing_organisation, class_name: "Organisation", optional: true belongs_to :managing_organisation, class_name: "Organisation", optional: true
belongs_to :created_by, class_name: "User", optional: true belongs_to :created_by, class_name: "User", optional: true
belongs_to :scheme, optional: true belongs_to :scheme, optional: true
belongs_to :location, optional: true
scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) } scope :filter_by_organisation, ->(org, _user = nil) { where(owning_organisation: org).or(where(managing_organisation: org)) }
scope :filter_by_status, ->(status, _user = nil) { where status: } scope :filter_by_status, ->(status, _user = nil) { where status: }
@ -688,4 +690,8 @@ private
def upcase_and_remove_whitespace(string) def upcase_and_remove_whitespace(string)
string.present? ? string.upcase.gsub(/\s+/, "") : string string.present? ? string.upcase.gsub(/\s+/, "") : string
end end
def reset_scheme_location!
self.location = nil
end
end end

10
app/models/derived_variables/case_log_variables.rb

@ -5,6 +5,12 @@ module DerivedVariables::CaseLogVariables
FeatureToggle.supported_housing_schemes_enabled? FeatureToggle.supported_housing_schemes_enabled?
end end
def scheme_has_multiple_locations?
return false unless scheme
scheme.locations.size > 1
end
def set_derived_fields! def set_derived_fields!
# TODO: Remove once we support parent/child relationships # TODO: Remove once we support parent/child relationships
self.managing_organisation_id ||= owning_organisation_id self.managing_organisation_id ||= owning_organisation_id
@ -60,6 +66,10 @@ module DerivedVariables::CaseLogVariables
self.hhtype = household_type self.hhtype = household_type
self.new_old = new_or_existing_tenant self.new_old = new_or_existing_tenant
self.vacdays = property_vacant_days self.vacdays = property_vacant_days
if is_supported_housing? && (scheme && scheme.locations.size == 1)
self.location = scheme.locations.first
end
end end
private private

19
app/models/form/setup/pages/location.rb

@ -0,0 +1,19 @@
class Form::Setup::Pages::Location < ::Form::Page
def initialize(_id, hsh, subsection)
super("location", hsh, subsection)
@header = ""
@description = ""
@questions = questions
@depends_on = [{
"supported_housing_schemes_enabled?" => true,
"needstype" => 2,
"scheme_has_multiple_locations?" => true,
}]
end
def questions
[
Form::Setup::Questions::LocationId.new(nil, nil, self),
]
end
end

6
app/models/form/setup/pages/rent_type.rb

@ -1,13 +1,11 @@
class Form::Setup::Pages::RentType < ::Form::Page class Form::Setup::Pages::RentType < ::Form::Page
def initialize(id, hsh, subsection) def initialize(_id, hsh, subsection)
super super("rent_type", hsh, subsection)
@id = "rent_type"
@header = "" @header = ""
@description = "" @description = ""
@questions = questions @questions = questions
@depends_on = [{ "supported_housing_schemes_enabled?" => true }] @depends_on = [{ "supported_housing_schemes_enabled?" => true }]
@derived = true @derived = true
@subsection = subsection
end end
def questions def questions

18
app/models/form/setup/pages/scheme.rb

@ -0,0 +1,18 @@
class Form::Setup::Pages::Scheme < ::Form::Page
def initialize(_id, hsh, subsection)
super("scheme", hsh, subsection)
@header = ""
@description = ""
@questions = questions
@depends_on = [{
"supported_housing_schemes_enabled?" => true,
"needstype" => 2,
}]
end
def questions
[
Form::Setup::Questions::SchemeId.new(nil, nil, self),
]
end
end

38
app/models/form/setup/questions/location_id.rb

@ -0,0 +1,38 @@
class Form::Setup::Questions::LocationId < ::Form::Question
def initialize(_id, hsh, page)
super("location_id", hsh, page)
@check_answer_label = "Location"
@header = "Which location is this log for?"
@hint_text = ""
@type = "radio"
@derived = true unless FeatureToggle.supported_housing_schemes_enabled?
@answer_options = answer_options
end
def answer_options
answer_opts = {}
return answer_opts unless ActiveRecord::Base.connected?
Location.select(:id, :postcode, :name).each_with_object(answer_opts) do |location, hsh|
hsh[location.id.to_s] = { "value" => location.postcode, "hint" => location.name }
hsh
end
end
def displayed_answer_options(case_log)
return {} unless case_log.scheme
scheme_location_ids = Location.where(scheme_id: case_log.scheme.id).map(&:id).map(&:to_s)
answer_options.select { |k, _v| scheme_location_ids.include?(k) }
end
def hidden_in_check_answers?(case_log, _current_user = nil)
!supported_housing_selected?(case_log)
end
private
def supported_housing_selected?(case_log)
case_log.needstype == 2
end
end

2
app/models/form/setup/questions/needs_type.rb

@ -7,7 +7,7 @@ class Form::Setup::Questions::NeedsType < ::Form::Question
@hint_text = "General needs housing includes both self-contained and shared housing without support or specific adaptations. Supported housing can include direct access hostels, group homes, residential care and nursing homes." @hint_text = "General needs housing includes both self-contained and shared housing without support or specific adaptations. Supported housing can include direct access hostels, group homes, residential care and nursing homes."
@type = "radio" @type = "radio"
@answer_options = ANSWER_OPTIONS @answer_options = ANSWER_OPTIONS
@derived = true @derived = true unless FeatureToggle.supported_housing_schemes_enabled?
@page = page @page = page
end end

40
app/models/form/setup/questions/scheme_id.rb

@ -0,0 +1,40 @@
class Form::Setup::Questions::SchemeId < ::Form::Question
def initialize(_id, hsh, page)
super("scheme_id", hsh, page)
@check_answer_label = "Scheme name"
@header = "What scheme is this log for?"
@hint_text = "Enter scheme name or postcode"
@type = "select"
@answer_options = answer_options
@derived = true unless FeatureToggle.supported_housing_schemes_enabled?
end
def answer_options
answer_opts = {}
return answer_opts unless ActiveRecord::Base.connected?
Scheme.select(:id, :service_name).each_with_object(answer_opts) do |scheme, hsh|
hsh[scheme.id.to_s] = scheme.service_name
hsh
end
end
def displayed_answer_options(case_log)
return {} unless case_log.created_by
user_org_scheme_ids = Scheme.select(:id).where(organisation_id: case_log.created_by.organisation_id).map(&:id)
answer_options.select do |k, _v|
user_org_scheme_ids.include?(k.to_i)
end
end
def hidden_in_check_answers?(case_log, _current_user = nil)
!supported_housing_selected?(case_log)
end
private
def supported_housing_selected?(case_log)
case_log.needstype == 2
end
end

2
app/models/form/setup/subsections/setup.rb

@ -12,6 +12,8 @@ class Form::Subsections::Setup < ::Form::Subsection
Form::Setup::Pages::Organisation.new(nil, nil, self), Form::Setup::Pages::Organisation.new(nil, nil, self),
Form::Setup::Pages::CreatedBy.new(nil, nil, self), Form::Setup::Pages::CreatedBy.new(nil, nil, self),
Form::Setup::Pages::NeedsType.new(nil, nil, self), Form::Setup::Pages::NeedsType.new(nil, nil, self),
Form::Setup::Pages::Scheme.new(nil, nil, self),
Form::Setup::Pages::Location.new(nil, nil, self),
Form::Setup::Pages::Renewal.new(nil, nil, self), Form::Setup::Pages::Renewal.new(nil, nil, self),
Form::Setup::Pages::TenancyStartDate.new(nil, nil, self), Form::Setup::Pages::TenancyStartDate.new(nil, nil, self),
Form::Setup::Pages::RentType.new(nil, nil, self), Form::Setup::Pages::RentType.new(nil, nil, self),

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

@ -18,7 +18,7 @@
<section class="x-govuk-summary-card govuk-!-margin-bottom-6"> <section class="x-govuk-summary-card govuk-!-margin-bottom-6">
<header class="x-govuk-summary-card__header"> <header class="x-govuk-summary-card__header">
<h2 class="x-govuk-summary-card__title"> <h2 class="x-govuk-summary-card__title">
<%= "#{location.address_line1}, #{location.address_line2}" %> <%= location.name %>
</h2> </h2>
</header> </header>
<div class="x-govuk-summary-card__body"> <div class="x-govuk-summary-card__body">

5
db/migrate/20220630154441_add_location_to_case_log.rb

@ -0,0 +1,5 @@
class AddLocationToCaseLog < ActiveRecord::Migration[7.0]
def change
add_reference :case_logs, :location, foreign_key: true
end
end

8
db/migrate/20220704135746_rename_location_name.rb

@ -0,0 +1,8 @@
class RenameLocationName < ActiveRecord::Migration[7.0]
def change
change_table :locations, bulk: true do |t|
t.rename :address_line1, :name
t.remove :address_line2, type: :string
end
end
end

12
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_29_105452) do ActiveRecord::Schema[7.0].define(version: 2022_07_04_135746) 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"
@ -191,15 +191,17 @@ ActiveRecord::Schema[7.0].define(version: 2022_06_29_105452) do
t.integer "joint" t.integer "joint"
t.bigint "created_by_id" t.bigint "created_by_id"
t.integer "illness_type_0" t.integer "illness_type_0"
t.integer "retirement_value_check"
t.integer "tshortfall_known" t.integer "tshortfall_known"
t.integer "sheltered" t.integer "sheltered"
t.integer "retirement_value_check"
t.integer "pregnancy_value_check" t.integer "pregnancy_value_check"
t.integer "hhtype" t.integer "hhtype"
t.integer "new_old" t.integer "new_old"
t.integer "vacdays" t.integer "vacdays"
t.bigint "scheme_id" t.bigint "scheme_id"
t.bigint "location_id"
t.index ["created_by_id"], name: "index_case_logs_on_created_by_id" t.index ["created_by_id"], name: "index_case_logs_on_created_by_id"
t.index ["location_id"], name: "index_case_logs_on_location_id"
t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id" t.index ["managing_organisation_id"], name: "index_case_logs_on_managing_organisation_id"
t.index ["old_id"], name: "index_case_logs_on_old_id", unique: true t.index ["old_id"], name: "index_case_logs_on_old_id", unique: true
t.index ["owning_organisation_id"], name: "index_case_logs_on_owning_organisation_id" t.index ["owning_organisation_id"], name: "index_case_logs_on_owning_organisation_id"
@ -241,8 +243,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_06_29_105452) do
t.string "type_of_building" t.string "type_of_building"
t.integer "wheelchair_adaptation" t.integer "wheelchair_adaptation"
t.bigint "scheme_id", null: false t.bigint "scheme_id", null: false
t.string "address_line1" t.string "name"
t.string "address_line2"
t.string "county" t.string "county"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
@ -251,7 +252,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_06_29_105452) do
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", precision: nil, null: false
t.integer "base_number", default: 1, null: false t.integer "base_number", default: 1, null: false
t.integer "increment_number", default: 1, null: false t.integer "increment_number", default: 1, null: false
t.boolean "empty_export", default: false, null: false t.boolean "empty_export", default: false, null: false
@ -369,6 +370,7 @@ ActiveRecord::Schema[7.0].define(version: 2022_06_29_105452) 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 "case_logs", "locations"
add_foreign_key "case_logs", "schemes" add_foreign_key "case_logs", "schemes"
add_foreign_key "locations", "schemes" add_foreign_key "locations", "schemes"
add_foreign_key "schemes", "organisations" add_foreign_key "schemes", "organisations"

9
db/seeds.rb

@ -116,8 +116,7 @@ unless Rails.env.test?
scheme: scheme1, scheme: scheme1,
location_code: "S254-CU193AA", location_code: "S254-CU193AA",
postcode: "CU19 3AA", postcode: "CU19 3AA",
address_line1: "Rectory Road", name: "Rectory Road",
address_line2: "North Chaim",
type_of_unit: "Self-contained flat or bedsit", type_of_unit: "Self-contained flat or bedsit",
type_of_building: "Purpose-built", type_of_building: "Purpose-built",
county: "Mid Sussex", county: "Mid Sussex",
@ -128,8 +127,7 @@ unless Rails.env.test?
scheme: scheme1, scheme: scheme1,
location_code: "S254-DM250DC", location_code: "S254-DM250DC",
postcode: "DM25 0DC", postcode: "DM25 0DC",
address_line1: "Smithy Lane", name: "Smithy Lane",
address_line2: "North Kellieworth",
type_of_unit: "Self-contained flat or bedsit with common facilities", type_of_unit: "Self-contained flat or bedsit with common facilities",
type_of_building: "Converted from previous residential or non-residential property", type_of_building: "Converted from previous residential or non-residential property",
county: "Fife", county: "Fife",
@ -140,8 +138,7 @@ unless Rails.env.test?
scheme: scheme2, scheme: scheme2,
location_code: "S254-YX130WP", location_code: "S254-YX130WP",
postcode: "YX13 0WP", postcode: "YX13 0WP",
address_line1: "Smithy Lane", name: "Smithy Lane",
address_line2: "East Darwin",
type_of_unit: "Shared house or hostel", type_of_unit: "Shared house or hostel",
type_of_building: "Converted from previous residential or non-residential property", type_of_building: "Converted from previous residential or non-residential property",
county: "Rochford", county: "Rochford",

3
spec/factories/location.rb

@ -2,8 +2,7 @@ FactoryBot.define do
factory :location do factory :location do
location_code { Faker::Name.initials(number: 10) } location_code { Faker::Name.initials(number: 10) }
postcode { Faker::Address.postcode.delete(" ") } postcode { Faker::Address.postcode.delete(" ") }
address_line1 { Faker::Address.street_name } name { Faker::Address.street_name }
address_line2 { Faker::Address.city }
type_of_unit { Faker::Lorem.word } type_of_unit { Faker::Lorem.word }
type_of_building { Faker::Lorem.word } type_of_building { Faker::Lorem.word }
wheelchair_adaptation { 0 } wheelchair_adaptation { 0 }

4
spec/features/log_spec.rb

@ -90,7 +90,7 @@ RSpec.describe "Log Features" do
visit("logs/#{log_id}/setup/check-answers") visit("logs/#{log_id}/setup/check-answers")
expect(page).to have_content("Owning organisation #{support_user.organisation.name}") expect(page).to have_content("Owning organisation #{support_user.organisation.name}")
expect(page).to have_content("User #{support_user.name}") expect(page).to have_content("User #{support_user.name}")
expect(page).to have_content("You have answered 2 of 7 questions") expect(page).to have_content("You have answered 2 of 8 questions")
end end
end end
end end
@ -120,7 +120,7 @@ RSpec.describe "Log Features" do
visit("logs/#{log_id}/setup/check-answers") visit("logs/#{log_id}/setup/check-answers")
expect(page).not_to have_content("Owning organisation #{support_user.organisation.name}") expect(page).not_to have_content("Owning organisation #{support_user.organisation.name}")
expect(page).not_to have_content("User #{support_user.name}") expect(page).not_to have_content("User #{support_user.name}")
expect(page).to have_content("You have answered 0 of 5 questions") expect(page).to have_content("You have answered 0 of 6 questions")
end end
end end
end end

2
spec/helpers/tasklist_helper_spec.rb

@ -2,7 +2,7 @@ require "rails_helper"
RSpec.describe TasklistHelper do RSpec.describe TasklistHelper do
let(:empty_case_log) { FactoryBot.create(:case_log) } let(:empty_case_log) { FactoryBot.create(:case_log) }
let(:case_log) { FactoryBot.create(:case_log, :in_progress) } let(:case_log) { FactoryBot.create(:case_log, :in_progress, needstype: 1) }
describe "get next incomplete section" do describe "get next incomplete section" do
it "returns the first subsection name if it is not completed" do it "returns the first subsection name if it is not completed" do

17
spec/models/case_log_spec.rb

@ -1678,6 +1678,23 @@ RSpec.describe CaseLog do
expect(case_log["tshortfall_known"]).to eq(0) expect(case_log["tshortfall_known"]).to eq(0)
end end
end end
context "when a case log is a supported housing log" do
before { case_log.needstype = 2 }
context "and a scheme with a single log is selected" do
let(:scheme) { FactoryBot.create(:scheme) }
let!(:location) { FactoryBot.create(:location, scheme:) }
before { case_log.update!(scheme:) }
it "derives the scheme location" do
record_from_db = ActiveRecord::Base.connection.execute("select location_id from case_logs where id=#{case_log.id}").to_a[0]
expect(record_from_db["location_id"]).to eq(location.id)
expect(case_log["location_id"]).to eq(location.id)
end
end
end
end end
describe "optional fields" do describe "optional fields" do

37
spec/models/form/setup/pages/location_spec.rb

@ -0,0 +1,37 @@
require "rails_helper"
RSpec.describe Form::Setup::Pages::Location, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[location_id])
end
it "has the correct id" do
expect(page.id).to eq("location")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has the correct depends_on" do
expect(page.depends_on).to eq([{
"supported_housing_schemes_enabled?" => true,
"needstype" => 2,
"scheme_has_multiple_locations?" => true,
}])
end
end

33
spec/models/form/setup/pages/scheme_spec.rb

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Setup::Pages::Scheme, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[scheme_id])
end
it "has the correct id" do
expect(page.id).to eq("scheme")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has the correct depends_on" do
expect(page.depends_on).to eq([{ "needstype" => 2, "supported_housing_schemes_enabled?" => true }])
end
end

37
spec/models/form/setup/questions/location_id_spec.rb

@ -0,0 +1,37 @@
require "rails_helper"
RSpec.describe Form::Setup::Questions::LocationId, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("location_id")
end
it "has the correct header" do
expect(question.header).to eq("Which location is this log for?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Location")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "is marked as derived" do
expect(question).not_to be_derived
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({})
end
end

4
spec/models/form/setup/questions/needs_type_spec.rb

@ -27,8 +27,8 @@ RSpec.describe Form::Setup::Questions::NeedsType, type: :model do
expect(question.type).to eq("radio") expect(question.type).to eq("radio")
end end
it "is marked as derived" do it "is not marked as derived" do
expect(question.derived?).to be true expect(question).not_to be_derived
end end
it "has the correct answer_options" do it "has the correct answer_options" do

58
spec/models/form/setup/questions/scheme_id_spec.rb

@ -0,0 +1,58 @@
require "rails_helper"
RSpec.describe Form::Setup::Questions::SchemeId, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("scheme_id")
end
it "has the correct header" do
expect(question.header).to eq("What scheme is this log for?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Scheme name")
end
it "has the correct type" do
expect(question.type).to eq("select")
end
it "has the correct hint_text" do
expect(question.hint_text).to eq("Enter scheme name or postcode")
end
it "has the correct conditional_for" do
expect(question.conditional_for).to be_nil
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
context "when a user is signed in" do
let(:organisation) { FactoryBot.create(:organisation) }
let(:organisation_2) { FactoryBot.create(:organisation) }
let(:user) { FactoryBot.create(:user, organisation_id: organisation.id) }
let(:scheme) { FactoryBot.create(:scheme, organisation_id: organisation.id) }
let(:case_log) { FactoryBot.create(:case_log, created_by: user) }
before do
FactoryBot.create(:scheme, organisation_id: organisation_2.id)
end
it "has the correct answer_options based on the schemes the user's organisation owns or manages" do
expected_answer = { scheme.id.to_s => scheme.service_name }
expect(question.displayed_answer_options(case_log)).to eq(expected_answer)
end
end
end

2
spec/models/form/setup/subsections/setup_spec.rb

@ -16,6 +16,8 @@ RSpec.describe Form::Setup::Subsections::Setup, type: :model do
%w[organisation %w[organisation
created_by created_by
needs_type needs_type
scheme
location
renewal renewal
tenancy_start_date tenancy_start_date
rent_type rent_type

2
spec/models/form_handler_spec.rb

@ -17,7 +17,7 @@ RSpec.describe FormHandler do
form_handler = described_class.instance form_handler = described_class.instance
form = form_handler.get_form(test_form_name) form = form_handler.get_form(test_form_name)
expect(form).to be_a(Form) expect(form).to be_a(Form)
expect(form.pages.count).to eq(42) expect(form.pages.count).to eq(44)
end end
end end

8
spec/models/form_spec.rb

@ -177,8 +177,10 @@ RSpec.describe Form, type: :model do
end end
describe "invalidated_page_questions" do describe "invalidated_page_questions" do
let(:case_log) { FactoryBot.create(:case_log, :in_progress, needstype: 1) }
context "when dependencies are not met" do context "when dependencies are not met" do
let(:expected_invalid) { %w[condition_effects cbl conditional_question_no_second_question net_income_value_check dependent_question offered layear declaration] } let(:expected_invalid) { %w[scheme_id location_id condition_effects cbl conditional_question_no_second_question net_income_value_check dependent_question offered layear declaration] }
it "returns an array of question keys whose pages conditions are not met" do it "returns an array of question keys whose pages conditions are not met" do
expect(form.invalidated_page_questions(case_log).map(&:id).uniq).to eq(expected_invalid) expect(form.invalidated_page_questions(case_log).map(&:id).uniq).to eq(expected_invalid)
@ -186,7 +188,7 @@ RSpec.describe Form, type: :model do
end end
context "with two pages having the same question and only one has dependencies met" do context "with two pages having the same question and only one has dependencies met" do
let(:expected_invalid) { %w[condition_effects cbl conditional_question_no_second_question net_income_value_check dependent_question offered layear declaration] } let(:expected_invalid) { %w[scheme_id location_id condition_effects cbl conditional_question_no_second_question net_income_value_check dependent_question offered layear declaration] }
it "returns an array of question keys whose pages conditions are not met" do it "returns an array of question keys whose pages conditions are not met" do
case_log["preg_occ"] = "No" case_log["preg_occ"] = "No"
@ -195,7 +197,7 @@ RSpec.describe Form, type: :model do
end end
context "when a question is marked as `derived` and `depends_on: false`" do context "when a question is marked as `derived` and `depends_on: false`" do
let(:case_log) { FactoryBot.build(:case_log, :in_progress, startdate: Time.utc(2023, 2, 2, 10, 36, 49)) } let(:case_log) { FactoryBot.build(:case_log, :in_progress, startdate: Time.utc(2022, 4, 2, 10, 36, 49)) }
it "does not count it's questions as invalidated" do it "does not count it's questions as invalidated" do
expect(form.enabled_page_questions(case_log).map(&:id).uniq).to include("tshortfall_known") expect(form.enabled_page_questions(case_log).map(&:id).uniq).to include("tshortfall_known")

6
spec/requests/schemes_controller_spec.rb

@ -316,8 +316,7 @@ RSpec.describe SchemesController, type: :request do
expect(page).to have_content(location.type_of_unit) expect(page).to have_content(location.type_of_unit)
expect(page).to have_content(location.type_of_building) expect(page).to have_content(location.type_of_building)
expect(page).to have_content(location.wheelchair_adaptation) expect(page).to have_content(location.wheelchair_adaptation)
expect(page).to have_content(location.address_line1) expect(page).to have_content(location.name)
expect(page).to have_content(location.address_line2)
end end
end end
@ -398,8 +397,7 @@ RSpec.describe SchemesController, type: :request do
expect(page).to have_content(location.type_of_unit) expect(page).to have_content(location.type_of_unit)
expect(page).to have_content(location.type_of_building) expect(page).to have_content(location.type_of_building)
expect(page).to have_content(location.wheelchair_adaptation) expect(page).to have_content(location.wheelchair_adaptation)
expect(page).to have_content(location.address_line1) expect(page).to have_content(location.name)
expect(page).to have_content(location.address_line2)
end end
end end

Loading…
Cancel
Save