Browse Source

feat: slight refactor, fix tag behaviour and add section tests

pull/1120/head
natdeanlewissoftwire 4 years ago
parent
commit
4aaafee1bd
  1. 4
      app/models/form/sales/questions/buyers_organisations.rb
  2. 2
      app/models/form/subsection.rb
  3. 1
      spec/models/form/sales/sections/household_spec.rb
  4. 34
      spec/models/form/sales/subsections/household_needs_spec copy.rb
  5. 34
      spec/models/form/sales/subsections/household_situation_spec.rb

4
app/models/form/sales/questions/buyers_organisations.rb

@ -11,8 +11,8 @@ class Form::Sales::Questions::BuyersOrganisations < ::Form::Question
end end
ANSWER_OPTIONS = { ANSWER_OPTIONS = {
"pregyrha" => { "value" => "Their private registered provider (PRP)- housing association" }, "pregyrha" => { "value" => "Their private registered provider (PRP) - housing association" },
"pregother" => { "value" => "Other private registered provider (PRP)- housing association" }, "pregother" => { "value" => "Other private registered provider (PRP) - housing association" },
"pregla" => { "value" => "Local Authority" }, "pregla" => { "value" => "Local Authority" },
"pregghb" => { "value" => "Help to Buy Agent" }, "pregghb" => { "value" => "Help to Buy Agent" },
}.freeze }.freeze

2
app/models/form/subsection.rb

@ -30,8 +30,8 @@ class Form::Subsection
qs = applicable_questions(log) qs = applicable_questions(log)
qs_optional_removed = qs.reject { |q| log.optional_fields.include?(q.id) } qs_optional_removed = qs.reject { |q| log.optional_fields.include?(q.id) }
return :not_started if qs.count.positive? && qs.all? { |question| log[question.id].blank? || question.read_only? || question.derived? }
return :completed if qs_optional_removed.all? { |question| question.completed?(log) } return :completed if qs_optional_removed.all? { |question| question.completed?(log) }
return :not_started if qs.count.positive? && qs.all? { |question| log[question.id].blank? || question.read_only? || question.derived? }
:in_progress :in_progress
end end

1
spec/models/form/sales/sections/household_spec.rb

@ -15,6 +15,7 @@ RSpec.describe Form::Sales::Sections::Household, type: :model do
expect(household.subsections.map(&:id)).to eq( expect(household.subsections.map(&:id)).to eq(
%w[ %w[
household_characteristics household_characteristics
household_situation
household_needs household_needs
], ],
) )

34
spec/models/form/sales/subsections/household_needs_spec copy.rb

@ -0,0 +1,34 @@
require "rails_helper"
RSpec.describe Form::Sales::Subsections::HouseholdNeeds, type: :model do
subject(:household_characteristics) { described_class.new(subsection_id, subsection_definition, section) }
let(:subsection_id) { nil }
let(:subsection_definition) { nil }
let(:section) { instance_double(Form::Sales::Sections::Household) }
it "has correct section" do
expect(household_characteristics.section).to eq(section)
end
it "has correct pages" do
expect(household_characteristics.pages.map(&:id)).to eq(
%w[
household_wheelchair
household_disability
],
)
end
it "has the correct id" do
expect(household_characteristics.id).to eq("household_needs")
end
it "has the correct label" do
expect(household_characteristics.label).to eq("Household needs")
end
it "has correct depends on" do
expect(household_characteristics.depends_on).to eq([{ "setup_completed?" => true }])
end
end

34
spec/models/form/sales/subsections/household_situation_spec.rb

@ -0,0 +1,34 @@
require "rails_helper"
RSpec.describe Form::Sales::Subsections::HouseholdSituation, type: :model do
subject(:household_characteristics) { described_class.new(subsection_id, subsection_definition, section) }
let(:subsection_id) { nil }
let(:subsection_definition) { nil }
let(:section) { instance_double(Form::Sales::Sections::Household) }
it "has correct section" do
expect(household_characteristics.section).to eq(section)
end
it "has correct pages" do
expect(household_characteristics.pages.map(&:id)).to eq(
%w[
household_wheelchair
household_disability
],
)
end
it "has the correct id" do
expect(household_characteristics.id).to eq("household_situation")
end
it "has the correct label" do
expect(household_characteristics.label).to eq("Household situation")
end
it "has correct depends on" do
expect(household_characteristics.depends_on).to eq([{ "setup_completed?" => true }])
end
end
Loading…
Cancel
Save