Flaky Test: Stabilize multi-line suggestion feature specs

What does this MR do and why?

This MR addresses flakiness in the spec/features/merge_request/user_comments_on_diff_spec.rb file, specifically within the tests for multi-line suggestions.

The previous implementation could intermittently fail to find or interact with diff lines, likely due to elements not being scrolled into the viewport before interaction attempts. The "suggestion is presented" test, for instance, was quarantined under #268240 (closed).

This MR makes the following improvements to this test context:

  • Uses the find_by_scrolling helper to ensure the target diff file's container element ([id='#{hash}']) is located and scrolled into view before attempting to scope actions within it or click on specific lines.
  • Consolidates the creation of the multi-line suggestion into the before block for better structure.
  • Retains wait_for_requests after actions like posting the comment and applying the suggestion.
  • Ensures the two-step apply process (suggestion button + confirmation modal "Apply" button) is correctly tested.

These changes aim to make the tests for multi-line suggestions more robust and reliable by ensuring proper element visibility and interaction timing.

References

#268240 (closed), #525849 (closed), #536809 (closed)

How to set up and validate locally

  1. Check out this branch.
  2. Run the affected spec file, focusing on the 'multi-line suggestions' context:
    bundle exec rspec spec/features/merge_request/user_suggests_changes_on_diff_spec.rb -e "multi-line suggestions"
  3. All tests within this context should now pass consistently.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Zakaria Fatahi

Merge request reports

Loading