2019-07-25 05:24:42 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-06-24 19:43:46 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-16 18:09:01 +00:00
|
|
|
RSpec.describe 'issuable templates', :js do
|
2017-09-29 08:04:50 +00:00
|
|
|
include ProjectForksHelper
|
|
|
|
|
2016-06-24 19:43:46 +00:00
|
|
|
let(:user) { create(:user) }
|
2017-07-24 22:51:14 +00:00
|
|
|
let(:project) { create(:project, :public, :repository) }
|
2017-09-19 08:30:18 +00:00
|
|
|
let(:issue_form_location) { '#content-body .issuable-details .detail-page-description' }
|
2016-06-24 19:43:46 +00:00
|
|
|
|
|
|
|
before do
|
2018-07-11 14:36:08 +00:00
|
|
|
project.add_maintainer(user)
|
2017-06-21 23:44:10 +00:00
|
|
|
sign_in user
|
2016-06-24 19:43:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'user creates an issue using templates' do
|
|
|
|
let(:template_content) { 'this is a test "bug" template' }
|
2016-09-09 14:11:37 +00: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 12:11:15 +00:00
|
|
|
let(:issue) { create(:issue, author: user, assignees: [user], project: project) }
|
2016-10-10 02:19:55 +00:00
|
|
|
let(:description_addition) { ' appending to description' }
|
2016-06-24 19:43:46 +00:00
|
|
|
|
2018-07-05 06:32:05 +00:00
|
|
|
before do
|
2017-02-15 23:28:29 +00:00
|
|
|
project.repository.create_file(
|
2016-12-08 11:11:52 +00:00
|
|
|
user,
|
|
|
|
'.gitlab/issue_templates/bug.md',
|
|
|
|
template_content,
|
|
|
|
message: 'added issue template',
|
2017-02-15 23:28:29 +00:00
|
|
|
branch_name: 'master')
|
|
|
|
project.repository.create_file(
|
2016-12-08 11:11:52 +00:00
|
|
|
user,
|
|
|
|
'.gitlab/issue_templates/test.md',
|
|
|
|
longtemplate_content,
|
|
|
|
message: 'added issue template',
|
2017-02-15 23:28:29 +00:00
|
|
|
branch_name: 'master')
|
2017-09-19 08:30:18 +00:00
|
|
|
visit project_issue_path project, issue
|
2017-12-19 17:48:29 +00:00
|
|
|
page.find('.js-issuable-edit').click
|
2017-10-20 19:26:51 +00:00
|
|
|
fill_in :'issuable-title', with: 'test issue title'
|
2016-06-24 19:43:46 +00:00
|
|
|
end
|
|
|
|
|
2018-07-05 06:32:05 +00:00
|
|
|
it 'user selects "bug" template' do
|
2016-06-24 19:43:46 +00:00
|
|
|
select_template 'bug'
|
2017-05-17 18:25:13 +00:00
|
|
|
wait_for_requests
|
2017-09-19 08:30:18 +00:00
|
|
|
assert_template(page_part: issue_form_location)
|
2016-10-10 02:19:55 +00:00
|
|
|
save_changes
|
|
|
|
end
|
|
|
|
|
2018-07-05 06:32:05 +00:00
|
|
|
it 'user selects "bug" template and then "no template"' do
|
2016-10-10 02:19:55 +00:00
|
|
|
select_template 'bug'
|
2017-05-17 18:25:13 +00:00
|
|
|
wait_for_requests
|
2016-10-10 02:19:55 +00:00
|
|
|
select_option 'No template'
|
2017-09-19 08:30:18 +00:00
|
|
|
assert_template(expected_content: '', page_part: issue_form_location)
|
2016-10-10 02:19:55 +00:00
|
|
|
save_changes('')
|
|
|
|
end
|
|
|
|
|
2018-07-05 06:32:05 +00:00
|
|
|
it 'user selects "bug" template, edits description and then selects "reset template"' do
|
2016-10-10 02:19:55 +00:00
|
|
|
select_template 'bug'
|
2017-05-17 18:25:13 +00:00
|
|
|
wait_for_requests
|
2017-09-19 08:30:18 +00:00
|
|
|
find_field('issue-description').send_keys(description_addition)
|
|
|
|
assert_template(expected_content: template_content + description_addition, page_part: issue_form_location)
|
2016-10-10 02:19:55 +00:00
|
|
|
select_option 'Reset template'
|
2017-09-19 08:30:18 +00:00
|
|
|
assert_template(page_part: issue_form_location)
|
2016-06-24 19:43:46 +00:00
|
|
|
save_changes
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-01 11:58:09 +00: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 12:11:15 +00:00
|
|
|
let(:issue) { create(:issue, author: user, assignees: [user], project: project) }
|
2016-09-01 11:58:09 +00:00
|
|
|
|
2018-07-05 06:32:05 +00:00
|
|
|
before do
|
2017-02-15 23:28:29 +00:00
|
|
|
project.repository.create_file(
|
2016-12-08 11:11:52 +00:00
|
|
|
user,
|
|
|
|
'.gitlab/issue_templates/bug.md',
|
|
|
|
template_content,
|
|
|
|
message: 'added issue template',
|
2017-02-15 23:28:29 +00:00
|
|
|
branch_name: 'master')
|
2017-09-19 08:30:18 +00:00
|
|
|
visit project_issue_path project, issue
|
2017-12-19 17:48:29 +00:00
|
|
|
page.find('.js-issuable-edit').click
|
2017-10-20 19:26:51 +00:00
|
|
|
fill_in :'issuable-title', with: 'test issue title'
|
2017-09-19 08:30:18 +00:00
|
|
|
fill_in :'issue-description', with: prior_description
|
2016-09-01 11:58:09 +00:00
|
|
|
end
|
|
|
|
|
2018-07-05 06:32:05 +00:00
|
|
|
it 'user selects "bug" template' do
|
2016-09-01 11:58:09 +00:00
|
|
|
select_template 'bug'
|
2017-05-17 18:25:13 +00:00
|
|
|
wait_for_requests
|
2017-09-19 08:30:18 +00:00
|
|
|
assert_template(page_part: issue_form_location)
|
2016-09-01 11:58:09 +00:00
|
|
|
save_changes
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-24 19:43:46 +00:00
|
|
|
context 'user creates a merge request using templates' do
|
|
|
|
let(:template_content) { 'this is a test "feature-proposal" template' }
|
2019-10-04 12:06:14 +00:00
|
|
|
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' }
|
2016-06-24 19:43:46 +00:00
|
|
|
let(:merge_request) { create(:merge_request, :with_diffs, source_project: project) }
|
|
|
|
|
2018-07-05 06:32:05 +00:00
|
|
|
before do
|
2017-02-15 23:28:29 +00:00
|
|
|
project.repository.create_file(
|
2016-12-08 11:11:52 +00:00
|
|
|
user,
|
|
|
|
'.gitlab/merge_request_templates/feature-proposal.md',
|
|
|
|
template_content,
|
|
|
|
message: 'added merge request template',
|
2017-02-15 23:28:29 +00:00
|
|
|
branch_name: 'master')
|
2019-10-04 12:06:14 +00:00
|
|
|
project.repository.create_file(
|
|
|
|
user,
|
|
|
|
'.gitlab/merge_request_templates/bug.md',
|
|
|
|
bug_template_content,
|
|
|
|
message: 'added merge request bug template',
|
|
|
|
branch_name: 'master')
|
2017-06-29 17:06:35 +00:00
|
|
|
visit edit_project_merge_request_path project, merge_request
|
2016-06-24 19:43:46 +00:00
|
|
|
fill_in :'merge_request[title]', with: 'test merge request title'
|
|
|
|
end
|
|
|
|
|
2018-07-05 06:32:05 +00:00
|
|
|
it 'user selects "feature-proposal" template' do
|
2016-06-24 19:43:46 +00:00
|
|
|
select_template 'feature-proposal'
|
2017-05-17 18:25:13 +00:00
|
|
|
wait_for_requests
|
2017-01-04 18:35:40 +00:00
|
|
|
assert_template
|
2016-06-24 19:43:46 +00:00
|
|
|
save_changes
|
|
|
|
end
|
2019-10-04 12:06:14 +00:00
|
|
|
|
|
|
|
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
|
2019-10-15 12:06:06 +00:00
|
|
|
page.find('.js-template-warning .js-close-btn.js-cancel-btn').click
|
2019-10-04 12:06:14 +00:00
|
|
|
expect(find('textarea')['value']).to eq(updated_description)
|
2019-10-15 12:06:06 +00:00
|
|
|
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
|
2019-10-04 12:06:14 +00:00
|
|
|
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
|
2016-06-24 19:43:46 +00:00
|
|
|
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-10-10 14:56:04 +00:00
|
|
|
let(:forked_project) { fork_project(project, fork_user, repository: true) }
|
2017-09-29 08:04:50 +00:00
|
|
|
let(:merge_request) { create(:merge_request, :with_diffs, source_project: forked_project, target_project: project) }
|
2016-06-24 19:43:46 +00:00
|
|
|
|
2018-07-05 06:32:05 +00:00
|
|
|
before do
|
2017-06-21 23:44:10 +00:00
|
|
|
sign_out(:user)
|
|
|
|
|
2017-12-22 08:18:28 +00:00
|
|
|
project.add_developer(fork_user)
|
2017-06-21 23:44:10 +00:00
|
|
|
|
|
|
|
sign_in(fork_user)
|
|
|
|
|
2017-02-15 23:28:29 +00:00
|
|
|
project.repository.create_file(
|
2016-12-08 11:11:52 +00:00
|
|
|
fork_user,
|
|
|
|
'.gitlab/merge_request_templates/feature-proposal.md',
|
|
|
|
template_content,
|
|
|
|
message: 'added merge request template',
|
2017-02-15 23:28:29 +00:00
|
|
|
branch_name: 'master')
|
2017-06-29 17:06:35 +00:00
|
|
|
visit edit_project_merge_request_path project, merge_request
|
2016-06-24 19:43:46 +00:00
|
|
|
fill_in :'merge_request[title]', with: 'test merge request title'
|
|
|
|
end
|
|
|
|
|
2016-09-13 18:36:13 +00:00
|
|
|
context 'feature proposal template' do
|
|
|
|
context 'template exists in target project' do
|
2018-07-05 06:32:05 +00:00
|
|
|
it 'user selects template' do
|
2016-09-13 18:36:13 +00:00
|
|
|
select_template 'feature-proposal'
|
2017-05-17 18:25:13 +00:00
|
|
|
wait_for_requests
|
2017-01-04 18:35:40 +00:00
|
|
|
assert_template
|
2016-09-13 18:36:13 +00:00
|
|
|
save_changes
|
|
|
|
end
|
|
|
|
end
|
2016-06-24 19:43:46 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-09-19 08:30:18 +00:00
|
|
|
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
|
2016-06-24 19:43:46 +00:00
|
|
|
end
|
|
|
|
|
2016-10-10 02:19:55 +00:00
|
|
|
def save_changes(expected_content = template_content)
|
2016-06-24 19:43:46 +00:00
|
|
|
click_button "Save changes"
|
2016-10-10 02:19:55 +00:00
|
|
|
expect(page).to have_content expected_content
|
2016-06-24 19:43:46 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def select_template(name)
|
2017-04-21 15:05:38 +00:00
|
|
|
find('.js-issuable-selector').click
|
|
|
|
|
|
|
|
find('.js-issuable-selector-wrap .dropdown-content a', text: name, match: :first).click
|
2016-06-24 19:43:46 +00:00
|
|
|
end
|
2016-10-10 02:19:55 +00:00
|
|
|
|
|
|
|
def select_option(name)
|
2017-04-21 15:05:38 +00:00
|
|
|
find('.js-issuable-selector').click
|
|
|
|
|
|
|
|
find('.js-issuable-selector-wrap .dropdown-footer-list a', text: name, match: :first).click
|
2016-10-10 02:19:55 +00:00
|
|
|
end
|
2016-06-24 19:43:46 +00:00
|
|
|
end
|