Browse Source

Refactor guidance to allow both top and bottom guidance at the same time

CLDC-2640-location-guidance
Kat 1 year ago
parent
commit
014045e5fc
  1. 2
      app/models/form/lettings/questions/declaration.rb
  2. 3
      app/models/form/lettings/questions/earnings.rb
  3. 3
      app/models/form/lettings/questions/net_income_known.rb
  4. 3
      app/models/form/lettings/questions/rent_type.rb
  5. 3
      app/models/form/lettings/questions/scheme_id.rb
  6. 3
      app/models/form/lettings/questions/voiddate.rb
  7. 15
      app/models/form/question.rb
  8. 3
      app/models/form/sales/questions/discounted_ownership_type.rb
  9. 3
      app/models/form/sales/questions/mortgage_lender.rb
  10. 3
      app/models/form/sales/questions/outright_ownership_type.rb
  11. 2
      app/models/form/sales/questions/privacy_notice.rb
  12. 3
      app/models/form/sales/questions/shared_ownership_type.rb
  13. 4
      app/views/form/_checkbox_question.html.erb
  14. 4
      app/views/form/_date_question.html.erb
  15. 4
      app/views/form/_numeric_output_question.html.erb
  16. 4
      app/views/form/_numeric_question.html.erb
  17. 4
      app/views/form/_radio_question.html.erb
  18. 4
      app/views/form/_select_question.html.erb
  19. 4
      app/views/form/_text_question.html.erb
  20. 4
      app/views/form/_textarea_question.html.erb
  21. 6
      config/forms/2021_2022.json
  22. 9
      config/forms/2022_2023.json
  23. 2
      spec/fixtures/forms/2021_2022.json
  24. 2
      spec/models/form/lettings/questions/rent_type_spec.rb
  25. 4
      spec/models/form/lettings/questions/voiddate_spec.rb
  26. 8
      spec/models/form/sales/questions/discounted_ownership_type_spec.rb
  27. 10
      spec/models/form/sales/questions/mortgage_lender_spec.rb
  28. 16
      spec/models/form/sales/questions/outright_ownership_type_spec.rb
  29. 8
      spec/models/form/sales/questions/shared_ownership_type_spec.rb

2
app/models/form/lettings/questions/declaration.rb

@ -6,7 +6,7 @@ class Form::Lettings::Questions::Declaration < ::Form::Question
@header = "Declaration"
@type = "checkbox"
@check_answers_card_number = 0
@guidance_partial = "privacy_notice_tenant"
@top_guidance_partial = "privacy_notice_tenant"
@answer_options = ANSWER_OPTIONS
@question_number = 30
end

3
app/models/form/lettings/questions/earnings.rb

@ -8,8 +8,7 @@ class Form::Lettings::Questions::Earnings < ::Form::Question
@width = 5
@check_answers_card_number = 0
@min = 0
@guidance_partial = "what_counts_as_income"
@guidance_position = GuidancePosition::TOP
@top_guidance_partial = "what_counts_as_income"
@hint_text = ""
@step = 0.01
@prefix = "£"

3
app/models/form/lettings/questions/net_income_known.rb

@ -6,8 +6,7 @@ class Form::Lettings::Questions::NetIncomeKnown < ::Form::Question
@header = "Do you know the household’s combined income after tax?"
@type = "radio"
@check_answers_card_number = 0
@guidance_partial = "what_counts_as_income"
@guidance_position = GuidancePosition::TOP
@top_guidance_partial = "what_counts_as_income"
@hint_text = ""
@answer_options = ANSWER_OPTIONS
@question_number = 86

3
app/models/form/lettings/questions/rent_type.rb

@ -5,8 +5,7 @@ class Form::Lettings::Questions::RentType < ::Form::Question
@check_answer_label = "Rent type"
@header = "What is the rent type?"
@type = "radio"
@guidance_partial = "rent_type_definitions"
@guidance_position = GuidancePosition::TOP
@top_guidance_partial = "rent_type_definitions"
@answer_options = ANSWER_OPTIONS
@conditional_for = { "irproduct_other" => [5] }
@question_number = 6

3
app/models/form/lettings/questions/scheme_id.rb

