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-12-20 17:22:11 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-12-20 17:22:11 +0300
commit0c872e02b2c822e3397515ec324051ff540f0cd5 (patch)
treece2fb6ce7030e4dad0f4118d21ab6453e5938cdd /spec/lib/banzai/filter/attributes_filter_spec.rb
parentf7e05a6853b12f02911494c4b3fe53d9540d74fc (diff)
Add latest changes from gitlab-org/gitlab@15-7-stable-eev15.7.0-rc42
Diffstat (limited to 'spec/lib/banzai/filter/attributes_filter_spec.rb')
-rw-r--r--spec/lib/banzai/filter/attributes_filter_spec.rb78
1 files changed, 78 insertions, 0 deletions
diff --git a/spec/lib/banzai/filter/attributes_filter_spec.rb b/spec/lib/banzai/filter/attributes_filter_spec.rb
new file mode 100644
index 00000000000..cef5e24cdaa
--- /dev/null
+++ b/spec/lib/banzai/filter/attributes_filter_spec.rb
@@ -0,0 +1,78 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Banzai::Filter::AttributesFilter, feature_category: :team_planning do
+ using RSpec::Parameterized::TableSyntax
+ include FilterSpecHelper
+
+ def image
+ %(<img src="example.jpg">)
+ end
+
+ describe 'attribute syntax' do
+ context 'when attribute syntax is valid' do
+ where(:text, :result) do
+ "#{image}{width=100}" | '<img src="example.jpg" width="100">'
+ "#{image}{ width=100 }" | '<img src="example.jpg" width="100">'
+ "#{image}{width=\"100\"}" | '<img src="example.jpg" width="100">'
+ "#{image}{width=100 width=200}" | '<img src="example.jpg" width="200">'
+
+ "#{image}{.test_class width=100 style=\"width:400\"}" | '<img src="example.jpg" width="100">'
+ "<img src=\"example.jpg\" class=\"lazy\" />{width=100}" | '<img src="example.jpg" class="lazy" width="100">'
+ end
+
+ with_them do
+ it 'adds them to the img' do
+ expect(filter(text).to_html).to eq result
+ end
+ end
+ end
+
+ context 'when attribute syntax is invalid' do
+ where(:text, :result) do
+ "#{image} {width=100}" | '<img src="example.jpg"> {width=100}'
+ "#{image}{width=100\nheight=100}" | "<img src=\"example.jpg\">{width=100\nheight=100}"
+ "{width=100 height=100}\n#{image}" | "{width=100 height=100}\n<img src=\"example.jpg\">"
+ '<h1>header</h1>{width=100}' | '<h1>header</h1>{width=100}'
+ end
+
+ with_them do
+ it 'does not recognize as attributes' do
+ expect(filter(text).to_html).to eq result
+ end
+ end
+ end
+ end
+
+ describe 'height and width' do
+ context 'when size attributes are valid' do
+ where(:text, :result) do
+ "#{image}{width=100 height=200px}" | '<img src="example.jpg" width="100" height="200px">'
+ "#{image}{width=100}" | '<img src="example.jpg" width="100">'
+ "#{image}{width=100px}" | '<img src="example.jpg" width="100px">'
+ "#{image}{height=100%}" | '<img src="example.jpg" height="100%">'
+ "#{image}{width=\"100%\"}" | '<img src="example.jpg" width="100%">'
+ end
+
+ with_them do
+ it 'adds them to the img' do
+ expect(filter(text).to_html).to eq result
+ end
+ end
+ end
+
+ context 'when size attributes are invalid' do
+ where(:text, :result) do
+ "#{image}{width=100cs}" | '<img src="example.jpg">'
+ "#{image}{width=auto height=200}" | '<img src="example.jpg" height="200">'
+ end
+
+ with_them do
+ it 'ignores them' do
+ expect(filter(text).to_html).to eq result
+ end
+ end
+ end
+ end
+end