Browse Source

CLDC-967: count inferred check answers answer as completed (#268)

* Count inferred check answers answer as an answered answer :)
and remove la unknown reason field

* rename the method and add a test for gdpr completed section

* remove commented code
pull/274/head
kosiakkatrina 3 years ago committed by GitHub
parent
commit
45a13428f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      app/models/form/question.rb
  2. 9
      config/forms/2021_2022.json
  3. 9
      db/migrate/20220203145845_remove_why_dont_you_know_la.rb
  4. 5
      db/schema.rb
  5. 2
      spec/features/form/check_answers_page_spec.rb
  6. 4
      spec/features/form/tasklist_page_spec.rb
  7. 1
      spec/fixtures/complete_case_log.json
  8. 38
      spec/fixtures/forms/2021_2022.json
  9. 4
      spec/helpers/tasklist_helper_spec.rb
  10. 26
      spec/models/form/question_spec.rb
  11. 9
      spec/models/form_spec.rb
  12. 4
      spec/requests/case_logs_controller_spec.rb

6
app/models/form/question.rb

@ -83,11 +83,15 @@ class Form::Question
return false if id == "gdpr_acceptance" && case_log[id] == "No"
return answer_options.keys.any? { |key| case_log[key] == "Yes" } if type == "checkbox"
case_log[id].present? || !case_log.respond_to?(id.to_sym)
case_log[id].present? || !case_log.respond_to?(id.to_sym) || has_inferred_display_value?(case_log)
end
private
def has_inferred_display_value?(case_log)
inferred_check_answers_value.present? && case_log[inferred_check_answers_value["condition"].keys.first] == inferred_check_answers_value["condition"].values.first
end
def checkbox_answer_label(case_log)
answer = []
answer_options.each { |key, value| case_log[key] == "Yes" ? answer << value : nil }

9
config/forms/2021_2022.json

@ -1716,16 +1716,7 @@
"answer_options": {
"1": "Yes",
"0": "No"
},
"conditional_for": {
"why_dont_you_know_la": ["No"]
}
},
"why_dont_you_know_la": {
"check_answer_label": "Reason you don’t know the postcode or local authority",
"header": "Give a reason why you don’t know the postcode or local authority",
"hint_text": "",
"type": "textarea"
}
},
"depends_on": [{ "is_la_inferred": false }]

9
db/migrate/20220203145845_remove_why_dont_you_know_la.rb

@ -0,0 +1,9 @@
class RemoveWhyDontYouKnowLa < ActiveRecord::Migration[7.0]
def up
remove_column :case_logs, :why_dont_you_know_la
end
def down
add_column :case_logs, :why_dont_you_know_la, :string
end
end

5
db/schema.rb

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2022_02_03_104800) do
ActiveRecord::Schema.define(version: 2022_02_03_145845) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -93,7 +93,6 @@ ActiveRecord::Schema.define(version: 2022_02_03_104800) do
t.integer "beds"
t.integer "offered"
t.integer "wchair"
t.integer "earnings"
t.integer "incfreq"
t.integer "benefits"
t.integer "period"
@ -162,7 +161,6 @@ ActiveRecord::Schema.define(version: 2022_02_03_104800) do
t.datetime "startdate"
t.integer "armedforces"
t.integer "first_time_property_let_as_social_housing"
t.string "why_dont_you_know_la"
t.integer "unitletas"
t.integer "builtype"
t.datetime "property_void_date"
@ -186,6 +184,7 @@ ActiveRecord::Schema.define(version: 2022_02_03_104800) do
t.integer "is_carehome"
t.integer "letting_in_sheltered_accomodation"
t.integer "household_charge"
t.integer "earnings"
t.integer "referral"
t.decimal "brent", precision: 10, scale: 2
t.decimal "scharge", precision: 10, scale: 2

2
spec/features/form/check_answers_page_spec.rb

@ -209,7 +209,7 @@ RSpec.describe "Form Check Answers Page" do
end
it "they can click a button to cycle around to the next incomplete section" do
visit("/logs/#{cycle_sections_case_log.id}/local-authority/check-answers")
visit("/logs/#{cycle_sections_case_log.id}/setup/check-answers")
click_link("Save and go to next incomplete section")
expect(page).to have_current_path("/logs/#{cycle_sections_case_log.id}/tenant-code")
end

4
spec/features/form/tasklist_page_spec.rb

@ -33,12 +33,12 @@ RSpec.describe "Task List" do
it "shows the number of completed sections if no sections are completed" do
visit("/logs/#{empty_case_log.id}")
expect(page).to have_content("You have completed 0 of 9 sections.")
expect(page).to have_content("You have completed 0 of 10 sections.")
end
it "shows the number of completed sections if one section is completed" do
answer_all_questions_in_income_subsection(empty_case_log)
visit("/logs/#{empty_case_log.id}")
expect(page).to have_content("You have completed 1 of 9 sections.")
expect(page).to have_content("You have completed 1 of 10 sections.")
end
end

1
spec/fixtures/complete_case_log.json vendored

@ -136,7 +136,6 @@
"postcod2": "w3",
"ppostc1": "w3",
"ppostc2": "w3",
"why_dont_you_know_la": "Forgot",
"first_time_property_let_as_social_housing": "No",
"unitletas": "Affordable rent basis",
"builtype": "Purpose built",

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

