Browse Source

Disaplay location name as an inferred answer

pull/750/head
Kat 3 years ago
parent
commit
7689cc1ed7
  1. 7
      app/models/form/question.rb
  2. 5
      app/models/form/setup/questions/location_id.rb
  3. 19
      spec/features/form/check_answers_page_spec.rb

7
app/models/form/question.rb

@ -52,7 +52,12 @@ class Form::Question
return [] unless inferred_answers return [] unless inferred_answers
enabled_inferred_answers(inferred_answers, case_log).keys.map do |x| enabled_inferred_answers(inferred_answers, case_log).keys.map do |x|
form.get_question(x, case_log).label_from_value(case_log[x]) question = form.get_question(x, case_log)
if question.present?
question.label_from_value(case_log[x])
else
Array(x.to_s.split(".")).inject(case_log) { |o, a| o.present? ? o.public_send(*a) : "" }
end
end end
end end

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

@ -7,6 +7,11 @@ class Form::Setup::Questions::LocationId < ::Form::Question
@type = "radio" @type = "radio"
@derived = true unless FeatureToggle.supported_housing_schemes_enabled? @derived = true unless FeatureToggle.supported_housing_schemes_enabled?
@answer_options = answer_options @answer_options = answer_options
@inferred_answers = {
"location.name": {
"needstype": 2,
},
}
end end
def answer_options def answer_options

19
spec/features/form/check_answers_page_spec.rb

@ -6,12 +6,18 @@ RSpec.describe "Form Check Answers Page" do
let(:user) { FactoryBot.create(:user) } let(:user) { FactoryBot.create(:user) }
let(:subsection) { "household-characteristics" } let(:subsection) { "household-characteristics" }
let(:conditional_subsection) { "conditional-question" } let(:conditional_subsection) { "conditional-question" }
let(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) }
let(:location) { FactoryBot.create(:location, scheme:) }
let(:case_log) do let(:case_log) do
FactoryBot.create( FactoryBot.create(
:case_log, :case_log,
:in_progress, :in_progress,
owning_organisation: user.organisation, owning_organisation: user.organisation,
managing_organisation: user.organisation, managing_organisation: user.organisation,
needstype: 2,
scheme:,
location:,
) )
end end
let(:empty_case_log) do let(:empty_case_log) do
@ -127,6 +133,19 @@ RSpec.describe "Form Check Answers Page" do
end end
end end
context "when viewing setup section answers" do
before do
FactoryBot.create(:location, scheme:)
end
it "displays inferred postcode with the location id" do
case_log.update!(location:)
visit("/logs/#{id}/setup/check-answers")
expect(page).to have_content("Location")
expect(page).to have_content(location.name)
end
end
context "when the user changes their answer from check answer page" do context "when the user changes their answer from check answer page" do
it "routes back to check answers" do it "routes back to check answers" do
visit("/logs/#{empty_case_log.id}/accessibility-requirements") visit("/logs/#{empty_case_log.id}/accessibility-requirements")

Loading…
Cancel
Save