Browse Source

Cldc 670 property information inferred answers (#190)

* Show inferred postcode

* Filter out the answers that were not inferred

* Refactor if statement

* Add a failing test for check answers page

* Do not show the postcode known question in check answers

* WIP - fix failing test

* Display inferred check answers value if the value is not set

* update test json

* Fix a check and method name

* Extract check for hiddent in check answers from displayed to the user

Co-authored-by: MadeTech Dushan <dushan@madetech.com>
pull/194/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
7be8e0e05f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      app/models/form/question.rb
  2. 6
      app/models/form/subsection.rb
  3. 5
      app/views/form/_check_answers_table.html.erb
  4. 149
      config/forms/2021_2022.json
  5. 9
      spec/fixtures/forms/2021_2022.json
  6. 38
      spec/requests/case_log_controller_spec.rb

30
app/models/form/question.rb

@ -1,7 +1,8 @@
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
:conditional_for, :readonly, :answer_options, :page, :check_answer_label,
:inferred_answers, :hidden_in_check_answers, :inferred_check_answers_value
def initialize(id, hsh, page)
@id = id
@ -18,6 +19,9 @@ class Form::Question
@readonly = hsh["readonly"]
@answer_options = hsh["answer_options"]
@conditional_for = hsh["conditional_for"]
@inferred_answers = hsh["inferred_answers"]
@inferred_check_answers_value = hsh["inferred_check_answers_value"]
@hidden_in_check_answers = hsh["hidden_in_check_answers"]
@page = page
end
@ -28,7 +32,15 @@ class Form::Question
return checkbox_answer_label(case_log) if type == "checkbox"
return case_log[id].strftime("%d %b %Y") if type == "date"
case_log[id].to_s
return case_log[id].to_s if case_log[id].present?
has_inferred_check_answers_value?(case_log) ? inferred_check_answers_value["value"] : ""
end
def get_inferred_answers(case_log)
return enabled_inferred_answers(inferred_answers, case_log).keys.map { |x| case_log[x].to_s } if inferred_answers
[]
end
def read_only?
@ -41,6 +53,16 @@ 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 has_inferred_check_answers_value?(case_log)
return inferred_check_answers_value["condition"].values[0] == case_log[inferred_check_answers_value["condition"].keys[0]] if inferred_check_answers_value.present?
false
end
def update_answer_link_name(case_log)
if type == "checkbox"
answer_options.keys.any? { |key| case_log[key] == "Yes" } ? "Change" : "Answer"
@ -82,4 +104,8 @@ private
raise "Not implemented yet"
end
end
def enabled_inferred_answers(inferred_answers, case_log)
inferred_answers.filter { |_key, value| value.all? { |condition_key, condition_value| case_log[condition_key] == condition_value } }
end
end

6
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| (displayed_to_user?(case_log, q) && !q.hidden_in_check_answers?) || q.has_inferred_check_answers_value?(case_log) }
end
def answered_questions(case_log)
@ -62,4 +62,8 @@ class Form::Subsection
def unanswered_questions(case_log)
applicable_questions(case_log) - answered_questions(case_log)
end
def displayed_to_user?(case_log, question)
question.page.routed_to?(case_log) && question.enabled?(case_log)
end
end

5
app/views/form/_check_answers_table.html.erb

@ -3,7 +3,10 @@
<%= question.check_answer_label.to_s.present? ? question.check_answer_label.to_s : question.header.to_s %>
<dt>
<dd class="govuk-summary-list__value">
<%= question.answer_label(@case_log) %>
<%= question.answer_label(@case_log) %> <br/>
<% question.get_inferred_answers(@case_log).each do |inferred_answer| %>
<span class="govuk-!-font-weight-regular app-!-colour-muted"><%= inferred_answer %></span><br/>
<% end %>
</dd>
<dd class="govuk-summary-list__actions">
<%= govuk_link_to(question.update_answer_link_name(@case_log), "/logs/#{@case_log.id}/#{question.page.id.to_s.dasherize}").html_safe %>

