Browse Source

Update tests

pull/2890/head
Manny Dinssa 4 weeks ago
parent
commit
18227c870c
  1. 97
      spec/features/home_page_spec.rb
  2. 2
      spec/rails_helper.rb

97
spec/features/home_page_spec.rb

@ -5,8 +5,6 @@ RSpec.describe "Home Page Features" do
let!(:user) { FactoryBot.create(:user) } let!(:user) { FactoryBot.create(:user) }
let(:storage_service) { instance_double(Storage::S3Service, get_file_metadata: nil) } let(:storage_service) { instance_double(Storage::S3Service, get_file_metadata: nil) }
let(:current_collection_year) { 2024 }
let(:next_collection_year) { 2025 }
before do before do
sign_in user sign_in user
@ -14,82 +12,107 @@ RSpec.describe "Home Page Features" do
allow(storage_service).to receive(:configuration).and_return(OpenStruct.new(bucket_name: "core-test-collection-resources")) allow(storage_service).to receive(:configuration).and_return(OpenStruct.new(bucket_name: "core-test-collection-resources"))
end end
describe "_upcoming_deadlines" do
let(:current_collection_year) { 2024 }
let(:next_collection_year) { 2025 }
context "when visiting during the current collection year" do context "when visiting during the current collection year" do
before do before do
allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(false) allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(false)
# rubocop:disable RSpec/AnyInstance
allow_any_instance_of(CollectionTimeHelper).to receive(:current_collection_start_year).and_return(current_collection_year) allow_any_instance_of(CollectionTimeHelper).to receive(:current_collection_start_year).and_return(current_collection_year)
allow_any_instance_of(CollectionTimeHelper).to receive(:current_collection_end_year).and_return(current_collection_year + 1) allow_any_instance_of(CollectionTimeHelper).to receive(:current_collection_end_year).and_return(current_collection_year + 1)
visit root_path # rubocop:enable RSpec/AnyInstance
find("span.govuk-details__summary-text", text: "Quarterly cut-off dates for 2024 to 2025").click
end end
after { travel_back } scenario "displays correct text for quarters" do
Timecop.freeze(Time.zone.local(current_collection_year, 4, 1)) do
scenario "displays correct text for Q1" do visit root_path
travel_to Time.zone.local(current_collection_year, 4, 1) do find("span.govuk-details__summary-text", text: "Quarterly cut-off dates for 2024 to 2025").click
expect(page).to have_content("Q1 - Friday 12 July 2024") expect(page).to have_content("Q1 - Friday 12 July 2024")
expect(page).to have_content("Q2 - Friday 11 October 2024")
expect(page).to have_content("Q3 - Friday 10 January 2025")
expect(page).to have_content("End of year deadline - Friday 6 June 2025")
expect(page).to have_content("You can still create logs for a previous quarter after its cut-off date, as long as you complete them by the end-of-year deadline: Friday 6 June 2025.") expect(page).to have_content("You can still create logs for a previous quarter after its cut-off date, as long as you complete them by the end-of-year deadline: Friday 6 June 2025.")
end end
Timecop.return
end end
scenario "displays correct text for Q2" do scenario "displays correct current quarter as Q1" do
travel_to Time.zone.local(current_collection_year, 7, 1) do Timecop.freeze(Time.zone.local(current_collection_year, 4, 1)) do
expect(page).to have_content("Q2 - Friday 11 October 2024") visit root_path
expect(page).to have_content("You can still create logs for a previous quarter after its cut-off date, as long as you complete them by the end-of-year deadline: Friday 6 June 2025.") expect(page).to have_selector("h1.govuk-heading-l + p.govuk-body.govuk-body-m", text: "Q1 - Friday 12 July 2024: Quarterly cut off date for tenancies and sales starting between 1 April 2024 and 30 June 2024.")
expect(page).to have_content("Q1 - Friday 12 July 2024")
end end
Timecop.return
end end
scenario "displays correct text for Q3" do scenario "displays correct current quarter as Q2" do
travel_to Time.zone.local(current_collection_year, 10, 1) do Timecop.freeze(Time.zone.local(current_collection_year, 8, 1)) do
expect(page).to have_content("Q3 - Friday 10 January 2025") visit root_path
expect(page).to have_content("You can still create logs for a previous quarter after its cut-off date, as long as you complete them by the end-of-year deadline: Friday 6 June 2025.") expect(page).to have_selector("h1.govuk-heading-l + p.govuk-body.govuk-body-m", text: "Q2 - Friday 11 October 2024: Quarterly cut off date for tenancies and sales starting between 1 July 2024 and 30 September 2024.")
expect(page).to have_content("Q2 - Friday 11 October 2024")
end end
Timecop.return
end end
scenario "displays correct text for Q4" do scenario "displays correct current quarter as Q3" do
travel_to Time.zone.local(current_collection_year + 1, 3, 1) do Timecop.freeze(Time.zone.local(current_collection_year, 11, 1)) do
expect(page).to have_content("End of year deadline - Friday 6 June 2025") visit root_path
expect(page).to have_content("You can still create logs for a previous quarter after its cut-off date, as long as you complete them by the end-of-year deadline: Friday 6 June 2025.") expect(page).to have_selector("h1.govuk-heading-l + p.govuk-body.govuk-body-m", text: "Q3 - Friday 10 January 2025: Quarterly cut off date for tenancies and sales starting between 1 October 2024 and 31 December 2024.")
expect(page).to have_content("Q3 - Friday 10 January 2025")
end end
Timecop.return
end end
end end
context "when visiting during the next collection year" do context "when visiting during the next collection year" do
before do before do
allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(false) allow(FormHandler.instance).to receive(:in_crossover_period?).and_return(false)
# rubocop:disable RSpec/AnyInstance
allow_any_instance_of(CollectionTimeHelper).to receive(:current_collection_start_year).and_return(next_collection_year) allow_any_instance_of(CollectionTimeHelper).to receive(:current_collection_start_year).and_return(next_collection_year)
allow_any_instance_of(CollectionTimeHelper).to receive(:current_collection_end_year).and_return(next_collection_year + 1) allow_any_instance_of(CollectionTimeHelper).to receive(:current_collection_end_year).and_return(next_collection_year + 1)
# rubocop:enable RSpec/AnyInstance
end
scenario "displays correct text for quarters" do
Timecop.freeze(Time.zone.local(next_collection_year, 4, 1)) do
visit root_path visit root_path
find("span.govuk-details__summary-text", text: "Quarterly cut-off dates for 2025 to 2026").click find("span.govuk-details__summary-text", text: "Quarterly cut-off dates for 2025 to 2026").click
expect(page).to have_content("Q1 - Friday 11 July 2025")
expect(page).to have_content("Q2 - Friday 10 October 2025")
expect(page).to have_content("Q3 - Friday 16 January 2026")
expect(page).to have_content("End of year deadline - Friday 5 June 2026")
expect(page).to have_content("You can still create logs for a previous quarter after its cut-off date, as long as you complete them by the end-of-year deadline: Friday 5 June 2026.")
end
Timecop.return
end end
after { travel_back } scenario "displays correct current quarter as Q1" do
Timecop.freeze(Time.zone.local(next_collection_year, 4, 1)) do
scenario "displays correct text for Q1" do visit root_path
travel_to Time.zone.local(next_collection_year, 4, 1) do expect(page).to have_selector("h1.govuk-heading-l + p.govuk-body.govuk-body-m", text: "Q1 - Friday 11 July 2025: Quarterly cut off date for tenancies and sales starting between 1 April 2025 and 30 June 2025.")
expect(page).to have_content("Q1 - Friday 11 July 2025") expect(page).to have_content("Q1 - Friday 11 July 2025")
expect(page).to have_content("You can still create logs for a previous quarter after its cut-off date, as long as you complete them by the end-of-year deadline: Friday 5 June 2026.")
end end
Timecop.return
end end
scenario "displays correct text for Q2" do scenario "displays correct current quarter as Q2" do
travel_to Time.zone.local(next_collection_year, 7, 1) do Timecop.freeze(Time.zone.local(next_collection_year, 8, 1)) do
visit root_path
expect(page).to have_selector("h1.govuk-heading-l + p.govuk-body.govuk-body-m", text: "Q2 - Friday 10 October 2025: Quarterly cut off date for tenancies and sales starting between 1 July 2025 and 30 September 2025.")
expect(page).to have_content("Q2 - Friday 10 October 2025") expect(page).to have_content("Q2 - Friday 10 October 2025")
expect(page).to have_content("You can still create logs for a previous quarter after its cut-off date, as long as you complete them by the end-of-year deadline: Friday 5 June 2026.")
end end
Timecop.return
end end
scenario "displays correct text for Q3" do scenario "displays correct current quarter as Q3" do
travel_to Time.zone.local(next_collection_year, 10, 1) do Timecop.freeze(Time.zone.local(next_collection_year, 11, 1)) do
visit root_path
expect(page).to have_selector("h1.govuk-heading-l + p.govuk-body.govuk-body-m", text: "Q3 - Friday 16 January 2026: Quarterly cut off date for tenancies and sales starting between 1 October 2025 and 31 December 2025.")
expect(page).to have_content("Q3 - Friday 16 January 2026") expect(page).to have_content("Q3 - Friday 16 January 2026")
expect(page).to have_content("You can still create logs for a previous quarter after its cut-off date, as long as you complete them by the end-of-year deadline: Friday 5 June 2026.")
end
end end
Timecop.return
scenario "displays correct text for Q4" do
travel_to Time.zone.local(next_collection_year + 1, 3, 1) do
expect(page).to have_content("End of year deadline - Friday 5 June 2026")
expect(page).to have_content("You can still create logs for a previous quarter after its cut-off date, as long as you complete them by the end-of-year deadline: Friday 5 June 2026.")
end end
end end
end end

2
spec/rails_helper.rb

@ -51,8 +51,6 @@ rescue ActiveRecord::PendingMigrationError => e
end end
RSpec.configure do |config| RSpec.configure do |config|
config.include ActiveSupport::Testing::TimeHelpers
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
config.fixture_paths = ["#{::Rails.root}/spec/fixtures"] config.fixture_paths = ["#{::Rails.root}/spec/fixtures"]

Loading…
Cancel
Save