Submit social housing lettings and sales data (CORE)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

143 lines
4.8 KiB

require "rails_helper"
RSpec.describe CollectionTimeHelper do
let(:current_user) { create(:user, :data_coordinator) }
let(:user) { create(:user, :data_coordinator) }
describe "Current collection start year" do
around do |example|
Timecop.freeze(now) do
example.run
end
CLDC-1917 test flakiness fix (#1437) * feat: add validation with feature flag, typo fix and update tests * feat: flip feature toggle * feat: update feature toggle name * feat: fix form handler inequality * refactor: linting * refactor: use between in form handler * feat: remove feature toggle * feat: add dynamic date to lettings log factory * feat: fix log_summary_component_spec.rb tests * feat: update lettings_log.rb and start fixing lettings_log_spec.rb * feat: fix more tests * feat: fix more tests * feat: fix lettings log import service * refactor: linting * feat: fix checkboxes_spec.rb * feat: fix interruption_screen_helper_spec.rb * feat: fix check_answers_helper_spec.rb * feat: fix page_routing_spec.rb * feat: fix lettings_logs_field_import_service_spec.rb * feat: fix lettings_log_spec.rb * feat: fix question_spec.rb * feat: fix lettings_logs_controller_spec.rb * feat: fix check_answers_page_lettings_logs_spec.rb * feat: fix tenancy_validations_spec.rb * feat: fix validations_spec.rb * feat: fix accessible_autocomplete_spec.rb * feat: fix form_navigation_spec.rb * feat: fix soft_validations_spec.rb * feat: fix lettings_log_export_service_spec.rb * feat: fix saving_data_spec.rb * feat: fix page_spec.rb * feat: fix form_controller_spec.rb * refactor: linting * feat: fix subsection_spec.rb * feat: fix lettings_log_spec.rb * feat: fix financial_validations_spec.rb * feat: fix tasklist_page_spec.rb * feat: fix conditional_questions_spec.rb * feat: fix form_page_error_helper_spec.rb and log_summary_component_spec.rb * feat: fix lettings_log_csv_service_spec.rb * feat: fix tasklist_helper_spec.rb * refactor: linting * refactor: linting * feat: fix lettings_log_spec.rb * refactor: linting * refactor: replace financial year with collection yaer * feat: respond to PR comments pt. 1 * feat: respond to PR comments pt. 2 * feat: unfreeze all timecop freezes
2 years ago
Timecop.return
end
context "when the date is after 1st of April" do
let(:now) { Time.utc(2022, 8, 3) }
it "returns the same year as the current start year" do
expect(current_collection_start_year).to eq(2022)
end
it "returns the correct current start date" do
expect(current_collection_start_date).to eq(Time.zone.local(2022, 4, 1))
end
it "returns the correct current end date" do
expect(current_collection_end_date).to eq(Time.zone.local(2023, 3, 31).end_of_day)
end
end
context "with the date before 1st of April" do
let(:now) { Time.utc(2022, 2, 3) }
it "returns the previous year as the current start year" do
expect(current_collection_start_year).to eq(2021)
end
it "returns the correct current start date" do
expect(current_collection_start_date).to eq(Time.zone.local(2021, 4, 1))
end
it "returns the correct current end date" do
expect(current_collection_end_date).to eq(Time.zone.local(2022, 3, 31).end_of_day)
end
end
end
describe "Any collection year" do
context "when the date is after 1st of April" do
let(:now) { Time.utc(2022, 8, 3) }
it "returns the same year as the current start year" do
expect(collection_start_year_for_date(now)).to eq(2022)
end
it "returns the correct current start date" do
expect(collection_start_date(now)).to eq(Time.zone.local(2022, 4, 1))
end
it "returns the correct current end date" do
expect(collection_end_date(now)).to eq(Time.zone.local(2023, 3, 31).end_of_day)
end
end
context "with the date before 1st of April" do
let(:now) { Time.utc(2022, 2, 3) }
it "returns the previous year as the current start year" do
expect(collection_start_year_for_date(now)).to eq(2021)
end
it "returns the correct current start date" do
expect(collection_start_date(now)).to eq(Time.zone.local(2021, 4, 1))
end
it "returns the correct current end date" do
expect(collection_end_date(now)).to eq(Time.zone.local(2022, 3, 31).end_of_day)
end
end
end
describe "#date_mid_collection_year_formatted" do
subject(:result) { date_mid_collection_year_formatted(input) }
context "when called with nil" do
let(:input) { nil }
it "returns the 13th of September in the current collection year" do
year = current_collection_start_year
expect(result).to eq("13 9 #{year}")
end
end
context "when called with a date after the first of April" do
calendar_year = 2030
let(:input) { Date.new(calendar_year, 7, 7) }
it "returns the 13th of September from that year" do
expect(result).to eq("13 9 #{calendar_year}")
end
end
context "when called with a date before April" do
calendar_year = 2040
let(:input) { Date.new(calendar_year, 2, 7) }
it "returns the 13th of September from the previous year" do
expect(result).to eq("13 9 #{calendar_year - 1}")
end
end
end
CLDC-3116 Create homepage (#2113) * feat: add blank homepage, update routing and tests * feat: add welcome message and thoroughly test routing * refactor: lint * feat: update tests * CLDC-3076: Make example dates consistent (#2107) * CLDC-3076: Make example dates consistent * Use example date even when some hint text provided already * Temp remove some date restrictions * Update to 2 line breaks * Revert "Temp remove some date restrictions" This reverts commit cd7f18f9f10957be0cbabee7665c0abe4239acb6. * Fix lettings log accessor in date question (#2117) * Fix lettings log accessor in date question * Remove hardcoded date example from mrcdate question (#2118) --------- Co-authored-by: Rachael Booth <Rachael.Booth@softwire.com> * CLDC-3061 Add guidance page (#2121) * Add guidance page * Link to guidance from start page * feat: test home/start paths explicitly * CLDC-2253 Add collection resources (#2120) * Update collection resources, add to homepage * Add guidance link to an empty page * Update headings * Rebase fix * Update title * Update file names * Add section break * CLDC-2593 Add upcoming deadlines section (#2119) * Add upcoming deadlines section * Update the content to use the correct dates * Update content * lint * typos * CLDC-2252 Add homepage task section (#2115) * feat: wip add lettings, sales and schemes sections with correct text, counts, links and colouring * feat: add flex styling to match designs * CLDC-3076: Make example dates consistent (#2107) * CLDC-3076: Make example dates consistent * Use example date even when some hint text provided already * Temp remove some date restrictions * Update to 2 line breaks * Revert "Temp remove some date restrictions" This reverts commit cd7f18f9f10957be0cbabee7665c0abe4239acb6. * Fix lettings log accessor in date question (#2117) * Fix lettings log accessor in date question * Remove hardcoded date example from mrcdate question (#2118) --------- Co-authored-by: Rachael Booth <Rachael.Booth@softwire.com> * feat: update breakpoints for responsive layout changes * lint: use hash lookup where possible * lint: erblinting * feat: improve formatting * Reuse govuk grid * Revert "Reuse govuk grid" This reverts commit 8c71f5d9edf261802a8a86e07c13552f51283668. * feat: test home page data boxes * refactor: lint * refactor: lint * feat: test link behaviour is correct in all user scenarios * refactor: lint * feat: update tests * feat: combine task, resources, deadlines sections --------- Co-authored-by: Rachael Booth <Rachael.Booth@softwire.com> Co-authored-by: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Co-authored-by: Kat <kosiak.katrina@gmail.com> * CLDC-2255 Add homepage notifications (#2131) * feat: add notification table * feat: add notification banner, use unread gem for notification management * feat: add notifications page and remove unread_notification.rb * feat: add blank homepage, update routing and tests * feat: add welcome message and thoroughly test routing * refactor: lint * feat: update tests * CLDC-3061 Add guidance page (#2121) * Add guidance page * Link to guidance from start page * feat: test home/start paths explicitly * feat: add notification table * feat: add notification banner, use unread gem for notification management * feat: add notifications page and remove unread_notification.rb * feat: default p tag around sanitized page content * feat: add active scope * feat: use newest active unread/unauthenticated notification and update start page * feat: add tests of notification behaviour and routing and refactor * refactor: lint * feat: update Gemfile.lock * feat: add timestamps to readmark table * feat: update gemfile.lock * refactor: lint * feat: test notifications page doesn't show notifications and code simplification * feat: move notification helper methods to notifications_helper.rb --------- Co-authored-by: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> * feat: clear all no-status filters on in progress links * CLDC-2590 Add about this service section (#2124) * Add about core section * Move about core to the correct spot on start page * Update content * Add some margins --------- Co-authored-by: Rachael Booth <Rachael.Booth@softwire.com> Co-authored-by: kosiakkatrina <54268893+kosiakkatrina@users.noreply.github.com> Co-authored-by: Kat <kosiak.katrina@gmail.com>
12 months ago
describe "#quarter_for_date" do
it "returns correct cutoff date for curent quarter" do
quarter = quarter_for_date(date: Time.zone.local(2023, 10, 1))
expect(quarter.cutoff_date).to eq(Time.zone.local(2024, 1, 12))
expect(quarter.quarter_start_date).to eq(Time.zone.local(2023, 10, 1))
expect(quarter.quarter_end_date).to eq(Time.zone.local(2023, 12, 31))
end
it "returns correct cutoff date for the first quarter of 2024/25" do
quarter = quarter_for_date(date: Time.zone.local(2024, 4, 1))
expect(quarter.cutoff_date).to eq(Time.zone.local(2024, 7, 12))
expect(quarter.quarter_start_date).to eq(Time.zone.local(2024, 4, 1))
expect(quarter.quarter_end_date).to eq(Time.zone.local(2024, 6, 30))
end
it "returns correct cutoff date for the second quarter of 2024/25" do
quarter = quarter_for_date(date: Time.zone.local(2024, 9, 30))
expect(quarter.cutoff_date).to eq(Time.zone.local(2024, 10, 11))
expect(quarter.quarter_start_date).to eq(Time.zone.local(2024, 7, 1))
expect(quarter.quarter_end_date).to eq(Time.zone.local(2024, 9, 30))
end
it "returns correct cutoff date for the third quarter of 2024/25" do
quarter = quarter_for_date(date: Time.zone.local(2024, 10, 25))
expect(quarter.cutoff_date).to eq(Time.zone.local(2025, 1, 10))
expect(quarter.quarter_start_date).to eq(Time.zone.local(2024, 10, 1))
expect(quarter.quarter_end_date).to eq(Time.zone.local(2024, 12, 31))
end
end
end