Commit 55734453 authored by Kushal Pandya's avatar Kushal Pandya

Add helpers for labels dropdown

parent afd2d381
......@@ -174,6 +174,39 @@ module LabelsHelper
end
end
def create_label_title(subject)
case subject
when Group
_('Create group label')
when Project
_('Create project label')
else
_('Create new label')
end
end
def manage_labels_title(subject)
case subject
when Group
_('Manage group labels')
when Project
_('Manage project labels')
else
_('Manage labels')
end
end
def view_labels_title(subject)
case subject
when Group
_('View group labels')
when Project
_('View project labels')
else
_('View labels')
end
end
# Required for Banzai::Filter::LabelReferenceFilter
module_function :render_colored_label, :text_color_for_bg, :escape_once
end
......@@ -139,4 +139,76 @@ describe LabelsHelper do
expect(text_color_for_bg('#000')).to eq '#FFFFFF'
end
end
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
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment