2014-04-11 13:06:27 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe LabelsHelper do
|
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) }
|
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
|
2017-07-20 05:34:09 -04:00
|
|
|
expect(link_to_label(label)).to match %r{<a href="/#{label.project.full_path}/issues\?label_name%5B%5D=#{label.name}">.*</a>}
|
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') }
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:another_project) { build(:project, namespace: namespace, name: 'bar3') }
|
2016-09-26 18:58:36 -04:00
|
|
|
|
|
|
|
it 'links to project issues page' do
|
|
|
|
expect(link_to_label(label, subject: another_project)).to match %r{<a href="/foo3/bar3/issues\?label_name%5B%5D=#{label.name}">.*</a>}
|
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
|
|
|
|
let(:group) { 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
|
2017-10-27 05:29:51 -04:00
|
|
|
expect(link_to_label(label, subject: group)).to match %r{<a href="/groups/bar/-/issues\?label_name%5B%5D=#{label.name}">.*</a>}
|
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
|
|
|
|
['issue', :issue, 'merge_request', :merge_request].each do |type|
|
|
|
|
context "set to #{type}" do
|
|
|
|
it 'links to correct page' do
|
2017-07-20 05:34:09 -04:00
|
|
|
expect(link_to_label(label, type: type)).to match %r{<a href="/#{label.project.full_path}/#{type.to_s.pluralize}\?label_name%5B%5D=#{label.name}">.*</a>}
|
2015-12-18 08:20:15 -05:00
|
|
|
end
|
|
|
|
end
|
2015-05-21 23:40:25 -04:00
|
|
|
end
|
|
|
|
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
|
|
|
|
expect(link_to_label(label, tooltip: false)).not_to match %r{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
|
|
|
|
link = link_to_label(label) { 'Foo' }
|
|
|
|
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)
|
|
|
|
.with(label, tooltip: true).and_return('Foo')
|
2015-05-21 23:40:25 -04:00
|
|
|
expect(link_to_label(label)).to match('Foo')
|
|
|
|
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-01-24 18:06:46 -05:00
|
|
|
|
|
|
|
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-05-21 23:40:25 -04:00
|
|
|
end
|
2014-04-11 13:06:27 -04:00
|
|
|
end
|