Browse Source

Refactor tests #1

pull/2421/head
Kat 2 years ago committed by kosiakkatrina
parent
commit
321e597abc
  1. 61
      spec/components/check_answers_summary_list_card_component_spec.rb
  2. 4
      spec/factories/lettings_log.rb
  3. 39
      spec/features/bulk_upload_lettings_logs_spec.rb
  4. 23
      spec/features/form/accessible_autocomplete_spec.rb

61
spec/components/check_answers_summary_list_card_component_spec.rb

@ -5,27 +5,15 @@ RSpec.describe CheckAnswersSummaryListCardComponent, type: :component do
let(:rendered) { render_inline(component) } let(:rendered) { render_inline(component) }
context "when before 23/24 collection" do let(:user) { create(:user) }
before do let(:log) { create(:lettings_log, :completed, age2: 99, retirement_value_check: 1) }
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_id) { "household_characteristics" }
let(:subsection) { log.form.get_subsection(subsection_id) } let(:subsection) { log.form.get_subsection(subsection_id) }
let(:questions) { subsection.applicable_questions(log) } let(:questions) { subsection.applicable_questions(log) }
it "renders a summary list card without question numbers for the answers to those questions" do 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 have_content(questions.first.answer_label(log))
expect(rendered).to have_content("Lead tenant’s age") expect(rendered).to match(/Q\d+ - Lead tenant’s age/)
expect(rendered).not_to have_content("Q32 - Lead tenant’s age")
end end
it "applicable questions doesn't return questions that are hidden in check answers" do it "applicable questions doesn't return questions that are hidden in check answers" do
@ -33,15 +21,13 @@ RSpec.describe CheckAnswersSummaryListCardComponent, type: :component do
end end
it "has the correct answer label for a question" do it "has the correct answer label for a question" do
sex1_question = questions[2] sex1_question = questions.find { |q| q.id == "sex1" }
expect(component.get_answer_label(sex1_question)).to eq("Female") expect(component.get_answer_label(sex1_question)).to eq("Female")
end end
context "when log was created via a bulk upload and has an unanswered question" do 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(: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:) } let(:log) { create(:lettings_log, :in_progress, creation_method: "bulk upload", age2: 99, bulk_upload:) }
it "displays tweaked copy in red" do 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") expect(rendered).to have_selector("span", class: "app-!-colour-red", text: "You still need to answer this question")
@ -49,9 +35,7 @@ RSpec.describe CheckAnswersSummaryListCardComponent, type: :component do
end end
context "when log was imported with a bulk upload creation method, without bulk upload id and has an unanswered question" do 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:) } let(:log) { create(:lettings_log, :in_progress, creation_method: "bulk upload", age2: 99, bulk_upload_id: nil) }
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 "displays tweaked copy in red" do 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") expect(rendered).not_to have_selector("span", class: "app-!-colour-red", text: "You still need to answer this question")
@ -59,49 +43,30 @@ RSpec.describe CheckAnswersSummaryListCardComponent, type: :component do
end end
context "when log was not created via a bulk upload and has an unanswered question" do context "when log was not created via a bulk upload and has an unanswered question" do
subject(:component) { described_class.new(questions:, log:, user:) }
let(:log) { build(:lettings_log, :in_progress, age2: 99, startdate: Time.zone.local(2021, 5, 1)) }
it "displays normal copy with muted colour " 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") expect(rendered).to have_selector("span", class: "app-!-colour-muted", text: "You didn’t answer this question")
end end
end end
context "when log was created via a bulk upload and has an unanswered optional question" do context "when log was created via a bulk upload and has an unanswered optional question" do
subject(:component) { described_class.new(questions:, log:, user:) }
let(:subsection_id) { "setup" } let(:subsection_id) { "setup" }
let(:bulk_upload) { create(:bulk_upload) } 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:) } let(:log) { create(:lettings_log, :completed, creation_method: "bulk upload", tenancycode: nil, bulk_upload:) }
it "displays tweaked copy in red" do 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).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") expect(rendered).not_to have_selector("span", class: "app-!-colour-red", text: "You still need to answer this question")
end end
end end
end
end
context "when in 23/24 collection" do context "when before 23/24 collection" do
context "when given a set of questions" do context "when given a set of questions" do
let(:user) { create(:user) } let(:log) { build(:lettings_log, :completed, age2: 99, startdate: Time.zone.local(2021, 5, 1)) }
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
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(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 end
end end

4
spec/factories/lettings_log.rb

@ -14,6 +14,7 @@ FactoryBot.define do
declaration { 1 } declaration { 1 }
end end
trait :in_progress do trait :in_progress do
setup_completed
status { 1 } status { 1 }
tenancycode { Faker::Name.initials(number: 10) } tenancycode { Faker::Name.initials(number: 10) }
postcode_full { Faker::Address.postcode } postcode_full { Faker::Address.postcode }
@ -21,9 +22,6 @@ FactoryBot.define do
hhmemb { 2 } hhmemb { 2 }
age1 { 17 } age1 { 17 }
age2 { 19 } age2 { 19 }
renewal { 1 }
rent_type { 1 }
startdate { Time.zone.today }
end end
trait :conditional_section_complete do trait :conditional_section_complete do
tenancycode { Faker::Name.initials(number: 10) } tenancycode { Faker::Name.initials(number: 10) }

39
spec/features/bulk_upload_lettings_logs_spec.rb

@ -1,7 +1,12 @@
require "rails_helper" require "rails_helper"
RSpec.describe "Bulk upload lettings log" do RSpec.describe "Bulk upload lettings log" do
include CollectionTimeHelper
let(:user) { create(:user) } 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 let(:stub_file_upload) do
vcap_services = { "aws-s3-bucket" => {} } vcap_services = { "aws-s3-bucket" => {} }
@ -22,11 +27,7 @@ RSpec.describe "Bulk upload lettings log" do
# rubocop:disable RSpec/AnyInstance # rubocop:disable RSpec/AnyInstance
context "when during crossover period" do context "when during crossover period" do
before do before do
Timecop.freeze(2023, 6, 1) allow(FormHandler.instance).to receive(:lettings_in_crossover_period?).and_return(true)
end
after do
Timecop.return
end end
it "shows journey with year option" do it "shows journey with year option" do
@ -38,20 +39,20 @@ RSpec.describe "Bulk upload lettings log" do
click_button("Continue") click_button("Continue")
expect(page).to have_content("You must select a collection period to upload for") 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_button("Continue")
click_link("Back") 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") 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") click_button("Continue")
expect(page).not_to have_content("What is the needs type?") 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") expect(page).to have_content("Upload your file")
click_button("Upload") click_button("Upload")
@ -79,11 +80,7 @@ RSpec.describe "Bulk upload lettings log" do
context "when not it crossover period" do context "when not it crossover period" do
before do before do
Timecop.freeze(2024, 1, 1) allow(FormHandler.instance).to receive(:lettings_in_crossover_period?).and_return(false)
end
after do
Timecop.return
end end
it "shows journey with year option" do 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") expect(page).to have_link("Upload lettings logs in bulk")
click_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") click_button("Continue")
expect(page).to have_content("Upload your file") expect(page).to have_content("Upload your file")
end 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 it "shows journey without the needstype" do
visit("/lettings-logs") visit("/lettings-logs")
@ -120,7 +107,7 @@ RSpec.describe "Bulk upload lettings log" do
expect(page).to have_content("Prepare your file") expect(page).to have_content("Prepare your file")
click_button("Continue") 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") expect(page).to have_content("Upload your file")
click_button("Upload") click_button("Upload")

