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 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Banzai::ReferenceParser::ExternalIssueParser, feature_category: :markdown do
include ReferenceParserHelpers
let(:project) { create(:project, :public) }
let(:user) { create(:user) }
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-external-issue'] = 123
end
levels = [ProjectFeature::DISABLED, ProjectFeature::PRIVATE, ProjectFeature::ENABLED]
levels.each do |level|
it "creates reference when the feature is #{level}" do
project.project_feature.update!(issues_access_level: level)
visible_nodes = subject.nodes_visible_to_user(user, [link])
expect(visible_nodes).to include(link)
end
end
end
end
describe '#referenced_by' do
context 'when the link has a data-project attribute' do
before do
link['data-project'] = project.id.to_s
end
context 'when the link has a data-external-issue attribute' do
it 'returns an Array of ExternalIssue instances' do
link['data-external-issue'] = '123'
refs = subject.referenced_by([link])
expect(refs).to eq([ExternalIssue.new('123', project)])
end
end
context 'when the link does not have a data-external-issue attribute' do
it 'returns an empty Array' do
expect(subject.referenced_by([link])).to eq([])
end
end
end
context 'when the link does not have a data-project attribute' do
it 'returns an empty Array' do
expect(subject.referenced_by([link])).to eq([])
end
end
end
describe '#issue_ids_per_project' do
before do
link['data-project'] = project.id.to_s
end
it 'returns a Hash containing range IDs per project' do
link['data-external-issue'] = '123'
hash = subject.issue_ids_per_project([link])
expect(hash).to be_an_instance_of(Hash)
expect(hash[project.id].to_a).to eq(['123'])
end
it 'does not add a project when the data-external-issue attribute is empty' do
hash = subject.issue_ids_per_project([link])
expect(hash).to be_empty
end
end
end
|