From 4ad1b6a75dc2f92b0201e8f11b96255ec7447dd5 Mon Sep 17 00:00:00 2001
From: Ross Byrne <robyrne@gitlab.com>
Date: Tue, 13 Feb 2024 13:34:29 +0000
Subject: [PATCH] Fixing rubocop exceptions in tests no 10

---
 .rubocop_todo/capybara/testid_finders.yml     | 15 -------------
 .../user_updates_comment_template_spec.rb     |  4 ++--
 spec/features/project_group_variables_spec.rb |  2 +-
 spec/features/projects/blobs/blame_spec.rb    | 16 +++++++-------
 .../branches/user_deletes_branch_spec.rb      |  2 +-
 spec/features/projects/branches_spec.rb       | 14 +++++++-----
 spec/features/projects/ci/editor_spec.rb      | 22 +++++++++----------
 spec/features/projects/ci/lint_spec.rb        |  2 +-
 spec/features/projects/clusters/gcp_spec.rb   |  4 ++--
 spec/features/projects/clusters/user_spec.rb  |  4 ++--
 .../projects/commit/cherry_pick_spec.rb       | 10 +++++----
 .../commit/user_sees_pipelines_tab_spec.rb    |  2 +-
 .../commits/user_browses_commits_spec.rb      |  2 +-
 spec/features/projects/compare_spec.rb        |  2 +-
 .../projects/environments/environment_spec.rb |  6 +++--
 .../environments/environments_spec.rb         |  2 +-
 16 files changed, 51 insertions(+), 58 deletions(-)

diff --git a/.rubocop_todo/capybara/testid_finders.yml b/.rubocop_todo/capybara/testid_finders.yml
index 558b21c7d3543..21bef5cfca5cb 100644
--- a/.rubocop_todo/capybara/testid_finders.yml
+++ b/.rubocop_todo/capybara/testid_finders.yml
@@ -2,21 +2,6 @@
 Capybara/TestidFinders:
   Exclude:
     - 'spec/features/merge_request/user_interacts_with_batched_mr_diffs_spec.rb'
-    - 'spec/features/profiles/user_updates_comment_template_spec.rb'
-    - 'spec/features/project_group_variables_spec.rb'
-    - 'spec/features/projects/blobs/blame_spec.rb'
-    - 'spec/features/projects/branches/user_deletes_branch_spec.rb'
-    - 'spec/features/projects/branches_spec.rb'
-    - 'spec/features/projects/ci/editor_spec.rb'
-    - 'spec/features/projects/ci/lint_spec.rb'
-    - 'spec/features/projects/clusters/gcp_spec.rb'
-    - 'spec/features/projects/clusters/user_spec.rb'
-    - 'spec/features/projects/commit/cherry_pick_spec.rb'
-    - 'spec/features/projects/commit/user_sees_pipelines_tab_spec.rb'
-    - 'spec/features/projects/commits/user_browses_commits_spec.rb'
-    - 'spec/features/projects/compare_spec.rb'
-    - 'spec/features/projects/environments/environment_spec.rb'
-    - 'spec/features/projects/environments/environments_spec.rb'
     - 'spec/features/projects/pipelines/pipeline_spec.rb'
     - 'spec/features/projects/pipelines/pipelines_spec.rb'
     - 'spec/features/projects/releases/user_creates_release_spec.rb'
diff --git a/spec/features/profiles/user_updates_comment_template_spec.rb b/spec/features/profiles/user_updates_comment_template_spec.rb
index 2e6bfdcc407ce..12e6ba45a8b0a 100644
--- a/spec/features/profiles/user_updates_comment_template_spec.rb
+++ b/spec/features/profiles/user_updates_comment_template_spec.rb
@@ -18,8 +18,8 @@
   it 'shows the user a list of their comment template' do
     click_button 'Comment template actions'
 
-    find('[data-testid="comment-template-edit-btn"]').click
-    find('[data-testid="comment-template-name-input"]').set('test')
+    find_by_testid('comment-template-edit-btn').click
+    find_by_testid('comment-template-name-input').set('test')
 
     click_button 'Save'
 
