From 48c5d6af6c42633e4d905c8886f43eaadc5c1ec5 Mon Sep 17 00:00:00 2001
From: Ross Byrne <robyrne@gitlab.com>
Date: Wed, 7 Feb 2024 15:23:57 +0000
Subject: [PATCH] Fixing rubocop exceptions no. 7

Changelog: changed
---
 .rubocop_todo/capybara/testid_finders.yml     | 14 -------
 spec/features/issues/issue_sidebar_spec.rb    |  6 +--
 spec/features/issues/issue_state_spec.rb      |  8 ++--
 .../issues/user_creates_issue_spec.rb         |  2 +-
 spec/features/issues/user_edits_issue_spec.rb | 20 +++++-----
 ..._resets_their_incoming_email_token_spec.rb |  2 +-
 ...r_sees_sidebar_updates_in_realtime_spec.rb |  4 +-
 .../issues/user_toggles_subscription_spec.rb  | 38 ++++++++++---------
 spec/features/labels_hierarchy_spec.rb        |  6 +--
 .../user_accepts_merge_request_spec.rb        |  2 +-
 .../user_assigns_themselves_spec.rb           |  6 +--
 .../user_comments_on_diff_spec.rb             |  2 +-
 ...comments_on_whitespace_hidden_diff_spec.rb |  2 +-
 .../merge_request/user_creates_mr_spec.rb     | 10 ++---
 14 files changed, 56 insertions(+), 66 deletions(-)

diff --git a/.rubocop_todo/capybara/testid_finders.yml b/.rubocop_todo/capybara/testid_finders.yml
index 0e02f3e3219d6..e41264d37afcc 100644
--- a/.rubocop_todo/capybara/testid_finders.yml
+++ b/.rubocop_todo/capybara/testid_finders.yml
@@ -1,20 +1,6 @@
 ---
 Capybara/TestidFinders:
   Exclude:
-    - 'spec/features/issues/issue_sidebar_spec.rb'
-    - 'spec/features/issues/issue_state_spec.rb'
-    - 'spec/features/issues/user_creates_issue_spec.rb'
-    - 'spec/features/issues/user_edits_issue_spec.rb'
-    - 'spec/features/issues/user_resets_their_incoming_email_token_spec.rb'
-    - 'spec/features/issues/user_sees_sidebar_updates_in_realtime_spec.rb'
-    - 'spec/features/issues/user_toggles_subscription_spec.rb'
-    - 'spec/features/labels_hierarchy_spec.rb'
-    - 'spec/features/merge_request/merge_request_discussion_lock_spec.rb'
-    - 'spec/features/merge_request/user_accepts_merge_request_spec.rb'
-    - 'spec/features/merge_request/user_assigns_themselves_spec.rb'
-    - 'spec/features/merge_request/user_comments_on_diff_spec.rb'
-    - 'spec/features/merge_request/user_comments_on_whitespace_hidden_diff_spec.rb'
-    - 'spec/features/merge_request/user_creates_mr_spec.rb'
     - 'spec/features/merge_request/user_interacts_with_batched_mr_diffs_spec.rb'
     - 'spec/features/merge_request/user_sees_pipelines_spec.rb'
     - 'spec/features/merge_request/user_sees_suggest_pipeline_spec.rb'
diff --git a/spec/features/issues/issue_sidebar_spec.rb b/spec/features/issues/issue_sidebar_spec.rb
index 08d0d54bcd299..ff1119af21f92 100644
--- a/spec/features/issues/issue_sidebar_spec.rb
+++ b/spec/features/issues/issue_sidebar_spec.rb
@@ -48,7 +48,7 @@
           open_assignees_dropdown
 
           page.within '.dropdown-menu-user' do
-            find('[data-testid="user-search-input"]').set(user2.name)
+            find_by_testid('user-search-input').set(user2.name)
 
             wait_for_requests
 
@@ -68,7 +68,7 @@
         it 'keeps your filtered term after filtering and dismissing the dropdown' do
           open_assignees_dropdown
 
