diff --git a/.rubocop_todo/capybara/testid_finders.yml b/.rubocop_todo/capybara/testid_finders.yml index e41264d37afcc02e4239490a4e04aaea0ea53dc6..c674b7f46b1ca64628c05e28ca21075e5cdac0ec 100644 --- a/.rubocop_todo/capybara/testid_finders.yml +++ b/.rubocop_todo/capybara/testid_finders.yml @@ -2,23 +2,6 @@ Capybara/TestidFinders: Exclude: - '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' - - 'spec/features/merge_request/user_sees_versions_spec.rb' - - 'spec/features/merge_request/user_squashes_merge_request_spec.rb' - - 'spec/features/merge_request/user_toggles_whitespace_changes_spec.rb' - - 'spec/features/merge_request/user_views_open_merge_request_spec.rb' - - 'spec/features/milestone_spec.rb' - - 'spec/features/nav/pinned_nav_items_spec.rb' - - 'spec/features/populate_new_pipeline_vars_with_params_spec.rb' - - 'spec/features/profile_spec.rb' - - 'spec/features/profiles/account_spec.rb' - - 'spec/features/profiles/keys_spec.rb' - - 'spec/features/profiles/oauth_applications_spec.rb' - - 'spec/features/profiles/password_spec.rb' - - 'spec/features/profiles/user_creates_comment_template_spec.rb' - - 'spec/features/profiles/user_deletes_comment_template_spec.rb' - - 'spec/features/profiles/user_edit_profile_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' diff --git a/spec/features/merge_request/user_sees_pipelines_spec.rb b/spec/features/merge_request/user_sees_pipelines_spec.rb index a06d1808b6b5ca6ac0bc6ff6250c207a257b89aa..5f65f348fadde73db9f210407b21e7fa08e1a6f8 100644 --- a/spec/features/merge_request/user_sees_pipelines_spec.rb +++ b/spec/features/merge_request/user_sees_pipelines_spec.rb @@ -48,7 +48,7 @@ wait_for_requests - page.within(find('[data-testid="pipeline-table-row"]', match: :first)) do + within_testid('pipeline-table-row', match: :first) 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"]') @@ -69,7 +69,7 @@ wait_for_requests - expect(page.find('[data-testid="run_pipeline_button"]')).to have_text('Run pipeline') + expect(find_by_testid('run_pipeline_button')).to have_text('Run pipeline') end end @@ -85,7 +85,7 @@ wait_for_requests - expect(page.find('[data-testid="run_pipeline_button"]')).to have_text('Run pipeline') + expect(find_by_testid('run_pipeline_button')).to have_text('Run pipeline') end end end @@ -107,7 +107,7 @@ end expect(page).to have_content('There are currently no pipelines.') - expect(page.find('[data-testid="run_pipeline_button"]')).to have_text('Run pipeline') + expect(find_by_testid('run_pipeline_button')).to have_text('Run pipeline') end end end @@ -213,7 +213,7 @@ def check_pipeline(expected_project:) page.within(first('[data-testid="pipeline-table-row"]')) do page.within('.pipeline-tags') do - expect(page.find('[data-testid="pipeline-url-link"]')[:href]).to include(expected_project.full_path) + expect(find_by_testid('pipeline-url-link')[:href]).to include(expected_project.full_path) expect(page).to have_content('merge request') end page.within('.pipeline-triggerer') do diff --git a/spec/features/merge_request/user_sees_suggest_pipeline_spec.rb b/spec/features/merge_request/user_sees_suggest_pipeline_spec.rb index 3a2e382fe99f45ad39b33cab1a50b1b24cf554de..635cec792de9277fd7edaeba01f192edde6171ef 100644 --- a/spec/features/merge_request/user_sees_suggest_pipeline_spec.rb +++ b/spec/features/merge_request/user_sees_suggest_pipeline_spec.rb @@ -20,7 +20,7 @@ expect(page).to have_content(content) page.within '.mr-pipeline-suggest' do - find('[data-testid="close"]').click + find_by_testid('close').click end wait_for_requests @@ -37,7 +37,7 @@ expect(page).to have_content('GitLab CI/CD can automatically build, test, and deploy your application') page.within '.mr-pipeline-suggest' do - find('[data-testid="ok"]').click + find_by_testid('ok').click end wait_for_requests diff --git a/spec/features/merge_request/user_sees_versions_spec.rb b/spec/features/merge_request/user_sees_versions_spec.rb index 2df9d91c8ee19faa9ca4e0e3915cd359725dafaa..7ded635945474beb7aa0f20a6b9fee22b975d9e6 100644 --- a/spec/features/merge_request/user_sees_versions_spec.rb +++ b/spec/features/merge_request/user_sees_versions_spec.rb @@ -33,7 +33,7 @@ # otherwise, the element could be hidden underneath a sticky header scroll_to_elements_bottom(line_code_element) line_code_element.hover - page.find("[data-testid='left-comment-button']", visible: true).click + find_by_testid('left-comment-button', visible: true).click expect(page).to have_selector("form", count: 1) diff --git a/spec/features/merge_request/user_squashes_merge_request_spec.rb b/spec/features/merge_request/user_squashes_merge_request_spec.rb index 5fd0f353e568b61ef332ab00360023555cd2d03f..b298df6a4ab670606fb9c10f1b2a6937521a9c11 100644 --- a/spec/features/merge_request/user_squashes_merge_request_spec.rb +++ b/spec/features/merge_request/user_squashes_merge_request_spec.rb @@ -83,7 +83,7 @@ def accept_mr context 'when squash message is the same as existing commit message' do before do - find('[data-testid="widget_edit_commit_message"]').click + find_by_testid('widget_edit_commit_message').click fill_in('Squash commit message', with: project.commit(source_branch).safe_message) accept_mr end diff --git a/spec/features/merge_request/user_toggles_whitespace_changes_spec.rb b/spec/features/merge_request/user_toggles_whitespace_changes_spec.rb index 15715a6d7752628e4bed972459718d7aa5047734..c668bae4c77bbf3144021df9f100f76b5c6150d3 100644 --- a/spec/features/merge_request/user_toggles_whitespace_changes_spec.rb +++ b/spec/features/merge_request/user_toggles_whitespace_changes_spec.rb @@ -21,13 +21,13 @@ describe 'clicking "Hide whitespace changes" button' do it 'toggles the "Hide whitespace changes" button', quarantine: 'https://gitlab.com/gitlab-org/gitlab/-/issues/333793' do - find('[data-testid="show-whitespace"]').click + find_by_testid('show-whitespace').click visit diffs_project_merge_request_path(project, merge_request) find('.js-show-diff-settings').click - expect(find('[data-testid="show-whitespace"]')).not_to be_checked + expect(find_by_testid('show-whitespace')).not_to be_checked end end end diff --git a/spec/features/milestone_spec.rb b/spec/features/milestone_spec.rb index 61098a8f2cd15b9c80c4cf4d8df878daef8c210d..058b4c8b770ef93329546126a80b8c87b7030e28 100644 --- a/spec/features/milestone_spec.rb +++ b/spec/features/milestone_spec.rb @@ -25,7 +25,7 @@ click_button 'Create milestone' - expect(find('[data-testid="no-issues-alert"]')).to have_content('Assign some issues to this milestone.') + expect(find_by_testid('no-issues-alert')).to have_content('Assign some issues to this milestone.') expect(page).to have_content('Nov 16, 2016–Dec 16, 2016') end @@ -43,7 +43,7 @@ create(:issue, title: "Bugfix1", project: project, milestone: milestone, state: "closed") visit project_milestone_path(project, milestone) - expect(find('[data-testid="all-issues-closed-alert"]')).to have_content('All issues for this milestone are closed. You may close this milestone now.') + expect(find_by_testid('all-issues-closed-alert')).to have_content('All issues for this milestone are closed. You may close this milestone now.') end end @@ -82,7 +82,7 @@ wait_for_requests - page.within('[data-testid="noTrackingPane"]') do + within_testid('noTrackingPane') do expect(page).to have_content 'No estimate or time spent' end end @@ -100,7 +100,7 @@ wait_for_requests - page.within('[data-testid="spentOnlyPane"]') do + within_testid('spentOnlyPane') do expect(page).to have_content 'Spent: 3h' end end diff --git a/spec/features/nav/pinned_nav_items_spec.rb b/spec/features/nav/pinned_nav_items_spec.rb index 2312ded2cf798442f31469813847ce8ae4966f01..07958bf3d6646ff8dd9ac1efc80dbff61f74617c 100644 --- a/spec/features/nav/pinned_nav_items_spec.rb +++ b/spec/features/nav/pinned_nav_items_spec.rb @@ -35,7 +35,7 @@ end it 'adds sensible defaults' do - within '[data-testid="pinned-nav-items"]' do + within_testid 'pinned-nav-items' do expect(page).to have_link 'Issues' end end @@ -53,7 +53,7 @@ add_pin('Members') end - within '[data-testid="pinned-nav-items"]' do + within_testid 'pinned-nav-items' do expect(page).to have_link 'Issues' expect(page).to have_link 'Activity' expect(page).to have_link 'Members' @@ -95,7 +95,7 @@ end it 'can be unpinned from within the pinned section' do - within '[data-testid="pinned-nav-items"]' do + within_testid 'pinned-nav-items' do remove_pin('Terraform states') expect(page).not_to have_content 'Terraform states' end @@ -108,13 +108,13 @@ remove_pin('Terraform modules') end - within '[data-testid="pinned-nav-items"]' do + within_testid 'pinned-nav-items' do expect(page).not_to have_content 'Terraform modules' end end it 'can be reordered' do - within '[data-testid="pinned-nav-items"]' do + within_testid 'pinned-nav-items' do pinned_items = page.find_all('a').map(&:text) item2 = page.find('a', text: 'Terraform states') item3 = page.find('a', text: 'Terraform modules') @@ -146,7 +146,7 @@ end visit project_path(project_without_repo) - within '[data-testid="pinned-nav-items"]' do + within_testid 'pinned-nav-items' do activity_item = page.find('a', text: 'Activity') members_item = page.find('a', text: 'Members') drag_item(members_item, to: activity_item) @@ -156,7 +156,7 @@ end it 'keeps pins of non-available features' do - within '[data-testid="pinned-nav-items"]' do + within_testid 'pinned-nav-items' do pinned_items = page.find_all('a') .map(&:text) .map { |text| text.split("\n").first } # to drop the counter badge text from "Issues\n0" @@ -173,13 +173,13 @@ context 'when a pinned item is clicked in the Pinned section' do before do - within '[data-testid="pinned-nav-items"]' do + within_testid 'pinned-nav-items' do click_on 'Issues' end end it 'shows the Pinned section as expanded' do - within '[data-testid="pinned-nav-items"]' do + within_testid 'pinned-nav-items' do expect(page).to have_link 'Issues' end end @@ -218,31 +218,37 @@ private def add_pin(nav_item_title) - nav_item = find("[data-testid=\"nav-item\"]", text: nav_item_title) + nav_item = find_by_testid('nav-item', text: nav_item_title) scroll_to(nav_item) nav_item.hover - pin_button = nav_item.find("[data-testid=\"nav-item-pin\"]") - pin_button.click - wait_for_requests + within(nav_item) do + pin_button = find_by_testid('nav-item-pin') + pin_button.click + wait_for_requests + end end def remove_pin(nav_item_title) - nav_item = find("[data-testid=\"nav-item\"]", text: nav_item_title) + nav_item = find_by_testid('nav-item', text: nav_item_title) scroll_to(nav_item) nav_item.hover - unpin_button = nav_item.find("[data-testid=\"nav-item-unpin\"]") - unpin_button.click - wait_for_requests + within(nav_item) do + unpin_button = find_by_testid('nav-item-unpin') + unpin_button.click + wait_for_requests + end end def drag_item(item, to:) item.hover - drag_handle = item.find('[data-testid="grip-icon"]') - - # Reduce delay to make it less likely for draggables to - # change position during drag operation, which reduces - # flakiness. - drag_handle.drag_to(to, delay: 0.01) - wait_for_requests + within(item) do + drag_handle = find_by_testid('grip-icon') + + # Reduce delay to make it less likely for draggables to + # change position during drag operation, which reduces + # flakiness. + drag_handle.drag_to(to, delay: 0.01) + wait_for_requests + end end end diff --git a/spec/features/populate_new_pipeline_vars_with_params_spec.rb b/spec/features/populate_new_pipeline_vars_with_params_spec.rb index 8bb5f2514ef33ca341295d95e4d6004683d2067a..20cf6d045d59ba880bf81ec42a4e1d6678ed999c 100644 --- a/spec/features/populate_new_pipeline_vars_with_params_spec.rb +++ b/spec/features/populate_new_pipeline_vars_with_params_spec.rb @@ -16,15 +16,15 @@ it "var[key1]=value1 populates env_var variable correctly" do page.within(all("[data-testid='ci-variable-row-container']")[0]) do - expect(find("[data-testid='pipeline-form-ci-variable-key-field']").value).to eq('key1') - expect(find("[data-testid='pipeline-form-ci-variable-value-field']").value).to eq('value1') + expect(find_by_testid('pipeline-form-ci-variable-key-field').value).to eq('key1') + expect(find_by_testid('pipeline-form-ci-variable-value-field').value).to eq('value1') end end it "file_var[key2]=value2 populates file variable correctly" do page.within(all("[data-testid='ci-variable-row-container']")[1]) do - expect(find("[data-testid='pipeline-form-ci-variable-key-field']").value).to eq('key2') - expect(find("[data-testid='pipeline-form-ci-variable-value-field']").value).to eq('value2') + expect(find_by_testid('pipeline-form-ci-variable-key-field').value).to eq('key2') + expect(find_by_testid('pipeline-form-ci-variable-value-field').value).to eq('value2') end end end diff --git a/spec/features/profile_spec.rb b/spec/features/profile_spec.rb index 6c6deef5b7405816c851c6274b479e6be9132555..0e3070b671b09de947b369581033647ea184f7a4 100644 --- a/spec/features/profile_spec.rb +++ b/spec/features/profile_spec.rb @@ -115,7 +115,7 @@ it 'changes my username' do fill_in 'username-change-input', with: 'new-username' - page.find('[data-testid="username-change-confirmation-modal"]').click + find_by_testid('username-change-confirmation-modal').click page.within('.modal') do find('.js-modal-action-primary').click diff --git a/spec/features/profiles/account_spec.rb b/spec/features/profiles/account_spec.rb index 08d9ec5f3a9f364b681f8d407323c3f064ff5142..74932f28cbe5fc710ea8b483d2d3b33c646076c5 100644 --- a/spec/features/profiles/account_spec.rb +++ b/spec/features/profiles/account_spec.rb @@ -128,7 +128,7 @@ def update_username(new_username) fill_in 'username-change-input', with: new_username - page.find('[data-testid="username-change-confirmation-modal"]').click + find_by_testid('username-change-confirmation-modal').click page.within('.modal') do find('.js-modal-action-primary').click diff --git a/spec/features/profiles/keys_spec.rb b/spec/features/profiles/keys_spec.rb index 65b65c356fa663744f11e53677e275fd8b7e8fc0..1d7bad930378d73628b233ab3f2c34c1bb6a1a49 100644 --- a/spec/features/profiles/keys_spec.rb +++ b/spec/features/profiles/keys_spec.rb @@ -31,7 +31,7 @@ expect(page).to have_content(format(s_('Profiles|SSH Key: %{title}'), title: attrs[:title])) expect(page).to have_content(attrs[:key]) - expect(find('[data-testid="breadcrumb-current-link"]')).to have_link(attrs[:title]) + expect(find_by_testid('breadcrumb-current-link')).to have_link(attrs[:title]) end it 'shows a confirmable warning if the key begins with an algorithm name that is unsupported' do diff --git a/spec/features/profiles/oauth_applications_spec.rb b/spec/features/profiles/oauth_applications_spec.rb index 0b1d67d00c9da41d607f1390ad2459a49739e77d..c201239262e69719fea781fb3c202d064cbcb0b5 100644 --- a/spec/features/profiles/oauth_applications_spec.rb +++ b/spec/features/profiles/oauth_applications_spec.rb @@ -17,7 +17,7 @@ visit oauth_application_path(application) expect(page).to have_content("Application: #{application.name}") - expect(find('[data-testid="breadcrumb-current-link"]')).to have_link(application.name) + expect(find_by_testid('breadcrumb-current-link')).to have_link(application.name) end it 'deletes an application' do diff --git a/spec/features/profiles/user_creates_comment_template_spec.rb b/spec/features/profiles/user_creates_comment_template_spec.rb index dcaf47088b02d4fa4b4dae5ce3562b6efc640996..e127fc0a89d6f8945eea1702af3041bc5785ce1b 100644 --- a/spec/features/profiles/user_creates_comment_template_spec.rb +++ b/spec/features/profiles/user_creates_comment_template_spec.rb @@ -16,8 +16,8 @@ it 'shows the user a list of their saved replies' do click_button 'Add new' - find('[data-testid="comment-template-name-input"]').set('test') - find('[data-testid="comment-template-content-input"]').set('Test content') + find_by_testid('comment-template-name-input').set('test') + find_by_testid('comment-template-content-input').set('Test content') click_button 'Save' diff --git a/spec/features/profiles/user_deletes_comment_template_spec.rb b/spec/features/profiles/user_deletes_comment_template_spec.rb index 7ef857e9622fcaf61e53ec84358a1b935b6f6237..c71d7f46987c4f002a8bd7b628940bacb030cf5c 100644 --- a/spec/features/profiles/user_deletes_comment_template_spec.rb +++ b/spec/features/profiles/user_deletes_comment_template_spec.rb @@ -15,7 +15,7 @@ visit profile_comment_templates_path click_button 'Comment template actions' - find('[data-testid="comment-template-delete-btn"]').click + find_by_testid('comment-template-delete-btn').click page.within('.gl-modal') do click_button 'Delete' diff --git a/spec/features/profiles/user_edit_profile_spec.rb b/spec/features/profiles/user_edit_profile_spec.rb index b8fb2c59f31d979f7c613093355910ddd8421874..0dc69017a4225c307ffb90a95ad5e79dbb83861a 100644 --- a/spec/features/profiles/user_edit_profile_spec.rb +++ b/spec/features/profiles/user_edit_profile_spec.rb @@ -24,7 +24,7 @@ def visit_user end def toggle_busy_status - find('[data-testid="user-availability-checkbox"]').set(true) + find_by_testid('user-availability-checkbox').set(true) end it 'changes user profile' do @@ -276,7 +276,7 @@ def select_emoji(emoji_name) end it 'sets the users status to busy' do - busy_status = find('[data-testid="user-availability-checkbox"]') + busy_status = find_by_testid('user-availability-checkbox') expect(busy_status.checked?).to eq(false) @@ -400,7 +400,7 @@ def set_user_status_in_modal it 'sets the users status to busy' do open_user_status_modal - busy_status = find('[data-testid="user-availability-checkbox"]') + busy_status = find_by_testid('user-availability-checkbox') expect(busy_status.checked?).to eq(false) @@ -543,7 +543,9 @@ def set_user_status_in_modal page.find('.user-time-preferences .gl-new-dropdown-toggle').click - expect(page.find('.user-time-preferences [data-testid="base-dropdown-menu"]')).to be_visible + within('.user-time-preferences') do + expect(find_by_testid('base-dropdown-menu')).to be_visible + end page.find("li", text: "Arizona").click