Browse Source

Merge branch 'main' into CLDC-1505-sales-buyer-working-situation

pull/932/head
Sam Collard 4 years ago
parent
commit
ddd797ee00
  1. 8
      app/frontend/controllers/conditional_question_controller.js
  2. 2
      app/helpers/question_attribute_helper.rb
  3. 16
      app/models/form/sales/pages/nationality1.rb
  4. 18
      app/models/form/sales/pages/privacy_notice.rb
  5. 30
      app/models/form/sales/questions/nationality1.rb
  6. 10
      app/models/form/sales/questions/other_nationality1.rb
  7. 18
      app/models/form/sales/questions/privacy_notice.rb
  8. 6
      app/models/form/sales/subsections/household_characteristics.rb
  9. 1
      app/views/form/guidance/_privacy_notice_buyer.erb
  10. 2
      app/views/form/guidance/_privacy_notice_tenant.erb
  11. 2
      config/forms/2021_2022.json
  12. 2
      config/forms/2022_2023.json
  13. 8
      db/migrate/20220927082602_add_national_column.rb
  14. 7
      db/migrate/20221004095132_add_privacy_notice_to_sales_log.rb
  15. 3
      db/schema.rb
  16. 1
      spec/factories/sales_log.rb
  17. 18
      spec/features/form/conditional_questions_spec.rb
  18. 4
      spec/helpers/question_attribute_helper_spec.rb
  19. 33
      spec/models/form/sales/pages/nationality1_spec.rb
  20. 33
      spec/models/form/sales/pages/privacy_notice_spec.rb
  21. 63
      spec/models/form/sales/questions/nationality1_spec.rb
  22. 37
      spec/models/form/sales/questions/other_nationality1_spec.rb
  23. 43
      spec/models/form/sales/questions/privacy_notice_spec.rb
  24. 6
      spec/models/form/sales/subsections/household_characteristics_spec.rb
  25. 4
      spec/models/form_handler_spec.rb

8
app/frontend/controllers/conditional_question_controller.js

