BigW Consortium Gitlab

label_parser_spec.rb 1.09 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11
require 'spec_helper'

describe Banzai::ReferenceParser::LabelParser, lib: true do
  include ReferenceParserHelpers

  let(:project) { create(:empty_project, :public) }
  let(:user) { create(:user) }
  let(:label) { create(:label, project: project) }
  subject { described_class.new(project, user) }
  let(:link) { empty_html_link }

12 13 14 15 16 17 18 19
  describe '#nodes_visible_to_user' do
    context 'when the link has a data-issue attribute' do
      before { link['data-label'] = label.id.to_s }

      it_behaves_like "referenced feature visibility", "issues", "merge_requests"
    end
  end

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
  describe '#referenced_by' do
    describe 'when the link has a data-label attribute' do
      context 'using an existing label ID' do
        it 'returns an Array of labels' do
          link['data-label'] = label.id.to_s

          expect(subject.referenced_by([link])).to eq([label])
        end
      end

      context 'using a non-existing label ID' do
        it 'returns an empty Array' do
          link['data-label'] = ''

          expect(subject.referenced_by([link])).to eq([])
        end
      end
    end
  end
end