blob: 09d2919c6c4067f667fae2823daedacb36e771bd (
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
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
86
|
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Banzai::Pipeline::IncidentManagement::TimelineEventPipeline do
let_it_be(:project) { create(:project) }
describe '.filters' do
it 'contains required filters' do
expect(described_class.filters).to eq(
[
*Banzai::Pipeline::PlainMarkdownPipeline.filters,
*Banzai::Pipeline::GfmPipeline.reference_filters,
Banzai::Filter::EmojiFilter,
Banzai::Filter::SanitizationFilter,
Banzai::Filter::ExternalLinkFilter,
Banzai::Filter::ImageLinkFilter
]
)
end
end
describe '.to_html' do
subject(:output) { described_class.to_html(markdown, project: project) }
context 'when markdown contains font style transformations' do
let(:markdown) { '**bold** _italic_ `code`' }
it { is_expected.to eq('<p><strong>bold</strong> <em>italic</em> <code>code</code></p>') }
end
context 'when markdown contains banned HTML tags' do
let(:markdown) { '<div>div</div><h1>h1</h1>' }
it 'filters out banned tags' do
is_expected.to eq(' div h1 ')
end
end
context 'when markdown contains links' do
let(:markdown) { '[GitLab](https://gitlab.com)' }
it do
is_expected.to eq(
%q(<p><a href="https://gitlab.com" rel="nofollow noreferrer noopener" target="_blank">GitLab</a></p>)
)
end
end
context 'when markdown contains images' do
let(:markdown) { '![Name](/path/to/image.png)' }
it 'replaces image with a link to the image' do
# rubocop:disable Layout/LineLength
is_expected.to eq(
'<p><a class="with-attachment-icon" href="/path/to/image.png" target="_blank" rel="noopener noreferrer">Name</a></p>'
)
# rubocop:enable Layout/LineLength
end
end
context 'when markdown contains emojis' do
let(:markdown) { ':+1:👍' }
it { is_expected.to eq('<p>👍👍</p>') }
end
context 'when markdown contains a reference to an issue' do
let!(:issue) { create(:issue, project: project) }
let(:markdown) { "issue ##{issue.iid}" }
it 'contains a link to the issue' do
is_expected.to match(%r(<p>issue <a href="[\w/]+-/issues/#{issue.iid}".*>##{issue.iid}</a></p>))
end
end
context 'when markdown contains a reference to a merge request' do
let!(:mr) { create(:merge_request, source_project: project, target_project: project) }
let(:markdown) { "MR !#{mr.iid}" }
it 'contains a link to the merge request' do
is_expected.to match(%r(<p>MR <a href="[\w/]+-/merge_requests/#{mr.iid}".*>!#{mr.iid}</a></p>))
end
end
end
end
|