2014-09-02 18:07:02 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe LabelsHelper do
|
2018-03-17 18:26:18 +05:30
|
|
|
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-10-12 21:52:04 +05:30
|
|
|
subject { show_label_issuables_link?(label.present(issuable_subject: nil), issuables_type) }
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
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
|
|
|
|
set(:group) { create(:group) }
|
|
|
|
let(:label) { create(:group_label, group: group, title: 'bug') }
|
|
|
|
|
|
|
|
context 'when asking for an issue link' do
|
2019-10-12 21:52:04 +05:30
|
|
|
it_behaves_like 'a valid response to show_label_issuables_link?', :issues, true, true
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
context 'when asking for a merge requests link' do
|
2019-10-12 21:52:04 +05:30
|
|
|
it_behaves_like 'a valid response to show_label_issuables_link?', :merge_requests, true, true
|
2018-03-17 18:26:18 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
describe 'link_to_label' do
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:project) { create(:project) }
|
2016-04-02 18:10:28 +05:30
|
|
|
let(:label) { create(:label, project: project) }
|
2019-07-31 22:56:46 +05:30
|
|
|
let(:subject) { nil }
|
|
|
|
let(:label_presenter) { label.present(issuable_subject: subject) }
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
context 'without subject' do
|
|
|
|
it "uses the label's project" do
|
2019-07-31 22:56:46 +05:30
|
|
|
expect(link_to_label(label_presenter)).to match %r{<a href="/#{label.project.full_path}/issues\?label_name%5B%5D=#{label.name}">.*</a>}
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
context 'with a project as subject' do
|
|
|
|
let(:namespace) { build(:namespace, name: 'foo3') }
|
2019-07-31 22:56:46 +05:30
|
|
|
let(:subject) { build(:project, namespace: namespace, name: 'bar3') }
|
2016-11-03 12:29:30 +05:30
|
|
|
|
|
|
|
it 'links to project issues page' do
|
2019-07-31 22:56:46 +05:30
|
|
|
expect(link_to_label(label_presenter)).to match %r{<a href="/foo3/bar3/issues\?label_name%5B%5D=#{label.name}">.*</a>}
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
context 'with a group as subject' do
|
2019-07-31 22:56:46 +05:30
|
|
|
let(:subject) { build(:group, name: 'bar') }
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2016-11-03 12:29:30 +05:30
|
|
|
it 'links to group issues page' do
|
2019-07-31 22:56:46 +05:30
|
|
|
expect(link_to_label(label_presenter)).to match %r{<a href="/groups/bar/-/issues\?label_name%5B%5D=#{label.name}">.*</a>}
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2016-04-02 18:10:28 +05:30
|
|
|
context 'with a type argument' do
|
|
|
|
['issue', :issue, 'merge_request', :merge_request].each do |type|
|
|
|
|
context "set to #{type}" do
|
|
|
|
it 'links to correct page' do
|
2019-07-31 22:56:46 +05:30
|
|
|
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>}
|
2016-04-02 18:10:28 +05:30
|
|
|
end
|
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
context 'with a tooltip argument' do
|
|
|
|
context 'set to false' do
|
|
|
|
it 'does not include the has-tooltip class' do
|
2019-07-31 22:56:46 +05:30
|
|
|
expect(link_to_label(label_presenter, tooltip: false)).not_to match /has-tooltip/
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
context 'with block' do
|
|
|
|
it 'passes the block to link_to' do
|
2019-07-31 22:56:46 +05:30
|
|
|
link = link_to_label(label_presenter) { 'Foo' }
|
2015-09-11 14:41:01 +05:30
|
|
|
expect(link).to match('Foo')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without block' do
|
|
|
|
it 'uses render_colored_label as the link content' do
|
2017-09-10 17:25:29 +05:30
|
|
|
expect(self).to receive(:render_colored_label)
|
2019-07-31 22:56:46 +05:30
|
|
|
.with(label_presenter, tooltip: true).and_return('Foo')
|
|
|
|
expect(link_to_label(label_presenter)).to match('Foo')
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'text_color_for_bg' do
|
|
|
|
it 'uses light text on dark backgrounds' do
|
|
|
|
expect(text_color_for_bg('#222E2E')).to eq('#FFFFFF')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'uses dark text on light backgrounds' do
|
|
|
|
expect(text_color_for_bg('#EEEEEE')).to eq('#333333')
|
|
|
|
end
|
2016-04-02 18:10:28 +05:30
|
|
|
|
|
|
|
it 'supports RGB triplets' do
|
|
|
|
expect(text_color_for_bg('#FFF')).to eq '#333333'
|
|
|
|
expect(text_color_for_bg('#000')).to eq '#FFFFFF'
|
|
|
|
end
|
2015-09-11 14:41:01 +05:30
|
|
|
end
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
describe 'create_label_title' do
|
|
|
|
set(:group) { create(:group) }
|
|
|
|
|
|
|
|
context 'with a group as subject' do
|
|
|
|
it 'returns "Create group label"' do
|
|
|
|
expect(create_label_title(group)).to eq 'Create group label'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a project as subject' do
|
|
|
|
set(:project) { create(:project, namespace: group) }
|
|
|
|
|
|
|
|
it 'returns "Create project label"' do
|
|
|
|
expect(create_label_title(project)).to eq 'Create project label'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with no subject' do
|
|
|
|
it 'returns "Create new label"' do
|
|
|
|
expect(create_label_title(nil)).to eq 'Create new label'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'manage_labels_title' do
|
|
|
|
set(:group) { create(:group) }
|
|
|
|
|
|
|
|
context 'with a group as subject' do
|
|
|
|
it 'returns "Manage group labels"' do
|
|
|
|
expect(manage_labels_title(group)).to eq 'Manage group labels'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a project as subject' do
|
|
|
|
set(:project) { create(:project, namespace: group) }
|
|
|
|
|
|
|
|
it 'returns "Manage project labels"' do
|
|
|
|
expect(manage_labels_title(project)).to eq 'Manage project labels'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with no subject' do
|
|
|
|
it 'returns "Manage labels"' do
|
|
|
|
expect(manage_labels_title(nil)).to eq 'Manage labels'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'view_labels_title' do
|
|
|
|
set(:group) { create(:group) }
|
|
|
|
|
|
|
|
context 'with a group as subject' do
|
|
|
|
it 'returns "View group labels"' do
|
|
|
|
expect(view_labels_title(group)).to eq 'View group labels'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with a project as subject' do
|
|
|
|
set(:project) { create(:project, namespace: group) }
|
|
|
|
|
|
|
|
it 'returns "View project labels"' do
|
|
|
|
expect(view_labels_title(project)).to eq 'View project labels'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'with no subject' do
|
|
|
|
it 'returns "View labels"' do
|
|
|
|
expect(view_labels_title(nil)).to eq 'View labels'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-12-13 13:39:08 +05:30
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
it 'links to the project labels page' do
|
|
|
|
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-07-07 11:18:12 +05:30
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
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-07-07 11:18:12 +05:30
|
|
|
it 'sorts labels alphabetically' do
|
2019-07-31 22:56:46 +05:30
|
|
|
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
|
2019-07-07 11:18:12 +05:30
|
|
|
|
2019-07-31 22:56:46 +05:30
|
|
|
it 'returns an array of label presenters' do
|
|
|
|
expect(presented_labels_sorted_by_title(labels, nil))
|
|
|
|
.to all(be_a(LabelPresenter))
|
2019-07-07 11:18:12 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'label_from_hash' do
|
|
|
|
it 'builds a group label with whitelisted attributes' do
|
|
|
|
label = label_from_hash({ title: 'foo', color: 'bar', id: 1, group_id: 1 })
|
|
|
|
|
|
|
|
expect(label).to be_a(GroupLabel)
|
|
|
|
expect(label.id).to be_nil
|
|
|
|
expect(label.title).to eq('foo')
|
|
|
|
expect(label.color).to eq('bar')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'builds a project label with whitelisted attributes' do
|
|
|
|
label = label_from_hash({ title: 'foo', color: 'bar', id: 1, project_id: 1 })
|
|
|
|
|
|
|
|
expect(label).to be_a(ProjectLabel)
|
|
|
|
expect(label.id).to be_nil
|
|
|
|
expect(label.title).to eq('foo')
|
|
|
|
expect(label.color).to eq('bar')
|
|
|
|
end
|
|
|
|
end
|
2019-07-31 22:56:46 +05:30
|
|
|
|
|
|
|
describe '#label_status_tooltip' do
|
|
|
|
let(:status) { 'unsubscribed'.inquiry }
|
|
|
|
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-09-04 21:01:54 +05:30
|
|
|
|
|
|
|
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
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|