2019-03-28 10:33:06 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-01 03:50:53 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 09:08:32 +00:00
|
|
|
RSpec.describe MergeRequestsHelper do
|
2017-09-29 08:04:50 +00:00
|
|
|
include ProjectForksHelper
|
2017-12-01 19:08:30 +00:00
|
|
|
|
2015-12-17 22:08:14 +00:00
|
|
|
describe '#format_mr_branch_names' do
|
|
|
|
describe 'within the same project' do
|
2015-10-01 03:50:53 +00:00
|
|
|
let(:merge_request) { create(:merge_request) }
|
2019-12-17 18:07:48 +00:00
|
|
|
|
2015-10-01 03:50:53 +00:00
|
|
|
subject { format_mr_branch_names(merge_request) }
|
|
|
|
|
|
|
|
it { is_expected.to eq([merge_request.source_branch, merge_request.target_branch]) }
|
|
|
|
end
|
|
|
|
|
2015-12-17 22:08:14 +00:00
|
|
|
describe 'within different projects' do
|
2017-08-02 19:55:11 +00:00
|
|
|
let(:project) { create(:project) }
|
2017-09-29 08:04:50 +00:00
|
|
|
let(:forked_project) { fork_project(project) }
|
|
|
|
let(:merge_request) { create(:merge_request, source_project: forked_project, target_project: project) }
|
2015-10-01 03:50:53 +00:00
|
|
|
subject { format_mr_branch_names(merge_request) }
|
2019-10-18 11:11:44 +00:00
|
|
|
|
2017-09-29 08:04:50 +00:00
|
|
|
let(:source_title) { "#{forked_project.full_path}:#{merge_request.source_branch}" }
|
2017-07-20 09:34:09 +00:00
|
|
|
let(:target_title) { "#{project.full_path}:#{merge_request.target_branch}" }
|
2015-10-01 03:50:53 +00:00
|
|
|
|
|
|
|
it { is_expected.to eq([source_title, target_title]) }
|
|
|
|
end
|
|
|
|
end
|
2017-12-01 19:08:30 +00:00
|
|
|
|
|
|
|
describe '#tab_link_for' do
|
|
|
|
let(:merge_request) { create(:merge_request, :simple) }
|
2020-09-02 15:10:54 +00:00
|
|
|
let(:options) { {} }
|
2017-12-01 19:08:30 +00:00
|
|
|
|
|
|
|
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-06-30 13:17:46 +00:00
|
|
|
is_expected.not_to match(/data-toggle="tabvue"/)
|
2017-12-01 19:08:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-01-05 00:10:20 +00:00
|
|
|
|
|
|
|
describe '#user_merge_requests_counts' do
|
|
|
|
let(:user) do
|
|
|
|
double(
|
|
|
|
assigned_open_merge_requests_count: 1,
|
2022-03-02 09:13:50 +00:00
|
|
|
review_requested_open_merge_requests_count: 2,
|
|
|
|
attention_requested_open_merge_requests_count: 3
|
2021-01-05 00:10:20 +00:00
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { helper.user_merge_requests_counts }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(helper).to receive(:current_user).and_return(user)
|
|
|
|
end
|
|
|
|
|
2022-03-02 09:13:50 +00:00
|
|
|
describe 'mr_attention_requests disabled' do
|
|
|
|
before do
|
2022-05-05 21:09:10 +00:00
|
|
|
allow(user).to receive(:mr_attention_requests_enabled?).and_return(false)
|
2022-03-02 09:13:50 +00:00
|
|
|
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
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'mr_attention_requests enabled' do
|
2022-05-05 21:09:10 +00:00
|
|
|
before do
|
|
|
|
allow(user).to receive(:mr_attention_requests_enabled?).and_return(true)
|
|
|
|
end
|
|
|
|
|
2022-03-02 09:13:50 +00:00
|
|
|
it "returns assigned, review requested, attention requests 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,
|
|
|
|
attention_requested_count: user.attention_requested_open_merge_requests_count,
|
|
|
|
total: user.attention_requested_open_merge_requests_count
|
|
|
|
)
|
|
|
|
end
|
2021-01-05 00:10:20 +00:00
|
|
|
end
|
|
|
|
end
|
2021-03-02 06:10:53 +00:00
|
|
|
|
|
|
|
describe '#reviewers_label' do
|
|
|
|
let(:merge_request) { build_stubbed(:merge_request) }
|
|
|
|
let(:reviewer1) { build_stubbed(:user, name: 'Jane Doe') }
|
|
|
|
let(:reviewer2) { build_stubbed(:user, name: 'John Doe') }
|
|
|
|
|
|
|
|
before do
|
|
|
|
allow(merge_request).to receive(:reviewers).and_return(reviewers)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when multiple reviewers exist' do
|
|
|
|
let(:reviewers) { [reviewer1, reviewer2] }
|
|
|
|
|
|
|
|
it 'returns reviewer label with reviewer names' do
|
|
|
|
expect(helper.reviewers_label(merge_request)).to eq("Reviewers: Jane Doe and John Doe")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns reviewer label only with include_value: false' do
|
|
|
|
expect(helper.reviewers_label(merge_request, include_value: false)).to eq("Reviewers")
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when the name contains a URL' do
|
|
|
|
let(:reviewers) { [build_stubbed(:user, name: 'www.gitlab.com')] }
|
|
|
|
|
|
|
|
it 'returns sanitized name' do
|
|
|
|
expect(helper.reviewers_label(merge_request)).to eq("Reviewer: www_gitlab_com")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when one reviewer exists' do
|
|
|
|
let(:reviewers) { [reviewer1] }
|
|
|
|
|
|
|
|
it 'returns reviewer label with no names' do
|
|
|
|
expect(helper.reviewers_label(merge_request)).to eq("Reviewer: Jane Doe")
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns reviewer label only with include_value: false' do
|
|
|
|
expect(helper.reviewers_label(merge_request, include_value: false)).to eq("Reviewer")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when no reviewers exist' do
|
|
|
|
let(:reviewers) { [] }
|
|
|
|
|
|
|
|
it 'returns reviewer label with no names' do
|
|
|
|
expect(helper.reviewers_label(merge_request)).to eq("Reviewers: ")
|
|
|
|
end
|
|
|
|
it 'returns reviewer label only with include_value: false' do
|
|
|
|
expect(helper.reviewers_label(merge_request, include_value: false)).to eq("Reviewers")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-10-01 03:50:53 +00:00
|
|
|
end
|