Browse Source

Changes introducing the scheme page

pull/705/head
Stéphane Meny 3 years ago
parent
commit
11deed057d
No known key found for this signature in database
GPG Key ID: 9D0AFEA988527923
  1. 27
      app/frontend/styles/_accessible-autocomplete.scss
  2. 20
      app/models/form/setup/pages/location.rb
  3. 4
      app/models/form/setup/pages/rent_type.rb
  4. 17
      app/models/form/setup/pages/scheme.rb
  5. 2
      app/models/form/setup/questions/needs_type.rb
  6. 25
      app/models/form/setup/questions/scheme_id.rb
  7. 1
      app/models/form/setup/subsections/setup.rb
  8. 33
      spec/models/form/setup/pages/scheme_spec.rb
  9. 52
      spec/models/form/setup/questions/scheme_id_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;
} }

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

@ -0,0 +1,20 @@
class Form::Setup::Pages::Location < ::Form::Page
def initialize(id, hsh, subsection)
super("location", hsh, subsection)
@header = ""
@description = ""
@questions = questions
# Only display if there is more than one location
@depends_on = [{
"supported_housing_schemes_enabled?" => true,
scheme.locations.size > 1 => true
}]
@derived = true
end
def questions
[
Form::Setup::Questions::SchemeId.new(nil, nil, self)
]
end
end

4
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

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

@ -0,0 +1,17 @@
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 }]
@derived = true
end
def questions
[
Form::Setup::Questions::SchemeId.new(nil, nil, self)
]
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

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

@ -0,0 +1,25 @@
class Form::Setup::Questions::SchemeId < ::Form::Question
def initialize(id, hsh, page)
super("scheme_id", hsh, page)
@header = "What scheme is this log for?"
@hint_text = "Enter scheme name or postcode"
@type = "select"
@answer_options = answer_options
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] = scheme.service_name
hsh
end
end
private
def selected_answer_option_is_derived?(_case_log)
false
end
end

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

@ -12,6 +12,7 @@ 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::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),

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])
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([{ "supported_housing_schemes_enabled?" => true }])
end
end

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

@ -0,0 +1,52 @@
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("Rent type")
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 "has the correct answer_options" do
expect(question.answer_options).to eq({
"1" => { "value" => "Affordable Rent" },
"2" => { "value" => "London Affordable Rent" },
"4" => { "value" => "London Living Rent" },
"3" => { "value" => "Rent to Buy" },
"0" => { "value" => "Social Rent" },
"5" => { "value" => "Other intermediate rent product" },
})
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
end
Loading…
Cancel
Save