diff --git a/spec/features/project_group_variables_spec.rb b/spec/features/project_group_variables_spec.rb
index cc01de736cb22..bbea1d85928e3 100644
--- a/spec/features/project_group_variables_spec.rb
+++ b/spec/features/project_group_variables_spec.rb
@@ -41,7 +41,7 @@
 
   shared_examples 'renders correct column headers' do
     it "shows inherited CI variables table with correct columns" do
-      page.within('[data-testid="inherited-ci-variable-table"]') do
+      within_testid('inherited-ci-variable-table') do
         # Wait for vue app to load
         wait_for_requests
 
diff --git a/spec/features/projects/blobs/blame_spec.rb b/spec/features/projects/blobs/blame_spec.rb
index dfda200cded96..752bf9b502639 100644
--- a/spec/features/projects/blobs/blame_spec.rb
+++ b/spec/features/projects/blobs/blame_spec.rb
@@ -35,7 +35,7 @@ def visit_blob_blame(path)
   it 'displays the blame page without pagination' do
     visit_blob_blame(path)
 
-    within '[data-testid="blob-content-holder"]' do
+    within_testid 'blob-content-holder' do
       expect(page).to have_css('.blame-commit')
       expect(page).not_to have_css('.gl-pagination')
       expect(page).not_to have_link _('Show full blame')
@@ -50,7 +50,7 @@ def visit_blob_blame(path)
     it 'displays two first lines of the file with pagination' do
       visit_blob_blame(path)
 
-      within '[data-testid="blob-content-holder"]' do
+      within_testid 'blob-content-holder' do
         expect(page).to have_css('.blame-commit')
         expect(page).to have_css('.gl-pagination')
         expect(page).to have_link _('Show full blame')
@@ -69,7 +69,7 @@ def visit_blob_blame(path)
       end
 
       it 'displays next two lines of the file with pagination' do
-        within '[data-testid="blob-content-holder"]' do
+        within_testid 'blob-content-holder' do
           expect(page).not_to have_css('#L1')
           expect(page).to have_css('#L3')
           expect(find('.page-link.active')).to have_text('2')
@@ -77,7 +77,7 @@ def visit_blob_blame(path)
       end
 
       it 'correctly redirects to the prior blame page' do
-        within '[data-testid="blob-content-holder"]' do
+        within_testid 'blob-content-holder' do
           find('.version-link').click
 
           expect(find('.page-link.active')).to have_text('2')
@@ -93,7 +93,7 @@ def visit_blob_blame(path)
         end
 
         it 'displays the blame page without pagination' do
-          within '[data-testid="blob-content-holder"]' do
+          within_testid 'blob-content-holder' do
             expect(page).to have_css('#L1')
             expect(page).to have_css('#L667')
             expect(page).not_to have_css('.gl-pagination')
@@ -124,7 +124,7 @@ def visit_blob_blame(path)
       it 'displays the blame page without pagination' do
         visit_blob_blame(path)
 
-        within '[data-testid="blob-content-holder"]' do
+        within_testid 'blob-content-holder' do
           expect(page).to have_css('.blame-commit')
           expect(page).not_to have_css('.gl-pagination')
           expect(page).not_to have_link _('Show full blame')
@@ -143,7 +143,7 @@ def visit_blob_blame(path)
     it 'displays two hundred lines of the file with pagination' do
       visit_blob_blame(path)
 
-      within '[data-testid="blob-content-holder"]' do
+      within_testid 'blob-content-holder' do
         expect(page).to have_css('.blame-commit')
         expect(page).to have_css('.gl-pagination')
 
@@ -159,7 +159,7 @@ def visit_blob_blame(path)
       end
 
       it 'displays next two hundred lines of the file with pagination' do
-        within '[data-testid="blob-content-holder"]' do
+        within_testid 'blob-content-holder' do
           find('.js-next-button').click
 
           expect(page).not_to have_css('#L1')
