2019-07-07 11:18:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-24 18:46:33 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe MergeRequestsHelper do
|
2018-03-17 18:26:18 +05:30
|
|
|
include ActionView::Helpers::UrlHelper
|
|
|
|
include ProjectForksHelper
|
|
|
|
|
2020-01-01 13:55:28 +05:30
|
|
|
describe '#state_name_with_icon' do
|
|
|
|
using RSpec::Parameterized::TableSyntax
|
|
|
|
|
|
|
|
let(:merge_request) { MergeRequest.new }
|
|
|
|
|
|
|
|
where(:state, :expected_name, :expected_icon) do
|
|
|
|
:merged? | 'Merged' | 'git-merge'
|
|
|
|
:closed? | 'Closed' | 'close'
|
|
|
|
:opened? | 'Open' | 'issue-open-m'
|
|
|
|
end
|
|
|
|
|
|
|
|
with_them do
|
|
|
|
before do
|
|
|
|
allow(merge_request).to receive(state).and_return(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns name and icon' do
|
|
|
|
name, icon = helper.state_name_with_icon(merge_request)
|
|
|
|
|
|
|
|
expect(name).to eq(expected_name)
|
|
|
|
expect(icon).to eq(expected_icon)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
describe '#format_mr_branch_names' do
|
|
|
|
describe 'within the same project' do
|
2015-10-24 18:46:33 +05:30
|
|
|
let(:merge_request) { create(:merge_request) }
|
2020-01-01 13:55:28 +05:30
|
|
|
|
2015-10-24 18:46:33 +05:30
|
|
|
subject { format_mr_branch_names(merge_request) }
|
|
|
|
|
|
|
|
it { is_expected.to eq([merge_request.source_branch, merge_request.target_branch]) }
|
|
|
|
end
|
|
|
|
|
2015-12-23 02:04:40 +05:30
|
|
|
describe 'within different projects' do
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:project) { create(:project) }
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:forked_project) { fork_project(project) }
|
|
|
|
let(:merge_request) { create(:merge_request, source_project: forked_project, target_project: project) }
|
2015-10-24 18:46:33 +05:30
|
|
|
subject { format_mr_branch_names(merge_request) }
|
2019-12-21 20:55:43 +05:30
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
let(:source_title) { "#{forked_project.full_path}:#{merge_request.source_branch}" }
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:target_title) { "#{project.full_path}:#{merge_request.target_branch}" }
|
2015-10-24 18:46:33 +05:30
|
|
|
|
|
|
|
it { is_expected.to eq([source_title, target_title]) }
|
|
|
|
end
|
|
|
|
end
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
describe '#tab_link_for' do
|
|
|
|
let(:merge_request) { create(:merge_request, :simple) }
|
2020-11-24 15:15:51 +05:30
|
|
|
let(:options) { {} }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
subject { tab_link_for(merge_request, :show, options) { 'Discussion' } }
|
|
|
|
|
|
|
|
describe 'supports the :force_link option' do
|
|
|
|
let(:options) { { force_link: true } }
|
|
|
|
|
|
|
|
it 'removes the data-toggle attributes' do
|
2018-11-08 19:23:39 +05:30
|
|
|
is_expected.not_to match(/data-toggle="tabvue"/)
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-03-08 18:12:59 +05:30
|
|
|
|
|
|
|
describe '#user_merge_requests_counts' do
|
|
|
|
let(:user) do
|
|
|
|
double(
|
|
|
|
assigned_open_merge_requests_count: 1,
|
|
|
|
review_requested_open_merge_requests_count: 2
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { helper.user_merge_requests_counts }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:current_user).and_return(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns assigned, review requested and total merge request counts" do
|
|
|
|
expect(subject).to eq(
|
|
|
|
assigned: user.assigned_open_merge_requests_count,
|
|
|
|
review_requested: user.review_requested_open_merge_requests_count,
|
|
|
|
total: user.assigned_open_merge_requests_count + user.review_requested_open_merge_requests_count
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when merge_request_reviewers is disabled' do
|
|
|
|
before do
|
|
|
|
stub_feature_flags(merge_request_reviewers: false)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns review_requested as 0' do
|
|
|
|
expect(subject[:review_requested]).to eq(0)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|