diff options
author | Tim Zallmann <tzallmann@gitlab.com> | 2017-07-24 20:36:52 +0300 |
---|---|---|
committer | Jacob Schatz <jschatz@gitlab.com> | 2017-07-24 20:36:52 +0300 |
commit | 52b8a0db689c2df968776a1f369ea6a6db245d39 (patch) | |
tree | 4955f45d5d19c1d32aee8bc496041acdd74763cb /spec/lib/banzai/filter | |
parent | 3a26bce80eb739ca3f552dfe71e39b9a177eb36e (diff) |
Resolve "Lazy load images on the Frontend"
Diffstat (limited to 'spec/lib/banzai/filter')
-rw-r--r-- | spec/lib/banzai/filter/gollum_tags_filter_spec.rb | 4 | ||||
-rw-r--r-- | spec/lib/banzai/filter/image_lazy_load_filter_spec.rb | 19 |
2 files changed, 21 insertions, 2 deletions
diff --git a/spec/lib/banzai/filter/gollum_tags_filter_spec.rb b/spec/lib/banzai/filter/gollum_tags_filter_spec.rb index 082c0d4dd0d..cbb2808c6bb 100644 --- a/spec/lib/banzai/filter/gollum_tags_filter_spec.rb +++ b/spec/lib/banzai/filter/gollum_tags_filter_spec.rb @@ -22,7 +22,7 @@ describe Banzai::Filter::GollumTagsFilter, lib: true do tag = '[[images/image.jpg]]' doc = filter("See #{tag}", project_wiki: project_wiki) - expect(doc.at_css('img')['src']).to eq "#{project_wiki.wiki_base_path}/images/image.jpg" + expect(doc.at_css('img')['data-src']).to eq "#{project_wiki.wiki_base_path}/images/image.jpg" end it 'does not creates img tag if image does not exist' do @@ -40,7 +40,7 @@ describe Banzai::Filter::GollumTagsFilter, lib: true do tag = '[[http://example.com/image.jpg]]' doc = filter("See #{tag}", project_wiki: project_wiki) - expect(doc.at_css('img')['src']).to eq "http://example.com/image.jpg" + expect(doc.at_css('img')['data-src']).to eq "http://example.com/image.jpg" end it 'does not creates img tag for invalid URL' do diff --git a/spec/lib/banzai/filter/image_lazy_load_filter_spec.rb b/spec/lib/banzai/filter/image_lazy_load_filter_spec.rb new file mode 100644 index 00000000000..c19de7b784a --- /dev/null +++ b/spec/lib/banzai/filter/image_lazy_load_filter_spec.rb @@ -0,0 +1,19 @@ +require 'spec_helper' + +describe Banzai::Filter::ImageLazyLoadFilter, lib: true do + include FilterSpecHelper + + def image(path) + %(<img src="#{path}" />) + end + + 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 |