diff --git a/spec/components/check_answers_summary_list_card_component_spec.rb b/spec/components/check_answers_summary_list_card_component_spec.rb index f2b300d57..241f1e547 100644 --- a/spec/components/check_answers_summary_list_card_component_spec.rb +++ b/spec/components/check_answers_summary_list_card_component_spec.rb @@ -5,103 +5,68 @@ RSpec.describe CheckAnswersSummaryListCardComponent, type: :component do let(:rendered) { render_inline(component) } - context "when before 23/24 collection" do - before do - Timecop.freeze(Time.zone.local(2023, 1, 10)) - Singleton.__init__(FormHandler) - end - - after do - Timecop.return - end - - context "when given a set of questions" do - let(:user) { build(:user) } - let(:log) { build(:lettings_log, :completed, age2: 99, startdate: Time.zone.local(2021, 5, 1)) } - let(:subsection_id) { "household_characteristics" } - let(:subsection) { log.form.get_subsection(subsection_id) } - let(:questions) { subsection.applicable_questions(log) } - - it "renders a summary list card without question numbers for the answers to those questions" do - expect(rendered).to have_content(questions.first.answer_label(log)) - expect(rendered).to have_content("Lead tenant’s age") - expect(rendered).not_to have_content("Q32 - Lead tenant’s age") - end - - it "applicable questions doesn't return questions that are hidden in check answers" do - expect(component.applicable_questions.map(&:id).include?("retirement_value_check")).to eq(false) - end - - it "has the correct answer label for a question" do - sex1_question = questions[2] - expect(component.get_answer_label(sex1_question)).to eq("Female") - end - - context "when log was created via a bulk upload and has an unanswered question" do - subject(:component) { described_class.new(questions:, log:, user:) } - - let(:bulk_upload) { create(:bulk_upload) } - let(:log) { build(:lettings_log, :in_progress, creation_method: "bulk upload", age2: 99, startdate: Time.zone.local(2021, 5, 1), bulk_upload:) } - - it "displays tweaked copy in red" do - expect(rendered).to have_selector("span", class: "app-!-colour-red", text: "You still need to answer this question") - end - end + let(:user) { create(:user) } + let(:log) { create(:lettings_log, :completed, age2: 99, retirement_value_check: 1) } + let(:subsection_id) { "household_characteristics" } + let(:subsection) { log.form.get_subsection(subsection_id) } + let(:questions) { subsection.applicable_questions(log) } + + it "renders a summary list card including question numbers for the answers to those questions" do + expect(rendered).to have_content(questions.first.answer_label(log)) + expect(rendered).to match(/Q\d+ - Lead tenant’s age/) + end - context "when log was imported with a bulk upload creation method, without bulk upload id and has an unanswered question" do - subject(:component) { described_class.new(questions:, log:, user:) } + it "applicable questions doesn't return questions that are hidden in check answers" do + expect(component.applicable_questions.map(&:id).include?("retirement_value_check")).to eq(false) + end - let(:log) { build(:lettings_log, :in_progress, creation_method: "bulk upload", age2: 99, startdate: Time.zone.local(2021, 5, 1), bulk_upload_id: nil) } + it "has the correct answer label for a question" do + sex1_question = questions.find { |q| q.id == "sex1" } + expect(component.get_answer_label(sex1_question)).to eq("Female") + end - it "displays tweaked copy in red" do - expect(rendered).not_to have_selector("span", class: "app-!-colour-red", text: "You still need to answer this question") - end - end + context "when log was created via a bulk upload and has an unanswered question" do + let(:bulk_upload) { create(:bulk_upload) } + let(:log) { create(:lettings_log, :in_progress, creation_method: "bulk upload", age2: 99, bulk_upload:) } - context "when log was not created via a bulk upload and has an unanswered question" do - subject(:component) { described_class.new(questions:, log:, user:) } + it "displays tweaked copy in red" do + expect(rendered).to have_selector("span", class: "app-!-colour-red", text: "You still need to answer this question") + end + end - let(:log) { build(:lettings_log, :in_progress, age2: 99, startdate: Time.zone.local(2021, 5, 1)) } + context "when log was imported with a bulk upload creation method, without bulk upload id and has an unanswered question" do + let(:log) { create(:lettings_log, :in_progress, creation_method: "bulk upload", age2: 99, bulk_upload_id: nil) } - it "displays normal copy with muted colour " do - expect(rendered).to have_selector("span", class: "app-!-colour-muted", text: "You didn’t answer this question") - end - end + it "displays tweaked copy in red" do + expect(rendered).not_to have_selector("span", class: "app-!-colour-red", text: "You still need to answer this question") + end + end - context "when log was created via a bulk upload and has an unanswered optional question" do - subject(:component) { described_class.new(questions:, log:, user:) } + context "when log was not created via a bulk upload and has an unanswered question" do + it "displays normal copy with muted colour " do + expect(rendered).to have_selector("span", class: "app-!-colour-muted", text: "You didn’t answer this question") + end + end - let(:subsection_id) { "setup" } - let(:bulk_upload) { create(:bulk_upload) } - let(:log) { build(:lettings_log, :completed, creation_method: "bulk upload", tenancycode: nil, startdate: Time.zone.local(2021, 5, 1), bulk_upload:) } + context "when log was created via a bulk upload and has an unanswered optional question" do + let(:subsection_id) { "setup" } + let(:bulk_upload) { create(:bulk_upload) } + let(:log) { create(:lettings_log, :completed, creation_method: "bulk upload", tenancycode: nil, bulk_upload:) } - it "displays tweaked copy in red" do - expect(rendered).to have_selector("span", class: "app-!-colour-muted", text: "You didn’t answer this question") - expect(rendered).not_to have_selector("span", class: "app-!-colour-red", text: "You still need to answer this question") - end - end + it "displays tweaked copy in red" do + expect(rendered).to have_selector("span", class: "app-!-colour-muted", text: "You didn’t answer this question") + expect(rendered).not_to have_selector("span", class: "app-!-colour-red", text: "You still need to answer this question") end end - context "when in 23/24 collection" do + context "when before 23/24 collection" do context "when given a set of questions" do - let(:user) { create(:user) } - let(:log) { create(:lettings_log, :completed, age2: 99, startdate: Time.zone.local(2023, 5, 1)) } - let(:subsection_id) { "household_characteristics" } - let(:subsection) { log.form.get_subsection(subsection_id) } - let(:questions) { subsection.applicable_questions(log) } - - around do |example| - Timecop.freeze(Time.zone.local(2023, 5, 1)) - Singleton.__init__(FormHandler) - example.run - Timecop.return - Singleton.__init__(FormHandler) - end + let(:log) { build(:lettings_log, :completed, age2: 99, startdate: Time.zone.local(2021, 5, 1)) } - it "renders a summary list card including question numbers for the answers to those questions" do + it "renders a summary list card without question numbers for the answers to those questions" do expect(rendered).to have_content(questions.first.answer_label(log)) - expect(rendered).to have_content("Q32 - Lead tenant’s age") + expect(rendered).to have_content("Lead tenant’s age") + expect(rendered).not_to include(" - Lead tenant’s age") end end end diff --git a/spec/factories/lettings_log.rb b/spec/factories/lettings_log.rb index 20357161a..4bb2eac36 100644 --- a/spec/factories/lettings_log.rb +++ b/spec/factories/lettings_log.rb @@ -14,6 +14,7 @@ FactoryBot.define do declaration { 1 } end trait :in_progress do + setup_completed status { 1 } tenancycode { Faker::Name.initials(number: 10) } postcode_full { Faker::Address.postcode } @@ -21,9 +22,6 @@ FactoryBot.define do hhmemb { 2 } age1 { 17 } age2 { 19 } - renewal { 1 } - rent_type { 1 } - startdate { Time.zone.today } end trait :conditional_section_complete do tenancycode { Faker::Name.initials(number: 10) } diff --git a/spec/features/bulk_upload_lettings_logs_spec.rb b/spec/features/bulk_upload_lettings_logs_spec.rb index 222edaa05..5d48d9ee0 100644 --- a/spec/features/bulk_upload_lettings_logs_spec.rb +++ b/spec/features/bulk_upload_lettings_logs_spec.rb @@ -1,7 +1,12 @@ require "rails_helper" RSpec.describe "Bulk upload lettings log" do + include CollectionTimeHelper + let(:user) { create(:user) } + let(:current_year) { current_collection_start_year } + let(:current_formatted_year) { "#{current_year}/#{current_year + 1}" } + let(:current_formatted_short_year) { "#{current_year}/#{current_year - 2000 + 1}" } let(:stub_file_upload) do vcap_services = { "aws-s3-bucket" => {} } @@ -22,11 +27,7 @@ RSpec.describe "Bulk upload lettings log" do # rubocop:disable RSpec/AnyInstance context "when during crossover period" do before do - Timecop.freeze(2023, 6, 1) - end - - after do - Timecop.return + allow(FormHandler.instance).to receive(:lettings_in_crossover_period?).and_return(true) end it "shows journey with year option" do @@ -38,20 +39,20 @@ RSpec.describe "Bulk upload lettings log" do click_button("Continue") expect(page).to have_content("You must select a collection period to upload for") - choose("2023/2024") + choose(current_formatted_year) click_button("Continue") click_link("Back") - expect(page.find_field("form-year-2023-field")).to be_checked + expect(page.find_field("form-year-#{current_year}-field")).to be_checked click_button("Continue") - expect(page).to have_content("Upload lettings logs in bulk (2023/24)") + expect(page).to have_content("Upload lettings logs in bulk (#{current_formatted_short_year})") click_button("Continue") expect(page).not_to have_content("What is the needs type?") - expect(page).to have_content("Upload lettings logs in bulk (2023/24)") + expect(page).to have_content("Upload lettings logs in bulk (#{current_formatted_short_year})") expect(page).to have_content("Upload your file") click_button("Upload") @@ -79,11 +80,7 @@ RSpec.describe "Bulk upload lettings log" do context "when not it crossover period" do before do - Timecop.freeze(2024, 1, 1) - end - - after do - Timecop.return + allow(FormHandler.instance).to receive(:lettings_in_crossover_period?).and_return(false) end it "shows journey with year option" do @@ -91,21 +88,11 @@ RSpec.describe "Bulk upload lettings log" do expect(page).to have_link("Upload lettings logs in bulk") click_link("Upload lettings logs in bulk") - expect(page).to have_content("Upload lettings logs in bulk (2023/24)") + expect(page).to have_content("Upload lettings logs in bulk (#{current_formatted_short_year})") click_button("Continue") expect(page).to have_content("Upload your file") end - end - - context "when the collection year isn't 22/23" do - before do - Timecop.freeze(2024, 1, 1) - end - - after do - Timecop.return - end it "shows journey without the needstype" do visit("/lettings-logs") @@ -120,7 +107,7 @@ RSpec.describe "Bulk upload lettings log" do expect(page).to have_content("Prepare your file") click_button("Continue") - expect(page).to have_content("Upload lettings logs in bulk (2023/24)") + expect(page).to have_content("Upload lettings logs in bulk (#{current_formatted_short_year})") expect(page).to have_content("Upload your file") click_button("Upload") diff --git a/spec/features/form/accessible_autocomplete_spec.rb b/spec/features/form/accessible_autocomplete_spec.rb index 30454da85..cd9780df1 100644 --- a/spec/features/form/accessible_autocomplete_spec.rb +++ b/spec/features/form/accessible_autocomplete_spec.rb @@ -2,28 +2,15 @@ require "rails_helper" require_relative "helpers" RSpec.describe "Accessible Autocomplete" do - around do |example| - Timecop.freeze(Time.zone.local(2022, 1, 1)) do - Singleton.__init__(FormHandler) - example.run - end - Timecop.return - Singleton.__init__(FormHandler) - end - include Helpers let(:user) { FactoryBot.create(:user) } let(:lettings_log) do FactoryBot.create( :lettings_log, :in_progress, - renewal: 0, previous_la_known: 1, prevloc: "E09000033", - illness: 1, is_la_inferred: false, - owning_organisation: user.organisation, - managing_organisation: user.organisation, assigned_to: user, ) end @@ -35,7 +22,7 @@ RSpec.describe "Accessible Autocomplete" do context "when using accessible autocomplete" do before do - visit("/lettings-logs/#{lettings_log.id}/accessible-select") + visit("/lettings-logs/#{lettings_log.id}/previous-local-authority") end it "allows type ahead filtering", js: true do @@ -50,12 +37,12 @@ RSpec.describe "Accessible Autocomplete" do it "ignores stop words", js: true do find("#lettings-log-prevloc-field").click.native.send_keys("t", "h", "e", " ", "W", "e", "s", "t", "m", :down, :enter) - expect(find("#lettings-log-prevloc-field").value).to eq("Westminster") + expect(find("#lettings-log-prevloc-field").value).to eq("Westmorland and Furness") end it "does not perform an exact match", js: true do - find("#lettings-log-prevloc-field").click.native.send_keys("o", "n", "l", "y", " ", "t", "o", "w", "n", :down, :enter) - expect(find("#lettings-log-prevloc-field").value).to eq("The one and only york town") + find("#lettings-log-prevloc-field").click.native.send_keys("K", "i", "n", "g", "s", "t", "o", "n", " ", "T", "h", "a", "m", "e", "s", :down, :enter) + expect(find("#lettings-log-prevloc-field").value).to eq("Kingston upon Thames") end it "maintains enhancement state across back navigation", js: true do @@ -100,7 +87,7 @@ RSpec.describe "Accessible Autocomplete" do it "has the correct option selected if one has been saved" do lettings_log.update!(postcode_known: 0, previous_la_known: 1, prevloc: "E07000178") - visit("/lettings-logs/#{lettings_log.id}/accessible-select") + visit("/lettings-logs/#{lettings_log.id}/previous-local-authority") expect(page).to have_select("lettings-log-prevloc-field", selected: %w[Oxford]) end end