@ -8,14 +8,16 @@ export default class extends Controller {
displayConditional () {
if (this.element.checked) {
const selectedValue = this.element.value
const conditionalFor = JSON.parse(this.element.dataset.info)
const dataInfo = JSON.parse(this.element.dataset.info)
const conditionalFor = dataInfo.conditional_questions
const logType = dataInfo.log_type
Object.entries(conditionalFor).forEach(([targetQuestion, conditions]) => {
if (!conditions.map(String).includes(String(selectedValue))) {
const textNumericInput = document.getElementById(`lettings-log-${targetQuestion.replaceAll('_', '-')}-field`)
const textNumericInput = document.getElementById(`${logType}-log-${targetQuestion.replaceAll('_', '-')}-field`)
if (textNumericInput == null) {
const dateInputs = [1, 2, 3].map((idx) => {
return document.getElementById(`lettings_log_${targetQuestion}_${idx}i`)
return document.getElementById(`${logType}_log_${targetQuestion}_${idx}i`)
})
this.clearDateInputs(dateInputs)
} else {

2
app/helpers/question_attribute_helper.rb

@ -27,7 +27,7 @@ private
{
"data-controller": "conditional-question",
"data-action": "click->conditional-question#displayConditional",
"data-info": question.conditional_for.to_json,
"data-info": { conditional_questions: question.conditional_for, log_type: question.form.type }.to_json,
}
end
end

16
app/models/form/sales/pages/nationality1.rb

@ -0,0 +1,16 @@
class Form::Sales::Pages::Nationality1 < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "buyer_1_nationality"
@header = ""
@description = ""
@subsection = subsection
end
def questions
@questions ||= [
Form::Sales::Questions::Nationality1.new(nil, nil, self),
Form::Sales::Questions::OtherNationality1.new(nil, nil, self),
]
end
end

18
app/models/form/sales/pages/privacy_notice.rb

@ -0,0 +1,18 @@
class Form::Sales::Pages::PrivacyNotice < ::Form::Page
def initialize(id, hsh, subsection)
super
@id = "privacy_notice"
@header = "Department for Levelling Up, Housing and Communities privacy notice"
@description = ""
@subsection = subsection
@depends_on = [{
"noint" => 1,
}]
end
def questions
@questions ||= [
Form::Sales::Questions::PrivacyNotice.new(nil, nil, self),
]
end
end

30
app/models/form/sales/questions/nationality1.rb

@ -0,0 +1,30 @@
class Form::Sales::Questions::Nationality1 < ::Form::Question
def initialize(id, hsh, page)
super
@id = "national"
@check_answer_label = "Buyer 1’s nationality"
@header = "What is buyer 1’s nationality?"
@type = "radio"
@hint_text = "Buyer 1 is the person in the household who does the most paid work. If it’s a joint purchase and the buyers do the same amount of paid work, buyer 1 is whoever is the oldest."
@page = page
@answer_options = ANSWER_OPTIONS
@conditional_for = {
"othernational" => [12],
}
@hidden_in_check_answers = {
"depends_on" => [
{
"national" => 12,
},
],
}
end
ANSWER_OPTIONS = {
"18" => { "value" => "United Kingdom" },
"17" => { "value" => "Republic of Ireland" },
"19" => { "value" => "European Economic Area (EEA), excluding ROI" },
"12" => { "value" => "Other" },
"13" => { "value" => "Buyer prefers not to say" },
}.freeze
end

10
app/models/form/sales/questions/other_nationality1.rb

@ -0,0 +1,10 @@
class Form::Sales::Questions::OtherNationality1 < ::Form::Question
def initialize(id, hsh, page)
super
@id = "othernational"
@check_answer_label = "Buyer 1’s nationality"
@header = "Nationality"
@type = "text"
@page = page
end
end

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

@ -0,0 +1,18 @@
class Form::Sales::Questions::PrivacyNotice < ::Form::Question
def initialize(id, hsh, page)
super
@id = "privacynotice"
@check_answer_label = "Buyer has seen the privacy notice?"
@header = "Declaration"
@type = "checkbox"
@hint_text = ""
@page = page
@answer_options = ANSWER_OPTIONS
@guidance_position = GuidancePosition::TOP
@guidance_partial = "privacy_notice_buyer"
end
ANSWER_OPTIONS = {
"privacynotice" => { "value" => "The buyer has seen the DLUHC privacy notice" },
}.freeze
end

6
app/models/form/sales/subsections/household_characteristics.rb

@ -10,17 +10,19 @@ class Form::Sales::Subsections::HouseholdCharacteristics < ::Form::Subsection
def pages
@pages ||= [
Form::Sales::Pages::BuyerInterview.new(nil, nil, self),
Form::Sales::Pages::PrivacyNotice.new(nil, nil, self),
Form::Sales::Pages::Age1.new(nil, nil, self),
Form::Sales::Pages::GenderIdentity1.new(nil, nil, self),
Form::Sales::Pages::Buyer1LiveInProperty.new(nil, nil, self),
Form::Sales::Pages::Buyer2RelationshipToBuyer1.new(nil, nil, self),
Form::Sales::Pages::Buyer1EthnicGroup.new(nil, nil, self),
Form::Sales::Pages::Buyer1EthnicBackgroundBlack.new(nil, nil, self),
Form::Sales::Pages::Buyer1EthnicBackgroundAsian.new(nil, nil, self),
Form::Sales::Pages::Buyer1EthnicBackgroundArab.new(nil, nil, self),
Form::Sales::Pages::Buyer1EthnicBackgroundMixed.new(nil, nil, self),
Form::Sales::Pages::Buyer1EthnicBackgroundWhite.new(nil, nil, self),
Form::Sales::Pages::Nationality1.new(nil, nil, self),
Form::Sales::Pages::Buyer1WorkingSituation.new(nil, nil, self),
Form::Sales::Pages::Buyer1LiveInProperty.new(nil, nil, self),
Form::Sales::Pages::Buyer2RelationshipToBuyer1.new(nil, nil, self),
Form::Sales::Pages::Age2.new(nil, nil, self),
Form::Sales::Pages::GenderIdentity2.new(nil, nil, self),
Form::Sales::Pages::Buyer2WorkingSituation.new(nil, nil, self),

1
app/views/form/guidance/_privacy_notice_buyer.erb

@ -0,0 +1 @@
<p class="govuk-body">Make sure the buyer has seen <%= govuk_link_to "the Department for Levelling Up, Housing & Communities (DLUHC) privacy notice", privacy_notice_path, target: :_blank %> before completing this log.</p>

2
app/views/form/guidance/_privacy_notice.erb → app/views/form/guidance/_privacy_notice_tenant.erb

@ -1 +1 @@
<p class="govuk-body">Make sure the tenant has seen <%= govuk_link_to "the Department for Levelling Up, Housing & Communities (DLUHC) privacy notice", privacy_notice_path %> before completing this log.</p>
<p class="govuk-body">Make sure the tenant has seen <%= govuk_link_to "the Department for Levelling Up, Housing & Communities (DLUHC) privacy notice", privacy_notice_path, target: :_blank %> before completing this log.</p>

2
config/forms/2021_2022.json

@ -1143,7 +1143,7 @@
"questions": {
"declaration": {
"header": "",
"guidance_partial": "privacy_notice",
"guidance_partial": "privacy_notice_tenant",
"check_answer_label": "Tenant has seen the privacy notice",
"check_answers_card_number": 0,
"type": "checkbox",

2
config/forms/2022_2023.json

@ -1178,7 +1178,7 @@
"questions": {
"declaration": {
"header": "",
"guidance_partial": "privacy_notice",
"guidance_partial": "privacy_notice_tenant",
"check_answer_label": "Tenant has seen the privacy notice",
"check_answers_card_number": 0,
"type": "checkbox",

8
db/migrate/20220927082602_add_national_column.rb

@ -0,0 +1,8 @@
class AddNationalColumn < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :national, :integer
t.column :othernational, :string
end
end
end

7
db/migrate/20221004095132_add_privacy_notice_to_sales_log.rb

@ -0,0 +1,7 @@
class AddPrivacyNoticeToSalesLog < ActiveRecord::Migration[7.0]
def change
change_table :sales_logs, bulk: true do |t|
t.column :privacynotice, :int
end
end
end

3
db/schema.rb

@ -352,6 +352,9 @@ ActiveRecord::Schema[7.0].define(version: 2022_10_04_184301) do
t.integer "buy2livein"
t.integer "ecstat2"
t.integer "ecstat1"
t.integer "national"
t.string "othernational"
t.integer "privacynotice"
t.index ["created_by_id"], name: "index_sales_logs_on_created_by_id"
t.index ["managing_organisation_id"], name: "index_sales_logs_on_managing_organisation_id"
t.index ["owning_organisation_id"], name: "index_sales_logs_on_owning_organisation_id"

1
spec/factories/sales_log.rb

@ -24,6 +24,7 @@ FactoryBot.define do
age1_known { 0 }
age1 { 30 }
sex1 { "X" }
national { 18 }
buy1livein { 1 }
relat2 { "P" }
proptype { 1 }

18
spec/features/form/conditional_questions_spec.rb

@ -12,6 +12,14 @@ RSpec.describe "Form Conditional Questions" do
managing_organisation: user.organisation,
)
end
let(:sales_log) do
FactoryBot.create(
:sales_log,
:completed,
owning_organisation: user.organisation,
managing_organisation: user.organisation,
)
end
let(:id) { lettings_log.id }
let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") }
@ -44,5 +52,15 @@ RSpec.describe "Form Conditional Questions" do
visit("/lettings-logs/#{id}/property-postcode")
expect(page).to have_field("lettings-log-postcode-full-field", with: "NW1 6RT")
end
it "gets cleared if the conditional question is hidden after editing the answer" do
sales_log.update!(national: 12, othernational: "other")
visit("/sales-logs/#{sales_log.id}/buyer-1-nationality")
expect(page).to have_field("sales-log-othernational-field", with: "other")
choose("sales-log-national-18-field", allow_label_click: true)
choose("sales-log-national-12-field", allow_label_click: true)
expect(page).to have_field("sales-log-othernational-field", with: "")
end
end
end

4
spec/helpers/question_attribute_helper_spec.rb

@ -40,7 +40,7 @@ RSpec.describe QuestionAttributeHelper do
"conditional_for" => {
"next_question": ">1",
},
}, nil)
}, form.get_page("rent"))
end
let(:expected_attribs) do
{
@ -48,7 +48,7 @@ RSpec.describe QuestionAttributeHelper do
"data-action": "input->numeric-question#calculateFields click->conditional-question#displayConditional",
"data-target": "lettings-log-#{question.result_field.to_s.dasherize}-field",
"data-calculated": question.fields_to_add.to_json,
"data-info": question.conditional_for.to_json,
"data-info": { conditional_questions: question.conditional_for, log_type: "lettings" }.to_json,
}
end

33
spec/models/form/sales/pages/nationality1_spec.rb

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::Nationality1, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[national othernational])
end
it "has the correct id" do
expect(page.id).to eq("buyer_1_nationality")
end
it "has the correct header" do
expect(page.header).to eq("")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to be_nil
end
end

33
spec/models/form/sales/pages/privacy_notice_spec.rb

@ -0,0 +1,33 @@
require "rails_helper"
RSpec.describe Form::Sales::Pages::PrivacyNotice, type: :model do
subject(:page) { described_class.new(page_id, page_definition, subsection) }
let(:page_id) { nil }
let(:page_definition) { nil }
let(:subsection) { instance_double(Form::Subsection) }
it "has correct subsection" do
expect(page.subsection).to eq(subsection)
end
it "has correct questions" do
expect(page.questions.map(&:id)).to eq(%w[privacynotice])
end
it "has the correct id" do
expect(page.id).to eq("privacy_notice")
end
it "has the correct header" do
expect(page.header).to eq("Department for Levelling Up, Housing and Communities privacy notice")
end
it "has the correct description" do
expect(page.description).to eq("")
end
it "has correct depends_on" do
expect(page.depends_on).to eq([{ "noint" => 1 }])
end
end

63
spec/models/form/sales/questions/nationality1_spec.rb

@ -0,0 +1,63 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::Nationality1, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("national")
end
it "has the correct header" do
expect(question.header).to eq("What is buyer 1’s nationality?")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 1’s nationality")
end
it "has the correct type" do
expect(question.type).to eq("radio")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint" do
expect(question.hint_text).to eq("Buyer 1 is the person in the household who does the most paid work. If it’s a joint purchase and the buyers do the same amount of paid work, buyer 1 is whoever is the oldest.")
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"18" => { "value" => "United Kingdom" },
"17" => { "value" => "Republic of Ireland" },
"19" => { "value" => "European Economic Area (EEA), excluding ROI" },
"12" => { "value" => "Other" },
"13" => { "value" => "Buyer prefers not to say" },
})
end
it "has correct conditional for" do
expect(question.conditional_for).to eq({
"othernational" => [12],
})
end
it "has correct hidden in check answers" do
expect(question.hidden_in_check_answers).to eq({
"depends_on" => [
{
"national" => 12,
},
],
})
end
end

37
spec/models/form/sales/questions/other_nationality1_spec.rb

@ -0,0 +1,37 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::OtherNationality1, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("othernational")
end
it "has the correct header" do
expect(question.header).to eq("Nationality")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer 1’s nationality")
end
it "has the correct type" do
expect(question.type).to eq("text")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint" do
expect(question.hint_text).to be_nil
end
end

43
spec/models/form/sales/questions/privacy_notice_spec.rb

@ -0,0 +1,43 @@
require "rails_helper"
RSpec.describe Form::Sales::Questions::PrivacyNotice, type: :model do
subject(:question) { described_class.new(question_id, question_definition, page) }
let(:question_id) { nil }
let(:question_definition) { nil }
let(:page) { instance_double(Form::Page) }
it "has correct page" do
expect(question.page).to eq(page)
end
it "has the correct id" do
expect(question.id).to eq("privacynotice")
end
it "has the correct header" do
expect(question.header).to eq("Declaration")
end
it "has the correct check_answer_label" do
expect(question.check_answer_label).to eq("Buyer has seen the privacy notice?")
end
it "has the correct type" do
expect(question.type).to eq("checkbox")
end
it "is not marked as derived" do
expect(question.derived?).to be false
end
it "has the correct hint" do
expect(question.hint_text).to eq("")
end
it "has the correct answer_options" do
expect(question.answer_options).to eq({
"privacynotice" => { "value" => "The buyer has seen the DLUHC privacy notice" },
})
end
end

6
spec/models/form/sales/subsections/household_characteristics_spec.rb

@ -15,17 +15,19 @@ RSpec.describe Form::Sales::Subsections::HouseholdCharacteristics, type: :model
expect(household_characteristics.pages.map(&:id)).to eq(
%w[
buyer_interview
privacy_notice
buyer_1_age
buyer_1_gender_identity
buyer_1_live_in_property
buyer_2_relationship_to_buyer_1
buyer_1_ethnic_group
buyer_1_ethnic_background_black
buyer_1_ethnic_background_asian
buyer_1_ethnic_background_arab
buyer_1_ethnic_background_mixed
buyer_1_ethnic_background_white
buyer_1_nationality
buyer_1_working_situation
buyer_1_live_in_property
buyer_2_relationship_to_buyer_1
buyer_2_age
buyer_2_gender_identity
buyer_2_working_situation

4
spec/models/form_handler_spec.rb

@ -61,14 +61,14 @@ RSpec.describe FormHandler do
it "is able to load a current sales form" do
form = form_handler.get_form("current_sales")
expect(form).to be_a(Form)
expect(form.pages.count).to eq(31)
expect(form.pages.count).to eq(33)
expect(form.name).to eq("2022_2023_sales")
end
it "is able to load a previous sales form" do
form = form_handler.get_form("previous_sales")
expect(form).to be_a(Form)
expect(form.pages.count).to eq(31)
expect(form.pages.count).to eq(33)
expect(form.name).to eq("2021_2022_sales")
end
end

Loading…
Cancel
Save