BigW Consortium Gitlab

update_merge_requests_spec.rb 3.4 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
require 'rails_helper'

feature 'Multiple merge requests updating from merge_requests#index', feature: true do
  include WaitForAjax

  let!(:user)    { create(:user)}
  let!(:project) { create(:project) }
  let!(:merge_request) { create(:merge_request, source_project: project, target_project: project) }

  before do
    project.team << [user, :master]
    login_as(user)
  end

  context 'status', js: true do
16 17 18 19
    describe 'close merge request' do
      before do
        visit namespace_project_merge_requests_path(project.namespace, project)
      end
20

21 22 23 24 25
      it 'closes merge request' do
        change_status('Closed')

        expect(page).to have_selector('.merge-request', count: 0)
      end
26 27
    end

28 29 30 31 32 33 34 35
    describe 'reopen merge request' do
      before do
        merge_request.close
        visit namespace_project_merge_requests_path(project.namespace, project, state: 'closed')
      end

      it 'reopens merge request' do
        change_status('Open')
36

37 38
        expect(page).to have_selector('.merge-request', count: 0)
      end
39 40 41 42
    end
  end

  context 'assignee', js: true do
43
    describe 'set assignee' do
44 45 46
      before do
        visit namespace_project_merge_requests_path(project.namespace, project)
      end
47

48
      it "updates merge request with assignee" do
49
        change_assignee(user.name)
50

51 52 53
        page.within('.merge-request .controls') do
          expect(find('.author_link')["title"]).to have_content(user.name)
        end
54 55 56
      end
    end

57
    describe 'remove assignee' do
58 59 60 61 62
      before do
        merge_request.assignee = user
        merge_request.save
        visit namespace_project_merge_requests_path(project.namespace, project)
      end
63

64
      it "removes assignee from the merge request" do
65
        change_assignee('Unassigned')
66

67 68
        expect(find('.merge-request .controls')).not_to have_css('.author_link')
      end
69 70 71 72 73 74
    end
  end

  context 'milestone', js: true do
    let(:milestone)  { create(:milestone, project: project) }

75
    describe 'set milestone' do
76 77 78
      before do
        visit namespace_project_merge_requests_path(project.namespace, project)
      end
79

80
      it "updates merge request with milestone" do
81
        change_milestone(milestone.title)
82

83 84
        expect(find('.merge-request')).to have_content milestone.title
      end
85 86
    end

87
    describe 'unset milestone' do
88 89 90 91 92
      before do
        merge_request.milestone = milestone
        merge_request.save
        visit namespace_project_merge_requests_path(project.namespace, project)
      end
93

94
      it "removes milestone from the merge request" do
95
        change_milestone("No Milestone")
96

97 98 99 100
        expect(find('.merge-request')).not_to have_content milestone.title
      end
    end
  end
101

102 103 104 105 106 107
  def change_status(text)
    find('#check_all_issues').click
    find('.js-issue-status').click
    find('.dropdown-menu-status a', text: text).click
    click_update_merge_requests_button
  end
108

109 110 111 112
  def change_assignee(text)
    find('#check_all_issues').click
    find('.js-update-assignee').click
    wait_for_ajax
113

114 115
    page.within '.dropdown-menu-user' do
      click_link text
116
    end
117 118

    click_update_merge_requests_button
119 120
  end

121 122 123 124 125
  def change_milestone(text)
    find('#check_all_issues').click
    find('.issues_bulk_update .js-milestone-select').click
    find('.dropdown-menu-milestone a', text: text).click
    click_update_merge_requests_button
126 127 128 129 130 131 132
  end

  def click_update_merge_requests_button
    find('.update_selected_issues').click
    wait_for_ajax
  end
end