149
config/forms/2021_2022.json

@ -29,8 +29,7 @@
"header": "You cannot use this service",
"hint_text": "",
"description": "We cannot accept data about a tenant or buyer unless they’ve seen the DLUHC privacy notice.",
"questions": {
},
"questions": {},
"depends_on": { "gdpr_acceptance": "No" }
},
"organisation_details": {
@ -92,7 +91,10 @@
}
}
},
"depends_on": { "gdpr_acceptance": "Yes", "sale_or_letting": "Letting" }
"depends_on": {
"gdpr_acceptance": "Yes",
"sale_or_letting": "Letting"
}
},
"startdate": {
"header": "",
@ -105,7 +107,10 @@
"type": "date"
}
},
"depends_on": { "gdpr_acceptance": "Yes", "sale_or_letting": "Letting" }
"depends_on": {
"gdpr_acceptance": "Yes",
"sale_or_letting": "Letting"
}
},
"about_this_letting": {
"header": "Tell us about this letting",
@ -125,7 +130,9 @@
"5": "Other intermediate rent product"
},
"conditional_for": {
"intermediate_rent_product_name": ["Other intermediate rent product"]
"intermediate_rent_product_name": [
"Other intermediate rent product"
]
}
},
"intermediate_rent_product_name": {
@ -144,7 +151,10 @@
}
}
},
"depends_on": { "gdpr_acceptance": "Yes", "sale_or_letting": "Letting" }
"depends_on": {
"gdpr_acceptance": "Yes",
"sale_or_letting": "Letting"
}
},
"tenant_code": {
"header": "",
@ -158,7 +168,10 @@
"width": 10
}
},
"depends_on": { "gdpr_acceptance": "Yes", "sale_or_letting": "Letting" }
"depends_on": {
"gdpr_acceptance": "Yes",
"sale_or_letting": "Letting"
}
},
"property_reference": {
"header": "",
@ -185,7 +198,10 @@
"type": "date"
}
},
"depends_on": { "gdpr_acceptance": "Yes", "sale_or_letting": "Sale" }
"depends_on": {
"gdpr_acceptance": "Yes",
"sale_or_letting": "Sale"
}
},
"purchaser_code": {
"header": "",
@ -199,7 +215,10 @@
"width": 10
}
},
"depends_on": { "gdpr_acceptance": "Yes", "sale_or_letting": "Sale" }
"depends_on": {
"gdpr_acceptance": "Yes",
"sale_or_letting": "Sale"
}
}
}
}
@ -210,7 +229,7 @@
"subsections": {
"household_characteristics": {
"label": "Household characteristics",
"depends_on": {"about_this_log": "completed"},
"depends_on": { "about_this_log": "completed" },
"pages": {
"person_1_age": {
"header": "",
@ -302,7 +321,7 @@
"10": "Romania",
"11": "Ireland",
"12": "Slovakia",
"13":"Slovenia",
"13": "Slovenia",
"14": "Croatia",
"15": "Other EU Economic Area (EEA country)",
"16": "Any other country",
@ -759,7 +778,7 @@
},
"household_situation": {
"label": "Household situation",
"depends_on": {"about_this_log": "completed"},
"depends_on": { "about_this_log": "completed" },
"pages": {
"previous_housing_situation": {
"header": "",
@ -885,7 +904,7 @@
},
"household_needs": {
"label": "Household needs",
"depends_on": {"about_this_log": "completed"},
"depends_on": { "about_this_log": "completed" },
"pages": {
"armed_forces": {
"header": "Experience of the UK Armed Forces",
@ -897,15 +916,19 @@
"type": "radio",
"check_answer_label": "Armed Forces",
"answer_options": {
"0":"A current or former regular in the UK Armed Forces (exc. National Service)",
"1":"A current or former reserve in the UK Armed Forces (exc. National Service)",
"0": "A current or former regular in the UK Armed Forces (exc. National Service)",
"1": "A current or former reserve in the UK Armed Forces (exc. National Service)",
"2": "A spouse / civil partner of a UK Armed Forces member who has separated or been bereaved within the last 2 years",
"3": "No",
"4": "Tenant prefers not to say"
},
"conditional_for": {
"leftreg": ["A current or former regular in the UK Armed Forces (exc. National Service)"],
"reservist": ["A current or former regular in the UK Armed Forces (exc. National Service)"]
"leftreg": [
"A current or former regular in the UK Armed Forces (exc. National Service)"
],
"reservist": [
"A current or former regular in the UK Armed Forces (exc. National Service)"
]
}
},
"leftreg": {
@ -1023,7 +1046,7 @@
"subsections": {
"tenancy_information": {
"label": "Tenancy information",
"depends_on": {"about_this_log": "completed"},
"depends_on": { "about_this_log": "completed" },
"pages": {
"starter_tenancy": {
"header": "",
@ -1121,14 +1144,20 @@
},
"conditional_for": {
"property_postcode": ["Yes"]
}
},
"hidden_in_check_answers": true
},
"property_postcode": {
"check_answer_label": "Postcode",
"header": "",
"hint_text": "",
"type": "text",
"width": 5
"width": 5,
"inferred_answers": { "la": { "is_la_inferred": true } },
"inferred_check_answers_value": {
"condition": { "postcode_known": "No" },
"value": "Not known"
}
}
}
},
@ -1147,7 +1176,7 @@
}
}
},
"depends_on": {"is_la_inferred": false}
"depends_on": { "is_la_inferred": false }
},
"select_local_authority": {
"header": "",
@ -1509,7 +1538,7 @@
}
}
},
"depends_on": { "tenant_same_property_renewal": "No"}
"depends_on": { "tenant_same_property_renewal": "No" }
},
"unitletas": {
"header": "",
@ -1528,7 +1557,10 @@
}
}
},
"depends_on": { "first_time_property_let_as_social_housing": "No", "tenant_same_property_renewal": "No" }
"depends_on": {
"first_time_property_let_as_social_housing": "No",
"tenant_same_property_renewal": "No"
}
},
"property_vacancy_reason_not_first_let": {
"header": "",
@ -1554,7 +1586,10 @@
}
}
},
"depends_on": { "first_time_property_let_as_social_housing": "No", "tenant_same_property_renewal": "No" }
"depends_on": {
"first_time_property_let_as_social_housing": "No",
"tenant_same_property_renewal": "No"
}
},
"property_vacancy_reason_first_let": {
"header": "",
@ -1572,7 +1607,10 @@
}
}
},
"depends_on": { "first_time_property_let_as_social_housing": "Yes", "tenant_same_property_renewal": "No" }
"depends_on": {
"first_time_property_let_as_social_housing": "Yes",
"tenant_same_property_renewal": "No"
}
},
"property_number_of_times_relet_not_social_let": {
"header": "",
@ -1588,7 +1626,10 @@
"step": 1
}
},
"depends_on": { "first_time_property_let_as_social_housing": "No", "tenant_same_property_renewal": "No" }
"depends_on": {
"first_time_property_let_as_social_housing": "No",
"tenant_same_property_renewal": "No"
}
},
"property_number_of_times_relet_social_let": {
"header": "",
@ -1604,7 +1645,10 @@
"step": 1
}
},
"depends_on": { "first_time_property_let_as_social_housing": "Yes", "tenant_same_property_renewal": "No" }
"depends_on": {
"first_time_property_let_as_social_housing": "Yes",
"tenant_same_property_renewal": "No"
}
},
"property_unit_type": {
"header": "",
@ -1687,7 +1731,10 @@
"type": "date"
}
},
"depends_on": { "rsnvac": "First let of newbuild property", "tenant_same_property_renewal": "No" }
"depends_on": {
"rsnvac": "First let of newbuild property",
"tenant_same_property_renewal": "No"
}
},
"new_build_handover_date": {
"header": "",
@ -1702,7 +1749,10 @@
},
"depends_on": {
"tenant_same_property_renewal": "No",
"rsnvac": ["First let of conversion, rehabilitation or acquired property?", "First let of leased property"]
"rsnvac": [
"First let of conversion, rehabilitation or acquired property?",
"First let of leased property"
]
}
},
"property_major_repairs": {
@ -1729,7 +1779,10 @@
"type": "date"
}
},
"depends_on": { "rsnvac": "First let of newbuild property", "tenant_same_property_renewal": "No"}
"depends_on": {
"rsnvac": "First let of newbuild property",
"tenant_same_property_renewal": "No"
}
}
}
}
@ -1740,7 +1793,7 @@
"subsections": {
"income_and_benefits": {
"label": "Income and benefits",
"depends_on": {"about_this_log": "completed"},
"depends_on": { "about_this_log": "completed" },
"pages": {
"net_income": {
"header": "",
@ -1834,7 +1887,7 @@
},
"rent": {
"label": "Rent",
"depends_on": {"about_this_log": "completed"},
"depends_on": { "about_this_log": "completed" },
"pages": {
"rent": {
"header": "",
@ -1865,12 +1918,7 @@
"type": "numeric",
"min": 0,
"step": 1,
"fields-to-add": [
"brent",
"scharge",
"pscharge",
"supcharg"
],
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"result-field": "tcharge"
},
"scharge": {
@ -1880,12 +1928,7 @@
"type": "numeric",
"min": 0,
"step": 1,
"fields-to-add": [
"brent",
"scharge",
"pscharge",
"supcharg"
],
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"result-field": "tcharge"
},
"pscharge": {
@ -1895,12 +1938,7 @@
"type": "numeric",
"min": 0,
"step": 1,
"fields-to-add": [
"brent",
"scharge",
"pscharge",
"supcharg"
],
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"result-field": "tcharge"
},
"supcharg": {
@ -1910,12 +1948,7 @@
"type": "numeric",
"min": 0,
"step": 1,
"fields-to-add": [
"brent",
"scharge",
"pscharge",
"supcharg"
],
"fields-to-add": ["brent", "scharge", "pscharge", "supcharg"],
"result-field": "tcharge"
},
"tcharge": {
@ -1960,7 +1993,7 @@
"subsections": {
"local_authority": {
"label": "Local authority",
"depends_on": {"about_this_log": "completed"},
"depends_on": { "about_this_log": "completed" },
"pages": {
"time_lived_in_la": {
"header": "",
@ -2428,7 +2461,7 @@
"answer_options": {
"0": "Yes",
"1": "No",
"2": "Do not know"
"2": "Do not know"
},
"conditional_for": {
"reasonable_preference_reason": ["Yes"]

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

@ -251,7 +251,12 @@
"header": "",
"hint_text": "",
"type": "text",
"width": 5
"width": 5,
"inferred_answers": { "la": { "is_la_inferred": true } },
"inferred_check_answers_value": {
"condition": { "postcode_known": "No" },
"value": "Not known"
}
}
}
},
@ -600,7 +605,7 @@
"hint_text": "If the household has moved from settled accommodation immediately prior to being re-housed",
"type": "text",
"width": 5,
"conditional_for": { "faake_key": "fake_condition" }
"conditional_for": { "fake_key": "fake_condition" }
},
"previous_postcode": {
"check_answer_label": "Postcode of previous accomodation if the household has moved from settled accommodation",

38
spec/requests/case_log_controller_spec.rb

@ -240,6 +240,44 @@ RSpec.describe CaseLogsController, type: :request do
end
end
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: {})
sign_in user
end
it "shows the inferred postcode" do
case_log = FactoryBot.create(:case_log,
owning_organisation: organisation,
managing_organisation: organisation,
postcode_known: "Yes",
property_postcode: "P0 0ST")
id = case_log.id
get "/logs/#{id}/property-information/check-answers"
expected_inferred_answer = "<span class=\"govuk-!-font-weight-regular app-!-colour-muted\">Manchester</span>"
expect(CGI.unescape_html(response.body)).to include(expected_inferred_answer)
end
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)).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
describe "PATCH" do

Loading…
Cancel
Save