Browse Source

rename the method and add a test for gdpr completed section

pull/268/head
Kat 3 years ago
parent
commit
e96c7804ee
  1. 4
      app/models/form/question.rb
  2. 2
      spec/features/form/check_answers_page_spec.rb
  3. 4
      spec/features/form/tasklist_page_spec.rb
  4. 26
      spec/fixtures/forms/2021_2022.json
  5. 4
      spec/helpers/tasklist_helper_spec.rb
  6. 26
      spec/models/form/question_spec.rb
  7. 2
      spec/models/form_handler_spec.rb
  8. 11
      spec/models/form_spec.rb
  9. 4
      spec/requests/case_logs_controller_spec.rb

4
app/models/form/question.rb

@ -83,12 +83,12 @@ class Form::Question
return false if id == "gdpr_acceptance" && case_log[id] == "No" return false if id == "gdpr_acceptance" && case_log[id] == "No"
return answer_options.keys.any? { |key| case_log[key] == "Yes" } if type == "checkbox" return answer_options.keys.any? { |key| case_log[key] == "Yes" } if type == "checkbox"
case_log[id].present? || !case_log.respond_to?(id.to_sym) || has_inferred_value?(case_log) case_log[id].present? || !case_log.respond_to?(id.to_sym) || has_inferred_display_value?(case_log)
end end
private private
def has_inferred_value?(case_log) 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 inferred_check_answers_value.present? && case_log[inferred_check_answers_value["condition"].keys.first] == inferred_check_answers_value["condition"].values.first
end end

2
spec/features/form/check_answers_page_spec.rb

@ -209,7 +209,7 @@ RSpec.describe "Form Check Answers Page" do
end end
it "they can click a button to cycle around to the next incomplete section" do 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") click_link("Save and go to next incomplete section")
expect(page).to have_current_path("/logs/#{cycle_sections_case_log.id}/tenant-code") expect(page).to have_current_path("/logs/#{cycle_sections_case_log.id}/tenant-code")
end 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 it "shows the number of completed sections if no sections are completed" do
visit("/logs/#{empty_case_log.id}") 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 end
it "shows the number of completed sections if one section is completed" do it "shows the number of completed sections if one section is completed" do
answer_all_questions_in_income_subsection(empty_case_log) answer_all_questions_in_income_subsection(empty_case_log)
visit("/logs/#{empty_case_log.id}") 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
end end

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

@ -626,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": { "submission": {
"label": "Submission", "label": "Submission",
"subsections": { "subsections": {

4
spec/helpers/tasklist_helper_spec.rb

@ -22,7 +22,7 @@ RSpec.describe TasklistHelper do
describe "get sections count" do describe "get sections count" do
it "returns the total of sections if no status is given" 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 end
it "returns 0 sections for completed sections if no sections are completed" do it "returns 0 sections for completed sections if no sections are completed" do
@ -30,7 +30,7 @@ RSpec.describe TasklistHelper do
end end
it "returns the number of not started sections" do 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 end
it "returns the number of sections in progress" do 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 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 end

2
spec/models/form_handler_spec.rb

@ -17,7 +17,7 @@ RSpec.describe FormHandler do
form_handler = described_class.instance form_handler = described_class.instance
form = form_handler.get_form(test_form_name) form = form_handler.get_form(test_form_name)
expect(form).to be_a(Form) expect(form).to be_a(Form)
expect(form.pages.count).to eq(28) expect(form.pages.count).to eq(29)
end end
end end

11
spec/models/form_spec.rb

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

4
spec/requests/case_logs_controller_spec.rb

@ -200,7 +200,7 @@ RSpec.describe CaseLogsController, type: :request do
end end
it "displays a section status for a case log" do 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: /Completed/, count: 0
assert_select ".govuk-tag", text: /Cannot start yet/, count: 1 assert_select ".govuk-tag", text: /Cannot start yet/, count: 1
end end
@ -222,7 +222,7 @@ RSpec.describe CaseLogsController, type: :request do
end end
it "displays a section status for a case log" do 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: /Completed/, count: 1
assert_select ".govuk-tag", text: /Cannot start yet/, count: 1 assert_select ".govuk-tag", text: /Cannot start yet/, count: 1
end end

Loading…
Cancel
Save