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

Refactor: Project Samples Test #869

Open
wants to merge 24 commits into
base: main
Choose a base branch
from

Conversation

ChrisHuynh333
Copy link
Collaborator

@ChrisHuynh333 ChrisHuynh333 commented Dec 12, 2024

What does this PR do and why?

This PR refactors system/projects/samples_test.rb.

Upon revision, there were many aspects of the testing file that needed cleanup and/or fixing.
This is including but not limited to:

  1. Ensuring assertions are actually testing what the test title states
  2. Removing redundancies between tests (eg: no need to check for a header every time we visit a page unless we're testing a redirect). Note: There are cases where tests are flaky, and the resolution is to add additional asserts (such as anything with select2). These cases will have repetitive assertions and should be commented on.
  3. Split larger tests into multiple tests so tests are shorter and more focused.
  4. Use of ID selectors as much as possible

Screenshots or screen recordings

Screenshots are required for UI changes, and strongly recommended for all other pull requests.

How to set up and validate locally

  1. Verify tests pass locally

PR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

This comment has been minimized.

@ChrisHuynh333 ChrisHuynh333 force-pushed the refactor/project-samples-test branch 3 times, most recently from 713784f to 2376ede Compare December 16, 2024 15:29

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@ChrisHuynh333 ChrisHuynh333 force-pushed the refactor/project-samples-test branch from b0cefc6 to 973859e Compare December 20, 2024 15:33

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@ChrisHuynh333 ChrisHuynh333 marked this pull request as ready for review December 20, 2024 17:05
Copy link

Code Metrics Report

Coverage Test Execution Time
92.6% 10m42s

Reported by octocov

@ChrisHuynh333 ChrisHuynh333 added ready for review Pull request is ready for review and removed on hold labels Dec 20, 2024
Copy link
Member

@ericenns ericenns left a comment

Choose a reason for hiding this comment

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

This is looking good. I left some comments, but in general can you assert for something that will ensure the samples table has fully loaded in your setup before proceeding with actions. This strategy should reduce flakes.

assert_no_selector 'form#deselect-all-form'
end

test 'User with role >= Maintainer sees sample table checkboxes' do
Copy link
Member

Choose a reason for hiding this comment

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

nitpick (blocking): Shouldn't a user with role ANALYST be able to see the checkboxes since they can launch workflow executions.

assert_selector 'a', text: I18n.t('projects.samples.index.new_button'), count: 1
within('#samples-table table tbody') do
# sample does not currently exist
assert_no_text 'New Name'
Copy link
Member

Choose a reason for hiding this comment

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

nitpick (blocking): This could pass even if a sample with New Name did exist in the project, since there is no assert to ensure that the samples table has been loaded.

# verify sample exists in samples table
visit namespace_project_samples_url(@namespace, @project)
within('#samples-table table tbody') do
assert_text 'New Name'
Copy link
Member

Choose a reason for hiding this comment

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

nitpick (blocking): This could be potentially flakey as there is no assertion to ensure that the table has been loaded on the page.

assert_selector 'h1', text: I18n.t(:'projects.samples.index.title'), count: 1
# deleted sample row no longer exists
assert_no_selector "#samples-table table tbody tr[id='#{@sample1.id}']"
Copy link
Member

Choose a reason for hiding this comment

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

nitpick (blocking): Can you move this below the other assertion as that would ensure that the samples table has been loaded.

assert_no_selector '#samples-table table tbody tr', text: @sample1.puid
assert_no_selector '#samples-table table tbody tr', text: @sample1.name
# sample no longer exists
assert_no_selector "tr[id='#{@sample1.id}']"
Copy link
Member

Choose a reason for hiding this comment

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

nitpick (blocking): Can you move this assertion after the limit_component assertion

project2 = projects(:project2)
test 'transfer dialog sample listing' do
### SETUP START ###
samples = @project.samples.pluck(:puid, :name)
visit namespace_project_samples_url(@namespace, @project)
Copy link
Member

Choose a reason for hiding this comment

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

nitpick (blocking): Can you add an assertion that the limit component is visible to ensure that the samples table has fully loaded to reduce flakes.


test 'transfer dialog with plural description' do
### SETUP START ###
visit namespace_project_samples_url(@namespace, @project)
Copy link
Member

Choose a reason for hiding this comment

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

nitpick (blocking): Same as comment above, please ensure table had fully loaded before proceeding to reduce changes of flakes.

test 'should transfer a single sample' do
project2 = projects(:project2)
test 'transfer dialog with singular description' do
### SETUP START ###
visit namespace_project_samples_url(@namespace, @project)
Copy link
Member

Choose a reason for hiding this comment

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

nitpick (blocking): Same as comment above.

end
assert_text strip_tags(I18n.t(:'viral.pagy.limit_component.summary', from: 1, to: 20, count: 23,
Copy link
Member

Choose a reason for hiding this comment

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

nitpick (blocking): Can you assert for this above the samples assertions, that should reduce flakes

login_as users(:user28)
namespace = groups(:group_hotel)
project = projects(:projectHotel)
visit namespace_project_samples_url(namespace, project)
Copy link
Member

Choose a reason for hiding this comment

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

nitpick (blocking): Can you assert for limit component before proceeding to reduce potential for flakes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready for review Pull request is ready for review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants