issuable_templates_spec.rb 5.45 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
require 'spec_helper'

feature 'issuable templates', feature: true, js: true do
  include WaitForAjax

  let(:user) { create(:user) }
  let(:project) { create(:project, :public) }

  before do
    project.team << [user, :master]
    login_as user
  end

  context 'user creates an issue using templates' do
    let(:template_content) { 'this is a test "bug" template' }
16
    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) }
17
    let(:issue) { create(:issue, author: user, assignee: user, project: project) }
18
    let(:description_addition) { ' appending to description' }
19 20 21

    background do
      project.repository.commit_file(user, '.gitlab/issue_templates/bug.md', template_content, 'added issue template', 'master', false)
22
      project.repository.commit_file(user, '.gitlab/issue_templates/test.md', longtemplate_content, 'added issue template', 'master', false)
23 24 25 26 27 28 29
      visit edit_namespace_project_issue_path project.namespace, project, issue
      fill_in :'issue[title]', with: 'test issue title'
    end

    scenario 'user selects "bug" template' do
      select_template 'bug'
      wait_for_ajax
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
      preview_template
      save_changes
    end

    scenario 'user selects "bug" template and then "no template"' do
      select_template 'bug'
      wait_for_ajax
      select_option 'No template'
      wait_for_ajax
      preview_template('')
      save_changes('')
    end

    scenario 'user selects "bug" template, edits description and then selects "reset template"' do
      select_template 'bug'
      wait_for_ajax
      find_field('issue_description').send_keys(description_addition)
      preview_template(template_content + description_addition)
      select_option 'Reset template'
      preview_template
50 51
      save_changes
    end
52 53 54 55 56 57 58 59

    it 'updates height of markdown textarea' do
      start_height = page.evaluate_script('$(".markdown-area").outerHeight()')

      select_template 'test'
      wait_for_ajax

      end_height = page.evaluate_script('$(".markdown-area").outerHeight()')
60

61 62
      expect(end_height).not_to eq(start_height)
    end
63 64
  end

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
  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, assignee: user, project: project) }

    background do
      project.repository.commit_file(user, '.gitlab/issue_templates/bug.md', template_content, 'added issue template', 'master', false)
      visit edit_namespace_project_issue_path project.namespace, project, issue
      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'
      wait_for_ajax
Luke Bennett's avatar
Luke Bennett committed
80
      preview_template("#{template_content}")
81 82 83 84
      save_changes
    end
  end

85 86 87 88 89 90 91 92 93 94 95 96 97
  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
      project.repository.commit_file(user, '.gitlab/merge_request_templates/feature-proposal.md', template_content, 'added merge request template', 'master', false)
      visit edit_namespace_project_merge_request_path project.namespace, project, merge_request
      fill_in :'merge_request[title]', with: 'test merge request title'
    end

    scenario 'user selects "feature-proposal" template' do
      select_template 'feature-proposal'
      wait_for_ajax
98
      preview_template
99 100 101 102 103 104 105 106
      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) }
    let(:fork_project) { create(:project, :public) }
107
    let(:merge_request) { create(:merge_request, :with_diffs, source_project: fork_project, target_project: project) }
108 109 110 111 112 113 114

    background do
      logout
      project.team << [fork_user, :developer]
      fork_project.team << [fork_user, :master]
      create(:forked_project_link, forked_to_project: fork_project, forked_from_project: project)
      login_as fork_user
115 116
      project.repository.commit_file(fork_user, '.gitlab/merge_request_templates/feature-proposal.md', template_content, 'added merge request template', 'master', false)
      visit edit_namespace_project_merge_request_path project.namespace, project, merge_request
117 118 119
      fill_in :'merge_request[title]', with: 'test merge request title'
    end

120 121 122 123 124
    context 'feature proposal template' do
      context 'template exists in target project' do
        scenario 'user selects template' do
          select_template 'feature-proposal'
          wait_for_ajax
125
          preview_template
126 127 128
          save_changes
        end
      end
129 130 131
    end
  end

132
  def preview_template(expected_content = template_content)
133
    click_link 'Preview'
134
    expect(page).to have_content expected_content
135
    click_link 'Write'
136 137
  end

138
  def save_changes(expected_content = template_content)
139
    click_button "Save changes"
140
    expect(page).to have_content expected_content
141 142 143 144 145 146
  end

  def select_template(name)
    first('.js-issuable-selector').click
    first('.js-issuable-selector-wrap .dropdown-content a', text: name).click
  end
147 148 149 150 151

  def select_option(name)
    first('.js-issuable-selector').click
    first('.js-issuable-selector-wrap .dropdown-footer-list a', text: name).click
  end
152
end