debian-mirror-gitlab/spec/lib/banzai/filter/image_link_filter_spec.rb

39 lines
1.3 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2016-06-02 11:05:42 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Banzai::Filter::ImageLinkFilter do
2016-06-02 11:05:42 +05:30
include FilterSpecHelper
def image(path)
%(<img src="#{path}" />)
end
it 'wraps the image with a link to the image src' do
doc = filter(image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg'))
expect(doc.at_css('img')['src']).to eq doc.at_css('a')['href']
end
it 'does not wrap a duplicate link' do
2017-08-17 22:00:37 +05:30
doc = filter(%Q(<a href="/whatever">#{image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg')}</a>))
2018-03-17 18:26:18 +05:30
expect(doc.to_html).to match %r{^<a href="/whatever"><img[^>]*></a>$}
2016-06-02 11:05:42 +05:30
end
it 'works with external images' do
doc = filter(image('https://i.imgur.com/DfssX9C.jpg'))
expect(doc.at_css('img')['src']).to eq doc.at_css('a')['href']
end
2016-08-24 12:49:21 +05:30
2017-08-17 22:00:37 +05:30
it 'works with inline images' do
doc = filter(%Q(<p>test #{image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg')} inline</p>))
2018-03-17 18:26:18 +05:30
expect(doc.to_html).to match %r{^<p>test <a[^>]*><img[^>]*></a> inline</p>$}
2016-08-24 12:49:21 +05:30
end
2019-09-04 21:01:54 +05:30
it 'keep the data-canonical-src' do
doc = filter(%q(<img src="http://assets.example.com/6cd/4d7" data-canonical-src="http://example.com/test.png" />))
expect(doc.at_css('img')['src']).to eq doc.at_css('a')['href']
expect(doc.at_css('img')['data-canonical-src']).to eq doc.at_css('a')['data-canonical-src']
end
2016-06-02 11:05:42 +05:30
end