Browse Source

Do not show the postcode known question in check answers

pull/190/head
Kat 3 years ago
parent
commit
e6e9c42924
  1. 7
      app/models/form/question.rb
  2. 2
      app/models/form/subsection.rb
  3. 3
      config/forms/2021_2022.json
  4. 21
      spec/requests/case_log_controller_spec.rb

7
app/models/form/question.rb

@ -2,7 +2,7 @@ class Form::Question
attr_accessor :id, :header, :hint_text, :description, :questions,
:type, :min, :max, :step, :width, :fields_to_add, :result_field,
:conditional_for, :readonly, :answer_options, :page, :check_answer_label,
:inferred_answers
:inferred_answers, :hidden_in_check_answers
def initialize(id, hsh, page)
@id = id
@ -20,6 +20,7 @@ class Form::Question
@answer_options = hsh["answer_options"]
@conditional_for = hsh["conditional_for"]
@inferred_answers = hsh["inferred_answers"]
@hidden_in_check_answers = hsh["hidden_in_check_answers"]
@page = page
end
@ -49,6 +50,10 @@ class Form::Question
conditional_on.map { |condition| evaluate_condition(condition, case_log) }.all?
end
def hidden_in_check_answers?
hidden_in_check_answers
end
def update_answer_link_name(case_log)
if type == "checkbox"
answer_options.keys.any? { |key| case_log[key] == "Yes" } ? "Change" : "Answer"

2
app/models/form/subsection.rb

@ -52,7 +52,7 @@ class Form::Subsection
end
def applicable_questions(case_log)
questions.select { |q| q.page.routed_to?(case_log) && q.enabled?(case_log) }
questions.select { |q| q.page.routed_to?(case_log) && q.enabled?(case_log) && !q.hidden_in_check_answers? }
end
def answered_questions(case_log)

3
config/forms/2021_2022.json

@ -1144,7 +1144,8 @@
},
"conditional_for": {
"property_postcode": ["Yes"]
}
},
"hidden_in_check_answers": true
},
"property_postcode": {
"check_answer_label": "Postcode",

21
spec/requests/case_log_controller_spec.rb

@ -242,6 +242,14 @@ RSpec.describe CaseLogsController, type: :request do
end
context "Check answers" do
let(:postcode_case_log) do
FactoryBot.create(:case_log,
owning_organisation: organisation,
managing_organisation: organisation,
postcode_known: "No")
end
let(:id) { postcode_case_log.id }
before do
stub_request(:get, /api.postcodes.io/)
.to_return(status: 200, body: "{\"status\":200,\"result\":{\"admin_district\":\"Manchester\"}}", headers: {})
@ -260,16 +268,15 @@ RSpec.describe CaseLogsController, type: :request do
expect(CGI.unescape_html(response.body)).to include(expected_inferred_answer)
end
it "shows is the postcode is not known" do
case_log = FactoryBot.create(:case_log,
owning_organisation: organisation,
managing_organisation: organisation,
postcode_known: "No")
id = case_log.id
it "does not show do you know the property postcode question" do
get "/logs/#{id}/property-information/check-answers"
expect(CGI.unescape_html(response.body)).to include("Not known")
expect(CGI.unescape_html(response.body)).not_to include("Do you know the property postcode?")
end
it "shows if the postcode is not known" do
get "/logs/#{id}/property-information/check-answers"
expect(CGI.unescape_html(response.body)).to include("Not known")
end
end
end

Loading…
Cancel
Save