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
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'issuable templates', :js, feature_category: :projects do
include ProjectForksHelper
include CookieHelper
let(:user) { create(:user) }
let(:project) { create(:project, :public, :repository) }
let(:issue_form_location) { '#content-body .issuable-details .detail-page-description' }
before do
project.add_maintainer(user)
sign_in user
set_cookie('new-actions-popover-viewed', 'true')
end
context 'user creates an issue using templates' do
let(:template_content) { 'this is a test "bug" template' }
let(:longtemplate_content) { %Q(this\n\n\n\n\nis\n\n\n\n\na\n\n\n\n\nbug\n\n\n\n\ntemplate) }
let(:issue) { create(:issue, author: user, assignees: [user], project: project) }
let(:description_addition) { ' appending to description' }
before do
project.repository.create_file(
user,
'.gitlab/issue_templates/bug.md',
template_content,
message: 'added issue template',
branch_name: 'master')
project.repository.create_file(
user,
'.gitlab/issue_templates/test.md',
longtemplate_content,
message: 'added issue template',
branch_name: 'master')
visit project_issue_path project, issue
page.find('.js-issuable-edit').click
fill_in :'issuable-title', with: 'test issue title'
end
it 'user selects "bug" template' do
select_template 'bug'
wait_for_requests
assert_template(page_part: issue_form_location)
save_changes
end
it 'user selects "bug" template and then "no template"' do
select_template 'bug'
wait_for_requests
select_option 'No template'
assert_template(expected_content: '', page_part: issue_form_location)
save_changes('')
end
it 'user selects "bug" template, edits description and then selects "reset template"' do
select_template 'bug'
wait_for_requests
find_field('issue-description').send_keys(description_addition)
assert_template(expected_content: template_content + description_addition, page_part: issue_form_location)
select_option 'Reset template'
assert_template(page_part: issue_form_location)
save_changes
end
end
context 'user creates an issue using templates, with a prior description' do
let(:prior_description) { 'test issue description' }
let(:template_content) { 'this is a test "bug" template' }
let(:issue) { create(:issue, author: user, assignees: [user], project: project) }
before do
project.repository.create_file(
user,
'.gitlab/issue_templates/bug.md',
template_content,
message: 'added issue template',
branch_name: 'master')
visit project_issue_path project, issue
page.find('.js-issuable-edit').click
fill_in :'issuable-title', with: 'test issue title'
fill_in :'issue-description', with: prior_description
end
it 'user selects "bug" template' do
select_template 'bug'
wait_for_requests
assert_template(page_part: issue_form_location)
save_changes
end
end
context 'user creates an issue with a default template from the repo' do
let(:template_content) { 'this is the default template' }
before do
project.repository.create_file(
user,
'.gitlab/issue_templates/default.md',
template_content,
message: 'added default issue template',
branch_name: 'master'
)
end
it 'does not overwrite autosaved description' do
visit new_project_issue_path project
wait_for_requests
assert_template # default template is loaded the first time
fill_in 'issue_description', with: 'my own description', fill_options: { clear: :backspace }
visit new_project_issue_path project
wait_for_requests
assert_template(expected_content: 'my own description')
end
end
context 'user creates a merge request using templates' do
let(:template_content) { 'this is a test "feature-proposal" template' }
let(:bug_template_content) { 'this is merge request bug template' }
let(:template_override_warning) { 'Applying a template will replace the existing issue description.' }
let(:updated_description) { 'updated merge request description' }
let(:merge_request) { create(:merge_request, source_project: project) }
before do
project.repository.create_file(
user,
'.gitlab/merge_request_templates/feature-proposal.md',
template_content,
message: 'added merge request template',
branch_name: 'master')
project.repository.create_file(
user,
'.gitlab/merge_request_templates/bug.md',
bug_template_content,
message: 'added merge request bug template',
branch_name: 'master')
visit edit_project_merge_request_path project, merge_request
fill_in :'merge_request[title]', with: 'test merge request title'
end
it 'user selects "feature-proposal" template' do
select_template 'feature-proposal'
wait_for_requests
assert_template
save_changes
end
context 'changes template' do
before do
select_template 'bug'
wait_for_requests
fill_in :'merge_request[description]', with: updated_description
select_template 'feature-proposal'
expect(page).to have_content template_override_warning
end
it 'user selects "bug" template, then updates description, then selects "feature-proposal" template, then cancels template change' do
page.find('.js-template-warning .js-close-btn.js-cancel-btn').click
expect(find('textarea')['value']).to eq(updated_description)
expect(page).not_to have_content template_override_warning
end
it 'user selects "bug" template, then updates description, then selects "feature-proposal" template, then dismiss the template warning' do
page.find('.js-template-warning .js-close-btn.js-dismiss-btn').click
expect(find('textarea')['value']).to eq(updated_description)
expect(page).not_to have_content template_override_warning
end
it 'user selects "bug" template, then updates description, then selects "feature-proposal" template, then applies template change' do
page.find('.js-template-warning .js-override-template').click
wait_for_requests
assert_template
end
end
end
context 'user creates a merge request from a forked project using templates' do
let(:template_content) { 'this is a test "feature-proposal" template' }
let(:fork_user) { create(:user) }
let(:forked_project) { fork_project(project, fork_user, repository: true) }
let(:merge_request) { create(:merge_request, source_project: forked_project, target_project: project) }
before do
sign_out(:user)
project.add_developer(fork_user)
sign_in(fork_user)
project.repository.create_file(
fork_user,
'.gitlab/merge_request_templates/feature-proposal.md',
template_content,
message: 'added merge request template',
branch_name: 'master')
visit edit_project_merge_request_path project, merge_request
fill_in :'merge_request[title]', with: 'test merge request title'
end
context 'feature proposal template' do
context 'template exists in target project' do
it 'user selects template' do
select_template 'feature-proposal'
wait_for_requests
assert_template
save_changes
end
end
end
end
def assert_template(expected_content: template_content, page_part: '#content-body')
page.within(page_part) do
expect(find('textarea')['value']).to eq(expected_content)
end
end
def save_changes(expected_content = template_content)
click_button "Save changes"
expect(page).to have_content expected_content
end
def select_template(name)
find('.js-issuable-selector').click
find('.js-issuable-selector-wrap .dropdown-content a', text: name, match: :first).click
end
def select_option(name)
find('.js-issuable-selector').click
find('.js-issuable-selector-wrap .dropdown-footer-list a', text: name, match: :first).click
end
end
|