Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix spec tests for table actions #5012

Merged
merged 11 commits into from
Jan 7, 2025
8 changes: 4 additions & 4 deletions drivers/hmis/spec/system/hmis/assessment_definitions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
end

it 'upgrades to the newer version when you unlock for editing' do
click_link old_definition.title
click_link 'View Assessment'

assert_text old_definition.title

Expand All @@ -101,7 +101,7 @@

# Re-open the assessment to ensure it is using the new form now
assert_no_text old_definition.title
click_link definition.title
click_link 'View Assessment'
assert_text 'New question'
assert_text 'Answer to new question'
assert_no_text 'Text on old form'
Expand All @@ -113,7 +113,7 @@
let!(:wip_assessment) { create(:hmis_custom_assessment, definition: old_definition, wip: true, values: { 'assessment_date': today.strftime('%Y-%m-%d') }, enrollment: e1, assessment_date: today) }

it 'uses old form version for editing' do
click_link old_definition.title
click_link 'View Assessment'
assert_text old_definition.title
expect(page).to have_field('Assessment Date', with: wip_assessment.assessment_date.strftime('%m/%d/%Y'))
assert_text 'Text on old form'
Expand Down Expand Up @@ -176,7 +176,7 @@
sign_in(hmis_user)

visit "/client/#{c1.id}/enrollments/#{e1.id}/assessments"
click_link 'Intake'
click_link 'Finish Intake'
end

def select_member(client)
Expand Down
12 changes: 6 additions & 6 deletions drivers/hmis/spec/system/hmis/bulk_services_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
require_relative '../../requests/hmis/login_and_permissions'
require_relative '../../support/hmis_base_setup'

RSpec.feature 'Hmis Form behavior', type: :system do
RSpec.feature 'Bulk Services behavior', type: :system do
include_context 'hmis base setup'
include_context 'hmis service setup'

Expand Down Expand Up @@ -52,25 +52,25 @@
find('input[type="checkbox"][aria-label="select all"]', visible: :all).trigger(:click)

expect do
click_button 'Enroll (3) + Assign (3)'
find('button', text: 'Enroll (3) + Assign (3)').trigger(:click)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@martha I'm wondering about this change, were you seeing failures?
We had previously needed this workaround for failed clicks, but I thought we fixed it with #4735.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gigxz yes, I thought I saw a failure with this locally, but let me poke it a little more...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. Something I will do if I want to be certain about new system test is to run it repeatedly on CI by adding to the below line:

RUN_SYSTEM_TESTS=true RAILS_ENV=test CAPYBARA_APP_HOST="http://$HOSTNAME:5173" rspec drivers/hmis/spec/system/hmis/*

RUN_SYSTEM_TESTS=true RAILS_ENV=test CAPYBARA_APP_HOST="http://$HOSTNAME:5173" rspec drivers/hmis/spec/system/hmis/my_test.rb
RUN_SYSTEM_TESTS=true RAILS_ENV=test CAPYBARA_APP_HOST="http://$HOSTNAME:5173" rspec drivers/hmis/spec/system/hmis/my_test.rb
RUN_SYSTEM_TESTS=true RAILS_ENV=test CAPYBARA_APP_HOST="http://$HOSTNAME:5173" rspec drivers/hmis/spec/system/hmis/my_test.rb
RUN_SYSTEM_TESTS=true RAILS_ENV=test CAPYBARA_APP_HOST="http://$HOSTNAME:5173" rspec drivers/hmis/spec/system/hmis/my_test.rb
etc...

temporarily of course :)

assert_text 'Assigned' # wait for it to process
end.to change(Hmis::Hud::Service, :count).by(3)

# Find the indices of the two columns we want to check
header_cells = all('thead th')
last_bed_night_date_index = header_cells.find_index { |cell| cell.text == 'Last Bed Night Date' }
assign_bed_night_index = header_cells.find_index { |cell| cell.text == "Assign Bed Night for #{bed_night_date.strftime('%m/%d/%Y')}" }
button_column_index = header_cells.find_index { |cell| cell.text == 'Actions' }
expect(last_bed_night_date_index).not_to be_nil
expect(assign_bed_night_index).not_to be_nil
expect(button_column_index).not_to be_nil

# Verify that all 3 rows have the expected attributes
all('tbody tr').each do |row|
# Check the "Last Bed Night Date" column
last_bed_night_date = row.all('td')[last_bed_night_date_index].text
expect(last_bed_night_date).to match(/#{bed_night_date.strftime('%m/%d/%Y')}/)

# Check the "Assign Bed Night for mm/dd/yyyy" column
assign_button = row.all('td')[assign_bed_night_index].find('button')
# Check the "Actions" column
assign_button = row.all('td')[button_column_index].first('button')
expect(assign_button.text).to eq('Assigned')
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def side_nav_elements
expect(table_row).to include(spouse.first_name)
expect(table_row).to include('Safe Haven')

click_link spouse.first_name
click_link 'View CLS'
assert_current_path("/client/#{spouse.id}/enrollments/#{spouse_enrollment.id}/current-living-situations")
end

Expand All @@ -76,7 +76,7 @@ def side_nav_elements

assert_no_text 'Add Current Living Situation'

find('tbody').first('tr').trigger(:click)
click_button 'View CLS'
assert_text 'View Current Living Situation'
assert_no_text 'Not Found'
assert_text 'Current Living Situation Safe Haven'
Expand Down Expand Up @@ -147,7 +147,7 @@ def side_nav_elements

assert_no_text 'Add Case Note'

find('tbody').first('tr').trigger(:click)
click_button 'View Case Note'
click_button 'Edit'
fill_in 'Note', with: 'An updated legacy custom case note'
click_button 'Save'
Expand Down
4 changes: 2 additions & 2 deletions drivers/hmis/spec/system/hmis/enrollment_management_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def make_household(household_id: Hmis::Hud::Base.generate_uuid, enrollment_facto
before(:each) do
make_household(enrollment_factory: :hmis_hud_wip_enrollment)
fill_in 'Search Clients', with: c1.last_name
click_link c1.brief_name
find('a', text: 'View Enrollment', match: :first).trigger(:click)
click_link 'Household'
click_link 'Manage Household'
end
Expand Down Expand Up @@ -155,7 +155,7 @@ def make_household(household_id: Hmis::Hud::Base.generate_uuid, enrollment_facto
# now we have to go back and find the enrollment again to see prev members
click_link 'Enrollments', match: :first
assert_text(c1.brief_name)
click_link c1.brief_name, match: :first
find('a', text: 'View Enrollment', match: :first).trigger(:click)
click_link 'Household'
click_link 'Manage Household'

Expand Down
4 changes: 2 additions & 2 deletions drivers/hmis/spec/system/hmis/intake_assessment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
require_relative '../../requests/hmis/login_and_permissions'
require_relative '../../support/hmis_base_setup'

RSpec.feature 'Enrollment/household management', type: :system do
RSpec.feature 'Intake assessment', type: :system do
include_context 'hmis base setup'
# could parse CAPYBARA_APP_HOST
let!(:ds1) { create(:hmis_data_source, hmis: 'localhost') }
Expand Down Expand Up @@ -74,7 +74,7 @@ def complete_individual_assessment
expect(e2.intake_assessment).to be_nil

fill_in 'Search Clients', with: c1.last_name
click_link c1.brief_name
find('a', text: 'View Enrollment', match: :first).trigger(:click)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We lose some fidelity here -- previously we knew we were clicking on the row for c1 (or at least, a client with their name), and now we're just clicking on the first row. Can we use the aria-label here, so we know who we're clicking on?

Copy link
Contributor

@gigxz gigxz Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we have enable_aria_label enabled so you may be able to just look for the text of the aria label directly to find the button, like click_button "View Enrollment, {c1.brief_name}" (untested)

click_link 'Assessments'
click_link 'Finish Intake'

Expand Down
Loading