diff --git a/.rubocop_todo/capybara/testid_finders.yml b/.rubocop_todo/capybara/testid_finders.yml index 558b21c7d35439a87e3f292ea682ba0d44545b92..21bef5cfca5cbd07d7e562d10686d11eff4966aa 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 2e6bfdcc407ce73d7a7d1df9bb38c9ef6a514ce1..12e6ba45a8b0a459a32f9acf1f52567786ebf091 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 cc01de736cb22edba6f243257b4b01821ec0075a..bbea1d85928e3ec0e3502347dbabaaf60c8343cd 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 dfda200cded96a2032cb3099cf213cde9a7819c3..752bf9b50263921de4b06879a62bbd97b7d7caff 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 d468d3ec7e7caaf0a677fc45011d12937cc3e29f..c82440d7ee8eb5b6b37f1bce76e65e7edbcc6b0a 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 41b8ad7825c51ba20c40196c099bba10074687c8..5bddb1d93e16af1d398f226f9ef80773864a6e03 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 22cc5c67987b0ab6f9449ba0dac1d8839b0bb2c1..1b63f446ea57e9a860c1a1578270d0ea5c15d049 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 bc370a296e40b43e72dbcac44092c55594a81df3..e7a39ccd23f670e80d1b4e215333bbdce3c55c54 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 e7e419a4c602ef580c784b5b1b82dac9bd3e587b..920d0afa77dffef9a5393fdcc6c7b5c2427f1a0f 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 bc4d64dad2138ffb6f5a9424d21f3a9b1ba93aa4..ec9f526d4e25647e2969d697c4428d47c2f60106 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 b608fc953f327f0d79555db4a0c72961ec3bd789..895c1ccc94149aeab442b2212779e8e610ff9901 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 5d722ddbedb8a4bdc434c31cf65b2776d9dac9fa..6237e669662263b8c74ee9bce1e0289cda472cb5 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 5a0b70532aa2597b2eea98815bd5d38563556982..fc60e6ba80bb0baeea7e282bcdb5d53b0efec786 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 ccf5c6996f1a62c4783baca43531ea9897bf70f8..bac1a42720ac7de48ee7a63b445c93d29c88c64d 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 61878a05fdfd8e83f4aa2cacf95d481d9169b936..66923fc23251608ffc49c1ea17c2625fa7c2f83a 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 c2b486a98ce123b0f3a2d44aca123f8bf17914c1..cfe011334497e57140f51c400ab5b33539f81eab 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