Browse Source

CLDC-3499: Update check answers page spec for modern years

CLDC-3499-remove-pre-2025-tests
samyou-softwire 2 weeks ago
parent
commit
c740250d36
  1. 136
      spec/features/form/check_answers_page_lettings_logs_spec.rb

136
spec/features/form/check_answers_page_lettings_logs_spec.rb

@ -2,21 +2,13 @@ require "rails_helper"
require_relative "helpers"
RSpec.describe "Lettings Log Check Answers Page" do
around do |example|
Timecop.freeze(Time.zone.local(2021, 5, 1)) do
Singleton.__init__(FormHandler)
example.run
end
Timecop.return
Singleton.__init__(FormHandler)
end
include Helpers
include CollectionTimeHelper
let(:user) { FactoryBot.create(:user) }
let(:subsection) { "household-characteristics" }
let(:conditional_subsection) { "conditional-question" }
let(:subsection) { "household-needs" }
let(:scheme) { FactoryBot.create(:scheme, owning_organisation: user.organisation) }
let(:location) { FactoryBot.create(:location, scheme:, mobility_type: "N", startdate: Time.zone.local(2021, 4, 1)) }
let(:location) { FactoryBot.create(:location, scheme:, mobility_type: "N", startdate: current_collection_start_date) }
let(:lettings_log) do
FactoryBot.create(
@ -31,9 +23,7 @@ RSpec.describe "Lettings Log Check Answers Page" do
let(:empty_lettings_log) do
FactoryBot.create(
:lettings_log,
previous_la_known: 1,
prevloc: "E09000033",
is_previous_la_inferred: false,
:setup_completed,
assigned_to: user,
)
end
@ -44,21 +34,17 @@ RSpec.describe "Lettings Log Check Answers Page" do
owning_organisation: user.organisation,
managing_organisation: user.organisation,
assigned_to: user,
startdate: Time.zone.local(2021, 5, 1),
startdate: current_collection_start_date,
)
end
let(:id) { lettings_log.id }
let(:fake_2021_2022_form) { Form.new("spec/fixtures/forms/2021_2022.json") }
before do
allow(lettings_log.form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day)
allow(fake_2021_2022_form).to receive(:new_logs_end_date).and_return(Time.zone.today + 1.day)
sign_in user
allow(FormHandler.instance).to receive(:current_lettings_form).and_return(fake_2021_2022_form)
end
context "when the user needs to check their answers for a subsection" do
let(:last_question_for_subsection) { "propcode" }
let(:last_question_for_subsection) { "health-conditions" }
it "can be visited by URL" do
visit("/lettings-logs/#{id}/#{subsection}/check-answers")
@ -66,80 +52,46 @@ RSpec.describe "Lettings Log Check Answers Page" do
end
it "redirects to the check answers page when answering the last question and clicking save and continue" do
fill_in_number_question(id, "propcode", 0, last_question_for_subsection)
fill_in_radio_question(id, "illness", "2", last_question_for_subsection)
expect(page).to have_current_path("/lettings-logs/#{id}/#{subsection}/check-answers")
end
it "has question headings based on the subsection" do
visit("/lettings-logs/#{id}/#{subsection}/check-answers")
question_labels = ["Tenant code", "Lead tenant’s age", "Number of Household Members"]
question_labels = ["Household links to UK armed forces", "Anybody in household pregnant", "Anybody with disabled access needs", "Anybody in household with physical or mental health condition"]
question_labels.each do |label|
expect(page).to have_content(label)
end
end
it "displays answers given by the user for the question in the subsection" do
fill_in_number_question(empty_lettings_log.id, "age1", 28, "person-1-age")
choose("lettings-log-sex1-x-field")
click_button("Save and continue")
visit("/lettings-logs/#{empty_lettings_log.id}/#{subsection}/check-answers")
expect(page).to have_content("28")
expect(page).to have_content("Non-binary")
fill_in_radio_question(id, "armedforces", "3", "armed-forces")
fill_in_radio_question(id, "illness", "2", "health-conditions")
visit("/lettings-logs/#{id}/#{subsection}/check-answers")
expect(page).to have_content("No")
expect(page).to have_content("Person prefers not to say")
end
# Regex explanation: match the string "Answer" but not if it's follow by "the missing questions"
# This way only the links in the table will get picked up
it "has an answer link with the check_answers_new_answer referrer for questions missing an answer" do
visit("/lettings-logs/#{empty_lettings_log.id}/#{subsection}/check-answers?referrer=check_answers")
visit("/lettings-logs/#{id}/#{subsection}/check-answers?referrer=check_answers")
assert_selector "a", text: "Change", count: 0
expect(page).to have_link("Enter lead tenant’s age", href: "/lettings-logs/#{empty_lettings_log.id}/person-1-age?referrer=check_answers_new_answer")
expect(page).to have_link("Tell us if there are any household links to UK armed forces", href: "/lettings-logs/#{id}/armed-forces?referrer=check_answers_new_answer")
end
it "has a change link for answered question" do
fill_in_number_question(empty_lettings_log.id, "age1", 28, "person-1-age")
visit("/lettings-logs/#{empty_lettings_log.id}/#{subsection}/check-answers")
fill_in_radio_question(id, "armedforces", "2", "armed-forces")
visit("/lettings-logs/#{id}/#{subsection}/check-answers")
assert_selector "a", text: "Change", count: 1
expect(page).to have_link("Change", href: "/lettings-logs/#{empty_lettings_log.id}/person-1-age?referrer=check_answers")
expect(page).to have_link("Change", href: "/lettings-logs/#{id}/armed-forces?referrer=check_answers")
end
it "updates the add change link when answers get answered" do
visit("/lettings-logs/#{empty_lettings_log.id}/household-needs/check-answers")
visit("/lettings-logs/#{id}/household-needs/check-answers")
assert_selector "a", text: "Change", count: 0
fill_in_radio_question(id, "armedforces", "2", "armed-forces")
visit("/lettings-logs/#{id}/household-needs/check-answers")
assert_selector "a", text: "Change", count: 1
visit("/lettings-logs/#{empty_lettings_log.id}/accessibility-requirements")
check("lettings-log-accessibility-requirements-housingneeds-c-field")
click_button("Save and continue")
visit("/lettings-logs/#{empty_lettings_log.id}/household-needs/check-answers")
assert_selector "a", text: "Change", count: 2
expect(page).to have_link("Change", href: "/lettings-logs/#{empty_lettings_log.id}/accessibility-requirements?referrer=check_answers")
end
it "does not display conditional questions that were not visited" do
visit("/lettings-logs/#{id}/#{conditional_subsection}/check-answers")
question_labels = ["Has the condition been met?"]
question_labels.each do |label|
expect(page).to have_content(label)
end
excluded_question_labels = ["Has the next condition been met?", "Has the condition not been met?"]
excluded_question_labels.each do |label|
expect(page).not_to have_content(label)
end
end
it "displays conditional question that were visited" do
visit("/lettings-logs/#{id}/conditional-question")
choose("lettings-log-preg-occ-2-field", allow_label_click: true)
click_button("Save and continue")
visit("/lettings-logs/#{id}/#{conditional_subsection}/check-answers")
question_labels = ["Has the condition been met?", "Has the condition not been met?"]
question_labels.each do |label|
expect(page).to have_content(label)
end
excluded_question_labels = ["Has the next condition been met?"]
excluded_question_labels.each do |label|
expect(page).not_to have_content(label)
end
expect(page).to have_link("Change", href: "/lettings-logs/#{id}/armed-forces?referrer=check_answers")
end
it "does not group questions into summary cards if the questions in the subsection don't have a check_answers_card_number attribute" do
@ -149,7 +101,7 @@ RSpec.describe "Lettings Log Check Answers Page" do
context "when the user is checking their answers for the household characteristics subsection" do
it "they see a separate summary card for each member of the household" do
visit("/lettings-logs/#{completed_lettings_log.id}/#{subsection}/check-answers")
visit("/lettings-logs/#{completed_lettings_log.id}/household-characteristics/check-answers")
assert_selector ".govuk-summary-card__title", text: "Lead tenant", count: 1
assert_selector ".govuk-summary-card__title", text: "Person 2", count: 1
end
@ -157,7 +109,7 @@ RSpec.describe "Lettings Log Check Answers Page" do
context "when viewing setup section answers" do
before do
FactoryBot.create(:location, scheme:, startdate: Time.zone.local(2021, 1, 1))
FactoryBot.create(:location, scheme:, startdate: current_collection_start_date)
end
it "displays inferred postcode with the location id" do
@ -175,15 +127,12 @@ RSpec.describe "Lettings Log Check Answers Page" do
context "when the user changes their answer from check answer page" do
it "routes back to check answers" do
visit("/lettings-logs/#{empty_lettings_log.id}/accessibility-requirements")
check("lettings-log-accessibility-requirements-housingneeds-c-field")
click_button("Save and continue")
visit("/lettings-logs/#{empty_lettings_log.id}/household-needs/check-answers")
fill_in_radio_question(id, "armedforces", "2", "armed-forces")
visit("/lettings-logs/#{id}/household-needs/check-answers")
first("a", text: /Change/).click
uncheck("lettings-log-accessibility-requirements-housingneeds-c-field")
check("lettings-log-accessibility-requirements-housingneeds-b-field")
choose("lettings-log-armedforces-3-field")
click_button("Save changes")
expect(page).to have_current_path("/lettings-logs/#{empty_lettings_log.id}/household-needs/check-answers")
expect(page).to have_current_path("/lettings-logs/#{id}/household-needs/check-answers")
end
end
@ -224,10 +173,24 @@ RSpec.describe "Lettings Log Check Answers Page" do
sex1: "M",
hhmemb: 1,
armedforces: 3,
preg_occ: 2,
housingneeds: 2,
illness: 1,
housingneeds_h: 1,
la: "E06000014",
illness_type_1: 1,
layear: 2,
waityear: 7,
reason: 4,
prevten: 6,
homeless: 1,
ppostcode_full: "SE2 6RT",
previous_la_known: 1,
prevloc: "E07000105",
reasonpref: 1,
cbl: 0,
chr: 1,
cap: 0,
accessible_register: 0,
referral_type: 1,
)
end
@ -240,6 +203,7 @@ RSpec.describe "Lettings Log Check Answers Page" do
tenancycode: nil,
hhmemb: nil,
age1: nil,
age2: nil,
layear: 2,
waityear: 1,
postcode_full: "NW1 5TY",
@ -265,13 +229,13 @@ RSpec.describe "Lettings Log Check Answers Page" do
it "they can click a button to skip sections until the next incomplete section" do
visit("/lettings-logs/#{skip_section_lettings_log.id}/household-characteristics/check-answers")
click_link("Save and go to next incomplete section")
expect(page).to have_current_path("/lettings-logs/#{skip_section_lettings_log.id}/property-information/check-answers")
expect(page).to have_current_path("/lettings-logs/#{skip_section_lettings_log.id}/household-situation/check-answers")
end
it "they can click a button to cycle around to the next incomplete section" do
visit("/lettings-logs/#{cycle_sections_lettings_log.id}/declaration/check-answers")
visit("/lettings-logs/#{cycle_sections_lettings_log.id}/income-and-benefits/check-answers")
click_link("Save and go to next incomplete section")
expect(page).to have_current_path("/lettings-logs/#{cycle_sections_lettings_log.id}/tenant-code-test")
expect(page).to have_current_path("/lettings-logs/#{cycle_sections_lettings_log.id}/property-information/check-answers")
end
end
end

Loading…
Cancel
Save