2019-09-30 08:06:01 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2014-04-11 13:06:27 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 05:08:32 -04:00
|
|
|
RSpec.describe LabelsHelper do
|
2017-03-30 06:39:02 -04:00
|
|
|
describe '#show_label_issuables_link?' do
|
|
|
|
shared_examples 'a valid response to show_label_issuables_link?' do |issuables_type, when_enabled = true, when_disabled = false|
|
|
|
|
context "when asking for a #{issuables_type} link" do
|
2019-07-23 05:30:25 -04:00
|
|
|
subject { show_label_issuables_link?(label.present(issuable_subject: nil), issuables_type) }
|
2017-03-30 06:39:02 -04:00
|
|
|
|
|
|
|
context "when #{issuables_type} are enabled for the project" do
|
|
|
|
let(:project) { create(:project, "#{issuables_type}_access_level": ProjectFeature::ENABLED) }
|
|
|
|
|
|
|
|
it { is_expected.to be(when_enabled) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when #{issuables_type} are disabled for the project" do
|
|
|
|
let(:project) { create(:project, :public, "#{issuables_type}_access_level": ProjectFeature::DISABLED) }
|
|
|
|
|
|
|
|
it { is_expected.to be(when_disabled) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a project label' do
|
|
|
|
let(:label) { create(:label, project: project, title: 'bug') }
|
|
|
|
|
|
|
|
context 'when asking for an issue link' do
|
|
|
|
it_behaves_like 'a valid response to show_label_issuables_link?', :issues
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when asking for a merge requests link' do
|
|
|
|
it_behaves_like 'a valid response to show_label_issuables_link?', :merge_requests
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a group label' do
|
2020-02-18 10:08:51 -05:00
|
|
|
let_it_be(:group) { create(:group) }
|
2021-04-19 14:09:09 -04:00
|
|
|
|
2017-03-30 06:39:02 -04:00
|
|
|
let(:label) { create(:group_label, group: group, title: 'bug') }
|
|
|
|
|
|
|
|
context 'when asking for an issue link' do
|
2019-07-23 05:30:25 -04:00
|
|
|
it_behaves_like 'a valid response to show_label_issuables_link?', :issues, true, true
|
2017-03-30 06:39:02 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when asking for a merge requests link' do
|
2019-07-23 05:30:25 -04:00
|
|
|
it_behaves_like 'a valid response to show_label_issuables_link?', :merge_requests, true, true
|
2017-03-30 06:39:02 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-05-21 23:40:25 -04:00
|
|
|
describe 'link_to_label' do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2015-12-18 08:20:15 -05:00
|
|
|
let(:label) { create(:label, project: project) }
|
2019-04-23 15:58:20 -04:00
|
|
|
let(:subject) { nil }
|
|
|
|
let(:label_presenter) { label.present(issuable_subject: subject) }
|
2015-05-21 23:40:25 -04:00
|
|
|
|
2016-09-26 18:58:36 -04:00
|
|
|
context 'without subject' do
|
|
|
|
it "uses the label's project" do
|
2020-03-02 10:08:01 -05:00
|
|
|
expect(link_to_label(label_presenter)).to match %r{<a.*href="/#{label.project.full_path}/-/issues\?label_name%5B%5D=#{label.name}".*>.*</a>}m
|
2015-05-21 23:40:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-26 18:58:36 -04:00
|
|
|
context 'with a project as subject' do
|
|
|
|
let(:namespace) { build(:namespace, name: 'foo3') }
|
2019-04-23 15:58:20 -04:00
|
|
|
let(:subject) { build(:project, namespace: namespace, name: 'bar3') }
|
2016-09-26 18:58:36 -04:00
|
|
|
|
|
|
|
it 'links to project issues page' do
|
2020-03-02 10:08:01 -05:00
|
|
|
expect(link_to_label(label_presenter)).to match %r{<a.*href="/foo3/bar3/-/issues\?label_name%5B%5D=#{label.name}".*>.*</a>}m
|
2015-05-21 23:40:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-09-26 18:58:36 -04:00
|
|
|
context 'with a group as subject' do
|
2019-04-23 15:58:20 -04:00
|
|
|
let(:subject) { build(:group, name: 'bar') }
|
2015-05-21 23:40:25 -04:00
|
|
|
|
2016-09-26 18:58:36 -04:00
|
|
|
it 'links to group issues page' do
|
2020-02-25 10:08:50 -05:00
|
|
|
expect(link_to_label(label_presenter)).to match %r{<a.*href="/groups/bar/-/issues\?label_name%5B%5D=#{label.name}".*>.*</a>}m
|
2015-05-21 23:40:25 -04:00
|
|
|
end
|
2015-12-18 08:20:15 -05:00
|
|
|
end
|
2015-05-21 23:40:25 -04:00
|
|
|
|
2015-12-18 08:20:15 -05:00
|
|
|
context 'with a type argument' do
|
2020-03-02 10:08:01 -05:00
|
|
|
['issue', :issue, 'merge_request', :merge_request].each do |type|
|
2020-01-20 19:08:46 -05:00
|
|
|
context "set to #{type}" do
|
|
|
|
it 'links to correct page' do
|
2020-02-25 10:08:50 -05:00
|
|
|
expect(link_to_label(label_presenter, type: type)).to match %r{<a.*href="/#{label.project.full_path}/-/#{type.to_s.pluralize}\?label_name%5B%5D=#{label.name}".*>.*</a>}m
|
2020-01-20 19:08:46 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-05-21 23:40:25 -04:00
|
|
|
end
|
|
|
|
|
2016-03-18 15:26:30 -04:00
|
|
|
context 'with a tooltip argument' do
|
|
|
|
context 'set to false' do
|
2016-03-20 15:01:46 -04:00
|
|
|
it 'does not include the has-tooltip class' do
|
2019-04-23 15:58:20 -04:00
|
|
|
expect(link_to_label(label_presenter, tooltip: false)).not_to match /has-tooltip/
|
2016-03-18 15:26:30 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-05-21 23:40:25 -04:00
|
|
|
context 'with block' do
|
|
|
|
it 'passes the block to link_to' do
|
2019-04-23 15:58:20 -04:00
|
|
|
link = link_to_label(label_presenter) { 'Foo' }
|
2015-05-21 23:40:25 -04:00
|
|
|
expect(link).to match('Foo')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without block' do
|
|
|
|
it 'uses render_colored_label as the link content' do
|
2017-06-21 09:48:12 -04:00
|
|
|
expect(self).to receive(:render_colored_label)
|
2020-02-25 10:08:50 -05:00
|
|
|
.with(label_presenter).and_return('Foo')
|
2019-04-23 15:58:20 -04:00
|
|
|
expect(link_to_label(label_presenter)).to match('Foo')
|
2015-05-21 23:40:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'text_color_for_bg' do
|
|
|
|
it 'uses light text on dark backgrounds' do
|
2022-03-02 19:20:18 -05:00
|
|
|
expect(text_color_for_bg('#222E2E')).to be_color('#FFFFFF')
|
2015-05-21 23:40:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'uses dark text on light backgrounds' do
|
2022-03-02 19:20:18 -05:00
|
|
|
expect(text_color_for_bg('#EEEEEE')).to be_color('#333333')
|
2015-05-21 23:40:25 -04:00
|
|
|
end
|
2016-01-24 18:06:46 -05:00
|
|
|
|
|
|
|
it 'supports RGB triplets' do
|
2022-03-02 19:20:18 -05:00
|
|
|
expect(text_color_for_bg('#FFF')).to be_color '#333333'
|
|
|
|
expect(text_color_for_bg('#000')).to be_color '#FFFFFF'
|
2016-01-24 18:06:46 -05:00
|
|
|
end
|
2015-05-21 23:40:25 -04:00
|
|
|
end
|
2018-03-08 07:39:32 -05:00
|
|
|
|
|
|
|
describe 'create_label_title' do
|
2020-02-18 10:08:51 -05:00
|
|
|
let_it_be(:group) { create(:group) }
|
2018-03-08 07:39:32 -05:00
|
|
|
|
|
|
|
context 'with a group as subject' do
|
|
|
|
it 'returns "Create group label"' do
|
2019-12-12 07:07:33 -05:00
|
|
|
expect(create_label_title(group)).to eq _('Create group label')
|
2018-03-08 07:39:32 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a project as subject' do
|
2020-02-18 10:08:51 -05:00
|
|
|
let_it_be(:project) { create(:project, namespace: group) }
|
2018-03-08 07:39:32 -05:00
|
|
|
|
|
|
|
it 'returns "Create project label"' do
|
2019-12-12 07:07:33 -05:00
|
|
|
expect(create_label_title(project)).to eq _('Create project label')
|
2018-03-08 07:39:32 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with no subject' do
|
|
|
|
it 'returns "Create new label"' do
|
2019-12-12 07:07:33 -05:00
|
|
|
expect(create_label_title(nil)).to eq _('Create new label')
|
2018-03-08 07:39:32 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'manage_labels_title' do
|
2020-02-18 10:08:51 -05:00
|
|
|
let_it_be(:group) { create(:group) }
|
2018-03-08 07:39:32 -05:00
|
|
|
|
|
|
|
context 'with a group as subject' do
|
|
|
|
it 'returns "Manage group labels"' do
|
2019-12-12 07:07:33 -05:00
|
|
|
expect(manage_labels_title(group)).to eq _('Manage group labels')
|
2018-03-08 07:39:32 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a project as subject' do
|
2020-02-18 10:08:51 -05:00
|
|
|
let_it_be(:project) { create(:project, namespace: group) }
|
2018-03-08 07:39:32 -05:00
|
|
|
|
|
|
|
it 'returns "Manage project labels"' do
|
2019-12-12 07:07:33 -05:00
|
|
|
expect(manage_labels_title(project)).to eq _('Manage project labels')
|
2018-03-08 07:39:32 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with no subject' do
|
|
|
|
it 'returns "Manage labels"' do
|
2019-12-12 07:07:33 -05:00
|
|
|
expect(manage_labels_title(nil)).to eq _('Manage labels')
|
2018-03-08 07:39:32 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'view_labels_title' do
|
2020-02-18 10:08:51 -05:00
|
|
|
let_it_be(:group) { create(:group) }
|
2018-03-08 07:39:32 -05:00
|
|
|
|
|
|
|
context 'with a group as subject' do
|
|
|
|
it 'returns "View group labels"' do
|
2019-12-12 07:07:33 -05:00
|
|
|
expect(view_labels_title(group)).to eq _('View group labels')
|
2018-03-08 07:39:32 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a project as subject' do
|
2020-02-18 10:08:51 -05:00
|
|
|
let_it_be(:project) { create(:project, namespace: group) }
|
2018-03-08 07:39:32 -05:00
|
|
|
|
|
|
|
it 'returns "View project labels"' do
|
2019-12-12 07:07:33 -05:00
|
|
|
expect(view_labels_title(project)).to eq _('View project labels')
|
2018-03-08 07:39:32 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with no subject' do
|
|
|
|
it 'returns "View labels"' do
|
2019-12-12 07:07:33 -05:00
|
|
|
expect(view_labels_title(nil)).to eq _('View labels')
|
2018-03-08 07:39:32 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-10-31 10:47:53 -04:00
|
|
|
|
|
|
|
describe 'labels_filter_path' do
|
|
|
|
let(:group) { create(:group) }
|
|
|
|
let(:project) { create(:project) }
|
|
|
|
|
|
|
|
it 'links to the dashboard labels page' do
|
|
|
|
expect(labels_filter_path).to eq(dashboard_labels_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'links to the group labels page' do
|
|
|
|
assign(:group, group)
|
|
|
|
|
|
|
|
expect(helper.labels_filter_path).to eq(group_labels_path(group))
|
|
|
|
end
|
|
|
|
|
2018-11-01 11:26:59 -04:00
|
|
|
it 'links to the project labels page' do
|
2018-10-31 10:47:53 -04:00
|
|
|
assign(:project, project)
|
|
|
|
|
|
|
|
expect(helper.labels_filter_path).to eq(project_labels_path(project))
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'supports json format' do
|
|
|
|
expect(labels_filter_path(format: :json)).to eq(dashboard_labels_path(format: :json))
|
|
|
|
end
|
|
|
|
end
|
2019-02-21 11:06:14 -05:00
|
|
|
|
2019-04-23 15:58:20 -04:00
|
|
|
describe 'presented_labels_sorted_by_title' do
|
|
|
|
let(:labels) do
|
|
|
|
[build(:label, title: 'a'),
|
|
|
|
build(:label, title: 'B'),
|
|
|
|
build(:label, title: 'c'),
|
|
|
|
build(:label, title: 'D')]
|
|
|
|
end
|
|
|
|
|
2019-02-21 11:06:14 -05:00
|
|
|
it 'sorts labels alphabetically' do
|
2019-04-23 15:58:20 -04:00
|
|
|
sorted_ids = presented_labels_sorted_by_title(labels, nil).map(&:id)
|
|
|
|
|
|
|
|
expect(sorted_ids)
|
|
|
|
.to match_array([labels[1].id, labels[3].id, labels[0].id, labels[2].id])
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns an array of label presenters' do
|
|
|
|
expect(presented_labels_sorted_by_title(labels, nil))
|
|
|
|
.to all(be_a(LabelPresenter))
|
2019-02-21 11:06:14 -05:00
|
|
|
end
|
|
|
|
end
|
2019-04-04 09:34:55 -04:00
|
|
|
|
2019-05-28 06:05:20 -04:00
|
|
|
describe '#label_status_tooltip' do
|
|
|
|
let(:status) { 'unsubscribed'.inquiry }
|
2019-12-17 13:07:48 -05:00
|
|
|
|
2019-05-28 06:05:20 -04:00
|
|
|
subject { label_status_tooltip(label.present(issuable_subject: nil), status) }
|
|
|
|
|
|
|
|
context 'with a project label' do
|
|
|
|
let(:label) { create(:label, title: 'bug') }
|
|
|
|
|
|
|
|
it { is_expected.to eq('Subscribe at project level') }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a group label' do
|
|
|
|
let(:label) { create(:group_label, title: 'bug') }
|
|
|
|
|
|
|
|
it { is_expected.to eq('Subscribe at group level') }
|
|
|
|
end
|
|
|
|
end
|
2019-07-15 07:29:56 -04:00
|
|
|
|
|
|
|
describe '#label_tooltip_title' do
|
|
|
|
let(:html) { '<img src="example.png">This is an image</img>' }
|
|
|
|
let(:label_with_html_content) { create(:label, title: 'test', description: html) }
|
|
|
|
|
|
|
|
it 'removes HTML' do
|
|
|
|
tooltip = label_tooltip_title(label_with_html_content)
|
|
|
|
expect(tooltip).to eq('This is an image')
|
|
|
|
end
|
|
|
|
end
|
2020-10-15 14:08:43 -04:00
|
|
|
|
|
|
|
describe '#show_labels_full_path?' do
|
|
|
|
let_it_be(:group) { create(:group) }
|
|
|
|
let_it_be(:subgroup) { create(:group, parent: group) }
|
|
|
|
let_it_be(:project) { create(:project, group: group) }
|
|
|
|
|
|
|
|
context 'within a project' do
|
|
|
|
it 'returns truthy' do
|
|
|
|
expect(show_labels_full_path?(project, nil)).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'within a subgroup' do
|
|
|
|
it 'returns truthy' do
|
|
|
|
expect(show_labels_full_path?(nil, subgroup)).to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'within a group' do
|
|
|
|
it 'returns falsey' do
|
|
|
|
expect(show_labels_full_path?(nil, group)).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'within the admin area' do
|
|
|
|
it 'returns falsey' do
|
|
|
|
expect(show_labels_full_path?(nil, nil)).to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2014-04-11 13:06:27 -04:00
|
|
|
end
|