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

image_lazy_load_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: 6475fd14ce42edd0698149ea434180fb2df076f0 (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
# frozen_string_literal: true

require 'spec_helper'

describe Banzai::Filter::ImageLazyLoadFilter do
  include FilterSpecHelper

  def image(path)
    %(<img src="#{path}" />)
  end

  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

  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