issues_spec.rb 8.97 KB
Newer Older
gitlabhq's avatar
gitlabhq committed
1 2
require 'spec_helper'

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
3
describe 'Issues', feature: true do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
4 5
  include SortingHelper

6
  let(:project) { create(:project) }
gitlabhq's avatar
gitlabhq committed
7

Nihad Abbasov's avatar
Nihad Abbasov committed
8
  before do
gitlabhq's avatar
gitlabhq committed
9
    login_as :user
Riyad Preukschas's avatar
Riyad Preukschas committed
10
    user2 = create(:user)
gitlabhq's avatar
fixes  
gitlabhq committed
11

12
    project.team << [[@user, user2], :developer]
gitlabhq's avatar
gitlabhq committed
13 14
  end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
15
  describe 'Edit issue' do
Riyad Preukschas's avatar
Riyad Preukschas committed
16 17 18 19 20 21 22
    let!(:issue) do
      create(:issue,
             author: @user,
             assignee: @user,
             project: project)
    end

Nihad Abbasov's avatar
Nihad Abbasov committed
23
    before do
Vinnie Okada's avatar
Vinnie Okada committed
24
      visit namespace_project_issues_path(project.namespace, project)
gitlabhq's avatar
gitlabhq committed
25 26 27
      click_link "Edit"
    end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
28
    it 'should open new issue popup' do
29
      expect(page).to have_content("Issue ##{issue.iid}")
gitlabhq's avatar
gitlabhq committed
30 31
    end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
32
    describe 'fill in' do
gitlabhq's avatar
gitlabhq committed
33
      before do
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
34 35
        fill_in 'issue_title', with: 'bug 345'
        fill_in 'issue_description', with: 'bug description'
gitlabhq's avatar
gitlabhq committed
36 37
      end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
38 39 40 41 42
      it 'does not change issue count' do
        expect {
          click_button 'Save changes'
        }.to_not change { Issue.count }
      end
gitlabhq's avatar
gitlabhq committed
43

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
44 45
      it 'should update issue fields' do
        click_button 'Save changes'
gitlabhq's avatar
gitlabhq committed
46

47
        expect(page).to have_content @user.name
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
48
        expect(page).to have_content 'bug 345'
49
        expect(page).to have_content project.name
gitlabhq's avatar
gitlabhq committed
50 51
      end
    end
52 53 54

  end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
55
  describe 'Editing issue assignee' do
56 57 58 59 60 61 62
    let!(:issue) do
      create(:issue,
             author: @user,
             assignee: @user,
             project: project)
    end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
63
    it 'allows user to select unasigned', js: true do
Vinnie Okada's avatar
Vinnie Okada committed
64
      visit edit_namespace_project_issue_path(project.namespace, project, issue)
65

66
      expect(page).to have_content "Assign to #{@user.name}"
67

68
      first('#s2id_issue_assignee_id').click
69
      sleep 2 # wait for ajax stuff to complete
70
      first('.user-result').click
71

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
72
      click_button 'Save changes'
73

74 75
      expect(page).to have_content 'Assignee: none'
      expect(issue.reload.assignee).to be_nil
76
    end
gitlabhq's avatar
gitlabhq committed
77
  end
Adam Leonard's avatar
Adam Leonard committed
78

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
79
  describe 'Filter issue' do
80 81
    before do
      ['foobar', 'barbaz', 'gitlab'].each do |title|
Riyad Preukschas's avatar
Riyad Preukschas committed
82 83 84 85 86
        create(:issue,
               author: @user,
               assignee: @user,
               project: project,
               title: title)
87 88
      end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
89
      @issue = Issue.find_by(title: 'foobar')
90 91 92
      @issue.milestone = create(:milestone, project: project)
      @issue.assignee = nil
      @issue.save
93 94
    end

95
    let(:issue) { @issue }
Riyad Preukschas's avatar
Riyad Preukschas committed
96

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
97
    it 'should allow filtering by issues with no specified milestone' do
98
      visit namespace_project_issues_path(project.namespace, project, milestone_id: IssuableFinder::NONE)
99

