diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-30 21:09:47 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-30 21:09:47 +0300 |
commit | cd99e8611a6df11975c227517892606440ad3ff6 (patch) | |
tree | aea53bef850be971e128b4be9649654d760b2b02 /spec/features/search | |
parent | 412fe7ab5511ec446f250d415d571108fe838b68 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/features/search')
8 files changed, 448 insertions, 503 deletions
diff --git a/spec/features/search/user_searches_for_code_spec.rb b/spec/features/search/user_searches_for_code_spec.rb index dd7095107f4..6c9db029683 100644 --- a/spec/features/search/user_searches_for_code_spec.rb +++ b/spec/features/search/user_searches_for_code_spec.rb @@ -3,242 +3,235 @@ require 'spec_helper' RSpec.describe 'User searches for code', :js, :disable_rate_limiter, feature_category: :global_search do - using RSpec::Parameterized::TableSyntax - let_it_be(:user) { create(:user) } let_it_be_with_reload(:project) { create(:project, :repository, namespace: user.namespace) } - where(search_page_vertical_nav_enabled: [true, false]) - with_them do - context 'when signed in' do + context 'when signed in' do + before do + project.add_maintainer(user) + sign_in(user) + end + + context 'when on a project page' do before do - stub_feature_flags(search_page_vertical_nav: search_page_vertical_nav_enabled) - project.add_maintainer(user) - sign_in(user) + visit(project_path(project)) end - context 'when on a project page' do - before do - visit(project_path(project)) - end + it 'finds a file' do + submit_search('application.js') + select_search_scope('Code') - it 'finds a file' do - submit_search('application.js') - select_search_scope('Code') + expect(page).to have_selector('.results', text: 'application.js') + expect(page).to have_selector('.file-content .code') + expect(page).to have_selector("span.line[lang='javascript']") + expect(page).to have_link('application.js', href: %r{master/files/js/application.js}) + expect(page).to have_button('Copy file path') + end + end + + context 'when on a project search page' do + before do + visit(search_path) + find('[data-testid="project-filter"]').click + + wait_for_requests - expect(page).to have_selector('.results', text: 'application.js') - expect(page).to have_selector('.file-content .code') - expect(page).to have_selector("span.line[lang='javascript']") - expect(page).to have_link('application.js', href: %r{master/files/js/application.js}) - expect(page).to have_button('Copy file path') + page.within('[data-testid="project-filter"]') do + click_on(project.name) end end - context 'when on a project search page' do - before do - visit(search_path) - find('[data-testid="project-filter"]').click + include_examples 'top right search form' + include_examples 'search timeouts', 'blobs' do + let(:additional_params) { { project_id: project.id } } + end - wait_for_requests + context 'when searching code' do + let(:expected_result) { 'Update capybara, rspec-rails, poltergeist to recent versions' } - page.within('[data-testid="project-filter"]') do - click_on(project.name) - end + before do + fill_in('dashboard_search', with: 'rspec') + find('.gl-search-box-by-click-search-button').click end - include_examples 'top right search form' - include_examples 'search timeouts', 'blobs' do - let(:additional_params) { { project_id: project.id } } + it 'finds code and links to blob' do + expect(page).to have_selector('.results', text: expected_result) + + find("#blob-L3").click + expect(current_url).to match(%r{blob/master/.gitignore#L3}) end - context 'when searching code' do - let(:expected_result) { 'Update capybara, rspec-rails, poltergeist to recent versions' } + it 'finds code and links to blame' do + expect(page).to have_selector('.results', text: expected_result) - before do - fill_in('dashboard_search', with: 'rspec') - find('.gl-search-box-by-click-search-button').click - end + find("#blame-L3").click + expect(current_url).to match(%r{blame/master/.gitignore#L3}) + end - it 'finds code and links to blob' do - expect(page).to have_selector('.results', text: expected_result) + it_behaves_like 'code highlight' do + subject { page } + end + end - find("#blob-L3").click - expect(current_url).to match(%r{blob/master/.gitignore#L3}) - end + it 'search multiple words with refs switching' do + expected_result = 'Use `snake_case` for naming files' + search = 'for naming files' + ref_selector = 'v1.0.0' - it 'finds code and links to blame' do - expect(page).to have_selector('.results', text: expected_result) + fill_in('dashboard_search', with: search) + find('.gl-search-box-by-click-search-button').click - find("#blame-L3").click - expect(current_url).to match(%r{blame/master/.gitignore#L3}) - end + expect(page).to have_selector('.results', text: expected_result) - it_behaves_like 'code highlight' do - subject { page } - end - end + find('.ref-selector').click + wait_for_requests - it 'search multiple words with refs switching' do - expected_result = 'Use `snake_case` for naming files' - search = 'for naming files' + page.within('.ref-selector') do + fill_in 'Search by Git revision', with: ref_selector + wait_for_requests + find('li', text: ref_selector, match: :prefer_exact).click + end - fill_in('dashboard_search', with: search) - find('.gl-search-box-by-click-search-button').click + expect(page).to have_selector('.results', text: expected_result) - expect(page).to have_selector('.results', text: expected_result) + expect(find_field('dashboard_search').value).to eq(search) + expect(find("#blob-L1502")[:href]).to match(%r{blob/v1.0.0/files/markdown/ruby-style-guide.md#L1502}) + expect(find("#blame-L1502")[:href]).to match(%r{blame/v1.0.0/files/markdown/ruby-style-guide.md#L1502}) + end + end - find('.ref-selector').click - wait_for_requests + context 'when :new_header_search is true' do + context 'search code within refs' do + let(:ref_name) { 'v1.0.0' } - page.within('.ref-selector') do - find('li', text: 'v1.0.0').click - end + before do + # This feature is disabled by default in spec_helper.rb. + # We missed a feature breaking bug, so to prevent this regression, testing both scenarios for this spec. + # This can be removed as part of closing https://gitlab.com/gitlab-org/gitlab/-/issues/339348. + stub_feature_flags(new_header_search: true) + visit(project_tree_path(project, ref_name)) - expect(page).to have_selector('.results', text: expected_result) + submit_search('gitlab-grack') + select_search_scope('Code') + end - expect(find_field('dashboard_search').value).to eq(search) - expect(find("#blob-L1502")[:href]).to match(%r{blob/v1.0.0/files/markdown/ruby-style-guide.md#L1502}) - expect(find("#blame-L1502")[:href]).to match(%r{blame/v1.0.0/files/markdown/ruby-style-guide.md#L1502}) + it 'shows ref switcher in code result summary' do + expect(find('.ref-selector')).to have_text(ref_name) end - end - context 'when :new_header_search is true' do - context 'search code within refs' do - let(:ref_name) { 'v1.0.0' } + it 'persists branch name across search' do + find('.gl-search-box-by-click-search-button').click + expect(find('.ref-selector')).to have_text(ref_name) + end - before do - # This feature is disabled by default in spec_helper.rb. - # We missed a feature breaking bug, so to prevent this regression, testing both scenarios for this spec. - # This can be removed as part of closing https://gitlab.com/gitlab-org/gitlab/-/issues/339348. - stub_feature_flags(new_header_search: true) - visit(project_tree_path(project, ref_name)) + # this example is use to test the design that the refs is not + # only represent the branch as well as the tags. + it 'ref switcher list all the branches and tags' do + find('.ref-selector').click + wait_for_requests - submit_search('gitlab-grack') - select_search_scope('Code') + page.within('.ref-selector') do + expect(page).to have_selector('li', text: 'add-ipython-files') + expect(page).to have_selector('li', text: 'v1.0.0') end + end - it 'shows ref switcher in code result summary' do - expect(find('.ref-selector')).to have_text(ref_name) - end + it 'search result changes when refs switched' do + ref = 'master' + expect(find('.results')).not_to have_content('path = gitlab-grack') - it 'persists branch name across search' do - find('.gl-search-box-by-click-search-button').click - expect(find('.ref-selector')).to have_text(ref_name) - end + find('.ref-selector').click + wait_for_requests - # this example is use to test the design that the refs is not - # only represent the branch as well as the tags. - it 'ref switcher list all the branches and tags' do - find('.ref-selector').click + page.within('.ref-selector') do + fill_in _('Search by Git revision'), with: ref wait_for_requests - page.within('.ref-selector') do - expect(page).to have_selector('li', text: 'add-ipython-files') - expect(page).to have_selector('li', text: 'v1.0.0') - end + find('li', text: ref).click end - it 'search result changes when refs switched' do - ref = 'master' - expect(find('.results')).not_to have_content('path = gitlab-grack') + expect(page).to have_selector('.results', text: 'path = gitlab-grack') + end + end + end - find('.ref-selector').click - wait_for_requests + context 'when :new_header_search is false' do + context 'search code within refs' do + let(:ref_name) { 'v1.0.0' } - page.within('.ref-selector') do - fill_in _('Search by Git revision'), with: ref - wait_for_requests + before do + # This feature is disabled by default in spec_helper.rb. + # We missed a feature breaking bug, so to prevent this regression, testing both scenarios for this spec. + # This can be removed as part of closing https://gitlab.com/gitlab-org/gitlab/-/issues/339348. + stub_feature_flags(new_header_search: false) + visit(project_tree_path(project, ref_name)) - find('li', text: ref).click - end + submit_search('gitlab-grack') + select_search_scope('Code') + end - expect(page).to have_selector('.results', text: 'path = gitlab-grack') - end + it 'shows ref switcher in code result summary' do + expect(find('.ref-selector')).to have_text(ref_name) end - end - context 'when :new_header_search is false' do - context 'search code within refs' do - let(:ref_name) { 'v1.0.0' } + it 'persists branch name across search' do + find('.gl-search-box-by-click-search-button').click + expect(find('.ref-selector')).to have_text(ref_name) + end - before do - # This feature is disabled by default in spec_helper.rb. - # We missed a feature breaking bug, so to prevent this regression, testing both scenarios for this spec. - # This can be removed as part of closing https://gitlab.com/gitlab-org/gitlab/-/issues/339348. - stub_feature_flags(new_header_search: false) - visit(project_tree_path(project, ref_name)) + # this example is use to test the design that the refs is not + # only represent the branch as well as the tags. + it 'ref switcher list all the branches and tags' do + find('.ref-selector').click + wait_for_requests - submit_search('gitlab-grack') - select_search_scope('Code') + page.within('.ref-selector') do + expect(page).to have_selector('li', text: 'add-ipython-files') + expect(page).to have_selector('li', text: 'v1.0.0') end + end - it 'shows ref switcher in code result summary' do - expect(find('.ref-selector')).to have_text(ref_name) - end + it 'search result changes when refs switched' do + ref = 'master' + expect(find('.results')).not_to have_content('path = gitlab-grack') - it 'persists branch name across search' do - find('.gl-search-box-by-click-search-button').click - expect(find('.ref-selector')).to have_text(ref_name) - end + find('.ref-selector').click + wait_for_requests - # this example is use to test the design that the refs is not - # only represent the branch as well as the tags. - it 'ref switcher list all the branches and tags' do - find('.ref-selector').click + page.within('.ref-selector') do + fill_in _('Search by Git revision'), with: ref wait_for_requests - page.within('.ref-selector') do - expect(page).to have_selector('li', text: 'add-ipython-files') - expect(page).to have_selector('li', text: 'v1.0.0') - end + find('li', text: ref).click end - it 'search result changes when refs switched' do - ref = 'master' - expect(find('.results')).not_to have_content('path = gitlab-grack') - - find('.ref-selector').click - wait_for_requests - - page.within('.ref-selector') do - fill_in _('Search by Git revision'), with: ref - wait_for_requests - - find('li', text: ref).click - end - - expect(page).to have_selector('.results', text: 'path = gitlab-grack') - end + expect(page).to have_selector('.results', text: 'path = gitlab-grack') end end + end - it 'no ref switcher shown in issue result summary' do - issue = create(:issue, title: 'test', project: project) - visit(project_tree_path(project)) + it 'no ref switcher shown in issue result summary' do + issue = create(:issue, title: 'test', project: project) + visit(project_tree_path(project)) - submit_search('test') - select_search_scope('Code') + submit_search('test') + select_search_scope('Code') - expect(page).to have_selector('.ref-selector') + expect(page).to have_selector('.ref-selector') - select_search_scope('Issues') + select_search_scope('Issues') - expect(find(:css, '.results')).to have_link(issue.title) - expect(page).not_to have_selector('.ref-selector') - end + expect(find(:css, '.results')).to have_link(issue.title) + expect(page).not_to have_selector('.ref-selector') end + end - context 'when signed out' do - before do - stub_feature_flags(search_page_vertical_nav: search_page_vertical_nav_enabled) - end - - context 'when block_anonymous_global_searches is enabled' do - it 'is redirected to login page' do - visit(search_path) + context 'when signed out' do + context 'when block_anonymous_global_searches is enabled' do + it 'is redirected to login page' do + visit(search_path) - expect(page).to have_content('You must be logged in to search across all of GitLab') - end + expect(page).to have_content('You must be logged in to search across all of GitLab') end end end diff --git a/spec/features/search/user_searches_for_comments_spec.rb b/spec/features/search/user_searches_for_comments_spec.rb index d7f6143d173..f7af1797c71 100644 --- a/spec/features/search/user_searches_for_comments_spec.rb +++ b/spec/features/search/user_searches_for_comments_spec.rb @@ -3,51 +3,45 @@ require 'spec_helper' RSpec.describe 'User searches for comments', :js, :disable_rate_limiter, feature_category: :global_search do - using RSpec::Parameterized::TableSyntax - let_it_be(:project) { create(:project, :repository) } let_it_be(:user) { create(:user) } - where(search_page_vertical_nav_enabled: [true, false]) - with_them do - before do - stub_feature_flags(search_page_vertical_nav: search_page_vertical_nav_enabled) - project.add_reporter(user) - sign_in(user) + before do + project.add_reporter(user) + sign_in(user) - visit(project_path(project)) - end + visit(project_path(project)) + end - include_examples 'search timeouts', 'notes' do - let(:additional_params) { { project_id: project.id } } - end + include_examples 'search timeouts', 'notes' do + let(:additional_params) { { project_id: project.id } } + end - context 'when a comment is in commits' do - context 'when comment belongs to an invalid commit' do - let(:comment) { create(:note_on_commit, author: user, project: project, commit_id: 12345678, note: 'Bug here') } + context 'when a comment is in commits' do + context 'when comment belongs to an invalid commit' do + let(:comment) { create(:note_on_commit, author: user, project: project, commit_id: 12345678, note: 'Bug here') } - it 'finds a commit' do - submit_search(comment.note) - select_search_scope('Comments') + it 'finds a commit' do + submit_search(comment.note) + select_search_scope('Comments') - page.within('.results') do - expect(page).to have_content('Commit deleted') - expect(page).to have_content('12345678') - end + page.within('.results') do + expect(page).to have_content('Commit deleted') + expect(page).to have_content('12345678') end end end + end - context 'when a comment is in a snippet' do - let(:snippet) { create(:project_snippet, :private, project: project, author: user, title: 'Some title') } - let(:comment) { create(:note, noteable: snippet, author: user, note: 'Supercalifragilisticexpialidocious', project: project) } + context 'when a comment is in a snippet' do + let(:snippet) { create(:project_snippet, :private, project: project, author: user, title: 'Some title') } + let(:comment) { create(:note, noteable: snippet, author: user, note: 'Supercalifragilisticexpialidocious', project: project) } - it 'finds a snippet' do - submit_search(comment.note) - select_search_scope('Comments') + it 'finds a snippet' do + submit_search(comment.note) + select_search_scope('Comments') - expect(page).to have_selector('.results', text: snippet.title) - end + expect(page).to have_selector('.results', text: snippet.title) end end end diff --git a/spec/features/search/user_searches_for_commits_spec.rb b/spec/features/search/user_searches_for_commits_spec.rb index 1fd62a01c78..724daf9277d 100644 --- a/spec/features/search/user_searches_for_commits_spec.rb +++ b/spec/features/search/user_searches_for_commits_spec.rb @@ -3,61 +3,55 @@ require 'spec_helper' RSpec.describe 'User searches for commits', :js, :clean_gitlab_redis_rate_limiting, feature_category: :global_search do - using RSpec::Parameterized::TableSyntax - let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, :repository) } - let(:project) { create(:project, :repository) } let(:sha) { '6d394385cf567f80a8fd85055db1ab4c5295806f' } - where(search_page_vertical_nav_enabled: [true, false]) - with_them do - before do - stub_feature_flags(search_page_vertical_nav: search_page_vertical_nav_enabled) - project.add_reporter(user) - sign_in(user) + before do + project.add_reporter(user) + sign_in(user) - visit(search_path(project_id: project.id)) - end + visit(search_path(project_id: project.id)) + end - include_examples 'search timeouts', 'commits' do - let(:additional_params) { { project_id: project.id } } - end + include_examples 'search timeouts', 'commits' do + let(:additional_params) { { project_id: project.id } } + end - context 'when searching by SHA' do - it 'finds a commit and redirects to its page' do - submit_search(sha) + context 'when searching by SHA' do + it 'finds a commit and redirects to its page' do + submit_search(sha) - expect(page).to have_current_path(project_commit_path(project, sha)) - end + expect(page).to have_current_path(project_commit_path(project, sha)) + end - it 'finds a commit in uppercase and redirects to its page' do - submit_search(sha.upcase) + it 'finds a commit in uppercase and redirects to its page' do + submit_search(sha.upcase) - expect(page).to have_current_path(project_commit_path(project, sha)) - end + expect(page).to have_current_path(project_commit_path(project, sha)) end + end - context 'when searching by message' do - it 'finds a commit and holds on /search page' do - project.repository.commit_files( - user, - message: 'Message referencing another sha: "deadbeef"', - branch_name: 'master', - actions: [{ action: :create, file_path: 'a/new.file', contents: 'new file' }] - ) + context 'when searching by message' do + it 'finds a commit and holds on /search page' do + project.repository.commit_files( + user, + message: 'Message referencing another sha: "deadbeef"', + branch_name: 'master', + actions: [{ action: :create, file_path: 'a/new.file', contents: 'new file' }] + ) - submit_search('deadbeef') + submit_search('deadbeef') - expect(page).to have_current_path('/search', ignore_query: true) - end + expect(page).to have_current_path('/search', ignore_query: true) + end - it 'finds multiple commits' do - submit_search('See merge request') - select_search_scope('Commits') + it 'finds multiple commits' do + submit_search('See merge request') + select_search_scope('Commits') - expect(page).to have_selector('.commit-row-description', visible: false, count: 9) - end + expect(page).to have_selector('.commit-row-description', visible: false, count: 9) end end end diff --git a/spec/features/search/user_searches_for_issues_spec.rb b/spec/features/search/user_searches_for_issues_spec.rb index 6ebbe86d1a9..9451e337db1 100644 --- a/spec/features/search/user_searches_for_issues_spec.rb +++ b/spec/features/search/user_searches_for_issues_spec.rb @@ -3,8 +3,6 @@ require 'spec_helper' RSpec.describe 'User searches for issues', :js, :clean_gitlab_redis_rate_limiting, feature_category: :global_search do - using RSpec::Parameterized::TableSyntax - let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project, namespace: user.namespace) } @@ -17,133 +15,123 @@ RSpec.describe 'User searches for issues', :js, :clean_gitlab_redis_rate_limitin select_search_scope('Issues') end - where(search_page_vertical_nav_enabled: [true, false]) - - with_them do - context 'when signed in' do - before do - stub_feature_flags(search_page_vertical_nav: search_page_vertical_nav_enabled) + context 'when signed in' do + before do + project.add_maintainer(user) + sign_in(user) - project.add_maintainer(user) - sign_in(user) + visit(search_path) + end - visit(search_path) - end + include_examples 'top right search form' + include_examples 'search timeouts', 'issues' - include_examples 'top right search form' - include_examples 'search timeouts', 'issues' + it 'finds an issue' do + search_for_issue(issue1.title) - it 'finds an issue' do - search_for_issue(issue1.title) - - page.within('.results') do - expect(page).to have_link(issue1.title) - expect(page).not_to have_link(issue2.title) - end + page.within('.results') do + expect(page).to have_link(issue1.title) + expect(page).not_to have_link(issue2.title) end + end - it 'hides confidential icon for non-confidential issues' do - search_for_issue(issue1.title) + it 'hides confidential icon for non-confidential issues' do + search_for_issue(issue1.title) - page.within('.results') do - expect(page).not_to have_css('[data-testid="eye-slash-icon"]') - end + page.within('.results') do + expect(page).not_to have_css('[data-testid="eye-slash-icon"]') end + end - it 'shows confidential icon for confidential issues' do - search_for_issue(issue2.title) + it 'shows confidential icon for confidential issues' do + search_for_issue(issue2.title) - page.within('.results') do - expect(page).to have_css('[data-testid="eye-slash-icon"]') - end + page.within('.results') do + expect(page).to have_css('[data-testid="eye-slash-icon"]') end + end - it 'shows correct badge for open issues' do - search_for_issue(issue1.title) + it 'shows correct badge for open issues' do + search_for_issue(issue1.title) - page.within('.results') do - expect(page).to have_css('.badge-success') - expect(page).not_to have_css('.badge-info') - end + page.within('.results') do + expect(page).to have_css('.badge-success') + expect(page).not_to have_css('.badge-info') end + end - it 'shows correct badge for closed issues' do - search_for_issue(issue2.title) + it 'shows correct badge for closed issues' do + search_for_issue(issue2.title) - page.within('.results') do - expect(page).not_to have_css('.badge-success') - expect(page).to have_css('.badge-info') - end + page.within('.results') do + expect(page).not_to have_css('.badge-success') + expect(page).to have_css('.badge-info') end + end - it 'sorts by created date' do - search_for_issue('issue') + it 'sorts by created date' do + search_for_issue('issue') - page.within('.results') do - expect(page.all('.search-result-row').first).to have_link(issue2.title) - expect(page.all('.search-result-row').last).to have_link(issue1.title) - end + page.within('.results') do + expect(page.all('.search-result-row').first).to have_link(issue2.title) + expect(page.all('.search-result-row').last).to have_link(issue1.title) + end - find('[data-testid="sort-highest-icon"]').click + find('[data-testid="sort-highest-icon"]').click - page.within('.results') do - expect(page.all('.search-result-row').first).to have_link(issue1.title) - expect(page.all('.search-result-row').last).to have_link(issue2.title) - end + page.within('.results') do + expect(page.all('.search-result-row').first).to have_link(issue1.title) + expect(page.all('.search-result-row').last).to have_link(issue2.title) end + end - context 'when on a project page' do - it 'finds an issue' do - find('[data-testid="project-filter"]').click + context 'when on a project page' do + it 'finds an issue' do + find('[data-testid="project-filter"]').click - wait_for_requests + wait_for_requests - page.within('[data-testid="project-filter"]') do - click_on(project.name) - end + page.within('[data-testid="project-filter"]') do + click_on(project.name) + end - search_for_issue(issue1.title) + search_for_issue(issue1.title) - page.within('.results') do - expect(page).to have_link(issue1.title) - expect(page).not_to have_link(issue2.title) - end + page.within('.results') do + expect(page).to have_link(issue1.title) + expect(page).not_to have_link(issue2.title) end end end + end - context 'when signed out' do - before do - stub_feature_flags(search_page_vertical_nav: search_page_vertical_nav_enabled) - end - - context 'when block_anonymous_global_searches is disabled' do - let_it_be(:project) { create(:project, :public) } + context 'when signed out' do + context 'when block_anonymous_global_searches is disabled' do + let_it_be(:project) { create(:project, :public) } - before do - stub_feature_flags(block_anonymous_global_searches: false) + before do + stub_feature_flags(block_anonymous_global_searches: false) - visit(search_path) - end + visit(search_path) + end - include_examples 'top right search form' + include_examples 'top right search form' - it 'finds an issue' do - search_for_issue(issue1.title) + it 'finds an issue' do + search_for_issue(issue1.title) - page.within('.results') do - expect(page).to have_link(issue1.title) - expect(page).not_to have_link(issue2.title) - end + page.within('.results') do + expect(page).to have_link(issue1.title) + expect(page).not_to have_link(issue2.title) end end + end - context 'when block_anonymous_global_searches is enabled' do - it 'is redirected to login page' do - visit(search_path) + context 'when block_anonymous_global_searches is enabled' do + it 'is redirected to login page' do + visit(search_path) - expect(page).to have_content('You must be logged in to search across all of GitLab') - end + expect(page).to have_content('You must be logged in to search across all of GitLab') end end end diff --git a/spec/features/search/user_searches_for_merge_requests_spec.rb b/spec/features/search/user_searches_for_merge_requests_spec.rb index 69f62a4c1e2..d7b52d9e07a 100644 --- a/spec/features/search/user_searches_for_merge_requests_spec.rb +++ b/spec/features/search/user_searches_for_merge_requests_spec.rb @@ -3,12 +3,10 @@ require 'spec_helper' RSpec.describe 'User searches for merge requests', :js, :clean_gitlab_redis_rate_limiting, feature_category: :global_search do - using RSpec::Parameterized::TableSyntax - - let(:user) { create(:user) } - let(:project) { create(:project, namespace: user.namespace) } - let!(:merge_request1) { create(:merge_request, title: 'Merge Request Foo', source_project: project, target_project: project, created_at: 1.hour.ago) } - let!(:merge_request2) { create(:merge_request, :simple, title: 'Merge Request Bar', source_project: project, target_project: project) } + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, namespace: user.namespace) } + let_it_be(:merge_request1) { create(:merge_request, title: 'Merge Request Foo', source_project: project, target_project: project, created_at: 1.hour.ago) } + let_it_be(:merge_request2) { create(:merge_request, :simple, title: 'Merge Request Bar', source_project: project, target_project: project) } def search_for_mr(search) fill_in('dashboard_search', with: search) @@ -16,64 +14,60 @@ RSpec.describe 'User searches for merge requests', :js, :clean_gitlab_redis_rate select_search_scope('Merge requests') end - where(search_page_vertical_nav_enabled: [true, false]) - with_them do - before do - stub_feature_flags(search_page_vertical_nav: search_page_vertical_nav_enabled) - sign_in(user) + before do + sign_in(user) - visit(search_path) - end + visit(search_path) + end - include_examples 'top right search form' - include_examples 'search timeouts', 'merge_requests' + include_examples 'top right search form' + include_examples 'search timeouts', 'merge_requests' - it 'finds a merge request' do - search_for_mr(merge_request1.title) + it 'finds a merge request' do + search_for_mr(merge_request1.title) - page.within('.results') do - expect(page).to have_link(merge_request1.title) - expect(page).not_to have_link(merge_request2.title) + page.within('.results') do + expect(page).to have_link(merge_request1.title) + expect(page).not_to have_link(merge_request2.title) - # Each result should have MR refs like `gitlab-org/gitlab!1` - page.all('.search-result-row').each do |e| - expect(e.text).to match(/!\d+/) - end + # Each result should have MR refs like `gitlab-org/gitlab!1` + page.all('.search-result-row').each do |e| + expect(e.text).to match(/!\d+/) end end + end - it 'sorts by created date' do - search_for_mr('Merge Request') + it 'sorts by created date' do + search_for_mr('Merge Request') - page.within('.results') do - expect(page.all('.search-result-row').first).to have_link(merge_request2.title) - expect(page.all('.search-result-row').last).to have_link(merge_request1.title) - end + page.within('.results') do + expect(page.all('.search-result-row').first).to have_link(merge_request2.title) + expect(page.all('.search-result-row').last).to have_link(merge_request1.title) + end - find('[data-testid="sort-highest-icon"]').click + find('[data-testid="sort-highest-icon"]').click - page.within('.results') do - expect(page.all('.search-result-row').first).to have_link(merge_request1.title) - expect(page.all('.search-result-row').last).to have_link(merge_request2.title) - end + page.within('.results') do + expect(page.all('.search-result-row').first).to have_link(merge_request1.title) + expect(page.all('.search-result-row').last).to have_link(merge_request2.title) end + end - context 'when on a project page' do - it 'finds a merge request' do - find('[data-testid="project-filter"]').click + context 'when on a project page' do + it 'finds a merge request' do + find('[data-testid="project-filter"]').click - wait_for_requests + wait_for_requests - page.within('[data-testid="project-filter"]') do - click_on(project.name) - end + page.within('[data-testid="project-filter"]') do + click_on(project.name) + end - search_for_mr(merge_request1.title) + search_for_mr(merge_request1.title) - page.within('.results') do - expect(page).to have_link(merge_request1.title) - expect(page).not_to have_link(merge_request2.title) - end + page.within('.results') do + expect(page).to have_link(merge_request1.title) + expect(page).not_to have_link(merge_request2.title) end end end diff --git a/spec/features/search/user_searches_for_milestones_spec.rb b/spec/features/search/user_searches_for_milestones_spec.rb index e87c2176380..238e59be940 100644 --- a/spec/features/search/user_searches_for_milestones_spec.rb +++ b/spec/features/search/user_searches_for_milestones_spec.rb @@ -4,29 +4,42 @@ require 'spec_helper' RSpec.describe 'User searches for milestones', :js, :clean_gitlab_redis_rate_limiting, feature_category: :global_search do - using RSpec::Parameterized::TableSyntax - let_it_be(:user) { create(:user) } let_it_be(:project) { create(:project, namespace: user.namespace) } + let_it_be(:milestone1) { create(:milestone, title: 'Foo', project: project) } + let_it_be(:milestone2) { create(:milestone, title: 'Bar', project: project) } + + before do + project.add_maintainer(user) + sign_in(user) - let!(:milestone1) { create(:milestone, title: 'Foo', project: project) } - let!(:milestone2) { create(:milestone, title: 'Bar', project: project) } + visit(search_path) + end - where(search_page_vertical_nav_enabled: [true, false]) + include_examples 'top right search form' + include_examples 'search timeouts', 'milestones' - with_them do - before do - project.add_maintainer(user) - sign_in(user) - stub_feature_flags(search_page_vertical_nav: search_page_vertical_nav_enabled) + it 'finds a milestone' do + fill_in('dashboard_search', with: milestone1.title) + find('.gl-search-box-by-click-search-button').click + select_search_scope('Milestones') - visit(search_path) + page.within('.results') do + expect(page).to have_link(milestone1.title) + expect(page).not_to have_link(milestone2.title) end + end - include_examples 'top right search form' - include_examples 'search timeouts', 'milestones' - + context 'when on a project page' do it 'finds a milestone' do + find('[data-testid="project-filter"]').click + + wait_for_requests + + page.within('[data-testid="project-filter"]') do + click_on(project.name) + end + fill_in('dashboard_search', with: milestone1.title) find('.gl-search-box-by-click-search-button').click select_search_scope('Milestones') @@ -36,26 +49,5 @@ feature_category: :global_search do expect(page).not_to have_link(milestone2.title) end end - - context 'when on a project page' do - it 'finds a milestone' do - find('[data-testid="project-filter"]').click - - wait_for_requests - - page.within('[data-testid="project-filter"]') do - click_on(project.name) - end - - fill_in('dashboard_search', with: milestone1.title) - find('.gl-search-box-by-click-search-button').click - select_search_scope('Milestones') - - page.within('.results') do - expect(page).to have_link(milestone1.title) - expect(page).not_to have_link(milestone2.title) - end - end - end end end diff --git a/spec/features/search/user_searches_for_users_spec.rb b/spec/features/search/user_searches_for_users_spec.rb index 4737cef98c7..e0a07c5103d 100644 --- a/spec/features/search/user_searches_for_users_spec.rb +++ b/spec/features/search/user_searches_for_users_spec.rb @@ -7,85 +7,80 @@ RSpec.describe 'User searches for users', :js, :clean_gitlab_redis_rate_limiting let_it_be(:user2) { create(:user, username: 'michael_bluth', name: 'Michael Bluth') } let_it_be(:user3) { create(:user, username: 'gob_2018', name: 'George Oscar Bluth') } - where(search_page_vertical_nav_enabled: [true, false]) - with_them do - before do - stub_feature_flags(search_page_vertical_nav: search_page_vertical_nav_enabled) - - sign_in(user1) - end + before do + sign_in(user1) + end - include_examples 'search timeouts', 'users' do - before do - visit(search_path) - end + include_examples 'search timeouts', 'users' do + before do + visit(search_path) end + end - context 'when on the dashboard' do - it 'finds the user' do - visit dashboard_projects_path + context 'when on the dashboard' do + it 'finds the user' do + visit dashboard_projects_path - submit_search('gob') - select_search_scope('Users') + submit_search('gob') + select_search_scope('Users') - page.within('.results') do - expect(page).to have_content('Gob Bluth') - expect(page).to have_content('@gob_bluth') - end + page.within('.results') do + expect(page).to have_content('Gob Bluth') + expect(page).to have_content('@gob_bluth') end end + end - context 'when on the project page' do - let_it_be_with_reload(:project) { create(:project) } + context 'when on the project page' do + let_it_be_with_reload(:project) { create(:project) } - before do - project.add_developer(user1) - project.add_developer(user2) - end + before do + project.add_developer(user1) + project.add_developer(user2) + end - it 'finds the user belonging to the project' do - visit project_path(project) + it 'finds the user belonging to the project' do + visit project_path(project) - submit_search('gob') - select_search_scope('Users') + submit_search('gob') + select_search_scope('Users') - page.within('.results') do - expect(page).to have_content('Gob Bluth') - expect(page).to have_content('@gob_bluth') + page.within('.results') do + expect(page).to have_content('Gob Bluth') + expect(page).to have_content('@gob_bluth') - expect(page).not_to have_content('Michael Bluth') - expect(page).not_to have_content('@michael_bluth') + expect(page).not_to have_content('Michael Bluth') + expect(page).not_to have_content('@michael_bluth') - expect(page).not_to have_content('George Oscar Bluth') - expect(page).not_to have_content('@gob_2018') - end + expect(page).not_to have_content('George Oscar Bluth') + expect(page).not_to have_content('@gob_2018') end end + end - context 'when on the group page' do - let(:group) { create(:group) } + context 'when on the group page' do + let(:group) { create(:group) } - before do - group.add_developer(user1) - group.add_developer(user2) - end + before do + group.add_developer(user1) + group.add_developer(user2) + end - it 'finds the user belonging to the group' do - visit group_path(group) + it 'finds the user belonging to the group' do + visit group_path(group) - submit_search('gob') - select_search_scope('Users') + submit_search('gob') + select_search_scope('Users') - page.within('.results') do - expect(page).to have_content('Gob Bluth') - expect(page).to have_content('@gob_bluth') + page.within('.results') do + expect(page).to have_content('Gob Bluth') + expect(page).to have_content('@gob_bluth') - expect(page).not_to have_content('Michael Bluth') - expect(page).not_to have_content('@michael_bluth') + expect(page).not_to have_content('Michael Bluth') + expect(page).not_to have_content('@michael_bluth') - expect(page).not_to have_content('George Oscar Bluth') - expect(page).not_to have_content('@gob_2018') - end + expect(page).not_to have_content('George Oscar Bluth') + expect(page).not_to have_content('@gob_2018') end end end diff --git a/spec/features/search/user_searches_for_wiki_pages_spec.rb b/spec/features/search/user_searches_for_wiki_pages_spec.rb index c7dc3e34bb7..1d8bdc58ce6 100644 --- a/spec/features/search/user_searches_for_wiki_pages_spec.rb +++ b/spec/features/search/user_searches_for_wiki_pages_spec.rb @@ -4,58 +4,53 @@ require 'spec_helper' RSpec.describe 'User searches for wiki pages', :js, :clean_gitlab_redis_rate_limiting, feature_category: :global_search do - using RSpec::Parameterized::TableSyntax - let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, :repository, :wiki_repo, namespace: user.namespace) } + let_it_be(:wiki_page) do + create(:wiki_page, wiki: project.wiki, title: 'directory/title', content: 'Some Wiki content') + end - let(:project) { create(:project, :repository, :wiki_repo, namespace: user.namespace) } - let!(:wiki_page) { create(:wiki_page, wiki: project.wiki, title: 'directory/title', content: 'Some Wiki content') } - - where(search_page_vertical_nav_enabled: [true, false]) - with_them do - before do - stub_feature_flags(search_page_vertical_nav: search_page_vertical_nav_enabled) - project.add_maintainer(user) - sign_in(user) + before do + project.add_maintainer(user) + sign_in(user) - visit(search_path) - end + visit(search_path) + end - include_examples 'top right search form' - include_examples 'search timeouts', 'wiki_blobs' do - let(:additional_params) { { project_id: project.id } } - end + include_examples 'top right search form' + include_examples 'search timeouts', 'wiki_blobs' do + let(:additional_params) { { project_id: project.id } } + end - shared_examples 'search wiki blobs' do - it 'finds a page' do - find('[data-testid="project-filter"]').click + shared_examples 'search wiki blobs' do + it 'finds a page' do + find('[data-testid="project-filter"]').click - wait_for_requests + wait_for_requests - page.within('[data-testid="project-filter"]') do - click_on(project.name) - end + page.within('[data-testid="project-filter"]') do + click_on(project.name) + end - fill_in('dashboard_search', with: search_term) - find('.gl-search-box-by-click-search-button').click - select_search_scope('Wiki') + fill_in('dashboard_search', with: search_term) + find('.gl-search-box-by-click-search-button').click + select_search_scope('Wiki') - page.within('.results') do - expect(page).to have_link(wiki_page.title, href: project_wiki_path(project, wiki_page.slug)) - end + page.within('.results') do + expect(page).to have_link(wiki_page.title, href: project_wiki_path(project, wiki_page.slug)) end end + end - context 'when searching by content' do - it_behaves_like 'search wiki blobs' do - let(:search_term) { 'content' } - end + context 'when searching by content' do + it_behaves_like 'search wiki blobs' do + let(:search_term) { 'content' } end + end - context 'when searching by title' do - it_behaves_like 'search wiki blobs' do - let(:search_term) { 'title' } - end + context 'when searching by title' do + it_behaves_like 'search wiki blobs' do + let(:search_term) { 'title' } end end end |