Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-05-19 10:33:21 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-05-19 10:33:21 +0300
commit36a59d088eca61b834191dacea009677a96c052f (patch)
treee4f33972dab5d8ef79e3944a9f403035fceea43f /spec/lib/banzai
parenta1761f15ec2cae7c7f7bbda39a75494add0dfd6f (diff)
Add latest changes from gitlab-org/gitlab@15-0-stable-eev15.0.0-rc42
Diffstat (limited to 'spec/lib/banzai')
-rw-r--r--spec/lib/banzai/filter/image_lazy_load_filter_spec.rb5
-rw-r--r--spec/lib/banzai/filter/references/issue_reference_filter_spec.rb22
-rw-r--r--spec/lib/banzai/pipeline/incident_management/timeline_event_pipeline_spec.rb86
3 files changed, 113 insertions, 0 deletions
diff --git a/spec/lib/banzai/filter/image_lazy_load_filter_spec.rb b/spec/lib/banzai/filter/image_lazy_load_filter_spec.rb
index 9f5aa558f24..5b32be0ea62 100644
--- a/spec/lib/banzai/filter/image_lazy_load_filter_spec.rb
+++ b/spec/lib/banzai/filter/image_lazy_load_filter_spec.rb
@@ -23,6 +23,11 @@ RSpec.describe Banzai::Filter::ImageLazyLoadFilter do
expect(doc.at_css('img')['class']).to eq 'test lazy'
end
+ it 'adds a async decoding attribute' do
+ doc = filter(image_with_class('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg', 'test'))
+ expect(doc.at_css('img')['decoding']).to eq 'async'
+ end
+
it 'transforms the image src to a data-src' do
doc = filter(image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg'))
expect(doc.at_css('img')['data-src']).to eq '/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg'
diff --git a/spec/lib/banzai/filter/references/issue_reference_filter_spec.rb b/spec/lib/banzai/filter/references/issue_reference_filter_spec.rb
index c493cb77c98..c6f0e592cdf 100644
--- a/spec/lib/banzai/filter/references/issue_reference_filter_spec.rb
+++ b/spec/lib/banzai/filter/references/issue_reference_filter_spec.rb
@@ -15,6 +15,14 @@ RSpec.describe Banzai::Filter::References::IssueReferenceFilter do
let(:issue_path) { "/#{issue.project.namespace.path}/#{issue.project.path}/-/issues/#{issue.iid}" }
let(:issue_url) { "http://#{Gitlab.config.gitlab.host}#{issue_path}" }
+ shared_examples 'a reference with issue type information' do
+ it 'contains issue-type as a data attribute' do
+ doc = reference_filter("Fixed #{reference}")
+
+ expect(doc.css('a').first.attr('data-issue-type')).to eq('issue')
+ end
+ end
+
it 'requires project context' do
expect { described_class.call('') }.to raise_error(ArgumentError, /:project/)
end
@@ -44,6 +52,8 @@ RSpec.describe Banzai::Filter::References::IssueReferenceFilter do
it_behaves_like 'a reference containing an element node'
+ it_behaves_like 'a reference with issue type information'
+
it 'links to a valid reference' do
doc = reference_filter("Fixed #{reference}")
@@ -158,6 +168,8 @@ RSpec.describe Banzai::Filter::References::IssueReferenceFilter do
it_behaves_like 'a reference containing an element node'
+ it_behaves_like 'a reference with issue type information'
+
it 'ignores valid references when cross-reference project uses external tracker' do
expect_any_instance_of(described_class).to receive(:find_object)
.with(project2, issue.iid)
@@ -208,6 +220,8 @@ RSpec.describe Banzai::Filter::References::IssueReferenceFilter do
it_behaves_like 'a reference containing an element node'
+ it_behaves_like 'a reference with issue type information'
+
it 'ignores valid references when cross-reference project uses external tracker' do
expect_any_instance_of(described_class).to receive(:find_object)
.with(project2, issue.iid)
@@ -258,6 +272,8 @@ RSpec.describe Banzai::Filter::References::IssueReferenceFilter do
it_behaves_like 'a reference containing an element node'
+ it_behaves_like 'a reference with issue type information'
+
it 'ignores valid references when cross-reference project uses external tracker' do
expect_any_instance_of(described_class).to receive(:find_object)
.with(project2, issue.iid)
@@ -307,6 +323,8 @@ RSpec.describe Banzai::Filter::References::IssueReferenceFilter do
it_behaves_like 'a reference containing an element node'
+ it_behaves_like 'a reference with issue type information'
+
it 'links to a valid reference' do
doc = reference_filter("See #{reference}")
@@ -342,6 +360,8 @@ RSpec.describe Banzai::Filter::References::IssueReferenceFilter do
it_behaves_like 'a reference containing an element node'
+ it_behaves_like 'a reference with issue type information'
+
it 'links to a valid reference' do
doc = reference_filter("See #{reference_link}")
@@ -371,6 +391,8 @@ RSpec.describe Banzai::Filter::References::IssueReferenceFilter do
it_behaves_like 'a reference containing an element node'
+ it_behaves_like 'a reference with issue type information'
+
it 'links to a valid reference' do
doc = reference_filter("See #{reference_link}")
diff --git a/spec/lib/banzai/pipeline/incident_management/timeline_event_pipeline_spec.rb b/spec/lib/banzai/pipeline/incident_management/timeline_event_pipeline_spec.rb
new file mode 100644
index 00000000000..09d2919c6c4
--- /dev/null
+++ b/spec/lib/banzai/pipeline/incident_management/timeline_event_pipeline_spec.rb
@@ -0,0 +1,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