user_sorts_merge_requests_spec.rb 2.76 KB
Newer Older
1 2 3
require 'spec_helper'

describe 'User sorts merge requests' do
4 5
  include CookieHelper

6 7 8 9
  let!(:merge_request) { create(:merge_request, source_project: project, target_project: project) }
  let!(:merge_request2) do
    create(:merge_request_with_diffs, source_project: project, target_project: project, source_branch: 'merge-test')
  end
10 11 12 13
  set(:user) { create(:user) }
  set(:group) { create(:group) }
  set(:group_member) { create(:group_member, :maintainer, user: user, group: group) }
  set(:project) { create(:project, :public, group: group) }
14 15 16 17 18 19 20 21

  before do
    sign_in(user)

    visit(project_merge_requests_path(project))
  end

  it 'keeps the sort option' do
22
    find('.filter-dropdown-container .dropdown').click
23

24
    page.within('ul.dropdown-menu.dropdown-menu-right li') do
25
      click_link('Milestone')
26 27
    end

Heinrich Lee Yu's avatar
Heinrich Lee Yu committed
28
    visit(merge_requests_dashboard_path(assignee_username: user.username))
29

30
    expect(find('.issues-filters a.is-active')).to have_content('Milestone')
31 32 33

    visit(project_merge_requests_path(project))

34 35 36 37 38 39 40 41 42 43
    expect(find('.issues-filters a.is-active')).to have_content('Milestone')

    visit(merge_requests_group_path(group))

    expect(find('.issues-filters a.is-active')).to have_content('Milestone')
  end

  it 'fallbacks to issuable_sort cookie key when remembering the sorting option' do
    set_cookie('issuable_sort', 'milestone')

Heinrich Lee Yu's avatar
Heinrich Lee Yu committed
44
    visit(merge_requests_dashboard_path(assignee_username: user.username))
45 46 47 48 49 50 51

    expect(find('.issues-filters a.is-active')).to have_content('Milestone')
  end

  it 'separates remember sorting with issues' do
    create(:issue, project: project)

52
    find('.filter-dropdown-container .dropdown').click
53

54
    page.within('ul.dropdown-menu.dropdown-menu-right li') do
55 56 57 58 59 60
      click_link('Milestone')
    end

    visit(project_issues_path(project))

    expect(find('.issues-filters a.is-active')).not_to have_content('Milestone')
61 62 63 64 65 66 67 68 69 70 71 72
  end

  context 'when merge requests have awards' do
    before do
      create_list(:award_emoji, 2, awardable: merge_request)
      create(:award_emoji, :downvote, awardable: merge_request)

      create(:award_emoji, awardable: merge_request2)
      create_list(:award_emoji, 2, :downvote, awardable: merge_request2)
    end

    it 'sorts by popularity' do
73
      find('.filter-dropdown-container .dropdown').click
74

75
      page.within('ul.dropdown-menu.dropdown-menu-right li') do
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
        click_link('Popularity')
      end

      page.within('.mr-list') do
        page.within('li.merge-request:nth-child(1)') do
          expect(page).to have_content(merge_request.title)
          expect(page).to have_content('2 1')
        end

        page.within('li.merge-request:nth-child(2)') do
          expect(page).to have_content(merge_request2.title)
          expect(page).to have_content('1 2')
        end
      end
    end
  end
end