2019-10-12 21:52:04 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe 'User searches for code' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:project) { create(:project, :repository, namespace: user.namespace) }
|
|
|
|
|
|
|
|
context 'when signed in' do
|
|
|
|
before do
|
2018-11-18 11:00:15 +05:30
|
|
|
project.add_maintainer(user)
|
2018-03-17 18:26:18 +05:30
|
|
|
sign_in(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'finds a file' do
|
|
|
|
visit(project_path(project))
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
submit_search('application.js')
|
2019-12-04 20:38:33 +05:30
|
|
|
select_search_scope('Code')
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(page).to have_selector('.results', text: 'application.js')
|
2018-03-17 18:26:18 +05:30
|
|
|
expect(page).to have_selector('.file-content .code')
|
|
|
|
expect(page).to have_selector("span.line[lang='javascript']")
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when on a project page', :js do
|
|
|
|
before do
|
|
|
|
visit(search_path)
|
|
|
|
find('.js-search-project-dropdown').click
|
|
|
|
|
|
|
|
page.within('.project-filter') do
|
2018-03-27 19:54:05 +05:30
|
|
|
click_link(project.full_name)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
2019-12-04 20:38:33 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
include_examples 'top right search form'
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
it 'finds code' do
|
2018-03-17 18:26:18 +05:30
|
|
|
fill_in('dashboard_search', with: 'rspec')
|
|
|
|
find('.btn-search').click
|
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(page).to have_selector('.results', text: 'Update capybara, rspec-rails, poltergeist to recent versions')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'search mutiple words with refs switching' do
|
|
|
|
expected_result = 'Use `snake_case` for naming files'
|
|
|
|
search = 'for naming files'
|
|
|
|
|
|
|
|
fill_in('dashboard_search', with: search)
|
|
|
|
find('.btn-search').click
|
|
|
|
|
|
|
|
expect(page).to have_selector('.results', text: expected_result)
|
|
|
|
|
|
|
|
find('.js-project-refs-dropdown').click
|
|
|
|
find('.dropdown-page-one .dropdown-content').click_link('v1.0.0')
|
|
|
|
|
|
|
|
expect(page).to have_selector('.results', text: expected_result)
|
|
|
|
|
|
|
|
expect(find_field('dashboard_search').value).to eq(search)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
2019-10-12 21:52:04 +05:30
|
|
|
|
|
|
|
context 'search code within refs', :js do
|
|
|
|
let(:ref_name) { 'v1.0.0' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
visit(project_tree_path(project, ref_name))
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
submit_search('gitlab-grack')
|
|
|
|
select_search_scope('Code')
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'shows ref switcher in code result summary' do
|
|
|
|
expect(find('.js-project-refs-dropdown')).to have_text(ref_name)
|
|
|
|
end
|
|
|
|
it 'persists branch name across search' do
|
|
|
|
find('.btn-search').click
|
|
|
|
expect(find('.js-project-refs-dropdown')).to have_text(ref_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
# this example is use to test the desgine that the refs is not
|
|
|
|
# only repersent the branch as well as the tags.
|
|
|
|
it 'ref swither list all the branchs and tags' do
|
|
|
|
find('.js-project-refs-dropdown').click
|
|
|
|
expect(find('.dropdown-page-one .dropdown-content')).to have_link('sha-starting-with-large-number')
|
|
|
|
expect(find('.dropdown-page-one .dropdown-content')).to have_link('v1.0.0')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'search result changes when refs switched' do
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(find('.results')).not_to have_content('path = gitlab-grack')
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
find('.js-project-refs-dropdown').click
|
|
|
|
find('.dropdown-page-one .dropdown-content').click_link('master')
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
expect(page).to have_selector('.results', text: 'path = gitlab-grack')
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
2019-12-21 20:55:43 +05:30
|
|
|
|
|
|
|
it 'persist refs over browser tabs' do
|
|
|
|
ref = 'feature'
|
|
|
|
find('.js-project-refs-dropdown').click
|
|
|
|
link = find_link(ref)[:href]
|
|
|
|
expect(link.include?("repository_ref=" + ref)).to be(true)
|
|
|
|
end
|
2019-10-12 21:52:04 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it 'no ref switcher shown in issue result summary', :js do
|
|
|
|
issue = create(:issue, title: 'test', project: project)
|
|
|
|
visit(project_tree_path(project))
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
submit_search('test')
|
|
|
|
select_search_scope('Code')
|
|
|
|
|
2019-10-12 21:52:04 +05:30
|
|
|
expect(page).to have_selector('.js-project-refs-dropdown')
|
2019-12-04 20:38:33 +05:30
|
|
|
|
|
|
|
select_search_scope('Issues')
|
|
|
|
|
|
|
|
expect(find(:css, '.results')).to have_link(issue.title)
|
2019-10-12 21:52:04 +05:30
|
|
|
expect(page).not_to have_selector('.js-project-refs-dropdown')
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when signed out' do
|
|
|
|
let(:project) { create(:project, :public, :repository) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
visit(project_path(project))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'finds code' do
|
2019-10-12 21:52:04 +05:30
|
|
|
submit_search('rspec')
|
2019-12-04 20:38:33 +05:30
|
|
|
select_search_scope('Code')
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2019-12-04 20:38:33 +05:30
|
|
|
expect(page).to have_selector('.results', text: 'Update capybara, rspec-rails, poltergeist to recent versions')
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|