2016-06-24 15:43:46 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-06-29 00:13:10 -04:00
|
|
|
feature 'issuable templates', js: true do
|
2016-06-24 15:43:46 -04:00
|
|
|
let(:user) { create(:user) }
|
2017-07-24 18:51:14 -04:00
|
|
|
let(:project) { create(:project, :public, :repository) }
|
2016-06-24 15:43:46 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
project.team << [user, :master]
|
2017-06-21 19:44:10 -04:00
|
|
|
sign_in user
|
2016-06-24 15:43:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'user creates an issue using templates' do
|
|
|
|
let(:template_content) { 'this is a test "bug" template' }
|
2016-09-09 10:11:37 -04:00
|
|
|
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) }
|
2017-05-04 08:11:15 -04:00
|
|
|
let(:issue) { create(:issue, author: user, assignees: [user], project: project) }
|
2016-10-09 22:19:55 -04:00
|
|
|
let(:description_addition) { ' appending to description' }
|
2016-06-24 15:43:46 -04:00
|
|
|
|
|
|
|
background do
|
2017-02-15 18:28:29 -05:00
|
|
|
project.repository.create_file(
|
2016-12-08 06:11:52 -05:00
|
|
|
user,
|
|
|
|
'.gitlab/issue_templates/bug.md',
|
|
|
|
template_content,
|
|
|
|
message: 'added issue template',
|
2017-02-15 18:28:29 -05:00
|
|
|
branch_name: 'master')
|
|
|
|
project.repository.create_file(
|
2016-12-08 06:11:52 -05:00
|
|
|
user,
|
|
|
|
'.gitlab/issue_templates/test.md',
|
|
|
|
longtemplate_content,
|
|
|
|
message: 'added issue template',
|
2017-02-15 18:28:29 -05:00
|
|
|
branch_name: 'master')
|
2017-06-29 13:06:35 -04:00
|
|
|
visit edit_project_issue_path project, issue
|
2016-06-24 15:43:46 -04:00
|
|
|
fill_in :'issue[title]', with: 'test issue title'
|
|
|
|
end
|
|
|
|
|
|
|
|
scenario 'user selects "bug" template' do
|
|
|
|
select_template 'bug'
|
2017-05-17 14:25:13 -04:00
|
|
|
wait_for_requests
|
2017-01-04 13:35:40 -05:00
|
|
|
assert_template
|
2016-10-09 22:19:55 -04:00
|
|
|
save_changes
|
|
|
|
end
|
|
|
|
|
|
|
|
scenario 'user selects "bug" template and then "no template"' do
|
|
|
|
select_template 'bug'
|
2017-05-17 14:25:13 -04:00
|
|
|
wait_for_requests
|
2016-10-09 22:19:55 -04:00
|
|
|
select_option 'No template'
|
2017-01-04 13:35:40 -05:00
|
|
|
assert_template('')
|
2016-10-09 22:19:55 -04:00
|
|
|
save_changes('')
|
|
|
|
end
|
|
|
|
|
|
|
|
scenario 'user selects "bug" template, edits description and then selects "reset template"' do
|
|
|
|
select_template 'bug'
|
2017-05-17 14:25:13 -04:00
|
|
|
wait_for_requests
|
2016-10-09 22:19:55 -04:00
|
|
|
find_field('issue_description').send_keys(description_addition)
|
2017-01-04 13:35:40 -05:00
|
|
|
assert_template(template_content + description_addition)
|
2016-10-09 22:19:55 -04:00
|
|
|
select_option 'Reset template'
|
2017-01-04 13:35:40 -05:00
|
|
|
assert_template
|
2016-06-24 15:43:46 -04:00
|
|
|
save_changes
|
|
|
|
end
|
2016-09-09 10:11:37 -04:00
|
|
|
|
|
|
|
it 'updates height of markdown textarea' do
|
|
|
|
start_height = page.evaluate_script('$(".markdown-area").outerHeight()')
|
|
|
|
|
|
|
|
select_template 'test'
|
2017-05-17 14:25:13 -04:00
|
|
|
wait_for_requests
|
2016-09-09 10:11:37 -04:00
|
|
|
|
|
|
|
end_height = page.evaluate_script('$(".markdown-area").outerHeight()')
|
2016-10-09 22:19:55 -04:00
|
|
|
|
2016-09-09 10:11:37 -04:00
|
|
|
expect(end_height).not_to eq(start_height)
|
|
|
|
end
|
2016-06-24 15:43:46 -04:00
|
|
|
end
|
|
|
|
|
2016-09-01 07:58:09 -04:00
|
|
|
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' }
|
2017-05-04 08:11:15 -04:00
|
|
|
let(:issue) { create(:issue, author: user, assignees: [user], project: project) }
|
2016-09-01 07:58:09 -04:00
|
|
|
|
|
|
|
background do
|
2017-02-15 18:28:29 -05:00
|
|
|
project.repository.create_file(
|
2016-12-08 06:11:52 -05:00
|
|
|
user,
|
|
|
|
'.gitlab/issue_templates/bug.md',
|
|
|
|
template_content,
|
|
|
|
message: 'added issue template',
|
2017-02-15 18:28:29 -05:00
|
|
|
branch_name: 'master')
|
2017-06-29 13:06:35 -04:00
|
|
|
visit edit_project_issue_path project, issue
|
2016-09-01 07:58:09 -04:00
|
|
|
fill_in :'issue[title]', with: 'test issue title'
|
|
|
|
fill_in :'issue[description]', with: prior_description
|
|
|
|
end
|
|
|
|
|
|
|
|
scenario 'user selects "bug" template' do
|
|
|
|
select_template 'bug'
|
2017-05-17 14:25:13 -04:00
|
|
|
wait_for_requests
|
2017-01-04 13:35:40 -05:00
|
|
|
assert_template("#{template_content}")
|
2016-09-01 07:58:09 -04:00
|
|
|
save_changes
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-24 15:43:46 -04:00
|
|
|
context 'user creates a merge request using templates' do
|
|
|
|
let(:template_content) { 'this is a test "feature-proposal" template' }
|
|
|
|
let(:merge_request) { create(:merge_request, :with_diffs, source_project: project) }
|
|
|
|
|
|
|
|
background do
|
2017-02-15 18:28:29 -05:00
|
|
|
project.repository.create_file(
|
2016-12-08 06:11:52 -05:00
|
|
|
user,
|
|
|
|
'.gitlab/merge_request_templates/feature-proposal.md',
|
|
|
|
template_content,
|
|
|
|
message: 'added merge request template',
|
2017-02-15 18:28:29 -05:00
|
|
|
branch_name: 'master')
|
2017-06-29 13:06:35 -04:00
|
|
|
visit edit_project_merge_request_path project, merge_request
|
2016-06-24 15:43:46 -04:00
|
|
|
fill_in :'merge_request[title]', with: 'test merge request title'
|
|
|
|
end
|
|
|
|
|
|
|
|
scenario 'user selects "feature-proposal" template' do
|
|
|
|
select_template 'feature-proposal'
|
2017-05-17 14:25:13 -04:00
|
|
|
wait_for_requests
|
2017-01-04 13:35:40 -05:00
|
|
|
assert_template
|
2016-06-24 15:43:46 -04:00
|
|
|
save_changes
|
|
|
|
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) }
|
2017-07-24 18:51:14 -04:00
|
|
|
let(:fork_project) { create(:project, :public, :repository) }
|
2016-09-13 14:36:13 -04:00
|
|
|
let(:merge_request) { create(:merge_request, :with_diffs, source_project: fork_project, target_project: project) }
|
2016-06-24 15:43:46 -04:00
|
|
|
|
|
|
|
background do
|
2017-06-21 19:44:10 -04:00
|
|
|
sign_out(:user)
|
|
|
|
|
2016-06-24 15:43:46 -04:00
|
|
|
project.team << [fork_user, :developer]
|
|
|
|
fork_project.team << [fork_user, :master]
|
|
|
|
create(:forked_project_link, forked_to_project: fork_project, forked_from_project: project)
|
2017-06-21 19:44:10 -04:00
|
|
|
|
|
|
|
sign_in(fork_user)
|
|
|
|
|
2017-02-15 18:28:29 -05:00
|
|
|
project.repository.create_file(
|
2016-12-08 06:11:52 -05:00
|
|
|
fork_user,
|
|
|
|
'.gitlab/merge_request_templates/feature-proposal.md',
|
|
|
|
template_content,
|
|
|
|
message: 'added merge request template',
|
2017-02-15 18:28:29 -05:00
|
|
|
branch_name: 'master')
|
2017-06-29 13:06:35 -04:00
|
|
|
visit edit_project_merge_request_path project, merge_request
|
2016-06-24 15:43:46 -04:00
|
|
|
fill_in :'merge_request[title]', with: 'test merge request title'
|
|
|
|
end
|
|
|
|
|
2016-09-13 14:36:13 -04:00
|
|
|
context 'feature proposal template' do
|
|
|
|
context 'template exists in target project' do
|
|
|
|
scenario 'user selects template' do
|
|
|
|
select_template 'feature-proposal'
|
2017-05-17 14:25:13 -04:00
|
|
|
wait_for_requests
|
2017-01-04 13:35:40 -05:00
|
|
|
assert_template
|
2016-09-13 14:36:13 -04:00
|
|
|
save_changes
|
|
|
|
end
|
|
|
|
end
|
2016-06-24 15:43:46 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-01-04 13:35:40 -05:00
|
|
|
def assert_template(expected_content = template_content)
|
|
|
|
expect(find('textarea')['value']).to eq(expected_content)
|
2016-06-24 15:43:46 -04:00
|
|
|
end
|
|
|
|
|
2016-10-09 22:19:55 -04:00
|
|
|
def save_changes(expected_content = template_content)
|
2016-06-24 15:43:46 -04:00
|
|
|
click_button "Save changes"
|
2016-10-09 22:19:55 -04:00
|
|
|
expect(page).to have_content expected_content
|
2016-06-24 15:43:46 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def select_template(name)
|
2017-04-21 11:05:38 -04:00
|
|
|
find('.js-issuable-selector').click
|
|
|
|
|
|
|
|
find('.js-issuable-selector-wrap .dropdown-content a', text: name, match: :first).click
|
2016-06-24 15:43:46 -04:00
|
|
|
end
|
2016-10-09 22:19:55 -04:00
|
|
|
|
|
|
|
def select_option(name)
|
2017-04-21 11:05:38 -04:00
|
|
|
find('.js-issuable-selector').click
|
|
|
|
|
|
|
|
find('.js-issuable-selector-wrap .dropdown-footer-list a', text: name, match: :first).click
|
2016-10-09 22:19:55 -04:00
|
|
|
end
|
2016-06-24 15:43:46 -04:00
|
|
|
end
|