23
spec/features/form/accessible_autocomplete_spec.rb

@ -2,28 +2,15 @@ require "rails_helper"
require_relative "helpers" require_relative "helpers"
RSpec.describe "Accessible Autocomplete" do 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 include Helpers
let(:user) { FactoryBot.create(:user) } let(:user) { FactoryBot.create(:user) }
let(:lettings_log) do let(:lettings_log) do
FactoryBot.create( FactoryBot.create(
:lettings_log, :lettings_log,
:in_progress, :in_progress,
renewal: 0,
previous_la_known: 1, previous_la_known: 1,
prevloc: "E09000033", prevloc: "E09000033",
illness: 1,
is_la_inferred: false, is_la_inferred: false,
owning_organisation: user.organisation,
managing_organisation: user.organisation,
assigned_to: user, assigned_to: user,
) )
end end
@ -35,7 +22,7 @@ RSpec.describe "Accessible Autocomplete" do
context "when using accessible autocomplete" do context "when using accessible autocomplete" do
before do before do
visit("/lettings-logs/#{lettings_log.id}/accessible-select") visit("/lettings-logs/#{lettings_log.id}/previous-local-authority")
end end
it "allows type ahead filtering", js: true do it "allows type ahead filtering", js: true do
@ -50,12 +37,12 @@ RSpec.describe "Accessible Autocomplete" do
it "ignores stop words", js: true 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) 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 end
it "does not perform an exact match", js: true do 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) 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("The one and only york town") expect(find("#lettings-log-prevloc-field").value).to eq("Kingston upon Thames")
end end
it "maintains enhancement state across back navigation", js: true do 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 it "has the correct option selected if one has been saved" do
lettings_log.update!(postcode_known: 0, previous_la_known: 1, prevloc: "E07000178") 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]) expect(page).to have_select("lettings-log-prevloc-field", selected: %w[Oxford])
end end
end end

Loading…
Cancel
Save