user_lists_merge_requests_spec.rb 4.01 KB
Newer Older
1
require 'rails_helper'
2

3
describe 'Merge requests > User lists merge requests' do
4
  include MergeRequestHelpers
5 6
  include SortingHelper

7
  let(:project) { create(:project, :public, :repository) }
8 9 10 11 12 13 14 15
  let(:user) { create(:user) }

  before do
    @fix = create(:merge_request,
                  title: 'fix',
                  source_project: project,
                  source_branch: 'fix',
                  assignee: user,
16
                  milestone: create(:milestone, project: project, due_date: '2013-12-11'),
17 18 19 20 21 22 23
                  created_at: 1.minute.ago,
                  updated_at: 1.minute.ago)
    create(:merge_request,
           title: 'markdown',
           source_project: project,
           source_branch: 'markdown',
           assignee: user,
24
           milestone: create(:milestone, project: project, due_date: '2013-12-12'),
25 26 27
           created_at: 2.minutes.ago,
           updated_at: 2.minutes.ago)
    create(:merge_request,
28
           title: 'merge-test',
29
           source_project: project,
30
           source_branch: 'merge-test',
31 32 33 34 35 36 37
           created_at: 3.minutes.ago,
           updated_at: 10.seconds.ago)
  end

  it 'filters on no assignee' do
    visit_merge_requests(project, assignee_id: IssuableFinder::NONE)

38
    expect(current_path).to eq(project_merge_requests_path(project))
39
    expect(page).to have_content 'merge-test'
40 41
    expect(page).not_to have_content 'fix'
    expect(page).not_to have_content 'markdown'
42
    expect(count_merge_requests).to eq(1)
43 44 45 46 47
  end

  it 'filters on a specific assignee' do
    visit_merge_requests(project, assignee_id: user.id)

48
    expect(page).not_to have_content 'merge-test'
49 50
    expect(page).to have_content 'fix'
    expect(page).to have_content 'markdown'
51
    expect(count_merge_requests).to eq(2)
52 53 54
  end

  it 'sorts by newest' do
55
    visit_merge_requests(project, sort: sort_value_created_date)
56

57
    expect(first_merge_request).to include('fix')
58
    expect(last_merge_request).to include('merge-test')
59
    expect(count_merge_requests).to eq(3)
60 61 62 63 64
  end

  it 'sorts by last updated' do
    visit_merge_requests(project, sort: sort_value_recently_updated)

65
    expect(first_merge_request).to include('merge-test')
66
    expect(count_merge_requests).to eq(3)
67 68
  end

69 70
  it 'sorts by milestone' do
    visit_merge_requests(project, sort: sort_value_milestone)
71 72

    expect(first_merge_request).to include('fix')
73
    expect(count_merge_requests).to eq(3)
74 75
  end

76
  it 'filters on one label and sorts by due date' do
77 78 79 80
    label = create(:label, project: project)
    create(:label_link, label: label, target: @fix)

    visit_merge_requests(project, label_name: [label.name],
81
                                  sort: sort_value_due_date)
82 83

    expect(first_merge_request).to include('fix')
84
    expect(count_merge_requests).to eq(1)
85 86 87 88 89 90 91 92 93 94 95
  end

  context 'while filtering on two labels' do
    let(:label) { create(:label, project: project) }
    let(:label2) { create(:label, project: project) }

    before do
      create(:label_link, label: label, target: @fix)
      create(:label_link, label: label2, target: @fix)
    end

96
    it 'sorts by due date' do
97
      visit_merge_requests(project, label_name: [label.name, label2.name],
98
                                    sort: sort_value_due_date)
99 100

      expect(first_merge_request).to include('fix')
101
      expect(count_merge_requests).to eq(1)
102 103 104 105 106 107
    end

    context 'filter on assignee and' do
      it 'sorts by due soon' do
        visit_merge_requests(project, label_name: [label.name, label2.name],
                                      assignee_id: user.id,
108
                                      sort: sort_value_due_date)
109 110

        expect(first_merge_request).to include('fix')
111
        expect(count_merge_requests).to eq(1)
112
      end
113 114

      it 'sorts by recently due milestone' do
115
        visit project_merge_requests_path(project,
116 117
          label_name: [label.name, label2.name],
          assignee_id: user.id,
118
          sort: sort_value_milestone)
119 120 121

        expect(first_merge_request).to include('fix')
      end
122 123 124
    end
  end

125 126 127
  def count_merge_requests
    page.all('ul.mr-list > li').count
  end
128
end