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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Issuables Close/Reopen/Report toggle', feature_category: :code_review_workflow do
include IssuablesHelper
let(:user) { create(:user) }
context 'on a merge request' do
let(:container) { find('.detail-page-header-actions') }
let(:project) { create(:project, :repository) }
let(:issuable) { create(:merge_request, source_project: project) }
before do
project.add_maintainer(user)
login_as user
end
context 'when user has permission to update', :js do
before do
visit project_merge_request_path(project, issuable)
end
context 'close/reopen/report toggle' do
it 'opens a dropdown when toggle is clicked' do
find('#new-actions-header-dropdown button').click
expect(container).to have_button("Close merge request")
expect(container).to have_button('Report abuse')
end
it 'links to Report Abuse' do
find('#new-actions-header-dropdown button').click
click_button 'Report abuse'
expect(page).to have_content('Report abuse to administrator')
end
end
context 'when the merge request is open' do
let(:issuable) { create(:merge_request, :opened, source_project: project) }
it 'shows the `Edit` and `Mark as draft` buttons' do
find('#new-actions-header-dropdown button').click
expect(container).to have_link('Edit')
expect(container).to have_button('Mark as draft')
expect(container).to have_button('Close merge request')
expect(container).to have_button('Report abuse')
expect(container).not_to have_button('Reopen merge request')
end
end
context 'when the merge request is closed' do
let(:issuable) { create(:merge_request, :closed, source_project: project) }
it 'shows both the `Edit` and `Reopen` button' do
find('#new-actions-header-dropdown button').click
expect(container).to have_link('Edit')
expect(container).to have_button('Report abuse')
expect(container).to have_button('Reopen merge request')
expect(container).not_to have_button('Close merge request')
end
context 'when the merge request author is the current user' do
let(:issuable) { create(:merge_request, :closed, source_project: project, author: user) }
it 'shows both the `Edit` and `Reopen` button' do
find('#new-actions-header-dropdown button').click
expect(container).to have_link('Edit')
expect(container).to have_button('Reopen merge request')
expect(container).not_to have_button('Close merge request')
expect(container).not_to have_button('Report abuse')
end
end
end
context 'when the merge request is merged' do
let(:issuable) { create(:merge_request, :merged, source_project: project) }
it 'shows only the `Edit` button' do
expect(container).to have_link(exact_text: 'Edit')
expect(container).not_to have_button('Report abuse')
expect(container).not_to have_button('Close merge request')
expect(container).not_to have_button('Reopen merge request')
end
context 'when the merge request author is the current user' do
let(:issuable) { create(:merge_request, :merged, source_project: project, author: user) }
it 'shows only the `Edit` button' do
expect(container).to have_link(exact_text: 'Edit')
expect(container).not_to have_button('Report abuse')
expect(container).not_to have_button('Close merge request')
expect(container).not_to have_button('Reopen merge request')
end
end
end
end
context 'when user doesnt have permission to update', :js do
let(:cant_project) { create(:project, :repository) }
let(:cant_issuable) { create(:merge_request, source_project: cant_project) }
before do
cant_project.add_reporter(user)
visit project_merge_request_path(cant_project, cant_issuable)
end
it 'only shows a `Report abuse` button' do
find('#new-actions-header-dropdown button').click
expect(container).to have_button('Report abuse')
expect(container).not_to have_button('Close merge request')
expect(container).not_to have_button('Reopen merge request')
expect(container).not_to have_link(exact_text: 'Edit')
end
end
end
end
|