issues_spec.rb 8.98 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
24
      visit edit_namespace_project_issue_path(project.namespace, project, issue)
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
      it 'does not change issue count' do
39
        expect { click_button 'Save changes' }.to_not change { Issue.count }
Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
40
      end
gitlabhq's avatar
gitlabhq committed
41

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

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

  end

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

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

64
      expect(page).to have_content "Assign to #{@user.name}"
65

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

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
70
      click_button 'Save changes'
71

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

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

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

93
    let(:issue) { @issue }
Riyad Preukschas's avatar
Riyad Preukschas committed
94

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

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

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
103
    it 'should allow filtering by a specified milestone' do
104
      visit namespace_project_issues_path(project.namespace, project, milestone_title: issue.milestone.title)
105

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    describe 'sorting by milestone' do
171
      before :each do
172 173 174 175 176 177 178
        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
179
        visit namespace_project_issues_path(project.namespace, project, sort: sort_value_milestone_soon)
180

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

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

Jeroen van Baarsen's avatar
Jeroen van Baarsen committed
187
        expect(first_issue).to include('bar')
188 189 190 191 192 193 194 195 196 197 198 199 200 201
      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
202 203 204
        visit namespace_project_issues_path(project.namespace, project,
                                            sort: sort_value_oldest_created,
                                            assignee_id: user2.id)
205

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

213 214 215 216 217 218
  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
219
        visit namespace_project_issue_path(project.namespace, project, issue)
220

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

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

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

233
      let(:guest) { create(:user) }
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
234

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

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

Vinnie Okada's avatar
Vinnie Okada committed
245
        visit namespace_project_issue_path(project.namespace, project, issue)
246
        expect(page).to have_content issue.assignee.name
247 248 249 250 251 252 253 254 255 256 257
      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
258
        visit namespace_project_issue_path(project.namespace, project, issue)
259

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

264 265
        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
266
        has_select?('issue_assignee_id', selected: milestone.title)
267 268 269 270 271
      end
    end

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

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

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

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

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

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

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

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

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

311
  def first_issue
312
    page.all('ul.issues-list li').first.text
313 314 315
  end

  def last_issue
316
    page.all('ul.issues-list li').last.text
317
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
318
end