Skip to content

Commit

Permalink
feature/APPEALS-63885: Fix tests to respect DST (#23420)
Browse files Browse the repository at this point in the history
* Fix tests to respect DST:
- spec/feature/hearings/virtual_hearings/daily_docket_spec.rb
- spec/models/hearings/forms/hearing_update_form_spec.rb

* Remove hardcoded dates from virtual_hearings/daily_docket_spec.rb

* Fix CI headless capybara test issue

---------

Co-authored-by: Matthew Thornton <[email protected]>
  • Loading branch information
ThorntonMatthew and ThorntonMatthew authored Nov 25, 2024
1 parent 9641a6e commit 1906c1d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ jobs:
CI: true
REDIS_URL_CACHE: redis://redis:6379/0/cache/
TEST_VACOLS_HOST: facols_db
HEADLESS: true

steps:
- uses: actions/checkout@v3
Expand Down
14 changes: 10 additions & 4 deletions spec/feature/hearings/virtual_hearings/daily_docket_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,15 @@ def check_email_events(hearing, current_user)

context "Formerly Video Virtual Hearing" do
let(:expected_central_office_time) do
time_str = "#{updated_hearing_time} #{hearing.hearing_day.scheduled_for} America/New_York"
tz_abbr = Time.zone.parse(time_str).dst? ? "ET" : "EST"

Time
.parse(updated_hearing_time)
.strftime("%F %T")
.in_time_zone(regional_office_timezone) # cast the updated hearing time to the ro timezone
.in_time_zone(HearingTimeService::CENTRAL_OFFICE_TIMEZONE) # convert it to the central office timezone
.strftime("%-l:%M %p ET") # and render it in the format expected in the modal
.strftime("%-l:%M %p #{tz_abbr}") # and render it in the format expected in the modal
end

scenario "Virtual hearing time is updated" do
Expand All @@ -55,6 +58,7 @@ def check_email_events(hearing, current_user)
click_dropdown(name: "optionalHearingTime0", text: updated_video_hearing_time)
expect(page).to have_content(COPY::VIRTUAL_HEARING_MODAL_CHANGE_HEARING_TIME_TITLE)
expect(page).to have_content(COPY::VIRTUAL_HEARING_MODAL_CHANGE_HEARING_TIME_BUTTON)

expect(page).to have_content("Time: #{expected_central_office_time} / #{expected_regional_office_time}")
click_button(COPY::VIRTUAL_HEARING_MODAL_CHANGE_HEARING_TIME_BUTTON)

Expand Down Expand Up @@ -180,6 +184,8 @@ def check_email_events(hearing, current_user)
end

context "Updating a hearing's time" do
let(:fall_date) { "#{1.year.from_now.year}-11-11" }

shared_examples "The hearing time is updated correctly" do
scenario do
visit "hearings/schedule/docket/" + hearing.hearing_day.id.to_s
Expand All @@ -195,15 +201,15 @@ def check_email_events(hearing, current_user)
let(:initial_hearing) { create(:legacy_hearing, case_hearing: case_hearing) }

# Ensure that the times are always in standard time.
before { initial_hearing.hearing_day.update!(scheduled_for: "2024-11-11") }
before { initial_hearing.hearing_day.update!(scheduled_for: fall_date) }

context "With a pre-existing scheduled_in_timezone value" do
let(:hearing_time_selection_string) { "10:00 AM Central Time (US & Canada)" }
let(:hearing) { initial_hearing.tap { _1.update!(scheduled_in_timezone: "America/Chicago") } }
let(:expected_post_update_time) { "10:00 AM CST" }

before do
hearing.hearing_day.update!(regional_office: "RO30", request_type: "V", scheduled_for: "2024-11-11")
hearing.hearing_day.update!(regional_office: "RO30", request_type: "V", scheduled_for: fall_date)
end

include_examples "The hearing time is updated correctly"
Expand All @@ -215,7 +221,7 @@ def check_email_events(hearing, current_user)
let(:expected_post_update_time) { "3:00 PM CST" }

before do
hearing.hearing_day.update!(regional_office: "RO30", request_type: "T", scheduled_for: "2024-11-11")
hearing.hearing_day.update!(regional_office: "RO30", request_type: "T", scheduled_for: fall_date)
end

include_examples "The hearing time is updated correctly"
Expand Down
9 changes: 7 additions & 2 deletions spec/models/hearings/forms/hearing_update_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,18 @@
end

it "should update scheduled_datetime if it is not null already" do
date_str = "#{hearing.hearing_day.scheduled_for} America/New_York"
is_dst = Time.zone.parse(date_str).dst?

hearing.update(
scheduled_datetime: "2021-04-23T11:30:00-04:00", scheduled_in_timezone: "America/New_York"
scheduled_datetime: "2021-04-23T11:30:00#{is_dst ? '-04:00' : '-05:00'}",
scheduled_in_timezone: "America/New_York"
)
subject.update
updated_scheduled_datetime = hearing.scheduled_datetime

expect(updated_scheduled_datetime.strftime("%Y-%m-%d %H:%M %z"))
.to eq "#{hearing.hearing_day.scheduled_for.strftime('%Y-%m-%d')} 21:45 -0400"
.to eq "#{hearing.hearing_day.scheduled_for.strftime('%Y-%m-%d')} 21:45 #{is_dst ? '-0400' : '-0500'}"
end

it "should not update scheduled_datetime if it is null already" do
Expand Down
2 changes: 1 addition & 1 deletion spec/support/capybara.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@

Capybara.javascript_driver = :logging_selenium_chrome

Capybara.default_driver = ENV["CI"] ? :sniffybara_headless : :parallel_sniffybara
Capybara.default_driver = ENV["HEADLESS"] ? :sniffybara_headless : :parallel_sniffybara
# the default default_max_wait_time is 2 seconds
Capybara.default_max_wait_time = 5
# Capybara uses puma by default, but for some reason, some of our tests don't
Expand Down

0 comments on commit 1906c1d

Please sign in to comment.