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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Projects > Show > User sees setup shortcut buttons' do
# For "New file", "Add license" functionality,
# see spec/features/projects/files/project_owner_creates_license_file_spec.rb
# see spec/features/projects/files/project_owner_sees_link_to_create_license_file_in_empty_project_spec.rb
include FakeBlobHelpers
let(:user) { create(:user) }
describe 'empty project' do
let(:project) { create(:project, :public, :empty_repo) }
let(:presenter) { project.present(current_user: user) }
describe 'as a normal user' do
before do
sign_in(user)
visit project_path(project)
end
it 'Project buttons are not visible' do
visit project_path(project)
page.within('.project-buttons') do
expect(page).not_to have_link('New file')
expect(page).not_to have_link('Add README')
expect(page).not_to have_link('Add CHANGELOG')
expect(page).not_to have_link('Add CONTRIBUTING')
expect(page).not_to have_link('Enable Auto DevOps')
expect(page).not_to have_link('Auto DevOps enabled')
expect(page).not_to have_link('Add Kubernetes cluster')
expect(page).not_to have_link('Kubernetes')
end
end
end
describe 'as a maintainer' do
before do
project.add_maintainer(user)
sign_in(user)
visit project_path(project)
end
it '"New file" button linked to IDE new file page' do
page.within('.project-buttons') do
expect(page).to have_link('New file', href: presenter.ide_edit_path(project, project.default_branch || 'master'))
end
end
it '"Add README" button linked to IDE new file populated for a README' do
page.within('.project-buttons') do
expect(page).to have_link('Add README', href: presenter.add_readme_ide_path)
end
end
it '"Add license" button linked to IDE new file populated for a license' do
page.within('.project-buttons') do
expect(page).to have_link('Add LICENSE', href: presenter.add_license_ide_path)
end
end
context 'Gitlab::CurrentSettings.default_branch_name is available' do
before do
expect(Gitlab::CurrentSettings)
.to receive(:default_branch_name)
.at_least(:once)
.and_return('example_branch')
visit project_path(project)
end
it '"New file" button linked to IDE new file page' do
page.within('.project-buttons') do
expect(page).to have_link('New file', href: presenter.ide_edit_path(project, 'example_branch'))
end
end
end
end
end
describe 'populated project' do
let(:project) { create(:project, :public, :repository) }
let(:presenter) { project.present(current_user: user) }
describe 'as a normal user' do
before do
sign_in(user)
visit project_path(project)
end
context 'when Auto DevOps is enabled' do
it '"Auto DevOps enabled" button not linked' do
visit project_path(project)
page.within('.project-buttons') do
expect(page).to have_text('Auto DevOps enabled')
end
end
end
context 'when Auto DevOps is not enabled' do
let(:project) { create(:project, :public, :repository, auto_devops_attributes: { enabled: false }) }
it 'no Auto DevOps button if can not manage pipelines' do
page.within('.project-buttons') do
expect(page).not_to have_link('Enable Auto DevOps')
expect(page).not_to have_link('Auto DevOps enabled')
end
end
it 'no Kubernetes cluster button if can not manage clusters' do
page.within('.project-buttons') do
expect(page).not_to have_link('Add Kubernetes cluster')
expect(page).not_to have_link('Kubernetes')
end
end
end
end
describe 'as a maintainer' do
before do
allow_any_instance_of(AutoDevopsHelper).to receive(:show_auto_devops_callout?).and_return(false)
project.add_maintainer(user)
sign_in(user)
end
context 'README button' do
before do
allow(Project).to receive(:find_by_full_path)
.with(project.full_path, follow_redirects: true)
.and_return(project)
end
context 'when the project has a populated README' do
it 'show the "README" anchor' do
visit project_path(project)
expect(project.repository.readme).not_to be_nil
page.within('.project-buttons') do
expect(page).not_to have_link('Add README', href: presenter.add_readme_ide_path)
expect(page).to have_link('README', href: presenter.readme_path)
end
end
context 'when the project has an empty README' do
it 'show the "README" anchor' do
allow(project.repository).to receive(:readme).and_return(fake_blob(path: 'README.md', data: '', size: 0))
visit project_path(project)
page.within('.project-buttons') do
expect(page).not_to have_link('Add README', href: presenter.add_readme_path)
expect(page).to have_link('README', href: presenter.readme_path)
end
end
end
end
context 'when the project does not have a README' do
it 'shows the single file editor "Add README" button' do
allow(project.repository).to receive(:readme_path).and_return(nil)
visit project_path(project)
page.within('.project-buttons') do
expect(page).to have_link('Add README', href: presenter.add_readme_path)
end
end
end
end
it 'no "Add CHANGELOG" button if the project already has a changelog' do
visit project_path(project)
expect(project.repository.changelog).not_to be_nil
page.within('.project-buttons') do
expect(page).not_to have_link('Add CHANGELOG')
end
end
it 'no "Add license" button if the project already has a license' do
visit project_path(project)
expect(project.repository.license_blob).not_to be_nil
page.within('.project-buttons') do
expect(page).not_to have_link('Add LICENSE')
end
end
it 'no "Add CONTRIBUTING" button if the project already has a contribution guide' do
visit project_path(project)
expect(project.repository.contribution_guide).not_to be_nil
page.within('.project-buttons') do
expect(page).not_to have_link('Add CONTRIBUTING')
end
end
describe 'GitLab CI configuration button' do
context 'when Auto DevOps is enabled' do
it 'no "Set up CI/CD" button if the project has Auto DevOps enabled' do
visit project_path(project)
page.within('.project-buttons') do
expect(page).not_to have_link('Set up CI/CD')
end
end
end
context 'when Auto DevOps is not enabled' do
let(:project) { create(:project, :public, :repository, auto_devops_attributes: { enabled: false }) }
it '"Set up CI/CD" button linked to new file populated for a .gitlab-ci.yml' do
visit project_path(project)
expect(project.repository.gitlab_ci_yml).to be_nil
page.within('.project-buttons') do
expect(page).to have_link('Set up CI/CD', href: presenter.add_ci_yml_path)
end
end
it 'no "Set up CI/CD" button if the project already has a .gitlab-ci.yml' do
Files::CreateService.new(
project,
project.creator,
start_branch: 'master',
branch_name: 'master',
commit_message: "Add .gitlab-ci.yml",
file_path: '.gitlab-ci.yml',
file_content: File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
).execute
expect(project.repository.gitlab_ci_yml).not_to be_nil
visit project_path(project)
page.within('.project-buttons') do
expect(page).not_to have_link('Set up CI/CD')
end
end
end
end
describe 'Auto DevOps button' do
context 'when Auto DevOps is enabled' do
it '"Auto DevOps enabled" anchor linked to settings page' do
visit project_path(project)
page.within('.project-buttons') do
expect(page).to have_link('Auto DevOps enabled', href: project_settings_ci_cd_path(project, anchor: 'autodevops-settings'))
end
end
end
context 'when Auto DevOps is not enabled' do
let(:project) { create(:project, :public, :repository, auto_devops_attributes: { enabled: false }) }
it '"Enable Auto DevOps" button linked to settings page' do
visit project_path(project)
page.within('.project-buttons') do
expect(page).to have_link('Enable Auto DevOps', href: project_settings_ci_cd_path(project, anchor: 'autodevops-settings'))
end
end
it 'no Auto DevOps button if Auto DevOps callout is shown' do
allow_any_instance_of(AutoDevopsHelper).to receive(:show_auto_devops_callout?).and_return(true)
visit project_path(project)
expect(page).to have_selector('.js-autodevops-banner')
page.within('.project-buttons') do
expect(page).not_to have_link('Enable Auto DevOps')
expect(page).not_to have_link('Auto DevOps enabled')
end
end
it 'no "Enable Auto DevOps" button when .gitlab-ci.yml already exists' do
Files::CreateService.new(
project,
project.creator,
start_branch: 'master',
branch_name: 'master',
commit_message: "Add .gitlab-ci.yml",
file_path: '.gitlab-ci.yml',
file_content: File.read(Rails.root.join('spec/support/gitlab_stubs/gitlab_ci.yml'))
).execute
expect(project.repository.gitlab_ci_yml).not_to be_nil
visit project_path(project)
page.within('.project-buttons') do
expect(page).not_to have_link('Enable Auto DevOps')
expect(page).not_to have_link('Auto DevOps enabled')
end
end
end
end
describe 'Kubernetes cluster button' do
it '"Add Kubernetes cluster" button linked to clusters page' do
visit project_path(project)
page.within('.project-buttons') do
expect(page).to have_link('Add Kubernetes cluster', href: new_project_cluster_path(project))
end
end
it '"Kubernetes cluster" button linked to cluster page' do
cluster = create(:cluster, :provided_by_gcp, projects: [project])
visit project_path(project)
page.within('.project-buttons') do
expect(page).to have_link('Kubernetes', href: project_cluster_path(project, cluster))
end
end
end
end
end
end
|