-          find('[data-testid="user-search-input"]').set(user2.name)
+          find_by_testid('user-search-input').set(user2.name)
           wait_for_requests
 
           page.within '.dropdown-menu-user' do
@@ -84,7 +84,7 @@
             expect(page.all('[data-testid="unselected-participant"]').length).to eq(1)
           end
 
-          expect(find('[data-testid="user-search-input"]').value).to eq(user2.name)
+          expect(find_by_testid('user-search-input').value).to eq(user2.name)
         end
       end
     end
diff --git a/spec/features/issues/issue_state_spec.rb b/spec/features/issues/issue_state_spec.rb
index 125329764c6cd..b85d40a798d57 100644
--- a/spec/features/issues/issue_state_spec.rb
+++ b/spec/features/issues/issue_state_spec.rb
@@ -16,14 +16,14 @@
     it 'can close an issue' do
       expect(page).to have_selector('[data-testid="issue-state-badge"]')
 
-      expect(find('[data-testid="issue-state-badge"]')).to have_content 'Open'
+      expect(find_by_testid('issue-state-badge')).to have_content 'Open'
 
       within selector do
         click_button 'Close issue'
         wait_for_requests
       end
 
-      expect(find('[data-testid="issue-state-badge"]')).to have_content 'Closed'
+      expect(find_by_testid('issue-state-badge')).to have_content 'Closed'
     end
   end
 
@@ -31,14 +31,14 @@
     it 'can reopen an issue' do
       expect(page).to have_selector('[data-testid="issue-state-badge"]')
 
-      expect(find('[data-testid="issue-state-badge"]')).to have_content 'Closed'
+      expect(find_by_testid('issue-state-badge')).to have_content 'Closed'
 
       within selector do
         click_button 'Reopen issue'
         wait_for_requests
       end
 
-      expect(find('[data-testid="issue-state-badge"]')).to have_content 'Open'
+      expect(find_by_testid('issue-state-badge')).to have_content 'Open'
     end
   end
 
diff --git a/spec/features/issues/user_creates_issue_spec.rb b/spec/features/issues/user_creates_issue_spec.rb
index a407e7fd11231..01a14aaca75c2 100644
--- a/spec/features/issues/user_creates_issue_spec.rb
+++ b/spec/features/issues/user_creates_issue_spec.rb
@@ -101,7 +101,7 @@
 
         wait_for_all_requests
 
-        page.within '[data-testid="sidebar-labels"]' do
+        within_testid('sidebar-labels') do
           click_button label_titles.first
           click_button _('Close')
 
diff --git a/spec/features/issues/user_edits_issue_spec.rb b/spec/features/issues/user_edits_issue_spec.rb
index e9bf1ef542b67..b3ac374ae6307 100644
--- a/spec/features/issues/user_edits_issue_spec.rb
+++ b/spec/features/issues/user_edits_issue_spec.rb
@@ -117,7 +117,7 @@ def click_edit_issue_description
           markdown_field_focused_selector = 'textarea:focus'
           click_edit_issue_description
 
-          issuable_form = find('[data-testid="issuable-form"]')
+          issuable_form = find_by_testid('issuable-form')
 
           expect(issuable_form).to have_selector(markdown_field_focused_selector)
 
@@ -220,8 +220,8 @@ def click_edit_issue_description
               click_button('Edit')
               wait_for_requests
 
-              find('[data-testid="unassign"]').click
-              find('[data-testid="title"]').click
+              find_by_testid('unassign').click
+              find_by_testid('title').click
               wait_for_requests
 
               expect(page).to have_content 'None - assign yourself'
@@ -243,7 +243,7 @@ def click_edit_issue_description
             end
 
             page.within('.assignee') do
-              find('[data-testid="title"]').click
+              find_by_testid('title').click
               wait_for_requests
 
               expect(page).to have_content user.name
@@ -262,7 +262,7 @@ def click_edit_issue_description
               wait_for_requests
               click_button user.name
 