diff --git a/spec/features/projects/branches/user_deletes_branch_spec.rb b/spec/features/projects/branches/user_deletes_branch_spec.rb
index d468d3ec7e7ca..c82440d7ee8eb 100644
--- a/spec/features/projects/branches/user_deletes_branch_spec.rb
+++ b/spec/features/projects/branches/user_deletes_branch_spec.rb
@@ -24,7 +24,7 @@
 
     page.within(".js-branch-improve\\/awesome") do
       click_button 'More actions'
-      find('[data-testid="delete-branch-button"]').click
+      find_by_testid('delete-branch-button').click
     end
 
     accept_gl_confirm(button_text: 'Yes, delete branch')
diff --git a/spec/features/projects/branches_spec.rb b/spec/features/projects/branches_spec.rb
index 41b8ad7825c51..5bddb1d93e16a 100644
--- a/spec/features/projects/branches_spec.rb
+++ b/spec/features/projects/branches_spec.rb
@@ -149,7 +149,7 @@
         visit project_branches_filtered_path(project, state: 'all')
 
         click_button "Updated date" # Open sorting dropdown
-        within '[data-testid="branches-dropdown"]' do
+        within_testid 'branches-dropdown' do
           first('span', text: 'Name').click
         end
 
@@ -160,7 +160,7 @@
         visit project_branches_filtered_path(project, state: 'all')
 
         click_button "Updated date" # Open sorting dropdown
-        within '[data-testid="branches-dropdown"]' do
+        within_testid 'branches-dropdown' do
           first('span', text: 'Oldest updated').click
         end
 
@@ -334,7 +334,9 @@
 
         page.within first('.all-branches li') do
           wait_for_requests
-          find('[data-testid="branch-more-actions"] .gl-new-dropdown-toggle').click
+          within_testid('branch-more-actions') do
+            find('.gl-new-dropdown-toggle').click
+          end
           click_link 'Compare'
         end
 
@@ -382,8 +384,10 @@ def clear_search_input
 
   def delete_branch_and_confirm
     wait_for_requests
-    find('[data-testid="branch-more-actions"] .gl-new-dropdown-toggle', match: :first).click
-    find('[data-testid="delete-branch-button"]').click
+    within_testid('branch-more-actions', match: :first) do
+      find('.gl-new-dropdown-toggle', match: :first).click
+    end
+    find_by_testid('delete-branch-button').click
 
     within '.modal-footer' do
       click_button 'Yes, delete branch'
diff --git a/spec/features/projects/ci/editor_spec.rb b/spec/features/projects/ci/editor_spec.rb
index 22cc5c67987b0..1b63f446ea57e 100644
--- a/spec/features/projects/ci/editor_spec.rb
+++ b/spec/features/projects/ci/editor_spec.rb
@@ -97,7 +97,7 @@
     end
 
     it 'shows "Pipeline syntax is correct" in the lint widget' do
-      page.within('[data-testid="validation-segment"]') do
+      within_testid('validation-segment') do
         expect(page).to have_content("Pipeline syntax is correct")
       end
     end
@@ -105,7 +105,7 @@
     it 'shows the graph in the visualization tab' do
       click_link "Visualize"
 
-      page.within('[data-testid="graph-container"') do
+      within_testid('graph-container') do
         expect(page).to have_content("job_a")
       end
     end
@@ -122,7 +122,7 @@
     it 'renders the merged yaml in the full configuration tab' do
       click_link "Full configuration"
 
-      page.within('[data-testid="merged-tab"') do
+      within_testid('merged-tab') do
         expect(page).to have_content("job_a")
       end
     end
@@ -135,7 +135,7 @@
     end
 
     it 'shows "Syntax is invalid" in the lint widget' do
-      page.within('[data-testid="validation-segment"]') do
+      within_testid('validation-segment') do
         expect(page).to have_content("This GitLab CI configuration is invalid")
       end
     end
@@ -159,7 +159,7 @@
     it 'renders merged yaml config' do
       click_link "Full configuration"
 
-      page.within('[data-testid="merged-tab"') do
+      within_testid('merged-tab') do
         expect(page).to have_content("job3")
       end
     end
@@ -169,7 +169,7 @@
     it 'renders an error in the merged yaml tab' do
       click_link "Full configuration"
 
