BigW Consortium Gitlab

issuable_templates_spec.rb 5.61 KB
Newer Older
1 2
require 'spec_helper'

3
feature 'issuable templates', js: true do
4
  let(:user) { create(:user) }
5
  let(:project) { create(:project, :public, :repository) }
6 7 8

  before do
    project.team << [user, :master]
9
    sign_in user
10 11 12 13
  end

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

    background do
19
      project.repository.create_file(
20 21 22 23
        user,
        '.gitlab/issue_templates/bug.md',
        template_content,
        message: 'added issue template',
24 25
        branch_name: 'master')
      project.repository.create_file(
26 27 28 29
        user,
        '.gitlab/issue_templates/test.md',
        longtemplate_content,
        message: 'added issue template',
30
        branch_name: 'master')
31
      visit edit_project_issue_path project, issue
32 33 34 35 36
      fill_in :'issue[title]', with: 'test issue title'
    end

    scenario 'user selects "bug" template' do
      select_template 'bug'
37
      wait_for_requests
38
      assert_template
39 40 41 42 43
      save_changes
    end

    scenario 'user selects "bug" template and then "no template"' do
      select_template 'bug'
44
      wait_for_requests
45
      select_option 'No template'
46
      assert_template('')
47 48 49 50 51
      save_changes('')
    end

    scenario 'user selects "bug" template, edits description and then selects "reset template"' do
      select_template 'bug'
52
      wait_for_requests
53
      find_field('issue_description').send_keys(description_addition)
54
      assert_template(template_content + description_addition)
55
      select_option 'Reset template'
56
      assert_template
57 58
      save_changes
    end
59 60 61 62 63

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

      select_template 'test'
64
      wait_for_requests
65 66

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

68 69
      expect(end_height).not_to eq(start_height)
    end
70 71
  end

72 73 74
  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' }
75
    let(:issue) { create(:issue, author: user, assignees: [user], project: project) }
76 77

    background do
78
      project.repository.create_file(
79 80 81 82
        user,
        '.gitlab/issue_templates/bug.md',
        template_content,
        message: 'added issue template',
83
        branch_name: 'master')
84
      visit edit_project_issue_path project, issue
85 86 87 88 89 90
      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'
91
      wait_for_requests
92
      assert_template("#{template_content}")
93 94 95 96
      save_changes
    end
  end

97 98 99 100 101
  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
102
      project.repository.create_file(
103 104 105 106
        user,
        '.gitlab/merge_request_templates/feature-proposal.md',
        template_content,
        message: 'added merge request template',
107
        branch_name: 'master')
108
      visit edit_project_merge_request_path project, merge_request
109 110 111 112 113
      fill_in :'merge_request[title]', with: 'test merge request title'
    end

    scenario 'user selects "feature-proposal" template' do
      select_template 'feature-proposal'
114
      wait_for_requests
115
      assert_template
116 117 118 119 120 121 122
      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) }
123
    let(:fork_project) { create(:project, :public, :repository) }
124
    let(:merge_request) { create(:merge_request, :with_diffs, source_project: fork_project, target_project: project) }
125 126

    background do
127 128
      sign_out(:user)

129 130 131
      project.team << [fork_user, :developer]
      fork_project.team << [fork_user, :master]
      create(:forked_project_link, forked_to_project: fork_project, forked_from_project: project)
132 133 134

      sign_in(fork_user)

135
      project.repository.create_file(
136 137 138 139
        fork_user,
        '.gitlab/merge_request_templates/feature-proposal.md',
        template_content,
        message: 'added merge request template',
140
        branch_name: 'master')
141
      visit edit_project_merge_request_path project, merge_request
142 143 144
      fill_in :'merge_request[title]', with: 'test merge request title'
    end

145 146 147 148
    context 'feature proposal template' do
      context 'template exists in target project' do
        scenario 'user selects template' do
          select_template 'feature-proposal'
149
          wait_for_requests
150
          assert_template
151 152 153
          save_changes
        end
      end
154 155 156
    end
  end

157 158
  def assert_template(expected_content = template_content)
    expect(find('textarea')['value']).to eq(expected_content)
159 160
  end

161
  def save_changes(expected_content = template_content)
162
    click_button "Save changes"
163
    expect(page).to have_content expected_content
164 165 166
  end

  def select_template(name)
167 168 169
    find('.js-issuable-selector').click

    find('.js-issuable-selector-wrap .dropdown-content a', text: name, match: :first).click
170
  end
171 172

  def select_option(name)
173 174 175
    find('.js-issuable-selector').click

    find('.js-issuable-selector-wrap .dropdown-footer-list a', text: name, match: :first).click
176
  end
177
end