Sha256: 40b6a7b0a9ed4e831353d0d18d2795d1190902f8440beb488a06fc0ac65d47b5

Contents?: true

Size: 1.53 KB

Versions: 15

Compression:

Stored size: 1.53 KB

Contents

require 'inline_svg/transform_pipeline'

describe InlineSvg::TransformPipeline::Transformations::Title do
  it "adds a title element as the first element in the SVG document" do
    document = Nokogiri::XML::Document.parse('<svg>Some document</svg>')
    transformation = InlineSvg::TransformPipeline::Transformations::Title.create_with_value("Some Title")

    expect(transformation.transform(document).to_html).to eq(
      "<svg><title>Some Title</title>Some document</svg>\n"
    )
  end

  it "overwrites the content of an existing title element" do
    document = Nokogiri::XML::Document.parse('<svg><title>My Title</title>Some document</svg>')
    transformation = InlineSvg::TransformPipeline::Transformations::Title.create_with_value("Some Title")

    expect(transformation.transform(document).to_html).to eq(
      "<svg><title>Some Title</title>Some document</svg>\n"
    )
  end

  it "handles empty SVG documents" do
    document = Nokogiri::XML::Document.parse('<svg></svg>')
    transformation = InlineSvg::TransformPipeline::Transformations::Title.create_with_value("Some Title")

    expect(transformation.transform(document).to_html).to eq(
      "<svg><title>Some Title</title></svg>\n"
    )
  end

  it "handles non-ASCII characters" do
    document = Nokogiri::XML::Document.parse('<svg>Some document</svg>')
    transformation = InlineSvg::TransformPipeline::Transformations::Title.create_with_value("åäö")

    expect(transformation.transform(document).to_html).to eq(
      "<svg><title>åäö</title>Some document</svg>\n"
    )
  end
end

Version data entries

15 entries across 15 versions & 2 rubygems

Version Path
inline_svg-1.10.0 spec/transformation_pipeline/transformations/title_spec.rb
inline_svg-1.9.0 spec/transformation_pipeline/transformations/title_spec.rb
inline_svg-1.8.0 spec/transformation_pipeline/transformations/title_spec.rb
rails_mini_profiler-0.2.0 vendor/bundle/ruby/3.0.0/gems/inline_svg-1.7.2/spec/transformation_pipeline/transformations/title_spec.rb
inline_svg-1.7.2 spec/transformation_pipeline/transformations/title_spec.rb
inline_svg-1.7.1 spec/transformation_pipeline/transformations/title_spec.rb
inline_svg-1.7.0 spec/transformation_pipeline/transformations/title_spec.rb
inline_svg-1.6.0 spec/transformation_pipeline/transformations/title_spec.rb
inline_svg-1.5.2 spec/transformation_pipeline/transformations/title_spec.rb
inline_svg-1.5.1 spec/transformation_pipeline/transformations/title_spec.rb
inline_svg-1.5.0 spec/transformation_pipeline/transformations/title_spec.rb
inline_svg-1.4.0 spec/transformation_pipeline/transformations/title_spec.rb
inline_svg-1.3.1 spec/transformation_pipeline/transformations/title_spec.rb
inline_svg-1.3.0 spec/transformation_pipeline/transformations/title_spec.rb
inline_svg-1.2.3 spec/transformation_pipeline/transformations/title_spec.rb