@ -593,18 +593,6 @@
}
}
},
"why_dont_you_know_la": {
"header": "",
"description": "",
"questions": {
"reason": {
"check_answer_label": "Reason for not knowing local authority",
"header": "Give a reason why you don’t know the postcode or local authority",
"hint_text": "",
"type": "textarea"
}
}
},
"property_postcode": {
"questions": {
"property_postcode": {
@ -638,6 +626,32 @@
}
}
},
"setup": {
"label": "Before you start",
"subsections": {
"setup": {
"label": "Set up your lettings log",
"pages": {
"gdpr_acceptance": {
"header": "",
"description": "",
"questions": {
"gdpr_acceptance": {
"check_answer_label": "Privacy notice seen",
"header": "Has the tenant or buyer seen the Department for Levelling Up, Housing and Communities (DLUHC) privacy notice?",
"hint_text": "You must <a class=\"govuk-link\" href=\"/files/privacy-notice.pdf\">show the privacy notice</a> to the tenant or buyer before you can use this service.",
"type": "radio",
"answer_options": {
"0": "Yes",
"1": "No"
}
}
}
}
}
}
}
},
"submission": {
"label": "Submission",
"subsections": {

4
spec/helpers/tasklist_helper_spec.rb

@ -22,7 +22,7 @@ RSpec.describe TasklistHelper do
describe "get sections count" do
it "returns the total of sections if no status is given" do
expect(get_subsections_count(empty_case_log)).to eq(9)
expect(get_subsections_count(empty_case_log)).to eq(10)
end
it "returns 0 sections for completed sections if no sections are completed" do
@ -30,7 +30,7 @@ RSpec.describe TasklistHelper do
end
it "returns the number of not started sections" do
expect(get_subsections_count(empty_case_log, :not_started)).to eq(8)
expect(get_subsections_count(empty_case_log, :not_started)).to eq(9)
end
it "returns the number of sections in progress" do

26
spec/models/form/question_spec.rb

@ -156,4 +156,30 @@ RSpec.describe Form::Question, type: :model do
end
end
end
describe ".completed?" do
context "when the question has inferred value only for check answers display" do
let(:section_id) { "tenancy_and_property" }
let(:subsection_id) { "property_information" }
let(:page_id) { "property_postcode" }
let(:question_id) { "property_postcode" }
it "returns true" do
case_log["postcode_known"] = "No"
expect(question.completed?(case_log)).to be(true)
end
end
context "when the gdpr acceptance is No" do
let(:section_id) { "setup" }
let(:subsection_id) { "setup" }
let(:page_id) { "gdpr_acceptance" }
let(:question_id) { "gdpr_acceptance" }
it "returns false" do
case_log["gdpr_acceptance"] = "No"
expect(question.completed?(case_log)).to be(false)
end
end
end
end

9
spec/models/form_spec.rb

@ -36,7 +36,7 @@ RSpec.describe Form, type: :model do
describe "next_incomplete_section_redirect_path" do
let(:case_log) { FactoryBot.build(:case_log, :in_progress) }
let(:subsection) { form.get_subsection("household_characteristics") }
let(:later_subsection) { form.get_subsection("local_authority") }
let(:later_subsection) { form.get_subsection("setup") }
context "when a user is on the check answers page for a subsection" do
def answer_household_needs(case_log)
@ -85,6 +85,10 @@ RSpec.describe Form, type: :model do
case_log.mrcdate = Time.zone.parse("03/11/2019")
end
def answer_local_gdpr_acceptance(case_log)
case_log.gdpr_acceptance = "Yes"
end
before do
case_log.tenant_code = "123"
case_log.age1 = 35
@ -108,7 +112,7 @@ RSpec.describe Form, type: :model do
end
it "returns the next incomplete section by cycling back around if next subsections are completed" do
answer_local_authority(case_log)
answer_local_gdpr_acceptance(case_log)
expect(form.next_incomplete_section_redirect_path(later_subsection, case_log)).to eq("armed-forces")
end
@ -124,6 +128,7 @@ RSpec.describe Form, type: :model do
answer_income_and_benefits(case_log)
answer_rent_and_charges(case_log)
answer_local_authority(case_log)
answer_local_gdpr_acceptance(case_log)
expect(form.next_incomplete_section_redirect_path(subsection, case_log)).to eq("declaration")
end

4
spec/requests/case_logs_controller_spec.rb

@ -200,7 +200,7 @@ RSpec.describe CaseLogsController, type: :request do
end
it "displays a section status for a case log" do
assert_select ".govuk-tag", text: /Not started/, count: 8
assert_select ".govuk-tag", text: /Not started/, count: 9
assert_select ".govuk-tag", text: /Completed/, count: 0
assert_select ".govuk-tag", text: /Cannot start yet/, count: 1
end
@ -222,7 +222,7 @@ RSpec.describe CaseLogsController, type: :request do
end
it "displays a section status for a case log" do
assert_select ".govuk-tag", text: /Not started/, count: 7
assert_select ".govuk-tag", text: /Not started/, count: 8
assert_select ".govuk-tag", text: /Completed/, count: 1
assert_select ".govuk-tag", text: /Cannot start yet/, count: 1
end

Loading…
Cancel
Save