9 changed files with 174 additions and 7 deletions
@ -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 |
@ -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 |
@ -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 |
@ -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 |
@ -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…
Reference in new issue