BigW Consortium Gitlab

issues_spec.rb 8.48 KB
Newer Older
gitlabhq committed
1 2
require 'spec_helper'

3
describe 'Issues', feature: true do
Dmitriy Zaporozhets committed
4 5
  include SortingHelper

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

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

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

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

Nihad Abbasov committed
23
    before do
24
      visit edit_namespace_project_issue_path(project.namespace, project, issue)
gitlabhq committed
25 26 27
      click_link "Edit"
    end

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

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

38
      it 'does not change issue count' do
39
        expect { click_button 'Save changes' }.to_not change { Issue.count }
40
      end
gitlabhq committed
41

42 43
      it 'should update issue fields' do
        click_button 'Save changes'
gitlabhq committed
44

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

  end

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

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

64
      expect(page).to have_content "Assignee #{@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

70
      click_button 'Save changes'
71

72 73 74 75
      page.within('.assignee') do
        expect(page).to have_content 'None'
      end

76
      expect(issue.reload.assignee).to be_nil
77
    end
gitlabhq committed
78
  end
79

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

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

96
    let(:issue) { @issue }
Riyad Preukschas committed
97

98
    it 'should allow filtering by issues with no specified assignee' do
99
      visit namespace_project_issues_path(project.namespace, project, assignee_id: IssuableFinder::NONE)
100

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

106
    it 'should allow filtering by a specified assignee' do
Vinnie Okada committed
107
      visit namespace_project_issues_path(project.namespace, project, assignee_id: @user.id)
108

109 110 111
      expect(page).not_to have_content 'foobar'
      expect(page).to have_content 'barbaz'
      expect(page).to have_content 'gitlab'
112
    end
113
  end
114 115 116 117

  describe 'filter issue' do
    titles = ['foo','bar','baz']
    titles.each_with_index do |title, index|
118 119 120 121 122
      let!(title.to_sym) do
        create(:issue, title: title,
                       project: project,
                       created_at: Time.now - (index * 60))
      end
123
    end
124 125
    let(:newer_due_milestone) { create(:milestone, due_date: '2013-12-11') }
    let(:later_due_milestone) { create(:milestone, due_date: '2013-12-12') }
126 127

    it 'sorts by newest' do
Vinnie Okada committed
128
      visit namespace_project_issues_path(project.namespace, project, sort: sort_value_recently_created)
129

130 131
      expect(first_issue).to include('baz')
      expect(last_issue).to include('foo')
132 133 134
    end

    it 'sorts by oldest' do
Vinnie Okada committed
135
      visit namespace_project_issues_path(project.namespace, project, sort: sort_value_oldest_created)
136

137 138
      expect(first_issue).to include('foo')
      expect(last_issue).to include('baz')
139 140 141 142 143
    end

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

146
      expect(first_issue).to include('baz')
147 148 149 150 151
    end

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

154
      expect(first_issue).to include('baz')
155 156 157
    end

    describe 'sorting by milestone' do
158
      before :each do
159 160 161 162 163 164 165
        foo.milestone = newer_due_milestone
        foo.save
        bar.milestone = later_due_milestone
        bar.save
      end

      it 'sorts by recently due milestone' do
Vinnie Okada committed
166
        visit namespace_project_issues_path(project.namespace, project, sort: sort_value_milestone_soon)
167

168
        expect(first_issue).to include('foo')
169 170 171
      end

      it 'sorts by least recently due milestone' do
Vinnie Okada committed
172
        visit namespace_project_issues_path(project.namespace, project, sort: sort_value_milestone_later)
173

174
        expect(first_issue).to include('bar')
175 176 177 178 179 180 181 182 183 184 185 186 187 188
      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 committed
189 190 191
        visit namespace_project_issues_path(project.namespace, project,
                                            sort: sort_value_oldest_created,
                                            assignee_id: user2.id)
192

193 194
        expect(first_issue).to include('foo')
        expect(last_issue).to include('bar')
195
        expect(page).not_to have_content 'baz'
196 197 198
      end
    end
  end
199

200 201 202 203 204 205
  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 committed
206
        visit namespace_project_issue_path(project.namespace, project, issue)
207

208
        find('.issuable-sidebar #issue_assignee_id').
209
          set project.team.members.first.id
210 211
        click_button 'Update Issue'

Dmitriy Zaporozhets committed
212
        expect(page).to have_content 'Assignee'
213 214
        has_select?('issue_assignee_id',
                    selected: project.team.members.first.name)
215 216 217 218
      end
    end

    context 'by unauthorized user' do
Dmitriy Zaporozhets committed
219

220
      let(:guest) { create(:user) }
Dmitriy Zaporozhets committed
221

222 223 224 225 226 227
      before :each do
        project.team << [[guest], :guest]
        issue.assignee = @user
        issue.save
      end

228
      it 'shows assignee text', js: true do
229 230 231
        logout
        login_with guest

Vinnie Okada committed
232
        visit namespace_project_issue_path(project.namespace, project, issue)
233
        expect(page).to have_content issue.assignee.name
234 235 236 237 238 239 240 241 242 243 244
      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 committed
245
        visit namespace_project_issue_path(project.namespace, project, issue)
246

247
        find('.issuable-sidebar').
248
          select(milestone.title, from: 'issue_milestone_id')
249 250
        click_button 'Update Issue'

251
        expect(page).to have_content "Milestone changed to #{milestone.title}"
252 253 254 255 256

        page.within('.milestone') do
          expect(page).to have_content milestone.title
        end

257
        has_select?('issue_assignee_id', selected: milestone.title)
258 259 260 261 262
      end
    end

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

264
      before :each do
Dmitriy Zaporozhets committed
265
        project.team << [guest, :guest]
266 267 268 269
        issue.milestone = milestone
        issue.save
      end

270
      it 'shows milestone text', js: true do
271 272 273
        logout
        login_with guest

Vinnie Okada committed
274
        visit namespace_project_issue_path(project.namespace, project, issue)
275
        expect(page).to have_content milestone.title
276 277
      end
    end
278 279 280 281 282 283 284 285 286

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

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

287
      it 'allows user to remove assignee', js: true do
Vinnie Okada committed
288
        visit namespace_project_issue_path(project.namespace, project, issue)
289

290 291 292 293 294
        page.within('.assignee') do
          expect(page).to have_content user2.name
        end

        find('.assignee .edit-link').click
295
        sleep 2 # wait for ajax stuff to complete
296
        first('.user-result').click
297

298 299 300 301
        page.within('.assignee') do
          expect(page).to have_content 'None'
        end

302
        sleep 2 # wait for ajax stuff to complete
303
        expect(issue.reload.assignee).to be_nil
304 305
      end
    end
306 307
  end

308
  def first_issue
Douwe Maan committed
309
    page.all('ul.issues-list > li').first.text
310 311 312
  end

  def last_issue
Douwe Maan committed
313
    page.all('ul.issues-list > li').last.text
314
  end
Dmitriy Zaporozhets committed
315
end