1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.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
project.add_maintainer(user)
sign_in(user)
end
it 'finds a file' do
visit(project_path(project))
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']")
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
click_link(project.full_name)
end
end
include_examples 'top right search form'
it 'finds code' do
fill_in('dashboard_search', with: 'rspec')
find('.btn-search').click
expect(page).to have_selector('.results', text: 'Update capybara, rspec-rails, poltergeist to recent versions')
find("#L3").click
expect(current_url).to match(/master\/.gitignore#L3/)
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)
expect(find("#L1502")[:href]).to match(/v1.0.0\/files\/markdown\/ruby-style-guide.md#L1502/)
end
end
context 'search code within refs', :js do
let(:ref_name) { 'v1.0.0' }
before do
visit(project_tree_path(project, ref_name))
submit_search('gitlab-grack')
select_search_scope('Code')
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
expect(find('.results')).not_to have_content('path = gitlab-grack')
find('.js-project-refs-dropdown').click
find('.dropdown-page-one .dropdown-content').click_link('master')
expect(page).to have_selector('.results', text: 'path = gitlab-grack')
end
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
end
it 'no ref switcher shown in issue result summary', :js do
issue = create(:issue, title: 'test', project: project)
visit(project_tree_path(project))
submit_search('test')
select_search_scope('Code')
expect(page).to have_selector('.js-project-refs-dropdown')
select_search_scope('Issues')
expect(find(:css, '.results')).to have_link(issue.title)
expect(page).not_to have_selector('.js-project-refs-dropdown')
end
end
context 'when signed out' do
let(:project) { create(:project, :public, :repository) }
before do
visit(project_path(project))
end
it 'finds code' do
submit_search('rspec')
select_search_scope('Code')
expect(page).to have_selector('.results', text: 'Update capybara, rspec-rails, poltergeist to recent versions')
end
end
end
|