-      page.within('[data-testid="merged-tab"') do
+      within_testid('merged-tab') do
         expect(page).not_to have_content("job_a")
         expect(page).to have_content("Could not load full configuration content")
       end
@@ -178,7 +178,7 @@
 
   shared_examples 'default branch switcher behavior' do
     it 'displays current branch' do
-      page.within('[data-testid="branch-selector"]') do
+      within_testid('branch-selector') do
         expect(page).to have_content(default_branch)
         expect(page).not_to have_content(other_branch)
       end
@@ -187,7 +187,7 @@
     it 'displays updated current branch after switching branches' do
       switch_to_branch(other_branch)
 
-      page.within('[data-testid="branch-selector"]') do
+      within_testid('branch-selector') do
         expect(page).to have_content(other_branch)
         expect(page).not_to have_content(default_branch)
       end
@@ -202,7 +202,7 @@
 
       click_button 'Commit changes'
 
-      page.within('[data-testid="branch-selector"]') do
+      within_testid('branch-selector') do
         expect(page).to have_content('new_branch')
         expect(page).not_to have_content(default_branch)
       end
@@ -216,9 +216,9 @@
   describe 'Branch Switcher' do
     def switch_to_branch(branch)
       # close button for the popover
-      find('[data-testid="close-button"]').click
+      find_by_testid('close-button').click
 
-      page.within '[data-testid="branch-selector"]' do
+      within_testid 'branch-selector' do
         toggle_listbox
         select_listbox_item(branch, exact_text: true)
       end
diff --git a/spec/features/projects/ci/lint_spec.rb b/spec/features/projects/ci/lint_spec.rb
index bc370a296e40b..e7a39ccd23f67 100644
--- a/spec/features/projects/ci/lint_spec.rb
+++ b/spec/features/projects/ci/lint_spec.rb
@@ -25,7 +25,7 @@
     shared_examples 'validates the YAML' do
       before do
         click_on 'Validate'
-        scroll_to(page.find('[data-testid="ci-lint-status"]'))
+        scroll_to(find_by_testid('ci-lint-status'))
       end
 
       context 'YAML is correct' do
diff --git a/spec/features/projects/clusters/gcp_spec.rb b/spec/features/projects/clusters/gcp_spec.rb
index e7e419a4c602e..920d0afa77dff 100644
--- a/spec/features/projects/clusters/gcp_spec.rb
+++ b/spec/features/projects/clusters/gcp_spec.rb
@@ -66,9 +66,9 @@
       context 'when user destroys the cluster' do
         before do
           click_link 'Advanced Settings'
-          find('[data-testid="remove-integration-button"]').click
+          find_by_testid('remove-integration-button').click
           fill_in 'confirm_cluster_name_input', with: cluster.name
-          find('[data-testid="remove-integration-modal-button"]').click
+          find_by_testid('remove-integration-modal-button').click
           click_link 'Certificate'
         end
 
diff --git a/spec/features/projects/clusters/user_spec.rb b/spec/features/projects/clusters/user_spec.rb
index bc4d64dad2138..ec9f526d4e256 100644
--- a/spec/features/projects/clusters/user_spec.rb
+++ b/spec/features/projects/clusters/user_spec.rb
@@ -100,9 +100,9 @@
     context 'when user destroys the cluster' do
       before do
         click_link 'Advanced Settings'
-        find('[data-testid="remove-integration-button"]').click
+        find_by_testid('remove-integration-button').click
         fill_in 'confirm_cluster_name_input', with: cluster.name
-        find('[data-testid="remove-integration-modal-button"]').click
+        find_by_testid('remove-integration-modal-button').click
         click_link 'Certificate'
       end
 
diff --git a/spec/features/projects/commit/cherry_pick_spec.rb b/spec/features/projects/commit/cherry_pick_spec.rb
index b608fc953f327..895c1ccc94149 100644
--- a/spec/features/projects/commit/cherry_pick_spec.rb
+++ b/spec/features/projects/commit/cherry_pick_spec.rb
@@ -77,12 +77,14 @@
           click_button 'master'
         end
 
