video_link_filter_spec.rb 1.32 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
require 'spec_helper'

describe Banzai::Filter::VideoLinkFilter, lib: true do
  def filter(doc, contexts = {})
    contexts.reverse_merge!({
      project: project
    })

    described_class.call(doc, contexts)
  end

12
  def link_to_image(path)
13
14
15
16
17
18
    %(<img src="#{path}" />)
  end

  let(:project) { create(:project) }

  context 'when the element src has a video extension' do
19
20
    UploaderHelper::VIDEO_EXT.each do |ext|
      it "replaces the image tag 'path/video.#{ext}' with a video tag" do
21
        container = filter(link_to_image("/path/video.#{ext}")).children.first
22

23
24
25
26
        expect(container.name).to eq 'div'
        expect(container['class']).to eq 'video-container'

        video, paragraph = container.children
27

28
29
30
31
32
33
34
35
36
37
        expect(video.name).to eq 'video'
        expect(video['src']).to eq "/path/video.#{ext}"

        expect(paragraph.name).to eq 'p'

        link = paragraph.children.first

        expect(link.name).to eq 'a'
        expect(link['href']).to eq "/path/video.#{ext}"
        expect(link['target']).to eq '_blank'
38
      end
39
40
41
42
43
    end
  end

  context 'when the element src is an image' do
    it 'leaves the document unchanged' do
44
      element = filter(link_to_image('/path/my_image.jpg')).children.first
45
46

      expect(element.name).to eq 'img'
47
      expect(element['src']).to eq '/path/my_image.jpg'
48
49
50
    end
  end
end