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

36 lines
1.1 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2017-09-10 17:25:29 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Banzai::Filter::ImageLazyLoadFilter do
2017-09-10 17:25:29 +05:30
include FilterSpecHelper
def image(path)
%(<img src="#{path}" />)
end
2018-11-18 11:00:15 +05:30
def image_with_class(path, class_attr = nil)
%(<img src="#{path}" class="#{class_attr}"/>)
end
it 'adds a class attribute' do
doc = filter(image('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg'))
expect(doc.at_css('img')['class']).to eq 'lazy'
end
it 'appends to the current class attribute' do
doc = filter(image_with_class('/uploads/e90decf88d8f96fe9e1389afc2e4a91f/test.jpg', 'test'))
expect(doc.at_css('img')['class']).to eq 'test lazy'
end
2017-09-10 17:25:29 +05:30
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'
end
it 'works with external images' do
doc = filter(image('https://i.imgur.com/DfssX9C.jpg'))
expect(doc.at_css('img')['data-src']).to eq 'https://i.imgur.com/DfssX9C.jpg'
end
end