-        page.within("#{modal_selector} [data-testid=\"base-dropdown-menu\"]") do
-          fill_in 'Search branches', with: 'feature'
+        page.within(modal_selector) do
+          within_testid('base-dropdown-menu') do
+            fill_in 'Search branches', with: 'feature'
 
-          wait_for_requests
+            wait_for_requests
 
-          find('[data-testid="listbox-item-feature"]').click
+            find_by_testid('listbox-item-feature').click
+          end
         end
 
         submit_cherry_pick
diff --git a/spec/features/projects/commit/user_sees_pipelines_tab_spec.rb b/spec/features/projects/commit/user_sees_pipelines_tab_spec.rb
index 5d722ddbedb8a..6237e66966226 100644
--- a/spec/features/projects/commit/user_sees_pipelines_tab_spec.rb
+++ b/spec/features/projects/commit/user_sees_pipelines_tab_spec.rb
@@ -35,7 +35,7 @@
 
       wait_for_requests
 
-      page.within('[data-testid="pipeline-table-row"]') do
+      within_testid('pipeline-table-row') do
         expect(page).to have_selector('[data-testid="ci-icon"]', text: 'Passed')
         expect(page).to have_content(pipeline.id)
         expect(page).to have_css('[data-testid="pipeline-mini-graph"]')
diff --git a/spec/features/projects/commits/user_browses_commits_spec.rb b/spec/features/projects/commits/user_browses_commits_spec.rb
index 5a0b70532aa25..fc60e6ba80bb0 100644
--- a/spec/features/projects/commits/user_browses_commits_spec.rb
+++ b/spec/features/projects/commits/user_browses_commits_spec.rb
@@ -115,7 +115,7 @@
 
       click_button '2 changed files'
 
-      expect(find('[data-testid="diff-stats-dropdown"]')).to have_content('files/ruby/popen.rb')
+      expect(find_by_testid('diff-stats-dropdown')).to have_content('files/ruby/popen.rb')
     end
   end
 
diff --git a/spec/features/projects/compare_spec.rb b/spec/features/projects/compare_spec.rb
index ccf5c6996f1a6..bac1a42720ac7 100644
--- a/spec/features/projects/compare_spec.rb
+++ b/spec/features/projects/compare_spec.rb
@@ -113,7 +113,7 @@
 
         click_button('Compare')
 
-        page.within('[data-testid="too-many-changes-alert"]') do
+        within_testid('too-many-changes-alert') do
           expect(page).to have_text("Some changes are not shown. For a faster browsing experience, only 3 of 3+ files are shown. Download one of the files below to see all changes.")
         end
       end
diff --git a/spec/features/projects/environments/environment_spec.rb b/spec/features/projects/environments/environment_spec.rb
index 61878a05fdfd8..66923fc232516 100644
--- a/spec/features/projects/environments/environment_spec.rb
+++ b/spec/features/projects/environments/environment_spec.rb
@@ -308,8 +308,10 @@ def auto_stop_button_selector
 
       remove_branch_with_hooks(project, user, 'feature') do
         page.within('.js-branch-feature') do
-          find('[data-testid="branch-more-actions"] .gl-new-dropdown-toggle').click
-          find('[data-testid="delete-branch-button"]').click
+          within_testid('branch-more-actions') do
+            find('.gl-new-dropdown-toggle').click
+          end
+          find_by_testid('delete-branch-button').click
         end
       end
 
diff --git a/spec/features/projects/environments/environments_spec.rb b/spec/features/projects/environments/environments_spec.rb
index c2b486a98ce12..cfe011334497e 100644
--- a/spec/features/projects/environments/environments_spec.rb
+++ b/spec/features/projects/environments/environments_spec.rb
@@ -331,7 +331,7 @@ def upcoming_deployment_content_selector
 
             # Wait for UI to transition to ensure we an GraphQL request has been made
             within(actions_button_selector) { find('.gl-spinner') }
-            within(actions_button_selector) { find('[data-testid="play-icon"]') }
+            within(actions_button_selector) { find_by_testid('play-icon') }
 
             wait_for_requests
           end
-- 
GitLab