@ -6,8 +6,7 @@ class Form::Lettings::Questions::SchemeId < ::Form::Question
@hint_text = "Enter scheme name or postcode"
@type = "select"
@answer_options = answer_options
@guidance_position = GuidancePosition::BOTTOM
@guidance_partial = "scheme_selection"
@bottom_guidance_partial = "scheme_selection"
@question_number = 9
@inferred_answers = {
"location.name": {

3
app/models/form/lettings/questions/voiddate.rb

@ -7,7 +7,6 @@ class Form::Lettings::Questions::Voiddate < ::Form::Question
@type = "date"
@check_answers_card_number = 0
@question_number = 23
@guidance_partial = "void_date"
@guidance_position = GuidancePosition::BOTTOM
@bottom_guidance_partial = "void_date"
end
end

15
app/models/form/question.rb

@ -3,22 +3,17 @@ class Form::Question
:type, :min, :max, :step, :width, :fields_to_add, :result_field,
:conditional_for, :readonly, :answer_options, :page, :check_answer_label,
:inferred_answers, :hidden_in_check_answers, :inferred_check_answers_value,
:guidance_partial, :prefix, :suffix, :requires_js, :fields_added, :derived,
:top_guidance_partial, :bottom_guidance_partial, :prefix, :suffix, :requires_js, :fields_added, :derived,
:check_answers_card_number, :unresolved_hint_text, :question_number, :hide_question_number_on_page, :plain_label, :error_label
module GuidancePosition
TOP = 1
BOTTOM = 2
end
def initialize(id, hsh, page)
@id = id
@page = page
if hsh
@check_answer_label = hsh["check_answer_label"]
@header = hsh["header"]
@guidance_partial = hsh["guidance_partial"]
@guidance_position = hsh["guidance_position"] || GuidancePosition::TOP
@top_guidance_partial = hsh["top_guidance_partial"]
@bottom_guidance_partial = hsh["bottom_guidance_partial"]
@hint_text = hsh["hint_text"]
@type = hsh["type"]
@min = hsh["min"]
@ -232,11 +227,11 @@ class Form::Question
end
def top_guidance?
@guidance_partial && @guidance_position == GuidancePosition::TOP
@top_guidance_partial.present?
end
def bottom_guidance?
@guidance_partial && @guidance_position == GuidancePosition::BOTTOM
@bottom_guidance_partial.present?
end
def is_derived_or_has_inferred_check_answers_value?(log)

3
app/models/form/sales/questions/discounted_ownership_type.rb

@ -5,8 +5,7 @@ class Form::Sales::Questions::DiscountedOwnershipType < ::Form::Question
@check_answer_label = "Type of discounted ownership sale"
@header = "What is the type of discounted ownership sale?"
@type = "radio"
@guidance_partial = guidance_partial
@guidance_position = GuidancePosition::TOP
@top_guidance_partial = guidance_partial
@answer_options = ANSWER_OPTIONS
@question_number = 5
end

3
app/models/form/sales/questions/mortgage_lender.rb

@ -8,8 +8,7 @@ class Form::Sales::Questions::MortgageLender < ::Form::Question
@hint_text = ""
@page = page
@answer_options = ANSWER_OPTIONS
@guidance_position = GuidancePosition::BOTTOM
@guidance_partial = "mortgage_lender"
@bottom_guidance_partial = "mortgage_lender"
@ownershipsch = ownershipsch
@question_number = question_number
end

3
app/models/form/sales/questions/outright_ownership_type.rb

@ -5,8 +5,7 @@ class Form::Sales::Questions::OutrightOwnershipType < ::Form::Question
@check_answer_label = "Type of outright sale"
@header = "What is the type of outright sale?"
@type = "radio"
@guidance_partial = guidance_partial
@guidance_position = GuidancePosition::TOP
@top_guidance_partial = guidance_partial
@answer_options = ANSWER_OPTIONS
@conditional_for = {
"othtype" => [12],

2
app/models/form/sales/questions/privacy_notice.rb

@ -6,7 +6,7 @@ class Form::Sales::Questions::PrivacyNotice < ::Form::Question
@header = "Declaration"
@type = "checkbox"
@answer_options = ANSWER_OPTIONS
@guidance_partial = "privacy_notice_buyer"
@top_guidance_partial = "privacy_notice_buyer"
@question_number = 19
end

3
app/models/form/sales/questions/shared_ownership_type.rb

@ -5,8 +5,7 @@ class Form::Sales::Questions::SharedOwnershipType < ::Form::Question
@check_answer_label = "Type of shared ownership sale"
@header = "What is the type of shared ownership sale?"
@hint_text = "A shared ownership sale is when the purchaser buys up to 75% of the property value and pays rent to the Private Registered Provider (PRP) on the remaining portion"
@guidance_partial = guidance_partial
@guidance_position = GuidancePosition::TOP
@top_guidance_partial = guidance_partial
@type = "radio"
@answer_options = answer_options
@question_number = 4

4
app/views/form/_checkbox_question.html.erb

@ -1,4 +1,4 @@
<%= render partial: "form/guidance/#{question.guidance_partial}" if question.top_guidance? %>
<%= render partial: "form/guidance/#{question.top_guidance_partial}" if question.top_guidance? %>
<%= f.govuk_check_boxes_fieldset question.id.to_sym,
caption: caption(caption_text, page_header, conditional),
@ -21,4 +21,4 @@
<% end %>
<% end %>
<%= render partial: "form/guidance/#{question.guidance_partial}" if question.bottom_guidance? %>
<%= render partial: "form/guidance/#{question.bottom_guidance_partial}" if question.bottom_guidance? %>

4
app/views/form/_date_question.html.erb

@ -1,4 +1,4 @@
<%= render partial: "form/guidance/#{question.guidance_partial}" if question.top_guidance? %>
<%= render partial: "form/guidance/#{question.top_guidance_partial}" if question.top_guidance? %>
<%= f.govuk_date_field question.id.to_sym,
caption: caption(caption_text, page_header, conditional),
@ -9,4 +9,4 @@
<%= govuk_inset_text(text: question.unresolved_hint_text) if question.unresolved_hint_text.present? && @log.unresolved %>
<% end %>
<%= render partial: "form/guidance/#{question.guidance_partial}" if question.bottom_guidance? %>
<%= render partial: "form/guidance/#{question.bottom_guidance_partial}" if question.bottom_guidance? %>

4
app/views/form/_numeric_output_question.html.erb

@ -1,4 +1,4 @@
<%= render partial: "form/guidance/#{question.guidance_partial}" if question.top_guidance? %>
<%= render partial: "form/guidance/#{question.top_guidance_partial}" if question.top_guidance? %>
<div class="govuk-form-group">
<label class="govuk-label govuk-label--<%= label_size(page_header, conditional, question) %>" for="lettings-log-<%= question.id %>-field">
@ -22,4 +22,4 @@
</div>
</div>
<%= render partial: "form/guidance/#{question.guidance_partial}" if question.bottom_guidance? %>
<%= render partial: "form/guidance/#{question.bottom_guidance_partial}" if question.bottom_guidance? %>

4
app/views/form/_numeric_question.html.erb

@ -1,4 +1,4 @@
<%= render partial: "form/guidance/#{question.guidance_partial}" if question.top_guidance? %>
<%= render partial: "form/guidance/#{question.top_guidance_partial}" if question.top_guidance? %>
<%= f.govuk_number_field(
question.id.to_sym,
@ -16,4 +16,4 @@
**stimulus_html_attributes(question),
) %>
<%= render partial: "form/guidance/#{question.guidance_partial}" if question.bottom_guidance? %>
<%= render partial: "form/guidance/#{question.bottom_guidance_partial}" if question.bottom_guidance? %>

4
app/views/form/_radio_question.html.erb

@ -1,4 +1,4 @@
<%= render partial: "form/guidance/#{question.guidance_partial}" if question.top_guidance? %>
<%= render partial: "form/guidance/#{question.top_guidance_partial}" if question.top_guidance? %>
<% banner = question.notification_banner(@log) %>
<% if banner %>
<%= govuk_notification_banner(
@ -44,4 +44,4 @@
<% end %>
<% end %>
<%= render partial: "form/guidance/#{question.guidance_partial}" if question.bottom_guidance? %>
<%= render partial: "form/guidance/#{question.bottom_guidance_partial}" if question.bottom_guidance? %>

4
app/views/form/_select_question.html.erb

@ -1,4 +1,4 @@
<%= render partial: "form/guidance/#{question.guidance_partial}" if question.top_guidance? %>
<%= render partial: "form/guidance/#{question.top_guidance_partial}" if question.top_guidance? %>
<% selected = @log.public_send(question.id) || "" %>
<% answers = question.displayed_answer_options(@log, current_user).map { |key, value| OpenStruct.new(id: key, name: value.respond_to?(:service_name) ? value.service_name : nil, resource: value) } %>
@ -17,4 +17,4 @@
<% end %>
<% end %>
<%= render partial: "form/guidance/#{question.guidance_partial}" if question.bottom_guidance? %>
<%= render partial: "form/guidance/#{question.bottom_guidance_partial}" if question.bottom_guidance? %>

4
app/views/form/_text_question.html.erb

@ -1,4 +1,4 @@
<%= render partial: "form/guidance/#{question.guidance_partial}" if question.top_guidance? %>
<%= render partial: "form/guidance/#{question.top_guidance_partial}" if question.top_guidance? %>
<%= f.govuk_text_field question.id.to_sym,
caption: caption(caption_text, page_header, conditional),
@ -7,4 +7,4 @@
width: question.width || nil,
**stimulus_html_attributes(question) %>
<%= render partial: "form/guidance/#{question.guidance_partial}" if question.bottom_guidance? %>
<%= render partial: "form/guidance/#{question.bottom_guidance_partial}" if question.bottom_guidance? %>

4
app/views/form/_textarea_question.html.erb

@ -1,4 +1,4 @@
<%= render partial: "form/guidance/#{question.guidance_partial}" if question.top_guidance? %>
<%= render partial: "form/guidance/#{question.top_guidance_partial}" if question.top_guidance? %>
<%= f.govuk_text_area question.id.to_sym,
caption: caption(caption_text, page_header, conditional),
@ -7,4 +7,4 @@
width: question.width || nil,
**stimulus_html_attributes(question) %>
<%= render partial: "form/guidance/#{question.guidance_partial}" if question.bottom_guidance? %>
<%= render partial: "form/guidance/#{question.bottom_guidance_partial}" if question.bottom_guidance? %>

6
config/forms/2021_2022.json

@ -1139,7 +1139,7 @@
"questions": {
"declaration": {
"header": "",
"guidance_partial": "privacy_notice_tenant",
"top_guidance_partial": "privacy_notice_tenant",
"check_answer_label": "Tenant has seen the privacy notice",
"check_answers_card_number": 0,
"type": "checkbox",
@ -7328,7 +7328,7 @@
"net_income_known": {
"check_answer_label": "Do you know the household’s combined income?",
"header": "Do you know the household’s combined income after tax?",
"guidance_partial": "what_counts_as_income",
"top_guidance_partial": "what_counts_as_income",
"hint_text": "",
"type": "radio",
"answer_options": {
@ -7360,7 +7360,7 @@
"earnings": {
"check_answer_label": "Total household income",
"header": "How much income does the household have in total?",
"guidance_partial": "what_counts_as_income",
"top_guidance_partial": "what_counts_as_income",
"hint_text": "",
"type": "numeric",
"min": 0,

9
config/forms/2022_2023.json

@ -721,8 +721,7 @@
"header": "What is the void date?",
"hint_text": "For example, 27 3 2021.",
"type": "date",
"guidance_partial": "void_date",
"guidance_position": 2
"bottom_guidance_partial": "void_date"
}
},
"depends_on": [
@ -1170,7 +1169,7 @@
"questions": {
"declaration": {
"header": "",
"guidance_partial": "privacy_notice_tenant",
"top_guidance_partial": "privacy_notice_tenant",
"check_answer_label": "Tenant has seen the privacy notice",
"check_answers_card_number": 0,
"type": "checkbox",
@ -7286,7 +7285,7 @@
"net_income_known": {
"check_answer_label": "Do you know the household’s combined income?",
"header": "Do you know the household’s combined income after tax?",
"guidance_partial": "what_counts_as_income",
"top_guidance_partial": "what_counts_as_income",
"hint_text": "",
"type": "radio",
"answer_options": {
@ -7318,7 +7317,7 @@
"earnings": {
"check_answer_label": "Total household income",
"header": "How much income does the household have in total?",
"guidance_partial": "what_counts_as_income",
"top_guidance_partial": "what_counts_as_income",
"hint_text": "",
"type": "numeric",
"min": 0,

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

@ -688,7 +688,7 @@
"earnings": {
"check_answer_label": "Income",
"header": "What is the tenant’s /and partner’s combined income after tax?",
"guidance_partial": "what_counts_as_income",
"top_guidance_partial": "what_counts_as_income",
"type": "numeric",
"min": 0,
"step": 1,

2
spec/models/form/lettings/questions/rent_type_spec.rb

@ -51,6 +51,6 @@ RSpec.describe Form::Lettings::Questions::RentType, type: :model do
end
it "has the guidance partial" do
expect(question.guidance_partial).to eq("rent_type_definitions")
expect(question.top_guidance_partial).to eq("rent_type_definitions")
end
end

4
spec/models/form/lettings/questions/voiddate_spec.rb

@ -31,8 +31,8 @@ RSpec.describe Form::Lettings::Questions::Voiddate, type: :model do
expect(question.question_number).to eq(23)
end
it "has the correct guidance_partial" do
expect(question.guidance_partial).to eq("void_date")
it "has the correct bottom_guidance_partial" do
expect(question.bottom_guidance_partial).to eq("void_date")
end
it "has the correct type" do

8
spec/models/form/sales/questions/discounted_ownership_type_spec.rb

@ -49,8 +49,8 @@ RSpec.describe Form::Sales::Questions::DiscountedOwnershipType, type: :model do
context "when the form is for 2023/24" do
let(:start_date) { Time.zone.local(2023, 4, 8) }
it "shows shows correct guidance_partial" do
expect(question.guidance_partial).to eq("discounted_ownership_type_definitions")
it "shows shows correct top_guidance_partial" do
expect(question.top_guidance_partial).to eq("discounted_ownership_type_definitions")
end
it "is at the top" do
@ -62,8 +62,8 @@ RSpec.describe Form::Sales::Questions::DiscountedOwnershipType, type: :model do
context "when the form is for before 2023/24" do
let(:start_date) { Time.zone.local(2022, 4, 8) }
it "does not show a guidance_partial" do
expect(question.guidance_partial).to eq(nil)
it "does not show a top_guidance_partial" do
expect(question.top_guidance_partial).to eq(nil)
end
end
end

10
spec/models/form/sales/questions/mortgage_lender_spec.rb

@ -31,13 +31,17 @@ RSpec.describe Form::Sales::Questions::MortgageLender, type: :model do
expect(question.derived?).to be false
end
it "is has correct guidance_position" do
it "is has correct guidance position" do
expect(question.top_guidance?).to be false
expect(question.bottom_guidance?).to be true
end
it "is has correct guidance_partial" do
expect(question.guidance_partial).to eq("mortgage_lender")
it "is has correct bottom_guidance_partial" do
expect(question.bottom_guidance_partial).to eq("mortgage_lender")
end
it "is has correct top_guidance_partial" do
expect(question.top_guidance_partial).to be_nil
end
it "has the correct answer_options" do

16
spec/models/form/sales/questions/outright_ownership_type_spec.rb

@ -50,8 +50,12 @@ RSpec.describe Form::Sales::Questions::OutrightOwnershipType, type: :model do
context "when the form is for year 2023/24" do
let(:start_date) { Time.zone.local(2023, 4, 8) }
it "has the correct guidance_partial" do
expect(question.guidance_partial).to eq("outright_sale_type_definitions")
it "has the correct top_guidance_partial" do
expect(question.top_guidance_partial).to eq("outright_sale_type_definitions")
end
it "has the correct bottom_guidance_partial" do
expect(question.bottom_guidance_partial).to be_nil
end
it "is at the top" do
@ -63,8 +67,12 @@ RSpec.describe Form::Sales::Questions::OutrightOwnershipType, type: :model do
context "when the form is for before year 2023/24" do
let(:start_date) { Time.zone.local(2022, 4, 8) }
it "does not display a guidance partial" do
expect(question.guidance_partial).to eq(nil)
it "does not display a top guidance partial" do
expect(question.top_guidance_partial).to eq(nil)
end
it "does not display a bottom guidance partial" do
expect(question.bottom_guidance_partial).to eq(nil)
end
end
end

8
spec/models/form/sales/questions/shared_ownership_type_spec.rb

@ -53,8 +53,8 @@ RSpec.describe Form::Sales::Questions::SharedOwnershipType, type: :model do
})
end
it "does not show a guidance_partial" do
expect(question.guidance_partial).to eq(nil)
it "does not show a top_guidance_partial" do
expect(question.top_guidance_partial).to eq(nil)
end
end
@ -74,8 +74,8 @@ RSpec.describe Form::Sales::Questions::SharedOwnershipType, type: :model do
})
end
it "shows shows correct guidance_partial" do
expect(question.guidance_partial).to eq("shared_ownership_type_definitions")
it "shows shows correct top_guidance_partial" do
expect(question.top_guidance_partial).to eq("shared_ownership_type_definitions")
end
end
end

Loading…
Cancel
Save