100 101 102
      expect(page).not_to have_content 'foobar'
      expect(page).to have_content 'barbaz'
      expect(page).to have_content 'gitlab'
103 104
    end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
105
    it 'should allow filtering by a specified milestone' do
Vinnie Okada's avatar
Vinnie Okada committed
106
      visit namespace_project_issues_path(project.namespace, project, milestone_id: issue.milestone.id)
107

108 109 110
      expect(page).to have_content 'foobar'
      expect(page).not_to have_content 'barbaz'
      expect(page).not_to have_content 'gitlab'
111
    end
112

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
113
    it 'should allow filtering by issues with no specified assignee' do
114
      visit namespace_project_issues_path(project.namespace, project, assignee_id: IssuableFinder::NONE)
115

116 117 118
      expect(page).to have_content 'foobar'
      expect(page).not_to have_content 'barbaz'
      expect(page).not_to have_content 'gitlab'
119 120
    end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
121
    it 'should allow filtering by a specified assignee' do
Vinnie Okada's avatar
Vinnie Okada committed
122
      visit namespace_project_issues_path(project.namespace, project, assignee_id: @user.id)
123

124 125 126
      expect(page).not_to have_content 'foobar'
      expect(page).to have_content 'barbaz'
      expect(page).to have_content 'gitlab'
127
    end
128
  end
129 130 131 132

  describe 'filter issue' do
    titles = ['foo','bar','baz']
    titles.each_with_index do |title, index|
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
133 134 135 136 137
      let!(title.to_sym) do
        create(:issue, title: title,
                       project: project,
                       created_at: Time.now - (index * 60))
      end
138
    end
139 140
    let(:newer_due_milestone) { create(:milestone, due_date: '2013-12-11') }
    let(:later_due_milestone) { create(:milestone, due_date: '2013-12-12') }
141 142

    it 'sorts by newest' do
Vinnie Okada's avatar
Vinnie Okada committed
143
      visit namespace_project_issues_path(project.namespace, project, sort: sort_value_recently_created)
144

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
145 146
      expect(first_issue).to include('foo')
      expect(last_issue).to include('baz')
147 148 149
    end

    it 'sorts by oldest' do
Vinnie Okada's avatar
Vinnie Okada committed
150
      visit namespace_project_issues_path(project.namespace, project, sort: sort_value_oldest_created)
151

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
152 153
      expect(first_issue).to include('baz')
      expect(last_issue).to include('foo')
154 155 156 157 158
    end

    it 'sorts by most recently updated' do
      baz.updated_at = Time.now + 100
      baz.save
Vinnie Okada's avatar
Vinnie Okada committed
159
      visit namespace_project_issues_path(project.namespace, project, sort: sort_value_recently_updated)
160

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
161
      expect(first_issue).to include('baz')
162 163 164 165 166
    end

    it 'sorts by least recently updated' do
      baz.updated_at = Time.now - 100
      baz.save
Vinnie Okada's avatar
Vinnie Okada committed
167
      visit namespace_project_issues_path(project.namespace, project, sort: sort_value_oldest_updated)
168

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
169
      expect(first_issue).to include('baz')
170 171 172
    end

    describe 'sorting by milestone' do
173
      before :each do
174 175 176 177 178 179 180
        foo.milestone = newer_due_milestone
        foo.save
        bar.milestone = later_due_milestone
        bar.save
      end

      it 'sorts by recently due milestone' do
Vinnie Okada's avatar
Vinnie Okada committed
181
        visit namespace_project_issues_path(project.namespace, project, sort: sort_value_milestone_soon)
182

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
183
        expect(first_issue).to include('foo')
184 185 186
      end

      it 'sorts by least recently due milestone' do
Vinnie Okada's avatar
Vinnie Okada committed
187
        visit namespace_project_issues_path(project.namespace, project, sort: sort_value_milestone_later)
188

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
189
        expect(first_issue).to include('bar')
190 191 192 193 194 195 196 197 198 199 200 201 202 203
      end
    end

    describe 'combine filter and sort' do
      let(:user2) { create(:user) }

      before :each do
        foo.assignee = user2
        foo.save
        bar.assignee = user2
        bar.save
      end

      it 'sorts with a filter applied' do
