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

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

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
gitlabhq's avatar
gitlabhq committed
24 25 26 27
      visit project_issues_path(project)
      click_link "Edit"
    end

Nihad Abbasov's avatar
Nihad Abbasov 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

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

38
      it { expect { click_button "Save changes" }.to_not change {Issue.count} }
gitlabhq's avatar
gitlabhq committed
39

Nihad Abbasov's avatar
Nihad Abbasov committed
40
      it "should update issue fields" do
41
        click_button "Save changes"
gitlabhq's avatar
gitlabhq committed
42

43 44 45
        expect(page).to have_content @user.name
        expect(page).to have_content "bug 345"
        expect(page).to have_content project.name
gitlabhq's avatar
gitlabhq committed
46 47
      end
    end
48 49 50 51 52 53 54 55 56 57 58 59 60 61

  end

  describe "Editing issue assignee" do
    let!(:issue) do
      create(:issue,
             author: @user,
             assignee: @user,
             project: project)
    end

    it 'allows user to select unasigned', :js => true do
      visit edit_project_issue_path(project, issue)

62
      expect(page).to have_content "Assign to #{@user.name}"
63

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

      click_button "Save changes"

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

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

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

91
    let(:issue) { @issue }
Riyad Preukschas's avatar
Riyad Preukschas committed
92

93 94 95
    it "should allow filtering by issues with no specified milestone" do
      visit project_issues_path(project, milestone_id: '0')

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

    it "should allow filtering by a specified milestone" do
Riyad Preukschas's avatar
Riyad Preukschas committed
102
      visit project_issues_path(project, milestone_id: issue.milestone.id)
103

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

    it "should allow filtering by issues with no specified assignee" do
      visit project_issues_path(project, assignee_id: '0')

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

    it "should allow filtering by a specified assignee" do
      visit project_issues_path(project, assignee_id: @user.id)

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

  describe 'filter issue' do
    titles = ['foo','bar','baz']
    titles.each_with_index do |title, index|
      let!(title.to_sym) { create(:issue, title: title, project: project, created_at: Time.now - (index * 60)) }
    end
131 132
    let(:newer_due_milestone) { create(:milestone, due_date: '2013-12-11') }
    let(:later_due_milestone) { create(:milestone, due_date: '2013-12-12') }
133 134

    it 'sorts by newest' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
135
      visit project_issues_path(project, sort: sort_value_recently_created)
136

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

    it 'sorts by oldest' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
142
      visit project_issues_path(project, sort: sort_value_oldest_created)
143

144 145
      expect(first_issue).to include("baz")
      expect(last_issue).to include("foo")
146 147 148 149 150
    end

    it 'sorts by most recently updated' do
      baz.updated_at = Time.now + 100
      baz.save
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
151
      visit project_issues_path(project, sort: sort_value_recently_updated)
152

153
      expect(first_issue).to include("baz")
154 155 156 157 158
    end

    it 'sorts by least recently updated' do
      baz.updated_at = Time.now - 100
      baz.save
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
159
      visit project_issues_path(project, sort: sort_value_oldest_updated)
160

161
      expect(first_issue).to include("baz")
162 163 164
    end

    describe 'sorting by milestone' do
165
      before :each do
166 167 168 169 170 171 172
        foo.milestone = newer_due_milestone
        foo.save
        bar.milestone = later_due_milestone
        bar.save
      end

      it 'sorts by recently due milestone' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
173
        visit project_issues_path(project, sort: sort_value_milestone_soon)
174

175
        expect(first_issue).to include("foo")
176 177 178
      end

      it 'sorts by least recently due milestone' do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
179
        visit project_issues_path(project, sort: sort_value_milestone_later)
180

181
        expect(first_issue).to include("bar")
182 183 184 185 186 187 188 189 190 191 192 193 194 195
      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
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
196
        visit project_issues_path(project, sort: sort_value_oldest_created, assignee_id: user2.id)
197

198 199 200
        expect(first_issue).to include("bar")
        expect(last_issue).to include("foo")
        expect(page).not_to have_content 'baz'
201 202 203
      end
    end
  end
204

205 206 207 208 209 210 211 212
  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
        visit project_issue_path(project, issue)

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
213
        find('.edit-issue.inline-update #issue_assignee_id').set project.team.members.first.id
214 215
        click_button 'Update Issue'

216
        expect(page).to have_content "Assignee:"
217
        has_select?('issue_assignee_id', :selected => project.team.members.first.name)
218 219 220 221
      end
    end

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

223
      let(:guest) { create(:user) }
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
224

225 226 227 228 229 230
      before :each do
        project.team << [[guest], :guest]
        issue.assignee = @user
        issue.save
      end

Ciro Santilli's avatar
Ciro Santilli committed
231
      it "shows assignee text", js: true do
232 233 234 235
        logout
        login_with guest

        visit project_issue_path(project, issue)
236
        expect(page).to have_content issue.assignee.name
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
      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
        visit project_issue_path(project, issue)

        find('.edit-issue.inline-update').select(milestone.title, from: 'issue_milestone_id')
        click_button 'Update Issue'

253 254
        expect(page).to have_content "Milestone changed to #{milestone.title}"
        expect(page).to have_content "Milestone: #{milestone.title}"
255
        has_select?('issue_assignee_id', :selected => milestone.title)
256 257 258 259 260
      end
    end

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

262
      before :each do
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
263
        project.team << [guest, :guest]
264 265 266 267
        issue.milestone = milestone
        issue.save
      end

Ciro Santilli's avatar
Ciro Santilli committed
268
      it "shows milestone text", js: true do
269 270 271 272
        logout
        login_with guest

        visit project_issue_path(project, issue)
273
        expect(page).to have_content milestone.title
274 275
      end
    end
276 277 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

      it 'allows user to remove assignee', :js => true do
        visit project_issue_path(project, issue)
287
        expect(page).to have_content "Assignee: #{user2.name}"
288

289
        first('#s2id_issue_assignee_id').click
290
        sleep 2 # wait for ajax stuff to complete
291
        first('.user-result').click
292

293
        expect(page).to have_content 'Assignee: none'
294
        sleep 2 # wait for ajax stuff to complete
295
        expect(issue.reload.assignee).to be_nil
296 297
      end
    end
298 299
  end

300 301 302 303 304 305 306
  def first_issue
    all("ul.issues-list li").first.text
  end

  def last_issue
    all("ul.issues-list li").last.text
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
307
end