-              find('[data-testid="title"]').click
+              find_by_testid('title').click
               wait_for_requests
 
               expect(page).to have_content "None"
@@ -314,7 +314,7 @@ def click_edit_issue_description
               wait_for_requests
               click_button milestone.title
 
-              page.within '[data-testid="select-milestone"]' do
+              within_testid('select-milestone') do
                 expect(page).to have_content milestone.title
               end
 
@@ -322,7 +322,7 @@ def click_edit_issue_description
               wait_for_requests
               click_button 'No milestone'
 
-              page.within '[data-testid="select-milestone"]' do
+              within_testid('select-milestone') do
                 expect(page).to have_content 'None'
               end
             end
@@ -376,7 +376,7 @@ def click_edit_issue_description
         it 'adds due date to issue' do
           date = Date.today.at_beginning_of_month + 2.days
 
-          page.within '[data-testid="sidebar-due-date"]' do
+          within_testid('sidebar-due-date') do
             click_button 'Edit'
             page.within '.pika-single' do
               click_button date.day
@@ -384,14 +384,14 @@ def click_edit_issue_description
 
             wait_for_requests
 
-            expect(find('[data-testid="sidebar-date-value"]').text).to have_content date.strftime('%b %-d, %Y')
+            expect(find_by_testid('sidebar-date-value').text).to have_content date.strftime('%b %-d, %Y')
           end
         end
 
         it 'removes due date from issue' do
           date = Date.today.at_beginning_of_month + 2.days
 
-          page.within '[data-testid="sidebar-due-date"]' do
+          within_testid('sidebar-due-date') do
             click_button 'Edit'
 
             page.within '.pika-single' do
diff --git a/spec/features/issues/user_resets_their_incoming_email_token_spec.rb b/spec/features/issues/user_resets_their_incoming_email_token_spec.rb
index 55c66eb8a39cb..df6443a32b4a4 100644
--- a/spec/features/issues/user_resets_their_incoming_email_token_spec.rb
+++ b/spec/features/issues/user_resets_their_incoming_email_token_spec.rb
@@ -20,7 +20,7 @@
 
     page.within '#issuable-email-modal' do
       previous_token = page.find('input[type="text"]').value
-      find('[data-testid="reset_email_token_link"]').click
+      find_by_testid('reset_email_token_link').click
 
       wait_for_requests
 
diff --git a/spec/features/issues/user_sees_sidebar_updates_in_realtime_spec.rb b/spec/features/issues/user_sees_sidebar_updates_in_realtime_spec.rb
index 91b18454af54a..1d66c543b7797 100644
--- a/spec/features/issues/user_sees_sidebar_updates_in_realtime_spec.rb
+++ b/spec/features/issues/user_sees_sidebar_updates_in_realtime_spec.rb
@@ -8,8 +8,8 @@
   let_it_be(:user) { create(:user) }
   let_it_be(:label)  { create(:label, project: project, name: 'Development') }
 
-  let(:labels_widget) { find('[data-testid="sidebar-labels"]') }
-  let(:labels_value) { find('[data-testid="value-wrapper"]') }
+  let(:labels_widget) { find_by_testid('sidebar-labels') }
+  let(:labels_value) { find_by_testid('value-wrapper') }
 
   before_all do
     project.add_developer(user)
diff --git a/spec/features/issues/user_toggles_subscription_spec.rb b/spec/features/issues/user_toggles_subscription_spec.rb
index a1ea40c511f7c..6c611608510f0 100644
--- a/spec/features/issues/user_toggles_subscription_spec.rb
+++ b/spec/features/issues/user_toggles_subscription_spec.rb
@@ -32,17 +32,19 @@
     it 'unsubscribes from issue' do
       find('.detail-page-header-actions .gl-new-dropdown-toggle').click
 
-      subscription_button = find('[data-testid="notification-toggle"] [data-testid="toggle-wrapper"]')
+      within_testid('notification-toggle') do
+        subscription_button = find_by_testid('toggle-wrapper')
 
