summaryrefslogtreecommitdiff
path: root/spec/lib/banzai/reference_parser/alert_parser_spec.rb
blob: 0a9499fe6e4e88c30cd2df4ebe8d42f7ccff5db9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Banzai::ReferenceParser::AlertParser do
  include ReferenceParserHelpers

  let(:project) { create(:project, :public) }
  let(:user) { create(:user) }
  let(:alert) { create(:alert_management_alert, project: project) }

  subject { described_class.new(Banzai::RenderContext.new(project, user)) }

  let(:link) { empty_html_link }

  describe '#nodes_visible_to_user' do
    context 'when the link has a data-issue attribute' do
      before do
        link['data-alert'] = alert.id.to_s
      end

      it_behaves_like "referenced feature visibility", "issues", "merge_requests" do
        before do
          project.add_developer(user) if enable_user?
        end
      end
    end
  end

  describe '#referenced_by' do
    describe 'when the link has a data-alert attribute' do
      context 'using an existing alert ID' do
        it 'returns an Array of alerts' do
          link['data-alert'] = alert.id.to_s

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

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

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