Vinnie Okada's avatar
Vinnie Okada committed
204 205 206
        visit namespace_project_issues_path(project.namespace, project,
                                            sort: sort_value_oldest_created,
                                            assignee_id: user2.id)
207

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
208 209
        expect(first_issue).to include('bar')
        expect(last_issue).to include('foo')
210
        expect(page).not_to have_content 'baz'
211 212 213
      end
    end
  end
214

215 216 217 218 219 220
  describe 'update assignee from issue#show' do
    let(:issue) { create(:issue, project: project, author: @user) }

    context 'by autorized user' do

      it 'with dropdown menu' do
Vinnie Okada's avatar
Vinnie Okada committed
221
        visit namespace_project_issue_path(project.namespace, project, issue)
222

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
223 224
        find('.edit-issue.inline-update #issue_assignee_id').
          set project.team.members.first.id
225 226
        click_button 'Update Issue'

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
227 228 229
        expect(page).to have_content 'Assignee:'
        has_select?('issue_assignee_id',
                    selected: project.team.members.first.name)
230 231 232 233
      end
    end

    context 'by unauthorized user' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
234

235
      let(:guest) { create(:user) }
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
236

237 238 239 240 241 242
      before :each do
        project.team << [[guest], :guest]
        issue.assignee = @user
        issue.save
      end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
243
      it 'shows assignee text', js: true do
244 245 246
        logout
        login_with guest

Vinnie Okada's avatar
Vinnie Okada committed
247
        visit namespace_project_issue_path(project.namespace, project, issue)
248
        expect(page).to have_content issue.assignee.name
249 250 251 252 253 254 255 256 257 258 259
      end
    end
  end

  describe 'update milestone from issue#show' do
    let!(:issue) { create(:issue, project: project, author: @user) }
    let!(:milestone) { create(:milestone, project: project) }

    context 'by authorized user' do

      it 'with dropdown menu' do
Vinnie Okada's avatar
Vinnie Okada committed
260
        visit namespace_project_issue_path(project.namespace, project, issue)
261

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
262 263
        find('.edit-issue.inline-update').
          select(milestone.title, from: 'issue_milestone_id')
264 265
        click_button 'Update Issue'

266 267
        expect(page).to have_content "Milestone changed to #{milestone.title}"
        expect(page).to have_content "Milestone: #{milestone.title}"
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
268
        has_select?('issue_assignee_id', selected: milestone.title)
269 270 271 272 273
      end
    end

    context 'by unauthorized user' do
      let(:guest) { create(:user) }
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
274

275
      before :each do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
276
        project.team << [guest, :guest]
277 278 279 280
        issue.milestone = milestone
        issue.save
      end

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
281
      it 'shows milestone text', js: true do
282 283 284
        logout
        login_with guest

Vinnie Okada's avatar
Vinnie Okada committed
285
        visit namespace_project_issue_path(project.namespace, project, issue)
286
        expect(page).to have_content milestone.title
287 288
      end
    end
289 290 291 292 293 294 295 296 297

    describe 'removing assignee' do
      let(:user2) { create(:user) }

      before :each do
        issue.assignee = user2
        issue.save
      end

Vinnie Okada's avatar
Vinnie Okada committed
298 299
      it 'allows user to remove assignee', :js => true do
        visit namespace_project_issue_path(project.namespace, project, issue)
300
        expect(page).to have_content "Assignee: #{user2.name}"
301

302
        first('#s2id_issue_assignee_id').click
303
        sleep 2 # wait for ajax stuff to complete
304
        first('.user-result').click
305

306
        expect(page).to have_content 'Assignee: none'
307
        sleep 2 # wait for ajax stuff to complete
308
        expect(issue.reload.assignee).to be_nil
309 310
      end
    end
311 312
  end

313
  def first_issue
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
314
    all('ul.issues-list li').first.text
315 316 317
  end

  def last_issue
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
318
    all('ul.issues-list li').last.text
319
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
320
end