-      # Check we're subscribed.
-      expect(subscription_button).to have_css("button.is-checked")
+        # Check we're subscribed.
+        expect(subscription_button).to have_css("button.is-checked")
 
-      # Toggle subscription.
-      subscription_button.find('button').click
-      wait_for_requests
+        # Toggle subscription.
+        subscription_button.find('button').click
+        wait_for_requests
 
-      # Check we're unsubscribed.
-      expect(subscription_button).to have_css("button:not(.is-checked)")
+        # Check we're unsubscribed.
+        expect(subscription_button).to have_css("button:not(.is-checked)")
+      end
     end
   end
 
@@ -57,17 +59,19 @@
     it 'subscribes to issue' do
       find('.detail-page-header-actions .gl-new-dropdown-toggle').click
 
-      subscription_button = find('[data-testid="notification-toggle"] [data-testid="toggle-wrapper"]')
+      within_testid('notification-toggle') do
+        subscription_button = find_by_testid('toggle-wrapper')
 
-      # Check we're not subscribed.
-      expect(subscription_button).to have_css("button:not(.is-checked)")
+        # Check we're not subscribed.
+        expect(subscription_button).to have_css("button:not(.is-checked)")
 
-      # Toggle subscription.
-      subscription_button.find('button').click
-      wait_for_requests
+        # Toggle subscription.
+        subscription_button.find('button').click
+        wait_for_requests
 
-      # Check we're subscribed.
-      expect(subscription_button).to have_css("button.is-checked")
+        # Check we're subscribed.
+        expect(subscription_button).to have_css("button.is-checked")
+      end
     end
   end
 
@@ -80,7 +84,7 @@
     end
 
     it 'toggles subscription' do
-      subscription_button = find('[data-testid="subscribe-button"]')
+      subscription_button = find_by_testid('subscribe-button')
 
       expect(page).to have_selector("button[title='Notifications off']")
       subscription_button.click
diff --git a/spec/features/labels_hierarchy_spec.rb b/spec/features/labels_hierarchy_spec.rb
index c6c7342325b09..c5bf230e98806 100644
--- a/spec/features/labels_hierarchy_spec.rb
+++ b/spec/features/labels_hierarchy_spec.rb
@@ -58,7 +58,7 @@
             expect(card).to have_selector('a', text: labeled_issue.title)
           end
         else
-          within '[data-testid="filtered-search-input"]' do
+          within_testid('filtered-search-input') do
             click_filtered_search_bar
             click_on 'Label'
             click_on '= is'
@@ -109,7 +109,7 @@
             expect(card).to have_selector('a', text: labeled_issue_2.title)
           end
         else
-          within '[data-testid="filtered-search-input"]' do
+          within_testid('filtered-search-input') do
             click_filtered_search_bar
             click_on 'Label'
             click_on '= is'
@@ -170,7 +170,7 @@
 
       wait_for_all_requests
 
-      page.within '[data-testid="sidebar-labels"]' do
+      within_testid('sidebar-labels') do
         click_button grandparent_group_label.title
         click_button parent_group_label.title
         click_button project_label_1.title
diff --git a/spec/features/merge_request/user_accepts_merge_request_spec.rb b/spec/features/merge_request/user_accepts_merge_request_spec.rb
index e3989a8a19236..6e0ad749dbb84 100644
--- a/spec/features/merge_request/user_accepts_merge_request_spec.rb
+++ b/spec/features/merge_request/user_accepts_merge_request_spec.rb
@@ -109,7 +109,7 @@
     end
 
     it 'accepts a merge request' do
-      find('[data-testid="widget_edit_commit_message"]').click
+      find_by_testid('widget_edit_commit_message').click
       fill_in('merge-message-edit', with: 'wow such merge')
 
       click_merge_button
diff --git a/spec/features/merge_request/user_assigns_themselves_spec.rb b/spec/features/merge_request/user_assigns_themselves_spec.rb
index ed4ea91f704b3..b1d87ee49044c 100644
--- a/spec/features/merge_request/user_assigns_themselves_spec.rb
+++ b/spec/features/merge_request/user_assigns_themselves_spec.rb
@@ -25,7 +25,7 @@
       wait_for_requests
 
       expect do
