labels_helper_spec.rb 2.51 KB
Newer Older
1 2 3
require 'spec_helper'

describe LabelsHelper do
Robert Speicher's avatar
Robert Speicher committed
4 5
  describe 'link_to_label' do
    let(:project) { create(:empty_project) }
6
    let(:label) { create(:label, project: project) }
Robert Speicher's avatar
Robert Speicher committed
7 8 9 10 11 12 13

    context 'with @project set' do
      before do
        @project = project
      end

      it 'uses the instance variable' do
14
        expect(link_to_label(label)).to match %r{<a href="/#{@project.to_reference}/issues\?label_name=#{label.name}"><span class="[\w\s\-]*has-tooltip".*</span></a>}
Robert Speicher's avatar
Robert Speicher committed
15 16 17 18 19
      end
    end

    context 'without @project set' do
      it "uses the label's project" do
20
        expect(link_to_label(label)).to match %r{<a href="/#{label.project.to_reference}/issues\?label_name=#{label.name}">.*</a>}
Robert Speicher's avatar
Robert Speicher committed
21 22 23
      end
    end

24 25
    context 'with a project argument' do
      let(:another_project) { double('project', namespace: 'foo3', to_param: 'bar3') }
Robert Speicher's avatar
Robert Speicher committed
26

27 28
      it 'links to merge requests page' do
        expect(link_to_label(label, project: another_project)).to match %r{<a href="/foo3/bar3/issues\?label_name=#{label.name}">.*</a>}
Robert Speicher's avatar
Robert Speicher committed
29
      end
30
    end
Robert Speicher's avatar
Robert Speicher committed
31

32 33 34 35 36 37 38
    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
            expect(link_to_label(label, type: type)).to match %r{<a href="/#{label.project.to_reference}/#{type.to_s.pluralize}\?label_name=#{label.name}">.*</a>}
          end
        end
Robert Speicher's avatar
Robert Speicher committed
39 40 41
      end
    end

Rémy Coutable's avatar
Rémy Coutable committed
42 43
    context 'with a tooltip argument' do
      context 'set to false' do
44 45
        it 'does not include the has-tooltip class' do
          expect(link_to_label(label, tooltip: false)).not_to match %r{has-tooltip}
Rémy Coutable's avatar
Rémy Coutable committed
46 47 48 49
        end
      end
    end

Robert Speicher's avatar
Robert Speicher committed
50 51 52 53 54 55 56 57 58 59
    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
        expect(self).to receive(:render_colored_label).
Rémy Coutable's avatar
Rémy Coutable committed
60
          with(label, tooltip: true).and_return('Foo')
Robert Speicher's avatar
Robert Speicher committed
61 62 63 64 65 66 67 68 69 70 71 72 73
        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
74 75 76 77 78

    it 'supports RGB triplets' do
      expect(text_color_for_bg('#FFF')).to eq '#333333'
      expect(text_color_for_bg('#000')).to eq '#FFFFFF'
    end
Robert Speicher's avatar
Robert Speicher committed
79
  end
80
end