Browse Source

CLDC-966-optional-setup-fields (#282)

* Add tenant_code and propcode as optional fields and consider subsection completed it they are not filled in'
pull/284/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
4fe1731705
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      app/models/case_log.rb
  2. 2
      app/models/constants/case_log.rb
  3. 4
      app/models/form/subsection.rb
  4. 4
      spec/features/form/check_answers_page_spec.rb
  5. 9
      spec/fixtures/forms/2021_2022.json
  6. 3
      spec/helpers/check_answers_helper_spec.rb
  7. 22
      spec/models/form/subsection_spec.rb
  8. 2
      spec/models/form_handler_spec.rb

1
app/models/case_log.rb

@ -144,7 +144,6 @@ class CaseLog < ApplicationRecord
enum declaration: POLAR, _suffix: true enum declaration: POLAR, _suffix: true
AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze AUTOGENERATED_FIELDS = %w[id status created_at updated_at discarded_at].freeze
OPTIONAL_FIELDS = %w[postcode_known la_known first_time_property_let_as_social_housing].freeze
def form def form
FormHandler.instance.get_form(form_name) FormHandler.instance.get_form(form_name)

2
app/models/constants/case_log.rb

@ -1123,4 +1123,6 @@ module Constants::CaseLog
"Sheltered accomodation", "Sheltered accomodation",
"Home Office Asylum Support", "Home Office Asylum Support",
"Other"].freeze "Other"].freeze
OPTIONAL_FIELDS = %w[postcode_known la_known first_time_property_let_as_social_housing tenant_code propcode].freeze
end end

4
app/models/form/subsection.rb

@ -1,4 +1,6 @@
class Form::Subsection class Form::Subsection
include Constants::CaseLog
attr_accessor :id, :label, :section, :pages, :depends_on, :form attr_accessor :id, :label, :section, :pages, :depends_on, :form
def initialize(id, hsh, section) def initialize(id, hsh, section)
@ -30,7 +32,7 @@ class Form::Subsection
return :cannot_start_yet return :cannot_start_yet
end end
qs = applicable_questions(case_log) qs = applicable_questions(case_log).reject { |q| OPTIONAL_FIELDS.include?(q.id) }
return :not_started if qs.all? { |question| case_log[question.id].blank? || question.read_only? } return :not_started if qs.all? { |question| case_log[question.id].blank? || question.read_only? }
return :completed if qs.all? { |question| question.completed?(case_log) } return :completed if qs.all? { |question| question.completed?(case_log) }

4
spec/features/form/check_answers_page_spec.rb

@ -38,7 +38,7 @@ RSpec.describe "Form Check Answers Page" do
end end
context "when the user needs to check their answers for a subsection" do context "when the user needs to check their answers for a subsection" do
let(:last_question_for_subsection) { "household-number-of-other-members" } let(:last_question_for_subsection) { "propcode" }
it "can be visited by URL" do it "can be visited by URL" do
visit("/logs/#{id}/#{subsection}/check-answers") visit("/logs/#{id}/#{subsection}/check-answers")
@ -46,7 +46,7 @@ RSpec.describe "Form Check Answers Page" do
end end
it "redirects to the check answers page when answering the last question and clicking save and continue" do it "redirects to the check answers page when answering the last question and clicking save and continue" do
fill_in_number_question(id, "other_hhmemb", 0, last_question_for_subsection) fill_in_number_question(id, "propcode", 0, last_question_for_subsection)
expect(page).to have_current_path("/logs/#{id}/#{subsection}/check-answers") expect(page).to have_current_path("/logs/#{id}/#{subsection}/check-answers")
end end

9
spec/fixtures/forms/2021_2022.json vendored

@ -104,6 +104,15 @@
} }
} }
} }
},
"propcode": {
"questions": {
"propcode": {
"check_answer_label": "",
"header": "property reference?",
"type": "text"
}
}
} }
} }
}, },

3
spec/helpers/check_answers_helper_spec.rb

@ -9,7 +9,7 @@ RSpec.describe CheckAnswersHelper do
context "when a section hasn't been completed yet" do context "when a section hasn't been completed yet" do
it "returns that you have unanswered questions" do it "returns that you have unanswered questions" do
expect(display_answered_questions_summary(subsection, case_log)) expect(display_answered_questions_summary(subsection, case_log))
.to match(/You have answered 2 of 4 questions./) .to match(/You have answered 2 of 5 questions./)
end end
end end
@ -17,6 +17,7 @@ RSpec.describe CheckAnswersHelper do
it "returns that you have answered all the questions" do it "returns that you have answered all the questions" do
case_log.sex1 = "F" case_log.sex1 = "F"
case_log.other_hhmemb = 0 case_log.other_hhmemb = 0
case_log.propcode = "123"
expect(display_answered_questions_summary(subsection, case_log)) expect(display_answered_questions_summary(subsection, case_log))
.to match(/You answered all the questions./) .to match(/You answered all the questions./)
expect(display_answered_questions_summary(subsection, case_log)) expect(display_answered_questions_summary(subsection, case_log))

22
spec/models/form/subsection_spec.rb

@ -1,4 +1,5 @@
require "rails_helper" require "rails_helper"
require_relative "../../request_helper"
RSpec.describe Form::Subsection, type: :model do RSpec.describe Form::Subsection, type: :model do
subject(:sub_section) { described_class.new(subsection_id, subsection_definition, section) } subject(:sub_section) { described_class.new(subsection_id, subsection_definition, section) }
@ -11,6 +12,10 @@ RSpec.describe Form::Subsection, type: :model do
let(:subsection_id) { "household_characteristics" } let(:subsection_id) { "household_characteristics" }
let(:subsection_definition) { section_definition["subsections"][subsection_id] } let(:subsection_definition) { section_definition["subsections"][subsection_id] }
before do
RequestHelper.stub_http_requests
end
it "has an id" do it "has an id" do
expect(sub_section.id).to eq(subsection_id) expect(sub_section.id).to eq(subsection_id)
end end
@ -20,12 +25,12 @@ RSpec.describe Form::Subsection, type: :model do
end end
it "has pages" do it "has pages" do
expected_pages = %w[tenant_code person_1_age person_1_gender household_number_of_other_members] expected_pages = %w[tenant_code person_1_age person_1_gender household_number_of_other_members propcode]
expect(sub_section.pages.map(&:id)).to eq(expected_pages) expect(sub_section.pages.map(&:id)).to eq(expected_pages)
end end
it "has questions" do it "has questions" do
expected_questions = %w[tenant_code age1 sex1 other_hhmemb relat2 age2 sex2 ecstat2] expected_questions = %w[tenant_code age1 sex1 other_hhmemb relat2 age2 sex2 ecstat2 propcode]
expect(sub_section.questions.map(&:id)).to eq(expected_questions) expect(sub_section.questions.map(&:id)).to eq(expected_questions)
end end
@ -53,9 +58,9 @@ RSpec.describe Form::Subsection, type: :model do
end end
it "has question helpers for the number of applicable questions" do it "has question helpers for the number of applicable questions" do
expected_questions = %w[tenant_code age1 sex1 other_hhmemb] expected_questions = %w[tenant_code age1 sex1 other_hhmemb propcode]
expect(sub_section.applicable_questions(case_log).map(&:id)).to eq(expected_questions) expect(sub_section.applicable_questions(case_log).map(&:id)).to eq(expected_questions)
expect(sub_section.applicable_questions_count(case_log)).to eq(4) expect(sub_section.applicable_questions_count(case_log)).to eq(5)
end end
it "has question helpers for the number of answered questions" do it "has question helpers for the number of answered questions" do
@ -72,18 +77,25 @@ RSpec.describe Form::Subsection, type: :model do
end end
it "has a question helpers for the unanswered questions" do it "has a question helpers for the unanswered questions" do
expected_questions = %w[sex1 other_hhmemb] expected_questions = %w[sex1 other_hhmemb propcode]
expect(sub_section.unanswered_questions(case_log).map(&:id)).to eq(expected_questions) expect(sub_section.unanswered_questions(case_log).map(&:id)).to eq(expected_questions)
end end
end end
context "with a completed case log" do context "with a completed case log" do
let(:case_log) { FactoryBot.build(:case_log, :completed) } let(:case_log) { FactoryBot.build(:case_log, :completed) }
let(:case_log_too) { FactoryBot.build(:case_log, :in_progress) }
it "has a status" do it "has a status" do
expect(sub_section.status(case_log)).to eq(:completed) expect(sub_section.status(case_log)).to eq(:completed)
end end
it "has a status when optional fields are not filled" do
case_log.update!({ propcode: nil })
case_log.reload
expect(sub_section.status(case_log)).to eq(:completed)
end
it "has status helpers" do it "has status helpers" do
expect(sub_section.is_incomplete?(case_log)).to be(false) expect(sub_section.is_incomplete?(case_log)).to be(false)
expect(sub_section.is_started?(case_log)).to be(true) expect(sub_section.is_started?(case_log)).to be(true)

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(28) expect(form.pages.count).to eq(29)
end end
end end

Loading…
Cancel
Save