BigW Consortium Gitlab

issues_spec.rb 8.31 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 "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

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 committed
75
  end
76

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

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 committed
94

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

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

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

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

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

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

127 128
      expect(first_issue).to include('foo')
      expect(last_issue).to include('baz')
129 130 131
    end

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

134 135
      expect(first_issue).to include('baz')
      expect(last_issue).to include('foo')
136 137 138 139 140
    end

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

143
      expect(first_issue).to include('baz')
144 145 146 147 148
    end

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

151
      expect(first_issue).to include('baz')
152 153 154
    end

    describe 'sorting by milestone' do
155
      before :each do
156 157 158 159 160 161 162
        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
163
        visit namespace_project_issues_path(project.namespace, project, sort: sort_value_milestone_soon)
164

165
        expect(first_issue).to include('foo')
166 167 168
      end

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

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

190 191
        expect(first_issue).to include('bar')
        expect(last_issue).to include('foo')
192
        expect(page).not_to have_content 'baz'
193 194 195
      end
    end
  end
196

197 198 199 200 201 202
  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
203
        visit namespace_project_issue_path(project.namespace, project, issue)
204

205
        find('.context #issue_assignee_id').
206
          set project.team.members.first.id
207 208
        click_button 'Update Issue'

209 210 211
        expect(page).to have_content 'Assignee:'
        has_select?('issue_assignee_id',
                    selected: project.team.members.first.name)
212 213 214 215
      end
    end

    context 'by unauthorized user' do
Dmitriy Zaporozhets committed
216

217
      let(:guest) { create(:user) }
Dmitriy Zaporozhets committed
218

219 220 221 222 223 224
      before :each do
        project.team << [[guest], :guest]
        issue.assignee = @user
        issue.save
      end

225
      it 'shows assignee text', js: true do
226 227 228
        logout
        login_with guest

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

244
        find('.context').
245
          select(milestone.title, from: 'issue_milestone_id')
246 247
        click_button 'Update Issue'

248 249
        expect(page).to have_content "Milestone changed to #{milestone.title}"
        expect(page).to have_content "Milestone: #{milestone.title}"
250
        has_select?('issue_assignee_id', selected: milestone.title)
251 252 253 254 255
      end
    end

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

257
      before :each do
Dmitriy Zaporozhets committed
258
        project.team << [guest, :guest]
259 260 261 262
        issue.milestone = milestone
        issue.save
      end

263
      it 'shows milestone text', js: true do
264 265 266
        logout
        login_with guest

Vinnie Okada committed
267
        visit namespace_project_issue_path(project.namespace, project, issue)
268
        expect(page).to have_content milestone.title
269 270
      end
    end
271 272 273 274 275 276 277 278 279

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

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

280
      it 'allows user to remove assignee', js: true do
Vinnie Okada committed
281
        visit namespace_project_issue_path(project.namespace, project, issue)
282
        expect(page).to have_content "Assignee: #{user2.name}"
283

284
        first('#s2id_issue_assignee_id').click
285
        sleep 2 # wait for ajax stuff to complete
286
        first('.user-result').click
287

288
        expect(page).to have_content 'Assignee: none'
289
        sleep 2 # wait for ajax stuff to complete
290
        expect(issue.reload.assignee).to be_nil
291 292
      end
    end
293 294
  end

295
  def first_issue
296
    page.all('ul.issues-list li').first.text
297 298 299
  end

  def last_issue
300
    page.all('ul.issues-list li').last.text
301
  end
Dmitriy Zaporozhets committed
302
end