-        page.within('[data-testid="assignee-block-container"]') do
+        within_testid('assignee-block-container') do
           click_button 'assign yourself'
         end
 
@@ -40,7 +40,7 @@
       end
 
       it 'does not display if related issues are already assigned' do
-        page.within('[data-testid="assignee-block-container"]') do
+        within_testid('assignee-block-container') do
           expect(page).not_to have_content 'Assign yourself'
         end
       end
@@ -54,7 +54,7 @@
     end
 
     it 'does not show assignment link' do
-      page.within('[data-testid="assignee-block-container"]') do
+      within_testid('assignee-block-container') do
         expect(page).not_to have_content 'Assign yourself'
       end
     end
diff --git a/spec/features/merge_request/user_comments_on_diff_spec.rb b/spec/features/merge_request/user_comments_on_diff_spec.rb
index 9135f5c7b981b..eb14bd3925386 100644
--- a/spec/features/merge_request/user_comments_on_diff_spec.rb
+++ b/spec/features/merge_request/user_comments_on_diff_spec.rb
@@ -146,7 +146,7 @@
           click_button "Insert suggestion"
         end
 
-        within '[data-testid="content-editor"]' do
+        within_testid('content-editor') do
           expect(page).to have_content('Suggested change From line')
         end
       end
diff --git a/spec/features/merge_request/user_comments_on_whitespace_hidden_diff_spec.rb b/spec/features/merge_request/user_comments_on_whitespace_hidden_diff_spec.rb
index c13fe8d1e45ad..233e6dd0f3ecb 100644
--- a/spec/features/merge_request/user_comments_on_whitespace_hidden_diff_spec.rb
+++ b/spec/features/merge_request/user_comments_on_whitespace_hidden_diff_spec.rb
@@ -23,7 +23,7 @@
   context 'when hiding whitespace changes' do
     before do
       find('.js-show-diff-settings').click
-      find('[data-testid="show-whitespace"]').click
+      find_by_testid('show-whitespace').click
       wait_for_requests
     end
 
diff --git a/spec/features/merge_request/user_creates_mr_spec.rb b/spec/features/merge_request/user_creates_mr_spec.rb
index 5f6e465d011e9..8c90a94b2282b 100644
--- a/spec/features/merge_request/user_creates_mr_spec.rb
+++ b/spec/features/merge_request/user_creates_mr_spec.rb
@@ -14,20 +14,20 @@
     include ListboxHelpers
 
     it 'creates new merge request', :js do
-      find('[data-testid="assignee-ids-dropdown-toggle"]').click
+      find_by_testid('assignee-ids-dropdown-toggle').click
       page.within '.dropdown-menu-user' do
         click_link user2.name
       end
 
       expect(find('input[name="merge_request[assignee_ids][]"]', visible: false).value).to match(user2.id.to_s)
-      page.within '[data-testid="assignee-ids-dropdown-toggle"]' do
+      within_testid('assignee-ids-dropdown-toggle') do
         expect(page).to have_content user2.name
       end
 
       click_link 'Assign to me'
 
       expect(find('input[name="merge_request[assignee_ids][]"]', visible: false).value).to match(user.id.to_s)
-      page.within '[data-testid="assignee-ids-dropdown-toggle"]' do
+      within_testid('assignee-ids-dropdown-toggle') do
         expect(page).to have_content user.name
       end
 
@@ -38,12 +38,12 @@
 
       click_button _('Select label')
       wait_for_all_requests
-      page.within '[data-testid="sidebar-labels"]' do
+      within_testid('sidebar-labels') do
         click_button label.title
         click_button label2.title
         click_button _('Close')
         wait_for_requests
-        page.within('[data-testid="embedded-labels-list"]') do
+        within_testid('embedded-labels-list') do
           expect(page).to have_content(label.title)
           expect(page).to have_content(label2.title)
         end
-- 
GitLab