From d59d0569c6304aabf89c0768871872f65c5cfaf9 Mon Sep 17 00:00:00 2001 From: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Date: Tue, 19 Jul 2022 13:28:02 +0100 Subject: [PATCH] Disaplay location name as an inferred answer (#750) --- app/models/form/question.rb | 7 ++++++- .../form/setup/questions/location_id.rb | 5 +++++ spec/features/form/check_answers_page_spec.rb | 19 +++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/models/form/question.rb b/app/models/form/question.rb index 17d047cdb..088138e45 100644 --- a/app/models/form/question.rb +++ b/app/models/form/question.rb @@ -52,7 +52,12 @@ class Form::Question return [] unless inferred_answers 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 diff --git a/app/models/form/setup/questions/location_id.rb b/app/models/form/setup/questions/location_id.rb index b3ddfdb0c..d5a0976f7 100644 --- a/app/models/form/setup/questions/location_id.rb +++ b/app/models/form/setup/questions/location_id.rb @@ -6,6 +6,11 @@ class Form::Setup::Questions::LocationId < ::Form::Question @hint_text = "" @type = "radio" @answer_options = answer_options + @inferred_answers = { + "location.name": { + "needstype": 2, + }, + } end def answer_options diff --git a/spec/features/form/check_answers_page_spec.rb b/spec/features/form/check_answers_page_spec.rb index f3b9418a2..ef01fc81a 100644 --- a/spec/features/form/check_answers_page_spec.rb +++ b/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(:subsection) { "household-characteristics" } let(:conditional_subsection) { "conditional-question" } + let(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) } + let(:location) { FactoryBot.create(:location, scheme:) } + let(:case_log) do FactoryBot.create( :case_log, :in_progress, owning_organisation: user.organisation, managing_organisation: user.organisation, + needstype: 2, + scheme:, + location:, ) end let(:empty_case_log) do @@ -127,6 +133,19 @@ RSpec.describe "Form Check Answers Page" do 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 it "routes back to check answers" do visit("/logs/#{empty_case_log.id}/accessibility-requirements")