summaryrefslogtreecommitdiff
path: root/spec/features/merge_request/user_approves_spec.rb
blob: 4f7bcb58551be9528cf43f9d78eaeac9cfe05e96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe 'Merge request > User approves', :js do
  let(:user) { create(:user) }
  let(:project) { create(:project, :public, :repository) }
  let(:merge_request) { create(:merge_request, source_project: project) }

  before do
    project.add_developer(user)

    sign_in(user)

    visit project_merge_request_path(project, merge_request)
  end

  it 'approves merge request' do
    click_approval_button('Approve')
    expect(page).to have_content('Approved by you')

    verify_approvals_count_on_index!

    click_approval_button('Revoke approval')
    expect(page).to have_content('Approval is optional')
  end

  def verify_approvals_count_on_index!
    visit(project_merge_requests_path(project, state: :all))
    expect(page.all('li').any? { |item| item["title"] == "1 approver (you've approved)"}).to be true
    visit project_merge_request_path(project, merge_request)
  end

  def click_approval_button(action)
    page.within('.mr-state-widget') do
      click_button(action)
    end

    wait_for_requests
  end
end