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

attributes_filter_spec.rb « filter « banzai « lib « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cef5e24cdaa0e7048749fb66b5b8f52b5d65c83d (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
# 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