Browse Source

Disaplay location name as an inferred answer (#750)

pull/754/head
kosiakkatrina 2 years ago committed by GitHub
parent
commit
d59d0569c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  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

@ -6,6 +6,11 @@ class Form::Setup::Questions::LocationId < ::Form::Question
@hint_text = "" @hint_text = ""
@type = "radio" @type = "radio"
@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